@agent-os-lab/agent-game-sdk 0.1.17 → 0.1.18

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/README.md CHANGED
@@ -82,6 +82,25 @@ export function Office() {
82
82
 
83
83
  `agent-game-sdk/office` is renderer and framework neutral. `agent-game-sdk/office/react` is the React-only entrypoint.
84
84
 
85
+ Static building canvas:
86
+
87
+ ```tsx
88
+ import type { AgentGameOfficeConfig } from "@agent-os-lab/agent-game-sdk/office";
89
+ import { OfficeBuildingCanvas } from "@agent-os-lab/agent-game-sdk/office/react";
90
+
91
+ export function BuildingPreview({ office }: { office: AgentGameOfficeConfig }) {
92
+ return (
93
+ <OfficeBuildingCanvas
94
+ office={office}
95
+ focusedFloorId="floor-2"
96
+ style={{ height: 360 }}
97
+ />
98
+ );
99
+ }
100
+ ```
101
+
102
+ Use `OfficeBuildingCanvas` or `mountOfficeBuildingCanvas` when you only need the static building model. It renders the same office scene without requiring a runtime source and without mounting agents, labels, activity effects, or movement state.
103
+
85
104
  ## Avatar Views
86
105
 
87
106
  Use `mountAgentAvatar3D` when a tenant application needs the same 3D Agent shape used inside the office game view:
package/USAGE.md CHANGED
@@ -37,8 +37,8 @@ import {
37
37
  subscribeAgentPresenceList,
38
38
  } from "@agent-os-lab/agent-game-sdk";
39
39
  import { mountAgentAvatar3D, mountAgentAvatarCanvas } from "@agent-os-lab/agent-game-sdk/avatar";
40
- import { mountAgentGameOffice } from "@agent-os-lab/agent-game-sdk/office";
41
- import { AgentGameOfficeView } from "@agent-os-lab/agent-game-sdk/office/react";
40
+ import { mountAgentGameOffice, mountOfficeBuildingCanvas } from "@agent-os-lab/agent-game-sdk/office";
41
+ import { AgentGameOfficeView, OfficeBuildingCanvas } from "@agent-os-lab/agent-game-sdk/office/react";
42
42
  import type { AgentPresence } from "@agent-os-lab/agent-game-sdk/office";
43
43
  ```
44
44
 
@@ -46,8 +46,8 @@ Available entry points:
46
46
 
47
47
  - `@agent-os-lab/agent-game-sdk`: runtime clients and office exports.
48
48
  - `@agent-os-lab/agent-game-sdk/avatar`: framework-neutral avatar view APIs.
49
- - `@agent-os-lab/agent-game-sdk/office`: framework-neutral office view APIs and office types.
50
- - `@agent-os-lab/agent-game-sdk/office/react`: React office view component.
49
+ - `@agent-os-lab/agent-game-sdk/office`: framework-neutral office view APIs, static building canvas APIs, and office types.
50
+ - `@agent-os-lab/agent-game-sdk/office/react`: React office view and static building canvas components.
51
51
 
52
52
  Do not import files from `src/` in application code. Use the published entry points above.
53
53
 
@@ -383,6 +383,40 @@ export function Office() {
383
383
 
384
384
  Keep `source` object identity stable across renders when possible. Recreating `source` every render can remount the view because the React wrapper treats it as an effect dependency. Equivalent inline `office` objects do not remount the view, but memoizing office config is still preferable when constructing it dynamically.
385
385
 
386
+ ## Static Building Canvas
387
+
388
+ Use `OfficeBuildingCanvas` when a React surface needs the building model without agents or runtime state.
389
+
390
+ ```tsx
391
+ import { useState } from "react";
392
+ import type {
393
+ AgentGameOfficeBuildingCanvasController,
394
+ AgentGameOfficeConfig,
395
+ } from "@agent-os-lab/agent-game-sdk/office";
396
+ import { OfficeBuildingCanvas } from "@agent-os-lab/agent-game-sdk/office/react";
397
+
398
+ export function BuildingPreview({ office }: { office: AgentGameOfficeConfig }) {
399
+ const [view, setView] = useState<AgentGameOfficeBuildingCanvasController | null>(null);
400
+
401
+ return (
402
+ <>
403
+ <button type="button" onClick={() => view?.resetCamera()}>
404
+ Reset building view
405
+ </button>
406
+ <OfficeBuildingCanvas
407
+ office={office}
408
+ focusedFloorId="floor-2"
409
+ style={{ height: 360 }}
410
+ onReady={setView}
411
+ onDestroy={() => setView(null)}
412
+ />
413
+ </>
414
+ );
415
+ }
416
+ ```
417
+
418
+ Framework-neutral callers can use `mountOfficeBuildingCanvas(container, { office })`. The static canvas reuses the office scene, camera, reset, and floor-focus behavior, but it does not accept a `source` and does not mount agents, labels, activity effects, movement, or runtime subscriptions.
419
+
386
420
  ## Snapshot Source
387
421
 
388
422
  Use `source.type: "snapshot"` for demos, tests, static previews, or applications that already have agent presence data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-os-lab/agent-game-sdk",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -0,0 +1,16 @@
1
+ import { resolveOfficeLayout } from "./layout";
2
+ import type {
3
+ AgentGameOfficeBuildingCanvasController,
4
+ AgentGameOfficeBuildingCanvasMountOptions,
5
+ } from "./core/types";
6
+ import { mountThreeOfficeBuildingCanvas } from "./renderers/three/building-canvas";
7
+
8
+ export function mountOfficeBuildingCanvas(
9
+ container: HTMLElement,
10
+ options: AgentGameOfficeBuildingCanvasMountOptions = {},
11
+ ): AgentGameOfficeBuildingCanvasController {
12
+ return mountThreeOfficeBuildingCanvas(container, {
13
+ ...options,
14
+ officeLayout: resolveOfficeLayout(options.office),
15
+ });
16
+ }
@@ -149,3 +149,22 @@ export type AgentGameOfficeController = {
149
149
  getNavigationErrors(): AgentNavigationError[];
150
150
  destroy(): void;
151
151
  };
152
+
153
+ export type AgentGameOfficeBuildingCanvasMountOptions = {
154
+ office?: AgentGameOfficeConfig;
155
+ focusedFloorId?: string | null;
156
+ className?: string;
157
+ onCameraChange?: (state: AgentGameOfficeCameraState) => void;
158
+ onFocusedFloorChange?: (floorId: string | null) => void;
159
+ };
160
+
161
+ export type AgentGameOfficeBuildingCanvasResolvedOptions = AgentGameOfficeBuildingCanvasMountOptions & {
162
+ officeLayout: ResolvedOfficeLayout;
163
+ };
164
+
165
+ export type AgentGameOfficeBuildingCanvasController = {
166
+ resetCamera(): void;
167
+ focusFloor(floorId: string | null): void;
168
+ getFocusedFloor(): string | null;
169
+ destroy(): void;
170
+ };
@@ -3,3 +3,4 @@ export * from "./core/projection";
3
3
  export * from "./core/source";
4
4
  export * from "./layout";
5
5
  export * from "./mount";
6
+ export * from "./building-canvas";
@@ -0,0 +1,87 @@
1
+ import React, { useEffect, useRef } from "react";
2
+
3
+ import { mountOfficeBuildingCanvas } from "../building-canvas";
4
+ import type {
5
+ AgentGameOfficeBuildingCanvasController,
6
+ AgentGameOfficeBuildingCanvasMountOptions,
7
+ } from "../core/types";
8
+
9
+ export type OfficeBuildingCanvasProps = AgentGameOfficeBuildingCanvasMountOptions & {
10
+ className?: string;
11
+ style?: React.CSSProperties;
12
+ onReady?: (controller: AgentGameOfficeBuildingCanvasController) => void;
13
+ onDestroy?: () => void;
14
+ };
15
+
16
+ export function OfficeBuildingCanvas({
17
+ className,
18
+ onDestroy,
19
+ onReady,
20
+ style,
21
+ ...options
22
+ }: OfficeBuildingCanvasProps) {
23
+ const containerRef = useRef<HTMLDivElement | null>(null);
24
+ const viewRef = useRef<AgentGameOfficeBuildingCanvasController | null>(null);
25
+ const onDestroyRef = useRef(onDestroy);
26
+ const onReadyRef = useRef(onReady);
27
+ const officeConfigKey = createOfficeConfigKey(options.office);
28
+
29
+ useEffect(() => {
30
+ onReadyRef.current = onReady;
31
+ onDestroyRef.current = onDestroy;
32
+ }, [onDestroy, onReady]);
33
+
34
+ useEffect(() => {
35
+ const container = containerRef.current;
36
+ if (!container) {
37
+ return;
38
+ }
39
+
40
+ const view = mountOfficeBuildingCanvas(container, options);
41
+ viewRef.current = view;
42
+ onReadyRef.current?.(view);
43
+
44
+ return () => {
45
+ viewRef.current?.destroy();
46
+ viewRef.current = null;
47
+ onDestroyRef.current?.();
48
+ };
49
+ }, [officeConfigKey]);
50
+
51
+ useEffect(() => {
52
+ viewRef.current?.focusFloor(options.focusedFloorId ?? null);
53
+ }, [options.focusedFloorId]);
54
+
55
+ return React.createElement("div", {
56
+ ref: containerRef,
57
+ className,
58
+ style: {
59
+ width: "100%",
60
+ height: "100%",
61
+ minHeight: 240,
62
+ ...style,
63
+ },
64
+ });
65
+ }
66
+
67
+ function createOfficeConfigKey(office: AgentGameOfficeBuildingCanvasMountOptions["office"]): string {
68
+ if (!office) {
69
+ return "default";
70
+ }
71
+ return JSON.stringify({
72
+ floors: office.building.floors.map((floor) => ({
73
+ id: floor.id,
74
+ name: floor.name,
75
+ rooms: floor.rooms.map((room) => ({
76
+ type: room.type,
77
+ capacity: room.capacity ?? null,
78
+ })),
79
+ })),
80
+ connectors: office.building.connectors.map((connector) => ({
81
+ id: connector.id,
82
+ name: connector.name,
83
+ type: connector.type,
84
+ serves: connector.serves,
85
+ })),
86
+ });
87
+ }
@@ -1 +1,2 @@
1
1
  export * from "./AgentGameOfficeView";
2
+ export * from "./OfficeBuildingCanvas";
@@ -0,0 +1,177 @@
1
+ import * as THREE from "three";
2
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
3
+
4
+ import type {
5
+ AgentGameOfficeBuildingCanvasController,
6
+ AgentGameOfficeBuildingCanvasResolvedOptions,
7
+ } from "../../core/types";
8
+ import type { ResolvedOfficeLayout } from "../../layout";
9
+ import {
10
+ addLights,
11
+ applyOfficeFloorFocus,
12
+ buildOfficeScene,
13
+ disposeObject,
14
+ } from "./scene";
15
+ import {
16
+ THREE_RENDERER_MAX_CAMERA_DISTANCE,
17
+ THREE_RENDERER_MIN_CAMERA_DISTANCE,
18
+ THREE_RENDERER_PIXEL_RATIO_LIMIT,
19
+ THREE_RENDERER_TARGET_FPS,
20
+ createInitialOfficeCameraView,
21
+ createOfficeCameraState,
22
+ createOfficeMouseButtons,
23
+ type OfficeCameraView,
24
+ } from "./mount";
25
+
26
+ export function mountThreeOfficeBuildingCanvas(
27
+ container: HTMLElement,
28
+ options: AgentGameOfficeBuildingCanvasResolvedOptions,
29
+ ): AgentGameOfficeBuildingCanvasController {
30
+ const width = Math.max(container.clientWidth || 960, 320);
31
+ const height = Math.max(container.clientHeight || 540, 240);
32
+ const scene = new THREE.Scene();
33
+ scene.background = new THREE.Color(0xf7f8fb);
34
+
35
+ const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
36
+ const initialCameraView = createInitialOfficeCameraView(options.officeLayout, camera.aspect, camera.fov);
37
+ applyOfficeCameraView(camera, initialCameraView);
38
+
39
+ const renderer = new THREE.WebGLRenderer({
40
+ antialias: true,
41
+ alpha: false,
42
+ powerPreference: "high-performance",
43
+ });
44
+ renderer.setSize(width, height);
45
+ renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio || 1, THREE_RENDERER_PIXEL_RATIO_LIMIT));
46
+ renderer.shadowMap.enabled = false;
47
+ renderer.domElement.style.width = "100%";
48
+ renderer.domElement.style.height = "100%";
49
+ renderer.domElement.style.display = "block";
50
+ renderer.domElement.style.cursor = "grab";
51
+
52
+ function setGrabbingCursor() {
53
+ renderer.domElement.style.cursor = "grabbing";
54
+ }
55
+
56
+ function setGrabCursor() {
57
+ renderer.domElement.style.cursor = "grab";
58
+ }
59
+
60
+ renderer.domElement.addEventListener("pointerdown", setGrabbingCursor);
61
+ renderer.domElement.addEventListener("pointerup", setGrabCursor);
62
+ renderer.domElement.addEventListener("pointerleave", setGrabCursor);
63
+
64
+ const controls = new OrbitControls(camera, renderer.domElement);
65
+ controls.target.copy(initialCameraView.target);
66
+ controls.enableDamping = true;
67
+ controls.dampingFactor = 0.08;
68
+ controls.enablePan = true;
69
+ controls.enableRotate = true;
70
+ controls.enableZoom = true;
71
+ controls.mouseButtons = createOfficeMouseButtons();
72
+ controls.minDistance = THREE_RENDERER_MIN_CAMERA_DISTANCE;
73
+ controls.maxDistance = THREE_RENDERER_MAX_CAMERA_DISTANCE;
74
+ controls.maxPolarAngle = Math.PI * 0.48;
75
+ controls.addEventListener("change", emitCameraChange);
76
+ controls.update();
77
+
78
+ const root = document.createElement("div");
79
+ root.style.position = "relative";
80
+ root.style.width = "100%";
81
+ root.style.height = "100%";
82
+ root.style.overflow = "hidden";
83
+ root.appendChild(renderer.domElement);
84
+ container.appendChild(root);
85
+
86
+ addLights(scene);
87
+ buildOfficeScene(scene, options.officeLayout);
88
+
89
+ let frameId = 0;
90
+ let disposed = false;
91
+ let previousRenderTime = performance.now();
92
+ let focusedFloorId = normalizeFocusedFloorId(options.officeLayout, options.focusedFloorId ?? null);
93
+ setFocusedFloor(focusedFloorId, false);
94
+
95
+ function animate() {
96
+ if (disposed) {
97
+ return;
98
+ }
99
+ const now = performance.now();
100
+ const targetFrameIntervalMs = 1000 / THREE_RENDERER_TARGET_FPS;
101
+ if (now - previousRenderTime >= targetFrameIntervalMs) {
102
+ previousRenderTime = now;
103
+ controls.update();
104
+ renderer.render(scene, camera);
105
+ }
106
+ frameId = requestAnimationFrame(animate);
107
+ }
108
+
109
+ const resizeObserver = new ResizeObserver(() => {
110
+ const nextWidth = Math.max(container.clientWidth || width, 320);
111
+ const nextHeight = Math.max(container.clientHeight || height, 240);
112
+ camera.aspect = nextWidth / nextHeight;
113
+ camera.updateProjectionMatrix();
114
+ renderer.setSize(nextWidth, nextHeight);
115
+ emitCameraChange();
116
+ });
117
+ resizeObserver.observe(container);
118
+
119
+ emitCameraChange();
120
+ animate();
121
+
122
+ return {
123
+ resetCamera() {
124
+ camera.zoom = 1;
125
+ camera.updateProjectionMatrix();
126
+ const view = createInitialOfficeCameraView(options.officeLayout, camera.aspect, camera.fov);
127
+ applyOfficeCameraView(camera, view);
128
+ controls.target.copy(view.target);
129
+ controls.update();
130
+ emitCameraChange();
131
+ },
132
+ focusFloor(floorId) {
133
+ setFocusedFloor(floorId);
134
+ },
135
+ getFocusedFloor() {
136
+ return focusedFloorId;
137
+ },
138
+ destroy() {
139
+ disposed = true;
140
+ cancelAnimationFrame(frameId);
141
+ resizeObserver.disconnect();
142
+ controls.dispose();
143
+ renderer.domElement.removeEventListener("pointerdown", setGrabbingCursor);
144
+ renderer.domElement.removeEventListener("pointerup", setGrabCursor);
145
+ renderer.domElement.removeEventListener("pointerleave", setGrabCursor);
146
+ disposeObject(scene);
147
+ renderer.dispose();
148
+ root.remove();
149
+ },
150
+ };
151
+
152
+ function emitCameraChange() {
153
+ options.onCameraChange?.(createOfficeCameraState(camera, controls));
154
+ }
155
+
156
+ function setFocusedFloor(floorId: string | null, emit = true) {
157
+ const nextFloorId = normalizeFocusedFloorId(options.officeLayout, floorId);
158
+ focusedFloorId = nextFloorId;
159
+ applyOfficeFloorFocus(scene, options.officeLayout, focusedFloorId);
160
+ if (emit) {
161
+ options.onFocusedFloorChange?.(focusedFloorId);
162
+ }
163
+ }
164
+ }
165
+
166
+ function applyOfficeCameraView(camera: THREE.PerspectiveCamera, view: OfficeCameraView) {
167
+ camera.up.copy(view.up);
168
+ camera.position.copy(view.position);
169
+ camera.rotation.copy(view.rotation);
170
+ }
171
+
172
+ function normalizeFocusedFloorId(layout: ResolvedOfficeLayout, floorId: string | null): string | null {
173
+ if (!floorId) {
174
+ return null;
175
+ }
176
+ return layout.building.floors.some((floor) => floor.id === floorId) ? floorId : null;
177
+ }