@blueharford/scrypted-spatial-awareness 0.4.7 → 0.5.0-beta

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.
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Auto-Topology Discovery Models
3
+ * Types for scene analysis and topology discovery via vision LLM
4
+ */
5
+
6
+ import { LandmarkType, Landmark, CameraConnection } from './topology';
7
+
8
+ // ==================== Discovery Configuration ====================
9
+
10
+ /** Configuration for the topology discovery engine */
11
+ export interface DiscoveryConfig {
12
+ /** Hours between automatic discovery scans (0 = disabled) */
13
+ discoveryIntervalHours: number;
14
+ /** Minimum confidence threshold for auto-accepting suggestions */
15
+ autoAcceptThreshold: number;
16
+ /** Minimum confidence for landmark suggestions */
17
+ minLandmarkConfidence: number;
18
+ /** Minimum confidence for connection suggestions */
19
+ minConnectionConfidence: number;
20
+ }
21
+
22
+ /** Default discovery configuration */
23
+ export const DEFAULT_DISCOVERY_CONFIG: DiscoveryConfig = {
24
+ discoveryIntervalHours: 0, // Disabled by default
25
+ autoAcceptThreshold: 0.85,
26
+ minLandmarkConfidence: 0.6,
27
+ minConnectionConfidence: 0.5,
28
+ };
29
+
30
+ /** Rate limit warning thresholds (in hours) */
31
+ export const RATE_LIMIT_WARNING_THRESHOLD = 1; // Warn if interval is less than 1 hour
32
+
33
+ // ==================== Scene Analysis Types ====================
34
+
35
+ /** Zone types that can be discovered in camera views */
36
+ export type DiscoveredZoneType =
37
+ | 'yard' // Front yard, back yard, side yard
38
+ | 'driveway' // Driveway, parking area
39
+ | 'street' // Street, road, sidewalk
40
+ | 'patio' // Patio, deck
41
+ | 'walkway' // Walkways, paths
42
+ | 'parking' // Parking lot, parking space
43
+ | 'garden' // Garden, landscaped area
44
+ | 'pool' // Pool area
45
+ | 'unknown'; // Unidentified area
46
+
47
+ /** A zone discovered in a camera view */
48
+ export interface DiscoveredZone {
49
+ /** Name of the zone (e.g., "Front Yard", "Driveway") */
50
+ name: string;
51
+ /** Type classification */
52
+ type: DiscoveredZoneType;
53
+ /** Estimated percentage of frame this zone covers (0-1) */
54
+ coverage: number;
55
+ /** Description from LLM analysis */
56
+ description: string;
57
+ /** Bounding box in normalized coordinates [x, y, width, height] (0-1) */
58
+ boundingBox?: [number, number, number, number];
59
+ }
60
+
61
+ /** A landmark discovered in a camera view */
62
+ export interface DiscoveredLandmark {
63
+ /** Name of the landmark */
64
+ name: string;
65
+ /** Type classification */
66
+ type: LandmarkType;
67
+ /** Confidence score from LLM (0-1) */
68
+ confidence: number;
69
+ /** Bounding box in normalized coordinates [x, y, width, height] (0-1) */
70
+ boundingBox?: [number, number, number, number];
71
+ /** Description from LLM analysis */
72
+ description: string;
73
+ }
74
+
75
+ /** Edge analysis - what's visible at frame boundaries */
76
+ export interface EdgeAnalysis {
77
+ /** What's visible at the top edge */
78
+ top: string;
79
+ /** What's visible at the left edge */
80
+ left: string;
81
+ /** What's visible at the right edge */
82
+ right: string;
83
+ /** What's visible at the bottom edge */
84
+ bottom: string;
85
+ }
86
+
87
+ /** Complete scene analysis result for a single camera */
88
+ export interface SceneAnalysis {
89
+ /** Camera device ID */
90
+ cameraId: string;
91
+ /** Camera name for reference */
92
+ cameraName: string;
93
+ /** When this analysis was performed */
94
+ timestamp: number;
95
+ /** Landmarks discovered in the scene */
96
+ landmarks: DiscoveredLandmark[];
97
+ /** Zones discovered in the scene */
98
+ zones: DiscoveredZone[];
99
+ /** Edge analysis for camera correlation */
100
+ edges: EdgeAnalysis;
101
+ /** Estimated camera facing direction */
102
+ orientation: 'north' | 'south' | 'east' | 'west' | 'northeast' | 'northwest' | 'southeast' | 'southwest' | 'unknown';
103
+ /** Camera IDs that may have overlapping views */
104
+ potentialOverlaps: string[];
105
+ /** Whether this analysis is still valid (not stale) */
106
+ isValid: boolean;
107
+ /** Error message if analysis failed */
108
+ error?: string;
109
+ }
110
+
111
+ // ==================== Correlation Types ====================
112
+
113
+ /** A landmark that appears in multiple camera views */
114
+ export interface SharedLandmark {
115
+ /** Suggested name for this landmark */
116
+ name: string;
117
+ /** Suggested type */
118
+ type: LandmarkType;
119
+ /** Camera IDs where this landmark is visible */
120
+ seenByCameras: string[];
121
+ /** Confidence in this correlation */
122
+ confidence: number;
123
+ /** Description of the shared landmark */
124
+ description?: string;
125
+ }
126
+
127
+ /** A suggested connection between cameras */
128
+ export interface SuggestedConnection {
129
+ /** Source camera ID */
130
+ fromCameraId: string;
131
+ /** Destination camera ID */
132
+ toCameraId: string;
133
+ /** Estimated transit time in seconds */
134
+ transitSeconds: number;
135
+ /** Path description (e.g., "via driveway", "through front yard") */
136
+ via: string;
137
+ /** Confidence in this suggestion */
138
+ confidence: number;
139
+ /** Whether this is bidirectional */
140
+ bidirectional: boolean;
141
+ }
142
+
143
+ /** Result of correlating scenes across multiple cameras */
144
+ export interface TopologyCorrelation {
145
+ /** Landmarks that appear in multiple camera views */
146
+ sharedLandmarks: SharedLandmark[];
147
+ /** Suggested connections between cameras */
148
+ suggestedConnections: SuggestedConnection[];
149
+ /** Overall description of property layout from LLM */
150
+ layoutDescription: string;
151
+ /** When this correlation was performed */
152
+ timestamp: number;
153
+ }
154
+
155
+ // ==================== Discovery Suggestions ====================
156
+
157
+ /** Status of a discovery suggestion */
158
+ export type SuggestionStatus = 'pending' | 'accepted' | 'rejected' | 'merged';
159
+
160
+ /** A pending discovery suggestion for user review */
161
+ export interface DiscoverySuggestion {
162
+ /** Unique ID for this suggestion */
163
+ id: string;
164
+ /** Type of suggestion */
165
+ type: 'landmark' | 'zone' | 'connection';
166
+ /** When this was discovered */
167
+ timestamp: number;
168
+ /** Cameras that contributed to this discovery */
169
+ sourceCameras: string[];
170
+ /** Confidence score */
171
+ confidence: number;
172
+ /** Current status */
173
+ status: SuggestionStatus;
174
+ /** The suggested landmark (if type is 'landmark') */
175
+ landmark?: Partial<Landmark>;
176
+ /** The suggested zone (if type is 'zone') */
177
+ zone?: DiscoveredZone;
178
+ /** The suggested connection (if type is 'connection') */
179
+ connection?: SuggestedConnection;
180
+ }
181
+
182
+ // ==================== Discovery Status ====================
183
+
184
+ /** Current status of the discovery engine */
185
+ export interface DiscoveryStatus {
186
+ /** Whether discovery is currently running */
187
+ isRunning: boolean;
188
+ /** Whether a scan is in progress */
189
+ isScanning: boolean;
190
+ /** Last scan timestamp */
191
+ lastScanTime: number | null;
192
+ /** Next scheduled scan timestamp */
193
+ nextScanTime: number | null;
194
+ /** Number of cameras analyzed */
195
+ camerasAnalyzed: number;
196
+ /** Number of pending suggestions */
197
+ pendingSuggestions: number;
198
+ /** Any error from last scan */
199
+ lastError?: string;
200
+ }
201
+
202
+ /** Default discovery status */
203
+ export const DEFAULT_DISCOVERY_STATUS: DiscoveryStatus = {
204
+ isRunning: false,
205
+ isScanning: false,
206
+ lastScanTime: null,
207
+ nextScanTime: null,
208
+ camerasAnalyzed: 0,
209
+ pendingSuggestions: 0,
210
+ };
@@ -198,6 +198,57 @@ export interface CameraZoneMapping {
198
198
  zone: ClipPath;
199
199
  }
