feat: added endpoint

ref:N25B-400
This commit is contained in:
Pim Hutting
2026-01-07 17:39:20 +01:00
28 changed files with 1927 additions and 133 deletions

View File

@@ -3,7 +3,6 @@ import styles from './MonitoringPage.module.css';
/**
* HELPER: Unified sender function
* In a real app, you might move this to a /services or /hooks folder
*/
const sendUserInterrupt = async (type: string, context: string) => {
try {

View File

@@ -1,14 +1,13 @@
import React from 'react';
import React, { use } from 'react';
import styles from './MonitoringPage.module.css';
import useProgramStore from "../../utils/programStore.ts";
import { GestureControls, SpeechPresets, DirectSpeechInput, StatusList } from './Components';
import { nextPhase } from ".//MonitoringPageAPI.ts"
import { nextPhase, useExperimentLogger } from ".//MonitoringPageAPI.ts"
type Goal = { id?: string | number; description?: string; achieved?: boolean };
type Trigger = { id?: string | number; label?: string ; achieved?: boolean };
type Norm = { id?: string | number; norm?: string };
const MonitoringPage: React.FC = () => {
const getPhaseIds = useProgramStore((s) => s.getPhaseIds);
const getNormsInPhase = useProgramStore((s) => s.getNormsInPhase);
@@ -43,7 +42,7 @@ const MonitoringPage: React.FC = () => {
setLoading(false);
}
};
useExperimentLogger();
return (
<div className={styles.dashboardContainer}>
{/* HEADER */}

View File

@@ -1,4 +1,5 @@
const API_BASE = "http://localhost:8000/"; // Change depending on Pims interup agent/ correct endpoint
import React, { useEffect } from 'react';
const API_BASE = "http://localhost:8000"; // Change depending on Pims interup agent/ correct endpoint
/**
@@ -16,4 +17,37 @@ export async function nextPhase(): Promise<void> {
if (!res.ok) {
throw new Error("Failed to advance to next phase");
}
}
/**
* A hook that listens to the experiment stream and logs data to the console.
* It does not render anything.
*/
export function useExperimentLogger() {
useEffect(() => {
console.log("Starting Experiment Stream listener...");
const eventSource = new EventSource(`${API_BASE}/experiment_stream`);
eventSource.onmessage = (event) => {
try {
const parsedData = JSON.parse(event.data);
console.log(" [Experiment Update Received] ", parsedData);
} catch (err) {
console.warn("Received non-JSON experiment data:", event.data);
}
};
eventSource.onerror = (err) => {
console.error("SSE Connection Error (Experiment Stream):", err);
eventSource.close();
};
return () => {
console.log("Closing Experiment Stream listener...");
eventSource.close();
};
}, []);
}