@perkos/perkos-a2a 0.8.11 → 0.8.12
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/index.js +45 -9
- package/dist/index.js.map +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +44 -8
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -26824,6 +26824,7 @@ var A2AServer = class {
|
|
|
26824
26824
|
const message = params.message;
|
|
26825
26825
|
const taskId = randomUUID3();
|
|
26826
26826
|
const contextId = message?.contextId || randomUUID3();
|
|
26827
|
+
const meta = message?.metadata || {};
|
|
26827
26828
|
const task = {
|
|
26828
26829
|
kind: "task",
|
|
26829
26830
|
id: taskId,
|
|
@@ -26832,7 +26833,10 @@ var A2AServer = class {
|
|
|
26832
26833
|
messages: [message],
|
|
26833
26834
|
artifacts: [],
|
|
26834
26835
|
metadata: {
|
|
26835
|
-
fromAgent:
|
|
26836
|
+
fromAgent: meta.fromAgent || "unknown",
|
|
26837
|
+
replyToTaskId: meta.replyToTaskId,
|
|
26838
|
+
conversationId: meta.conversationId || contextId,
|
|
26839
|
+
kind: meta.kind || "request"
|
|
26836
26840
|
},
|
|
26837
26841
|
sessionKeyHint: "agent:main"
|
|
26838
26842
|
};
|
|
@@ -26848,11 +26852,33 @@ var A2AServer = class {
|
|
|
26848
26852
|
this.tasks.set(task.id, structuredClone(task));
|
|
26849
26853
|
const textParts = task.messages.flatMap((m) => m.parts || []).filter((p) => p.kind === "text").map((p) => p.text).join("\n");
|
|
26850
26854
|
try {
|
|
26855
|
+
if (task.metadata?.kind === "response" && task.metadata?.replyToTaskId) {
|
|
26856
|
+
const original = this.tasks.get(String(task.metadata.replyToTaskId));
|
|
26857
|
+
if (original) {
|
|
26858
|
+
appendArtifact(original, textParts || "(empty response)");
|
|
26859
|
+
original.status = {
|
|
26860
|
+
state: "completed",
|
|
26861
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26862
|
+
message: {
|
|
26863
|
+
role: "agent",
|
|
26864
|
+
parts: [{ kind: "text", text: textParts || "(empty response)" }]
|
|
26865
|
+
}
|
|
26866
|
+
};
|
|
26867
|
+
this.tasks.set(original.id, structuredClone(original));
|
|
26868
|
+
appendArtifact(task, `Response linked to original task ${original.id}`);
|
|
26869
|
+
task.status = { state: "completed", timestamp: (/* @__PURE__ */ new Date()).toISOString() };
|
|
26870
|
+
this.tasks.set(task.id, structuredClone(task));
|
|
26871
|
+
this.logger.info(`[perkos-a2a] Response task ${task.id} linked to original task ${original.id}`);
|
|
26872
|
+
return;
|
|
26873
|
+
}
|
|
26874
|
+
}
|
|
26851
26875
|
if (this.messageInjector) {
|
|
26852
26876
|
this.messageInjector(textParts, {
|
|
26853
26877
|
source: "a2a",
|
|
26854
26878
|
fromAgent: task.metadata?.fromAgent,
|
|
26855
|
-
taskId: task.id
|
|
26879
|
+
taskId: task.id,
|
|
26880
|
+
conversationId: task.metadata?.conversationId,
|
|
26881
|
+
kind: task.metadata?.kind
|
|
26856
26882
|
});
|
|
26857
26883
|
appendArtifact(task, "Task accepted and dispatched for execution");
|
|
26858
26884
|
this.tasks.set(task.id, structuredClone(task));
|
|
@@ -26928,11 +26954,11 @@ var A2AServer = class {
|
|
|
26928
26954
|
return this.success(rpcId, task);
|
|
26929
26955
|
}
|
|
26930
26956
|
/** Send a task to a peer agent via A2A protocol (direct HTTP or relay) */
|
|
26931
|
-
async sendTask(targetAgent, messageText) {
|
|
26957
|
+
async sendTask(targetAgent, messageText, metadata) {
|
|
26932
26958
|
const targetUrl = this.config.peers[targetAgent];
|
|
26933
26959
|
if (targetUrl) {
|
|
26934
26960
|
try {
|
|
26935
|
-
return await this.sendTaskDirect(targetAgent, targetUrl, messageText);
|
|
26961
|
+
return await this.sendTaskDirect(targetAgent, targetUrl, messageText, metadata);
|
|
26936
26962
|
} catch (err) {
|
|
26937
26963
|
if (!this.relayClient?.isConnected()) {
|
|
26938
26964
|
throw err;
|
|
@@ -26943,13 +26969,13 @@ var A2AServer = class {
|
|
|
26943
26969
|
}
|
|
26944
26970
|
}
|
|
26945
26971
|
if (this.relayClient?.isConnected()) {
|
|
26946
|
-
return this.sendTaskViaRelay(targetAgent, messageText);
|
|
26972
|
+
return this.sendTaskViaRelay(targetAgent, messageText, metadata);
|
|
26947
26973
|
}
|
|
26948
26974
|
throw new Error(
|
|
26949
26975
|
`Cannot reach ${targetAgent}: no direct URL configured and relay not connected. Known peers: ${Object.keys(this.config.peers).join(", ")}`
|
|
26950
26976
|
);
|
|
26951
26977
|
}
|
|
26952
|
-
async sendTaskDirect(targetAgent, targetUrl, messageText) {
|
|
26978
|
+
async sendTaskDirect(targetAgent, targetUrl, messageText, metadata) {
|
|
26953
26979
|
const headers = { "Content-Type": "application/json" };
|
|
26954
26980
|
const peerAuth = this.config.peerAuth?.[targetAgent];
|
|
26955
26981
|
if (peerAuth) {
|
|
@@ -26965,7 +26991,12 @@ var A2AServer = class {
|
|
|
26965
26991
|
messageId: randomUUID3(),
|
|
26966
26992
|
role: "user",
|
|
26967
26993
|
parts: [{ kind: "text", text: messageText }],
|
|
26968
|
-
metadata: {
|
|
26994
|
+
metadata: {
|
|
26995
|
+
fromAgent: this.config.agentName,
|
|
26996
|
+
conversationId: metadata?.conversationId,
|
|
26997
|
+
replyToTaskId: metadata?.replyToTaskId,
|
|
26998
|
+
kind: metadata?.kind || "request"
|
|
26999
|
+
}
|
|
26969
27000
|
}
|
|
26970
27001
|
}
|
|
26971
27002
|
};
|
|
@@ -26976,7 +27007,7 @@ var A2AServer = class {
|
|
|
26976
27007
|
});
|
|
26977
27008
|
return await response.json();
|
|
26978
27009
|
}
|
|
26979
|
-
async sendTaskViaRelay(targetAgent, messageText) {
|
|
27010
|
+
async sendTaskViaRelay(targetAgent, messageText, metadata) {
|
|
26980
27011
|
const rpcId = randomUUID3();
|
|
26981
27012
|
const result = await this.relayClient.sendTask(targetAgent, {
|
|
26982
27013
|
jsonrpc: "2.0",
|
|
@@ -26988,7 +27019,12 @@ var A2AServer = class {
|
|
|
26988
27019
|
messageId: randomUUID3(),
|
|
26989
27020
|
role: "user",
|
|
26990
27021
|
parts: [{ kind: "text", text: messageText }],
|
|
26991
|
-
metadata: {
|
|
27022
|
+
metadata: {
|
|
27023
|
+
fromAgent: this.config.agentName,
|
|
27024
|
+
conversationId: metadata?.conversationId,
|
|
27025
|
+
replyToTaskId: metadata?.replyToTaskId,
|
|
27026
|
+
kind: metadata?.kind || "request"
|
|
27027
|
+
}
|
|
26992
27028
|
}
|
|
26993
27029
|
}
|
|
26994
27030
|
});
|