Claude Code Claude Opus 4.6 commited on
Commit
b1af383
·
1 Parent(s): 9930b35

Claude Code: Refactor dashboard to use static CONFIG object - remove external config file dependency, use window.location.origin directly for API base

Browse files
Files changed (1) hide show
  1. frontend/agent-dashboard.html +29 -34
frontend/agent-dashboard.html CHANGED
@@ -740,10 +740,17 @@
740
  </div>
741
 
742
  <script>
743
- // Configuration
744
- const API_BASE = window.location.origin;
745
- const POLL_INTERVAL = 2000; // 2 seconds
746
- const RESOURCE_INTERVAL = 5000; // 5 seconds
 
 
 
 
 
 
 
747
 
748
  // State
749
  let lastThoughtCount = 0;
@@ -751,46 +758,34 @@
751
  let eventCount = 0;
752
  let lastResources = { adam: 100, eve: 100 };
753
 
754
- // Default config fallback - used when config fetch fails
755
- const defaultConfig = {
756
- state: 'idle',
757
- agent: 'Cain',
758
- stage: 'RUNNING',
759
- health: 'healthy',
760
- detail: 'Cain is operational (fallback mode)'
761
- };
762
-
763
  // Initialize with error boundary
764
  document.addEventListener('DOMContentLoaded', () => {
765
  try {
766
  connectToEventBus();
767
- setInterval(fetchThoughts, POLL_INTERVAL);
768
  setInterval(updateStats, 1000);
769
- setInterval(fetchResources, RESOURCE_INTERVAL);
770
- setInterval(fetchDebugHealth, 5000); // Poll /debug/health every 5 seconds
771
- setInterval(fetchApiHealth, 3000); // Poll /api/health every 3 seconds
772
- setInterval(fetchCainState, 2000); // Poll /api/state every 2 seconds
773
- fetchResources(); // Initial fetch
774
- fetchDebugHealth(); // Initial health fetch
775
- fetchApiHealth(); // Initial API health fetch
776
- fetchCainState(); // Initial state fetch
777
  } catch (initError) {
778
  console.error('Initialization error:', initError);
779
- // Initialize UI with fallback defaults
780
- initializeWithDefaults(defaultConfig);
781
  }
782
  });
783
 
784
- // Initialize UI with default config when fetch fails
785
  function initializeWithDefaults(config) {
786
- // Set Cain state to defaults
787
  updateCainState({
788
  health: config.health,
789
  stage: config.stage,
790
  state: config.state,
791
  detail: config.detail
792
  });
793
- // Update connection to show degraded but functional
794
  updateConnectionStatus(false);
795
  document.getElementById('connectionText').textContent = 'Fallback mode';
796
  }
@@ -818,7 +813,7 @@
818
  // Fetch thoughts from API
