Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

1.2 KB
Raw Blame
import { create } from "zustand";
import { getPlatform } from "@/platform/platform-singleton";

type GlobalInstructionsState = {
  instructions: string;
  isLoading: boolean;
  loadInstructions: () => Promise<void>;
  saveInstructions: (instructions: string) => Promise<boolean>;
};

export const useGlobalInstructionsStore = create<GlobalInstructionsState>((set) => ({
  instructions: "",
  isLoading: false,

  loadInstructions: async () => {
    set({ isLoading: true });
    const { storage } = getPlatform();
    try {
      const instructions = await storage.loadGlobalInstructions();
      set({ instructions: instructions || "" });
    } catch (error) {
      console.error("Failed to load global instructions:", error);
    } finally {
      set({ isLoading: false });
    }
  },

  saveInstructions: async (instructions: string) => {
    set({ isLoading: true });
    const { storage } = getPlatform();
    try {
      await storage.saveGlobalInstructions(instructions);
      set({ instructions });
      return true;
    } catch (error) {
      console.error("Failed to save global instructions:", error);
      return false;
    } finally {
      set({ isLoading: false });
    }
  },
}));