@perkos/perkos-a2a 0.8.8 → 0.8.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,cAAc,YAAY,CAAC;AAuB3B,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,GAAG,QAofxC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,cAAc,YAAY,CAAC;AAuB3B,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,GAAG,QAsiBxC"}
package/dist/index.js CHANGED
@@ -26665,6 +26665,13 @@ var RelayHub = class {
26665
26665
  };
26666
26666
 
26667
26667
  // src/server.ts
26668
+ function appendArtifact(task, text) {
26669
+ task.artifacts.push({
26670
+ kind: "artifact",
26671
+ artifactId: randomUUID3(),
26672
+ parts: [{ kind: "text", text }]
26673
+ });
26674
+ }
26668
26675
  async function detectNetworking() {
26669
26676
  const localIps = [];
26670
26677
  const ifaces = networkInterfaces();
@@ -26829,11 +26836,12 @@ var A2AServer = class {
26829
26836
  this.logger.info(
26830
26837
  `[perkos-a2a] Task ${taskId} received from ${task.metadata?.fromAgent}`
26831
26838
  );
26832
- this.processTask(task);
26839
+ void this.processTask(task);
26833
26840
  return this.success(rpcId, task);
26834
26841
  }
26835
26842
  async processTask(task) {
26836
26843
  task.status = { state: "working", timestamp: (/* @__PURE__ */ new Date()).toISOString() };
26844
+ this.tasks.set(task.id, structuredClone(task));
26837
26845
  const textParts = task.messages.flatMap((m) => m.parts || []).filter((p) => p.kind === "text").map((p) => p.text).join("\n");
26838
26846
  try {
26839
26847
  if (this.messageInjector) {
@@ -26842,11 +26850,8 @@ var A2AServer = class {
26842
26850
  fromAgent: task.metadata?.fromAgent,
26843
26851
  taskId: task.id
26844
26852
  });
26845
- task.artifacts.push({
26846
- kind: "artifact",
26847
- artifactId: randomUUID3(),
26848
- parts: [{ kind: "text", text: "Task accepted and dispatched for execution" }]
26849
- });
26853
+ appendArtifact(task, "Task accepted and dispatched for execution");
26854
+ this.tasks.set(task.id, structuredClone(task));
26850
26855
  } else {
26851
26856
  const fs = await import("fs");
26852
26857
  const taskDir = this.config.workspacePath || `${homedir()}/.openclaw/workspace/memory`;
@@ -26867,11 +26872,8 @@ var A2AServer = class {
26867
26872
  ""
26868
26873
  ].join("\n");
26869
26874
  fs.writeFileSync(taskFile, content);
26870
- task.artifacts.push({
26871
- kind: "artifact",
26872
- artifactId: randomUUID3(),
26873
- parts: [{ kind: "text", text: `Task queued: ${taskFile}` }]
26874
- });
26875
+ appendArtifact(task, `Task queued: ${taskFile}`);
26876
+ this.tasks.set(task.id, structuredClone(task));
26875
26877
  }
26876
26878
  if (this.taskResultHandler) {
26877
26879
  await this.taskResultHandler(task, textParts);
@@ -26881,6 +26883,7 @@ var A2AServer = class {
26881
26883
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
26882
26884
  };
26883
26885
  }
26886
+ this.tasks.set(task.id, structuredClone(task));
26884
26887
  this.logger.info(`[perkos-a2a] Task ${task.id} completed`);
26885
26888
  } catch (err) {
26886
26889
  const msg = err instanceof Error ? err.message : String(err);
@@ -26896,16 +26899,17 @@ var A2AServer = class {
26896
26899
  }
26897
26900
  };
26898
26901
  }
26902
+ this.tasks.set(task.id, structuredClone(task));
26899
26903
  this.logger.error(`[perkos-a2a] Task ${task.id} failed: ${msg}`);
26900
26904
  }
26901
26905
  }
26902
26906
  handleGetTask(params, rpcId) {
26903
26907
  const task = this.tasks.get(params?.id);
26904
26908
  if (!task) return this.error(rpcId, 404, "Task not found");
26905
- return this.success(rpcId, task);
26909
+ return this.success(rpcId, structuredClone(task));
26906
26910
  }
