@zvada/agent-server 0.3.27 → 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 +38 -0
- package/README.md +6 -4
- 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/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/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/stderr-tail.js +5 -2
- package/dist/core/presets.js +13 -0
- 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/operator/errors.js +2 -2
- package/dist/operator/operator.js +171 -74
- package/dist/operator/render.js +33 -25
- package/dist/operator/session-tools.js +2 -1
- package/dist/protocol/account.js +5 -1
- package/dist/protocol/auth.js +5 -1
- package/dist/protocol/credentials.js +9 -1
- package/dist/protocol/harness.js +9 -1
- package/dist/server/bin.js +22 -7
- package/dist/server/install.js +6 -4
- 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/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/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/operator/errors.d.ts +5 -1
- package/dist/types/operator/errors.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +11 -6
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/operator/session-tools.d.ts.map +1 -1
- package/dist/types/operator/types.d.ts +1 -0
- package/dist/types/operator/types.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 +2 -0
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +3 -3
- 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/lifecycle.d.ts +8 -8
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +39 -29
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +13 -10
- 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/docs/consuming.md +6 -0
- package/docs/deploy.md +17 -8
- package/docs/harnesses.md +166 -44
- package/package.json +1 -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/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/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/stderr-tail.ts +5 -2
- package/src/core/presets.ts +15 -2
- 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/operator/errors.ts +5 -2
- package/src/operator/operator.ts +181 -77
- package/src/operator/render.ts +60 -28
- package/src/operator/session-tools.ts +2 -1
- package/src/operator/types.ts +1 -0
- package/src/protocol/account.ts +5 -2
- package/src/protocol/auth.ts +5 -1
- package/src/protocol/credentials.ts +11 -2
- package/src/protocol/harness.ts +9 -1
- package/src/server/bin.ts +20 -6
- package/src/server/install.ts +6 -3
|
@@ -4,7 +4,7 @@ import type { AcpLaunch } from "./client.ts";
|
|
|
4
4
|
/**
|
|
5
5
|
* Advisory catalog of well-known ACP agents — UX sugar, not wire vocabulary
|
|
6
6
|
* (like the model catalog). On the wire the harness is always `acp`; these names
|
|
7
|
-
* let entry points offer "pi" or "gemini" as first-class choices and expand
|
|
7
|
+
* let entry points offer "pi" or "gemini-cli" as first-class choices and expand
|
|
8
8
|
* them to launch commands at the operator edge. Anything not listed here runs
|
|
9
9
|
* via an explicit launch command — any ACP-compatible agent works.
|
|
10
10
|
*/
|
|
@@ -15,8 +15,9 @@ export const KNOWN_ACP_AGENTS: Record<string, { label: string; launch: AcpLaunch
|
|
|
15
15
|
// Bump after checking the new release.
|
|
16
16
|
launch: { command: "npx", args: ["-y", "pi-acp@0.0.34"] },
|
|
17
17
|
},
|
|
18
|
-
gemini:
|
|
19
|
-
|
|
18
|
+
// `gemini` is the harness (Google's Antigravity CLI): this is the other CLI.
|
|
19
|
+
"gemini-cli": {
|
|
20
|
+
label: "Gemini CLI (native ACP mode; the enterprise CLI, without Gemini 4)",
|
|
20
21
|
launch: { command: "gemini", args: ["--acp"] },
|
|
21
22
|
},
|
|
22
23
|
};
|
|
@@ -53,9 +54,17 @@ export function resolveHarnessName(
|
|
|
53
54
|
/**
|
|
54
55
|
* Resolve an operator spec that is either a known agent name (`"pi"`) or a
|
|
55
56
|
* raw launch command (`"npx -y pi-acp"`). The canonical resolver behind
|
|
56
|
-
* `--acp-agent` and `$AGENT_SERVER_ACP_AGENT`.
|
|
57
|
+
* `--acp-agent` and `$AGENT_SERVER_ACP_AGENT`. A harness's own name is no
|
|
58
|
+
* ACP agent and no command to launch: it is refused, naming the harness and
|
|
59
|
+
* the known agents, so an old setting (`gemini`) says what to write instead.
|
|
57
60
|
*/
|
|
58
61
|
export function resolveAcpLaunch(spec: string | undefined): AcpLaunch | undefined {
|
|
59
62
|
if (!spec) return undefined;
|
|
60
|
-
|
|
63
|
+
const name = spec.trim();
|
|
64
|
+
if (isAgentHarness(name)) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`'${name}' is a harness, not an ACP agent: run it with --harness=${name}, or give an ACP agent's name (${Object.keys(KNOWN_ACP_AGENTS).join(", ")}) or launch command`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return knownAgent(name)?.launch ?? parseAcpLaunch(spec);
|
|
61
70
|
}
|
|
@@ -4,19 +4,22 @@ import type {
|
|
|
4
4
|
PermissionOption,
|
|
5
5
|
RequestPermissionRequest,
|
|
6
6
|
RequestPermissionResponse,
|
|
7
|
+
SessionConfigOption,
|
|
7
8
|
ToolCallContent,
|
|
8
9
|
ToolCallLocation,
|
|
9
10
|
} from "@agentclientprotocol/sdk";
|
|
10
11
|
import type {
|
|
11
12
|
AgentInput,
|
|
13
|
+
FileKind,
|
|
12
14
|
McpServerConfig,
|
|
15
|
+
McpTool,
|
|
13
16
|
PermissionMode,
|
|
14
17
|
PermissionToolCall,
|
|
15
18
|
ToolKind,
|
|
16
19
|
ToolLocation,
|
|
17
20
|
ToolResultContent,
|
|
18
21
|
} from "../../../protocol/index.ts";
|
|
19
|
-
import { TOOL_KINDS } from "../../../protocol/index.ts";
|
|
22
|
+
import { TOOL_KINDS, fileKind } from "../../../protocol/index.ts";
|
|
20
23
|
import { isRecord } from "../../utils/is-record.ts";
|
|
21
24
|
import {
|
|
22
25
|
UnsupportedAttachmentError,
|
|
@@ -104,6 +107,22 @@ export interface AcpPromptCapabilities {
|
|
|
104
107
|
embeddedContext: boolean;
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Refuse a file of a kind the harness does not offer (`capabilities.files`),
|
|
112
|
+
* before any agent starts: what an agent says it embeds is not what it reads,
|
|
113
|
+
* so the harness's own list decides (LLP 0020, decision 13).
|
|
114
|
+
*/
|
|
115
|
+
export function refuseFiles(input: AgentInput, harness: string, files: readonly FileKind[]): void {
|
|
116
|
+
if (typeof input === "string") return;
|
|
117
|
+
for (const part of input) {
|
|
118
|
+
if (part.type !== "file" || part.url !== undefined || files.includes(fileKind(part.mimeType)))
|
|
119
|
+
continue;
|
|
120
|
+
throw new UnsupportedAttachmentError(
|
|
121
|
+
`The ${harness} harness cannot take ${part.mimeType} file attachments`,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
107
126
|
/**
|
|
108
127
|
* Engine turn input → ACP prompt content blocks. Every agent takes text and
|
|
109
128
|
* resource links; image data needs the `image` capability and inline files
|
|
@@ -143,16 +162,23 @@ export function toPromptBlocks(input: AgentInput, prompt: AcpPromptCapabilities)
|
|
|
143
162
|
return blocks.length ? blocks : [{ type: "text", text: "" }];
|
|
144
163
|
}
|
|
145
164
|
|
|
146
|
-
/**
|
|
147
|
-
|
|
165
|
+
/**
|
|
166
|
+
* ACP permission request → the engine's PermissionToolCall (SDK-validated, no
|
|
167
|
+
* casts). `described` is what the harness's tool rules read of the call
|
|
168
|
+
* (`AcpProfile.stream`): an ACP agent names its tools by no rule of its own.
|
|
169
|
+
*/
|
|
170
|
+
export function permissionToolCall(
|
|
171
|
+
request: RequestPermissionRequest,
|
|
172
|
+
described: { mcp?: McpTool; command?: string } = {},
|
|
173
|
+
): PermissionToolCall {
|
|
148
174
|
const toolCall = request.toolCall;
|
|
149
175
|
const kind = toolKindOf(toolCall.kind);
|
|
150
176
|
const locations = toToolLocations(toolCall.locations);
|
|
151
177
|
return {
|
|
152
178
|
...(toolCall.toolCallId && { toolCallId: toolCall.toolCallId }),
|
|
153
|
-
// No `mcp`: an ACP agent names its tools by no rule, so no server or tool can be read from it.
|
|
154
179
|
toolName: toolCall.name ?? toolCall.title ?? toolCall.kind ?? "tool",
|
|
155
180
|
...(kind && { kind }),
|
|
181
|
+
...described,
|
|
156
182
|
...(toolCall.title && { title: toolCall.title }),
|
|
157
183
|
...(locations && { locations }),
|
|
158
184
|
...(isRecord(toolCall.rawInput) && { rawInput: toolCall.rawInput }),
|
|
@@ -182,32 +208,97 @@ export function chooseOutcome(
|
|
|
182
208
|
return CANCELLED_OUTCOME;
|
|
183
209
|
}
|
|
184
210
|
|
|
211
|
+
/** An edit or a read: what `accept_edits` allows unasked. */
|
|
212
|
+
function editOrRead(request: RequestPermissionRequest): boolean {
|
|
213
|
+
const kind = request.toolCall.kind;
|
|
214
|
+
return kind === "edit" || kind === "read";
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// @ref LLP 0016.000#an-acp-agents-permission-mode — accept_edits asks for the rest, as Claude and Codex do
|
|
218
|
+
/**
|
|
219
|
+
* Whether a request is the user's to answer in `mode`, when the turn has a
|
|
220
|
+
* broker: everything in `default`; in `accept_edits` what is neither an edit
|
|
221
|
+
* nor a read, as Claude and Codex ask for a command in that mode. Every other
|
|
222
|
+
* mode decides by itself (`autoDecide`).
|
|
223
|
+
*/
|
|
224
|
+
export function asksInMode(request: RequestPermissionRequest, mode: PermissionMode): boolean {
|
|
225
|
+
return mode === "default" || (mode === "accept_edits" && !editOrRead(request));
|
|
226
|
+
}
|
|
227
|
+
|
|
185
228
|
/**
|
|
186
|
-
* Decide an ACP permission request without the engine broker:
|
|
187
|
-
*
|
|
229
|
+
* Decide an ACP permission request without the engine broker:
|
|
230
|
+
* `bypass_permissions` allows everything, `accept_edits` edits and reads, and
|
|
231
|
+
* every other mode denies.
|
|
188
232
|
*/
|
|
189
233
|
export function autoDecide(
|
|
190
234
|
request: RequestPermissionRequest,
|
|
191
235
|
mode: PermissionMode | undefined,
|
|
192
236
|
): RequestPermissionResponse {
|
|
193
|
-
const
|
|
194
|
-
const allowed =
|
|
195
|
-
mode === "bypass_permissions" ||
|
|
196
|
-
(mode === "accept_edits" && (kind === "edit" || kind === "read"));
|
|
237
|
+
const allowed = mode === "bypass_permissions" || (mode === "accept_edits" && editOrRead(request));
|
|
197
238
|
return chooseOutcome(request.options, allowed);
|
|
198
239
|
}
|
|
199
240
|
|
|
200
|
-
/**
|
|
241
|
+
/** The engine's modes by their ids without case or separators: `acceptEdits`, `accept_edits` and `accept-edits` are one. */
|
|
242
|
+
const MODE_IDS: Record<string, PermissionMode> = {
|
|
243
|
+
default: "default",
|
|
244
|
+
plan: "plan",
|
|
245
|
+
acceptedits: "accept_edits",
|
|
246
|
+
dontask: "dont_ask",
|
|
247
|
+
bypasspermissions: "bypass_permissions",
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/** An ACP mode id the engine has a name for: its own, or Claude's (claude-agent-acp), however it is cased and separated. */
|
|
201
251
|
export function permissionModeOf(modeId: string): PermissionMode | undefined {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
252
|
+
const key = modeId.replace(/[-_\s]/g, "").toLowerCase();
|
|
253
|
+
return Object.hasOwn(MODE_IDS, key) ? MODE_IDS[key] : undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** An agent's own id for an engine mode, where its ids name none (`AcpProfile.modeIds`). */
|
|
257
|
+
export type ModeIds = Partial<Record<PermissionMode, string>>;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* An agent's mode ids and the engine's modes, each way: the agent's own ids
|
|
261
|
+
* first (`own`), then the ids that name a mode (`permissionModeOf`).
|
|
262
|
+
*/
|
|
263
|
+
export function modeNames(own: ModeIds = {}) {
|
|
264
|
+
const modeOf = (modeId: string): PermissionMode | undefined =>
|
|
265
|
+
(Object.keys(own) as PermissionMode[]).find((mode) => own[mode] === modeId) ??
|
|
266
|
+
permissionModeOf(modeId);
|
|
267
|
+
return {
|
|
268
|
+
/** The engine's mode an agent's mode id is, when the engine can name it. */
|
|
269
|
+
modeOf,
|
|
270
|
+
/** The agent's id for `mode`, of the ids it offers. */
|
|
271
|
+
idOf: (mode: PermissionMode, offered: readonly string[]): string | undefined => {
|
|
272
|
+
const id = own[mode];
|
|
273
|
+
if (id !== undefined && offered.includes(id)) return id;
|
|
274
|
+
return offered.find((candidate) => modeOf(candidate) === mode);
|
|
275
|
+
},
|
|
211
276
|
};
|
|
212
|
-
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** A select config option (`model`, `thought_level`). */
|
|
280
|
+
export type SelectOption = SessionConfigOption & { type: "select" };
|
|
281
|
+
|
|
282
|
+
/** Every choice a select option offers, whether listed flat or in groups. */
|
|
283
|
+
export function selectableChoices(option: SelectOption): Array<{ value: string; name: string }> {
|
|
284
|
+
return option.options.flatMap((entry) =>
|
|
285
|
+
"options" in entry
|
|
286
|
+
? entry.options.map(({ value, name }) => ({ value, name }))
|
|
287
|
+
: [{ value: entry.value, name: entry.name }],
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Every value a select option offers. */
|
|
292
|
+
export function selectableValues(option: SelectOption): string[] {
|
|
293
|
+
return selectableChoices(option).map(({ value }) => value);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The agent's select option of a category, as it stands. */
|
|
297
|
+
export function selectOf(
|
|
298
|
+
options: readonly SessionConfigOption[],
|
|
299
|
+
category: "model" | "thought_level",
|
|
300
|
+
): SelectOption | undefined {
|
|
301
|
+
return options.find(
|
|
302
|
+
(option): option is SelectOption => option.category === category && option.type === "select",
|
|
303
|
+
);
|
|
213
304
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { SessionConfigOption } from "@agentclientprotocol/sdk";
|
|
2
|
+
import type { AgentHarness, ModelDescriptor } from "../../../protocol/index.ts";
|
|
3
|
+
import type { ListModelsOptions } from "../base.ts";
|
|
4
|
+
import { listedThinkingLevels } from "../thinking-levels.ts";
|
|
5
|
+
import { type AcpAccount, SESSION_REQUEST_TIMEOUT_MS } from "./account.ts";
|
|
6
|
+
import { type SelectOption, selectOf, selectableChoices, selectableValues } from "./mappings.ts";
|
|
7
|
+
|
|
8
|
+
// @ref LLP 0016.000#an-acp-agents-model-and-thinking-level — a harness that lists its models runs only one of them
|
|
9
|
+
/**
|
|
10
|
+
* The model a turn that names none runs, for a harness that lists its
|
|
11
|
+
* models: the agent's current one when the harness offers it, else the first
|
|
12
|
+
* the agent lists that it offers (a person's own default may be another
|
|
13
|
+
* vendor's model), else none.
|
|
14
|
+
*/
|
|
15
|
+
export function defaultModel(option: SelectOption, offers: (value: string) => boolean) {
|
|
16
|
+
const listed = selectableValues(option);
|
|
17
|
+
// The current one only while the agent still lists it.
|
|
18
|
+
if (listed.includes(option.currentValue) && offers(option.currentValue))
|
|
19
|
+
return option.currentValue;
|
|
20
|
+
return listed.find(offers);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The models an agent offers, from a session with no turn: each value of its
|
|
25
|
+
* `model` option that `offers` takes, labelled by the option's name, the
|
|
26
|
+
* default the one a turn naming none runs (`defaultModel`). A model's levels
|
|
27
|
+
* are those its `thought_level` offers once it is set, which change with the
|
|
28
|
+
* model, so each is set in turn; only the default model's level is its own,
|
|
29
|
+
* the others carrying over the one set before. The read stops between models
|
|
30
|
+
* once `signal` aborts.
|
|
31
|
+
*/
|
|
32
|
+
export function listAcpModels(
|
|
33
|
+
account: AcpAccount,
|
|
34
|
+
harness: AgentHarness,
|
|
35
|
+
offers: (value: string) => boolean,
|
|
36
|
+
options: ListModelsOptions,
|
|
37
|
+
): Promise<ModelDescriptor[]> {
|
|
38
|
+
const { env, signal } = options;
|
|
39
|
+
return account.open({ ...(env && { env }), ...(signal && { signal }) }, async (client, read) => {
|
|
40
|
+
const initial = read.session.configOptions ?? [];
|
|
41
|
+
const model = selectOf(initial, "model");
|
|
42
|
+
if (!model) return [];
|
|
43
|
+
const fallback = defaultModel(model, offers);
|
|
44
|
+
const rows: ModelDescriptor[] = [];
|
|
45
|
+
for (const { value, name } of selectableChoices(model).filter((c) => offers(c.value))) {
|
|
46
|
+
signal?.throwIfAborted();
|
|
47
|
+
let now: readonly SessionConfigOption[] = initial;
|
|
48
|
+
if (value !== model.currentValue) {
|
|
49
|
+
const set = await client.request(
|
|
50
|
+
"session/set_config_option",
|
|
51
|
+
{ sessionId: read.session.sessionId, configId: model.id, value },
|
|
52
|
+
SESSION_REQUEST_TIMEOUT_MS,
|
|
53
|
+
);
|
|
54
|
+
now = set.configOptions;
|
|
55
|
+
}
|
|
56
|
+
const isDefault = value === fallback;
|
|
57
|
+
const thought = selectOf(now, "thought_level");
|
|
58
|
+
const level = isDefault ? thought?.currentValue : undefined;
|
|
59
|
+
rows.push({
|
|
60
|
+
id: value,
|
|
61
|
+
harness,
|
|
62
|
+
label: name,
|
|
63
|
+
...(isDefault && { isDefault }),
|
|
64
|
+
thinking: {
|
|
65
|
+
levels: listedThinkingLevels(thought ? selectableValues(thought) : []),
|
|
66
|
+
...(level && { default: level }),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return rows;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { InitializeResponse } from "@agentclientprotocol/sdk";
|
|
2
|
+
import type {
|
|
3
|
+
AgentCapabilities,
|
|
4
|
+
AgentHarness,
|
|
5
|
+
McpTool,
|
|
6
|
+
RunConfig,
|
|
7
|
+
} from "../../../protocol/index.ts";
|
|
8
|
+
import type { AgentExecuteOptions } from "../base.ts";
|
|
9
|
+
import type { CliLogin } from "../login.ts";
|
|
10
|
+
import type { AcpAccount } from "./account.ts";
|
|
11
|
+
import type { AcpLaunch } from "./client.ts";
|
|
12
|
+
import type { ModeIds } from "./mappings.ts";
|
|
13
|
+
|
|
14
|
+
/** A tool call as the agent names it: ACP's `name`, its input, and once it ended its output. */
|
|
15
|
+
export interface AcpToolCall {
|
|
16
|
+
name?: string | null;
|
|
17
|
+
rawInput?: unknown;
|
|
18
|
+
rawOutput?: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What a harness reads of its agent's tool calls beyond ACP's kind and text (LLP 0002). */
|
|
22
|
+
export interface AcpToolRules {
|
|
23
|
+
/**
|
|
24
|
+
* What a call acts on, from the agent's own names: its MCP server and
|
|
25
|
+
* tool, told apart against the session's own server names, and a
|
|
26
|
+
* command's line. What it does not say is left out.
|
|
27
|
+
*/
|
|
28
|
+
describe(call: AcpToolCall, servers: readonly string[]): { mcp?: McpTool; command?: string };
|
|
29
|
+
/**
|
|
30
|
+
* A finished call's output, where the agent's `rawOutput` holds it: its
|
|
31
|
+
* text, a command's exit code (`metadata.exitCode`; non-zero fails the
|
|
32
|
+
* call), and `failed` for a call the agent says did not run, with no exit
|
|
33
|
+
* code to say it (the text then says why). Undefined: ACP's reading.
|
|
34
|
+
*/
|
|
35
|
+
output?(call: AcpToolCall): { text: string; exitCode?: number; failed?: boolean } | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// @ref LLP 0016.000#an-acp-agents-profile — a harness that runs one agent over ACP is a profile, internal to the engine
|
|
39
|
+
/**
|
|
40
|
+
* What one ACP agent decides that the protocol does not: the name it runs
|
|
41
|
+
* under, what it supports (`capabilities.steering`: a prompt sent while one
|
|
42
|
+
* runs is input to the running turn), how it starts, and where it departs
|
|
43
|
+
* from what its `initialize` says. The protocol is `ProfiledAcpAgent`'s, so a harness
|
|
44
|
+
* that runs one agent over ACP is a profile, never a second client; it
|
|
45
|
+
* reaches the agent only through its harness's registration
|
|
46
|
+
* (`ProfiledAcpAgent`). Operator-level only: nothing in it comes from the
|
|
47
|
+
* wire.
|
|
48
|
+
*/
|
|
49
|
+
export interface AcpProfile {
|
|
50
|
+
/** The harness it runs under: its turns, its processes and its host-tool leases say so. */
|
|
51
|
+
readonly harness: AgentHarness;
|
|
52
|
+
/** What it supports (LLP 0001, D22). */
|
|
53
|
+
readonly capabilities: AgentCapabilities;
|
|
54
|
+
/**
|
|
55
|
+
* The agent subprocess to start, undefined when none is configured. Never
|
|
56
|
+
* from the wire: the command is arbitrary code execution.
|
|
57
|
+
*/
|
|
58
|
+
launch(): Promise<AcpLaunch | undefined> | AcpLaunch | undefined;
|
|
59
|
+
/** Throws for a turn it cannot run (a setting the agent cannot honour), first in the turn, before anything starts. */
|
|
60
|
+
admit?(options: AgentExecuteOptions): void;
|
|
61
|
+
/** Throws for an agent it cannot drive (a version below its floor), at once after `initialize`. */
|
|
62
|
+
accept?(init: InitializeResponse): void;
|
|
63
|
+
/** The agent takes HTTP MCP servers, though its `initialize` does not say so. */
|
|
64
|
+
readonly httpMcp?: boolean;
|
|
65
|
+
/** The agent's own id for an engine mode, where its ids name none (`permissionModeOf`). */
|
|
66
|
+
readonly modeIds?: ModeIds;
|
|
67
|
+
/**
|
|
68
|
+
* What a new conversation starts with and keeps for its life: `meta(options)`
|
|
69
|
+
* goes with `session/new`, never with a resume or a load. A later turn on
|
|
70
|
+
* that conversation whose `meta` differs did not apply `settings`.
|
|
71
|
+
*/
|
|
72
|
+
readonly newSession?: {
|
|
73
|
+
readonly settings: readonly (keyof RunConfig)[];
|
|
74
|
+
meta(options: AgentExecuteOptions): Record<string, unknown> | undefined;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Present: the harness lists its models, and a turn runs only one it
|
|
78
|
+
* `offers`, also when it names none. Absent: a turn names any the agent
|
|
79
|
+
* offers.
|
|
80
|
+
*/
|
|
81
|
+
readonly models?: { offers(value: string): boolean };
|
|
82
|
+
/** What its tool calls are beyond ACP's kind; the harness's adapter reads them the same. */
|
|
83
|
+
readonly tools?: AcpToolRules;
|
|
84
|
+
/**
|
|
85
|
+
* Its CLI's own login (`Agent.login`), which reads the account through
|
|
86
|
+
* the agent's own sessions with no turn. Absent: the agent signs in on its own.
|
|
87
|
+
*/
|
|
88
|
+
login?(account: AcpAccount): CliLogin;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const CAPABILITIES: AgentCapabilities = {
|
|
92
|
+
multiTurn: true,
|
|
93
|
+
// A requested resume fails if the target agent cannot load saved sessions.
|
|
94
|
+
sessionResume: true,
|
|
95
|
+
// v1 has no portable model parameter. A requested model or thinking level
|
|
96
|
+
// is applied only when the agent offers a `model` / `thought_level` config
|
|
97
|
+
// option, so neither is promised here.
|
|
98
|
+
modelSwitch: "unsupported",
|
|
99
|
+
thinkingLevels: false,
|
|
100
|
+
// The most an agent can take: its `initialize` decides, image data with its
|
|
101
|
+
// `image` prompt capability and files beyond text with `embeddedContext`.
|
|
102
|
+
images: true,
|
|
103
|
+
files: ["text", "pdf", "binary"],
|
|
104
|
+
mcpServers: true,
|
|
105
|
+
permissionRequests: true,
|
|
106
|
+
// The answer is an option id.
|
|
107
|
+
rejectionMessages: false,
|
|
108
|
+
ignoredSettings: [
|
|
109
|
+
// ACP v1 has no system prompt: session/new takes the folder, the MCP
|
|
110
|
+
// servers and the extra directories only (`ProfiledAcpAgent.spawn`).
|
|
111
|
+
"systemPromptAppend",
|
|
112
|
+
// A prompt runs until the agent ends it: ACP v1 has no turn limit.
|
|
113
|
+
"maxTurns",
|
|
114
|
+
// session/resume and session/load name a session, not a message in it.
|
|
115
|
+
"resumeSessionAt",
|
|
116
|
+
// The agent's credentials are its launch command's: the client gets the
|
|
117
|
+
// launch, the folder and the env only (`AcpClientOptions`).
|
|
118
|
+
"apiKey",
|
|
119
|
+
// ACP v1 cannot ask an agent to run without its tools.
|
|
120
|
+
"disableTools",
|
|
121
|
+
] satisfies Array<keyof RunConfig>,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** The `acp` harness: any ACP v1 agent the operator launches, taken at its `initialize`'s word. */
|
|
125
|
+
export function genericAcpProfile(launch: AcpProfile["launch"]): AcpProfile {
|
|
126
|
+
return { harness: "acp", capabilities: CAPABILITIES, launch };
|
|
127
|
+
}
|