a2acalling 0.5.0 → 0.5.1
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/lib/runtime-adapter.js +47 -30
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* - A2A_NOTIFY_COMMAND command that receives JSON payload on stdin for owner notifications
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const { execSync } = require('child_process');
|
|
18
|
+
const { execSync, spawnSync } = require('child_process');
|
|
19
19
|
|
|
20
20
|
function commandExists(command) {
|
|
21
21
|
try {
|
|
@@ -171,10 +171,13 @@ function runCommand(command, payload, options = {}) {
|
|
|
171
171
|
|
|
172
172
|
function escapeCliValue(value) {
|
|
173
173
|
return String(value || '')
|
|
174
|
-
.replace(/\\/g, '\\\\')
|
|
175
|
-
.replace(/"/g, '\\"')
|
|
176
|
-
.replace(
|
|
177
|
-
.replace(
|
|
174
|
+
.replace(/\\/g, '\\\\') // Backslashes first
|
|
175
|
+
.replace(/"/g, '\\"') // Double quotes
|
|
176
|
+
.replace(/\$/g, '\\$') // Dollar signs (variable expansion)
|
|
177
|
+
.replace(/`/g, '\\`') // Backticks (command substitution)
|
|
178
|
+
.replace(/!/g, '\\!') // History expansion in some shells
|
|
179
|
+
.replace(/\n/g, '\\n') // Newlines
|
|
180
|
+
.replace(/\r/g, ''); // Carriage returns
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
function buildFallbackResponse(message, context = {}, reason = null) {
|
|
@@ -245,32 +248,44 @@ function createRuntimeAdapter(options = {}) {
|
|
|
245
248
|
|
|
246
249
|
async function runOpenClawTurn({ sessionId, prompt, timeoutMs }) {
|
|
247
250
|
const timeoutSeconds = Math.max(5, Math.min(300, Math.round((timeoutMs || 65000) / 1000)));
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
251
|
+
// Use spawnSync with stdin to avoid shell escaping issues with complex prompts
|
|
252
|
+
const result = spawnSync('openclaw', [
|
|
253
|
+
'agent',
|
|
254
|
+
'--session-id', sessionId,
|
|
255
|
+
'--message', prompt,
|
|
256
|
+
'--timeout', String(timeoutSeconds)
|
|
257
|
+
], {
|
|
258
|
+
encoding: 'utf8',
|
|
259
|
+
timeout: (timeoutMs || 65000) + 5000,
|
|
260
|
+
maxBuffer: 1024 * 1024,
|
|
261
|
+
cwd: workspaceDir,
|
|
262
|
+
env: { ...process.env, FORCE_COLOR: '0' }
|
|
263
|
+
});
|
|
264
|
+
const output = (result.stdout || '') + (result.stderr || '');
|
|
265
|
+
if (result.error) {
|
|
266
|
+
throw result.error;
|
|
267
|
+
}
|
|
259
268
|
return normalizeOpenClawOutput(output) || '[Sub-agent returned empty response]';
|
|
260
269
|
}
|
|
261
270
|
|
|
262
271
|
async function runOpenClawSummary({ sessionId, prompt, timeoutMs }) {
|
|
263
272
|
const timeoutSeconds = Math.max(5, Math.min(120, Math.round((timeoutMs || 35000) / 1000)));
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
273
|
+
// Use spawnSync with stdin to avoid shell escaping issues with complex prompts
|
|
274
|
+
const result = spawnSync('openclaw', [
|
|
275
|
+
'agent',
|
|
276
|
+
'--session-id', sessionId,
|
|
277
|
+
'--message', prompt,
|
|
278
|
+
'--timeout', String(timeoutSeconds)
|
|
279
|
+
], {
|
|
280
|
+
encoding: 'utf8',
|
|
281
|
+
timeout: (timeoutMs || 35000) + 5000,
|
|
282
|
+
cwd: workspaceDir,
|
|
283
|
+
env: { ...process.env, FORCE_COLOR: '0' }
|
|
284
|
+
});
|
|
285
|
+
const output = (result.stdout || '') + (result.stderr || '');
|
|
286
|
+
if (result.error) {
|
|
287
|
+
throw result.error;
|
|
288
|
+
}
|
|
274
289
|
const summaryText = cleanText(normalizeOpenClawOutput(output), 1500);
|
|
275
290
|
if (!summaryText) {
|
|
276
291
|
return null;
|
|
@@ -283,10 +298,12 @@ function createRuntimeAdapter(options = {}) {
|
|
|
283
298
|
|
|
284
299
|
async function runOpenClawNotify({ callerName, callerOwner, message }) {
|
|
285
300
|
const notification = `🤝 **A2A Call**\nFrom: ${callerName}${callerOwner}\n> ${message.slice(0, 150)}...`;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
301
|
+
// Use spawnSync to avoid shell escaping issues
|
|
302
|
+
spawnSync('openclaw', [
|
|
303
|
+
'message', 'send',
|
|
304
|
+
'--channel', 'telegram',
|
|
305
|
+
'--message', notification
|
|
306
|
+
], { timeout: 10000, stdio: 'pipe' });
|
|
290
307
|
}
|
|
291
308
|
|
|
292
309
|
async function runGenericTurn({ message, caller, context, runtimeError }) {
|