200
200
 
201
+ // ==================== Drawn Zones (Floor Plan) ====================
202
+
203
+ /** Zone type for floor plan zones */
204
+ export type DrawnZoneType =
205
+ | 'yard' // Front yard, back yard, side yard
206
+ | 'driveway' // Driveway, parking area
207
+ | 'street' // Street, sidewalk
208
+ | 'patio' // Patio, deck
209
+ | 'walkway' // Walkways, paths
210
+ | 'parking' // Parking lot, parking space
211
+ | 'garden' // Garden, landscaped area
212
+ | 'pool' // Pool area
213
+ | 'garage' // Garage area
214
+ | 'entrance' // Entry areas
215
+ | 'custom'; // Custom zone type
216
+
217
+ /** Zone colors by type */
218
+ export const ZONE_TYPE_COLORS: Record<DrawnZoneType, string> = {
219
+ yard: 'rgba(76, 175, 80, 0.3)', // Green
220
+ driveway: 'rgba(158, 158, 158, 0.3)', // Gray
221
+ street: 'rgba(96, 96, 96, 0.3)', // Dark gray
222
+ patio: 'rgba(255, 152, 0, 0.3)', // Orange
223
+ walkway: 'rgba(121, 85, 72, 0.3)', // Brown
224
+ parking: 'rgba(189, 189, 189, 0.3)', // Light gray
225
+ garden: 'rgba(139, 195, 74, 0.3)', // Light green
226
+ pool: 'rgba(33, 150, 243, 0.3)', // Blue
227
+ garage: 'rgba(117, 117, 117, 0.3)', // Medium gray
228
+ entrance: 'rgba(233, 30, 99, 0.3)', // Pink
229
+ custom: 'rgba(156, 39, 176, 0.3)', // Purple
230
+ };
231
+
232
+ /** A zone drawn on the floor plan */
233
+ export interface DrawnZone {
234
+ /** Unique identifier */
235
+ id: string;
236
+ /** Display name */
237
+ name: string;
238
+ /** Zone type */
239
+ type: DrawnZoneType;
240
+ /** Polygon points on floor plan (x, y coordinates) */
241
+ polygon: Point[];
242
+ /** Custom color override (optional) */
243
+ color?: string;
244
+ /** Linked camera IDs that can see this zone */
245
+ linkedCameras?: string[];
246
+ /** Linked landmark IDs within this zone */
247
+ linkedLandmarks?: string[];
248
+ /** Description for context */
249
+ description?: string;
250
+ }
251
+
201
252
  // ==================== Spatial Relationships ====================
202
253
 
203
254
  /** Types of spatial relationships between entities */
@@ -297,6 +348,8 @@ export interface CameraTopology {
297
348
  relationships: SpatialRelationship[];
298
349
  /** Named zones spanning multiple cameras */
299
350
  globalZones: GlobalZone[];
351
+ /** Zones drawn on the floor plan */
352
+ drawnZones?: DrawnZone[];
300
353
  /** Floor plan configuration (optional) */
301
354
  floorPlan?: FloorPlanConfig;
302
355
  /** Pending AI landmark suggestions */