gopherhole_openclaw_a2a 0.4.4 → 0.4.6
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/dist/src/channel.js +65 -9
- package/dist/src/connection.d.ts +5 -2
- package/dist/src/connection.js +4 -4
- package/openclaw.plugin.json +114 -0
- package/package.json +2 -2
package/dist/src/channel.js
CHANGED
|
@@ -7,6 +7,8 @@ const DEFAULT_ACCOUNT_ID = 'default';
|
|
|
7
7
|
function normalizeAccountId(id) {
|
|
8
8
|
return id?.trim()?.toLowerCase() || DEFAULT_ACCOUNT_ID;
|
|
9
9
|
}
|
|
10
|
+
import { existsSync, readFileSync } from 'fs';
|
|
11
|
+
import { join } from 'path';
|
|
10
12
|
import { A2AConnectionManager } from './connection.js';
|
|
11
13
|
import { sendChatMessage } from './gateway-client.js';
|
|
12
14
|
import { a2aLog } from './logger.js';
|
|
@@ -16,6 +18,27 @@ let currentRuntime = null;
|
|
|
16
18
|
export function setA2ARuntime(runtime) {
|
|
17
19
|
currentRuntime = runtime;
|
|
18
20
|
}
|
|
21
|
+
function loadAgentSecrets(agentId) {
|
|
22
|
+
const secretsDir = join(process.cwd(), '.gopherhole', 'secrets');
|
|
23
|
+
const filePath = join(secretsDir, `${agentId}.json`);
|
|
24
|
+
if (!existsSync(filePath))
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
const raw = readFileSync(filePath, 'utf-8');
|
|
28
|
+
const parsed = JSON.parse(raw);
|
|
29
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
30
|
+
return null;
|
|
31
|
+
const secrets = {};
|
|
32
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
33
|
+
if (typeof v === 'string')
|
|
34
|
+
secrets[k] = v;
|
|
35
|
+
}
|
|
36
|
+
return Object.keys(secrets).length > 0 ? secrets : null;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
19
42
|
function resolveA2AConfig(cfg) {
|
|
20
43
|
return cfg?.channels?.a2a ?? {};
|
|
21
44
|
}
|
|
@@ -145,7 +168,8 @@ export const a2aPlugin = {
|
|
|
145
168
|
return { channel: 'a2a', success: false, error: 'A2A not connected' };
|
|
146
169
|
}
|
|
147
170
|
try {
|
|
148
|
-
const
|
|
171
|
+
const secrets = loadAgentSecrets(to) ?? undefined;
|
|
172
|
+
const response = await connectionManager.sendMessage(to, text, secrets ? { secrets } : undefined);
|
|
149
173
|
return {
|
|
150
174
|
channel: 'a2a',
|
|
151
175
|
success: true,
|
|
@@ -203,9 +227,19 @@ export const a2aPlugin = {
|
|
|
203
227
|
const config = account.config;
|
|
204
228
|
ctx.log?.info(`[a2a] Starting A2A channel`);
|
|
205
229
|
ctx.setStatus({ accountId: account.accountId });
|
|
206
|
-
|
|
230
|
+
const localConnection = new A2AConnectionManager(config);
|
|
231
|
+
// Defensive: prior plugin versions leaked a connection on every
|
|
232
|
+
// supervisor auto-restart. If a stale manager is still around, stop it
|
|
233
|
+
// before overwriting the module-level singleton.
|
|
234
|
+
if (connectionManager && connectionManager !== localConnection) {
|
|
235
|
+
try {
|
|
236
|
+
await connectionManager.stop();
|
|
237
|
+
}
|
|
238
|
+
catch { /* ignore */ }
|
|
239
|
+
}
|
|
240
|
+
connectionManager = localConnection;
|
|
207
241
|
// Set up message handler for incoming messages
|
|
208
|
-
|
|
242
|
+
localConnection.setMessageHandler(async (agentId, message) => {
|
|
209
243
|
if (message.type === 'message' && message.from) {
|
|
210
244
|
const text = message.content?.parts
|
|
211
245
|
?.filter((p) => p.kind === 'text')
|
|
@@ -252,24 +286,46 @@ export const a2aPlugin = {
|
|
|
252
286
|
}
|
|
253
287
|
}
|
|
254
288
|
});
|
|
255
|
-
await
|
|
289
|
+
await localConnection.start();
|
|
256
290
|
ctx.setStatus({
|
|
257
291
|
accountId: account.accountId,
|
|
258
292
|
running: true,
|
|
259
293
|
lastStartAt: Date.now(),
|
|
260
294
|
});
|
|
261
295
|
ctx.log?.info(`[a2a] A2A channel started`);
|
|
262
|
-
//
|
|
263
|
-
|
|
296
|
+
// OpenClaw's channel supervisor treats resolution of this promise as
|
|
297
|
+
// "channel exited" and immediately schedules an auto-restart. Hold the
|
|
298
|
+
// channel open for its lifetime by blocking on the abort signal — the
|
|
299
|
+
// supervisor aborts it only when it actually wants us to stop.
|
|
300
|
+
try {
|
|
301
|
+
await new Promise((resolve) => {
|
|
302
|
+
const signal = ctx.abortSignal;
|
|
303
|
+
if (!signal)
|
|
304
|
+
return; // no signal provided: never resolve
|
|
305
|
+
if (signal.aborted) {
|
|
306
|
+
resolve();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
signal.addEventListener('abort', () => resolve(), { once: true });
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
264
313
|
ctx.log?.info(`[a2a] Stopping A2A channel`);
|
|
265
|
-
|
|
266
|
-
|
|
314
|
+
try {
|
|
315
|
+
await localConnection.stop();
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
ctx.log?.error?.(`[a2a] Error during stop: ${err.message}`);
|
|
319
|
+
}
|
|
320
|
+
if (connectionManager === localConnection) {
|
|
321
|
+
connectionManager = null;
|
|
322
|
+
}
|
|
267
323
|
ctx.setStatus({
|
|
268
324
|
accountId: account.accountId,
|
|
269
325
|
running: false,
|
|
270
326
|
lastStopAt: Date.now(),
|
|
271
327
|
});
|
|
272
|
-
}
|
|
328
|
+
}
|
|
273
329
|
},
|
|
274
330
|
},
|
|
275
331
|
};
|
package/dist/src/connection.d.ts
CHANGED
|
@@ -25,7 +25,10 @@ export declare class A2AConnectionManager {
|
|
|
25
25
|
/**
|
|
26
26
|
* Send a message to another agent via GopherHole and wait for response
|
|
27
27
|
*/
|
|
28
|
-
sendMessage(targetAgentId: string, text: string,
|
|
28
|
+
sendMessage(targetAgentId: string, text: string, opts?: {
|
|
29
|
+
contextId?: string;
|
|
30
|
+
secrets?: Record<string, string>;
|
|
31
|
+
}): Promise<A2AResponse>;
|
|
29
32
|
/**
|
|
30
33
|
* Send a multi-part message via GopherHole hub
|
|
31
34
|
* Supports text, images, and other MIME types
|
|
@@ -35,7 +38,7 @@ export declare class A2AConnectionManager {
|
|
|
35
38
|
text?: string;
|
|
36
39
|
data?: string;
|
|
37
40
|
mimeType?: string;
|
|
38
|
-
}>, contextId?: string): Promise<A2AResponse>;
|
|
41
|
+
}>, contextId?: string, secrets?: Record<string, string>): Promise<A2AResponse>;
|
|
39
42
|
/**
|
|
40
43
|
* Send a response to an incoming message via GopherHole
|
|
41
44
|
* Uses SDK's respond() method to complete the original task
|
package/dist/src/connection.js
CHANGED
|
@@ -197,14 +197,14 @@ export class A2AConnectionManager {
|
|
|
197
197
|
/**
|
|
198
198
|
* Send a message to another agent via GopherHole and wait for response
|
|
199
199
|
*/
|
|
200
|
-
async sendMessage(targetAgentId, text,
|
|
201
|
-
return this.sendPartsViaGopherHole(targetAgentId, [{ kind: 'text', text }]);
|
|
200
|
+
async sendMessage(targetAgentId, text, opts) {
|
|
201
|
+
return this.sendPartsViaGopherHole(targetAgentId, [{ kind: 'text', text }], opts?.contextId, opts?.secrets);
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* Send a multi-part message via GopherHole hub
|
|
205
205
|
* Supports text, images, and other MIME types
|
|
206
206
|
*/
|
|
207
|
-
async sendPartsViaGopherHole(targetAgentId, parts, contextId) {
|
|
207
|
+
async sendPartsViaGopherHole(targetAgentId, parts, contextId, secrets) {
|
|
208
208
|
if (!this.gopherhole || !this.connected) {
|
|
209
209
|
throw new Error('GopherHole not connected');
|
|
210
210
|
}
|
|
@@ -219,7 +219,7 @@ export class A2AConnectionManager {
|
|
|
219
219
|
data: p.data,
|
|
220
220
|
mimeType: p.mimeType,
|
|
221
221
|
})),
|
|
222
|
-
}, { contextId });
|
|
222
|
+
}, { contextId, secrets });
|
|
223
223
|
// Wait for task completion
|
|
224
224
|
const completedTask = await this.gopherhole.waitForTask(task.id, {
|
|
225
225
|
pollIntervalMs: 1000,
|
package/openclaw.plugin.json
CHANGED
|
@@ -10,5 +10,119 @@
|
|
|
10
10
|
"description": "Enable the plugin"
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
},
|
|
14
|
+
"channelConfigs": {
|
|
15
|
+
"a2a": {
|
|
16
|
+
"label": "A2A (GopherHole)",
|
|
17
|
+
"description": "Agent-to-agent communication over the GopherHole hub. Lets other AI agents discover and message this OpenClaw instance.",
|
|
18
|
+
"schema": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"properties": {
|
|
22
|
+
"enabled": {
|
|
23
|
+
"type": "boolean",
|
|
24
|
+
"default": false,
|
|
25
|
+
"description": "Enable the A2A channel"
|
|
26
|
+
},
|
|
27
|
+
"apiKey": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "GopherHole API key (starts with gph_)"
|
|
30
|
+
},
|
|
31
|
+
"bridgeUrl": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"format": "uri",
|
|
34
|
+
"default": "wss://hub.gopherhole.ai/ws",
|
|
35
|
+
"description": "WebSocket URL for the GopherHole hub"
|
|
36
|
+
},
|
|
37
|
+
"agentId": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "Canonical hub-side agent ID (e.g. agent-9a2fb7a8). Assigned by the hub; look it up via the GopherHole admin dashboard."
|
|
40
|
+
},
|
|
41
|
+
"agentName": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "Display name for this agent; used to build the default agent card when agentCard is not provided."
|
|
44
|
+
},
|
|
45
|
+
"agentCard": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"description": "Override the default agent card sent to the hub on connect.",
|
|
48
|
+
"properties": {
|
|
49
|
+
"name": { "type": "string" },
|
|
50
|
+
"description": { "type": "string" },
|
|
51
|
+
"url": { "type": "string", "format": "uri" },
|
|
52
|
+
"version": { "type": "string" },
|
|
53
|
+
"skills": {
|
|
54
|
+
"type": "array",
|
|
55
|
+
"items": {
|
|
56
|
+
"type": "object",
|
|
57
|
+
"properties": {
|
|
58
|
+
"id": { "type": "string" },
|
|
59
|
+
"name": { "type": "string" },
|
|
60
|
+
"description": { "type": "string" },
|
|
61
|
+
"tags": { "type": "array", "items": { "type": "string" } },
|
|
62
|
+
"examples": { "type": "array", "items": { "type": "string" } },
|
|
63
|
+
"inputModes": { "type": "array", "items": { "type": "string" } },
|
|
64
|
+
"outputModes": { "type": "array", "items": { "type": "string" } }
|
|
65
|
+
},
|
|
66
|
+
"required": ["id", "name"]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"reconnectIntervalMs": {
|
|
72
|
+
"type": "integer",
|
|
73
|
+
"minimum": 100,
|
|
74
|
+
"default": 5000,
|
|
75
|
+
"description": "Initial reconnect delay in milliseconds. The SDK backs off exponentially up to a 5-minute cap."
|
|
76
|
+
},
|
|
77
|
+
"requestTimeoutMs": {
|
|
78
|
+
"type": "integer",
|
|
79
|
+
"minimum": 1000,
|
|
80
|
+
"default": 180000,
|
|
81
|
+
"description": "Timeout in milliseconds for outbound requests and inbound message-response waits."
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"uiHints": {
|
|
86
|
+
"": {
|
|
87
|
+
"label": "A2A (GopherHole)",
|
|
88
|
+
"help": "Connect this OpenClaw instance to the GopherHole hub so other AI agents can discover and message it. Get an API key at https://gopherhole.ai."
|
|
89
|
+
},
|
|
90
|
+
"apiKey": {
|
|
91
|
+
"label": "API Key",
|
|
92
|
+
"help": "Your GopherHole API key (starts with gph_). Create one at https://gopherhole.ai settings.",
|
|
93
|
+
"sensitive": true,
|
|
94
|
+
"placeholder": "gph_..."
|
|
95
|
+
},
|
|
96
|
+
"bridgeUrl": {
|
|
97
|
+
"label": "Bridge URL",
|
|
98
|
+
"help": "WebSocket endpoint of the GopherHole hub. Only override for self-hosted deployments.",
|
|
99
|
+
"advanced": true,
|
|
100
|
+
"placeholder": "wss://hub.gopherhole.ai/ws"
|
|
101
|
+
},
|
|
102
|
+
"agentId": {
|
|
103
|
+
"label": "Agent ID",
|
|
104
|
+
"help": "Hub-assigned agent ID. Find it in your GopherHole admin dashboard.",
|
|
105
|
+
"advanced": true,
|
|
106
|
+
"placeholder": "agent-xxxxxxxx"
|
|
107
|
+
},
|
|
108
|
+
"agentName": {
|
|
109
|
+
"label": "Display Name",
|
|
110
|
+
"help": "Human-readable name shown in agent cards and discovery listings."
|
|
111
|
+
},
|
|
112
|
+
"agentCard": {
|
|
113
|
+
"label": "Agent Card",
|
|
114
|
+
"help": "Advanced: fully override the agent card metadata (name, description, version, skills) registered with the hub on connect.",
|
|
115
|
+
"advanced": true
|
|
116
|
+
},
|
|
117
|
+
"reconnectIntervalMs": {
|
|
118
|
+
"label": "Reconnect Interval (ms)",
|
|
119
|
+
"advanced": true
|
|
120
|
+
},
|
|
121
|
+
"requestTimeoutMs": {
|
|
122
|
+
"label": "Request Timeout (ms)",
|
|
123
|
+
"advanced": true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
13
127
|
}
|
|
14
128
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gopherhole_openclaw_a2a",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "GopherHole A2A plugin for OpenClaw - connect your AI agent to the GopherHole network",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@gopherhole/sdk": "^0.7.
|
|
38
|
+
"@gopherhole/sdk": "^0.7.5",
|
|
39
39
|
"uuid": "^10.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|