refactor: move all ZMQ to API

also removed a lot of logs to the console to avoid cluttering

ref: N25B-400
This commit is contained in:
Pim Hutting
2026-01-15 09:24:51 +01:00
parent 7d00f35990
commit 714ee34bbe
3 changed files with 26 additions and 26 deletions

View File

@@ -1,6 +1,24 @@
import { useEffect } from 'react';
const API_BASE_BP = "http://localhost:8000/button_pressed"; // Change depending on Pims interup agent/ correct endpoint
const API_BASE = "http://localhost:8000";
const API_BASE_BP = API_BASE + "/button_pressed"; //UserInterruptAgent endpoint
/**
* HELPER: Unified sender function
*/
export const sendUserInterrupt = async (type: string, context: string) => {
try {
const response = await fetch(API_BASE_BP, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({type, context}),
});
if (!response.ok) throw new Error("Backend response error");
console.log(`Interrupt Sent - Type: ${type}, Context: ${context}`);
} catch (err) {
console.error(`Failed to send interrupt:`, err);
}
};
/**
@@ -76,8 +94,8 @@ export type CondNormsStateUpdate = { type: 'cond_norms_state_update'; norms: { i
export type ExperimentStreamData = PhaseUpdate | GoalUpdate | TriggerUpdate | CondNormsStateUpdate | Record<string, unknown>;
/**
* A hook that listens to the experiment stream and logs data to the console.
* It does not render anything.
* A hook that listens to the experiment stream that updates current state of the program
* via updates sent from the backend
*/
export function useExperimentLogger(onUpdate?: (data: ExperimentStreamData) => void) {
useEffect(() => {
@@ -87,19 +105,16 @@ export function useExperimentLogger(onUpdate?: (data: ExperimentStreamData) => v
try {
const parsedData = JSON.parse(event.data) as ExperimentStreamData;
if (onUpdate) {
console.log(event.data);
onUpdate(parsedData);
}
} catch (err) {
console.warn("Stream parse error:", err);
}
};
eventSource.onerror = (err) => {
console.error("SSE Connection Error:", err);
eventSource.close();
};
return () => {
eventSource.close();
};