Add experiment logs to the monitoring page #48
@@ -106,24 +106,34 @@ interface StatusListProps {
|
|||||||
title: string;
|
title: string;
|
||||||
items: any[];
|
items: any[];
|
||||||
type: 'goal' | 'trigger' | 'norm'| 'cond_norm';
|
type: 'goal' | 'trigger' | 'norm'| 'cond_norm';
|
||||||
|
activeIds: Record<string, boolean>;
|
||||||
|
currentGoalIndex?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- STATUS LIST COMPONENT ---
|
// --- STATUS LIST COMPONENT ---
|
||||||
export const StatusList: React.FC<StatusListProps> = ({ title, items, type }) => {
|
export const StatusList: React.FC<StatusListProps> = ({
|
||||||
|
title,
|
||||||
|
items,
|
||||||
|
type,
|
||||||
|
activeIds,
|
||||||
|
currentGoalIndex // Destructure this prop
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<section className={styles.phaseBox}>
|
<section className={styles.phaseBox}>
|
||||||
<h3>{title}</h3>
|
<h3>{title}</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{items.map((item, idx) => {
|
{items.map((item, idx) => {
|
||||||
let isAchieved = item.achieved;
|
const isActive = !!activeIds[item.id];
|
||||||
const showIndicator = type !== 'norm';
|
const showIndicator = type !== 'norm';
|
||||||
const canOverride = showIndicator && !isAchieved;
|
const canOverride = showIndicator && !isActive;
|
||||||
const isCurrentGoal = type === 'goal' && item.isCurrent;
|
|
||||||
|
// HIGHLIGHT LOGIC:
|
||||||
|
// If this is the "Goals" list, check if the current index matches
|
||||||
|
const isCurrentGoal = type === 'goal' && idx === currentGoalIndex;
|
||||||
|
|
||||||
const handleOverrideClick = () => {
|
const handleOverrideClick = () => {
|
||||||
if (!canOverride) return;
|
if (!canOverride) return;
|
||||||
let contextValue = String(item.id);
|
sendUserInterrupt("override", String(item.id));
|
||||||
sendUserInterrupt("override", contextValue);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -133,18 +143,23 @@ export const StatusList: React.FC<StatusListProps> = ({ title, items, type }) =>
|
|||||||
className={`${styles.statusIndicator} ${canOverride ? styles.clickable : ''}`}
|
className={`${styles.statusIndicator} ${canOverride ? styles.clickable : ''}`}
|
||||||
onClick={handleOverrideClick}
|
onClick={handleOverrideClick}
|
||||||
>
|
>
|
||||||
{isAchieved ? "✔️" : "❌"}
|
{isActive ? "✔️" : "❌"}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<span
|
<span
|
||||||
className={styles.itemDescription}
|
className={styles.itemDescription}
|
||||||
style={{
|
style={{
|
||||||
|
// Visual Feedback
|
||||||
textDecoration: isCurrentGoal ? 'underline' : 'none',
|
textDecoration: isCurrentGoal ? 'underline' : 'none',
|
||||||
fontWeight: isCurrentGoal ? 'bold' : 'normal',
|
fontWeight: isCurrentGoal ? 'bold' : 'normal',
|
||||||
color: isCurrentGoal ? '#007bff' : 'inherit'
|
color: isCurrentGoal ? '#007bff' : 'inherit',
|
||||||
|
backgroundColor: isCurrentGoal ? '#e7f3ff' : 'transparent', // Added subtle highlight
|
||||||
|
padding: isCurrentGoal ? '2px 4px' : '0',
|
||||||
|
borderRadius: '4px'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{item.description || item.label || item.norm}
|
{item.description || item.label || item.norm}
|
||||||
|
{isCurrentGoal && " (Current)"}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const MonitoringPage: React.FC = () => {
|
|||||||
const phaseIds = getPhaseIds();
|
const phaseIds = getPhaseIds();
|
||||||
const [phaseIndex, setPhaseIndex] = React.useState(0);
|
const [phaseIndex, setPhaseIndex] = React.useState(0);
|
||||||
|
|
||||||
|
const isFinished = phaseIndex >= phaseIds.length; //determines if experiment is over
|
||||||
|
|
||||||
const handleStreamUpdate = React.useCallback((data: any) => {
|
const handleStreamUpdate = React.useCallback((data: any) => {
|
||||||
// Check for phase updates
|
// Check for phase updates
|
||||||
@@ -34,18 +35,28 @@ const MonitoringPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data.type === 'goal_update') {
|
else if (data.type === 'goal_update') {
|
||||||
// We find which goal in the current phase matches this ID
|
const currentPhaseGoals = getGoalsInPhase(phaseIds[phaseIndex]) as any[];
|
||||||
const currentPhaseGoals = getGoalsInPhase(phaseIds[phaseIndex]);
|
|
||||||
const gIndex = currentPhaseGoals.findIndex((g: any) => g.id === data.id);
|
const gIndex = currentPhaseGoals.findIndex((g: any) => g.id === data.id);
|
||||||
|
|
||||||
if (gIndex !== -1) {
|
if (gIndex !== -1) {
|
||||||
|
//set current goal to the goal that is just started
|
||||||
setGoalIndex(gIndex);
|
setGoalIndex(gIndex);
|
||||||
console.log(`Goal index updated to ${gIndex} for goal ID ${data.id}`);
|
|
||||||
|
// All previous goals are set to "active" which means they are achieved
|
||||||
|
setActiveIds((prev) => {
|
||||||
|
const nextState = { ...prev };
|
||||||
|
|
||||||
|
// We loop until i is LESS than gIndex.
|
||||||
|
// This leaves currentPhaseGoals[gIndex] as isActive: false.
|
||||||
|
for (let i = 0; i < gIndex; i++) {
|
||||||
|
nextState[currentPhaseGoals[i].id ] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
setActiveIds((prev) => ({
|
return nextState;
|
||||||
...prev,
|
});
|
||||||
[data.id]: true
|
|
||||||
}));
|
console.log(`Now pursuing goal: ${data.id}. Previous goals marked achieved.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (data.type === 'trigger_update') {
|
else if (data.type === 'trigger_update') {
|
||||||
@@ -54,6 +65,18 @@ const MonitoringPage: React.FC = () => {
|
|||||||
[data.id]: data.achieved // data.id is de key, achieved is true/false
|
[data.id]: data.achieved // data.id is de key, achieved is true/false
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
else if (data.type === 'cond_norms_state_update') {
|
||||||
|
setActiveIds((prev) => {
|
||||||
|
const nextState = { ...prev };
|
||||||
|
|
||||||
|
data.norms.forEach((normUpdate: { id: string; active: boolean }) => {
|
||||||
|
nextState[normUpdate.id] = normUpdate.active;
|
||||||
|
});
|
||||||
|
|
||||||
|
return nextState;
|
||||||
|
});
|
||||||
|
console.log("Updated conditional norms state:", data.norms);
|
||||||
|
}
|
||||||
}, [getPhaseIds]);
|
}, [getPhaseIds]);
|
||||||
|
|
||||||
useExperimentLogger(handleStreamUpdate);
|
useExperimentLogger(handleStreamUpdate);
|
||||||
@@ -74,30 +97,39 @@ const MonitoringPage: React.FC = () => {
|
|||||||
const triggers = (getTriggersInPhase(phaseId) as any[]).map(t => ({
|
const triggers = (getTriggersInPhase(phaseId) as any[]).map(t => ({
|
||||||
...t,
|
...t,
|
||||||
label: (() => {
|
label: (() => {
|
||||||
// Determine the Condition Prefix
|
|
||||||
let prefix = t.label; // Default fallback
|
let prefix = "";
|
||||||
if (t.condition?.keyword) {
|
if (t.condition?.keyword) {
|
||||||
prefix = `if keywords said: "${t.condition.keyword}"`;
|
prefix = `if keywords said: "${t.condition.keyword}"`;
|
||||||
} else if (t.condition?.name) {
|
} else if (t.condition?.name) {
|
||||||
prefix = `if LLM belief: ${t.condition.name}`;
|
prefix = `if LLM belief: ${t.condition.name}`;
|
||||||
|
} else { //fallback
|
||||||
|
prefix = t.label || "Trigger";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the Plan Steps
|
|
||||||
// We check if plan exists and has steps
|
|
||||||
const stepLabels = t.plan?.steps?.map((step: any) => {
|
|
||||||
|
|
||||||
return step.label || step.name || "Action";
|
const stepLabels = t.plan?.steps?.map((step: any) => {
|
||||||
|
if (step.text) {
|
||||||
|
return `say: "${step.text}"`;
|
||||||
|
}
|
||||||
|
if (step.gesture) {
|
||||||
|
return `perform gesture: ${step.gesture.name || step.gesture.type}`;
|
||||||
|
}
|
||||||
|
if (step.goal) {
|
||||||
|
return `perform LLM: ${step.goal}`;
|
||||||
|
}
|
||||||
|
return "Action"; // Fallback
|
||||||
}) || [];
|
}) || [];
|
||||||
|
|
||||||
const planText = stepLabels.length > 0
|
const planText = stepLabels.length > 0
|
||||||
? `➔ Do: ${stepLabels.join(", ")}`
|
? `➔ Do: ${stepLabels.join(", ")}`
|
||||||
: "➔ (No actions set)";
|
: "➔ (No actions set)";
|
||||||
|
|
||||||
// "If [Condition] ➔ Do: [Steps]"
|
|
||||||
return `${prefix} ${planText}`;
|
return `${prefix} ${planText}`;
|
||||||
})(),
|
})(),
|
||||||
achieved: activeIds[t.id] ?? false
|
isActive: activeIds[t.id] ?? false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const norms = (getNormsInPhase(phaseId) as NormNodeData[])
|
const norms = (getNormsInPhase(phaseId) as NormNodeData[])
|
||||||
.filter(n => !n.condition)
|
.filter(n => !n.condition)
|
||||||
.map(n => ({
|
.map(n => ({
|
||||||
@@ -186,11 +218,18 @@ const MonitoringPage: React.FC = () => {
|
|||||||
<section className={styles.phaseOverviewText}>
|
<section className={styles.phaseOverviewText}>
|
||||||
<h3>Phase Overview</h3>
|
<h3>Phase Overview</h3>
|
||||||
</section>
|
</section>
|
||||||
|
{isFinished ? (
|
||||||
<StatusList title="Goals" items={goals} type="goal" />
|
<div className={styles.finishedMessage}>
|
||||||
<StatusList title="Triggers" items={triggers} type="trigger" />
|
<p> All phases have been successfully completed.</p>
|
||||||
<StatusList title="Norms" items={norms} type="norm" />
|
</div>
|
||||||
<StatusList title="Conditional Norms" items={conditionalNorms} type="cond_norm"/>
|
) : (
|
||||||
|
<>
|
||||||
|
<StatusList title="Goals" items={goals} type="goal" activeIds={activeIds} currentGoalIndex={goalIndex} />
|
||||||
|
<StatusList title="Triggers" items={triggers} type="trigger" activeIds={activeIds} />
|
||||||
|
<StatusList title="Norms" items={norms} type="norm" activeIds={activeIds} />
|
||||||
|
<StatusList title="Conditional Norms" items={conditionalNorms} type="cond_norm" activeIds={activeIds} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
{/* LOGS */}
|
{/* LOGS */}
|
||||||
|
|||||||
Reference in New Issue
Block a user