fix: use custom event for training panel toggle, no more poll inference

SkillInsertDialog dispatches SKILL_TOGGLED_EVENT on user click.
AssistantWorkspace listens for that event to set applied state.
Completely eliminates poll-based state inference that caused flash.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
hupenglong1
2026-05-25 17:46:51 +08:00
parent 2acbd0b509
commit 5b708d2996
3 changed files with 24 additions and 24 deletions
+10
View File
@@ -3,6 +3,7 @@
import { useCallback, useEffect, useState } from "react";
export const SESSION_UPDATED_EVENT = "claw-session-updated";
export const SKILL_TOGGLED_EVENT = "claw-skill-toggled";
const APPLIED_STORAGE_PREFIX = "claw.training.applied:";
const MODEL_ITERATION_SKILL_NAMES = new Set(["model-iteration"]);
@@ -158,6 +159,15 @@ export function dispatchSessionUpdated(detail: SessionUpdatedDetail) {
);
}
export type SkillToggledDetail = { skill: string; enabled: boolean };
export function dispatchSkillToggled(detail: SkillToggledDetail) {
if (typeof window === "undefined") return;
window.dispatchEvent(
new CustomEvent<SkillToggledDetail>(SKILL_TOGGLED_EVENT, { detail }),
);
}
export function useTrainingMode(sessionId: string | null) {
const [isTraining, setIsTraining] = useState(false);
const [loaded, setLoaded] = useState(false);