@agentclientprotocol/claude-agent-acp 0.102.1-preview.1 → 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.
- package/README.md +5 -1
- package/dist/acp-agent.d.ts +113 -439
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +362 -2409
- package/dist/acp-subagents.d.ts +1 -2
- package/dist/acp-subagents.d.ts.map +1 -1
- package/dist/auth-methods.d.ts +21 -0
- package/dist/auth-methods.d.ts.map +1 -0
- package/dist/auth-methods.js +68 -0
- package/dist/auth-status-reporter.d.ts +112 -0
- package/dist/auth-status-reporter.d.ts.map +1 -0
- package/dist/auth-status-reporter.js +253 -0
- package/dist/background-work.d.ts +12 -265
- package/dist/background-work.d.ts.map +1 -1
- package/dist/background-work.js +8 -558
- package/dist/client-system-prompt.d.ts +7 -0
- package/dist/client-system-prompt.d.ts.map +1 -1
- package/dist/client-system-prompt.js +24 -0
- package/dist/context-compaction.d.ts +20 -0
- package/dist/context-compaction.d.ts.map +1 -1
- package/dist/context-compaction.js +26 -0
- package/dist/context-window.d.ts +70 -0
- package/dist/context-window.d.ts.map +1 -0
- package/dist/context-window.js +132 -0
- package/dist/diff.d.ts +1 -1
- package/dist/diff.js +1 -1
- package/dist/elicitation.d.ts +66 -1
- package/dist/elicitation.d.ts.map +1 -1
- package/dist/elicitation.js +109 -0
- package/dist/file-change-audit.d.ts +4 -3
- package/dist/file-change-audit.d.ts.map +1 -1
- package/dist/file-change-audit.js +3 -2
- package/dist/mcp-oauth.d.ts +44 -0
- package/dist/mcp-oauth.d.ts.map +1 -0
- package/dist/mcp-oauth.js +142 -0
- package/dist/mcp-servers.d.ts +10 -0
- package/dist/mcp-servers.d.ts.map +1 -0
- package/dist/mcp-servers.js +29 -0
- package/dist/native-subagents.d.ts +18 -8
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +7 -35
- package/dist/permissions/presentation.d.ts +29 -0
- package/dist/permissions/presentation.d.ts.map +1 -1
- package/dist/permissions/presentation.js +38 -11
- package/dist/prompt-suggestions.d.ts +29 -0
- package/dist/prompt-suggestions.d.ts.map +1 -1
- package/dist/prompt-suggestions.js +45 -0
- package/dist/providers.d.ts +139 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +286 -0
- package/dist/remote-control.d.ts +62 -0
- package/dist/remote-control.d.ts.map +1 -0
- package/dist/remote-control.js +78 -0
- package/dist/result-end.d.ts +39 -0
- package/dist/result-end.d.ts.map +1 -0
- package/dist/result-end.js +50 -0
- package/dist/serve.d.ts +7 -2
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +10 -5
- package/dist/session-config-ids.d.ts +1 -0
- package/dist/session-config-ids.d.ts.map +1 -1
- package/dist/session-config-ids.js +1 -0
- package/dist/session-config-options.d.ts +64 -0
- package/dist/session-config-options.d.ts.map +1 -0
- package/dist/session-config-options.js +162 -0
- package/dist/session-effort.d.ts +67 -0
- package/dist/session-effort.d.ts.map +1 -1
- package/dist/session-effort.js +98 -0
- package/dist/session-env.d.ts +22 -0
- package/dist/session-env.d.ts.map +1 -0
- package/dist/session-env.js +66 -0
- package/dist/session-fast-mode.d.ts +83 -0
- package/dist/session-fast-mode.d.ts.map +1 -0
- package/dist/session-fast-mode.js +142 -0
- package/dist/session-index/connection.d.ts +2 -5
- package/dist/session-index/connection.d.ts.map +1 -1
- package/dist/session-index/connection.js +3 -5
- package/dist/session-mode.d.ts +1 -0
- package/dist/session-mode.d.ts.map +1 -1
- package/dist/session-mode.js +1 -1
- package/dist/session-model.d.ts +41 -0
- package/dist/session-model.d.ts.map +1 -1
- package/dist/session-model.js +110 -45
- package/dist/session-notices.d.ts +44 -0
- package/dist/session-notices.d.ts.map +1 -1
- package/dist/session-notices.js +68 -0
- package/dist/session-titles.d.ts +34 -12
- package/dist/session-titles.d.ts.map +1 -1
- package/dist/session-titles.js +7 -6
- package/dist/session-usage.d.ts +125 -0
- package/dist/session-usage.d.ts.map +1 -0
- package/dist/session-usage.js +196 -0
- package/dist/streamed-text.d.ts +33 -0
- package/dist/streamed-text.d.ts.map +1 -0
- package/dist/streamed-text.js +71 -0
- package/dist/subagent-configuration.d.ts +32 -0
- package/dist/subagent-configuration.d.ts.map +1 -0
- package/dist/subagent-configuration.js +70 -0
- package/dist/subagent-replay.d.ts +18 -0
- package/dist/subagent-replay.d.ts.map +1 -1
- package/dist/subagent-replay.js +25 -15
- package/dist/tool-calls/client-capabilities.d.ts +8 -8
- package/dist/tool-calls/client-capabilities.js +4 -4
- package/dist/tool-calls/renderer.d.ts +4 -5
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +4 -5
- package/dist/turn-events.d.ts +6 -46
- package/dist/turn-events.d.ts.map +1 -1
- package/dist/v2/agent.d.ts +7 -11
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +751 -331
- package/dist/v2/air.d.ts +33 -0
- package/dist/v2/air.d.ts.map +1 -0
- package/dist/v2/air.js +29 -0
- package/dist/v2/auth.d.ts +97 -0
- package/dist/v2/auth.d.ts.map +1 -0
- package/dist/v2/auth.js +216 -0
- package/dist/v2/background.d.ts +27 -16
- package/dist/v2/background.d.ts.map +1 -1
- package/dist/v2/background.js +4 -32
- package/dist/v2/child-config.d.ts +55 -0
- package/dist/v2/child-config.d.ts.map +1 -0
- package/dist/v2/child-config.js +92 -0
- package/dist/v2/clear-context.d.ts +94 -0
- package/dist/v2/clear-context.d.ts.map +1 -0
- package/dist/v2/clear-context.js +176 -0
- package/dist/v2/commands.d.ts +46 -0
- package/dist/v2/commands.d.ts.map +1 -0
- package/dist/v2/commands.js +54 -0
- package/dist/v2/config.d.ts +187 -0
- package/dist/v2/config.d.ts.map +1 -0
- package/dist/v2/config.js +494 -0
- package/dist/v2/elicitation.d.ts +93 -0
- package/dist/v2/elicitation.d.ts.map +1 -0
- package/dist/v2/elicitation.js +160 -0
- package/dist/v2/file-changes.d.ts +61 -0
- package/dist/v2/file-changes.d.ts.map +1 -0
- package/dist/v2/file-changes.js +108 -0
- package/dist/v2/file-preview.d.ts +18 -0
- package/dist/v2/file-preview.d.ts.map +1 -0
- package/dist/v2/file-preview.js +29 -0
- package/dist/v2/initialize.d.ts +10 -24
- package/dist/v2/initialize.d.ts.map +1 -1
- package/dist/v2/initialize.js +4 -111
- package/dist/v2/outcome.d.ts +81 -0
- package/dist/v2/outcome.d.ts.map +1 -0
- package/dist/v2/outcome.js +165 -0
- package/dist/v2/permissions.d.ts +92 -0
- package/dist/v2/permissions.d.ts.map +1 -0
- package/dist/v2/permissions.js +162 -0
- package/dist/v2/prompt.d.ts +2 -42
- package/dist/v2/prompt.d.ts.map +1 -1
- package/dist/v2/prompt.js +2 -119
- package/dist/v2/remote-control.d.ts +41 -0
- package/dist/v2/remote-control.d.ts.map +1 -0
- package/dist/v2/remote-control.js +63 -0
- package/dist/v2/reports.d.ts +198 -0
- package/dist/v2/reports.d.ts.map +1 -0
- package/dist/v2/reports.js +487 -0
- package/dist/v2/restarts.d.ts +128 -0
- package/dist/v2/restarts.d.ts.map +1 -0
- package/dist/v2/restarts.js +348 -0
- package/dist/v2/session-requests.d.ts +20 -0
- package/dist/v2/session-requests.d.ts.map +1 -0
- package/dist/v2/session-requests.js +108 -0
- package/dist/v2/session-update.d.ts +2 -13
- package/dist/v2/session-update.d.ts.map +1 -1
- package/dist/v2/session-update.js +2 -22
- package/dist/v2/session.d.ts +340 -41
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +1223 -141
- package/dist/v2/setup.d.ts +49 -0
- package/dist/v2/setup.d.ts.map +1 -0
- package/dist/v2/setup.js +62 -0
- package/dist/v2/stopped-work.d.ts +123 -0
- package/dist/v2/stopped-work.d.ts.map +1 -0
- package/dist/v2/stopped-work.js +210 -0
- package/dist/v2/stream.d.ts +228 -0
- package/dist/v2/stream.d.ts.map +1 -0
- package/dist/v2/stream.js +506 -0
- package/dist/v2/subagent-replay.d.ts +115 -0
- package/dist/v2/subagent-replay.d.ts.map +1 -0
- package/dist/v2/subagent-replay.js +479 -0
- package/dist/v2/subscription-guard.d.ts +60 -0
- package/dist/v2/subscription-guard.d.ts.map +1 -0
- package/dist/v2/subscription-guard.js +84 -0
- package/dist/v2/tasks.d.ts +492 -0
- package/dist/v2/tasks.d.ts.map +1 -0
- package/dist/v2/tasks.js +1728 -0
- package/dist/v2/terminal.d.ts.map +1 -1
- package/dist/v2/terminal.js +6 -1
- package/dist/v2/tool-call.d.ts +3 -2
- package/dist/v2/tool-call.d.ts.map +1 -1
- package/dist/v2/update-translator.d.ts +36 -0
- package/dist/v2/update-translator.d.ts.map +1 -0
- package/dist/v2/update-translator.js +80 -0
- package/dist/workflow-progress.d.ts +23 -0
- package/dist/workflow-progress.d.ts.map +1 -1
- package/dist/workflow-progress.js +31 -8
- package/package.json +1 -1
- package/dist/v2/permission.d.ts +0 -28
- package/dist/v2/permission.d.ts.map +0 -1
- package/dist/v2/permission.js +0 -41
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How Claude Code's `result` ends the work that it reports: the rules that
|
|
3
|
+
* both cores read a turn's result with (the v1 prompt loop in `acp-agent.ts`
|
|
4
|
+
* and `v2/outcome.ts`). Each core adds its own side effects, such as v1's
|
|
5
|
+
* session failure category.
|
|
6
|
+
*/
|
|
7
|
+
import type { SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
8
|
+
export type ResultEnd = {
|
|
9
|
+
stopReason: "refusal" | "max_tokens" | "end_turn" | "max_turn_requests";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The result failed the work, with Claude Code's error text. `loginRequired`:
|
|
13
|
+
* the text of a `success` result tells the user to run `/login`.
|
|
14
|
+
*/
|
|
15
|
+
| {
|
|
16
|
+
error: string;
|
|
17
|
+
loginRequired: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* True when CLI error text tells the user to sign in with `/login`. The CLI
|
|
21
|
+
* words this several ways — "Not logged in · Please run /login", "Not logged
|
|
22
|
+
* in · Run /login", "Login expired · Run /login to sign in again, or
|
|
23
|
+
* re-authenticate your Anthropic profile" — so match the "run /login"
|
|
24
|
+
* instruction rather than one sentence.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isLoginRequiredText(text: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* - Any subtype with `stop_reason: "refusal"`: `refusal`, also on an error.
|
|
29
|
+
* - `success`: an error with the `/login` text fails the work, then
|
|
30
|
+
* `stop_reason: "max_tokens"` is `max_tokens`, then any other error fails
|
|
31
|
+
* the work. Otherwise `end_turn`.
|
|
32
|
+
* - `error_during_execution`: `max_tokens` as for `success`, then an error
|
|
33
|
+
* fails the work. Otherwise `end_turn`.
|
|
34
|
+
* - `error_max_turns`, `error_max_budget_usd` and
|
|
35
|
+
* `error_max_structured_output_retries`: an error fails the work, whatever
|
|
36
|
+
* the stop reason. Otherwise `max_turn_requests`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resultEnd(result: SDKResultMessage): ResultEnd;
|
|
39
|
+
//# 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;;;;;GAKG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,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"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
}
|