Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions kiloclaw/openclaw-pairing-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,57 @@
// List pending pairing requests across all configured channels.
// Called via Fly exec from the worker. Outputs a single JSON blob:
// { "requests": [{ "code": "...", "id": "...", "channel": "telegram", ... }] }
const { execFileSync } = require('child_process');
const { execFile } = require('child_process');
const { promisify } = require('util');
const fs = require('fs');

const execFileAsync = promisify(execFile);

// Fly exec sets HOME=/ — hardcode to /root where openclaw config and pairing store live
process.env.HOME = '/root';

let cfg;
try {
cfg = JSON.parse(fs.readFileSync('/root/.openclaw/openclaw.json', 'utf8'));
} catch {
console.log(JSON.stringify({ requests: [] }));
process.exit(0);
}
(async () => {
let cfg;
try {
cfg = JSON.parse(fs.readFileSync('/root/.openclaw/openclaw.json', 'utf8'));
} catch {
console.log(JSON.stringify({ requests: [] }));
process.exit(0);
}

const ch = cfg.channels || {};
const channels = [];
if (ch.telegram?.enabled && ch.telegram?.botToken) channels.push('telegram');
if (ch.discord?.enabled && ch.discord?.token) channels.push('discord');
if (ch.slack?.enabled && (ch.slack?.botToken || ch.slack?.appToken)) channels.push('slack');
const ch = cfg.channels || {};
const channels = [];
if (ch.telegram?.enabled && ch.telegram?.botToken) channels.push('telegram');
if (ch.discord?.enabled && ch.discord?.token) channels.push('discord');
if (ch.slack?.enabled && (ch.slack?.botToken || ch.slack?.appToken)) channels.push('slack');

const allRequests = [];
for (const channel of channels) {
try {
const output = execFileSync('openclaw', ['pairing', 'list', channel, '--json'], {
encoding: 'utf8',
timeout: 10000,
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, HOME: '/root' },
});
const data = JSON.parse(output.trim());
for (const req of data.requests || []) {
allRequests.push({ ...req, channel });
const results = await Promise.allSettled(
channels.map(async channel => {
const { stdout } = await execFileAsync('openclaw', ['pairing', 'list', channel, '--json'], {
encoding: 'utf8',
timeout: 45000,
env: { ...process.env, HOME: '/root' },
});
const data = JSON.parse(stdout.trim());
return (data.requests || []).map(req => ({ ...req, channel }));
})
);

const allRequests = [];
for (let i = 0; i < results.length; i++) {
const result = results[i];
if (result.status === 'fulfilled') {
allRequests.push(...result.value);
} else {
const err = result.reason;
const msg = err && err.stderr ? err.stderr.toString().trim() : String(err);
process.stderr.write(`[pairing-list] ${channels[i]}: ${msg}\n`);
}
} catch (err) {
// Log to stderr so the caller can see what went wrong
const msg = err && err.stderr ? err.stderr.toString().trim() : String(err);
process.stderr.write(`[pairing-list] ${channel}: ${msg}\n`);
}
}

console.log(JSON.stringify({ requests: allRequests }));
console.log(JSON.stringify({ requests: allRequests }));
})().catch(err => {
process.stderr.write(`[pairing-list] fatal: ${err}\n`);
console.log(JSON.stringify({ requests: [] }));
process.exitCode = 1;
});
4 changes: 2 additions & 2 deletions kiloclaw/src/durable-objects/kiloclaw-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export class KiloClawInstance extends DurableObject<KiloClawEnv> {
flyConfig,
flyMachineId,
['/usr/bin/env', 'HOME=/root', 'node', '/usr/local/bin/openclaw-pairing-list.js'],
20
60
);

const empty = {
Expand Down Expand Up @@ -663,7 +663,7 @@ export class KiloClawInstance extends DurableObject<KiloClawEnv> {
flyConfig,
flyMachineId,
['/usr/bin/env', 'HOME=/root', 'openclaw', 'pairing', 'approve', channel, code, '--notify'],
15
60
);

const success = result.exit_code === 0;
Expand Down
2 changes: 1 addition & 1 deletion kiloclaw/src/fly/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export async function execCommand(
config: FlyClientConfig,
machineId: string,
command: string[],
timeout = 10
timeout = 60
): Promise<MachineExecResponse> {
const body: MachineExecRequest = { command, timeout };
const resp = await flyFetch(config, `/machines/${machineId}/exec`, {
Expand Down