@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
package/dist/v2/air.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JetBrains AIR extensions (`docs/air-extensions.md`) that the v2
|
|
3
|
+
* core serves, and their negotiation. Only a client that declares
|
|
4
|
+
* `_meta.jetbrains.air` in `initialize` gets them, with the wire output that
|
|
5
|
+
* the v1 core gives AIR. The extensions that ACP v2 covers on its own are
|
|
6
|
+
* not served (see "ACP v2" in docs/air-extensions.md).
|
|
7
|
+
*/
|
|
8
|
+
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
9
|
+
/** What the connection's client takes of the AIR extensions. */
|
|
10
|
+
export interface AirSupport {
|
|
11
|
+
/**
|
|
12
|
+
* The client is AIR. It gets the permission presentation, the AIR
|
|
13
|
+
* permission tool call `_meta`, AskUserQuestion's custom answer marker and
|
|
14
|
+
* the predicted follow-up prompt.
|
|
15
|
+
*/
|
|
16
|
+
readonly client: boolean;
|
|
17
|
+
/** `recommendedValue`: concrete model and effort rows with a recommendation. */
|
|
18
|
+
readonly recommendedValue: boolean;
|
|
19
|
+
/** `agentFileChangeReport`: the changed files of a prompt's turn. */
|
|
20
|
+
readonly fileChangeReport: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** A client that is not AIR. */
|
|
23
|
+
export declare const NO_AIR: AirSupport;
|
|
24
|
+
/** What the client declared in `initialize`. */
|
|
25
|
+
export declare function airSupport(capabilities: v2.ClientCapabilities | null | undefined): AirSupport;
|
|
26
|
+
/**
|
|
27
|
+
* The `initialize` response `_meta` of an AIR client: the capabilities this
|
|
28
|
+
* core serves, which the v1 core advertises too. `loadReplayEnd` is served
|
|
29
|
+
* (see `setup.ts`) but not listed: the client declares it, and the agent does
|
|
30
|
+
* not advertise it. Undefined for every other client.
|
|
31
|
+
*/
|
|
32
|
+
export declare function airInitializeMeta(air: AirSupport): Record<string, unknown> | undefined;
|
|
33
|
+
//# sourceMappingURL=air.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"air.d.ts","sourceRoot":"","sources":["../../src/v2/air.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAY7E,gEAAgE;AAChE,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,gFAAgF;IAChF,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,qEAAqE;IACrE,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAED,gCAAgC;AAChC,eAAO,MAAM,MAAM,EAAE,UAIpB,CAAC;AAEF,gDAAgD;AAChD,wBAAgB,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,CAU7F;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAMtF"}
|
package/dist/v2/air.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, airCapabilityMeta, clientSupportsAirCapability, isAirClient, } from "../air-extension.js";
|
|
2
|
+
import { AGENT_FILE_CHANGE_REPORT_CAPABILITY, supportsAgentFileChangeReport, } from "../file-change-audit.js";
|
|
3
|
+
/** A client that is not AIR. */
|
|
4
|
+
export const NO_AIR = {
|
|
5
|
+
client: false,
|
|
6
|
+
recommendedValue: false,
|
|
7
|
+
fileChangeReport: false,
|
|
8
|
+
};
|
|
9
|
+
/** What the client declared in `initialize`. */
|
|
10
|
+
export function airSupport(capabilities) {
|
|
11
|
+
if (!isAirClient(capabilities))
|
|
12
|
+
return NO_AIR;
|
|
13
|
+
return {
|
|
14
|
+
client: true,
|
|
15
|
+
recommendedValue: clientSupportsAirCapability(capabilities, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY),
|
|
16
|
+
fileChangeReport: supportsAgentFileChangeReport(capabilities),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The `initialize` response `_meta` of an AIR client: the capabilities this
|
|
21
|
+
* core serves, which the v1 core advertises too. `loadReplayEnd` is served
|
|
22
|
+
* (see `setup.ts`) but not listed: the client declares it, and the agent does
|
|
23
|
+
* not advertise it. Undefined for every other client.
|
|
24
|
+
*/
|
|
25
|
+
export function airInitializeMeta(air) {
|
|
26
|
+
if (!air.client)
|
|
27
|
+
return undefined;
|
|
28
|
+
return airCapabilityMeta(AGENT_FILE_CHANGE_REPORT_CAPABILITY, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY);
|
|
29
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
2
|
+
import type { AccountInfo, ModelInfo, Settings } from "@anthropic-ai/claude-agent-sdk";
|
|
3
|
+
import type { AuthStatusKind } from "../auth-status.js";
|
|
4
|
+
import type { Logger } from "../acp-agent.js";
|
|
5
|
+
import { type AuthStatusSettings } from "../auth-status-reporter.js";
|
|
6
|
+
/** The route of a session that starts now. */
|
|
7
|
+
export interface SessionRouting {
|
|
8
|
+
/** Added to the query's env. Empty without a gateway login or a provider. */
|
|
9
|
+
env: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* The programmatic settings of the query, with the route's env too: Claude
|
|
12
|
+
* Code applies the env of settings.json after the process env, so user or
|
|
13
|
+
* project settings could restore another `ANTHROPIC_BASE_URL` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
settings?: Settings;
|
|
16
|
+
/** The models the session offers: those the provider's gateway listed. */
|
|
17
|
+
models(models: ModelInfo[]): ModelInfo[];
|
|
18
|
+
/** Whether {@link models} narrows the models to a gateway's list. */
|
|
19
|
+
narrowsModels: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** What the auth state tells the rest of the core. */
|
|
22
|
+
export interface AuthEvents {
|
|
23
|
+
/**
|
|
24
|
+
* The route of live sessions changed: resolves once the sessions at a turn
|
|
25
|
+
* boundary restarted (see `SessionRestarts.reroute`).
|
|
26
|
+
*/
|
|
27
|
+
routeChanged(): Promise<void>;
|
|
28
|
+
/** An auth status probe read the identity `kind`. */
|
|
29
|
+
probed(kind: AuthStatusKind): void;
|
|
30
|
+
}
|
|
31
|
+
export declare class V2Auth {
|
|
32
|
+
private readonly logger;
|
|
33
|
+
private readonly events;
|
|
34
|
+
private gatewayLogin?;
|
|
35
|
+
private provider?;
|
|
36
|
+
/** Runs `providers/set` and `providers/disable` one at a time, in arrival order. */
|
|
37
|
+
private providerUpdate;
|
|
38
|
+
/** How many of {@link providerUpdate} have not settled. */
|
|
39
|
+
private providerUpdates;
|
|
40
|
+
/** The settings of each live session, for the probe at the start of its prompts. */
|
|
41
|
+
private readonly sessionSettings;
|
|
42
|
+
private readonly status;
|
|
43
|
+
/**
|
|
44
|
+
* Counts the route changes that restarted the live sessions. A session
|
|
45
|
+
* whose start read {@link routing} before one is not live yet then, so it
|
|
46
|
+
* restarts once its setup answered (see `SessionRestarts.track`).
|
|
47
|
+
*/
|
|
48
|
+
private routeChanges;
|
|
49
|
+
constructor(ctx: v2.AgentContext, logger: Logger, events: AuthEvents);
|
|
50
|
+
/**
|
|
51
|
+
* The auth fields of the `initialize` response. It starts the probe, which
|
|
52
|
+
* nothing waits for: its push goes out after the response.
|
|
53
|
+
*/
|
|
54
|
+
initialize(capabilities: v2.ClientCapabilities | null | undefined): {
|
|
55
|
+
authMethods: v2.AuthMethod[];
|
|
56
|
+
_meta: {
|
|
57
|
+
authStatus: Record<string, never>;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/** `auth/login`: a gateway login. The terminal logins are the client's to run. */
|
|
61
|
+
login(params: v2.LoginAuthRequest): v2.LoginAuthResponse;
|
|
62
|
+
/**
|
|
63
|
+
* `auth/logout`: drops the gateway login and the provider, runs `claude auth
|
|
64
|
+
* logout`, and reports the identity that remains (an API key from the env
|
|
65
|
+
* survives it).
|
|
66
|
+
*/
|
|
67
|
+
logout(): Promise<v2.LogoutAuthResponse>;
|
|
68
|
+
listProviders(): v2.ListProvidersResponse;
|
|
69
|
+
setProvider(params: v2.SetProviderRequest): Promise<v2.SetProviderResponse>;
|
|
70
|
+
disableProvider(params: v2.DisableProviderRequest): Promise<v2.DisableProviderResponse>;
|
|
71
|
+
/** Whether a provider or a gateway login routes the traffic, rather than the CLI's own login. */
|
|
72
|
+
overridesRoute(): boolean;
|
|
73
|
+
/** The number of route changes so far: read it right before {@link routing}. */
|
|
74
|
+
get routeGeneration(): number;
|
|
75
|
+
/** The route changed: restarts the live sessions (see `SessionRestarts.reroute`). */
|
|
76
|
+
private rerouted;
|
|
77
|
+
/** Settles once the provider changes that came so far have applied. */
|
|
78
|
+
routeSettled(): Promise<void>;
|
|
79
|
+
/** The route of a session that starts now: the provider, else the gateway login. */
|
|
80
|
+
routing(): SessionRouting;
|
|
81
|
+
/**
|
|
82
|
+
* A session starts under `settings`: probes run in them from now on. Call
|
|
83
|
+
* the result with the session's account once Claude Code reports it. It
|
|
84
|
+
* reports nothing when a login or a logout came in between.
|
|
85
|
+
*/
|
|
86
|
+
sessionStarting(settings: AuthStatusSettings): (sessionId: string, account: AccountInfo | undefined) => void;
|
|
87
|
+
/**
|
|
88
|
+
* A prompt of `sessionId` starts: reads the identity again, without waiting.
|
|
89
|
+
* This finds a login or a logout done in another terminal.
|
|
90
|
+
*/
|
|
91
|
+
promptStarted(sessionId: string): void;
|
|
92
|
+
/** Reports the account that the query of `sessionId` cached, as the identity. */
|
|
93
|
+
publishAccount(sessionId: string, account: AccountInfo): void;
|
|
94
|
+
sessionEnded(sessionId: string): void;
|
|
95
|
+
private updateProvider;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/v2/auth.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,OAAO,EAAiC,KAAK,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAmBpG,8CAA8C;AAC9C,MAAM,WAAW,cAAc;IAC7B,6EAA6E;IAC7E,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,0EAA0E;IAC1E,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC;IACzC,qE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C,EAAE,CAAC,mBAAmB,CAAC;IAS3E,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,sBAAsB,GAAG,OAAO,CAAC,EAAE,CAAC,uBAAuB,CAAC;IAW7F,iGAAiG;IACjG,cAAc,IAAI,OAAO;IAIzB,gFAAgF;IAChF,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,qFAAqF;IACrF,OAAO,CAAC,QAAQ;IAOhB,uEAAuE;IACjE,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC,oFAAoF;IACpF,OAAO,IAAI,cAAc;IAczB;;;;OAIG;IACH,eAAe,CACb,QAAQ,EAAE,kBAAkB,GAC3B,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,SAAS,KAAK,IAAI;IAWhE;;;OAGG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAMtC,iFAAiF;IACjF,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAO7D,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIrC,OAAO,CAAC,cAAc;CAUvB"}
|
package/dist/v2/auth.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection's auth and LLM routing on the v2 core: the `authStatus`
|
|
3
|
+
* extension (`_meta.authStatus` and `_auth/status_update`), the gateway logins
|
|
4
|
+
* of `auth/login`, `auth/logout`, and `providers/list|set|disable`.
|
|
5
|
+
*
|
|
6
|
+
* The state and its rules are the v1 core's (`AuthStatusReporter`,
|
|
7
|
+
* `providers.ts`). The identity is read at the same moments as there: after
|
|
8
|
+
* `initialize`, from each session's account, after a login or a logout, and at
|
|
9
|
+
* the start of each prompt (see `auth-status.ts`).
|
|
10
|
+
*
|
|
11
|
+
* A gateway login routes the sessions started after it.
|
|
12
|
+
* `providers/set`, `providers/disable`, and a logout that drops a provider or
|
|
13
|
+
* a gateway login also route the live sessions: each one's query restarts at
|
|
14
|
+
* its next turn boundary (see `restarts.ts`). The request answers once the
|
|
15
|
+
* sessions at a turn boundary restarted, and does not wait for the busy ones.
|
|
16
|
+
*/
|
|
17
|
+
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
18
|
+
import { terminalAuthMethods } from "../auth-methods.js";
|
|
19
|
+
import { AUTH_STATUS_UPDATE_METHOD, authStatusCapability, gatewayAuthStatus, notLoggedInAuthStatus, } from "../auth-status.js";
|
|
20
|
+
import { AuthStatusReporter, cliLogout } from "../auth-status-reporter.js";
|
|
21
|
+
import { clearContextWindowCache } from "../context-window.js";
|
|
22
|
+
import { createEnvForProvider, defaultProviderConfig, gatewayAuthMethods, gatewayRequestToProviderConfig, isGatewayAuthMethod, listProvidersResponse, PROVIDER_ID, providerConfigFromSetRequest, validatedGatewayAuthRequest, withListedModels, } from "../providers.js";
|
|
23
|
+
import { narrowToGatewayModels } from "../session-model.js";
|
|
24
|
+
import { v2AuthMethod } from "./initialize.js";
|
|
25
|
+
export class V2Auth {
|
|
26
|
+
logger;
|
|
27
|
+
events;
|
|
28
|
+
gatewayLogin;
|
|
29
|
+
provider;
|
|
30
|
+
/** Runs `providers/set` and `providers/disable` one at a time, in arrival order. */
|
|
31
|
+
providerUpdate = Promise.resolve();
|
|
32
|
+
/** How many of {@link providerUpdate} have not settled. */
|
|
33
|
+
providerUpdates = 0;
|
|
34
|
+
/** The settings of each live session, for the probe at the start of its prompts. */
|
|
35
|
+
sessionSettings = new Map();
|
|
36
|
+
status;
|
|
37
|
+
/**
|
|
38
|
+
* Counts the route changes that restarted the live sessions. A session
|
|
39
|
+
* whose start read {@link routing} before one is not live yet then, so it
|
|
40
|
+
* restarts once its setup answered (see `SessionRestarts.track`).
|
|
41
|
+
*/
|
|
42
|
+
routeChanges = 0;
|
|
43
|
+
constructor(ctx, logger, events) {
|
|
44
|
+
this.logger = logger;
|
|
45
|
+
this.events = events;
|
|
46
|
+
this.status = new AuthStatusReporter({
|
|
47
|
+
push: (authStatus) => ctx.notify(AUTH_STATUS_UPDATE_METHOD, { authStatus }),
|
|
48
|
+
logger,
|
|
49
|
+
gatewayLogin: () => this.gatewayLogin !== undefined,
|
|
50
|
+
providerOverride: () => this.provider !== undefined,
|
|
51
|
+
onProbe: (kind) => events.probed(kind),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The auth fields of the `initialize` response. It starts the probe, which
|
|
56
|
+
* nothing waits for: its push goes out after the response.
|
|
57
|
+
*/
|
|
58
|
+
initialize(capabilities) {
|
|
59
|
+
void this.status.probe();
|
|
60
|
+
return {
|
|
61
|
+
authMethods: [
|
|
62
|
+
// v2 advertises terminal logins only to a client with `auth.terminal`.
|
|
63
|
+
...(capabilities?.auth?.terminal != null
|
|
64
|
+
? terminalAuthMethods({ terminal: true, metaTerminal: false })
|
|
65
|
+
: []),
|
|
66
|
+
// Only offered when the client advertises `auth._meta.gateway`.
|
|
67
|
+
...(capabilities?.auth?._meta?.gateway === true ? gatewayAuthMethods() : []),
|
|
68
|
+
].map(v2AuthMethod),
|
|
69
|
+
// The `authStatus` marker: this agent pushes its identity.
|
|
70
|
+
_meta: { authStatus: authStatusCapability() },
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** `auth/login`: a gateway login. The terminal logins are the client's to run. */
|
|
74
|
+
login(params) {
|
|
75
|
+
if (!isGatewayAuthMethod(params.methodId)) {
|
|
76
|
+
const terminal = terminalAuthMethods({ terminal: true, metaTerminal: false });
|
|
77
|
+
if (terminal.some((method) => method.id === params.methodId)) {
|
|
78
|
+
throw RequestError.invalidParams({ methodId: params.methodId }, `${params.methodId} is a terminal login: run it in a terminal, then retry the request`);
|
|
79
|
+
}
|
|
80
|
+
throw RequestError.invalidParams({ methodId: params.methodId }, `Unsupported authentication method: ${params.methodId}`);
|
|
81
|
+
}
|
|
82
|
+
this.gatewayLogin = validatedGatewayAuthRequest(params);
|
|
83
|
+
// The gateway holds the credentials from here on. A probe that started
|
|
84
|
+
// before this login is stale.
|
|
85
|
+
this.status.changed();
|
|
86
|
+
this.status.set(gatewayAuthStatus(gatewayRequestToProviderConfig(this.gatewayLogin)?.baseUrl));
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* `auth/logout`: drops the gateway login and the provider, runs `claude auth
|
|
91
|
+
* logout`, and reports the identity that remains (an API key from the env
|
|
92
|
+
* survives it).
|
|
93
|
+
*/
|
|
94
|
+
async logout() {
|
|
95
|
+
// A `providers/set` that is still listing would set a provider too.
|
|
96
|
+
const routed = this.overridesRoute() || this.providerUpdates > 0;
|
|
97
|
+
this.gatewayLogin = undefined;
|
|
98
|
+
this.status.changed();
|
|
99
|
+
await this.updateProvider(async () => {
|
|
100
|
+
this.provider = undefined;
|
|
101
|
+
});
|
|
102
|
+
// The windows learned under this login must not seed sessions under the next.
|
|
103
|
+
clearContextWindowCache();
|
|
104
|
+
try {
|
|
105
|
+
await cliLogout();
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
// The live sessions leave the dropped route, also when the CLI logout
|
|
109
|
+
// failed. A plain CLI login needs no restart: the running CLI picks up
|
|
110
|
+
// the logout by itself.
|
|
111
|
+
if (routed)
|
|
112
|
+
await this.rerouted();
|
|
113
|
+
}
|
|
114
|
+
// The read starts after the credentials were cleared, so it does not join
|
|
115
|
+
// a probe in flight. If it cannot read them, the logout still happened.
|
|
116
|
+
if (!(await this.status.probe({ fresh: true }))) {
|
|
117
|
+
this.status.set(notLoggedInAuthStatus());
|
|
118
|
+
}
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
listProviders() {
|
|
122
|
+
return listProvidersResponse(this.provider ?? defaultProviderConfig(this.gatewayLogin));
|
|
123
|
+
}
|
|
124
|
+
async setProvider(params) {
|
|
125
|
+
const config = providerConfigFromSetRequest(params);
|
|
126
|
+
await this.updateProvider(async () => {
|
|
127
|
+
this.provider = await withListedModels(config, this.provider, this.logger);
|
|
128
|
+
});
|
|
129
|
+
await this.rerouted();
|
|
130
|
+
return {};
|
|
131
|
+
}
|
|
132
|
+
async disableProvider(params) {
|
|
133
|
+
// An unknown provider: idempotent success.
|
|
134
|
+
if (params.providerId === PROVIDER_ID) {
|
|
135
|
+
await this.updateProvider(async () => {
|
|
136
|
+
this.provider = undefined;
|
|
137
|
+
});
|
|
138
|
+
await this.rerouted();
|
|
139
|
+
}
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
/** Whether a provider or a gateway login routes the traffic, rather than the CLI's own login. */
|
|
143
|
+
overridesRoute() {
|
|
144
|
+
return (this.provider ?? gatewayRequestToProviderConfig(this.gatewayLogin)) != null;
|
|
145
|
+
}
|
|
146
|
+
/** The number of route changes so far: read it right before {@link routing}. */
|
|
147
|
+
get routeGeneration() {
|
|
148
|
+
return this.routeChanges;
|
|
149
|
+
}
|
|
150
|
+
/** The route changed: restarts the live sessions (see `SessionRestarts.reroute`). */
|
|
151
|
+
rerouted() {
|
|
152
|
+
// In the same call as the reroute's look at the live sessions: a session
|
|
153
|
+
// either is among them or sees the new count when it is tracked.
|
|
154
|
+
this.routeChanges++;
|
|
155
|
+
return this.events.routeChanged();
|
|
156
|
+
}
|
|
157
|
+
/** Settles once the provider changes that came so far have applied. */
|
|
158
|
+
async routeSettled() {
|
|
159
|
+
await this.providerUpdate.catch(() => undefined);
|
|
160
|
+
}
|
|
161
|
+
/** The route of a session that starts now: the provider, else the gateway login. */
|
|
162
|
+
routing() {
|
|
163
|
+
const config = this.provider ?? gatewayRequestToProviderConfig(this.gatewayLogin);
|
|
164
|
+
const env = createEnvForProvider(config);
|
|
165
|
+
return {
|
|
166
|
+
env,
|
|
167
|
+
...(config ? { settings: { apiKeyHelper: "", env } } : {}),
|
|
168
|
+
models: (models) => config?.listedModels
|
|
169
|
+
? narrowToGatewayModels(models, config.listedModels, config.bedrockRegionPrefix)
|
|
170
|
+
: models,
|
|
171
|
+
narrowsModels: config?.listedModels !== undefined,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A session starts under `settings`: probes run in them from now on. Call
|
|
176
|
+
* the result with the session's account once Claude Code reports it. It
|
|
177
|
+
* reports nothing when a login or a logout came in between.
|
|
178
|
+
*/
|
|
179
|
+
sessionStarting(settings) {
|
|
180
|
+
this.status.useSettings(settings);
|
|
181
|
+
const epoch = this.status.epoch;
|
|
182
|
+
return (sessionId, account) => {
|
|
183
|
+
this.sessionSettings.set(sessionId, settings);
|
|
184
|
+
if (epoch === this.status.epoch) {
|
|
185
|
+
this.status.publishSessionAccount(account, settings.getApiKeyHelper());
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* A prompt of `sessionId` starts: reads the identity again, without waiting.
|
|
191
|
+
* This finds a login or a logout done in another terminal.
|
|
192
|
+
*/
|
|
193
|
+
promptStarted(sessionId) {
|
|
194
|
+
const settings = this.sessionSettings.get(sessionId);
|
|
195
|
+
if (settings)
|
|
196
|
+
this.status.useSettings(settings);
|
|
197
|
+
void this.status.probe();
|
|
198
|
+
}
|
|
199
|
+
/** Reports the account that the query of `sessionId` cached, as the identity. */
|
|
200
|
+
publishAccount(sessionId, account) {
|
|
201
|
+
this.status.publishSessionAccount(account, this.sessionSettings.get(sessionId)?.getApiKeyHelper());
|
|
202
|
+
}
|
|
203
|
+
sessionEnded(sessionId) {
|
|
204
|
+
this.sessionSettings.delete(sessionId);
|
|
205
|
+
}
|
|
206
|
+
updateProvider(update) {
|
|
207
|
+
const next = this.providerUpdate.catch(() => undefined).then(update);
|
|
208
|
+
this.providerUpdate = next;
|
|
209
|
+
this.providerUpdates++;
|
|
210
|
+
const settled = () => {
|
|
211
|
+
this.providerUpdates--;
|
|
212
|
+
};
|
|
213
|
+
next.then(settled, settled);
|
|
214
|
+
return next;
|
|
215
|
+
}
|
|
216
|
+
}
|
package/dist/v2/background.d.ts
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `background` lists of
|
|
3
|
-
* `
|
|
2
|
+
* The `background` lists of a v2 session and of its subagent sessions (see
|
|
3
|
+
* `tasks.ts`, which builds them).
|
|
4
4
|
*
|
|
5
5
|
* A session that reports its background work gets its list on every
|
|
6
|
-
* `state_update` of its own stream, as v2 requires, from the list the
|
|
6
|
+
* `state_update` of its own stream, as v2 requires, from the list the core
|
|
7
7
|
* reports when the session starts. A subagent session of such a session
|
|
8
8
|
* reports its own list from its announcement on, also in the parent's mirror
|
|
9
9
|
* of its state (`subagent_update.state`).
|
|
10
10
|
*/
|
|
11
11
|
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
12
|
-
import type { BackgroundReport, WorkStateName } from "../background-work.js";
|
|
13
12
|
import type { V2Terminals } from "./terminal.js";
|
|
13
|
+
/** An item of a `background` list. */
|
|
14
|
+
export type BackgroundItem = {
|
|
15
|
+
type: "terminal";
|
|
16
|
+
terminalId: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: "tool_call";
|
|
19
|
+
toolCallId: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "subagent";
|
|
22
|
+
sessionId: string;
|
|
23
|
+
};
|
|
24
|
+
/** The work state of a session, as its `state_update` names it. */
|
|
25
|
+
export type WorkStateName = "idle" | "running" | "requires_action" | "unknown";
|
|
26
|
+
/** A new list of the session `sessionId`, with what its repeated state needs. */
|
|
27
|
+
export interface BackgroundReport {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
items: BackgroundItem[];
|
|
30
|
+
/** The session's work state now, or undefined when it has none yet. */
|
|
31
|
+
state: WorkStateName | undefined;
|
|
32
|
+
/** The parent of a subagent session, which mirrors the child's state. */
|
|
33
|
+
parentSessionId?: string;
|
|
34
|
+
}
|
|
14
35
|
/** The `state_update` that reports `state` as the session's current work state. */
|
|
15
36
|
export declare function stateUpdate(state: WorkStateName): v2.SessionUpdate;
|
|
16
37
|
export declare class V2Background {
|
|
17
38
|
private readonly terminals;
|
|
18
|
-
/**
|
|
19
|
-
* The latest list of each session that reports one, whether a state of the
|
|
20
|
-
* session carried it, and the parent of a subagent session.
|
|
21
|
-
*/
|
|
39
|
+
/** The latest list of each session that reports one, and whether a state of the session carried it. */
|
|
22
40
|
private readonly sessions;
|
|
23
41
|
/**
|
|
24
42
|
* The tool calls that advertise `cancel`, by session and tool call. Like a
|
|
@@ -50,23 +68,16 @@ export declare class V2Background {
|
|
|
50
68
|
/**
|
|
51
69
|
* The current `terminal_update` of each terminal that the session
|
|
52
70
|
* `sessionId` lists, and the `cancel` capability of each tool call that it
|
|
53
|
-
* lists, whose other fields the
|
|
54
|
-
* `ClaudeAcpAgent.publishBackgroundToolCalls`). v2 requires them before the
|
|
71
|
+
* lists, whose other fields the core sends. v2 requires them before the
|
|
55
72
|
* state snapshot of `session/resume`, as a replay may not have delivered
|
|
56
73
|
* them.
|
|
57
74
|
*/
|
|
58
75
|
currentItems(sessionId: string): v2.UpdateSessionNotification[];
|
|
59
|
-
/** The tool calls that the session `sessionId` lists. */
|
|
60
|
-
listedToolCalls(sessionId: string): string[];
|
|
61
76
|
/**
|
|
62
77
|
* The update that lets the client cancel the listed terminal or tool call
|
|
63
78
|
* `item`, unless it advertises that already. `again` sends it anyway, as
|
|
64
79
|
* the item's current state.
|
|
65
80
|
*/
|
|
66
81
|
private advertiseCancel;
|
|
67
|
-
/** The subagent sessions that the session `sessionId` lists. */
|
|
68
|
-
listedSubagents(sessionId: string): string[];
|
|
69
|
-
/** Forgets the list of a session, and those of its subagent sessions. */
|
|
70
|
-
forget(sessionId: string): void;
|
|
71
82
|
}
|
|
72
83
|
//# sourceMappingURL=background.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../src/v2/background.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,
|
|
1
|
+
{"version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E,CAAC,yBAAyB,EAAE;IAqBjE;;;;;;OAMG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC,yBAAyB,EAAE;IAM/D;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAwBxB"}
|
package/dist/v2/background.js
CHANGED
|
@@ -20,10 +20,7 @@ function withBackground(state, background) {
|
|
|
20
20
|
const FINAL_STATUSES = new Set(["completed", "failed", "cancelled"]);
|
|
21
21
|
export class V2Background {
|
|
22
22
|
terminals;
|
|
23
|
-
/**
|
|
24
|
-
* The latest list of each session that reports one, whether a state of the
|
|
25
|
-
* session carried it, and the parent of a subagent session.
|
|
26
|
-
*/
|
|
23
|
+
/** The latest list of each session that reports one, and whether a state of the session carried it. */
|
|
27
24
|
sessions = new Map();
|
|
28
25
|
/**
|
|
29
26
|
* The tool calls that advertise `cancel`, by session and tool call. Like a
|
|
@@ -59,7 +56,7 @@ export class V2Background {
|
|
|
59
56
|
const subagent = update;
|
|
60
57
|
let child = this.sessions.get(subagent.sessionId);
|
|
61
58
|
if (!child) {
|
|
62
|
-
child = { items: [], reported: false
|
|
59
|
+
child = { items: [], reported: false };
|
|
63
60
|
this.sessions.set(subagent.sessionId, child);
|
|
64
61
|
}
|
|
65
62
|
if (subagent.state) {
|
|
@@ -87,11 +84,7 @@ export class V2Background {
|
|
|
87
84
|
const { sessionId, items, state, parentSessionId } = report;
|
|
88
85
|
const session = this.sessions.get(sessionId);
|
|
89
86
|
const unchanged = session && JSON.stringify(session.items) === JSON.stringify(items);
|
|
90
|
-
this.sessions.set(sessionId, {
|
|
91
|
-
items,
|
|
92
|
-
reported: session?.reported ?? false,
|
|
93
|
-
parent: parentSessionId ?? session?.parent,
|
|
94
|
-
});
|
|
87
|
+
this.sessions.set(sessionId, { items, reported: session?.reported ?? false });
|
|
95
88
|
const known = new Set((session?.items ?? []).map((item) => JSON.stringify(item)));
|
|
96
89
|
const updates = items.flatMap((item) => known.has(JSON.stringify(item)) ? [] : this.advertiseCancel(sessionId, item, false));
|
|
97
90
|
if (session?.reported && state && !unchanged) {
|
|
@@ -108,18 +101,13 @@ export class V2Background {
|
|
|
108
101
|
/**
|
|
109
102
|
* The current `terminal_update` of each terminal that the session
|
|
110
103
|
* `sessionId` lists, and the `cancel` capability of each tool call that it
|
|
111
|
-
* lists, whose other fields the
|
|
112
|
-
* `ClaudeAcpAgent.publishBackgroundToolCalls`). v2 requires them before the
|
|
104
|
+
* lists, whose other fields the core sends. v2 requires them before the
|
|
113
105
|
* state snapshot of `session/resume`, as a replay may not have delivered
|
|
114
106
|
* them.
|
|
115
107
|
*/
|
|
116
108
|
currentItems(sessionId) {
|
|
117
109
|
return (this.sessions.get(sessionId)?.items ?? []).flatMap((item) => this.advertiseCancel(sessionId, item, true));
|
|
118
110
|
}
|
|
119
|
-
/** The tool calls that the session `sessionId` lists. */
|
|
120
|
-
listedToolCalls(sessionId) {
|
|
121
|
-
return (this.sessions.get(sessionId)?.items ?? []).flatMap((item) => item.type === "tool_call" ? [item.toolCallId] : []);
|
|
122
|
-
}
|
|
123
111
|
/**
|
|
124
112
|
* The update that lets the client cancel the listed terminal or tool call
|
|
125
113
|
* `item`, unless it advertises that already. `again` sends it anyway, as
|
|
@@ -147,20 +135,4 @@ export class V2Background {
|
|
|
147
135
|
},
|
|
148
136
|
];
|
|
149
137
|
}
|
|
150
|
-
/** The subagent sessions that the session `sessionId` lists. */
|
|
151
|
-
listedSubagents(sessionId) {
|
|
152
|
-
return (this.sessions.get(sessionId)?.items ?? []).flatMap((item) => item.type === "subagent" ? [item.sessionId] : []);
|
|
153
|
-
}
|
|
154
|
-
/** Forgets the list of a session, and those of its subagent sessions. */
|
|
155
|
-
forget(sessionId) {
|
|
156
|
-
this.sessions.delete(sessionId);
|
|
157
|
-
for (const key of this.cancellableToolCalls) {
|
|
158
|
-
if (key.startsWith(`${sessionId} `))
|
|
159
|
-
this.cancellableToolCalls.delete(key);
|
|
160
|
-
}
|
|
161
|
-
for (const [child, { parent }] of this.sessions) {
|
|
162
|
-
if (parent === sessionId)
|
|
163
|
-
this.forget(child);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
138
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configuration of each child session, as the v1 core reports it
|
|
3
|
+
* (`NativeSubagentRuntime.reportConfiguration`): the options that the
|
|
4
|
+
* child's hooks report (its mode, model after a `PostModelSwitch`, effort and
|
|
5
|
+
* agent type, see `subagentHookOptions`) and the model of its responses. Each
|
|
6
|
+
* report merges into the child's options, by id, and the client gets all of
|
|
7
|
+
* them again when any changed, in `orderedSubagentConfiguration`'s order.
|
|
8
|
+
*
|
|
9
|
+
* A hook can come before the child's announcement: its options wait for it.
|
|
10
|
+
*/
|
|
11
|
+
import type { SessionConfigOption, SessionModeState } from "@agentclientprotocol/sdk/unstable";
|
|
12
|
+
import type { AgentInfo, HookCallbackMatcher, HookInput } from "@anthropic-ai/claude-agent-sdk";
|
|
13
|
+
import type { SubagentModels } from "../native-subagents.js";
|
|
14
|
+
/** What the configurations need of their root session. */
|
|
15
|
+
export interface ConfigurationHost {
|
|
16
|
+
/** The root's modes, for the name of a child's mode. */
|
|
17
|
+
modes(): SessionModeState["availableModes"];
|
|
18
|
+
/** The entries of the root's `model` option, for a child's `model`. */
|
|
19
|
+
models(): SubagentModels;
|
|
20
|
+
/** Whether `agentId` is an announced child session. */
|
|
21
|
+
announced(agentId: string): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class ChildConfigurations {
|
|
24
|
+
private readonly host;
|
|
25
|
+
/** Each child's options, by id, and the snapshot that the client last got. */
|
|
26
|
+
private readonly children;
|
|
27
|
+
/** The custom agents of the session, for the description of a child's agent type. */
|
|
28
|
+
private agents;
|
|
29
|
+
constructor(host: ConfigurationHost);
|
|
30
|
+
/** The session's custom agents, from Claude Code's initialization (see `customAgents`). */
|
|
31
|
+
configureAgents(agents: readonly AgentInfo[]): void;
|
|
32
|
+
/** The options that a hook of a subagent reports of it. */
|
|
33
|
+
hookOptions(input: HookInput): SessionConfigOption[];
|
|
34
|
+
/**
|
|
35
|
+
* Takes options of the child `agentId`. Those of a child that is not
|
|
36
|
+
* announced wait for it, for at most {@link MAX_PENDING_CHILDREN} children.
|
|
37
|
+
* Returns whether they were kept.
|
|
38
|
+
*/
|
|
39
|
+
take(agentId: string, options: SessionConfigOption[]): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The child's configuration to send, or undefined when the client holds it
|
|
42
|
+
* already. It counts as sent.
|
|
43
|
+
*/
|
|
44
|
+
unsent(agentId: string): SessionConfigOption[] | undefined;
|
|
45
|
+
/** The configuration that the client last got for the child `agentId`, if any. */
|
|
46
|
+
published(agentId: string): SessionConfigOption[] | undefined;
|
|
47
|
+
/** A child that stays unexposed: its options go nowhere. */
|
|
48
|
+
forget(agentId: string): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The hook that reports a subagent's hooks to `report`, for each hook event
|
|
52
|
+
* that reports them. The hook makes no decision.
|
|
53
|
+
*/
|
|
54
|
+
export declare function subagentHooks(report: (input: HookInput) => void): Record<"SubagentStart" | "SubagentStop" | "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "PostModelSwitch", HookCallbackMatcher>;
|
|
55
|
+
//# sourceMappingURL=child-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-config.d.ts","sourceRoot":"","sources":["../../src/v2/child-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM7D,0DAA0D;AAC1D,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,KAAK,IAAI,gBAA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