Spaces:
Running
Running
File size: 3,692 Bytes
6ce4ca6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
import type { Positionable, Position3D } from '$lib/types/positionable.js';
import type { AISessionConfig, AISessionResponse } from './RemoteComputeManager.svelte';
export type ComputeStatus = 'disconnected' | 'ready' | 'running' | 'stopped' | 'initializing';
export class RemoteCompute implements Positionable {
readonly id: string;
// Reactive state using Svelte 5 runes
position = $state<Position3D>({ x: 0, y: 0, z: 0 });
name = $state<string>('');
status = $state<ComputeStatus>('disconnected');
// Session data
sessionId = $state<string | null>(null);
sessionConfig = $state<AISessionConfig | null>(null);
sessionData = $state<AISessionResponse | null>(null);
// Derived reactive values
hasSession = $derived(this.sessionId !== null);
isRunning = $derived(this.status === 'running');
canStart = $derived(this.status === 'ready' || this.status === 'stopped');
canStop = $derived(this.status === 'running');
constructor(id: string, name?: string) {
this.id = id;
this.name = name || `Compute ${id}`;
}
/**
* Get input connections (camera and joint inputs)
*/
get inputConnections() {
if (!this.sessionData) return null;
return {
cameras: this.sessionData.camera_room_ids,
jointInput: this.sessionData.joint_input_room_id,
workspaceId: this.sessionData.workspace_id
};
}
/**
* Get output connections (joint output)
*/
get outputConnections() {
if (!this.sessionData) return null;
return {
jointOutput: this.sessionData.joint_output_room_id,
workspaceId: this.sessionData.workspace_id
};
}
/**
* Get display information for UI
*/
get displayInfo() {
return {
id: this.id,
name: this.name,
status: this.status,
sessionId: this.sessionId,
policyPath: this.sessionConfig?.policyPath,
cameraNames: this.sessionConfig?.cameraNames || [],
hasSession: this.hasSession,
isRunning: this.isRunning,
canStart: this.canStart,
canStop: this.canStop
};
}
/**
* Get status for billboard display
*/
get statusInfo() {
const status = this.status;
let statusText = '';
let statusColor = '';
switch (status) {
case 'disconnected':
statusText = 'Disconnected';
statusColor = 'rgb(107, 114, 128)'; // gray
break;
case 'ready':
statusText = 'Ready';
statusColor = 'rgb(245, 158, 11)'; // yellow
break;
case 'running':
statusText = 'Running';
statusColor = 'rgb(34, 197, 94)'; // green
break;
case 'stopped':
statusText = 'Stopped';
statusColor = 'rgb(239, 68, 68)'; // red
break;
case 'initializing':
statusText = 'Initializing';
statusColor = 'rgb(59, 130, 246)'; // blue
break;
}
return {
status,
statusText,
statusColor,
emoji: this.getStatusEmoji()
};
}
private getStatusEmoji(): string {
switch (this.status) {
case 'disconnected': return 'βͺ';
case 'ready': return 'π‘';
case 'running': return 'π’';
case 'stopped': return 'π΄';
case 'initializing': return 'π ';
default: return 'βͺ';
}
}
/**
* Reset session data
*/
resetSession(): void {
this.sessionId = null;
this.sessionConfig = null;
this.sessionData = null;
this.status = 'disconnected';
}
/**
* Update position
*/
updatePosition(newPosition: Position3D): void {
this.position = { ...newPosition };
}
/**
* Update name
*/
updateName(newName: string): void {
this.name = newName;
}
} |