diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..c66e115bc --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,103 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL Advanced" + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + schedule: + - cron: '42 22 * * 5' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: actions + build-mode: none + - language: javascript-typescript + build-mode: none + - language: python + build-mode: none + # CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Add any setup steps before running the `github/codeql-action/init` action. + # This includes steps like installing compilers or runtimes (`actions/setup-node` + # or others). This is typically only required for manual builds. + # - name: Setup runtime (example) + # uses: actions/setup-example@v1 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v4 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - name: Run manual build steps + if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v4 + with: + category: "/language:${{matrix.language}}" diff --git a/backend/app/utils/agent.py b/backend/app/utils/agent.py index 26a3f9357..8be1ce71a 100644 --- a/backend/app/utils/agent.py +++ b/backend/app/utils/agent.py @@ -1521,7 +1521,6 @@ async def get_toolkits(tools: list[str], agent_name: str, api_task_id: str): toolkit_tools = await toolkit_tools if asyncio.iscoroutine(toolkit_tools) else toolkit_tools res.extend(toolkit_tools) else: - logger.warning(f"Toolkit {item} not found, please check your configuration.") traceroot_logger.warning(f"Toolkit {item} not found for agent {agent_name}") return res diff --git a/backend/app/utils/server/sync_step.py b/backend/app/utils/server/sync_step.py index eb29d5856..ac79bda6b 100644 --- a/backend/app/utils/server/sync_step.py +++ b/backend/app/utils/server/sync_step.py @@ -24,12 +24,23 @@ def sync_step(func): value_json_str = value[len("data: ") :].strip() else: value_json_str = value - json_data = json.loads(value_json_str) - + + try: + json_data = json.loads(value_json_str) + except json.JSONDecodeError as e: + logger.error(f"Failed to parse JSON in sync_step: {e}. Value: {value_json_str}") + yield value + continue + + if "step" not in json_data or "data" not in json_data: + logger.error(f"Missing 'step' or 'data' key in sync_step JSON. Keys: {list(json_data.keys())}") + yield value + continue + # Dynamic task_id extraction - prioritize runtime data over static args chat: Chat = args[0] if args and hasattr(args[0], 'task_id') else None task_id = None - + if chat is not None: task_lock = get_task_lock_if_exists(chat.project_id) if task_lock is not None: @@ -38,7 +49,7 @@ def sync_step(func): else: logger.warning(f"Task lock not found for project_id {chat.project_id}, using chat.task_id") task_id = chat.task_id - + if task_id: asyncio.create_task( send_to_api( @@ -62,4 +73,4 @@ async def send_to_api(url, data): res = await client.post(url, json=data) # logger.info(res) except Exception as e: - logger.error(e) + logger.error(f"Failed to sync step to {url}: {type(e).__name__}: {e}") diff --git a/src/pages/Setting/Models.tsx b/src/pages/Setting/Models.tsx index eec20bd77..b277c08df 100644 --- a/src/pages/Setting/Models.tsx +++ b/src/pages/Setting/Models.tsx @@ -73,9 +73,9 @@ export default function SettingModels() { INIT_PROVODERS.filter((p) => p.id !== "local").map(() => false) ); const [loading, setLoading] = useState(null); -const [errors, setErrors] = useState< - { apiKey?: string; apiHost?: string; model_type?: string; externalConfig?: string }[] ->(() => + const [errors, setErrors] = useState< + { apiKey?: string; apiHost?: string; model_type?: string; externalConfig?: string }[] + >(() => INIT_PROVODERS.filter((p) => p.id !== "local").map(() => ({ apiKey: "", apiHost: "", @@ -123,14 +123,14 @@ const [errors, setErrors] = useState< model_type: found.model_type ?? "", externalConfig: fi.externalConfig ? fi.externalConfig.map((ec) => { - if ( - found.encrypted_config && - found.encrypted_config[ec.key] !== undefined - ) { - return { ...ec, value: found.encrypted_config[ec.key] }; - } - return ec; - }) + if ( + found.encrypted_config && + found.encrypted_config[ec.key] !== undefined + ) { + return { ...ec, value: found.encrypted_config[ec.key] }; + } + return ec; + }) : undefined, }; } @@ -146,8 +146,8 @@ const [errors, setErrors] = useState< setLocalEndpoint(local.endpoint_url || ""); setLocalPlatform( local.encrypted_config?.model_platform || - local.provider_name || - "ollama" + local.provider_name || + "ollama" ); setLocalType(local.encrypted_config?.model_type || "llama3.2"); setLocalEnabled(local.is_valid ?? true); @@ -216,7 +216,7 @@ const [errors, setErrors] = useState< } console.log(form[idx]); - try { + try { const res = await fetchPost("/model/validate", { model_platform: item.id, model_type: form[idx].model_type, @@ -224,7 +224,7 @@ const [errors, setErrors] = useState< url: form[idx].apiHost, extra_params: external, }); - if (res.is_tool_calls && res.is_valid) { + if (res.is_tool_calls && res.is_valid) { console.log("success"); toast(t("setting.validate-success"), { description: t( @@ -233,27 +233,27 @@ const [errors, setErrors] = useState< closeButton: true, }); } else { - console.log("failed", res.message); - // Surface error inline on API Key input - setErrors((prev) => { - const next = [...prev]; - if (!next[idx]) next[idx] = {} as any; - next[idx].apiKey = getValidateMessage(res); - return next; - }); - return; + console.log("failed", res.message); + // Surface error inline on API Key input + setErrors((prev) => { + const next = [...prev]; + if (!next[idx]) next[idx] = {} as any; + next[idx].apiKey = getValidateMessage(res); + return next; + }); + return; } console.log(res); } catch (e) { - console.log(e); - // Network/exception case: show inline error - setErrors((prev) => { - const next = [...prev]; - if (!next[idx]) next[idx] = {} as any; - next[idx].apiKey = getValidateMessage(e); - return next; - }); - return; + console.log(e); + // Network/exception case: show inline error + setErrors((prev) => { + const next = [...prev]; + if (!next[idx]) next[idx] = {} as any; + next[idx].apiKey = getValidateMessage(e); + return next; + }); + return; } finally { setLoading(null); } @@ -296,14 +296,14 @@ const [errors, setErrors] = useState< prefer: found.prefer ?? false, externalConfig: fi.externalConfig ? fi.externalConfig.map((ec) => { - if ( - found.encrypted_config && - found.encrypted_config[ec.key] !== undefined - ) { - return { ...ec, value: found.encrypted_config[ec.key] }; - } - return ec; - }) + if ( + found.encrypted_config && + found.encrypted_config[ec.key] !== undefined + ) { + return { ...ec, value: found.encrypted_config[ec.key] }; + } + return ec; + }) : undefined, }; } @@ -436,8 +436,8 @@ const [errors, setErrors] = useState< setLocalPrefer(local.prefer ?? false); setLocalPlatform( local.encrypted_config?.model_platform || - local.provider_name || - localPlatform + local.provider_name || + localPlatform ); await handleLocalSwitch(true, local.id); } @@ -583,7 +583,7 @@ const [errors, setErrors] = useState< } }; -// removed bulk reset; only single-provider delete is supported + // removed bulk reset; only single-provider delete is supported const checkHasSearchKey = async () => { const configsRes = await proxyFetchGet("/api/configs"); @@ -630,37 +630,37 @@ const [errors, setErrors] = useState<
{t("setting.eigent-cloud-version")}
- {cloudPrefer ? ( - - ) : ( - - )} + {cloudPrefer ? ( + + ) : ( + + )}
@@ -726,20 +726,22 @@ const [errors, setErrors] = useState< {cloud_model_type === "gpt-4.1-mini" ? t("setting.gpt-4.1-mini") : cloud_model_type === "gpt-4.1" - ? t("setting.gpt-4.1") - : cloud_model_type === "claude-sonnet-4-5" - ? t("setting.claude-sonnet-4-5") - : cloud_model_type === "claude-sonnet-4-20250514" - ? t("setting.claude-sonnet-4") - : cloud_model_type === "claude-3-5-haiku-20241022" - ? t("setting.claude-3.5-haiku") - : cloud_model_type === "gemini-3-pro-preview" - ? t("setting.gemini-3-pro-preview") - : cloud_model_type === "gpt-5" - ? t("setting.gpt-5") - : cloud_model_type === "gpt-5-mini" - ? t("setting.gpt-5-mini") - : t("setting.gemini-2.5-pro")} + ? t("setting.gpt-4.1") + : cloud_model_type === "claude-sonnet-4-5" + ? t("setting.claude-sonnet-4-5") + : cloud_model_type === "claude-sonnet-4-20250514" + ? t("setting.claude-sonnet-4") + : cloud_model_type === "claude-3-5-haiku-20241022" + ? t("setting.claude-3.5-haiku") + : cloud_model_type === "gemini-3-pro-preview" + ? t("setting.gemini-3-pro-preview") + : cloud_model_type === "gpt-5" + ? t("setting.gpt-5") + : cloud_model_type === "gpt-5-mini" + ? t("setting.gpt-5-mini") + : cloud_model_type === "gemini-3-flash-preview" + ? t("setting.gemini-3-flash-preview") + : t("setting.gemini-2.5-pro")} @@ -756,6 +758,7 @@ const [errors, setErrors] = useState< Gemini 2.5 Pro Gemini 2.5 Flash Gemini 3 Pro Preview + Gemini 3 Flash Preview GPT-4.1 mini GPT-4.1 GPT-5 @@ -779,14 +782,14 @@ const [errors, setErrors] = useState<
{/* header */}
-
- - {t("setting.custom-model")} - - - {t("setting.use-your-own-api-keys-or-set-up-a-local-model")} - -
+
+ + {t("setting.custom-model")} + + + {t("setting.use-your-own-api-keys-or-set-up-a-local-model")} + +
- ) : ( - - )} + {form[idx].prefer ? ( + + ) : ( + + )}
- {item.description} -
+ {item.description} +
- {/* API Key Setting */} - : } - onBackIconClick={() => - setShowApiKey((arr) => arr.map((v, i) => (i === idx ? !v : v))) - } - value={form[idx].apiKey} - onChange={(e) => { - const v = e.target.value; - setForm((f) => - f.map((fi, i) => - i === idx ? { ...fi, apiKey: v } : fi - ) - ); - setErrors((errs) => - errs.map((er, i) => - i === idx ? { ...er, apiKey: "" } : er - ) - ); - }} - /> - {/* API Host Setting */} - : } + onBackIconClick={() => + setShowApiKey((arr) => arr.map((v, i) => (i === idx ? !v : v))) + } + value={form[idx].apiKey} + onChange={(e) => { + const v = e.target.value; + setForm((f) => + f.map((fi, i) => + i === idx ? { ...fi, apiKey: v } : fi + ) + ); + setErrors((errs) => + errs.map((er, i) => + i === idx ? { ...er, apiKey: "" } : er + ) + ); + }} + /> + {/* API Host Setting */} + { - const v = e.target.value; - setForm((f) => - f.map((fi, i) => - i === idx ? { ...fi, apiHost: v } : fi - ) - ); - setErrors((errs) => - errs.map((er, i) => - i === idx ? { ...er, apiHost: "" } : er - ) - ); - }} - /> - {/* Model Type Setting */} - { + const v = e.target.value; + setForm((f) => + f.map((fi, i) => + i === idx ? { ...fi, apiHost: v } : fi + ) + ); + setErrors((errs) => + errs.map((er, i) => + i === idx ? { ...er, apiHost: "" } : er + ) + ); + }} + /> + {/* Model Type Setting */} + { - const v = e.target.value; - setForm((f) => - f.map((fi, i) => - i === idx ? { ...fi, model_type: v } : fi - ) - ); - setErrors((errs) => - errs.map((er, i) => - i === idx ? { ...er, model_type: "" } : er - ) - ); - }} - /> - {/* externalConfig render */} + value={form[idx].model_type} + onChange={(e) => { + const v = e.target.value; + setForm((f) => + f.map((fi, i) => + i === idx ? { ...fi, model_type: v } : fi + ) + ); + setErrors((errs) => + errs.map((er, i) => + i === idx ? { ...er, model_type: "" } : er + ) + ); + }} + /> + {/* externalConfig render */} {item.externalConfig && form[idx].externalConfig && form[idx].externalConfig.map((ec, ecIdx) => ( @@ -948,14 +947,14 @@ const [errors, setErrors] = useState< f.map((fi, i) => i === idx ? { - ...fi, - externalConfig: fi.externalConfig?.map( - (eec, i2) => - i2 === ecIdx - ? { ...eec, value: v } - : eec - ), - } + ...fi, + externalConfig: fi.externalConfig?.map( + (eec, i2) => + i2 === ecIdx + ? { ...eec, value: v } + : eec + ), + } : fi ) ); @@ -985,14 +984,14 @@ const [errors, setErrors] = useState< f.map((fi, i) => i === idx ? { - ...fi, - externalConfig: fi.externalConfig?.map( - (eec, i2) => - i2 === ecIdx - ? { ...eec, value: v } - : eec - ), - } + ...fi, + externalConfig: fi.externalConfig?.map( + (eec, i2) => + i2 === ecIdx + ? { ...eec, value: v } + : eec + ), + } : fi ) ); @@ -1002,9 +1001,9 @@ const [errors, setErrors] = useState<
))} - {/* Action Button */} + {/* Action Button */}
- + diff --git a/src/store/authStore.ts b/src/store/authStore.ts index 3bdf08f5d..ca88739b5 100644 --- a/src/store/authStore.ts +++ b/src/store/authStore.ts @@ -4,7 +4,7 @@ import { persist } from 'zustand/middleware'; // type definition type InitState = 'permissions' | 'carousel' | 'done'; type ModelType = 'cloud' | 'local' | 'custom'; -type CloudModelType = 'gemini/gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-3-pro-preview' | 'gpt-4.1-mini' | 'gpt-4.1' | 'claude-sonnet-4-5' | 'claude-sonnet-4-20250514' | 'claude-3-5-haiku-20241022' | 'gpt-5' | 'gpt-5-mini'; +type CloudModelType = 'gemini/gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-3-pro-preview' | 'gemini-3-flash-preview' | 'gpt-4.1-mini' | 'gpt-4.1' | 'claude-sonnet-4-5' | 'claude-sonnet-4-20250514' | 'claude-3-5-haiku-20241022' | 'gpt-5' | 'gpt-5-mini'; // auth info interface interface AuthInfo { @@ -21,7 +21,7 @@ interface AuthState { username: string | null; email: string | null; user_id: number | null; - + // application settings appearance: string; language: string; @@ -29,21 +29,21 @@ interface AuthState { modelType: ModelType; cloud_model_type: CloudModelType; initState: InitState; - + // shared token share_token?: string | null; - + // local proxy value recorded at login localProxyValue?: string | null; - + // worker list data workerListData: { [key: string]: Agent[] }; - - // auth related methods - setAuth: (auth: AuthInfo) => void; - logout: () => void; - setLocalProxyValue: (value: string | null) => void; - + + // auth related methods + setAuth: (auth: AuthInfo) => void; + logout: () => void; + setLocalProxyValue: (value: string | null) => void; + // set related methods setAppearance: (appearance: string) => void; setLanguage: (language: string) => void; @@ -51,7 +51,7 @@ interface AuthState { setModelType: (modelType: ModelType) => void; setCloudModelType: (cloud_model_type: CloudModelType) => void; setIsFirstLaunch: (isFirstLaunch: boolean) => void; - + // worker related methods setWorkerList: (workerList: Agent[]) => void; checkAgentTool: (tool: string) => void; @@ -75,7 +75,7 @@ const authStore = create()( share_token: null, localProxyValue: null, workerListData: {}, - + // auth related methods setAuth: ({ token, username, email, user_id }) => set({ token, username, email, user_id }), @@ -89,25 +89,25 @@ const authStore = create()( initState: 'carousel', localProxyValue: null }), - + // set related methods setAppearance: (appearance) => set({ appearance }), - + setLanguage: (language) => set({ language }), - + setInitState: (initState) => { console.log('set({ initState })', initState); set({ initState }); }, - + setModelType: (modelType) => set({ modelType }), - + setCloudModelType: (cloud_model_type) => set({ cloud_model_type }), - + setIsFirstLaunch: (isFirstLaunch) => set({ isFirstLaunch }), - + setLocalProxyValue: (value) => set({ localProxyValue: value }), - + // worker related methods setWorkerList: (workerList) => { const { email } = get(); @@ -119,15 +119,15 @@ const authStore = create()( } })); }, - + checkAgentTool: (tool) => { const { email } = get(); set((state) => { const currentEmail = email as string; const originalList = state.workerListData[currentEmail] ?? []; - + console.log("tool!!!", tool); - + const updatedList = originalList .map((worker) => { const filteredTools = worker.tools?.filter((t) => t !== tool) ?? []; @@ -135,9 +135,9 @@ const authStore = create()( return { ...worker, tools: filteredTools }; }) .filter((worker) => worker.tools.length > 0); - + console.log("updatedList", updatedList); - + return { ...state, workerListData: { @@ -182,4 +182,4 @@ export const useWorkerList = (): Agent[] => { const { email, workerListData } = getAuthStore(); const workerList = workerListData[email as string]; return workerList ?? EMPTY_LIST; -}; \ No newline at end of file +};