Initial commit: RA-H Open Source Edition
Local-first knowledge management system with BYO API keys. Features: - 3-panel UI (Nodes | Focus | Helpers) - SQLite + sqlite-vec for vector search - Agent system (Easy/Hard mode orchestrators) - Content extraction (YouTube, PDF, web) - Integrate workflow for connection discovery - Dimension system with auto-assignment Tech stack: - Next.js 15 + TypeScript + Tailwind CSS - Anthropic (Claude) + OpenAI (GPT) via Vercel AI SDK Setup: npm install && npm rebuild better-sqlite3 scripts/dev/bootstrap-local.sh npm run dev MIT License
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export function usePersistentState<T>(
|
||||
key: string,
|
||||
defaultValue: T
|
||||
): [T, (value: T | ((prev: T) => T)) => void] {
|
||||
// Initialize with default value first
|
||||
const [state, setState] = useState<T>(defaultValue);
|
||||
|
||||
// Load from localStorage after mount
|
||||
useEffect(() => {
|
||||
try {
|
||||
const item = window.localStorage.getItem(key);
|
||||
if (item !== null) {
|
||||
setState(JSON.parse(item));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error loading ${key} from localStorage:`, error);
|
||||
}
|
||||
}, [key]);
|
||||
|
||||
// Save to localStorage when state changes
|
||||
const setPersistentState = (value: T | ((prev: T) => T)) => {
|
||||
setState(prev => {
|
||||
const newValue = typeof value === 'function'
|
||||
? (value as (prev: T) => T)(prev)
|
||||
: value;
|
||||
|
||||
try {
|
||||
window.localStorage.setItem(key, JSON.stringify(newValue));
|
||||
} catch (error) {
|
||||
console.error(`Error saving ${key} to localStorage:`, error);
|
||||
}
|
||||
|
||||
return newValue;
|
||||
});
|
||||
};
|
||||
|
||||
return [state, setPersistentState];
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
interface QuotaError {
|
||||
message: string;
|
||||
tokensUsed?: number | null;
|
||||
tokenLimit?: number | null;
|
||||
costUsd?: number | null;
|
||||
}
|
||||
|
||||
const messageIncludesQuota = (message?: string) => {
|
||||
if (!message) return false;
|
||||
const normalized = message.toLowerCase();
|
||||
return normalized.includes('quota') || normalized.includes('limit');
|
||||
};
|
||||
|
||||
export function useQuotaHandler() {
|
||||
const [quotaError, setQuotaError] = useState<QuotaError | null>(null);
|
||||
|
||||
const handleAPIError = useCallback((error: unknown, response?: Response) => {
|
||||
const message =
|
||||
error instanceof Error ? error.message : typeof error === 'string' ? error : undefined;
|
||||
|
||||
if (response?.status === 429 || messageIncludesQuota(message)) {
|
||||
setQuotaError({
|
||||
message: message || 'Rate limit reached. Please wait and try again.',
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}, []);
|
||||
|
||||
const dismissQuotaError = useCallback(() => {
|
||||
setQuotaError(null);
|
||||
}, []);
|
||||
|
||||
const checkQuotaBeforeRequest = useCallback(() => true, []);
|
||||
|
||||
const refetchUsage = useCallback(async () => {}, []);
|
||||
|
||||
return {
|
||||
quotaError,
|
||||
handleAPIError,
|
||||
checkQuotaBeforeRequest,
|
||||
dismissQuotaError,
|
||||
refetchUsage,
|
||||
isQuotaExceeded: false,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user