@agentclientprotocol/claude-agent-acp 0.102.0 → 0.102.1-preview.2

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 (206) hide show
  1. package/README.md +5 -1
  2. package/dist/acp-agent.d.ts +119 -439
  3. package/dist/acp-agent.d.ts.map +1 -1
  4. package/dist/acp-agent.js +380 -2412
  5. package/dist/acp-subagents.d.ts +1 -2
  6. package/dist/acp-subagents.d.ts.map +1 -1
  7. package/dist/auth-methods.d.ts +21 -0
  8. package/dist/auth-methods.d.ts.map +1 -0
  9. package/dist/auth-methods.js +68 -0
  10. package/dist/auth-status-reporter.d.ts +112 -0
  11. package/dist/auth-status-reporter.d.ts.map +1 -0
  12. package/dist/auth-status-reporter.js +253 -0
  13. package/dist/background-work.d.ts +12 -265
  14. package/dist/background-work.d.ts.map +1 -1
  15. package/dist/background-work.js +8 -558
  16. package/dist/client-system-prompt.d.ts +7 -0
  17. package/dist/client-system-prompt.d.ts.map +1 -1
  18. package/dist/client-system-prompt.js +24 -0
  19. package/dist/context-compaction.d.ts +20 -0
  20. package/dist/context-compaction.d.ts.map +1 -1
  21. package/dist/context-compaction.js +26 -0
  22. package/dist/context-window.d.ts +70 -0
  23. package/dist/context-window.d.ts.map +1 -0
  24. package/dist/context-window.js +132 -0
  25. package/dist/diff.d.ts +1 -1
  26. package/dist/diff.js +1 -1
  27. package/dist/elicitation.d.ts +66 -1
  28. package/dist/elicitation.d.ts.map +1 -1
  29. package/dist/elicitation.js +109 -0
  30. package/dist/file-change-audit.d.ts +4 -3
  31. package/dist/file-change-audit.d.ts.map +1 -1
  32. package/dist/file-change-audit.js +3 -2
  33. package/dist/mcp-oauth.d.ts +44 -0
  34. package/dist/mcp-oauth.d.ts.map +1 -0
  35. package/dist/mcp-oauth.js +142 -0
  36. package/dist/mcp-servers.d.ts +10 -0
  37. package/dist/mcp-servers.d.ts.map +1 -0
  38. package/dist/mcp-servers.js +29 -0
  39. package/dist/native-subagents.d.ts +18 -8
  40. package/dist/native-subagents.d.ts.map +1 -1
  41. package/dist/native-subagents.js +7 -35
  42. package/dist/permissions/presentation.d.ts +29 -0
  43. package/dist/permissions/presentation.d.ts.map +1 -1
  44. package/dist/permissions/presentation.js +38 -11
  45. package/dist/plans.d.ts +36 -6
  46. package/dist/plans.d.ts.map +1 -1
  47. package/dist/plans.js +49 -11
  48. package/dist/prompt-suggestions.d.ts +29 -0
  49. package/dist/prompt-suggestions.d.ts.map +1 -1
  50. package/dist/prompt-suggestions.js +45 -0
  51. package/dist/providers.d.ts +139 -0
  52. package/dist/providers.d.ts.map +1 -0
  53. package/dist/providers.js +286 -0
  54. package/dist/remote-control.d.ts +62 -0
  55. package/dist/remote-control.d.ts.map +1 -0
  56. package/dist/remote-control.js +78 -0
  57. package/dist/result-end.d.ts +39 -0
  58. package/dist/result-end.d.ts.map +1 -0
  59. package/dist/result-end.js +50 -0
  60. package/dist/serve.d.ts +7 -2
  61. package/dist/serve.d.ts.map +1 -1
  62. package/dist/serve.js +10 -5
  63. package/dist/session-config-ids.d.ts +1 -0
  64. package/dist/session-config-ids.d.ts.map +1 -1
  65. package/dist/session-config-ids.js +1 -0
  66. package/dist/session-config-options.d.ts +64 -0
  67. package/dist/session-config-options.d.ts.map +1 -0
  68. package/dist/session-config-options.js +162 -0
  69. package/dist/session-effort.d.ts +67 -0
  70. package/dist/session-effort.d.ts.map +1 -1
  71. package/dist/session-effort.js +98 -0
  72. package/dist/session-env.d.ts +22 -0
  73. package/dist/session-env.d.ts.map +1 -0
  74. package/dist/session-env.js +66 -0
  75. package/dist/session-fast-mode.d.ts +83 -0
  76. package/dist/session-fast-mode.d.ts.map +1 -0
  77. package/dist/session-fast-mode.js +142 -0
  78. package/dist/session-index/connection.d.ts +2 -5
  79. package/dist/session-index/connection.d.ts.map +1 -1
  80. package/dist/session-index/connection.js +3 -5
  81. package/dist/session-mode.d.ts +1 -0
  82. package/dist/session-mode.d.ts.map +1 -1
  83. package/dist/session-mode.js +1 -1
  84. package/dist/session-model.d.ts +41 -0
  85. package/dist/session-model.d.ts.map +1 -1
  86. package/dist/session-model.js +110 -45
  87. package/dist/session-notices.d.ts +44 -0
  88. package/dist/session-notices.d.ts.map +1 -1
  89. package/dist/session-notices.js +68 -0
  90. package/dist/session-titles.d.ts +34 -12
  91. package/dist/session-titles.d.ts.map +1 -1
  92. package/dist/session-titles.js +7 -6
  93. package/dist/session-usage.d.ts +125 -0
  94. package/dist/session-usage.d.ts.map +1 -0
  95. package/dist/session-usage.js +196 -0
  96. package/dist/streamed-text.d.ts +33 -0
  97. package/dist/streamed-text.d.ts.map +1 -0
  98. package/dist/streamed-text.js +71 -0
  99. package/dist/subagent-configuration.d.ts +32 -0
  100. package/dist/subagent-configuration.d.ts.map +1 -0
  101. package/dist/subagent-configuration.js +70 -0
  102. package/dist/subagent-replay.d.ts +18 -0
  103. package/dist/subagent-replay.d.ts.map +1 -1
  104. package/dist/subagent-replay.js +25 -15
  105. package/dist/tool-calls/client-capabilities.d.ts +8 -8
  106. package/dist/tool-calls/client-capabilities.js +4 -4
  107. package/dist/tool-calls/renderer.d.ts +4 -5
  108. package/dist/tool-calls/renderer.d.ts.map +1 -1
  109. package/dist/tool-calls/renderer.js +4 -5
  110. package/dist/turn-events.d.ts +6 -46
  111. package/dist/turn-events.d.ts.map +1 -1
  112. package/dist/v2/agent.d.ts +7 -11
  113. package/dist/v2/agent.d.ts.map +1 -1
  114. package/dist/v2/agent.js +751 -331
  115. package/dist/v2/air.d.ts +33 -0
  116. package/dist/v2/air.d.ts.map +1 -0
  117. package/dist/v2/air.js +29 -0
  118. package/dist/v2/auth.d.ts +97 -0
  119. package/dist/v2/auth.d.ts.map +1 -0
  120. package/dist/v2/auth.js +216 -0
  121. package/dist/v2/background.d.ts +27 -16
  122. package/dist/v2/background.d.ts.map +1 -1
  123. package/dist/v2/background.js +4 -32
  124. package/dist/v2/child-config.d.ts +55 -0
  125. package/dist/v2/child-config.d.ts.map +1 -0
  126. package/dist/v2/child-config.js +92 -0
  127. package/dist/v2/clear-context.d.ts +94 -0
  128. package/dist/v2/clear-context.d.ts.map +1 -0
  129. package/dist/v2/clear-context.js +176 -0
  130. package/dist/v2/commands.d.ts +46 -0
  131. package/dist/v2/commands.d.ts.map +1 -0
  132. package/dist/v2/commands.js +54 -0
  133. package/dist/v2/config.d.ts +187 -0
  134. package/dist/v2/config.d.ts.map +1 -0
  135. package/dist/v2/config.js +494 -0
  136. package/dist/v2/elicitation.d.ts +93 -0
  137. package/dist/v2/elicitation.d.ts.map +1 -0
  138. package/dist/v2/elicitation.js +160 -0
  139. package/dist/v2/file-changes.d.ts +61 -0
  140. package/dist/v2/file-changes.d.ts.map +1 -0
  141. package/dist/v2/file-changes.js +108 -0
  142. package/dist/v2/file-preview.d.ts +18 -0
  143. package/dist/v2/file-preview.d.ts.map +1 -0
  144. package/dist/v2/file-preview.js +29 -0
  145. package/dist/v2/initialize.d.ts +10 -24
  146. package/dist/v2/initialize.d.ts.map +1 -1
  147. package/dist/v2/initialize.js +4 -111
  148. package/dist/v2/outcome.d.ts +81 -0
  149. package/dist/v2/outcome.d.ts.map +1 -0
  150. package/dist/v2/outcome.js +165 -0
  151. package/dist/v2/permissions.d.ts +92 -0
  152. package/dist/v2/permissions.d.ts.map +1 -0
  153. package/dist/v2/permissions.js +162 -0
  154. package/dist/v2/prompt.d.ts +2 -42
  155. package/dist/v2/prompt.d.ts.map +1 -1
  156. package/dist/v2/prompt.js +2 -119
  157. package/dist/v2/remote-control.d.ts +41 -0
  158. package/dist/v2/remote-control.d.ts.map +1 -0
  159. package/dist/v2/remote-control.js +63 -0
  160. package/dist/v2/reports.d.ts +198 -0
  161. package/dist/v2/reports.d.ts.map +1 -0
  162. package/dist/v2/reports.js +487 -0
  163. package/dist/v2/restarts.d.ts +128 -0
  164. package/dist/v2/restarts.d.ts.map +1 -0
  165. package/dist/v2/restarts.js +348 -0
  166. package/dist/v2/session-requests.d.ts +20 -0
  167. package/dist/v2/session-requests.d.ts.map +1 -0
  168. package/dist/v2/session-requests.js +108 -0
  169. package/dist/v2/session-update.d.ts +2 -13
  170. package/dist/v2/session-update.d.ts.map +1 -1
  171. package/dist/v2/session-update.js +2 -22
  172. package/dist/v2/session.d.ts +340 -41
  173. package/dist/v2/session.d.ts.map +1 -1
  174. package/dist/v2/session.js +1223 -141
  175. package/dist/v2/setup.d.ts +49 -0
  176. package/dist/v2/setup.d.ts.map +1 -0
  177. package/dist/v2/setup.js +62 -0
  178. package/dist/v2/stopped-work.d.ts +123 -0
  179. package/dist/v2/stopped-work.d.ts.map +1 -0
  180. package/dist/v2/stopped-work.js +210 -0
  181. package/dist/v2/stream.d.ts +228 -0
  182. package/dist/v2/stream.d.ts.map +1 -0
  183. package/dist/v2/stream.js +506 -0
  184. package/dist/v2/subagent-replay.d.ts +115 -0
  185. package/dist/v2/subagent-replay.d.ts.map +1 -0
  186. package/dist/v2/subagent-replay.js +479 -0
  187. package/dist/v2/subscription-guard.d.ts +60 -0
  188. package/dist/v2/subscription-guard.d.ts.map +1 -0
  189. package/dist/v2/subscription-guard.js +84 -0
  190. package/dist/v2/tasks.d.ts +492 -0
  191. package/dist/v2/tasks.d.ts.map +1 -0
  192. package/dist/v2/tasks.js +1728 -0
  193. package/dist/v2/terminal.d.ts.map +1 -1
  194. package/dist/v2/terminal.js +6 -1
  195. package/dist/v2/tool-call.d.ts +3 -2
  196. package/dist/v2/tool-call.d.ts.map +1 -1
  197. package/dist/v2/update-translator.d.ts +36 -0
  198. package/dist/v2/update-translator.d.ts.map +1 -0
  199. package/dist/v2/update-translator.js +80 -0
  200. package/dist/workflow-progress.d.ts +23 -0
  201. package/dist/workflow-progress.d.ts.map +1 -1
  202. package/dist/workflow-progress.js +31 -8
  203. package/package.json +1 -1
  204. package/dist/v2/permission.d.ts +0 -28
  205. package/dist/v2/permission.d.ts.map +0 -1
  206. package/dist/v2/permission.js +0 -41
