@openagents-org/agent-launcher 0.2.207 → 0.2.208
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
CHANGED
package/src/adapters/base.js
CHANGED
|
@@ -23,6 +23,7 @@ const { defaultAgentWorkdir } = require('../paths');
|
|
|
23
23
|
const { configuredModel } = require('../agent-model');
|
|
24
24
|
const { buildThreadHistory } = require('./thread-history');
|
|
25
25
|
const { publishResponseArtifacts } = require('./response-artifacts');
|
|
26
|
+
const { ResponseOutbox } = require('./response-outbox');
|
|
26
27
|
const fs = require('fs');
|
|
27
28
|
const os = require('os');
|
|
28
29
|
const path = require('path');
|
|
@@ -447,6 +448,8 @@ class BaseAdapter {
|
|
|
447
448
|
// /status responsive immediately after join.
|
|
448
449
|
await this._skipExistingControlEvents();
|
|
449
450
|
const heartbeatInterval = setInterval(() => this._heartbeat(), 30000);
|
|
451
|
+
const responseInterval = setInterval(() => this._flushResponses(), 10000);
|
|
452
|
+
void this._flushResponses();
|
|
450
453
|
const controlPoller = this._controlPollerLoop();
|
|
451
454
|
|
|
452
455
|
try {
|
|
@@ -462,6 +465,7 @@ class BaseAdapter {
|
|
|
462
465
|
this._running = false;
|
|
463
466
|
this._wakeControlPoller();
|
|
464
467
|
clearInterval(heartbeatInterval);
|
|
468
|
+
clearInterval(responseInterval);
|
|
465
469
|
if (this._presenceHeartbeatTimer) { clearTimeout(this._presenceHeartbeatTimer); this._presenceHeartbeatTimer = null; }
|
|
466
470
|
try { await controlPoller; } catch {}
|
|
467
471
|
try {
|
|
@@ -1832,35 +1836,56 @@ class BaseAdapter {
|
|
|
1832
1836
|
async sendResponse(channel, content, { statusKind = 'completed' } = {}) {
|
|
1833
1837
|
if (this._isMuted(channel)) return;
|
|
1834
1838
|
try {
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
const published = await publishResponseArtifacts({
|
|
1838
|
-
content,
|
|
1839
|
-
workingDir: this.workingDir,
|
|
1840
|
-
upload: (filename, bytes, contentType) => this.client.uploadFile(this.workspaceId, this.token, filename, bytes, {
|
|
1841
|
-
contentType, source: `openagents:${this.agentName}`, channelName: channel, visibility: 'inherit',
|
|
1842
|
-
}),
|
|
1843
|
-
onError: () => this._log('Could not attach a linked document; leaving its original link in the reply.'),
|
|
1844
|
-
});
|
|
1845
|
-
content = published.content;
|
|
1846
|
-
attachments = published.attachments;
|
|
1847
|
-
}
|
|
1848
|
-
await this.client.sendMessage(this.workspaceId, channel, this.token, content, {
|
|
1849
|
-
attachments,
|
|
1850
|
-
senderType: 'agent',
|
|
1851
|
-
senderName: this.agentName,
|
|
1839
|
+
await this._replyOutbox().enqueue({
|
|
1840
|
+
channel, content,
|
|
1852
1841
|
metadata: { status_kind: statusKind, ...(this._channelTriggerId?.[channel] ? { in_reply_to: this._channelTriggerId[channel] } : {}) },
|
|
1853
|
-
sessionId: this._sessionId,
|
|
1854
1842
|
});
|
|
1855
1843
|
} catch (e) {
|
|
1856
|
-
|
|
1857
|
-
this._onSessionRevoked();
|
|
1858
|
-
return;
|
|
1859
|
-
}
|
|
1844
|
+
this._log('Could not save or deliver the final reply; check the local response outbox and disk permissions.', 'error');
|
|
1860
1845
|
throw e;
|
|
1861
1846
|
}
|
|
1862
1847
|
}
|
|
1863
1848
|
|
|
1849
|
+
_replyOutbox() {
|
|
1850
|
+
if (!this._responseOutbox) this._responseOutbox = new ResponseOutbox({
|
|
1851
|
+
endpoint: this.endpoint, workspaceId: this.workspaceId, agentName: this.agentName,
|
|
1852
|
+
directory: this._responseOutboxDirectory,
|
|
1853
|
+
log: (message, level) => this._log(message, level),
|
|
1854
|
+
onRevoked: () => this._onSessionRevoked(),
|
|
1855
|
+
prepare: async (entry) => {
|
|
1856
|
+
// Old/custom servers may not support idempotency. Never blindly retry
|
|
1857
|
+
// an ambiguous send against one of those servers.
|
|
1858
|
+
const safeRetry = this.client.supportsMessageDelivery
|
|
1859
|
+
? await this.client.supportsMessageDelivery() : false;
|
|
1860
|
+
let published = { content: entry.content, attachments: [] };
|
|
1861
|
+
if (!(this.disabledModules || new Set()).has('files') && entry.channel && !entry.channel.startsWith('dm:') && this.client.uploadFile) {
|
|
1862
|
+
published = await publishResponseArtifacts({
|
|
1863
|
+
content: entry.content, workingDir: this.workingDir,
|
|
1864
|
+
upload: (filename, bytes, contentType) => this.client.uploadFile(this.workspaceId, this.token, filename, bytes, {
|
|
1865
|
+
contentType, source: `openagents:${this.agentName}`, channelName: entry.channel, visibility: 'inherit',
|
|
1866
|
+
}),
|
|
1867
|
+
onError: () => this._log('Could not attach a linked document; leaving its original link in the reply.'),
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
return { ...published, safeRetry };
|
|
1871
|
+
},
|
|
1872
|
+
send: async (entry) => {
|
|
1873
|
+
if (this._isMuted(entry.channel)) throw new Error('Channel is muted');
|
|
1874
|
+
return this.client.sendMessage(this.workspaceId, entry.channel, this.token, entry.content, {
|
|
1875
|
+
attachments: entry.attachments, senderType: 'agent', senderName: this.agentName,
|
|
1876
|
+
metadata: entry.metadata, sessionId: this._sessionId,
|
|
1877
|
+
idempotencyKey: entry.safeRetry ? entry.id : undefined,
|
|
1878
|
+
});
|
|
1879
|
+
},
|
|
1880
|
+
});
|
|
1881
|
+
return this._responseOutbox;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
async _flushResponses() {
|
|
1885
|
+
try { await this._replyOutbox().flush(); }
|
|
1886
|
+
catch { this._log('Could not drain the response outbox; saved replies retained.', 'error'); }
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1864
1889
|
async cleanupTodos(channel) {
|
|
1865
1890
|
try {
|
|
1866
1891
|
const result = await this.client.getTodos(this.workspaceId, channel, this.token, {
|
package/src/adapters/claude.js
CHANGED
|
@@ -526,14 +526,17 @@ class ClaudeAdapter extends BaseAdapter {
|
|
|
526
526
|
// process.cwd() as the fallback — on a packaged Windows daemon that is
|
|
527
527
|
// C:\WINDOWS\system32 and mkdir there throws EPERM.
|
|
528
528
|
const workDir = this.workingDir || defaultAgentWorkdir(this.agentName);
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
|
|
529
|
+
const skillsRoot = path.join(workDir, '.claude', 'skills');
|
|
530
|
+
const skillDir = path.join(skillsRoot, workspaceSkillName(this.agentName));
|
|
531
|
+
fs.mkdirSync(skillDir, { recursive: true, mode: 0o700 });
|
|
532
|
+
// Per-agent directory: Claude discovers <name>/SKILL.md, not flat .md files.
|
|
533
|
+
// Agents sharing a working directory used to clobber
|
|
532
534
|
// one shared openagents-workspace.md, so uploads carried the identity of
|
|
533
535
|
// whichever agent wrote the file last. Drop that legacy file so a stale
|
|
534
536
|
// copy (with another agent's embedded identity) can never be read again.
|
|
535
|
-
const skillFile = path.join(skillDir,
|
|
536
|
-
try { fs.unlinkSync(path.join(
|
|
537
|
+
const skillFile = path.join(skillDir, 'SKILL.md');
|
|
538
|
+
try { fs.unlinkSync(path.join(skillsRoot, 'openagents-workspace.md')); } catch {}
|
|
539
|
+
try { fs.unlinkSync(path.join(skillsRoot, `${workspaceSkillName(this.agentName)}.md`)); } catch {}
|
|
537
540
|
|
|
538
541
|
const skillContent = buildClaudeSkillMd({
|
|
539
542
|
endpoint: this.endpoint,
|
|
@@ -544,7 +547,8 @@ class ClaudeAdapter extends BaseAdapter {
|
|
|
544
547
|
disabledModules: this.disabledModules,
|
|
545
548
|
browserEnabled: this._browserEnabledCache === true,
|
|
546
549
|
});
|
|
547
|
-
fs.writeFileSync(skillFile, skillContent, 'utf-8');
|
|
550
|
+
fs.writeFileSync(skillFile, skillContent, { encoding: 'utf-8', mode: 0o600 });
|
|
551
|
+
fs.chmodSync(skillFile, 0o600);
|
|
548
552
|
this._log(`Wrote workspace skill to ${skillFile}`);
|
|
549
553
|
|
|
550
554
|
return { cmd, skillFile };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const { createHash, randomUUID } = require('crypto');
|
|
7
|
+
const { isTransientNetworkError, isLogPoint } = require('./failure-streak');
|
|
8
|
+
|
|
9
|
+
/** Final answers are saved before delivery; neither tokens nor session IDs are saved. */
|
|
10
|
+
class ResponseOutbox {
|
|
11
|
+
constructor({ endpoint, workspaceId, agentName, directory, prepare, send, log, onRevoked }) {
|
|
12
|
+
const scope = createHash('sha256').update(JSON.stringify([endpoint, workspaceId, agentName])).digest('hex');
|
|
13
|
+
this.directory = directory || path.join(os.homedir(), '.openagents', 'response-outbox', scope);
|
|
14
|
+
this.prepare = prepare;
|
|
15
|
+
this.send = send;
|
|
16
|
+
this.log = log;
|
|
17
|
+
this.onRevoked = onRevoked;
|
|
18
|
+
this.flight = null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
save(entry) {
|
|
22
|
+
fs.mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
23
|
+
const file = path.join(this.directory, `${entry.id}.json`);
|
|
24
|
+
const temp = `${file}.${randomUUID()}.tmp`;
|
|
25
|
+
fs.writeFileSync(temp, JSON.stringify(entry), { mode: 0o600 });
|
|
26
|
+
fs.renameSync(temp, file);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async enqueue(reply) {
|
|
30
|
+
const createdAt = this.readEntries().reduce((latest, entry) => Math.max(latest, entry.createdAt + 1), Date.now());
|
|
31
|
+
this.save({ ...reply, id: randomUUID(), createdAt, attempts: 0 });
|
|
32
|
+
// A new reply arriving during a drain must not be left waiting for a heartbeat.
|
|
33
|
+
if (this.flight) await this.flight;
|
|
34
|
+
await this.flush();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
flush() {
|
|
38
|
+
if (this.flight) return this.flight;
|
|
39
|
+
this.flight = this.drain().finally(() => { this.flight = null; });
|
|
40
|
+
return this.flight;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
readEntries() {
|
|
44
|
+
let files;
|
|
45
|
+
try { files = fs.readdirSync(this.directory).filter(f => /^[\da-f-]+\.json$/.test(f)); }
|
|
46
|
+
catch (e) { if (e.code === 'ENOENT') return []; throw e; }
|
|
47
|
+
return files.map(file => {
|
|
48
|
+
try { return JSON.parse(fs.readFileSync(path.join(this.directory, file), 'utf8')); }
|
|
49
|
+
catch { this.log('Unreadable saved reply in response outbox; retained for recovery.', 'error'); return null; }
|
|
50
|
+
}).filter(Boolean).sort((a, b) => a.createdAt - b.createdAt);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async drain() {
|
|
54
|
+
const entries = this.readEntries();
|
|
55
|
+
const waitingChannels = new Set();
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (waitingChannels.has(entry.channel)) continue;
|
|
58
|
+
if (entry.blocked || entry.nextAttemptAt > Date.now()) {
|
|
59
|
+
waitingChannels.add(entry.channel);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if (!entry.prepared) {
|
|
64
|
+
Object.assign(entry, await this.prepare(entry), { prepared: true });
|
|
65
|
+
this.save(entry);
|
|
66
|
+
}
|
|
67
|
+
await this.send(entry);
|
|
68
|
+
fs.unlinkSync(path.join(this.directory, `${entry.id}.json`));
|
|
69
|
+
if (entry.attempts) this.log(`Delivered saved reply ${entry.id} after recovery.`);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
waitingChannels.add(entry.channel);
|
|
72
|
+
entry.attempts++;
|
|
73
|
+
// A replaced session stops this adapter. Its successor can deliver the
|
|
74
|
+
// saved reply with a fresh session and the SAME idempotency key.
|
|
75
|
+
if (e.name === 'SessionRevokedError') {
|
|
76
|
+
this.onRevoked();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const retry = isTransientNetworkError(e) && (!entry.prepared || entry.safeRetry);
|
|
80
|
+
entry.blocked = !retry;
|
|
81
|
+
entry.nextAttemptAt = Date.now() + Math.min(300000, 1000 * 2 ** Math.min(entry.attempts, 8));
|
|
82
|
+
this.save(entry);
|
|
83
|
+
if (isLogPoint(entry.attempts)) {
|
|
84
|
+
this.log(`Reply ${entry.id} saved locally: ${retry ? 'delivery will retry' : 'delivery needs attention; automatic retries paused'}${e.status ? ` (HTTP ${e.status})` : ''}.`, retry ? 'warn' : 'error');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { ResponseOutbox };
|
|
@@ -746,6 +746,8 @@ function buildClaudeSkillsToolBlock(skillName = 'openagents-workspace') {
|
|
|
746
746
|
'action. It is your ONLY interface to the workspace — every operation goes\n' +
|
|
747
747
|
'through the exact Bash + curl commands documented there. Do not guess\n' +
|
|
748
748
|
'endpoints or improvise; open and follow the skill instructions.\n' +
|
|
749
|
+
`If skill lookup fails, read .claude/skills/${skillName}/SKILL.md directly\n` +
|
|
750
|
+
'from your working directory. Do not search the filesystem for it.\n' +
|
|
749
751
|
`The ${skillName} skill (Bash + curl) covers all workspace operations:\n` +
|
|
750
752
|
'reading message history, discovering agents (and who is in this channel),\n' +
|
|
751
753
|
'sharing files, browsing the shared browser, managing to-do lists, setting\n' +
|
package/src/workspace-client.js
CHANGED
|
@@ -371,10 +371,24 @@ class WorkspaceClient {
|
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
/**
|
|
374
|
-
*
|
|
374
|
+
* Detect safe retry support before using a durable message outbox.
|
|
375
375
|
*/
|
|
376
|
+
async supportsMessageDelivery() {
|
|
377
|
+
if (this._messageDeliverySupported !== undefined && Date.now() < this._messageDeliveryCheckUntil) return this._messageDeliverySupported;
|
|
378
|
+
try {
|
|
379
|
+
const result = await this._get('/v1/events/delivery-capabilities');
|
|
380
|
+
this._messageDeliverySupported = (result.data || result).idempotent_messages === true;
|
|
381
|
+
} catch (e) {
|
|
382
|
+
if (e.status !== 404) throw e;
|
|
383
|
+
this._messageDeliverySupported = false;
|
|
384
|
+
}
|
|
385
|
+
this._messageDeliveryCheckUntil = Date.now() + 60000;
|
|
386
|
+
return this._messageDeliverySupported;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** Send a chat message, optionally with a stable delivery key. */
|
|
376
390
|
async sendMessage(workspaceId, channelName, token, content, {
|
|
377
|
-
senderType = 'agent', senderName, messageType = 'chat', metadata, attachments, sessionId,
|
|
391
|
+
senderType = 'agent', senderName, messageType = 'chat', metadata, attachments, sessionId, idempotencyKey,
|
|
378
392
|
} = {}) {
|
|
379
393
|
const sourcePrefix = senderType === 'agent' ? 'openagents' : 'human';
|
|
380
394
|
const source = senderName ? `${sourcePrefix}:${senderName}` : `${sourcePrefix}:unknown`;
|
|
@@ -395,6 +409,7 @@ class WorkspaceClient {
|
|
|
395
409
|
}
|
|
396
410
|
return this.sendEvent(workspaceId, {
|
|
397
411
|
type: 'workspace.message.posted',
|
|
412
|
+
...(idempotencyKey ? { idempotency_key: idempotencyKey } : {}),
|
|
398
413
|
source,
|
|
399
414
|
target: counterpart,
|
|
400
415
|
payload,
|
|
@@ -405,6 +420,7 @@ class WorkspaceClient {
|
|
|
405
420
|
|
|
406
421
|
return this.sendEvent(workspaceId, {
|
|
407
422
|
type: 'workspace.message.posted',
|
|
423
|
+
...(idempotencyKey ? { idempotency_key: idempotencyKey } : {}),
|
|
408
424
|
source,
|
|
409
425
|
target: `channel/${channelName}`,
|
|
410
426
|
payload,
|
|
@@ -1324,7 +1340,9 @@ class WorkspaceClient {
|
|
|
1324
1340
|
resolve(parsed);
|
|
1325
1341
|
}
|
|
1326
1342
|
} catch {
|
|
1327
|
-
|
|
1343
|
+
const err = new Error(`Invalid response (HTTP ${res.statusCode})`);
|
|
1344
|
+
err.status = res.statusCode;
|
|
1345
|
+
reject(err);
|
|
1328
1346
|
}
|
|
1329
1347
|
});
|
|
1330
1348
|
});
|