26907
26911
  handleListTasks(rpcId) {
26908
- const allTasks = Array.from(this.tasks.values()).sort(
26912
+ const allTasks = Array.from(this.tasks.values()).map((task) => structuredClone(task)).sort(
26909
26913
  (a, b) => new Date(b.status.timestamp).getTime() - new Date(a.status.timestamp).getTime()
26910
26914
  );
26911
26915
  return this.success(rpcId, { tasks: allTasks, nextPageToken: "" });
@@ -27187,79 +27191,126 @@ function register(api) {
27187
27191
  logger.info("[perkos-a2a] runtime.system.requestHeartbeatNow unavailable \u2014 wake will rely on next agent turn");
27188
27192
  }
27189
27193
  server.setTaskResultHandler(async (task, text) => {
27190
- const cfg = await api.runtime?.config?.loadConfig?.();
27191
- if (!api.runtime?.agent?.runEmbeddedAgent || !cfg) {
27192
- task.status = {
27193
- state: "completed",
27194
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
27195
- };
27196
- return;
27197
- }
27198
- const agentDir = api.runtime.agent.resolveAgentDir(cfg);
27199
- const workspaceDir = api.runtime.agent.resolveAgentWorkspaceDir(cfg);
27200
- await api.runtime.agent.ensureAgentWorkspace(cfg);
27201
- const sessionId = `perkos-a2a:task:${task.id}`;
27202
- const prompt = [
27203
- `You are handling an incoming A2A task from agent ${task.metadata?.fromAgent || "unknown"}.`,
27204
- `Task ID: ${task.id}`,
27205
- `Context ID: ${task.contextId}`,
27206
- "",
27207
- "Execute the request below and return the actual final answer for the peer agent.",
27208
- "Do not describe internal steps unless the task explicitly asks for them.",
27209
- "Return only the useful final response.",
27210
- "",
27211
- text
27212
- ].join("\n");
27213
- const result = await api.runtime.agent.runEmbeddedAgent({
27214
- sessionId,
27215
- runId: randomUUID4(),
27216
- sessionFile: path.join(agentDir, "sessions", `perkos-a2a-task-${task.id}.jsonl`),
27217
- workspaceDir,
27218
- prompt,
27219
- timeoutMs: api.runtime.agent.resolveAgentTimeoutMs(cfg)
27220
- });
27221
- const payloadText = result?.payloads?.map((p) => p?.text).filter(Boolean).join("\n\n") || "";
27222
- const finalText = (result?.meta?.finalAssistantVisibleText || payloadText || "").trim();
27223
27194
  task.artifacts.push({
27224
27195
  kind: "artifact",
27225
27196
  artifactId: randomUUID4(),
27226
- parts: [{
27227
- kind: "text",
27228
- text: JSON.stringify({
27229
- debug: "embedded-run-result",
27230
- stopReason: result?.meta?.stopReason || null,
27231
- finalAssistantVisibleText: result?.meta?.finalAssistantVisibleText || null,
27232
- payloadText: payloadText || null,
27233
- didSendViaMessagingTool: result?.didSendViaMessagingTool || false,
27234
- payloadCount: Array.isArray(result?.payloads) ? result.payloads.length : 0
27235
- }, null, 2)
27236
- }]
27197
+ parts: [{ kind: "text", text: "debug: entered task result handler" }]
27237
27198
  });
27238
- if (finalText) {
27199
+ try {
27200
+ const cfg = await api.runtime?.config?.loadConfig?.();
27239
27201
  task.artifacts.push({
27240
27202
  kind: "artifact",
27241
27203
  artifactId: randomUUID4(),
27242
- parts: [{ kind: "text", text: finalText }]
27204
+ parts: [{ kind: "text", text: `debug: config loaded=${!!cfg}` }]
27243
27205
  });
27244
- task.status = {
27245
- state: "completed",
27246
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27247
- message: {
27248
- role: "agent",
27206
+ if (!api.runtime?.agent?.runEmbeddedAgent || !cfg) {
27207
+ task.artifacts.push({
27208
+ kind: "artifact",
27209
+ artifactId: randomUUID4(),
27210
+ parts: [{ kind: "text", text: "debug: embedded agent runtime unavailable" }]
27211
+ });
27212
+ task.status = {
27213
+ state: "completed",
27214
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27215
+ message: {
27216
+ role: "agent",
27217
+ parts: [{ kind: "text", text: "Embedded agent runtime unavailable." }]
27218
+ }
27219
+ };
27220
+ return;
27221
+ }
27222
+ const agentDir = api.runtime.agent.resolveAgentDir(cfg);
27223
+ const workspaceDir = api.runtime.agent.resolveAgentWorkspaceDir(cfg);
27224
+ await api.runtime.agent.ensureAgentWorkspace(cfg);
27225
+ task.artifacts.push({
27226
+ kind: "artifact",
27227
+ artifactId: randomUUID4(),
27228
+ parts: [{ kind: "text", text: "debug: agent workspace ensured" }]
27229
+ });
27230
+ const sessionId = `perkos-a2a:task:${task.id}`;
27231
+ const prompt = [
27232
+ `You are handling an incoming A2A task from agent ${task.metadata?.fromAgent || "unknown"}.`,
27233
+ `Task ID: ${task.id}`,
27234
+ `Context ID: ${task.contextId}`,
27235
+ "",
27236
+ "Execute the request below and return the actual final answer for the peer agent.",
27237
+ "Do not describe internal steps unless the task explicitly asks for them.",
27238
+ "Return only the useful final response.",
27239
+ "",
27240
+ text
27241
+ ].join("\n");
27242
+ task.artifacts.push({
27243
+ kind: "artifact",
27244
+ artifactId: randomUUID4(),
27245
+ parts: [{ kind: "text", text: "debug: starting embedded run" }]
27246
+ });
27247
+ const result = await api.runtime.agent.runEmbeddedAgent({
27248
+ sessionId,
27249
+ runId: randomUUID4(),
27250
+ sessionFile: path.join(agentDir, "sessions", `perkos-a2a-task-${task.id}.jsonl`),
27251
+ workspaceDir,
27252
+ prompt,
27253
+ timeoutMs: api.runtime.agent.resolveAgentTimeoutMs(cfg)
27254
+ });
27255
+ const payloadText = result?.payloads?.map((p) => p?.text).filter(Boolean).join("\n\n") || "";
27256
+ const finalText = (result?.meta?.finalAssistantVisibleText || payloadText || "").trim();
27257
+ task.artifacts.push({
27258
+ kind: "artifact",
27259
+ artifactId: randomUUID4(),
27260
+ parts: [{
27261
+ kind: "text",
27262
+ text: JSON.stringify({
27263
+ debug: "embedded-run-result",
27264
+ stopReason: result?.meta?.stopReason || null,
27265
+ finalAssistantVisibleText: result?.meta?.finalAssistantVisibleText || null,
27266
+ payloadText: payloadText || null,
27267
+ didSendViaMessagingTool: result?.didSendViaMessagingTool || false,
27268
+ payloadCount: Array.isArray(result?.payloads) ? result.payloads.length : 0
27269
+ }, null, 2)
27270
+ }]
27271
+ });
27272
+ if (finalText) {
27273
+ task.artifacts.push({
27274
+ kind: "artifact",
27275
+ artifactId: randomUUID4(),
27249
27276
  parts: [{ kind: "text", text: finalText }]
27250
- }
27251
- };
27252
- logger.info(`[perkos-a2a] Task ${task.id} final result captured from embedded agent`);
27253
- } else {
27277
+ });
27278
+ task.status = {
27279
+ state: "completed",
27280
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27281
+ message: {
27282
+ role: "agent",
27283
+ parts: [{ kind: "text", text: finalText }]
27284
+ }
27285
+ };
27286
+ logger.info(`[perkos-a2a] Task ${task.id} final result captured from embedded agent`);
27287
+ } else {
27288
+ task.status = {
27289
+ state: "completed",
27290
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27291
+ message: {
27292
+ role: "agent",
27293
+ parts: [{ kind: "text", text: "Task executed but no final visible text was captured." }]
27294
+ }
27295
+ };
27296
+ logger.info(`[perkos-a2a] Task ${task.id} executed, but no final visible text was captured`);
27297
+ }
27298
+ } catch (err) {
27299
+ const msg = err instanceof Error ? err.stack || err.message : String(err);
27300
+ task.artifacts.push({
27301
+ kind: "artifact",
27302
+ artifactId: randomUUID4(),
27303
+ parts: [{ kind: "text", text: `debug: result handler threw: ${msg}` }]
27304
+ });
27254
27305
  task.status = {
27255
- state: "completed",
27306
+ state: "failed",
27256
27307
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27257
27308
  message: {
27258
27309
  role: "agent",
27259
- parts: [{ kind: "text", text: "Task executed but no final visible text was captured." }]
27310
+ parts: [{ kind: "text", text: msg }]
27260
27311
  }
27261
27312
  };
27262
- logger.info(`[perkos-a2a] Task ${task.id} executed, but no final visible text was captured`);
27313
+ throw err;
27263
27314
  }
27264
27315
  });
27265
27316
  server.setTaskFailureHandler(async (task, errorText) => {