@sparkelf/dsh-group-chat 0.5.3 → 0.5.4
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/lib/client.js +190 -171
- package/lib/client.js.map +1 -1
- package/lib/index.js +59 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -792,6 +792,49 @@ const cleanupRoomSessions = async (input) => {
|
|
|
792
792
|
};
|
|
793
793
|
};
|
|
794
794
|
/**
|
|
795
|
+
* Register a room's Session with the workspace that owns its directory.
|
|
796
|
+
*
|
|
797
|
+
* The shell's `openSession` selects a Session that belongs to a Workspace, so a room created
|
|
798
|
+
* with a `cwd` and no workspace id is not selectable until this runs. Registration is idempotent
|
|
799
|
+
* on the registry (`attachSession` checks membership before writing), which is what lets the
|
|
800
|
+
* discovery poll run it on every boot without duplicating rows.
|
|
801
|
+
*
|
|
802
|
+
* Never throws: a room that cannot be registered still reads and writes through its Host, only
|
|
803
|
+
* the main view cannot follow it, and that is a state worth reporting rather than a failed open.
|
|
804
|
+
* @param registry - the workspace registry surface, absent on a minimal host.
|
|
805
|
+
* @param directory - the room directory the workspace is resolved by.
|
|
806
|
+
* @param sessionId - the room's canonical Session.
|
|
807
|
+
* @param log - optional warning sink; the plugin passes its Cordis logger.
|
|
808
|
+
* @returns whether the Session is now attached.
|
|
809
|
+
*/
|
|
810
|
+
const attachRoomSession = async (registry, directory, sessionId, log) => {
|
|
811
|
+
if (registry === void 0) {
|
|
812
|
+
log?.warn?.("[group-chat] the workspace registry is unavailable; the room session stays unlisted", sessionId);
|
|
813
|
+
return {
|
|
814
|
+
attached: false,
|
|
815
|
+
reason: "registry-unavailable"
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
try {
|
|
819
|
+
const workspace = await registry.resolveByPath(directory);
|
|
820
|
+
if (workspace === void 0) {
|
|
821
|
+
log?.warn?.("[group-chat] no workspace owns the room directory; the room session stays unlisted", sessionId, directory);
|
|
822
|
+
return {
|
|
823
|
+
attached: false,
|
|
824
|
+
reason: "workspace-not-found"
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
await workspace.attachSession(sessionId);
|
|
828
|
+
return { attached: true };
|
|
829
|
+
} catch (error) {
|
|
830
|
+
log?.warn?.("[group-chat] attaching the room session to its workspace failed", sessionId, error);
|
|
831
|
+
return {
|
|
832
|
+
attached: false,
|
|
833
|
+
reason: "attach-failed"
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
/**
|
|
795
838
|
* Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
|
|
796
839
|
*
|
|
797
840
|
* This can be used with JS designed for browsers to improve reuse of code and
|
|
@@ -9271,6 +9314,7 @@ var RoomSessions = class {
|
|
|
9271
9314
|
const resumed = await this.resolvePersisted(sessionId, directory);
|
|
9272
9315
|
if (resumed !== void 0) {
|
|
9273
9316
|
await this.installRoomModel(resumed, room, false);
|
|
9317
|
+
await this.attachToWorkspace(sessionId, directory);
|
|
9274
9318
|
return resumed;
|
|
9275
9319
|
}
|
|
9276
9320
|
const created = await this.ctx.sessionController.create({
|
|
@@ -9285,6 +9329,7 @@ var RoomSessions = class {
|
|
|
9285
9329
|
const session = this.existing(roomId);
|
|
9286
9330
|
if (session === void 0) throw new Error(`group-chat could not open a session for room ${roomId}`);
|
|
9287
9331
|
await this.installRoomModel(session, room, true);
|
|
9332
|
+
await this.attachToWorkspace(sessionId, directory);
|
|
9288
9333
|
return session;
|
|
9289
9334
|
}
|
|
9290
9335
|
/** Load a persisted room Session, or `undefined` only when the controller denies it exists. */
|
|
@@ -9331,6 +9376,20 @@ var RoomSessions = class {
|
|
|
9331
9376
|
get archiveRegistry() {
|
|
9332
9377
|
return hostService(this.ctx, "workspaceRegistry");
|
|
9333
9378
|
}
|
|
9379
|
+
/**
|
|
9380
|
+
* Attach the room's Session to the workspace that owns its directory.
|
|
9381
|
+
*
|
|
9382
|
+
* The shell's `openSession` selects a Session that belongs to a Workspace, so a room created
|
|
9383
|
+
* with a `cwd` alone is not selectable and clicking it moves the highlight only. Attaching is
|
|
9384
|
+
* idempotent on the registry side, and every failure here is logged rather than fatal: a room
|
|
9385
|
+
* whose registration failed still reads and writes through its Host, only the main view
|
|
9386
|
+
* cannot follow it.
|
|
9387
|
+
* @param sessionId - the room's canonical Session.
|
|
9388
|
+
* @param directory - the room directory the workspace is resolved by.
|
|
9389
|
+
*/
|
|
9390
|
+
async attachToWorkspace(sessionId, directory) {
|
|
9391
|
+
await attachRoomSession(hostService(this.ctx, "workspaceRegistry"), directory, sessionId, this.ctx.logger);
|
|
9392
|
+
}
|
|
9334
9393
|
/** Hide a replacement the controller minted instead of honoring the room id. */
|
|
9335
9394
|
async archiveReplacement(sessionId) {
|
|
9336
9395
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparkelf/dsh-group-chat",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Human-agent group chat for DataOps-managed DSH workspaces: rooms broadcast to every member, and only a member's own @mention wakes that member's agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|