waveterm/frontend/app/block/block-model.ts
Mike Sawka 0e8eb83f62
Updates to prepare for v0.12 launch (#2434)
Documentation Updates (removing AI Widget Information / deprecation)
Hover effect on tool calls shows which widget is effected
Remove AI Widget from sidebar unless there is customized presets
Backend now provides blockid (if available) to frontend for tool calls
2025-10-15 16:10:37 -07:00

51 lines
No EOL
1.5 KiB
TypeScript

// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { globalStore } from "@/app/store/jotaiStore";
import * as jotai from "jotai";
export interface BlockHighlightType {
blockId: string;
icon: string;
}
export class BlockModel {
private static instance: BlockModel | null = null;
private blockHighlightAtomCache = new Map<string, jotai.Atom<BlockHighlightType | null>>();
blockHighlightAtom: jotai.PrimitiveAtom<BlockHighlightType> = jotai.atom(null) as jotai.PrimitiveAtom<BlockHighlightType>;
private constructor() {
// Empty for now
}
getBlockHighlightAtom(blockId: string): jotai.Atom<BlockHighlightType | null> {
let atom = this.blockHighlightAtomCache.get(blockId);
if (!atom) {
atom = jotai.atom((get) => {
const highlight = get(this.blockHighlightAtom);
if (highlight?.blockId === blockId) {
return highlight;
}
return null;
});
this.blockHighlightAtomCache.set(blockId, atom);
}
return atom;
}
setBlockHighlight(highlight: BlockHighlightType | null) {
globalStore.set(this.blockHighlightAtom, highlight);
}
static getInstance(): BlockModel {
if (!BlockModel.instance) {
BlockModel.instance = new BlockModel();
}
return BlockModel.instance;
}
static resetInstance(): void {
BlockModel.instance = null;
}
}