@clawchatsai/connector 0.1.38 → 0.1.40
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/peer/sharing.js +15 -3
- package/server/peer/sharing.test.js +7 -3
- package/server/team.js +2 -1
- package/server/team.test.js +1 -0
package/package.json
CHANGED
package/server/peer/sharing.js
CHANGED
|
@@ -722,11 +722,23 @@ export class SharingManager {
|
|
|
722
722
|
return this._db().prepare('UPDATE peer_funnel SET project = ?, updated_at = ? WHERE project = ?').run(String(to).slice(0, 100), Date.now(), from).changes;
|
|
723
723
|
}
|
|
724
724
|
|
|
725
|
+
/** Every gateway this person has been on, across shares of any age (old ones were ended and replaced). */
|
|
726
|
+
gatewayIdsOf(email) {
|
|
727
|
+
const ids = new Set();
|
|
728
|
+
for (const s of this._shares) {
|
|
729
|
+
const o = s.as === 'owner' ? s.requester : s.owner;
|
|
730
|
+
if (String(o?.email || '').toLowerCase() === email && o.gatewayId) ids.add(o.gatewayId);
|
|
731
|
+
}
|
|
732
|
+
return ids;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/** Our agents' guest sessions for this person, including ones from shares since ended. */
|
|
725
736
|
_guestSessionKeysOf(email) {
|
|
737
|
+
const ids = this.gatewayIdsOf(email);
|
|
726
738
|
const keys = [];
|
|
727
|
-
for (const r of this._db().prepare('SELECT
|
|
728
|
-
|
|
729
|
-
if (
|
|
739
|
+
for (const r of this._db().prepare('SELECT p.session_key, g.grant_json FROM peer_sessions p JOIN peer_grants g ON g.share_id = p.share_id').all()) {
|
|
740
|
+
let gw; try { gw = JSON.parse(r.grant_json).requesterGatewayId; } catch { continue; }
|
|
741
|
+
if (ids.has(gw)) keys.push(r.session_key);
|
|
730
742
|
}
|
|
731
743
|
return keys;
|
|
732
744
|
}
|
|
@@ -118,10 +118,14 @@ test("funnel: a person's chats go to the project chosen for them; renames follow
|
|
|
118
118
|
const create = s.ownerCalls.find(c => c.method === 'sessions.create').params;
|
|
119
119
|
assert.equal(create.category, 'Friends');
|
|
120
120
|
|
|
121
|
-
// Changed later: chats already there move.
|
|
121
|
+
// Changed later: chats already there move, including ones from a share since ended (a new share replaced it).
|
|
122
|
+
const db = s.owner._db();
|
|
123
|
+
db.prepare('INSERT INTO peer_grants (share_id, grant_json, sig, created_at, revoked_at) VALUES (?, ?, ?, ?, ?)').run('old1', JSON.stringify({ requesterGatewayId: 'gwH', agents: [] }), 'x', 1, 2);
|
|
124
|
+
db.prepare('INSERT INTO peer_sessions (share_id, room_id, agent_id, session_key) VALUES (?, ?, ?, ?)').run('old1', 'r0', 'jarvis-guest', 'agent:jarvis-guest:dashboard:old');
|
|
122
125
|
const moved = await s.owner.setFunnel('h@x.dev', 'Work friends');
|
|
123
|
-
assert.equal(moved.moved,
|
|
124
|
-
assert.deepEqual(s.ownerCalls.filter(c => c.method === 'sessions.patch' && c.params.category).map(c => [c.params.key, c.params.category])
|
|
126
|
+
assert.equal(moved.moved, 2);
|
|
127
|
+
assert.deepEqual(s.ownerCalls.filter(c => c.method === 'sessions.patch' && c.params.category).map(c => [c.params.key, c.params.category]).sort(),
|
|
128
|
+
[[create.key, 'Work friends'], ['agent:jarvis-guest:dashboard:old', 'Work friends']].sort());
|
|
125
129
|
|
|
126
130
|
// The project is renamed in ClawChats: they follow. Deleted: the next chat makes it again (sessions.create names it).
|
|
127
131
|
assert.equal(s.owner.renameFunnel('Work friends', 'Team'), 1);
|
package/server/team.js
CHANGED
|
@@ -219,8 +219,9 @@ export class TeamCoordinator {
|
|
|
219
219
|
/** The project for this person's chats changed: our copies of the chats they host move there. Returns how many. */
|
|
220
220
|
async refileCopies(email, project) {
|
|
221
221
|
let moved = 0;
|
|
222
|
+
const gateways = this.remote?.gatewayIdsOf?.(email) || new Set(); // includes ones from ended connections: their archived copies move too
|
|
222
223
|
for (const r of this.store.listRooms()) {
|
|
223
|
-
if (!r.host ||
|
|
224
|
+
if (!r.host || !gateways.has(r.host.gatewayId)) continue;
|
|
224
225
|
if (await this.request('sessions.patch', { key: r.roomKey, category: project }).then(() => true, () => false)) moved++;
|
|
225
226
|
}
|
|
226
227
|
return moved;
|
package/server/team.test.js
CHANGED
|
@@ -557,6 +557,7 @@ function twoGateways({ devShared = true } = {}) {
|
|
|
557
557
|
labelOf: (id, full) => String(full || '').split(/\s+/)[0],
|
|
558
558
|
guestSessionOf: () => null,
|
|
559
559
|
funnelOf: (email, name) => `Shared with ${name}`,
|
|
560
|
+
gatewayIdsOf: () => new Set(['gwH', 'gwK']),
|
|
560
561
|
contact: gw => (net.connected && gw === other ? { personId: other, name: other === 'gwK' ? 'Kamil' : 'Houman', email: null } : null),
|
|
561
562
|
personRequest: async (gw, method, params) => {
|
|
562
563
|
if (gw !== other) throw Object.assign(new Error('not connected'), { code: 'not_connected' });
|