Skip to content

Commit c3590d7

Browse files
committed
Merge branch 'main' of github.com:OpenAgentPlatform/Dive
2 parents 215782d + 7bb2900 commit c3590d7

File tree

10 files changed

+96
-14
lines changed

10 files changed

+96
-14
lines changed

src/App.tsx

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RouterProvider } from "react-router-dom"
22
import { router } from "./router"
33
import { useAtom, useAtomValue, useSetAtom } from "jotai"
44
import { removeOapConfigAtom, writeOapConfigAtom } from "./atoms/configState"
5-
import { useEffect } from "react"
5+
import { useEffect, useRef, useState } from "react"
66
import { handleGlobalHotkey } from "./atoms/hotkeyState"
77
import { handleWindowResizeAtom } from "./atoms/sidebarState"
88
import { systemThemeAtom } from "./atoms/themeState"
@@ -16,8 +16,11 @@ import { setModelSettings } from "./ipc/config"
1616
import { oapGetMe, oapGetToken, oapLogout, registBackendEvent } from "./ipc"
1717
import { refreshConfig } from "./ipc/host"
1818
import { openOverlayAtom } from "./atoms/layerState"
19+
import PopupConfirm from "./components/PopupConfirm"
1920

2021
function App() {
22+
const { t } = useTranslation()
23+
2124
const setSystemTheme = useSetAtom(systemThemeAtom)
2225
const handleWindowResize = useSetAtom(handleWindowResizeAtom)
2326
const setOAPUser = useSetAtom(oapUserAtom)
@@ -32,7 +35,10 @@ function App() {
3235
const loadMcpConfig = useSetAtom(loadMcpConfigAtom)
3336
const loadOapTools = useSetAtom(loadOapToolsAtom)
3437
const openOverlay = useSetAtom(openOverlayAtom)
38+
3539
const setInstallToolBuffer = useSetAtom(installToolBufferAtom)
40+
const installToolBuffer = useRef<{ name: string, config: any } | null>(null)
41+
const [installToolConfirm, setInstallToolConfirm] = useState(false)
3642

3743
useEffect(() => {
3844
console.log("set model setting", modelSetting)
@@ -67,6 +73,21 @@ function App() {
6773
}
6874
}
6975

76+
const openToolPageWithMcpServerJson = (data?: { name: string, config: any }) => {
77+
if (!data && !installToolBuffer.current) {
78+
return
79+
}
80+
81+
try {
82+
data = data || installToolBuffer.current!
83+
const { name, config } = data
84+
setInstallToolBuffer(prev => [...prev, { name, config }])
85+
openOverlay("Tools")
86+
} catch(e) {
87+
console.error("mcp install error", e)
88+
}
89+
}
90+
7091
// handle backend event
7192
useEffect(() => {
7293
const unregistLogin = registBackendEvent("login", () => {
@@ -100,15 +121,18 @@ function App() {
100121
})
101122

102123
const unlistenMcpInstall = registBackendEvent("mcp.install", (data: { name: string, config: string }) => {
103-
try {
104-
const { name } = data
105-
const config = JSON.parse(atob(data.config))
106-
console.log(config)
107-
setInstallToolBuffer(prev => [...prev, { name, config }])
108-
openOverlay("Tools")
109-
} catch(e) {
110-
console.error("oap mcp install error", e)
124+
const _config = JSON.parse(atob(data.config))
125+
if (!_config.transport) {
126+
return
111127
}
128+
129+
if (_config.transport === "stdio") {
130+
setInstallToolConfirm(true)
131+
installToolBuffer.current = { name: data.name, config: _config }
132+
return
133+
}
134+
135+
openToolPageWithMcpServerJson({ name: data.name, config: _config })
112136
})
113137

114138
return () => {
@@ -161,10 +185,35 @@ function App() {
161185
document.documentElement.lang = langCode
162186
}, [i18n.language])
163187

188+
const closeInstallTool = () => {
189+
setInstallToolConfirm(false)
190+
installToolBuffer.current = null
191+
}
192+
164193
return (
165194
<>
166195
<RouterProvider router={router} />
167196
<Updater />
197+
198+
{installToolConfirm &&
199+
<PopupConfirm
200+
confirmText={t("common.confirm")}
201+
cancelText={t("common.cancel")}
202+
onConfirm={() => {
203+
openToolPageWithMcpServerJson()
204+
closeInstallTool()
205+
}}
206+
onCancel={closeInstallTool}
207+
onClickOutside={closeInstallTool}
208+
noBorder
209+
footerType="center"
210+
zIndex={1000}
211+
className="mcp-install-confirm-modal"
212+
>
213+
{t("deeplink.mcpInstallConfirm")}
214+
<pre>{installToolBuffer.current!.config.command} {installToolBuffer.current!.config.args.join(" ")}</pre>
215+
</PopupConfirm>
216+
}
168217
</>
169218
)
170219
}

src/helper/model.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ModelConfig, ModelConfigMap, ModelParameter, RawModelConfig } from "../
33
import { defaultInterface } from "../atoms/interfaceState"
44
import isMatch from "lodash/isMatch"
55
import merge from "lodash/merge"
6-
import { getVerifyKeyFromModelConfig } from "./verify"
6+
import { getVerifyKey, getVerifyKeyFromModelConfig } from "./verify"
77
import { getVerifyStatus } from "../views/Overlay/Model/ModelVerify"
88

99
export type GroupTerm = Partial<Omit<LLMGroup, "models">>
@@ -267,13 +267,24 @@ export function getGroupAndModel(groupTerm: GroupTerm, modelTerm: ModelTerm, gro
267267
export function intoModelConfig(group: LLMGroup, model: BaseModel): ModelConfig {
268268
// eslint-disable-next-line @typescript-eslint/no-unused-vars
269269
const { active, models, extra, custom, baseURL, apiKey, ...baseConfig } = group
270-
const { disableStreaming, toolsInPrompt, extra: modelExtra, custom: modelCustom, model: modelName } = model
270+
const { disableStreaming, extra: modelExtra, custom: modelCustom, model: modelName } = model
271+
272+
const allVerifiedList: Record<string, any> = JSON.parse(localStorage.getItem("modelVerify") || "{}")
273+
const status = getVerifyStatus(allVerifiedList?.[getVerifyKey(group)][modelName] ?? null)
271274

272275
const modelConfig = baseConfig as unknown as ModelConfig
273276
modelConfig.disable_streaming = disableStreaming
274-
modelConfig.toolsInPrompt = toolsInPrompt
277+
modelConfig.toolsInPrompt = status === "successInPrompt"
275278
modelConfig.model = modelName
276-
modelConfig.modelProvider = group.modelProvider === "openai_compatible" ? "openai" : group.modelProvider
279+
modelConfig.modelProvider = [
280+
"openai_compatible",
281+
"lmstudio",
282+
"openrouter",
283+
"groq",
284+
"grok",
285+
"nvdia",
286+
"perplexity",
287+
].includes(group.modelProvider) ? "openai" : group.modelProvider
277288

278289
if (apiKey) {
279290
modelConfig.apiKey = apiKey

src/locales/en/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,8 @@
406406
"retry": "Retry",
407407
"stop": "Stop",
408408
"tip": "If an error occurs during download, please close this window first and restart the application to re-download."
409+
},
410+
"deeplink": {
411+
"mcpInstallConfirm": "Add stdio MCP Service - You will add MCP via the following command, please confirm:"
409412
}
410413
}

src/locales/es/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,8 @@
406406
"retry": "Reintentar",
407407
"stop": "Detener",
408408
"tip": "Si ocurre un error durante la descarga, cierre primero esta ventana y reinicie la aplicación para volver a descargar."
409+
},
410+
"deeplink": {
411+
"mcpInstallConfirm": "Agregar servicio stdio MCP - Agregarás MCP mediante el siguiente comando, por favor confirma:"
409412
}
410413
}

src/locales/ja/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,8 @@
406406
"retry": "再試行",
407407
"stop": "停止",
408408
"tip": "ダウンロード中にエラーが発生した場合は、まずこのウィンドウを閉じてアプリケーションを再起動すると、再ダウンロードできます。"
409+
},
410+
"deeplink": {
411+
"mcpInstallConfirm": "stdio MCP サービスを追加 - 以下のコマンドで MCP を追加します。確認してください:"
409412
}
410413
}

src/locales/ko/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,8 @@
406406
"retry": "다시 시도",
407407
"stop": "중지",
408408
"tip": "다운로드 중 오류가 발생하면 이 창을 닫고 애플리케이션을 다시 시작하여 다시 시도하세요."
409+
},
410+
"deeplink": {
411+
"mcpInstallConfirm": "stdio MCP 서비스 추가 - 다음 명령을 통해 MCP를 추가합니다. 확인하세요:"
409412
}
410413
}

src/locales/zh-CN/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,8 @@
406406
"retry": "重新尝试",
407407
"stop": "停止",
408408
"tip": "下载发生错误时,请先关闭此窗口,重新启动应用程序即可重新下载。"
409+
},
410+
"deeplink": {
411+
"mcpInstallConfirm": "新增 stdio MCP 服务 - 你将会通过下列命令新增 MCP,请确认:"
409412
}
410413
}

src/locales/zh-TW/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,8 @@
406406
"retry": "重新嘗試",
407407
"stop": "停止",
408408
"tip": "下載發生錯誤時,請先關閉此視窗,重新啟動應用程式即可重新下載。"
409+
},
410+
"deeplink": {
411+
"mcpInstallConfirm": "新增 stdio MCP 服務 - 你將會透過下列命令新增 MCP, 請確認: "
409412
}
410413
}

src/styles/components/_HistorySidebar.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,8 @@
408408
}
409409
}
410410
}
411+
412+
&.mcp-install-confirm-modal {
413+
padding: 15px;
414+
}
411415
}

0 commit comments

Comments
 (0)