@tbrandenburg/opencode-a2a-lite 0.3.2 → 0.4.0
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 +9 -1
- package/dist/package.json +1 -1
- package/dist/src/acp-client.js +27 -4
- package/dist/src/bridge-error.js +7 -0
- package/dist/src/cli-options.js +3 -1
- package/dist/src/cli.js +3 -1
- package/dist/src/executor.js +46 -4
- package/dist/src/server.js +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ launcher still use Linux-specific tooling.
|
|
|
88
88
|
## Usage
|
|
89
89
|
|
|
90
90
|
```text
|
|
91
|
-
opencode-a2a-lite --workspace <path> [--port <0..65535>]
|
|
91
|
+
opencode-a2a-lite --workspace <path> [--port <0..65535>] [--publish-activity]
|
|
92
92
|
opencode-a2a-lite --help | --version
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -124,6 +124,14 @@ reusing the ACP session for that context.
|
|
|
124
124
|
- Only ACP `end_turn` means completed; confirmed `cancelled` means canceled.
|
|
125
125
|
Errors and other stop reasons fail the task without publishing private diagnostics.
|
|
126
126
|
- Permission requests are rejected/canceled, not silently approved.
|
|
127
|
+
- A failed task names the failing phase (for example `ACP session creation failed`); the
|
|
128
|
+
underlying OpenCode diagnostic is never published. A bridge failure is permanent until restart.
|
|
129
|
+
- Every task's metadata carries `opencode.sessionId` and `opencode.stopReason` (after a session
|
|
130
|
+
exists). The session id is the key for finding the full transcript in OpenCode itself.
|
|
131
|
+
- `--publish-activity` (off by default) adds an `activity` artifact of data parts with only tool
|
|
132
|
+
call id, title, kind and status; tool inputs, outputs and reasoning are never published. Titles
|
|
133
|
+
may reveal paths or commands, so enable it only for clients you trust. The Agent Card then
|
|
134
|
+
declares the `urn:opencode-a2a-lite:activity:v1` extension.
|
|
127
135
|
- Defaults: 30-second startup/session allocation, 120-second prompt, 5-second
|
|
128
136
|
cancellation and 5-second ACP shutdown. Failure retires the unhealthy bridge.
|
|
129
137
|
- Streaming sends stable artifact IDs and ordered append events. Task states are
|
package/dist/package.json
CHANGED
package/dist/src/acp-client.js
CHANGED
|
@@ -3,8 +3,20 @@ import { isAbsolute } from "node:path";
|
|
|
3
3
|
import { Readable, Writable } from "node:stream";
|
|
4
4
|
import * as acp from "@agentclientprotocol/sdk";
|
|
5
5
|
import manifest from "../package.json" with { type: "json" };
|
|
6
|
+
import { BridgeError } from "./bridge-error.js";
|
|
6
7
|
import { supportedOpenCode } from "./opencode-version.js";
|
|
7
8
|
import { StartupError } from "./startup-error.js";
|
|
9
|
+
// Only identifying fields are forwarded; tool inputs and outputs never leave the bridge.
|
|
10
|
+
function toolActivity(update) {
|
|
11
|
+
if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update")
|
|
12
|
+
return;
|
|
13
|
+
return {
|
|
14
|
+
toolCallId: update.toolCallId,
|
|
15
|
+
...(update.title ? { title: update.title } : {}),
|
|
16
|
+
...(update.kind ? { kind: update.kind } : {}),
|
|
17
|
+
...(update.status ? { status: update.status } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
8
20
|
export function createAcpBridge(options) {
|
|
9
21
|
if (!isAbsolute(options.cwd))
|
|
10
22
|
throw new Error("ACP workspace must be absolute");
|
|
@@ -32,7 +44,7 @@ export function createAcpBridge(options) {
|
|
|
32
44
|
function fail(message) {
|
|
33
45
|
if (failure.signal.aborted)
|
|
34
46
|
return;
|
|
35
|
-
failure.abort(message instanceof StartupError ? message : new
|
|
47
|
+
failure.abort(message instanceof StartupError ? message : new BridgeError(message));
|
|
36
48
|
ready = false;
|
|
37
49
|
connection?.close();
|
|
38
50
|
// Retain the cleanup result for close(); request errors never contain peer diagnostics.
|
|
@@ -70,14 +82,14 @@ export function createAcpBridge(options) {
|
|
|
70
82
|
}
|
|
71
83
|
function requireConnection(sessionId) {
|
|
72
84
|
if (!ready || !connection || failure.signal.aborted || stopping)
|
|
73
|
-
throw new
|
|
85
|
+
throw new BridgeError("ACP bridge unavailable");
|
|
74
86
|
if (sessionId !== undefined && !sessions.has(sessionId))
|
|
75
87
|
throw new Error("Unknown ACP session");
|
|
76
88
|
return connection;
|
|
77
89
|
}
|
|
78
90
|
function start() {
|
|
79
91
|
if (failure.signal.aborted || stopping)
|
|
80
|
-
return Promise.reject(new
|
|
92
|
+
return Promise.reject(new BridgeError("ACP bridge unavailable"));
|
|
81
93
|
if (starting)
|
|
82
94
|
return starting;
|
|
83
95
|
starting = bounded(async () => {
|
|
@@ -144,6 +156,16 @@ export function createAcpBridge(options) {
|
|
|
144
156
|
if (notification.params._meta?.["opencode/child-session"] !== undefined ||
|
|
145
157
|
update._meta?.["opencode/child-session"] !== undefined)
|
|
146
158
|
return;
|
|
159
|
+
const activity = toolActivity(update);
|
|
160
|
+
if (activity) {
|
|
161
|
+
try {
|
|
162
|
+
turn.onActivity?.(activity);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
fail("ACP activity callback failed");
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
147
169
|
if (update.sessionUpdate !== "agent_message_chunk" || update.content.type !== "text")
|
|
148
170
|
return;
|
|
149
171
|
if (update.content._meta?.["opencode/child-session"] !== undefined)
|
|
@@ -183,13 +205,14 @@ export function createAcpBridge(options) {
|
|
|
183
205
|
sessions.add(response.sessionId);
|
|
184
206
|
return response;
|
|
185
207
|
}
|
|
186
|
-
async function prompt(sessionId, text, onText) {
|
|
208
|
+
async function prompt(sessionId, text, onText, onActivity) {
|
|
187
209
|
const current = requireConnection(sessionId);
|
|
188
210
|
if (turn)
|
|
189
211
|
throw new Error("ACP prompt in progress");
|
|
190
212
|
const active = {
|
|
191
213
|
sessionId,
|
|
192
214
|
onText,
|
|
215
|
+
onActivity,
|
|
193
216
|
cancelled: false,
|
|
194
217
|
settled: false,
|
|
195
218
|
cancellation: undefined,
|
package/dist/src/cli-options.js
CHANGED
|
@@ -17,10 +17,12 @@ export function parseOptions(args, env) {
|
|
|
17
17
|
server: {
|
|
18
18
|
workspace,
|
|
19
19
|
port: parsePort(flags.get("--port") ?? env.A2A_PORT),
|
|
20
|
+
...(flags.has("--publish-activity") ? { executor: { activity: true } } : {}),
|
|
20
21
|
...(identity === undefined ? {} : { identity }),
|
|
21
22
|
},
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
const VALUELESS = new Set(["--help", "--version", "--publish-activity"]);
|
|
24
26
|
function parseFlags(args) {
|
|
25
27
|
const flags = new Map();
|
|
26
28
|
for (let index = 0; index < args.length; index += 1) {
|
|
@@ -28,7 +30,7 @@ function parseFlags(args) {
|
|
|
28
30
|
const flag = token === "-h" ? "--help" : token === "-v" ? "--version" : token;
|
|
29
31
|
if (flag === undefined || flags.has(flag))
|
|
30
32
|
throw new StartupError("arguments");
|
|
31
|
-
if (flag
|
|
33
|
+
if (VALUELESS.has(flag)) {
|
|
32
34
|
flags.set(flag, "");
|
|
33
35
|
continue;
|
|
34
36
|
}
|
package/dist/src/cli.js
CHANGED
|
@@ -5,13 +5,15 @@ import { reportStartupError } from "./startup-error.js";
|
|
|
5
5
|
async function main() {
|
|
6
6
|
const options = parseOptions(process.argv.slice(2), process.env);
|
|
7
7
|
if (options.action === "help") {
|
|
8
|
-
console.log(`Usage: opencode-a2a-lite --workspace <path> [--port <0..65535>]
|
|
8
|
+
console.log(`Usage: opencode-a2a-lite --workspace <path> [--port <0..65535>] [--publish-activity]
|
|
9
9
|
|
|
10
10
|
Start the foreground, unauthenticated A2A gateway.
|
|
11
11
|
Linux or macOS (experimental), Bun 1.4.4, stable OpenCode 2.2.7 or newer on PATH, and configured provider required.
|
|
12
12
|
|
|
13
13
|
--workspace <path> Explicitly trust this directory; relative paths are resolved.
|
|
14
14
|
--port <0..65535> Port (default 41241; 0 selects a free port).
|
|
15
|
+
--publish-activity Also publish an "activity" artifact with tool call ids, titles, kinds and
|
|
16
|
+
statuses (no inputs or outputs). Titles may reveal paths or commands.
|
|
15
17
|
--help, -h Show help without starting OpenCode.
|
|
16
18
|
--version, -v Print package version without starting OpenCode.
|
|
17
19
|
|
package/dist/src/executor.js
CHANGED
|
@@ -2,7 +2,17 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { Role, TaskState } from "@a2a-js/sdk";
|
|
3
3
|
import { TaskNotCancelableError } from "@a2a-js/sdk/errors";
|
|
4
4
|
import { AgentEvent, } from "@a2a-js/sdk/server";
|
|
5
|
+
import { BridgeError } from "./bridge-error.js";
|
|
5
6
|
export const EXPLICIT_CONTEXT = "opencode.explicitContext";
|
|
7
|
+
export const ACTIVITY_EXTENSION = "urn:opencode-a2a-lite:activity:v1";
|
|
8
|
+
function dataPart(value) {
|
|
9
|
+
return {
|
|
10
|
+
content: { $case: "data", value },
|
|
11
|
+
mediaType: "application/json",
|
|
12
|
+
filename: "",
|
|
13
|
+
metadata: undefined,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
6
16
|
function textPart(text) {
|
|
7
17
|
return {
|
|
8
18
|
content: { $case: "text", value: text },
|
|
@@ -21,7 +31,10 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
21
31
|
const taskId = ctx.taskId;
|
|
22
32
|
const contextId = ctx.contextId;
|
|
23
33
|
const artifactId = randomUUID();
|
|
34
|
+
const activityId = randomUUID();
|
|
35
|
+
const meta = {};
|
|
24
36
|
let emitted = false;
|
|
37
|
+
let activityEmitted = false;
|
|
25
38
|
let terminal = false;
|
|
26
39
|
function status(state, text) {
|
|
27
40
|
bus.publish(AgentEvent.statusUpdate({
|
|
@@ -43,7 +56,7 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
43
56
|
}
|
|
44
57
|
: undefined,
|
|
45
58
|
},
|
|
46
|
-
metadata: undefined,
|
|
59
|
+
metadata: Object.keys(meta).length ? { ...meta } : undefined,
|
|
47
60
|
}));
|
|
48
61
|
}
|
|
49
62
|
function chunk(text, lastChunk = false) {
|
|
@@ -64,10 +77,31 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
64
77
|
}));
|
|
65
78
|
emitted = true;
|
|
66
79
|
}
|
|
80
|
+
function activity(entry) {
|
|
81
|
+
const lastChunk = entry === undefined;
|
|
82
|
+
bus.publish(AgentEvent.artifactUpdate({
|
|
83
|
+
taskId,
|
|
84
|
+
contextId,
|
|
85
|
+
artifact: {
|
|
86
|
+
artifactId: activityId,
|
|
87
|
+
name: "activity",
|
|
88
|
+
description: "Tool activity summary",
|
|
89
|
+
parts: [entry ? dataPart(entry) : textPart("")],
|
|
90
|
+
metadata: undefined,
|
|
91
|
+
extensions: [ACTIVITY_EXTENSION],
|
|
92
|
+
},
|
|
93
|
+
append: activityEmitted,
|
|
94
|
+
lastChunk,
|
|
95
|
+
metadata: undefined,
|
|
96
|
+
}));
|
|
97
|
+
activityEmitted = true;
|
|
98
|
+
}
|
|
67
99
|
function finish(state, text) {
|
|
68
100
|
terminal = true;
|
|
69
101
|
if (emitted)
|
|
70
102
|
chunk("", true);
|
|
103
|
+
if (activityEmitted)
|
|
104
|
+
activity();
|
|
71
105
|
status(state, text);
|
|
72
106
|
}
|
|
73
107
|
bus.publish(AgentEvent.task(ctx.task ?? {
|
|
@@ -123,11 +157,18 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
123
157
|
try {
|
|
124
158
|
const sessionId = existing ?? (await bridge.newSession()).sessionId;
|
|
125
159
|
record.sessionId = sessionId;
|
|
160
|
+
meta["opencode.sessionId"] = sessionId;
|
|
126
161
|
sessions.set(contextId, sessionId);
|
|
127
162
|
const response = await bridge.prompt(sessionId, text, (value) => {
|
|
128
163
|
if (!terminal && value)
|
|
129
164
|
chunk(value);
|
|
130
|
-
}
|
|
165
|
+
}, options.activity
|
|
166
|
+
? (entry) => {
|
|
167
|
+
if (!terminal)
|
|
168
|
+
activity(entry);
|
|
169
|
+
}
|
|
170
|
+
: undefined);
|
|
171
|
+
meta["opencode.stopReason"] = response.stopReason;
|
|
131
172
|
if (response.stopReason === "end_turn") {
|
|
132
173
|
finish(TaskState.TASK_STATE_COMPLETED);
|
|
133
174
|
return;
|
|
@@ -139,10 +180,11 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
139
180
|
sessions.delete(contextId);
|
|
140
181
|
finish(TaskState.TASK_STATE_FAILED, "ACP did not complete the turn");
|
|
141
182
|
}
|
|
142
|
-
catch {
|
|
183
|
+
catch (error) {
|
|
143
184
|
sessions.delete(contextId);
|
|
185
|
+
// Only gateway-authored phase messages are published; peer diagnostics never are.
|
|
144
186
|
if (!terminal)
|
|
145
|
-
finish(TaskState.TASK_STATE_FAILED, "ACP execution failed");
|
|
187
|
+
finish(TaskState.TASK_STATE_FAILED, error instanceof BridgeError ? error.message : "ACP execution failed");
|
|
146
188
|
}
|
|
147
189
|
finally {
|
|
148
190
|
record.terminal = true;
|
package/dist/src/server.js
CHANGED
|
@@ -7,7 +7,7 @@ import manifest from "../package.json" with { type: "json" };
|
|
|
7
7
|
import { A2A_PROTOCOL_VERSION, AGENT_CARD_PATH } from "@a2a-js/sdk";
|
|
8
8
|
import { agentCardHandler, jsonRpcHandler, UserBuilder } from "@a2a-js/sdk/server/express";
|
|
9
9
|
import { createAcpBridge } from "./acp-client.js";
|
|
10
|
-
import { createAgentExecutor, EXPLICIT_CONTEXT } from "./executor.js";
|
|
10
|
+
import { ACTIVITY_EXTENSION, createAgentExecutor, EXPLICIT_CONTEXT, } from "./executor.js";
|
|
11
11
|
import { createRequestHandler } from "./request-handler.js";
|
|
12
12
|
import { parseOptions } from "./cli-options.js";
|
|
13
13
|
import { reportStartupError, StartupError } from "./startup-error.js";
|
|
@@ -104,7 +104,16 @@ export function createGateway(options) {
|
|
|
104
104
|
streaming: true,
|
|
105
105
|
pushNotifications: false,
|
|
106
106
|
extendedAgentCard: false,
|
|
107
|
-
extensions:
|
|
107
|
+
extensions: options.executor?.activity
|
|
108
|
+
? [
|
|
109
|
+
{
|
|
110
|
+
uri: ACTIVITY_EXTENSION,
|
|
111
|
+
description: "Adds an optional 'activity' artifact of tool call ids, titles, kinds and statuses.",
|
|
112
|
+
required: false,
|
|
113
|
+
params: undefined,
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
: [],
|
|
108
117
|
},
|
|
109
118
|
securitySchemes: {},
|
|
110
119
|
securityRequirements: [],
|
|
@@ -191,6 +200,8 @@ export async function launchGateway(options) {
|
|
|
191
200
|
const cardUrl = new URL(".well-known/agent-card.json", ready.url).href;
|
|
192
201
|
status("ready", `gateway · ${ready.url}`);
|
|
193
202
|
status("workspace", options.workspace);
|
|
203
|
+
if (options.executor?.activity)
|
|
204
|
+
status("activity", "tool call titles are published; they may reveal paths or commands");
|
|
194
205
|
status("agent card", cardUrl);
|
|
195
206
|
status("connect", `a2a send -a ${ready.url} "Reply with a short greeting." --stream`);
|
|
196
207
|
status("stop", "press Ctrl-C to stop the gateway");
|