The root .gitignore had `lib/` which matched frontend/src/lib/, causing Docker build to fail with "Module not found: Can't resolve '@/lib/utils'" and '@/lib/i18n'. Changed to `/lib/` so it only ignores the Python lib at repo root. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import { useState, useCallback } from "react";
|
|
|
|
interface WebLLMState {
|
|
isLoaded: boolean;
|
|
loading: boolean;
|
|
error: string | null;
|
|
}
|
|
|
|
export function useWebLLM() {
|
|
const [state, setState] = useState<WebLLMState>({
|
|
isLoaded: false,
|
|
loading: false,
|
|
error: null,
|
|
});
|
|
|
|
const isWebGPUSupported = useCallback(() => {
|
|
if (typeof navigator === "undefined") return false;
|
|
return "gpu" in navigator;
|
|
}, []);
|
|
|
|
const translate = useCallback(
|
|
async (
|
|
_text: string,
|
|
_targetLang: string,
|
|
_systemPrompt?: string,
|
|
_glossary?: string,
|
|
): Promise<string> => {
|
|
setState((s) => ({ ...s, loading: true, error: null }));
|
|
try {
|
|
throw new Error("WebLLM is not available in this environment");
|
|
} catch (err) {
|
|
const message =
|
|
err instanceof Error ? err.message : "WebLLM translation failed";
|
|
setState((s) => ({ ...s, loading: false, error: message }));
|
|
throw err;
|
|
}
|
|
},
|
|
[],
|
|
);
|
|
|
|
return {
|
|
...state,
|
|
isWebGPUSupported,
|
|
translate,
|
|
};
|
|
}
|