819
  async function fetchThoughts() {
820
  try {
821
- const response = await fetch(`${API_BASE}/api/thoughts?limit=50`);
822
  if (response.ok) {
823
  const thoughts = await response.json();
824
  displayThoughts(thoughts);
@@ -909,7 +904,7 @@
909
  // Clear thoughts display
910
  async function clearThoughts() {
911
  try {
912
- await fetch(`${API_BASE}/api/thoughts/clear`, { method: 'POST' });
913
  document.getElementById('thoughtsContainer').innerHTML = `
914
  <div class="empty-state">
915
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
@@ -977,7 +972,7 @@
977
  // Fetch resources from API
978
  async function fetchResources() {
979
  try {
980
- const response = await fetch(`${API_BASE}/api/resources`);
981
  if (response.ok) {
982
  const data = await response.json();
983
  updateResourceDisplay(data.resources || {});
@@ -1040,7 +1035,7 @@
1040
  // Show transfer history
1041
  async function showTransferHistory() {
1042
  try {
1043
- const response = await fetch(`${API_BASE}/api/resources/history?limit=10`);
1044
  if (response.ok) {
1045
  const data = await response.json();
1046
  displayTransferHistory(data.history || []);
@@ -1067,7 +1062,7 @@
1067
  // Fetch debug health from API
1068
  async function fetchDebugHealth() {
1069
  try {
1070
- const response = await fetch(`${API_BASE}/debug/health`);
1071
  if (response.ok) {
1072
  const data = await response.json();
1073
  updateDebugStats(data);
@@ -1107,7 +1102,7 @@
1107
  // Fetch API health status
1108
  async function fetchApiHealth() {
1109
  try {
1110
- const response = await fetch(`${API_BASE}/api/health`);
1111
  if (response.ok) {
1112
  const data = await response.json();
1113
  updateFooterStatus(true, data);
@@ -1161,7 +1156,7 @@
1161
  // Fetch Cain state from /api/state
1162
  async function fetchCainState() {
1163
  try {
1164
- const response = await fetch(`${API_BASE}/api/state`);
1165
  if (response.ok) {
1166
  const data = await response.json();
1167
  updateCainState(data);
 
740
  </div>
741
 
742
  <script>
743
+ // Static CONFIG - no external file fetch required
744
+ const CONFIG = {
745
+ apiBase: window.location.origin,
746
+ pollInterval: 2000,
747
+ resourceInterval: 5000,
748
+ state: 'idle',
749
+ agent: 'Cain',
750
+ stage: 'RUNNING',
751
+ health: 'healthy',
752
+ detail: 'Cain is operational'
753
+ };
754
 
755
  // State
756
  let lastThoughtCount = 0;
 
758
  let eventCount = 0;
759
  let lastResources = { adam: 100, eve: 100 };
760
 
 
 
 
 
 
 
 
 
 
761
  // Initialize with error boundary
762
  document.addEventListener('DOMContentLoaded', () => {
763
  try {
764
  connectToEventBus();
765
+ setInterval(fetchThoughts, CONFIG.pollInterval);
766
  setInterval(updateStats, 1000);
767
+ setInterval(fetchResources, CONFIG.resourceInterval);
768
+ setInterval(fetchDebugHealth, 5000);
769
+ setInterval(fetchApiHealth, 3000);
770
+ setInterval(fetchCainState, 2000);
771
+ fetchResources();
772
+ fetchDebugHealth();
773
+ fetchApiHealth();
774
+ fetchCainState();
775
  } catch (initError) {
776
  console.error('Initialization error:', initError);
777
+ initializeWithDefaults(CONFIG);
 
778
  }
779
  });
780
 
781
+ // Initialize UI with static CONFIG
782
  function initializeWithDefaults(config) {
 
783
  updateCainState({
784
  health: config.health,
785
  stage: config.stage,
786
  state: config.state,
787
  detail: config.detail
788
  });
 
789
  updateConnectionStatus(false);
790
  document.getElementById('connectionText').textContent = 'Fallback mode';
791
  }
 
813
  // Fetch thoughts from API
814
  async function fetchThoughts() {
815
  try {
816
+ const response = await fetch(`${CONFIG.apiBase}/api/thoughts?limit=50`);
817
  if (response.ok) {
818
  const thoughts = await response.json();
819
  displayThoughts(thoughts);
 
904
  // Clear thoughts display
905
  async function clearThoughts() {
906
  try {
907
+ await fetch(`${CONFIG.apiBase}/api/thoughts/clear`, { method: 'POST' });
908
  document.getElementById('thoughtsContainer').innerHTML = `
909
  <div class="empty-state">
910
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
 
972
  // Fetch resources from API
973
  async function fetchResources() {
974
  try {
975
+ const response = await fetch(`${CONFIG.apiBase}/api/resources`);
976
  if (response.ok) {
977
  const data = await response.json();
978
  updateResourceDisplay(data.resources || {});
 
1035
  // Show transfer history
1036
  async function showTransferHistory() {
1037
  try {
1038
+ const response = await fetch(`${CONFIG.apiBase}/api/resources/history?limit=10`);
1039
  if (response.ok) {
1040
  const data = await response.json();
1041
  displayTransferHistory(data.history || []);
 
1062
  // Fetch debug health from API
1063
  async function fetchDebugHealth() {
1064
  try {
1065
+ const response = await fetch(`${CONFIG.apiBase}/debug/health`);
1066
  if (response.ok) {
1067
  const data = await response.json();
1068
  updateDebugStats(data);
 
1102
  // Fetch API health status
1103
  async function fetchApiHealth() {
1104
  try {
1105
+ const response = await fetch(`${CONFIG.apiBase}/api/health`);
1106
  if (response.ok) {
1107
  const data = await response.json();
1108
  updateFooterStatus(true, data);
 
1156
  // Fetch Cain state from /api/state
1157
  async function fetchCainState() {
1158
  try {
1159
+ const response = await fetch(`${CONFIG.apiBase}/api/state`);
1160
  if (response.ok) {
1161
  const data = await response.json();
1162
  updateCainState(data);