@@ -34,4 +34,33 @@ export declare function promptSuggestionText(raw: string | null | undefined): st
34
34
  * predicted nothing, so the composer must not keep the previous prediction.
35
35
  */
36
36
  export declare function promptSuggestionsMeta(text: string | null): Record<string, unknown>;
37
+ /**
38
+ * The prediction a session holds on the client, and whether an arriving
39
+ * `prompt_suggestion` still answers the turn the user waits on. Both cores
40
+ * keep one per session and send the `_meta` that its methods return as a
41
+ * `session_info_update`, to an AIR client only. Undefined: nothing to send.
42
+ */
43
+ export declare class PromptSuggestions {
44
+ /** The last text sent (`null` after a clear). Undefined until the first send. */
45
+ private published;
46
+ /**
47
+ * Set at a turn's result, cleared when the next prompt arrives. A
48
+ * prediction that the next prompt outran (sent before the prediction was
49
+ * read off the stream) follows a turn that is answered already, so it is
50
+ * dropped instead of published mid-turn.
51
+ */
52
+ private expected;
53
+ /** A result came: the CLI predicts the next prompt right after it. */
54
+ resultArrived(): void;
55
+ /** The `_meta` of the CLI's `prompt_suggestion`, if it answers the last result and changes what the client holds. */
56
+ suggested(raw: string | null | undefined): Record<string, unknown> | undefined;
57
+ /**
58
+ * The `_meta` that clears the prediction: a client prompt spent it, or a
59
+ * `conversation_reset` dropped the transcript it came from. It also drops
60
+ * a prediction still in flight for the last result. Undefined when the
61
+ * client holds none.
62
+ */
63
+ clear(): Record<string, unknown> | undefined;
64
+ private publish;
65
+ }
37
66
  //# sourceMappingURL=prompt-suggestions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-suggestions.d.ts","sourceRoot":"","sources":["../src/prompt-suggestions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,wEAAwE;AACxE,eAAO,MAAM,2BAA2B,sBAAsB,CAAC;AAE/D,6DAA6D;AAC7D,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGlF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGlF"}
