@clawchatsai/connector 0.2.4 → 0.2.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/server/team.js +11 -4
- package/server/team.test.js +12 -0
package/package.json
CHANGED
package/server/team.js
CHANGED
|
@@ -221,6 +221,15 @@ export class TeamCoordinator {
|
|
|
221
221
|
return [...this._agents.list, ...this._remoteAgents()];
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
/** One agent, or null. A miss reads agents.list again: an agent added in the last minute isn't in the cache yet. */
|
|
225
|
+
async _agent(agentId) {
|
|
226
|
+
const find = list => list.find(a => a.agentId === agentId) || null;
|
|
227
|
+
const hit = find(await this.agents());
|
|
228
|
+
if (hit || TeamCoordinator.isRemote(agentId)) return hit;
|
|
229
|
+
this._agents = null;
|
|
230
|
+
return find(await this.agents());
|
|
231
|
+
}
|
|
232
|
+
|
|
224
233
|
_remoteAgents() {
|
|
225
234
|
let list = [];
|
|
226
235
|
try { list = (this.remote?.remoteAgents() || []).map(a => ({ agentId: a.agentId, name: a.name, remote: true, ownerName: a.ownerName })); }
|
|
@@ -340,9 +349,7 @@ export class TeamCoordinator {
|
|
|
340
349
|
members.unshift({ agentId: own.agentId });
|
|
341
350
|
}
|
|
342
351
|
if (members.length + people.length < 2) throw new Error('a team chat needs at least two participants');
|
|
343
|
-
const
|
|
344
|
-
const unknown = members.find(m => !known.has(m.agentId));
|
|
345
|
-
if (unknown) throw new Error(`unknown agent: ${unknown.agentId}`);
|
|
352
|
+
for (const m of members) if (!await this._agent(m.agentId)) throw new Error(`unknown agent: ${m.agentId}`);
|
|
346
353
|
|
|
347
354
|
const roomKey = `agent:${members[0].agentId}:dashboard:${crypto.randomUUID()}`;
|
|
348
355
|
// Register first so the lens never shows a working session or forwards a half-made room.
|
|
@@ -428,7 +435,7 @@ export class TeamCoordinator {
|
|
|
428
435
|
async addAgent(roomKey, agentId, { history = 'all' } = {}) {
|
|
429
436
|
const room = this.store.getRoom(roomKey);
|
|
430
437
|
if (room?.host) throw new Error("Only the chat's host can add agents");
|
|
431
|
-
const named =
|
|
438
|
+
const named = await this._agent(agentId);
|
|
432
439
|
if (!named) throw new Error(`unknown agent: ${agentId}`);
|
|
433
440
|
const fresh = !room?.members.some(m => m.agentId === agentId);
|
|
434
441
|
if (!this.store.addMember(roomKey, agentId, { history, seenAt: history === 'now' ? Date.now() : 0 })) return null;
|
package/server/team.test.js
CHANGED
|
@@ -251,6 +251,18 @@ test('a team chat needs two agents; removing down to one is refused', async () =
|
|
|
251
251
|
assert.deepEqual((await h.team.removeAgent(roomKey, 'dev')).agents.map(a => a.agentId), ['atlas', 'main']);
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
+
test('an agent added on the gateway a moment ago can join right away (agents.list cache refreshed on a miss)', async () => {
|
|
255
|
+
const agents = [...AGENTS];
|
|
256
|
+
const h = harness(() => 'x', { agents });
|
|
257
|
+
const { roomKey } = await h.team.createRoom({ agentIds: ['dev', 'atlas'] }); // fills the cache
|
|
258
|
+
agents.push({ id: 'helper', identity: { name: 'Helper' } }, { id: 'ops', identity: {} });
|
|
259
|
+
assert.deepEqual((await h.team.createRoom({ agentIds: ['main', 'helper'] })).agents.map(a => a.agentId), ['main', 'helper']);
|
|
260
|
+
assert.deepEqual((await h.team.addAgent(roomKey, 'ops')).agents.map(a => a.agentId), ['dev', 'atlas', 'ops']);
|
|
261
|
+
const lists = h.calls.filter(c => c.method === 'agents.list').length;
|
|
262
|
+
await assert.rejects(h.team.createRoom({ agentIds: ['main', 'nobody'] }), /unknown agent: nobody/);
|
|
263
|
+
assert.equal(h.calls.filter(c => c.method === 'agents.list').length, lists + 1); // one re-read, then refused
|
|
264
|
+
});
|
|
265
|
+
|
|
254
266
|
test('stop: a partial reply is posted marked stopped; a reply that finished anyway is posted', async () => {
|
|
255
267
|
const pending = [];
|
|
256
268
|
const h = harness(agent => new Promise(resolve => pending.push({ agent, resolve })));
|