Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(agents): the real agent chat on desk monitors, a screen-filling dive, and the office remembers where you were

rubenluetke10-beepe48f96f0fd5e
diff --git a/jarvis/ui/web/frontend/src/components/society/office/LiveMonitors.tsx b/jarvis/ui/web/frontend/src/components/society/office/LiveMonitors.tsx
index 4002b307a7..35752aa2f5 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/LiveMonitors.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/LiveMonitors.tsx
@@ -2,7 +2,7 @@
* Desk monitors that show the seated agent's live chat. A click on a screen
* zooms the camera into it and then opens that agent's chat view.
*/
-import { useEffect, useMemo, useRef } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import { useFrame, type ThreeEvent } from "@react-three/fiber";
import { CanvasTexture, SRGBColorSpace, type Mesh } from "three";
import type { SocietyAgent } from "../data";
@@ -10,6 +10,13 @@ import type { DeskSlot, Point } from "./officeLayout";
import type { DeskChat } from "./useDeskChats";
import type { ChatLineKind } from "./deskChat";
import { seatedAtDesk } from "./walkerRegistry";
+import { RealChatScreen } from "./RealChatScreen";
+
+/** At most this many monitors run the real chat at once; farther ones keep the light preview. */
+const MAX_REAL_CHATS = 3;
+/** Start the real chat within this camera distance, stop it beyond the second (no flicker at the edge). */
+const REAL_CHAT_NEAR_M = 11;
+const REAL_CHAT_FAR_M = 14;
const W = 512, H = 296;
/** Same place as the instanced screen, a hair in front of it. */
@@ -70,8 +77,9 @@ export function drawChatScreen(ctx: CanvasRenderingContext2D, agent: Pick<Societ
if (agent.state === "working") { ctx.fillStyle = "#4ade80"; ctx.fillRect(textLeft, H - 12, 9, 4); }
}
-function Screen({ desk, agent, chat, onOpen }: {
- desk: DeskSlot; agent: SocietyAgent; chat: DeskChat | undefined; onOpen: (agentId: string, screen: Point & { y: number }, facing: number) => void;
+function Screen({ desk, agent, chat, real, roster, onOpen }: {
+ desk: DeskSlot; agent: SocietyAgent; chat: DeskChat | undefined; real: boolean; roster: SocietyAgent[];
+ onOpen: (agentId: string, screen: Point & { y: number }, facing: number) => void;
}) {
const mesh = useRef<Mesh>(null);
const turn = desk.facing === "north" ? 0 : Math.PI;
@@ -109,19 +117,45 @@ function Screen({ desk, agent, chat, onOpen }: {
<planeGeometry args={[SCREEN_W, SCREEN_H]} />
<meshBasicMaterial map={surface.texture} toneMapped={false} />
</mesh>
+ {real && <RealChatScreen agent={agent} roster={roster} position={[0, SCREEN_Y, SCREEN_Z + 0.002]} />}
</group>
);
}
+/** Which seated agents get the real chat: the nearest few to the camera, with hysteresis. Pure. */
+export function pickRealChats(candidates: { id: string; distance: number }[], current: ReadonlySet<string>): Set<string> {
+ const keep = candidates
+ .filter((c) => c.distance <= (current.has(c.id) ? REAL_CHAT_FAR_M : REAL_CHAT_NEAR_M))
+ .sort((a, b) => a.distance - b.distance)
+ .slice(0, MAX_REAL_CHATS);
+ return new Set(keep.map((c) => c.id));
+}
+
export function LiveMonitors({ desks, agents, chats, onOpen }: {
desks: DeskSlot[]; agents: ReadonlyMap<string, SocietyAgent>; chats: ReadonlyMap<string, DeskChat>;
onOpen: (agentId: string, screen: Point & { y: number }, facing: number) => void;
}) {
+ const roster = useMemo(() => [...agents.values()], [agents]);
+ const [real, setReal] = useState<ReadonlySet<string>>(new Set());
+ const nextCheck = useRef(0);
+ useFrame(({ camera, clock }) => {
+ if (clock.elapsedTime < nextCheck.current) return;
+ nextCheck.current = clock.elapsedTime + 0.3;
+ const candidates: { id: string; distance: number }[] = [];
+ for (const desk of desks) {
+ const agent = desk.agentId ? agents.get(desk.agentId) : undefined;
+ // The lead's chat is the app's own voice chat; its monitor keeps the preview.
+ if (!agent || agent.tier === "lead" || !agent.chatSessionId || !seatedAtDesk.has(agent.agentId)) continue;
+ candidates.push({ id: agent.agentId, distance: Math.hypot(camera.position.x - desk.x, camera.position.y - 1.2, camera.position.z - desk.z) });
+ }
+ const next = pickRealChats(candidates, real);
+ if (next.size !== real.size || [...next].some((id) => !real.has(id))) setReal(next);
+ });
return (
<group>
{desks.map((desk) => {
const agent = desk.agentId ? agents.get(desk.agentId) : undefined;
- return agent ? <Screen key={desk.id} desk={desk} agent={agent} chat={chats.get(agent.agentId)} onOpen={onOpen} /> : null;
+ return agent ? <Screen key={desk.id} desk={desk} agent={agent} chat={chats.get(agent.agentId)} real={real.has(agent.agentId)} roster={roster} onOpen={onOpen} /> : null;
})}
</group>
);
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsx
index d079d02919..2019d7c52a 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeCameraRig.tsx
@@ -8,17 +8,25 @@
import { useEffect, useRef } from "react";
import { OrbitControls } from "@react-three/drei";
import { useFrame, useThree } from "@react-three/fiber";
-import { Vector3 } from "three";
+import { MOUSE, Vector3 } from "three";
import type { OrbitControls as OrbitControlsImpl } from "three-stdlib";
import { cameraHome, CAMERA_LIMITS, HOME_PITCH_RAD, HOME_YAW_RAD } from "./officeCamera";
import type { OfficeLayout } from "./officeLayout";
-import { cameraView, player, useOfficeStore } from "./officeStore";
+import { cameraView, officeSession, player, useOfficeStore } from "./officeStore";
/** Where the camera starts: close behind the character, south-east, looking down. */
export const FOLLOW_DISTANCE = 15;
const TARGET_HEIGHT = 0.8;
/** How long the dive into a monitor takes before the chat opens. */
-export const ZOOM_SECONDS = 0.9;
+export const ZOOM_SECONDS = 1.15;
+/** Monitor screen size in metres (see LiveMonitors): the dive ends with it filling the view. */
+const SCREEN_W = 0.66, SCREEN_H = 0.38;
+
+/** How far in front of a screen the camera must stand for the screen to fill the view. */
+export function screenFillDistance(fovDeg: number, aspect: number): number {
+ const v = Math.tan((fovDeg * Math.PI) / 360);
+ return Math.max(SCREEN_H / 2 / v, SCREEN_W / 2 / (v * Math.max(0.2, aspect)));
+}
export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; overview: number }) {
const controls = useRef<OrbitControlsImpl>(null);
@@ -35,8 +43,27 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ov
const desired = useRef(new Vector3());
const delta = useRef(new Vector3());
- // Start close to the character.
+ // Remember the view when leaving: the pose before a dive, never the inside of a monitor.
+ const preDive = useRef<{ position: [number, number, number]; target: [number, number, number] } | null>(null);
+ useEffect(() => () => {
+ const c = controls.current;
+ officeSession.camera = preDive.current ?? (c
+ ? { position: camera.position.toArray() as [number, number, number], target: c.target.toArray() as [number, number, number] }
+ : null);
+ officeSession.follow = useOfficeStore.getState().follow;
+ }, [camera]);
+
+ // Start where the last visit left off, or close to the character.
useEffect(() => {
+ if (import.meta.env.DEV) (window as unknown as Record<string, unknown>).__office = { camera, controls: controls.current, gl, scene };
+ const saved = officeSession.camera;
+ if (saved) {
+ camera.position.set(...saved.position);
+ controls.current?.target.set(...saved.target);
+ controls.current?.update();
+ useOfficeStore.getState().setFollow(officeSession.follow);
+ return;
+ }
const target = new Vector3(player.x, TARGET_HEIGHT, player.z);
const horizontal = Math.cos(HOME_PITCH_RAD) * FOLLOW_DISTANCE;
camera.position.set(target.x + Math.sin(HOME_YAW_RAD) * horizontal, Math.sin(HOME_PITCH_RAD) * FOLLOW_DISTANCE + TARGET_HEIGHT,
@@ -44,7 +71,6 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ov
controls.current?.target.copy(target);
controls.current?.update();
useOfficeStore.getState().setFollow(true);
- if (import.meta.env.DEV) (window as unknown as Record<string, unknown>).__office = { camera, controls: controls.current, gl, scene };
}, [camera, gl, scene, layout.spawn]);
// "Overview": frame the whole floor and stop following.
@@ -59,14 +85,22 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ov
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [overview]);
- // A right-drag (or Shift/Ctrl-drag) pans: the person takes the camera, so stop following.
+ // A right-drag (or Ctrl-drag) pans: the person takes the camera, so stop following.
+ // Shift is the sprint key, so a Shift-drag must still rotate: OrbitControls
+ // turns Shift+left into a pan, which slid the view off a running character
+ // while the follow kept dragging it back. Flipping the left button to "pan"
+ // for that press makes the controls' own Shift inversion land on "rotate".
+ // (Capture phase: this runs before the controls read the button.)
useEffect(() => {
const el = gl.domElement;
const down = (event: PointerEvent) => {
- if (event.button === 2 || event.shiftKey || event.ctrlKey || event.metaKey) useOfficeStore.getState().setFollow(false);
+ const c = controls.current;
+ const sprintDrag = event.shiftKey && !event.ctrlKey && !event.metaKey;
+ if (c) c.mouseButtons.LEFT = sprintDrag ? MOUSE.PAN : MOUSE.ROTATE;
+ if (event.button === 2 || event.ctrlKey || event.metaKey) useOfficeStore.getState().setFollow(false);
};
- el.addEventListener("pointerdown", down);
- return () => el.removeEventListener("pointerdown", down);
+ el.addEventListener("pointerdown", down, true);
+ return () => el.removeEventListener("pointerdown", down, true);
}, [gl]);
useFrame((_, rawDt) => {
@@ -83,28 +117,37 @@ export function OfficeCameraRig({ layout, overview }: { layout: OfficeLayout; ov
if (store.zoom && store.zoom.seq !== lastZoom.current) {
lastZoom.current = store.zoom.seq;
flight.current = null;
- dive.current = { fromEye: camera.position.clone(), toEye: new Vector3(...store.zoom.eye),
- fromTarget: c.target.clone(), toTarget: new Vector3(...store.zoom.target), t: 0 };
+ // End squarely in front of the screen, far enough back that it exactly fills the view.
+ const lens = camera as unknown as { fov: number; aspect: number };
+ const reach = screenFillDistance(lens.fov ?? 35, lens.aspect ?? 1.6) * 1.02;
+ const [tx, ty, tz] = store.zoom.target;
+ preDive.current = { position: camera.position.toArray() as [number, number, number], target: c.target.toArray() as [number, number, number] };
+ dive.current = { fromEye: camera.position.clone(),
+ toEye: new Vector3(tx + Math.sin(store.zoom.facing) * reach, ty, tz + Math.cos(store.zoom.facing) * reach),
+ fromTarget: c.target.clone(), toTarget: new Vector3(tx, ty, tz), t: 0 };
// Orbit limits (minimum distance, pitch) would stop the camera short of the glass.
c.enabled = false;
}
if (dive.current) {
- // Dive: eye and target travel together into the monitor, easing in at the end.
+ // Dive: the look turns to the screen first, then the camera glides in (smooth in and out).
const d = dive.current;
d.t = Math.min(1, d.t + dt / ZOOM_SECONDS);
- const ease = 1 - (1 - d.t) ** 3;
+ const ease = d.t < 0.5 ? 4 * d.t ** 3 : 1 - (-2 * d.t + 2) ** 3 / 2;
+ const look = Math.min(1, d.t / 0.45);
+ c.target.lerpVectors(d.fromTarget, d.toTarget, 1 - (1 - look) ** 3);
camera.position.lerpVectors(d.fromEye, d.toEye, ease);
- c.target.lerpVectors(d.fromTarget, d.toTarget, ease);
camera.lookAt(c.target);
if (d.t >= 1) {
dive.current = null;
- // If the chat does not take over (no handler), hand the camera back a step away.
+ // If the chat does not take over (no handler), return to the view before the dive.
backOff.current = setTimeout(() => {
- const away = camera.position.clone().sub(c.target).setLength(CAMERA_LIMITS.minDistance + 1);
- camera.position.copy(c.target).add(away);
+ const back = preDive.current;
+ if (back) { camera.position.set(...back.position); c.target.set(...back.target); }
+ else camera.position.copy(c.target).add(camera.position.clone().sub(c.target).setLength(CAMERA_LIMITS.minDistance + 1));
+ preDive.current = null;
c.enabled = true;
c.update();
- }, 1500);
+ }, 2500);
}
return;
}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeFurniture.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeFurniture.tsx
index d2e2292e3a..5cdf9a5e67 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeFurniture.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeFurniture.tsx
@@ -136,7 +136,8 @@ export function Plant({ position, size = 1 }: { position: [number, number, numbe
export function Bookshelf({ position, rotationY = 0 }: { position: [number, number, number]; rotationY?: number }) {
const books = useMemo(() => Array.from({ length: 14 }, (_, i) => ({
x: -0.72 + (i % 7) * 0.22 + ((i * 13) % 5) * 0.01,
- y: i < 7 ? 0.42 : 0.98,
+ // Bottom-row books stay below the shelf board, whose front is flush with theirs.
+ y: i < 7 ? 0.4 : 0.98,
h: 0.3 + ((i * 7) % 4) * 0.04,
m: MAT.books[i % MAT.books.length],
})), []);
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
index 834474573a..86d10b1e1e 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficePlayer.tsx
@@ -12,7 +12,7 @@ import { ToyFigure } from "./ToyFigure";
import type { ToyLook } from "./toyFigureModel";
import { findPath, isWalkable, nearestWalkable, type NavGrid } from "./officeNav";
import { applySeparation, clearOfBodies, separation, stepMover, turnToward } from "./officeMotion";
-import { player, sameSelection, useOfficeStore, type Selection } from "./officeStore";
+import { officeSession, player, sameSelection, useOfficeStore, type Selection } from "./officeStore";
import { agentPositions, bodiesExcept } from "./walkerRegistry";
import { OFFICE_FIGURE_HEIGHT_M } from "./OfficeAgents";
import type { OfficeLayout } from "./officeLayout";
@@ -107,10 +107,16 @@ export function OfficePlayer({ layout, grid, look, name, awake, reduced }: {
}, []);
const { pressed, run } = useMoveKeys(awake, interact);
- // Place the character at the elevator once per floor plan.
+ // Arrive by the elevator once per app run; coming back to the map keeps the
+ // character where it was, unless a changed floor plan put that spot in a wall.
useEffect(() => {
- const start = nearestWalkable(grid, layout.spawn) ?? layout.spawn;
- player.x = start.x; player.z = start.z; player.heading = Math.PI; player.path = []; player.moving = false;
+ player.path = []; player.moving = false;
+ if (officeSession.playerPlaced && isWalkable(grid, player)) return;
+ const start = (officeSession.playerPlaced ? nearestWalkable(grid, player) : null)
+ ?? nearestWalkable(grid, layout.spawn) ?? layout.spawn;
+ player.x = start.x; player.z = start.z;
+ if (!officeSession.playerPlaced) player.heading = Math.PI;
+ officeSession.playerPlaced = true;
}, [grid, layout.spawn]);
useFrame((_, rawDt) => {
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeProps.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeProps.tsx
index 48685be843..39e186d400 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeProps.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeProps.tsx
@@ -401,7 +401,8 @@ function TeamBoard() {
function ReceptionDesk() {
return (
<group>
- <Rounded size={[2.8, 0.98, 0.4]} radius={0.15} position={[0, 0.49, 0.25]} material={MAT.deskBody} />
+ {/* Counter front stops 2 cm short of the wood strip: coplanar faces z-fight into stripes. */}
+ <Rounded size={[2.8, 0.98, 0.38]} radius={0.15} position={[0, 0.49, 0.24]} material={MAT.deskBody} />
<Rounded size={[2.8, 0.05, 0.46]} radius={0.02} position={[0, 1.005, 0.22]} material={MAT.wood} />
<Box size={[2.3, 0.1, 0.02]} position={[0, 0.55, 0.44]} material={MAT.wood} cast={false} />
<Rounded size={[2.5, 0.04, 0.44]} radius={0.015} position={[0, 0.74, -0.2]} material={MAT.deskTop} />
@@ -587,7 +588,8 @@ function RugPiece({ w, d }: { w: number; d: number }) {
function Elevator() {
return (
<group>
- <Rounded size={[2.2, 2.4, 0.3]} radius={0.04} position={[0, 1.2, -0.05]} material={PM.shaft} />
+ {/* The back stops 3 cm short of the slats' outer face: coplanar faces z-fight into stripes. */}
+ <Rounded size={[2.2, 2.4, 0.27]} radius={0.04} position={[0, 1.2, -0.035]} material={PM.shaft} />
<Box size={[0.1, 2.08, 0.06]} position={[-0.66, 1.04, 0.12]} material={PM.steelDark} />
<Box size={[0.1, 2.08, 0.06]} position={[0.66, 1.04, 0.12]} material={PM.steelDark} />
<Box size={[1.42, 0.1, 0.06]} position={[0, 2.13, 0.12]} material={PM.steelDark} />
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
index d92f2c73be..0583aa0d49 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
@@ -139,13 +139,15 @@ export function OfficeStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpen
// Clicking a monitor dives into it, then opens that agent's chat.
const openTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
useEffect(() => () => clearTimeout(openTimer.current), []);
+ const [diving, setDiving] = useState(false);
const openScreen = useCallback((agentId: string, screen: Point & { y: number }, facing: number) => {
- const eye: [number, number, number] = [screen.x + Math.sin(facing) * 0.62, screen.y + 0.02, screen.z + Math.cos(facing) * 0.62];
select(null);
clearTimeout(openTimer.current);
if (reduced) { onSelectAgent?.(agentId); return; }
- useOfficeStore.getState().zoomInto(eye, [screen.x, screen.y, screen.z]);
- openTimer.current = setTimeout(() => onSelectAgent?.(agentId), ZOOM_SECONDS * 1000 + 120);
+ useOfficeStore.getState().zoomInto([screen.x, screen.y, screen.z], facing);
+ // The screen fills the view, then the real chat view fades in over it.
+ setDiving(true);
+ openTimer.current = setTimeout(() => { onSelectAgent?.(agentId); setDiving(false); }, ZOOM_SECONDS * 1000 + 260);
}, [onSelectAgent, reduced, select]);
const counts = countStates(active);
@@ -196,7 +198,7 @@ export function OfficeStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpen
<RenderBoundary key={generation} fallbackText={t("society.office.no_graphics")}>
<Suspense fallback={<div className="office-fallback" role="status">{t("society.office.loading")}</div>}>
<Canvas shadows="percentage" camera={{ fov: CAMERA_FOV, near: 0.2, far: 800, position: [30, 30, 30] }} dpr={[1, 1.75]}
- gl={{ antialias: true, alpha: false, preserveDrawingBuffer: import.meta.env.DEV }}
+ gl={{ antialias: true, alpha: true, preserveDrawingBuffer: import.meta.env.DEV }}
frameloop={!awake ? "never" : "always"}
onPointerMissed={() => select(null)}>
<OfficeScene layout={layout} grid={grid} walkers={walkers} agents={agents} newcomers={newcomers}
@@ -248,6 +250,7 @@ export function OfficeStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpen
</button>
)}
<OfficeCompass layout={layout} agents={agents} selectedId={selection?.kind === "agent" ? selection.id : null} />
+ {diving && <div className="office-dive-fade" aria-hidden />}
<OfficeMinimap layout={layout} agents={agents} selectedId={selection?.kind === "agent" ? selection.id : null}
onOpenMap={() => setMapOpen(true)} />
<OfficeFullMap open={mapOpen} onOpen={() => setMapOpen(true)} onClose={() => setMapOpen(false)}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/RealChatScreen.tsx b/jarvis/ui/web/frontend/src/components/society/office/RealChatScreen.tsx
new file mode 100644
index 0000000000..65b6205f52
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/RealChatScreen.tsx
@@ -0,0 +1,43 @@
+/**
+ * The agent's REAL chat on its desk monitor: the same AgentChatPanel the chat
+ * view shows, live, drawn onto the screen plane. Each monitor owns its own
+ * chat store (one socket through the shared connect budget), so it never
+ * touches the chat the rest of the app has open. Display only: clicks go to
+ * the monitor underneath, which dives into the chat view.
+ */
+import { Suspense, lazy, useEffect, useMemo } from "react";
+import { Html } from "@react-three/drei";
+import { QueryClientProvider, useQueryClient } from "@tanstack/react-query";
+import { createAgentChatStore } from "@/store/agentChat";
+import type { SocietyAgent } from "../data";
+
+const AgentChatPanel = lazy(() => import("../chat/AgentChatPanel").then((m) => ({ default: m.AgentChatPanel })));
+
+/** The chat is laid out at a normal window size, then scaled onto the 0.66 × 0.38 m screen. */
+export const REAL_CHAT_PX = { w: 880, h: 507 } as const;
+const SCREEN_W_M = 0.66;
+/** drei maps one CSS pixel to distanceFactor / 400 metres in transform mode. */
+const DISTANCE_FACTOR = (SCREEN_W_M * 400) / REAL_CHAT_PX.w;
+
+export function RealChatScreen({ agent, roster, position }: {
+ agent: SocietyAgent; roster: SocietyAgent[]; position: [number, number, number];
+}) {
+ // drei renders <Html> content in a separate React root: the app's data client
+ // must be handed over, or the chat panel's queries throw and the screen stays blank.
+ const client = useQueryClient();
+ const store = useMemo(() => createAgentChatStore("society", `office-monitor:${agent.agentId}`), [agent.agentId]);
+ // Leaving the monitor closes its socket; the chat itself keeps running on the server.
+ useEffect(() => () => store.getState().disconnect(), [store]);
+ return (
+ <Html transform occlude="blending" position={position} distanceFactor={DISTANCE_FACTOR} zIndexRange={[10, 0]}
+ style={{ width: REAL_CHAT_PX.w, height: REAL_CHAT_PX.h, pointerEvents: "none" }}>
+ <div className="office-real-chat" data-office-ui>
+ <QueryClientProvider client={client}>
+ <Suspense fallback={null}>
+ <AgentChatPanel agent={agent} roster={roster} chatStore={store} />
+ </Suspense>
+ </QueryClientProvider>
+ </div>
+ </Html>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/liveMonitors.test.ts b/jarvis/ui/web/frontend/src/components/society/office/liveMonitors.test.ts
new file mode 100644
index 0000000000..771f1c51f7
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/liveMonitors.test.ts
@@ -0,0 +1,28 @@
+import { describe, expect, it } from "vitest";
+import { pickRealChats } from "./LiveMonitors";
+import { screenFillDistance } from "./OfficeCameraRig";
+
+describe("real chat monitors", () => {
+ it("runs the real chat only on the nearest few seated agents", () => {
+ const picked = pickRealChats([
+ { id: "a", distance: 3 }, { id: "b", distance: 9 }, { id: "c", distance: 5 }, { id: "d", distance: 7 }, { id: "far", distance: 30 },
+ ], new Set());
+ expect([...picked].sort()).toEqual(["a", "c", "d"]);
+ });
+ it("keeps a running chat until it is clearly out of range (no flicker at the edge)", () => {
+ expect(pickRealChats([{ id: "a", distance: 12 }], new Set()).has("a")).toBe(false);
+ expect(pickRealChats([{ id: "a", distance: 12 }], new Set(["a"])).has("a")).toBe(true);
+ expect(pickRealChats([{ id: "a", distance: 15 }], new Set(["a"])).has("a")).toBe(false);
+ });
+});
+
+describe("monitor dive", () => {
+ it("stands back far enough for the whole screen to fit, wider views closer", () => {
+ const wide = screenFillDistance(35, 2.2);
+ const narrow = screenFillDistance(35, 0.8);
+ expect(narrow).toBeGreaterThan(wide);
+ // At 35° the 0.38 m screen height needs about 0.6 m.
+ expect(wide).toBeGreaterThan(0.55);
+ expect(wide).toBeLessThan(0.7);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeHud.css b/jarvis/ui/web/frontend/src/components/society/office/officeHud.css
index 84984ab27c..5d4c35d1bf 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/officeHud.css
+++ b/jarvis/ui/web/frontend/src/components/society/office/officeHud.css
@@ -60,3 +60,11 @@
/* No minimap on short windows: the panel goes back under the corner buttons. */
@media (max-height:520px) { .office-panel-slot { top:60px; max-height:calc(100% - 100px); } }
@media (max-width:600px) { .office-panel-slot { top:auto; bottom:12px; max-height:55%; } .office-hud-right { max-width:60%; } .office-prompt { bottom:48px; max-width:calc(100% - 28px); } }
+
+/* The monitor dive ends in the chat view: the stage fades to the app background just before it opens. */
+.office-dive-fade { position:absolute; inset:0; z-index:60; pointer-events:none; background:hsl(var(--background)); opacity:0; animation:office-dive-fade 1.4s ease-in forwards; }
+@keyframes office-dive-fade { 0%, 72% { opacity:0; } 100% { opacity:1; } }
+@media (prefers-reduced-motion: reduce) { .office-dive-fade { animation:none; } }
+
+/* The real chat on a desk monitor: the app's own chat panel at window size, scaled onto the screen. */
+.office-real-chat { width:100%; height:100%; overflow:hidden; background:hsl(var(--background)); color:hsl(var(--foreground)); border-radius:6px; }
diff --git a/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts b/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts
index 546640cb09..e0ff22c740 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/officeStore.ts
@@ -25,8 +25,9 @@ interface OfficeState {
focus: { point: Point; seq: number } | null;
summons: Record<string, Summon>;
/** One-shot camera dive into a desk monitor (then the chat opens), consumed by the camera rig. */
- zoom: { eye: [number, number, number]; target: [number, number, number]; seq: number } | null;
- zoomInto: (eye: [number, number, number], target: [number, number, number]) => void;
+ zoom: { target: [number, number, number]; facing: number; seq: number } | null;
+ /** Dive into a monitor centred on `target`, whose screen faces yaw `facing`. */
+ zoomInto: (target: [number, number, number], facing: number) => void;
/** Walk the character to this point (click-to-move / "walk there"), consumed by the player. */
walkTo: { point: Point; seq: number } | null;
/** Agents picked for a new team, carried from agent panels to the team room. */
@@ -52,7 +53,7 @@ export const useOfficeStore = create<OfficeState>((set) => ({
summons: {},
walkTo: null,
zoom: null,
- zoomInto: (eye, target) => set({ zoom: { eye, target, seq: ++seq }, follow: false }),
+ zoomInto: (target, facing) => set({ zoom: { target, facing, seq: ++seq }, follow: false }),
teamDraft: [],
toggleDraft: (agentId) => set((s) => ({
teamDraft: s.teamDraft.includes(agentId) ? s.teamDraft.filter((id) => id !== agentId) : [...s.teamDraft, agentId],
@@ -82,6 +83,17 @@ export const useOfficeStore = create<OfficeState>((set) => ({
/** Where the camera looks on the floor, mutated by the camera rig every frame (for the minimap). */
export const cameraView = { x: 0, z: 0, yaw: 0, halfWidth: 0.5, ready: false };
+/**
+ * What the office remembers while the app runs: where the character stands
+ * and how the camera looked. Leaving the map (e.g. into an agent's chat) and
+ * coming back puts you where you were; only an app reload starts fresh.
+ */
+export const officeSession: {
+ playerPlaced: boolean;
+ camera: { position: [number, number, number]; target: [number, number, number] } | null;
+ follow: boolean;
+} = { playerPlaced: false, camera: null, follow: true };
+
/** The character's body, mutated by the player controller every frame. */
export const player: PlayerBody = { x: 0, z: 0, heading: Math.PI, path: [], moving: false };