@zvada/agent-server 0.3.26 → 0.3.28
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/CHANGELOG.md +71 -0
- package/README.md +7 -5
- package/dist/client/client.js +27 -11
- package/dist/client/connection.js +35 -3
- package/dist/core/agents/acp/account.js +111 -0
- package/dist/core/agents/acp/acp-agent.js +247 -158
- package/dist/core/agents/acp/adapter.js +103 -34
- package/dist/core/agents/acp/client.js +169 -42
- package/dist/core/agents/acp/known-agents.js +12 -5
- package/dist/core/agents/acp/mappings.js +84 -20
- package/dist/core/agents/acp/models.js +59 -0
- package/dist/core/agents/acp/profile.js +36 -0
- package/dist/core/agents/acp/prompts.js +248 -0
- package/dist/core/agents/acp/requests.js +4 -4
- package/dist/core/agents/claude-code/approvals.js +1 -1
- package/dist/core/agents/claude-code/login.js +4 -1
- package/dist/core/agents/claude-code/session.js +38 -10
- package/dist/core/agents/claude-code/spawn.js +0 -26
- package/dist/core/agents/codex-app-server/client.js +12 -13
- package/dist/core/agents/codex-app-server/login.js +4 -1
- package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
- package/dist/core/agents/gemini/failures.js +133 -0
- package/dist/core/agents/gemini/login.js +173 -0
- package/dist/core/agents/gemini/profile.js +137 -0
- package/dist/core/agents/gemini/tools.js +91 -0
- package/dist/core/agents/login.js +8 -6
- package/dist/core/agents/scripted/scripted-agent.js +30 -3
- package/dist/core/agents/stderr-tail.js +5 -2
- package/dist/core/presets.js +17 -1
- package/dist/core/processes/native-processes.js +23 -1
- package/dist/core/provision/install-build.js +70 -26
- package/dist/core/provision/pins.js +5 -0
- package/dist/core/provision/provisioner.js +39 -16
- package/dist/core/provision/releases.js +39 -1
- package/dist/core/provision/tools.js +87 -28
- package/dist/core/runtime/agent-runtime.js +15 -5
- package/dist/core/runtime/event-processor.js +13 -8
- package/dist/core/runtime/origin-line.js +42 -0
- package/dist/core/runtime/request-broker.js +2 -1
- package/dist/core/runtime/steering.js +4 -3
- package/dist/core/runtime/turn.js +6 -4
- package/dist/operator/errors.js +97 -0
- package/dist/operator/index.js +10 -5
- package/dist/operator/mcp.js +7 -12
- package/dist/operator/operator.js +1431 -378
- package/dist/operator/refs.js +59 -0
- package/dist/operator/render.js +199 -94
- package/dist/operator/session-tools.js +88 -0
- package/dist/operator/types.js +30 -0
- package/dist/operator/view.js +82 -27
- package/dist/protocol/account.js +5 -1
- package/dist/protocol/auth.js +5 -1
- package/dist/protocol/config.js +12 -5
- package/dist/protocol/conversation.js +3 -0
- package/dist/protocol/credentials.js +9 -1
- package/dist/protocol/harness.js +9 -1
- package/dist/protocol/history.js +2 -1
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/lifecycle.js +19 -0
- package/dist/protocol/origin.js +39 -0
- package/dist/protocol/reduce.js +2 -0
- package/dist/protocol/wire.js +17 -0
- package/dist/server/bin.js +22 -7
- package/dist/server/install.js +6 -4
- package/dist/server/routes.js +15 -5
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +14 -2
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +2 -2
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/account.d.ts +55 -0
- package/dist/types/core/agents/acp/account.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts +28 -3
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +66 -4
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +53 -7
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/acp/models.d.ts +22 -0
- package/dist/types/core/agents/acp/models.d.ts.map +1 -0
- package/dist/types/core/agents/acp/profile.d.ts +92 -0
- package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
- package/dist/types/core/agents/acp/prompts.d.ts +108 -0
- package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +7 -1
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +2 -0
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/session.d.ts +3 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
- package/dist/types/core/agents/gemini/failures.d.ts +25 -0
- package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/login.d.ts +28 -0
- package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/profile.d.ts +30 -0
- package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/tools.d.ts +18 -0
- package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +15 -5
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
- package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
- package/dist/types/core/agents/stderr-tail.d.ts +1 -1
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +2 -2
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/native-processes.d.ts +6 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -1
- package/dist/types/core/provision/checksums.d.ts +7 -1
- package/dist/types/core/provision/checksums.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +32 -6
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/pins.d.ts +4 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +18 -7
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/releases.d.ts +2 -1
- package/dist/types/core/provision/releases.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +36 -7
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +2 -2
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/origin-line.d.ts +15 -0
- package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +1 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/steering.d.ts +7 -4
- package/dist/types/core/runtime/steering.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/operator/errors.d.ts +87 -0
- package/dist/types/operator/errors.d.ts.map +1 -0
- package/dist/types/operator/index.d.ts +10 -5
- package/dist/types/operator/index.d.ts.map +1 -1
- package/dist/types/operator/mcp.d.ts +1 -1
- package/dist/types/operator/mcp.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts +15 -197
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/refs.d.ts +25 -0
- package/dist/types/operator/refs.d.ts.map +1 -0
- package/dist/types/operator/render.d.ts +67 -22
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/operator/session-tools.d.ts +61 -0
- package/dist/types/operator/session-tools.d.ts.map +1 -0
- package/dist/types/operator/types.d.ts +442 -0
- package/dist/types/operator/types.d.ts.map +1 -0
- package/dist/types/operator/view.d.ts +19 -29
- package/dist/types/operator/view.d.ts.map +1 -1
- package/dist/types/protocol/account.d.ts +4 -2
- package/dist/types/protocol/account.d.ts.map +1 -1
- package/dist/types/protocol/auth.d.ts +10 -7
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +4 -3
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +22 -5
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +47 -6
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/credentials.d.ts +8 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +1 -1
- package/dist/types/protocol/harness.d.ts +5 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +1 -1
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/index.d.ts +1 -0
- package/dist/types/protocol/index.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +48 -10
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/origin.d.ts +49 -0
- package/dist/types/protocol/origin.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +78 -30
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +78 -12
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/install.d.ts +2 -1
- package/dist/types/server/install.d.ts.map +1 -1
- package/dist/types/server/routes.d.ts.map +1 -1
- package/docs/consuming.md +62 -121
- package/docs/deploy.md +17 -8
- package/docs/harnesses.md +166 -44
- package/docs/sync-history.md +2 -1
- package/package.json +1 -1
- package/src/client/client.ts +36 -9
- package/src/client/connection.ts +31 -1
- package/src/client/turns.ts +2 -1
- package/src/core/agents/acp/account.ts +158 -0
- package/src/core/agents/acp/acp-agent.ts +288 -178
- package/src/core/agents/acp/adapter.ts +126 -35
- package/src/core/agents/acp/client.ts +196 -49
- package/src/core/agents/acp/known-agents.ts +14 -5
- package/src/core/agents/acp/mappings.ts +112 -21
- package/src/core/agents/acp/models.ts +72 -0
- package/src/core/agents/acp/profile.ts +127 -0
- package/src/core/agents/acp/prompts.ts +287 -0
- package/src/core/agents/acp/requests.ts +16 -9
- package/src/core/agents/base.ts +2 -0
- package/src/core/agents/claude-code/approvals.ts +2 -2
- package/src/core/agents/claude-code/login.ts +4 -1
- package/src/core/agents/claude-code/session.ts +38 -8
- package/src/core/agents/claude-code/spawn.ts +0 -26
- package/src/core/agents/codex-app-server/client.ts +11 -18
- package/src/core/agents/codex-app-server/login.ts +4 -5
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/gemini/failures.ts +148 -0
- package/src/core/agents/gemini/login.ts +188 -0
- package/src/core/agents/gemini/profile.ts +162 -0
- package/src/core/agents/gemini/tools.ts +99 -0
- package/src/core/agents/login.ts +14 -8
- package/src/core/agents/scripted/scripted-agent.ts +42 -3
- package/src/core/agents/stderr-tail.ts +5 -2
- package/src/core/presets.ts +19 -3
- package/src/core/processes/native-processes.ts +32 -1
- package/src/core/provision/checksums.ts +12 -2
- package/src/core/provision/install-build.ts +122 -55
- package/src/core/provision/pins.ts +5 -0
- package/src/core/provision/provisioner.ts +62 -27
- package/src/core/provision/releases.ts +47 -1
- package/src/core/provision/tools.ts +124 -31
- package/src/core/runtime/agent-runtime.ts +31 -7
- package/src/core/runtime/event-processor.ts +13 -6
- package/src/core/runtime/origin-line.ts +43 -0
- package/src/core/runtime/request-broker.ts +2 -0
- package/src/core/runtime/steering.ts +8 -4
- package/src/core/runtime/turn.ts +11 -4
- package/src/operator/errors.ts +221 -0
- package/src/operator/index.ts +18 -23
- package/src/operator/mcp.ts +7 -16
- package/src/operator/operator.ts +1684 -610
- package/src/operator/refs.ts +75 -0
- package/src/operator/render.ts +260 -118
- package/src/operator/session-tools.ts +127 -0
- package/src/operator/types.ts +506 -0
- package/src/operator/view.ts +93 -42
- package/src/protocol/account.ts +5 -2
- package/src/protocol/auth.ts +5 -1
- package/src/protocol/config.ts +14 -6
- package/src/protocol/conversation.ts +3 -0
- package/src/protocol/credentials.ts +11 -2
- package/src/protocol/harness.ts +9 -1
- package/src/protocol/history.ts +2 -1
- package/src/protocol/index.ts +1 -0
- package/src/protocol/lifecycle.ts +21 -0
- package/src/protocol/origin.ts +47 -0
- package/src/protocol/reduce.ts +4 -0
- package/src/protocol/wire.ts +18 -0
- package/src/server/bin.ts +20 -6
- package/src/server/install.ts +6 -3
- package/src/server/routes.ts +16 -5
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
InitializeResponse,
|
|
3
|
-
PromptRequest,
|
|
4
3
|
SessionConfigOption,
|
|
5
4
|
SessionModeState,
|
|
6
5
|
} from "@agentclientprotocol/sdk";
|
|
7
6
|
import type {
|
|
8
7
|
AgentCapabilities,
|
|
8
|
+
AgentHarness,
|
|
9
9
|
AgentInput,
|
|
10
10
|
McpServerConfig,
|
|
11
|
+
ModelDescriptor,
|
|
11
12
|
PermissionMode,
|
|
12
13
|
RunConfig,
|
|
13
14
|
} from "../../../protocol/index.ts";
|
|
14
|
-
import { AsyncQueue } from "../../../protocol/index.ts";
|
|
15
|
+
import { AsyncQueue, clampThinkingLevel } from "../../../protocol/index.ts";
|
|
15
16
|
import { type NativeProcesses, sharedNativeProcesses } from "../../processes/native-processes.ts";
|
|
16
17
|
import { onAbort, untilAborted } from "../../utils/deadline.ts";
|
|
17
|
-
import {
|
|
18
|
-
|
|
18
|
+
import {
|
|
19
|
+
InvalidRequestError,
|
|
20
|
+
McpUnavailableError,
|
|
21
|
+
SessionResumeError,
|
|
22
|
+
} from "../../utils/errors.ts";
|
|
23
|
+
import type {
|
|
24
|
+
AgentExecuteOptions,
|
|
25
|
+
AppliedExecution,
|
|
26
|
+
ListModelsOptions,
|
|
27
|
+
RawAgentEvent,
|
|
28
|
+
} from "../base.ts";
|
|
19
29
|
import { configFingerprint } from "../config-fingerprint.ts";
|
|
20
30
|
import {
|
|
21
31
|
type HostLease,
|
|
@@ -25,17 +35,38 @@ import {
|
|
|
25
35
|
loopbackDirect,
|
|
26
36
|
refuseHostName,
|
|
27
37
|
} from "../host-tools.ts";
|
|
38
|
+
import type { CliLogin } from "../login.ts";
|
|
28
39
|
import { IDLE_TIMEOUT_MS, ProcessPool } from "../process-pool.ts";
|
|
29
40
|
import { SessionAgent } from "../session-agent.ts";
|
|
41
|
+
import {
|
|
42
|
+
AcpAccount,
|
|
43
|
+
type AcpStart,
|
|
44
|
+
SESSION_REQUEST_TIMEOUT_MS,
|
|
45
|
+
initialize,
|
|
46
|
+
launchOf,
|
|
47
|
+
startClient,
|
|
48
|
+
} from "./account.ts";
|
|
30
49
|
import { type AcpRawEvent, CANCELLED_PROMPT_RESULT } from "./adapter.ts";
|
|
31
|
-
import { AcpClient,
|
|
50
|
+
import type { AcpClient, AcpClientOptions, AcpLaunch } from "./client.ts";
|
|
32
51
|
import {
|
|
33
52
|
type AcpPromptCapabilities,
|
|
34
|
-
|
|
53
|
+
type SelectOption,
|
|
54
|
+
modeNames,
|
|
55
|
+
refuseFiles,
|
|
56
|
+
selectOf,
|
|
57
|
+
selectableValues,
|
|
35
58
|
toAcpMcpServers,
|
|
36
59
|
toPromptBlocks,
|
|
37
60
|
} from "./mappings.ts";
|
|
38
|
-
import {
|
|
61
|
+
import { defaultModel, listAcpModels } from "./models.ts";
|
|
62
|
+
import { type AcpProfile, genericAcpProfile } from "./profile.ts";
|
|
63
|
+
import { TurnPrompts } from "./prompts.ts";
|
|
64
|
+
import {
|
|
65
|
+
type RequestScope,
|
|
66
|
+
type TurnScope,
|
|
67
|
+
answerElicitation,
|
|
68
|
+
answerPermission,
|
|
69
|
+
} from "./requests.ts";
|
|
39
70
|
|
|
40
71
|
/**
|
|
41
72
|
* What a session's agent process was started with, as one key: a change to
|
|
@@ -69,7 +100,12 @@ function spawnKey(
|
|
|
69
100
|
host: string | undefined,
|
|
70
101
|
): string {
|
|
71
102
|
return configFingerprint({
|
|
72
|
-
launch: {
|
|
103
|
+
launch: {
|
|
104
|
+
command: launch.command,
|
|
105
|
+
args: launch.args ?? [],
|
|
106
|
+
env: launch.env ?? {},
|
|
107
|
+
fixedEnv: launch.fixedEnv ?? {},
|
|
108
|
+
},
|
|
73
109
|
cwd: options.cwd,
|
|
74
110
|
env: options.env,
|
|
75
111
|
// @ref LLP 0018#acp — only what the agent is given
|
|
@@ -81,42 +117,6 @@ function spawnKey(
|
|
|
81
117
|
});
|
|
82
118
|
}
|
|
83
119
|
|
|
84
|
-
const CAPABILITIES: AgentCapabilities = {
|
|
85
|
-
multiTurn: true,
|
|
86
|
-
// A requested resume fails if the target agent cannot load saved sessions.
|
|
87
|
-
sessionResume: true,
|
|
88
|
-
// v1 has no portable model parameter. A requested model or thinking level
|
|
89
|
-
// is applied only when the agent offers a `model` / `thought_level` config
|
|
90
|
-
// option, so neither is promised here.
|
|
91
|
-
modelSwitch: "unsupported",
|
|
92
|
-
thinkingLevels: false,
|
|
93
|
-
// The most an agent can take: its `initialize` decides, image data with its
|
|
94
|
-
// `image` prompt capability and files beyond text with `embeddedContext`.
|
|
95
|
-
images: true,
|
|
96
|
-
files: ["text", "pdf", "binary"],
|
|
97
|
-
mcpServers: true,
|
|
98
|
-
permissionRequests: true,
|
|
99
|
-
// The answer is an option id.
|
|
100
|
-
rejectionMessages: false,
|
|
101
|
-
ignoredSettings: [
|
|
102
|
-
// ACP v1 has no system prompt: session/new takes the folder, the MCP
|
|
103
|
-
// servers and the extra directories only (`resolveSession`).
|
|
104
|
-
"systemPromptAppend",
|
|
105
|
-
// A prompt runs until the agent ends it: ACP v1 has no turn limit.
|
|
106
|
-
"maxTurns",
|
|
107
|
-
// session/resume and session/load name a session, not a message in it.
|
|
108
|
-
"resumeSessionAt",
|
|
109
|
-
// The agent's credentials are its launch command's: the client gets the
|
|
110
|
-
// launch, the folder and the env only (`AcpClientOptions`).
|
|
111
|
-
"apiKey",
|
|
112
|
-
// ACP v1 cannot ask an agent to run without its tools.
|
|
113
|
-
"disableTools",
|
|
114
|
-
] satisfies Array<keyof RunConfig>,
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/** ACP protocol major version this harness speaks. */
|
|
118
|
-
const PROTOCOL_VERSION = 1;
|
|
119
|
-
|
|
120
120
|
/**
|
|
121
121
|
* How long a cancelled prompt may take to end before the agent is ended,
|
|
122
122
|
* unless `cancelGraceMs` says otherwise: an agent that can neither resume nor
|
|
@@ -124,12 +124,6 @@ const PROTOCOL_VERSION = 1;
|
|
|
124
124
|
*/
|
|
125
125
|
const CANCEL_GRACE_MS = 10_000;
|
|
126
126
|
|
|
127
|
-
/** Deadline for `initialize` on a freshly spawned agent (mirrors codex startup). */
|
|
128
|
-
const INITIALIZE_TIMEOUT_MS = 15_000;
|
|
129
|
-
|
|
130
|
-
/** Deadline for session lifecycle requests (`session/new`, `session/resume`). */
|
|
131
|
-
const SESSION_REQUEST_TIMEOUT_MS = 30_000;
|
|
132
|
-
|
|
133
127
|
export interface AcpAgentOptions {
|
|
134
128
|
/**
|
|
135
129
|
* Resolve the ACP agent subprocess to launch. Operator-level only — never
|
|
@@ -171,7 +165,7 @@ export interface AcpAgentOptions {
|
|
|
171
165
|
hostTools?: HostTools;
|
|
172
166
|
}
|
|
173
167
|
|
|
174
|
-
interface AcpSession {
|
|
168
|
+
interface AcpSession extends RequestScope {
|
|
175
169
|
client: AcpClient;
|
|
176
170
|
acpSessionId: string;
|
|
177
171
|
/** What its agent process was started with (`spawnKey`). */
|
|
@@ -186,8 +180,12 @@ interface AcpSession {
|
|
|
186
180
|
configOptions: SessionConfigOption[];
|
|
187
181
|
/** The agent's modes, kept current by `current_mode_update`; absent when it offers none. */
|
|
188
182
|
modes?: SessionModeState;
|
|
183
|
+
/** For a profile that lists models: the one a turn naming none runs, as the session opened on it. */
|
|
184
|
+
defaultModel?: string;
|
|
189
185
|
/** From `initialize`: what the agent's prompts accept beyond text and links. */
|
|
190
186
|
prompt: AcpPromptCapabilities;
|
|
187
|
+
/** The MCP servers the agent was given, by name: what tells a call's server from its tool. */
|
|
188
|
+
servers: string[];
|
|
191
189
|
turn?: TurnScope;
|
|
192
190
|
}
|
|
193
191
|
|
|
@@ -210,33 +208,81 @@ function failureMessage(error: unknown): string {
|
|
|
210
208
|
return `${error}: ${detail}`;
|
|
211
209
|
}
|
|
212
210
|
|
|
213
|
-
/**
|
|
214
|
-
function
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
/** Set an option to `value` unless it holds it; the answer carries every option as it now stands. */
|
|
212
|
+
async function select(session: AcpSession, option: SelectOption, value: string): Promise<void> {
|
|
213
|
+
if (option.currentValue === value) return;
|
|
214
|
+
const updated = await session.client.request(
|
|
215
|
+
"session/set_config_option",
|
|
216
|
+
{ sessionId: session.acpSessionId, configId: option.id, value },
|
|
217
|
+
SESSION_REQUEST_TIMEOUT_MS,
|
|
217
218
|
);
|
|
219
|
+
session.configOptions = updated.configOptions;
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
* What the agent's options say the turn runs, where it has them: what it ran,
|
|
224
|
+
* not what was asked (a level the model lacks was fitted, or left alone).
|
|
225
|
+
*/
|
|
226
|
+
function selected(session: AcpSession): AppliedExecution {
|
|
227
|
+
const model = selectOf(session.configOptions, "model")?.currentValue;
|
|
228
|
+
const thinkingLevel = selectOf(session.configOptions, "thought_level")?.currentValue;
|
|
229
|
+
return { ...(model && { model }), ...(thinkingLevel && { thinkingLevel }) };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// @ref LLP 0016.000#an-acp-agents-profile — a profile reaches the agent only through its harness's registration
|
|
233
|
+
/**
|
|
234
|
+
* An ACP agent running a profile: drives an Agent Client Protocol v1 agent
|
|
235
|
+
* as a long-lived subprocess (one per logical session, reused across turns).
|
|
236
|
+
* What is one agent's own, its name, its launch command and where it departs
|
|
237
|
+
* from its `initialize`, is its profile; `initialize` negotiates the protocol
|
|
238
|
+
* version and gates optional features (resume, images) on the agent's
|
|
239
|
+
* advertised capabilities. The turn's stopReason arrives as the
|
|
226
240
|
* `session/prompt` *response*, so `execute` re-injects it into the raw stream
|
|
227
|
-
* as a synthetic `session/prompt_result` event for the adapter.
|
|
241
|
+
* as a synthetic `session/prompt_result` event for the adapter. Internal to
|
|
242
|
+
* the engine: a harness that is a profile constructs it in its registration
|
|
243
|
+
* (`geminiHarness`); `AcpAgent` is the `acp` harness.
|
|
228
244
|
*/
|
|
229
|
-
export class
|
|
230
|
-
readonly harness
|
|
231
|
-
readonly capabilities
|
|
245
|
+
export class ProfiledAcpAgent extends SessionAgent {
|
|
246
|
+
readonly harness: AgentHarness;
|
|
247
|
+
readonly capabilities: AgentCapabilities;
|
|
248
|
+
readonly login?: CliLogin;
|
|
249
|
+
/** Present when its profile lists models: what the agent offers this login. */
|
|
250
|
+
readonly listModels?: (options: ListModelsOptions) => Promise<ModelDescriptor[]>;
|
|
232
251
|
/** Its CLIs start here: the runtime's, or this OS process's own when it was made without one. */
|
|
233
252
|
readonly processes: NativeProcesses;
|
|
253
|
+
private readonly profile: AcpProfile;
|
|
234
254
|
private readonly sessions: ProcessPool<AcpSession, AcpPoolTurn>;
|
|
235
255
|
private readonly host?: HostToolSessions;
|
|
256
|
+
/** How its agents start: its profile's, on its processes. */
|
|
257
|
+
private readonly starts: AcpStart;
|
|
258
|
+
/** The agent with no turn: its account, for the login and the model list. */
|
|
259
|
+
private readonly account: AcpAccount;
|
|
260
|
+
/** What each session's conversation was started with, when this agent started it (`newSession`). */
|
|
261
|
+
private readonly startedWith = new Map<string, { conversation: string; meta: string }>();
|
|
236
262
|
|
|
237
|
-
constructor(
|
|
263
|
+
constructor(
|
|
264
|
+
profile: AcpProfile,
|
|
265
|
+
private readonly agentOptions: Omit<AcpAgentOptions, "resolveLaunch">,
|
|
266
|
+
) {
|
|
238
267
|
super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
|
|
268
|
+
this.profile = profile;
|
|
269
|
+
this.harness = this.profile.harness;
|
|
270
|
+
this.capabilities = this.profile.capabilities;
|
|
239
271
|
this.processes = agentOptions.processes ?? sharedNativeProcesses();
|
|
272
|
+
const { clientName, clientVersion, createClient } = agentOptions;
|
|
273
|
+
this.starts = {
|
|
274
|
+
profile: this.profile,
|
|
275
|
+
processes: this.processes,
|
|
276
|
+
clientName,
|
|
277
|
+
clientVersion,
|
|
278
|
+
createClient,
|
|
279
|
+
};
|
|
280
|
+
this.account = new AcpAccount(this.starts);
|
|
281
|
+
this.login = this.profile.login?.(this.account);
|
|
282
|
+
const models = this.profile.models;
|
|
283
|
+
if (models)
|
|
284
|
+
this.listModels = (listing) =>
|
|
285
|
+
listAcpModels(this.account, this.harness, (value) => models.offers(value), listing);
|
|
240
286
|
this.host = hostToolSessions(agentOptions.hostTools, this.harness, {
|
|
241
287
|
// @ref LLP 0018#acp — the engine's mode: the turn's, moved only by a plan the broker approved
|
|
242
288
|
// The agent's own `current_mode_update` never raises it.
|
|
@@ -272,15 +318,8 @@ export class AcpAgent extends SessionAgent {
|
|
|
272
318
|
options: AgentExecuteOptions,
|
|
273
319
|
signal: AbortSignal,
|
|
274
320
|
): Promise<AcpSession> {
|
|
275
|
-
signal.throwIfAborted();
|
|
276
321
|
// A cancel ends the wait: the operator's resolution goes on for the next turn.
|
|
277
|
-
const launch = await
|
|
278
|
-
signal.throwIfAborted();
|
|
279
|
-
if (!launch) {
|
|
280
|
-
throw new Error(
|
|
281
|
-
"acp harness is not configured: resolveLaunch returned no agent launch command",
|
|
282
|
-
);
|
|
283
|
-
}
|
|
322
|
+
const launch = await launchOf(this.profile, signal);
|
|
284
323
|
|
|
285
324
|
const host = await untilAborted(
|
|
286
325
|
Promise.resolve(this.host?.lease(options.sessionId, options.cwd)),
|
|
@@ -337,24 +376,26 @@ export class AcpAgent extends SessionAgent {
|
|
|
337
376
|
signal: AbortSignal,
|
|
338
377
|
): Promise<AcpSession> {
|
|
339
378
|
const resumeTarget = options.resumeSessionId;
|
|
340
|
-
const
|
|
379
|
+
const client = await startClient(this.starts, {
|
|
341
380
|
launch,
|
|
342
381
|
cwd: options.cwd,
|
|
343
382
|
// @ref LLP 0018#acp — the bearer never travels through a proxy
|
|
344
|
-
// In the client's own order: the engine's environment, the launch's, the turn's.
|
|
383
|
+
// In the client's own order: the engine's environment, the launch's, the turn's, the launch's fixed.
|
|
345
384
|
env: this.host
|
|
346
385
|
? {
|
|
347
386
|
...options.env,
|
|
348
|
-
...loopbackDirect({
|
|
387
|
+
...loopbackDirect({
|
|
388
|
+
...process.env,
|
|
389
|
+
...launch.env,
|
|
390
|
+
...options.env,
|
|
391
|
+
...launch.fixedEnv,
|
|
392
|
+
}),
|
|
349
393
|
}
|
|
350
394
|
: options.env,
|
|
351
|
-
clientName: this.agentOptions.clientName,
|
|
352
395
|
sessionId: options.sessionId,
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
? await this.agentOptions.createClient(clientOptions)
|
|
357
|
-
: await AcpClient.create(clientOptions);
|
|
396
|
+
// What the agent asks gates the steers sent as prompts (`TurnPrompts`).
|
|
397
|
+
watchRequests: this.capabilities.steering === true,
|
|
398
|
+
});
|
|
358
399
|
own(client);
|
|
359
400
|
// Closed at once when the turn was cancelled meanwhile.
|
|
360
401
|
const offAbort = onAbort(signal, () => client.close());
|
|
@@ -362,20 +403,7 @@ export class AcpAgent extends SessionAgent {
|
|
|
362
403
|
let acpSessionId: string | undefined;
|
|
363
404
|
try {
|
|
364
405
|
signal.throwIfAborted();
|
|
365
|
-
init = await client.
|
|
366
|
-
"initialize",
|
|
367
|
-
{
|
|
368
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
369
|
-
// The engine brokers the agent's requests for input, form or URL;
|
|
370
|
-
// a turn whose client cannot answer declines them.
|
|
371
|
-
clientCapabilities: { elicitation: { form: {}, url: {} } },
|
|
372
|
-
clientInfo: {
|
|
373
|
-
name: this.agentOptions.clientName ?? "agent-server",
|
|
374
|
-
version: this.agentOptions.clientVersion ?? "0.0.0",
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
INITIALIZE_TIMEOUT_MS,
|
|
378
|
-
);
|
|
406
|
+
init = await initialize(client, this.starts);
|
|
379
407
|
signal.throwIfAborted();
|
|
380
408
|
const capabilities = init.agentCapabilities;
|
|
381
409
|
const takesDirectories = Boolean(capabilities?.sessionCapabilities?.additionalDirectories);
|
|
@@ -387,7 +415,7 @@ export class AcpAgent extends SessionAgent {
|
|
|
387
415
|
const given = await this.serversFor(
|
|
388
416
|
options,
|
|
389
417
|
host,
|
|
390
|
-
Boolean(capabilities?.mcpCapabilities?.http),
|
|
418
|
+
this.profile.httpMcp || Boolean(capabilities?.mcpCapabilities?.http),
|
|
391
419
|
);
|
|
392
420
|
const target = {
|
|
393
421
|
cwd: options.cwd,
|
|
@@ -423,14 +451,26 @@ export class AcpAgent extends SessionAgent {
|
|
|
423
451
|
configOptions = resumed?.configOptions;
|
|
424
452
|
modes = resumed?.modes;
|
|
425
453
|
} else {
|
|
426
|
-
const
|
|
454
|
+
const meta = this.profile.newSession?.meta(options);
|
|
455
|
+
const created = await client.request(
|
|
456
|
+
"session/new",
|
|
457
|
+
{ ...target, ...(meta && { _meta: meta }) },
|
|
458
|
+
SESSION_REQUEST_TIMEOUT_MS,
|
|
459
|
+
);
|
|
427
460
|
acpSessionId = created.sessionId;
|
|
461
|
+
if (this.profile.newSession)
|
|
462
|
+
this.startedWith.set(options.sessionId, {
|
|
463
|
+
conversation: created.sessionId,
|
|
464
|
+
meta: configFingerprint(meta ?? {}),
|
|
465
|
+
});
|
|
428
466
|
configOptions = created.configOptions;
|
|
429
467
|
modes = created.modes;
|
|
430
468
|
}
|
|
431
469
|
signal.throwIfAborted();
|
|
432
470
|
if (!acpSessionId) throw new Error("acp agent returned no session id");
|
|
433
471
|
|
|
472
|
+
// A session opens, new or resumed, on the account's default model.
|
|
473
|
+
const opened = selectOf(configOptions ?? [], "model");
|
|
434
474
|
const session: AcpSession = {
|
|
435
475
|
client,
|
|
436
476
|
acpSessionId,
|
|
@@ -440,11 +480,16 @@ export class AcpAgent extends SessionAgent {
|
|
|
440
480
|
resumable: resumeMethod !== undefined,
|
|
441
481
|
configOptions: configOptions ?? [],
|
|
442
482
|
...(modes?.availableModes.length && { modes }),
|
|
483
|
+
...(this.profile.models &&
|
|
484
|
+
opened && { defaultModel: defaultModel(opened, this.profile.models.offers) }),
|
|
443
485
|
prompt: {
|
|
444
486
|
image: Boolean(init.agentCapabilities?.promptCapabilities?.image),
|
|
445
487
|
embeddedContext: Boolean(init.agentCapabilities?.promptCapabilities?.embeddedContext),
|
|
446
488
|
},
|
|
489
|
+
servers: Object.keys(given.servers ?? {}),
|
|
447
490
|
};
|
|
491
|
+
const tools = this.profile.tools;
|
|
492
|
+
if (tools) session.describe = (call) => tools.describe(call, session.servers);
|
|
448
493
|
client.setPermissionHandler((request) => answerPermission(session, request));
|
|
449
494
|
client.setElicitationHandler((request) => answerElicitation(session, request));
|
|
450
495
|
client.onSessionUpdate(({ sessionId, update }) => {
|
|
@@ -465,75 +510,104 @@ export class AcpAgent extends SessionAgent {
|
|
|
465
510
|
}
|
|
466
511
|
|
|
467
512
|
/**
|
|
468
|
-
* Select the requested model
|
|
469
|
-
* options
|
|
470
|
-
* agent does not offer
|
|
471
|
-
*
|
|
472
|
-
*
|
|
513
|
+
* Select the requested model, then the thinking level, through the agent's
|
|
514
|
+
* config options; an agent without the option keeps its own default. A
|
|
515
|
+
* model the agent does not offer, or its profile does not take, fails the
|
|
516
|
+
* turn; a turn that names none on a profile that lists models runs the
|
|
517
|
+
* one its list marks default (`defaultModel`). The levels are the ones
|
|
518
|
+
* offered once the model is set, which are that model's, and the turn
|
|
519
|
+
* runs the nearest of them, as on Claude and Codex (`clampThinkingLevel`);
|
|
520
|
+
* a level that cannot be fitted is left alone. Returns the settings it
|
|
521
|
+
* left alone.
|
|
473
522
|
*/
|
|
474
523
|
private async applyConfig(
|
|
475
524
|
session: AcpSession,
|
|
476
525
|
options: AgentExecuteOptions,
|
|
477
526
|
): Promise<Array<keyof RunConfig>> {
|
|
478
|
-
const requested = [
|
|
479
|
-
["model", options.model, "model"],
|
|
480
|
-
["thought_level", options.thinkingLevel, "thinkingLevel"],
|
|
481
|
-
] as const;
|
|
482
527
|
const left: Array<keyof RunConfig> = [];
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
);
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
528
|
+
const option = selectOf(session.configOptions, "model");
|
|
529
|
+
const offers = this.profile.models?.offers;
|
|
530
|
+
if (!option) {
|
|
531
|
+
if (options.model) left.push("model");
|
|
532
|
+
} else if (options.model || offers) {
|
|
533
|
+
const offered = selectableValues(option).filter((value) => offers?.(value) ?? true);
|
|
534
|
+
// @ref LLP 0016.000#an-acp-agents-model-and-thinking-level — a harness that lists its models runs only one of them
|
|
535
|
+
// The default the session opened on, while the agent still offers it.
|
|
536
|
+
const opened =
|
|
537
|
+
session.defaultModel && offered.includes(session.defaultModel)
|
|
538
|
+
? session.defaultModel
|
|
539
|
+
: undefined;
|
|
540
|
+
const model =
|
|
541
|
+
options.model ?? opened ?? (offers && defaultModel(option, offers)) ?? option.currentValue;
|
|
542
|
+
if (!offered.includes(model)) {
|
|
500
543
|
throw new Error(
|
|
501
|
-
`invalid request: the
|
|
544
|
+
`invalid request: the ${this.harness} harness does not offer model '${model}' (available: ${offered.join(", ") || "none"})`,
|
|
502
545
|
);
|
|
503
546
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
);
|
|
509
|
-
session
|
|
547
|
+
await select(session, option, model);
|
|
548
|
+
}
|
|
549
|
+
if (options.thinkingLevel) {
|
|
550
|
+
const option = selectOf(session.configOptions, "thought_level");
|
|
551
|
+
const level = option && clampThinkingLevel(options.thinkingLevel, selectableValues(option));
|
|
552
|
+
if (option && level !== undefined) await select(session, option, level);
|
|
553
|
+
else left.push("thinkingLevel");
|
|
510
554
|
}
|
|
511
555
|
return left;
|
|
512
556
|
}
|
|
513
557
|
|
|
514
|
-
// @ref LLP 0016.000#an-acp-agents-
|
|
558
|
+
// @ref LLP 0016.000#an-acp-agents-profile — what a conversation starts with it keeps
|
|
559
|
+
/**
|
|
560
|
+
* What a conversation keeps from its start (`newSession`), said not
|
|
561
|
+
* applied by a later turn that asks otherwise; what a conversation this
|
|
562
|
+
* agent did not start was given is unknown, and nothing is said.
|
|
563
|
+
*/
|
|
564
|
+
private keptFromStart(session: AcpSession, options: AgentExecuteOptions): Array<keyof RunConfig> {
|
|
565
|
+
const kept = this.profile.newSession;
|
|
566
|
+
const started = this.startedWith.get(options.sessionId);
|
|
567
|
+
if (!kept || started?.conversation !== session.acpSessionId) return [];
|
|
568
|
+
// Compared, not said of every later turn: a product sends the same config each turn, and that one is in effect.
|
|
569
|
+
return started.meta === configFingerprint(kept.meta(options) ?? {}) ? [] : [...kept.settings];
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// @ref LLP 0016.000#an-acp-agents-permission-mode — never a turn in a mode the engine knows is not the one asked
|
|
515
573
|
/**
|
|
516
574
|
* Put the agent in the turn's permission mode (`default` when it names
|
|
517
|
-
* none) through `session/set_mode`, by the agent's own id for it.
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* has
|
|
575
|
+
* none) through `session/set_mode`, by the agent's own id for it. An agent
|
|
576
|
+
* with no id for the mode is put in its `default`, never left in the mode
|
|
577
|
+
* an earlier turn left it in, and the engine answers what it asks by the
|
|
578
|
+
* turn's mode (`autoDecide`), as for an agent that offers no modes; neither
|
|
579
|
+
* has a plan of its own to make, so `plan` does not hold there. An agent
|
|
580
|
+
* with no `default` either stays where it is: in a mode the engine names
|
|
581
|
+
* and was not asked, the turn is refused; in one it cannot name, it runs,
|
|
582
|
+
* and the mode is said not applied. Returns whether the mode holds.
|
|
522
583
|
*/
|
|
523
584
|
private async applyMode(session: AcpSession, requested: PermissionMode): Promise<boolean> {
|
|
524
585
|
const modes = session.modes;
|
|
525
586
|
if (!modes) return requested !== "plan";
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
587
|
+
const names = modeNames(this.profile.modeIds);
|
|
588
|
+
const offered = modes.availableModes.map(({ id }) => id);
|
|
589
|
+
const own = names.idOf(requested, offered);
|
|
590
|
+
const target = own ?? names.idOf("default", offered);
|
|
591
|
+
if (target === undefined) {
|
|
592
|
+
const current = names.modeOf(modes.currentModeId);
|
|
593
|
+
if (current === undefined) return false;
|
|
594
|
+
if (current === requested) return true;
|
|
595
|
+
throw new InvalidRequestError([
|
|
596
|
+
{
|
|
597
|
+
path: "permissionMode",
|
|
598
|
+
message: `the ${this.harness} harness cannot run a ${requested} turn: the agent is in ${current}, and offers no mode to move it to`,
|
|
599
|
+
},
|
|
600
|
+
]);
|
|
601
|
+
}
|
|
602
|
+
if (target !== modes.currentModeId) {
|
|
529
603
|
await session.client.request(
|
|
530
604
|
"session/set_mode",
|
|
531
|
-
{ sessionId: session.acpSessionId, modeId: target
|
|
605
|
+
{ sessionId: session.acpSessionId, modeId: target },
|
|
532
606
|
SESSION_REQUEST_TIMEOUT_MS,
|
|
533
607
|
);
|
|
534
|
-
session.modes = { ...modes, currentModeId: target
|
|
608
|
+
session.modes = { ...modes, currentModeId: target };
|
|
535
609
|
}
|
|
536
|
-
return
|
|
610
|
+
return own !== undefined || requested !== "plan";
|
|
537
611
|
}
|
|
538
612
|
|
|
539
613
|
protected override async *executeTurn(
|
|
@@ -547,6 +621,8 @@ export class AcpAgent extends SessionAgent {
|
|
|
547
621
|
let session: AcpSession | undefined;
|
|
548
622
|
try {
|
|
549
623
|
controller.signal.throwIfAborted();
|
|
624
|
+
this.profile.admit?.(options);
|
|
625
|
+
refuseFiles(input, this.harness, this.capabilities.files);
|
|
550
626
|
session = await this.resolveSession(options, controller.signal);
|
|
551
627
|
const notApplied = await this.applyConfig(session, options);
|
|
552
628
|
// Sent only to an agent that takes them (`resolveSession`).
|
|
@@ -554,7 +630,8 @@ export class AcpAgent extends SessionAgent {
|
|
|
554
630
|
notApplied.push("additionalDirectories");
|
|
555
631
|
if (!(await this.applyMode(session, options.permissionMode ?? "default")))
|
|
556
632
|
notApplied.push("permissionMode");
|
|
557
|
-
|
|
633
|
+
notApplied.push(...this.keptFromStart(session, options));
|
|
634
|
+
options.onExecution?.({ ...selected(session), ...(notApplied.length && { notApplied }) });
|
|
558
635
|
controller.signal.throwIfAborted();
|
|
559
636
|
session.turn = {
|
|
560
637
|
broker: options.onPermissionRequest,
|
|
@@ -566,33 +643,51 @@ export class AcpAgent extends SessionAgent {
|
|
|
566
643
|
options.onNativeSession?.(session.acpSessionId, {
|
|
567
644
|
resumed: session.acpSessionId === options.resumeSessionId,
|
|
568
645
|
});
|
|
646
|
+
// What tells its calls' servers from their tools, for the adapter's tool rules.
|
|
647
|
+
if (this.profile.tools)
|
|
648
|
+
yield { method: "agentServer/mcpServers", params: { names: session.servers } };
|
|
569
649
|
const { client, acpSessionId } = session;
|
|
650
|
+
const takes = session.prompt;
|
|
570
651
|
|
|
571
|
-
unsubscribe.push(
|
|
572
|
-
client.onSessionUpdate((notification) => {
|
|
573
|
-
if (notification.sessionId !== acpSessionId) return;
|
|
574
|
-
queue.push({ method: "session/update", params: notification });
|
|
575
|
-
}),
|
|
576
|
-
);
|
|
577
652
|
const finishCancelled = () => {
|
|
578
653
|
queue.push(CANCELLED_PROMPT_RESULT);
|
|
579
654
|
queue.end();
|
|
580
655
|
};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
656
|
+
const prompts = new TurnPrompts({
|
|
657
|
+
send: (prompt) => client.request("session/prompt", { sessionId: acpSessionId, prompt }),
|
|
658
|
+
...(client.asking && { asking: client.asking }),
|
|
659
|
+
signal: controller.signal,
|
|
660
|
+
ends: {
|
|
661
|
+
read: (steerId) => queue.push({ method: "agentServer/steerRead", params: { steerId } }),
|
|
662
|
+
ended: (result) => {
|
|
663
|
+
this.holdSteering(options);
|
|
664
|
+
queue.push({ method: "session/prompt_result", params: result });
|
|
665
|
+
queue.end();
|
|
666
|
+
},
|
|
667
|
+
failed: (error) => {
|
|
668
|
+
this.holdSteering(options);
|
|
669
|
+
if (controller.signal.aborted) return finishCancelled();
|
|
670
|
+
queue.push({ method: "error", params: { message: failureMessage(error) } });
|
|
671
|
+
queue.end();
|
|
672
|
+
},
|
|
673
|
+
},
|
|
585
674
|
});
|
|
586
675
|
unsubscribe.push(
|
|
676
|
+
client.onSessionUpdate((notification) => {
|
|
677
|
+
if (notification.sessionId !== acpSessionId) return;
|
|
678
|
+
// A steer the agent took is read before what it says next.
|
|
679
|
+
prompts.update(notification.update);
|
|
680
|
+
queue.push({ method: "session/update", params: notification });
|
|
681
|
+
}),
|
|
587
682
|
client.onClose((error) => {
|
|
588
|
-
|
|
683
|
+
prompts.close();
|
|
589
684
|
if (controller.signal.aborted) finishCancelled();
|
|
590
685
|
else queue.fail(error ?? new Error("acp agent exited mid-turn"));
|
|
591
686
|
}),
|
|
592
687
|
);
|
|
593
688
|
|
|
594
689
|
const cancelPrompt = () => {
|
|
595
|
-
// ACP semantics: session/cancel makes the in-flight
|
|
690
|
+
// ACP semantics: session/cancel makes the in-flight prompts resolve
|
|
596
691
|
// with stopReason=cancelled. Bound the wait for misbehaving agents.
|
|
597
692
|
void client.notify("session/cancel", { sessionId: acpSessionId }).catch(() => {});
|
|
598
693
|
cancelTimer = setTimeout(() => {
|
|
@@ -609,28 +704,16 @@ export class AcpAgent extends SessionAgent {
|
|
|
609
704
|
finishCancelled();
|
|
610
705
|
} else {
|
|
611
706
|
unsubscribe.push(onAbort(controller.signal, cancelPrompt));
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
queue.end();
|
|
623
|
-
},
|
|
624
|
-
(error: unknown) => {
|
|
625
|
-
promptEnded();
|
|
626
|
-
if (controller.signal.aborted) {
|
|
627
|
-
finishCancelled();
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
queue.push({ method: "error", params: { message: failureMessage(error) } });
|
|
631
|
-
queue.end();
|
|
632
|
-
},
|
|
633
|
-
);
|
|
707
|
+
// @ref LLP 0001#d9--the-wire-is-quick-ack-json-rpc-requests-flow-one-way — confirmed only when the prompts ended
|
|
708
|
+
this.cancelWith(options, () => prompts.settled.then(() => true));
|
|
709
|
+
prompts.start(toPromptBlocks(input, takes));
|
|
710
|
+
// @ref LLP 0016.000#an-acp-agent-steered-by-prompt — input during a turn is a prompt of its own
|
|
711
|
+
if (this.capabilities.steering)
|
|
712
|
+
await this.openSteering(options, (request) => {
|
|
713
|
+
if (!prompts.open || controller.signal.aborted) return "no_active_turn";
|
|
714
|
+
prompts.steer(request.steerId, toPromptBlocks(request.input, takes));
|
|
715
|
+
return "steered";
|
|
716
|
+
});
|
|
634
717
|
}
|
|
635
718
|
|
|
636
719
|
for await (const event of queue) {
|
|
@@ -643,18 +726,34 @@ export class AcpAgent extends SessionAgent {
|
|
|
643
726
|
if (cancelTimer) clearTimeout(cancelTimer);
|
|
644
727
|
for (const off of unsubscribe) off();
|
|
645
728
|
if (session) {
|
|
729
|
+
// A turn that has ended asks nothing: what it left open is forgotten.
|
|
730
|
+
session.client.asking?.askNothing();
|
|
646
731
|
session.turn = undefined;
|
|
647
732
|
this.sessions.leave(options.sessionId, session);
|
|
648
733
|
}
|
|
649
734
|
}
|
|
650
735
|
}
|
|
651
736
|
|
|
737
|
+
/** A steer's file of a kind the harness does not take is refused, as a turn's is. */
|
|
738
|
+
protected override checkSteerInput(input: AgentInput): void {
|
|
739
|
+
refuseFiles(input, this.harness, this.capabilities.files);
|
|
740
|
+
}
|
|
741
|
+
|
|
652
742
|
override async release(sessionId: string): Promise<void> {
|
|
653
743
|
// The cancel aborts its turn at once; the agent is ended beside its
|
|
654
744
|
// confirm window, not after it, and its exit is what confirms it.
|
|
655
745
|
// An agent an eviction or a replacement ended earlier is waited for too.
|
|
656
746
|
await Promise.all([super.release(sessionId), this.sessions.release(sessionId)]);
|
|
657
747
|
this.host?.release(sessionId);
|
|
748
|
+
this.startedWith.delete(sessionId);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* The agent's login changed (in `store`, or in every store): each session's
|
|
753
|
+
* next turn starts a new agent, which resumes its conversation.
|
|
754
|
+
*/
|
|
755
|
+
loginChanged(store?: string): void {
|
|
756
|
+
this.sessions.loginChanged(store);
|
|
658
757
|
}
|
|
659
758
|
|
|
660
759
|
/** After a host resume, each session's next turn starts its agent again, on its conversation. */
|
|
@@ -668,3 +767,14 @@ export class AcpAgent extends SessionAgent {
|
|
|
668
767
|
await this.host?.close();
|
|
669
768
|
}
|
|
670
769
|
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* The `acp` harness: any ACP v1 agent the operator launches
|
|
773
|
+
* (`resolveLaunch`), taken at its `initialize`'s word.
|
|
774
|
+
*/
|
|
775
|
+
export class AcpAgent extends ProfiledAcpAgent {
|
|
776
|
+
constructor(options: AcpAgentOptions) {
|
|
777
|
+
const { resolveLaunch, ...shared } = options;
|
|
778
|
+
super(genericAcpProfile(resolveLaunch), shared);
|
|
779
|
+
}
|
|
780
|
+
}
|