ds-bot-dual-surface 0.3.3 → 0.3.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/client.js +47 -2
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -29301,6 +29301,39 @@ function apply(ctx) {
|
|
|
29301
29301
|
});
|
|
29302
29302
|
}
|
|
29303
29303
|
};
|
|
29304
|
+
const SURFACE_SESSIONS = "ds-bot:surface-sessions";
|
|
29305
|
+
let surfaceSessions = {};
|
|
29306
|
+
try {
|
|
29307
|
+
surfaceSessions = JSON.parse(localStorage.getItem(SURFACE_SESSIONS) ?? "{}") ?? {};
|
|
29308
|
+
} catch {
|
|
29309
|
+
surfaceSessions = {};
|
|
29310
|
+
}
|
|
29311
|
+
const rememberSurface = (mode) => {
|
|
29312
|
+
const current = mainView();
|
|
29313
|
+
if (current === void 0 || surfaceSessions[mode] === current) return;
|
|
29314
|
+
surfaceSessions = { ...surfaceSessions, [mode]: current };
|
|
29315
|
+
try {
|
|
29316
|
+
localStorage.setItem(SURFACE_SESSIONS, JSON.stringify(surfaceSessions));
|
|
29317
|
+
} catch {
|
|
29318
|
+
}
|
|
29319
|
+
};
|
|
29320
|
+
const isBotChat = (id) => {
|
|
29321
|
+
const snapshot = roster.getSnapshot();
|
|
29322
|
+
return snapshot.byId?.[id] !== void 0 || snapshot.roomsById?.[id] !== void 0;
|
|
29323
|
+
};
|
|
29324
|
+
const landOn = (mode, last) => {
|
|
29325
|
+
if (mode === "agent") actions.openAgentSession(last);
|
|
29326
|
+
else actions.openSession(last);
|
|
29327
|
+
};
|
|
29328
|
+
const restoreSurface = (mode) => {
|
|
29329
|
+
const last = surfaceSessions[mode];
|
|
29330
|
+
if (last === void 0) return false;
|
|
29331
|
+
if (last === mainView()) return true;
|
|
29332
|
+
if (ctx.sessions.list.getSnapshot().byId?.[last] === void 0) return false;
|
|
29333
|
+
if (mode === "agent" ? isBotChat(last) : !isBotChat(last)) return false;
|
|
29334
|
+
landOn(mode, last);
|
|
29335
|
+
return true;
|
|
29336
|
+
};
|
|
29304
29337
|
const actions = {
|
|
29305
29338
|
...teamActions({ call, after, partFor, roster, ui: ui2, live, cards, heldCards, turnClock, panelFolded }),
|
|
29306
29339
|
learningAnswer: (id, approve) => after(call("learning-answer", { id, approve })),
|
|
@@ -29413,14 +29446,26 @@ function apply(ctx) {
|
|
|
29413
29446
|
if (mode === "bot") ensureBotHome();
|
|
29414
29447
|
return;
|
|
29415
29448
|
}
|
|
29449
|
+
rememberSurface(surface.getSnapshot().mode);
|
|
29416
29450
|
if (mode === "agent") {
|
|
29417
29451
|
ui2.set((state) => ({ ...state, details: null, view: "details", settings: null, palette: null, newChat: null, menu: null, voice: null, exchange: null, memory: null, toast: null }));
|
|
29418
29452
|
}
|
|
29419
29453
|
writeMode(mode);
|
|
29420
29454
|
surface.set((state) => ({ ...state, mode }));
|
|
29421
29455
|
if (mode === "agent" && window.innerWidth >= DSH_NARROW && frame.getSnapshot().collapsed) ctx.layout.toggleSidebar();
|
|
29422
|
-
|
|
29423
|
-
|
|
29456
|
+
const other = mode === "agent" ? "bot" : "agent";
|
|
29457
|
+
setTimeout(() => {
|
|
29458
|
+
if (surface.getSnapshot().mode !== mode) return;
|
|
29459
|
+
if (restoreSurface(mode)) return;
|
|
29460
|
+
if (mode === "bot") ensureBotHome();
|
|
29461
|
+
}, 0);
|
|
29462
|
+
setTimeout(() => {
|
|
29463
|
+
if (surface.getSnapshot().mode !== mode) return;
|
|
29464
|
+
const target = surfaceSessions[mode];
|
|
29465
|
+
if (target === void 0 || mainView() === target) return;
|
|
29466
|
+
if (surfaceSessions[other] !== void 0 && mainView() !== surfaceSessions[other]) return;
|
|
29467
|
+
landOn(mode, target);
|
|
29468
|
+
}, 250);
|
|
29424
29469
|
},
|
|
29425
29470
|
markUnread: (id) => writeUnread(id, true),
|
|
29426
29471
|
beginVisit: (id) => {
|