1
+ {"version":3,"file":"prompt-suggestions.d.ts","sourceRoot":"","sources":["../src/prompt-suggestions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,wEAAwE;AACxE,eAAO,MAAM,2BAA2B,sBAAsB,CAAC;AAE/D,6DAA6D;AAC7D,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGlF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGlF;AAED;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC5B,iFAAiF;IACjF,OAAO,CAAC,SAAS,CAA4B;IAC7C;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAS;IAEzB,sEAAsE;IACtE,aAAa,IAAI,IAAI;IAIrB,qHAAqH;IACrH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAM9E;;;;;OAKG;IACH,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAK5C,OAAO,CAAC,OAAO;CAMhB"}
@@ -34,3 +34,48 @@ export function promptSuggestionsMeta(text) {
34
34
  const value = { suggestions: text === null ? [] : [{ text }] };
35
35
  return { [PROMPT_SUGGESTIONS_META_KEY]: value };
36
36
  }
37
+ /**
38
+ * The prediction a session holds on the client, and whether an arriving
39
+ * `prompt_suggestion` still answers the turn the user waits on. Both cores
40
+ * keep one per session and send the `_meta` that its methods return as a
41
+ * `session_info_update`, to an AIR client only. Undefined: nothing to send.
42
+ */
43
+ export class PromptSuggestions {
44
+ /** The last text sent (`null` after a clear). Undefined until the first send. */
45
+ published;
46
+ /**
47
+ * Set at a turn's result, cleared when the next prompt arrives. A
48
+ * prediction that the next prompt outran (sent before the prediction was
49
+ * read off the stream) follows a turn that is answered already, so it is
50
+ * dropped instead of published mid-turn.
51
+ */
52
+ expected = false;
53
+ /** A result came: the CLI predicts the next prompt right after it. */
54
+ resultArrived() {
55
+ this.expected = true;
56
+ }
57
+ /** The `_meta` of the CLI's `prompt_suggestion`, if it answers the last result and changes what the client holds. */
58
+ suggested(raw) {
59
+ if (!this.expected)
60
+ return undefined;
61
+ this.expected = false;
62
+ return this.publish(promptSuggestionText(raw));
63
+ }
64
+ /**
65
+ * The `_meta` that clears the prediction: a client prompt spent it, or a
66
+ * `conversation_reset` dropped the transcript it came from. It also drops
67
+ * a prediction still in flight for the last result. Undefined when the
68
+ * client holds none.
69
+ */
70
+ clear() {
71
+ this.expected = false;
72
+ return this.publish(null);
73
+ }
74
+ publish(text) {
75
+ // An unchanged prediction is not sent again.
76
+ if ((this.published ?? null) === text)
77
+ return undefined;
78
+ this.published = text;
79
+ return promptSuggestionsMeta(text);
80
+ }
81
+ }
@@ -0,0 +1,139 @@
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 { type AuthenticateRequest, type AuthMethod, type ListProvidersResponse, type LlmProtocol, type SetProviderRequest } from "@agentclientprotocol/sdk/unstable";
10
+ type ProviderLogger = {
11
+ log: (...args: any[]) => void;
12
+ error: (...args: any[]) => void;
13
+ };
14
+ /**
15
+ * Extra metadata for 'gateway' authentication requests.
16
+ */
17
+ export type GatewayAuthMeta = {
18
+ /**
19
+ * These parameters are mapped to environment variables to:
20
+ * - Redirect API calls via baseUrl
21
+ * - Inject custom headers
22
+ * - Bypass the default Claude login requirement
23
+ *
24
+ * Both members are optional in the type because the payload arrives
25
+ * unvalidated from the client. `authenticate` rejects a request that lacks a
26
+ * usable `baseUrl`.
27
+ */
28
+ gateway?: {
29
+ baseUrl?: string;
30
+ headers?: Record<string, string>;
31
+ };
32
+ };
33
+ export type GatewayAuthRequest = AuthenticateRequest & {
34
+ _meta?: GatewayAuthMeta;
35
+ };
36
+ export declare const SUPPORTED_PROTOCOLS: LlmProtocol[];
37
+ export declare const PROVIDER_ID = "main";
38
+ export declare const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com";
39
+ export declare const DEFAULT_VERTEX_BASE_URL = "https://aiplatform.googleapis.com";
40
+ /**
41
+ * Vertex needs project + region that the standard `providers/set` payload
42
+ * (`apiType`/`baseUrl`/`headers`) does not model, so clients pass them through
43
+ * `_meta.claudeCode.vertex`. Required only when `apiType === "vertex"`.
44
+ */
45
+ export type SetProviderMeta = {
46
+ claudeCode?: {
47
+ vertex?: {
48
+ projectId: string;
49
+ region: string;
50
+ };
51
+ };
52
+ };
53
+ /**
54
+ * Resolved, non-secret + secret routing config for the `main` provider. This is
55
+ * the shared shape produced by both `providers/set` and the legacy gateway auth
56
+ * path, and consumed by {@link createEnvForProvider}. `null` means the provider
57
+ * is unconfigured (no client-managed routing in effect).
58
+ */
59
+ export type ProviderConfig = {
60
+ apiType: LlmProtocol;
61
+ baseUrl: string;
62
+ headers: Record<string, string>;
63
+ /** Present only for `apiType === "vertex"`. */
64
+ vertex?: {
65
+ projectId: string;
66
+ region: string;
67
+ };
68
+ /**
69
+ * Model ids an `anthropic` or `bedrock` gateway listed when it was set via
70
+ * `providers/set`; the model picker offers only these. Absent when the
71
+ * listing failed or the config came from elsewhere (gateway `authenticate`),
72
+ * so nothing is narrowed.
73
+ */
74
+ listedModels?: string[];
75
+ /**
76
+ * The cross-region prefix of the model ids a `bedrock` gateway
77
+ * listed (`eu` for `eu.anthropic.claude-sonnet-5`), passed to the CLI as
78
+ * `ANTHROPIC_BEDROCK_REGION_PREFIX` so it calls the models under that prefix.
79
+ */
80
+ bedrockRegionPrefix?: string;
81
+ };
82
+ /**
83
+ * Adapt a legacy gateway `authenticate` request into the shared
84
+ * {@link ProviderConfig} shape. Returns `null` when no gateway request is
85
+ * present. `methodId` selects the protocol: `gateway-bedrock` → bedrock,
86
+ * otherwise anthropic.
87
+ */
88
+ export declare function gatewayRequestToProviderConfig(request?: GatewayAuthRequest): ProviderConfig | null;
89
+ /**
90
+ * Map a resolved provider config into the Claude Code env vars that redirect API
91
+ * traffic and inject headers. Returns an empty object when routing is
92
+ * unconfigured. The token/bypass placeholders (`" "`) are required so the CLI
93
+ * skips its normal login/credential checks when a gateway is in use.
94
+ */
95
+ export declare function createEnvForProvider(config: ProviderConfig | null): Record<string, string>;
96
+ /**
97
+ * A provider base URL as logs may show it: its origin only. The URL can come
98
+ * from the env or the client and can carry credentials (`https://user:key@host`)
99
+ * or a key in its path or query, so a log line must not print it whole.
100
+ */
101
+ export declare function loggableBaseUrl(baseUrl: string | undefined): string;
102
+ /**
103
+ * Validate a provider base URL: must be a non-empty absolute http(s) URL.
104
+ */
105
+ export declare function isValidBaseUrl(baseUrl: string | undefined): baseUrl is string;
106
+ /** The gateway login methods, advertised to a client with `auth._meta.gateway`. */
107
+ export declare function gatewayAuthMethods(): AuthMethod[];
108
+ export declare function isGatewayAuthMethod(methodId: string): boolean;
109
+ /**
110
+ * The gateway login `params` asks for, once its payload is usable: the same
111
+ * base URL rule as `providers/set`. An unchecked payload either throws a
112
+ * `TypeError` deep in session creation, or installs an empty base URL that
113
+ * silently turns the `--hide-claude-auth` subscription guard off.
114
+ *
115
+ * A request that carries no gateway payload at all keeps its historical
116
+ * meaning: it installs no override and succeeds. A client that probes the
117
+ * method this way must keep working. Only a payload that IS present has to be
118
+ * usable.
119
+ */
120
+ export declare function validatedGatewayAuthRequest(params: AuthenticateRequest): GatewayAuthRequest;
121
+ /** The native routing of the agent: a gateway login, else the process env. */
122
+ export declare function defaultProviderConfig(gatewayAuthRequest?: GatewayAuthRequest): ProviderConfig;
123
+ /** The `providers/list` response for the `main` provider routed by `config`. */
124
+ export declare function listProvidersResponse(config: ProviderConfig): ListProvidersResponse;
125
+ /**
126
+ * The configuration a `providers/set` request asks for. Rejects unknown IDs,
127
+ * unsupported protocols, empty or invalid base URLs, and a `vertex` request
128
+ * without its project and region, with `invalid_params`.
129
+ */
130
+ export declare function providerConfigFromSetRequest(params: SetProviderRequest): ProviderConfig;
131
+ /**
132
+ * Adds to `config` the model ids its gateway lists, and for `bedrock` the
133
+ * region prefix picked from them, so the sessions it routes offer only those.
134
+ * Setting the same gateway as `current` again reuses its listing. `vertex`
135
+ * gateways are not listed. A failed listing throws an `internal_error`.
136
+ */
137
+ export declare function withListedModels(config: ProviderConfig, current: ProviderConfig | undefined, logger: ProviderLogger): Promise<ProviderConfig>;
138
+ export {};
139
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"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"}
@@ -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
+ }