@perkos/perkos-a2a 0.8.9 → 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();
@@ -26843,11 +26850,7 @@ var A2AServer = class {
26843
26850
  fromAgent: task.metadata?.fromAgent,
26844
26851
  taskId: task.id
26845
26852
  });
26846
- task.artifacts.push({
26847
- kind: "artifact",
26848
- artifactId: randomUUID3(),
26849
- parts: [{ kind: "text", text: "Task accepted and dispatched for execution" }]
26850
- });
26853
+ appendArtifact(task, "Task accepted and dispatched for execution");
26851
26854
  this.tasks.set(task.id, structuredClone(task));
26852
26855
  } else {
26853
26856
  const fs = await import("fs");
@@ -26869,11 +26872,7 @@ var A2AServer = class {
26869
26872
  ""
26870
26873
  ].join("\n");
26871
26874
  fs.writeFileSync(taskFile, content);
26872
- task.artifacts.push({
26873
- kind: "artifact",
26874
- artifactId: randomUUID3(),
26875
- parts: [{ kind: "text", text: `Task queued: ${taskFile}` }]
26876
- });
26875
+ appendArtifact(task, `Task queued: ${taskFile}`);
26877
26876
  this.tasks.set(task.id, structuredClone(task));
26878
26877
  }
26879
26878
  if (this.taskResultHandler) {
@@ -27192,79 +27191,126 @@ function register(api) {
27192
27191
  logger.info("[perkos-a2a] runtime.system.requestHeartbeatNow unavailable \u2014 wake will rely on next agent turn");
27193
27192
  }
27194
27193
  server.setTaskResultHandler(async (task, text) => {
27195
- const cfg = await api.runtime?.config?.loadConfig?.();
27196
- if (!api.runtime?.agent?.runEmbeddedAgent || !cfg) {
27197
- task.status = {
27198
- state: "completed",
27199
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
27200
- };
27201
- return;
27202
- }
27203
- const agentDir = api.runtime.agent.resolveAgentDir(cfg);
27204
- const workspaceDir = api.runtime.agent.resolveAgentWorkspaceDir(cfg);
27205
- await api.runtime.agent.ensureAgentWorkspace(cfg);
27206
- const sessionId = `perkos-a2a:task:${task.id}`;
27207
- const prompt = [
27208
- `You are handling an incoming A2A task from agent ${task.metadata?.fromAgent || "unknown"}.`,
27209
- `Task ID: ${task.id}`,
27210
- `Context ID: ${task.contextId}`,
27211
- "",
27212
- "Execute the request below and return the actual final answer for the peer agent.",
27213
- "Do not describe internal steps unless the task explicitly asks for them.",
27214
- "Return only the useful final response.",
27215
- "",
27216
- text
27217
- ].join("\n");
27218
- const result = await api.runtime.agent.runEmbeddedAgent({
27219
- sessionId,
27220
- runId: randomUUID4(),
27221
- sessionFile: path.join(agentDir, "sessions", `perkos-a2a-task-${task.id}.jsonl`),
27222
- workspaceDir,
27223
- prompt,
27224
- timeoutMs: api.runtime.agent.resolveAgentTimeoutMs(cfg)
27225
- });
27226
- const payloadText = result?.payloads?.map((p) => p?.text).filter(Boolean).join("\n\n") || "";
27227
- const finalText = (result?.meta?.finalAssistantVisibleText || payloadText || "").trim();
27228
27194
  task.artifacts.push({
27229
27195
  kind: "artifact",
27230
27196
  artifactId: randomUUID4(),
27231
- parts: [{
27232
- kind: "text",
27233
- text: JSON.stringify({
27234
- debug: "embedded-run-result",
27235
- stopReason: result?.meta?.stopReason || null,
27236
- finalAssistantVisibleText: result?.meta?.finalAssistantVisibleText || null,
27237
- payloadText: payloadText || null,
27238
- didSendViaMessagingTool: result?.didSendViaMessagingTool || false,
27239
- payloadCount: Array.isArray(result?.payloads) ? result.payloads.length : 0
27240
- }, null, 2)
27241
- }]
27197
+ parts: [{ kind: "text", text: "debug: entered task result handler" }]
27242
27198
  });
27243
- if (finalText) {
27199
+ try {
27200
+ const cfg = await api.runtime?.config?.loadConfig?.();
27244
27201
  task.artifacts.push({
27245
27202
  kind: "artifact",
27246
27203
  artifactId: randomUUID4(),
27247
- parts: [{ kind: "text", text: finalText }]
27204
+ parts: [{ kind: "text", text: `debug: config loaded=${!!cfg}` }]
27248
27205
  });
27249
- task.status = {
27250
- state: "completed",
27251
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27252
- message: {
27253
- 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(),
27254
27276
  parts: [{ kind: "text", text: finalText }]
27255
- }
27256
- };
27257
- logger.info(`[perkos-a2a] Task ${task.id} final result captured from embedded agent`);
27258
- } 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
+ });
27259
27305
  task.status = {
27260
- state: "completed",
27306
+ state: "failed",
27261
27307
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27262
27308
  message: {
27263
27309
  role: "agent",
27264
- parts: [{ kind: "text", text: "Task executed but no final visible text was captured." }]
27310
+ parts: [{ kind: "text", text: msg }]
27265
27311
  }
27266
27312
  };
27267
- logger.info(`[perkos-a2a] Task ${task.id} executed, but no final visible text was captured`);
27313
+ throw err;
27268
27314
  }
27269
27315
  });
27270
27316
  server.setTaskFailureHandler(async (task, errorText) => {