a2acalling 0.1.4 → 0.1.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.js +17 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "a2acalling",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Agent-to-agent calling for OpenClaw - federated agent communication",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/server.js CHANGED
@@ -113,25 +113,25 @@ Respond to this federated agent call. Be yourself - collaborative but protect pr
113
113
  const sessionId = `a2a-${federationContext.conversation_id || Date.now()}`;
114
114
 
115
115
  try {
116
- // Write prompt to temp file to avoid shell escaping issues
117
- const tmpFile = `/tmp/a2a-${Date.now()}.txt`;
118
- fs.writeFileSync(tmpFile, prompt);
116
+ // Escape the prompt for shell (replace quotes and newlines)
117
+ const escapedPrompt = prompt
118
+ .replace(/\\/g, '\\\\')
119
+ .replace(/"/g, '\\"')
120
+ .replace(/\n/g, '\\n')
121
+ .replace(/\r/g, '');
119
122
 
120
123
  // Call openclaw agent to spawn a sub-agent
121
124
  const result = execSync(
122
- `cat "${tmpFile}" | openclaw agent --session-id "${sessionId}" --timeout 55 2>/dev/null`,
125
+ `openclaw agent --session-id "${sessionId}" --message "${escapedPrompt}" --timeout 55 2>&1`,
123
126
  {
124
127
  encoding: 'utf8',
125
- timeout: 60000,
128
+ timeout: 65000,
126
129
  maxBuffer: 1024 * 1024,
127
130
  cwd: process.env.OPENCLAW_WORKSPACE || '/root/clawd',
128
131
  env: { ...process.env, FORCE_COLOR: '0' }
129
132
  }
130
133
  );
131
134
 
132
- // Clean up temp file
133
- try { fs.unlinkSync(tmpFile); } catch (e) {}
134
-
135
135
  // Filter out plugin registration messages and return clean response
136
136
  const lines = result.split('\n').filter(line =>
137
137
  !line.includes('[telegram-topic-tracker]') &&
@@ -139,12 +139,19 @@ Respond to this federated agent call. Be yourself - collaborative but protect pr
139
139
  line.trim()
140
140
  );
141
141
 
142
- return lines.join('\n').trim() || '[No response]';
142
+ const response = lines.join('\n').trim();
143
+
144
+ if (!response || response.includes('error') || response.includes('failed')) {
145
+ console.error('[a2a] Sub-agent returned error, using fallback');
146
+ return await callAgentDirect(message, federationContext);
147
+ }
148
+
149
+ return response;
143
150
 
144
151
  } catch (err) {
145
152
  console.error('[a2a] Sub-agent spawn failed:', err.message);
146
153
 
147
- // Fallback to direct API call
154
+ // Fallback to direct API call only if sub-agent completely fails
148
155
  return await callAgentDirect(message, federationContext);
149
156
  }
150
157
  }