File size: 765 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export interface SkillChangeDetail {
  agentId: string;
}

const SKILL_CHANGE_EVENT = "qwenpaw:skills-changed";

export function notifySkillChange(agentId: string): void {
  if (typeof window === "undefined") return;
  window.dispatchEvent(
    new CustomEvent<SkillChangeDetail>(SKILL_CHANGE_EVENT, {
      detail: { agentId },
    }),
  );
}

export function subscribeToSkillChanges(
  listener: (detail: SkillChangeDetail) => void,
): () => void {
  if (typeof window === "undefined") return () => undefined;

  const handleChange = (event: Event) => {
    listener((event as CustomEvent<SkillChangeDetail>).detail);
  };
  window.addEventListener(SKILL_CHANGE_EVENT, handleChange);
  return () => window.removeEventListener(SKILL_CHANGE_EVENT, handleChange);
}