@clawchatsai/connector 0.1.35 → 0.1.37
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/index.js +7 -4
- package/server/peer/sharing.js +72 -2
- package/server/peer/sharing.test.js +26 -0
- package/server/session-lens.js +68 -8
- package/server/session-lens.test.js +62 -5
- package/server/store/team-store.js +26 -9
- package/server/team.js +294 -60
- package/server/team.test.js +271 -11
package/server/team.test.js
CHANGED
|
@@ -11,6 +11,7 @@ const AGENTS = [{ id: 'main', identity: {} }, { id: 'dev', identity: { name: 'De
|
|
|
11
11
|
function harness(reply, { preparedTitle = 'Team title', titler = null, remote = null, agents = AGENTS } = {}) {
|
|
12
12
|
const sessions = new Map(); // key -> [{ role, content, timestamp, __m: { id } }]
|
|
13
13
|
const calls = [];
|
|
14
|
+
const labels = new Map(); // session key -> label
|
|
14
15
|
let clock = 1_000, seq = 0;
|
|
15
16
|
const events = [];
|
|
16
17
|
let team;
|
|
@@ -18,10 +19,16 @@ function harness(reply, { preparedTitle = 'Team title', titler = null, remote =
|
|
|
18
19
|
calls.push({ method, params });
|
|
19
20
|
switch (method) {
|
|
20
21
|
case 'agents.list': return { agents };
|
|
21
|
-
case 'sessions.create': sessions.
|
|
22
|
-
|
|
22
|
+
case 'sessions.create': case 'sessions.patch': {
|
|
23
|
+
// Labels are unique per gateway, as on the real one.
|
|
24
|
+
if (params.label && [...labels].some(([k, l]) => l === params.label && k !== params.key)) throw new Error(`label already in use: ${params.label}`);
|
|
25
|
+
if (method === 'sessions.create') sessions.set(params.key, []);
|
|
26
|
+
if (params.label) labels.set(params.key, params.label);
|
|
27
|
+
return { ok: true, key: params.key };
|
|
28
|
+
}
|
|
29
|
+
case 'sessions.describe': return { session: { key: params.key, ...(labels.has(params.key) ? { label: labels.get(params.key) } : {}) } };
|
|
23
30
|
case 'sessions.title.prepare': return { title: preparedTitle };
|
|
24
|
-
case 'sessions.
|
|
31
|
+
case 'sessions.delete': labels.delete(params.key); return { ok: true };
|
|
25
32
|
case 'chat.inject': {
|
|
26
33
|
const id = `m${++seq}`;
|
|
27
34
|
sessions.get(params.sessionKey).push({ role: 'assistant', content: [{ type: 'text', text: `[${params.label}]\n\n${params.message}` }], timestamp: ++clock, __m: { id } });
|
|
@@ -55,7 +62,7 @@ function harness(reply, { preparedTitle = 'Team title', titler = null, remote =
|
|
|
55
62
|
team = new TeamCoordinator({ store: createTeamStore(() => db), request, titler, remote, broadcast: d => events.push(JSON.parse(d)), logger: { warn() {}, error() {} } });
|
|
56
63
|
const room = key => (sessions.get(key) || []).map(m => m.content[0].text);
|
|
57
64
|
const settle = async () => { for (let i = 0; i < 50; i++) await new Promise(r => setImmediate(r)); for (const c of team._chains.values()) await c; };
|
|
58
|
-
return { team, calls, room, settle, events, sessions };
|
|
65
|
+
return { team, calls, room, settle, events, sessions, labels };
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
test('parsing helpers', () => {
|
|
@@ -179,6 +186,27 @@ test('converting an existing chat keeps it as the agent working session; delete
|
|
|
179
186
|
assert.ok(h.calls.some(c => c.method === 'sessions.delete' && c.params.key === devWork));
|
|
180
187
|
});
|
|
181
188
|
|
|
189
|
+
test('converting a titled chat: the team chat takes the title; undoing or deleting gives it back', async () => {
|
|
190
|
+
const h = harness(agent => `${agent} ok`);
|
|
191
|
+
const source = 'agent:atlas:dashboard:titled-chat';
|
|
192
|
+
h.sessions.set(source, []);
|
|
193
|
+
h.labels.set(source, 'My chat');
|
|
194
|
+
const { roomKey } = await h.team.createRoom({ sourceKey: source, agentIds: ['dev'], label: 'My chat' });
|
|
195
|
+
assert.equal(h.labels.get(roomKey), 'My chat');
|
|
196
|
+
assert.match(h.labels.get(source), /^My chat · before team chat /);
|
|
197
|
+
assert.equal(await h.team.unconvert(roomKey), source);
|
|
198
|
+
assert.equal(h.labels.get(source), 'My chat');
|
|
199
|
+
|
|
200
|
+
// Deleting the team chat (the gateway already removed its session) also hands the title back.
|
|
201
|
+
const again = (await h.team.createRoom({ sourceKey: source, agentIds: ['dev'], label: 'My chat' })).roomKey;
|
|
202
|
+
assert.notEqual(h.labels.get(source), 'My chat');
|
|
203
|
+
h.labels.delete(again);
|
|
204
|
+
new SessionLens({ broadcast() {}, team: h.team }).sessionsChanged({ sessionKey: again, reason: 'delete' });
|
|
205
|
+
await new Promise(r => setTimeout(r, 0));
|
|
206
|
+
await new Promise(r => setTimeout(r, 0));
|
|
207
|
+
assert.equal(h.labels.get(source), 'My chat');
|
|
208
|
+
});
|
|
209
|
+
|
|
182
210
|
test('unconvert: back to the original chat; only converted rooms', async () => {
|
|
183
211
|
const h = harness(agent => `${agent} ok`);
|
|
184
212
|
const source = 'agent:atlas:dashboard:orig';
|
|
@@ -214,9 +242,9 @@ test('a team chat needs two agents; removing down to one is refused', async () =
|
|
|
214
242
|
const h = harness(() => 'x');
|
|
215
243
|
await assert.rejects(h.team.createRoom({ agentIds: ['dev'] }), /at least two/);
|
|
216
244
|
const { roomKey } = await h.team.createRoom({ agentIds: ['dev', 'atlas'] });
|
|
217
|
-
assert.
|
|
245
|
+
await assert.rejects(h.team.removeAgent(roomKey, 'dev'), /at least two/);
|
|
218
246
|
await h.team.addAgent(roomKey, 'main');
|
|
219
|
-
assert.deepEqual(h.team.removeAgent(roomKey, 'dev').agents.map(a => a.agentId), ['atlas', 'main']);
|
|
247
|
+
assert.deepEqual((await h.team.removeAgent(roomKey, 'dev')).agents.map(a => a.agentId), ['atlas', 'main']);
|
|
220
248
|
});
|
|
221
249
|
|
|
222
250
|
test('stop: a partial reply is posted marked stopped; a reply that finished anyway is posted', async () => {
|
|
@@ -476,17 +504,21 @@ test('rounds: a per-room host setting, validated', async () => {
|
|
|
476
504
|
function twoGateways({ devShared = true } = {}) {
|
|
477
505
|
const forCalls = [];
|
|
478
506
|
const sides = {};
|
|
507
|
+
const net = { connected: true, jarvisShared: true };
|
|
479
508
|
const mk = (self, other, name) => ({
|
|
480
509
|
gatewayId: () => self,
|
|
481
510
|
selfName: () => name,
|
|
482
|
-
|
|
511
|
+
hasShareWith: gw => net.connected && gw === other,
|
|
512
|
+
labelOf: (id, full) => String(full || '').split(/\s+/)[0],
|
|
513
|
+
guestSessionOf: () => null,
|
|
514
|
+
contact: gw => (net.connected && gw === other ? { personId: other, name: other === 'gwK' ? 'Kamil' : 'Houman', email: null } : null),
|
|
483
515
|
personRequest: async (gw, method, params) => {
|
|
484
516
|
if (gw !== other) throw Object.assign(new Error('not connected'), { code: 'not_connected' });
|
|
485
517
|
return sides[other].team.onRoom(method, JSON.parse(JSON.stringify(params)), self);
|
|
486
518
|
},
|
|
487
519
|
ownerOf: id => (String(id).startsWith('peer:sh1:') && self === 'gwH' ? 'gwK' : null),
|
|
488
520
|
ownsShare: shareId => shareId === 'sh1' && self === 'gwK',
|
|
489
|
-
remoteAgents: () => (self === 'gwH' ? [{ agentId: 'peer:sh1:jarvis-guest', name: 'Jarvis · Kamil', ownerName: 'Kamil' }] : []),
|
|
521
|
+
remoteAgents: () => (self === 'gwH' && net.jarvisShared ? [{ agentId: 'peer:sh1:jarvis-guest', name: 'Jarvis · Kamil', ownerName: 'Kamil' }] : []),
|
|
490
522
|
turn: async () => ({ state: 'final', text: 'guest jarvis here' }),
|
|
491
523
|
abort: async () => {},
|
|
492
524
|
actingForName: () => 'Kamil',
|
|
@@ -507,7 +539,7 @@ function twoGateways({ devShared = true } = {}) {
|
|
|
507
539
|
for (const c of sides.gwK.team._syncChains?.values() || []) await c.catch(() => {});
|
|
508
540
|
}
|
|
509
541
|
};
|
|
510
|
-
return { H: sides.gwH, K: sides.gwK, settle, forCalls };
|
|
542
|
+
return { H: sides.gwH, K: sides.gwK, settle, forCalls, net };
|
|
511
543
|
}
|
|
512
544
|
|
|
513
545
|
test('people: a person gets a live copy, posts back, their own agent runs on their gateway, removal ends it', async () => {
|
|
@@ -524,7 +556,7 @@ test('people: a person gets a live copy, posts back, their own agent runs on the
|
|
|
524
556
|
assert.equal(copy.replica.hostName, 'Houman Satarian');
|
|
525
557
|
assert.ok(K.room(copy.roomKey).some(t => t.endsWith('before kamil joins')));
|
|
526
558
|
assert.deepEqual(copy.people.map(p => [p.name, !!p.host, !!p.me]), [['Houman Satarian', true, false], ['Kamil', false, true]]);
|
|
527
|
-
assert.ok(copy.agents.find(a => a.agentId === '
|
|
559
|
+
assert.ok(copy.agents.find(a => a.agentId === 'gwK:jarvis-guest').mine, 'Kamil sees Jarvis as his own agent');
|
|
528
560
|
assert.ok(K.events.some(e => e.event === 'team-invited'));
|
|
529
561
|
|
|
530
562
|
// Kamil asks his own Jarvis: it runs at full strength on Kamil's gateway; Houman's never runs it.
|
|
@@ -554,7 +586,7 @@ test('people: a person gets a live copy, posts back, their own agent runs on the
|
|
|
554
586
|
assert.ok(Object.values(H.team.room(roomKey).authors).some(a => a.agentId === 'dev' && a.actingFor === 'Kamil'));
|
|
555
587
|
|
|
556
588
|
// Houman removes Kamil: Jarvis leaves with him, the copy ends, sending fails.
|
|
557
|
-
H.team.removePerson(roomKey, 'gwK');
|
|
589
|
+
await H.team.removePerson(roomKey, 'gwK');
|
|
558
590
|
await settle();
|
|
559
591
|
assert.ok(!H.team.room(roomKey).agents.some(a => a.agentId === 'peer:sh1:jarvis-guest'));
|
|
560
592
|
assert.equal(K.team.room(copy.roomKey).replica.ended, 'removed');
|
|
@@ -604,3 +636,231 @@ test('a chat turned into a team chat: agents added later get its earlier history
|
|
|
604
636
|
const main = h.team.store.getRoom(roomKey).members.find(m => m.agentId === 'main');
|
|
605
637
|
assert.equal(await h.team._earlier(h.team.store.getRoom(roomKey), main), '');
|
|
606
638
|
});
|
|
639
|
+
|
|
640
|
+
// ── Rooms behave like Discord: one log, membership changes access, never the view ────────────────
|
|
641
|
+
|
|
642
|
+
const lines = (h, key) => h.room(key).map(t => splitLabel(t)).map(m => `${m.label}: ${m.body}`);
|
|
643
|
+
|
|
644
|
+
test('a chat created with someone\'s agent brings its owner in (create, convert, add: one rule)', async () => {
|
|
645
|
+
const { H, K, settle } = twoGateways();
|
|
646
|
+
const created = await H.team.createRoom({ agentIds: ['dev', 'peer:sh1:jarvis-guest'] });
|
|
647
|
+
assert.deepEqual(created.people.map(p => p.personId), ['gwK']);
|
|
648
|
+
await settle();
|
|
649
|
+
assert.ok(K.team.rooms().find(r => r.replica), 'Kamil has a copy straight away, not only his agent\'s session');
|
|
650
|
+
|
|
651
|
+
const { H: H2, K: K2, settle: settle2 } = twoGateways();
|
|
652
|
+
H2.sessions.set('agent:main:dashboard:orig', []);
|
|
653
|
+
const converted = await H2.team.createRoom({ sourceKey: 'agent:main:dashboard:orig', agentIds: ['peer:sh1:jarvis-guest'] });
|
|
654
|
+
assert.deepEqual(converted.people.map(p => p.personId), ['gwK']);
|
|
655
|
+
await settle2();
|
|
656
|
+
assert.ok(K2.team.rooms().find(r => r.replica));
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
test('a chat with only people: the agent stays quiet unless @mentioned', async () => {
|
|
660
|
+
const { H, K, settle } = twoGateways();
|
|
661
|
+
const room = await H.team.createRoom({ personIds: ['gwK'], mentionOnly: true });
|
|
662
|
+
assert.equal(room.mentionOnly, true);
|
|
663
|
+
assert.deepEqual(room.people.map(p => p.personId), ['gwK']);
|
|
664
|
+
assert.equal(room.agents.length, 1, 'one agent of this gateway anchors the room');
|
|
665
|
+
await H.team.send(room.roomKey, { text: 'hey Kamil, just us', userLabel: 'Houman' });
|
|
666
|
+
await settle();
|
|
667
|
+
assert.equal(H.calls.filter(c => c.method === 'chat.send').length, 0, 'no agent ran');
|
|
668
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
669
|
+
assert.ok(K.room(copy.roomKey).some(t => t.endsWith('hey Kamil, just us')));
|
|
670
|
+
// Kamil answers; still nobody else runs. Then an @mention wakes the agent.
|
|
671
|
+
await K.team.send(copy.roomKey, { text: 'hi Houman' });
|
|
672
|
+
await settle();
|
|
673
|
+
assert.equal(H.calls.filter(c => c.method === 'chat.send').length, 0);
|
|
674
|
+
await H.team.send(room.roomKey, { text: '@main what time is it', userLabel: 'Houman' });
|
|
675
|
+
await settle();
|
|
676
|
+
assert.equal(H.calls.filter(c => c.method === 'chat.send').length, 1);
|
|
677
|
+
// The setting is the host's, and it travels to the copy.
|
|
678
|
+
assert.equal(K.team.room(copy.roomKey).mentionOnly, true);
|
|
679
|
+
H.team.setMentionOnly(room.roomKey, false);
|
|
680
|
+
assert.equal(H.team.room(room.roomKey).mentionOnly, false);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
test('adding the first person from the popover turns "agents reply only when @mentioned" on; later adds and create-time adds leave it', async () => {
|
|
684
|
+
const { H, K, settle } = twoGateways();
|
|
685
|
+
const { roomKey } = await H.team.createRoom({ agentIds: ['dev', 'atlas'] });
|
|
686
|
+
assert.equal(H.team.room(roomKey).mentionOnly, false);
|
|
687
|
+
await H.team.addPerson(roomKey, 'gwK', { history: 'all', quietAgents: true });
|
|
688
|
+
await settle();
|
|
689
|
+
assert.equal(H.team.room(roomKey).mentionOnly, true, 'first other person: agents go quiet');
|
|
690
|
+
assert.equal(K.team.rooms().find(r => r.replica).mentionOnly, true, 'and the copy knows');
|
|
691
|
+
H.team.setMentionOnly(roomKey, false);
|
|
692
|
+
await H.team.addPerson(roomKey, 'gwK', { history: 'all', quietAgents: true });
|
|
693
|
+
assert.equal(H.team.room(roomKey).mentionOnly, false, 'the host\'s later choice is kept');
|
|
694
|
+
|
|
695
|
+
const plain = await H.team.createRoom({ agentIds: ['dev', 'atlas'] });
|
|
696
|
+
await H.team.addPerson(plain.roomKey, 'gwK', { history: 'all' });
|
|
697
|
+
assert.equal(H.team.room(plain.roomKey).mentionOnly, false, 'create-time adds decide for themselves');
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
test('the timeline says who joined and left, the same on both sides; agents never see those lines', async () => {
|
|
701
|
+
const { H, K, settle } = twoGateways();
|
|
702
|
+
const { roomKey } = await H.team.createRoom({ agentIds: ['dev', 'atlas'] });
|
|
703
|
+
await H.team.addPerson(roomKey, 'gwK', { history: 'all' });
|
|
704
|
+
await H.team.send(roomKey, { text: '@dev hello', userLabel: 'Houman' });
|
|
705
|
+
await settle();
|
|
706
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
707
|
+
assert.ok(lines(H, roomKey).includes('System: Kamil joined'));
|
|
708
|
+
assert.ok(lines(K, copy.roomKey).includes('System: Kamil joined'), 'Kamil\'s copy has the same line');
|
|
709
|
+
assert.ok(Object.values(K.team.room(copy.roomKey).authors).some(a => a.type === 'system'));
|
|
710
|
+
const devPrompt = H.calls.find(c => c.method === 'chat.send' && c.params.sessionKey.startsWith('agent:dev:')).params.message;
|
|
711
|
+
assert.ok(!/joined/.test(devPrompt), 'system lines are not part of what agents are told');
|
|
712
|
+
|
|
713
|
+
await H.team.removePerson(roomKey, 'gwK');
|
|
714
|
+
await settle();
|
|
715
|
+
assert.ok(lines(H, roomKey).includes('System: Kamil was removed'));
|
|
716
|
+
// The removed person keeps the room as it was, plus how it ended: a read-only archive.
|
|
717
|
+
assert.ok(K.room(copy.roomKey).some(t => t.endsWith('hello')), 'history kept');
|
|
718
|
+
assert.ok(lines(K, copy.roomKey).includes('System: Kamil was removed'));
|
|
719
|
+
assert.equal(lines(K, copy.roomKey).filter(l => /removed/.test(l)).length, 1, 'one line for one event');
|
|
720
|
+
assert.equal(K.team.room(copy.roomKey).replica.ended, 'removed');
|
|
721
|
+
assert.ok(!K.calls.some(c => c.method === 'sessions.delete'), 'nothing deleted');
|
|
722
|
+
// Nothing about the copy changed for the people still in the room.
|
|
723
|
+
assert.equal(H.team.room(roomKey).people.length, 0);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
test('a copy shows entries at the time they were sent, and host and guest agents named `main` never collide', async () => {
|
|
727
|
+
const { H, K, settle } = twoGateways();
|
|
728
|
+
const { roomKey } = await H.team.createRoom({ agentIds: ['main', 'peer:sh1:jarvis-guest'] });
|
|
729
|
+
await H.team.send(roomKey, { text: '@main say hi', userLabel: 'Houman' });
|
|
730
|
+
await settle();
|
|
731
|
+
const hostAuthors = H.team.room(roomKey).authors;
|
|
732
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
733
|
+
const copyAuthors = K.team.room(copy.roomKey).authors;
|
|
734
|
+
const hostTs = Object.values(await H.team._roomEntries(roomKey).then(es => es.map(e => e.ts)));
|
|
735
|
+
const copyTs = Object.values(copyAuthors).map(a => a.ts).filter(Boolean).sort();
|
|
736
|
+
assert.deepEqual(copyTs, [...hostTs].sort(), 'original times');
|
|
737
|
+
// Houman's `main` answered on Houman's gateway. Kamil's own `main` exists too (his default agent) and must not claim that line.
|
|
738
|
+
const hostMain = Object.entries(copyAuthors).find(([, a]) => a.type === 'agent' && a.ownerId === 'gwH');
|
|
739
|
+
assert.ok(hostMain, 'Houman\'s main is recorded under its owner');
|
|
740
|
+
assert.notEqual(hostMain[1].agentId, 'main');
|
|
741
|
+
// Kamil asks his Jarvis: it is told about Houman\'s main reply (not filtered out as its own).
|
|
742
|
+
await K.team.send(copy.roomKey, { text: '@Jarvis-Kamil what did main say?' });
|
|
743
|
+
await settle();
|
|
744
|
+
const prompt = K.calls.filter(c => c.method === 'chat.send' && c.params.sessionKey.startsWith('agent:jarvis:')).at(-1).params.message;
|
|
745
|
+
assert.match(prompt, /main/);
|
|
746
|
+
assert.ok(Object.keys(hostAuthors).length > 0);
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
test('a person takes only their own agent out of a room; the host does not need to be asked', async () => {
|
|
750
|
+
const { H, K, settle } = twoGateways();
|
|
751
|
+
const { roomKey } = await H.team.createRoom({ agentIds: ['dev', 'peer:sh1:jarvis-guest'] });
|
|
752
|
+
await settle();
|
|
753
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
754
|
+
await assert.rejects(K.team.leave(copy.roomKey, { agentId: copy.agents.find(a => !a.mine).agentId }), /Not your agent/);
|
|
755
|
+
const mine = copy.agents.find(a => a.mine);
|
|
756
|
+
await K.team.leave(copy.roomKey, { agentId: mine.agentId });
|
|
757
|
+
await settle();
|
|
758
|
+
const room = H.team.room(roomKey);
|
|
759
|
+
assert.ok(!room.agents.some(a => a.agentId === 'peer:sh1:jarvis-guest'));
|
|
760
|
+
assert.deepEqual(room.people.map(p => p.personId), ['gwK'], 'Kamil stays');
|
|
761
|
+
assert.ok(lines(H, roomKey).some(l => /^System: Jarvis · Kamil left$/.test(l)));
|
|
762
|
+
assert.equal(K.team.room(copy.roomKey).replica.ended, null, 'his copy is still live');
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
test('@mentions in an agent\'s reply get the mentioned agent one answer, with a hard stop', async () => {
|
|
766
|
+
// dev always answers by mentioning atlas, atlas always mentions dev back: it must stop.
|
|
767
|
+
const h = harness(agent => (agent === 'dev' ? 'over to @Atlas' : 'back to @Dev'));
|
|
768
|
+
const { roomKey } = await h.team.createRoom({ agentIds: ['dev', 'atlas'] });
|
|
769
|
+
await h.team.send(roomKey, { text: '@dev start', userLabel: 'H' });
|
|
770
|
+
await h.settle();
|
|
771
|
+
const sends = h.calls.filter(c => c.method === 'chat.send').length;
|
|
772
|
+
assert.ok(sends >= 2, 'atlas answered the mention');
|
|
773
|
+
assert.ok(sends <= 4, `bounded, not endless (${sends})`);
|
|
774
|
+
// A reply that names nobody ends the chain.
|
|
775
|
+
const h2 = harness(agent => `${agent} done`);
|
|
776
|
+
const r2 = await h2.team.createRoom({ agentIds: ['dev', 'atlas'] });
|
|
777
|
+
await h2.team.send(r2.roomKey, { text: '@dev go', userLabel: 'H' });
|
|
778
|
+
await h2.settle();
|
|
779
|
+
assert.equal(h2.calls.filter(c => c.method === 'chat.send').length, 1);
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
test('connections ending: people and agents leave the rooms, copies end as archives', async () => {
|
|
783
|
+
const { H, K, settle, net } = twoGateways();
|
|
784
|
+
const { roomKey } = await H.team.createRoom({ agentIds: ['dev', 'peer:sh1:jarvis-guest', 'atlas'] });
|
|
785
|
+
await H.team.send(roomKey, { text: 'before', userLabel: 'Houman' });
|
|
786
|
+
await settle();
|
|
787
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
788
|
+
|
|
789
|
+
// Kamil stops sharing Jarvis only: the agent leaves, Kamil stays.
|
|
790
|
+
net.jarvisShared = false;
|
|
791
|
+
await H.team._reconcileNow();
|
|
792
|
+
await settle();
|
|
793
|
+
assert.ok(!H.team.room(roomKey).agents.some(a => a.agentId === 'peer:sh1:jarvis-guest'));
|
|
794
|
+
assert.deepEqual(H.team.room(roomKey).people.map(p => p.personId), ['gwK']);
|
|
795
|
+
assert.ok(lines(H, roomKey).includes('System: Jarvis · Kamil is no longer shared'));
|
|
796
|
+
assert.equal(K.team.room(copy.roomKey).replica.ended, null);
|
|
797
|
+
|
|
798
|
+
// The whole connection ends: Kamil leaves Houman's room; on Kamil's side the copy is kept, read-only.
|
|
799
|
+
net.connected = false;
|
|
800
|
+
await H.team._reconcileNow();
|
|
801
|
+
await K.team._reconcileNow();
|
|
802
|
+
assert.deepEqual(H.team.room(roomKey).people, []);
|
|
803
|
+
assert.ok(lines(H, roomKey).includes('System: Kamil is no longer connected'));
|
|
804
|
+
const kc = K.team.room(copy.roomKey);
|
|
805
|
+
assert.equal(kc.replica.ended, 'disconnected');
|
|
806
|
+
assert.ok(K.room(copy.roomKey).some(t => t.endsWith('before')), 'history kept');
|
|
807
|
+
assert.ok(lines(K, copy.roomKey).includes("System: You're no longer connected with Houman Satarian"));
|
|
808
|
+
await assert.rejects(K.team.send(copy.roomKey, { text: 'hello?' }), /no longer connected/);
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
test('ending or undoing a chat with people turns their copies into archives', async () => {
|
|
812
|
+
const { H, K, settle } = twoGateways();
|
|
813
|
+
H.sessions.set('agent:main:dashboard:orig2', []);
|
|
814
|
+
const { roomKey } = await H.team.createRoom({ sourceKey: 'agent:main:dashboard:orig2', agentIds: ['peer:sh1:jarvis-guest'] });
|
|
815
|
+
await H.team.send(roomKey, { text: 'before the end', userLabel: 'Houman' });
|
|
816
|
+
await settle();
|
|
817
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
818
|
+
await H.team.unconvert(roomKey);
|
|
819
|
+
await settle();
|
|
820
|
+
const kc = K.team.room(copy.roomKey);
|
|
821
|
+
assert.equal(kc.replica.ended, 'deleted');
|
|
822
|
+
assert.ok(K.room(copy.roomKey).some(t => t.endsWith('before the end')));
|
|
823
|
+
assert.ok(lines(K, copy.roomKey).includes('System: Houman Satarian ended this chat'));
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
test('a copy has no label until the host\'s chat has a title, then follows it', async () => {
|
|
827
|
+
const { H, K, settle } = twoGateways();
|
|
828
|
+
const { roomKey } = await H.team.createRoom({ agentIds: ['dev', 'peer:sh1:jarvis-guest'] });
|
|
829
|
+
await settle();
|
|
830
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
831
|
+
assert.equal(K.labels.get(copy.roomKey), undefined, 'untitled: the app names it after who is in it');
|
|
832
|
+
H.labels.set(roomKey, 'Trip plans');
|
|
833
|
+
await H.team.send(roomKey, { text: 'more', userLabel: 'Houman' });
|
|
834
|
+
await settle();
|
|
835
|
+
assert.equal(K.labels.get(copy.roomKey), 'Trip plans · Houman Satarian');
|
|
836
|
+
H.labels.set(roomKey, 'Trip plans v2');
|
|
837
|
+
await H.team.send(roomKey, { text: 'again', userLabel: 'Houman' });
|
|
838
|
+
await settle();
|
|
839
|
+
assert.equal(K.labels.get(copy.roomKey), 'Trip plans v2 · Houman Satarian');
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
test('names that clash: a converted chat\'s earlier answers carry the full host name, like the agents list does', async () => {
|
|
843
|
+
const { H, K, settle } = twoGateways();
|
|
844
|
+
H.team.remote.labelOf = () => 'Houman Satarian'; // another Houman is in the picture
|
|
845
|
+
H.sessions.set('agent:main:dashboard:orig', [
|
|
846
|
+
{ role: 'user', content: [{ type: 'text', text: 'what is the code word?' }], timestamp: 1, __m: { id: 'o1' } },
|
|
847
|
+
{ role: 'assistant', content: [{ type: 'text', text: 'marmot' }], timestamp: 2, __m: { id: 'o2' } },
|
|
848
|
+
]);
|
|
849
|
+
await H.team.createRoom({ sourceKey: 'agent:main:dashboard:orig', agentIds: ['peer:sh1:jarvis-guest'] });
|
|
850
|
+
await settle();
|
|
851
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
852
|
+
assert.ok(lines(K, copy.roomKey).includes('main · Houman Satarian: marmot'), lines(K, copy.roomKey).join(' | '));
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
test('a host renaming the chat reaches the copies without anyone sending a message', async () => {
|
|
856
|
+
const { H, K, settle } = twoGateways();
|
|
857
|
+
const { roomKey } = await H.team.createRoom({ personIds: ['gwK'], mentionOnly: true, label: 'First title' });
|
|
858
|
+
await settle();
|
|
859
|
+
const copy = K.team.rooms().find(r => r.replica);
|
|
860
|
+
const label = () => K.labels.get(copy.roomKey);
|
|
861
|
+
assert.equal(label(), 'First title · Houman Satarian');
|
|
862
|
+
H.labels.set(roomKey, 'Second title');
|
|
863
|
+
await H.team.onSessionPatched(roomKey);
|
|
864
|
+
await settle();
|
|
865
|
+
assert.equal(label(), 'Second title · Houman Satarian');
|
|
866
|
+
});
|