fleet-memory/hindsight-control-plane/src/lib/features-context.tsx
Nicolò Boschi 5b52a84fff
chore: internal renames (#204)
This commit renames the terminology across the entire codebase:
- "mental models" (fact_type='mental_model' in memory_units) → "observations"
- "reflections" table (stored reflect responses) → "mental_models"

Changes include:
- Database migration to rename tables, indexes, and constraints
- API endpoints: /reflections → /mental-models, /mental-models → /observations
- Config: ENABLE_MENTAL_MODELS → ENABLE_OBSERVATIONS
- Response models and Pydantic classes
- Reflect agent tools and prompts
- Control plane UI and routes
- Documentation and examples
- Regenerated OpenAPI spec and client SDKs (Python, TypeScript)
- Rust CLI: reflection commands → mental-model commands
- LiteLLM: updated fact_types documentation
2026-01-27 09:53:28 +01:00

63 lines
1.5 KiB
TypeScript

"use client";
import React, { createContext, useContext, useState, useEffect } from "react";
import { client } from "./api";
interface Features {
observations: boolean;
mcp: boolean;
worker: boolean;
}
interface FeaturesContextType {
features: Features | null;
loading: boolean;
error: string | null;
}
const defaultFeatures: Features = {
observations: false,
mcp: false,
worker: false,
};
const FeaturesContext = createContext<FeaturesContextType | undefined>(undefined);
export function FeaturesProvider({ children }: { children: React.ReactNode }) {
const [features, setFeatures] = useState<Features | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const loadFeatures = async () => {
try {
const response = await client.getVersion();
setFeatures(response.features);
setError(null);
} catch (err) {
console.error("Error loading features:", err);
setError("Failed to load feature flags");
// Use defaults on error
setFeatures(defaultFeatures);
} finally {
setLoading(false);
}
};
loadFeatures();
}, []);
return (
<FeaturesContext.Provider value={{ features, loading, error }}>
{children}
</FeaturesContext.Provider>
);
}
export function useFeatures() {
const context = useContext(FeaturesContext);
if (context === undefined) {
throw new Error("useFeatures must be used within a FeaturesProvider");
}
return context;
}