repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { useState } from 'react'; |
| #2 | import axios from 'axios'; |
| #3 | import { useDispatch, useSelector } from 'react-redux'; |
| #4 | import { AppDispatch, RootState } from '@/store/store'; |
| #5 | import { |
| #6 | setConfigLoading, |
| #7 | setConfigSuccess, |
| #8 | setConfigError, |
| #9 | updateLLM, |
| #10 | updateEmbedder, |
| #11 | updateMem0Config, |
| #12 | updateOpenMemory, |
| #13 | LLMProvider, |
| #14 | EmbedderProvider, |
| #15 | Mem0Config, |
| #16 | OpenMemoryConfig |
| #17 | } from '@/store/configSlice'; |
| #18 | |
| #19 | interface UseConfigApiReturn { |
| #20 | fetchConfig: () => Promise<void>; |
| #21 | saveConfig: (config: { openmemory?: OpenMemoryConfig; mem0: Mem0Config }) => Promise<void>; |
| #22 | saveLLMConfig: (llmConfig: LLMProvider) => Promise<void>; |
| #23 | saveEmbedderConfig: (embedderConfig: EmbedderProvider) => Promise<void>; |
| #24 | resetConfig: () => Promise<void>; |
| #25 | isLoading: boolean; |
| #26 | error: string | null; |
| #27 | } |
| #28 | |
| #29 | export const useConfig = (): UseConfigApiReturn => { |
| #30 | const [isLoading, setIsLoading] = useState<boolean>(false); |
| #31 | const [error, setError] = useState<string | null>(null); |
| #32 | const dispatch = useDispatch<AppDispatch>(); |
| #33 | const URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8765"; |
| #34 | |
| #35 | const fetchConfig = async () => { |
| #36 | setIsLoading(true); |
| #37 | dispatch(setConfigLoading()); |
| #38 | |
| #39 | try { |
| #40 | const response = await axios.get(`${URL}/api/v1/config`); |
| #41 | dispatch(setConfigSuccess(response.data)); |
| #42 | setIsLoading(false); |
| #43 | } catch (err: any) { |
| #44 | const errorMessage = err.response?.data?.detail || err.message || 'Failed to fetch configuration'; |
| #45 | dispatch(setConfigError(errorMessage)); |
| #46 | setError(errorMessage); |
| #47 | setIsLoading(false); |
| #48 | throw new Error(errorMessage); |
| #49 | } |
| #50 | }; |
| #51 | |
| #52 | const saveConfig = async (config: { openmemory?: OpenMemoryConfig; mem0: Mem0Config }) => { |
| #53 | setIsLoading(true); |
| #54 | setError(null); |
| #55 | |
| #56 | try { |
| #57 | const response = await axios.put(`${URL}/api/v1/config`, config); |
| #58 | dispatch(setConfigSuccess(response.data)); |
| #59 | setIsLoading(false); |
| #60 | return response.data; |
| #61 | } catch (err: any) { |
| #62 | const errorMessage = err.response?.data?.detail || err.message || 'Failed to save configuration'; |
| #63 | dispatch(setConfigError(errorMessage)); |
| #64 | setError(errorMessage); |
| #65 | setIsLoading(false); |
| #66 | throw new Error(errorMessage); |
| #67 | } |
| #68 | }; |
| #69 | |
| #70 | const resetConfig = async () => { |
| #71 | setIsLoading(true); |
| #72 | setError(null); |
| #73 | |
| #74 | try { |
| #75 | const response = await axios.post(`${URL}/api/v1/config/reset`); |
| #76 | dispatch(setConfigSuccess(response.data)); |
| #77 | setIsLoading(false); |
| #78 | return response.data; |
| #79 | } catch (err: any) { |
| #80 | const errorMessage = err.response?.data?.detail || err.message || 'Failed to reset configuration'; |
| #81 | dispatch(setConfigError(errorMessage)); |
| #82 | setError(errorMessage); |
| #83 | setIsLoading(false); |
| #84 | throw new Error(errorMessage); |
| #85 | } |
| #86 | }; |
| #87 | |
| #88 | const saveLLMConfig = async (llmConfig: LLMProvider) => { |
| #89 | setIsLoading(true); |
| #90 | setError(null); |
| #91 | |
| #92 | try { |
| #93 | const response = await axios.put(`${URL}/api/v1/config/mem0/llm`, llmConfig); |
| #94 | dispatch(updateLLM(response.data)); |
| #95 | setIsLoading(false); |
| #96 | return response.data; |
| #97 | } catch (err: any) { |
| #98 | const errorMessage = err.response?.data?.detail || err.message || 'Failed to save LLM configuration'; |
| #99 | setError(errorMessage); |
| #100 | setIsLoading(false); |
| #101 | throw new Error(errorMessage); |
| #102 | } |
| #103 | }; |
| #104 | |
| #105 | const saveEmbedderConfig = async (embedderConfig: EmbedderProvider) => { |
| #106 | setIsLoading(true); |
| #107 | setError(null); |
| #108 | |
| #109 | try { |
| #110 | const response = await axios.put(`${URL}/api/v1/config/mem0/embedder`, embedderConfig); |
| #111 | dispatch(updateEmbedder(response.data)); |
| #112 | setIsLoading(false); |
| #113 | return response.data; |
| #114 | } catch (err: any) { |
| #115 | const errorMessage = err.response?.data?.detail || err.message || 'Failed to save Embedder configuration'; |
| #116 | setError(errorMessage); |
| #117 | setIsLoading(false); |
| #118 | throw new Error(errorMessage); |
| #119 | } |
| #120 | }; |
| #121 | |
| #122 | return { |
| #123 | fetchConfig, |
| #124 | saveConfig, |
| #125 | saveLLMConfig, |
| #126 | saveEmbedderConfig, |
| #127 | resetConfig, |
| #128 | isLoading, |
| #129 | error |
| #130 | }; |
| #131 | }; |