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.
- package/package.json +1 -1
- package/src/server.js +17 -10
package/package.json
CHANGED
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
|
-
//
|
|
117
|
-
const
|
|
118
|
-
|
|
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
|
-
`
|
|
125
|
+
`openclaw agent --session-id "${sessionId}" --message "${escapedPrompt}" --timeout 55 2>&1`,
|
|
123
126
|
{
|
|
124
127
|
encoding: 'utf8',
|
|
125
|
-
timeout:
|
|
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
|
-
|
|
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
|
}
|