mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(opencode): migrate OpenCode Manager to OpenCode 2 (#359)
* feat(opencode): migrate OpenCode Manager to OpenCode 2 Port the backend lifecycle, generated plugins, event aggregation, schedules, worktrees, provider credentials, MCP, config handling, the frontend chat model, and the ocm CLI to OpenCode 2. Adopt @opencode/client 2.0.15 as the single typed V2 API contract, require OpenCode 2.0.0 or newer (pinned 2.0.15), and delete every V1-only code path. * refactor(opencode): reload config in place and drop v1 compatibility shims Route config/skill/AGENTS.md changes through the OpenCode location reload API instead of a full server restart, stop auto-resuming interrupted sessions, remove the restart coordinator and v1 MCP/version shims, and pin support to OpenCode >=2.0.15 <3.0.0. Adds integration-ready retries, service-mode launch, ocm-cli repo proxy, and new frontend form/MCP helpers. * refactor(opencode): consolidate v2 migration helpers and harden install, proxy, and session flows - extract shared semver and model-ref utilities, reuse across version checks - share the OpenCode release download script across Docker, entrypoint, dev setup - unify install/upgrade failure recovery and guard externally managed OPENCODE_BIN - scope the repo proxy location rewrite and surface ocm proxy errors - rework frontend session projection, permission lookup, and cache invalidation * fix(schedules): reject unavailable agents before creating a session * feat(opencode): add ocm install, schedule agent fallback, and session move guards
This commit is contained in:
1 parent
6c2ebd764b
commit
dacde879d6
383 files changed
+29905
-46566
No files matched your search
@@ -8,6 +8,11 @@ import { Loader2 } from 'lucide-react'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { useMcpServers } from '@/hooks/useMcpServers'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import {
|
||||
mcpOAuthRedirectUri,
|
||||
type McpServerConfig,
|
||||
type McpTimeoutConfig,
|
||||
} from '@opencode-manager/shared/opencode'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
|
||||
interface AddMcpServerDialogProps {
|
||||
@@ -37,90 +42,75 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
|
||||
const queryClient = useQueryClient()
|
||||
const { addServerAsync, isAddingServer } = useMcpServers()
|
||||
|
||||
const buildTimeout = (): McpTimeoutConfig | undefined => {
|
||||
const parsed = parseInt(timeout)
|
||||
return Number.isFinite(parsed) ? { catalog: parsed, execution: parsed } : undefined
|
||||
}
|
||||
|
||||
const buildMcpServerConfig = (): McpServerConfig => {
|
||||
const timeoutConfig = buildTimeout()
|
||||
const shared = {
|
||||
disabled: !enabled,
|
||||
...(timeoutConfig ? { timeout: timeoutConfig } : {}),
|
||||
}
|
||||
|
||||
if (serverType === 'local') {
|
||||
const commandArray = command.split(' ').filter((arg) => arg.trim())
|
||||
if (commandArray.length === 0) {
|
||||
throw new Error('Command is required for local MCP servers')
|
||||
}
|
||||
|
||||
const environmentVariables = Object.fromEntries(
|
||||
environment
|
||||
.filter((env) => env.key.trim() && env.value.trim())
|
||||
.map((env) => [env.key.trim(), env.value.trim()]),
|
||||
)
|
||||
|
||||
return {
|
||||
type: 'local',
|
||||
command: commandArray,
|
||||
...(Object.keys(environmentVariables).length > 0 ? { environment: environmentVariables } : {}),
|
||||
...shared,
|
||||
}
|
||||
}
|
||||
|
||||
if (!url.trim()) {
|
||||
throw new Error('URL is required for remote MCP servers')
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'remote',
|
||||
url: url.trim(),
|
||||
...(oauthEnabled
|
||||
? {
|
||||
oauth: {
|
||||
...(oauthClientId.trim() ? { client_id: oauthClientId.trim() } : {}),
|
||||
...(oauthClientSecret.trim() ? { client_secret: oauthClientSecret.trim() } : {}),
|
||||
...(oauthScope.trim() ? { scope: oauthScope.trim() } : {}),
|
||||
redirect_uri: mcpOAuthRedirectUri(window.location.origin),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...shared,
|
||||
}
|
||||
}
|
||||
|
||||
const addMcpServerMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
const config = await settingsApi.getOpenCodeConfig()
|
||||
const currentMcp = (config.content.mcp as Record<string, unknown>) || {}
|
||||
|
||||
const mcpConfig: Record<string, unknown> = {
|
||||
type: serverType,
|
||||
enabled,
|
||||
}
|
||||
const mcpServerConfig = buildMcpServerConfig()
|
||||
const mcp = (config.content.mcp as Record<string, unknown> | undefined) ?? {}
|
||||
|
||||
if (serverType === 'local') {
|
||||
const commandArray = command.split(' ').filter(arg => arg.trim())
|
||||
if (commandArray.length === 0) {
|
||||
throw new Error('Command is required for local MCP servers')
|
||||
}
|
||||
mcpConfig.command = commandArray
|
||||
|
||||
const envVars: Record<string, string> = {}
|
||||
environment.forEach(env => {
|
||||
if (env.key.trim() && env.value.trim()) {
|
||||
envVars[env.key.trim()] = env.value.trim()
|
||||
}
|
||||
})
|
||||
if (Object.keys(envVars).length > 0) {
|
||||
mcpConfig.environment = envVars
|
||||
}
|
||||
} else {
|
||||
if (!url.trim()) {
|
||||
throw new Error('URL is required for remote MCP servers')
|
||||
}
|
||||
mcpConfig.url = url.trim()
|
||||
|
||||
if (oauthEnabled) {
|
||||
const oauthConfig: Record<string, string> = {}
|
||||
if (oauthClientId.trim()) oauthConfig.clientId = oauthClientId.trim()
|
||||
if (oauthClientSecret.trim()) oauthConfig.clientSecret = oauthClientSecret.trim()
|
||||
if (oauthScope.trim()) oauthConfig.scope = oauthScope.trim()
|
||||
mcpConfig.oauth = Object.keys(oauthConfig).length > 0 ? oauthConfig : true
|
||||
}
|
||||
}
|
||||
|
||||
if (timeout && parseInt(timeout)) {
|
||||
mcpConfig.timeout = parseInt(timeout)
|
||||
}
|
||||
|
||||
const updatedConfig = {
|
||||
await onUpdate({
|
||||
...config.content,
|
||||
mcp: {
|
||||
...currentMcp,
|
||||
[serverId]: mcpConfig,
|
||||
...mcp,
|
||||
servers: { ...(mcp.servers as Record<string, unknown> | undefined), [serverId]: mcpServerConfig },
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
await onUpdate(updatedConfig)
|
||||
|
||||
if (enabled) {
|
||||
const buildOauthField = () => {
|
||||
if (serverType !== 'remote' || !oauthEnabled) return undefined
|
||||
const cfg: Record<string, string> = {}
|
||||
if (oauthClientId.trim()) cfg.clientId = oauthClientId.trim()
|
||||
if (oauthClientSecret.trim()) cfg.clientSecret = oauthClientSecret.trim()
|
||||
if (oauthScope.trim()) cfg.scope = oauthScope.trim()
|
||||
return Object.keys(cfg).length > 0 ? cfg : true
|
||||
}
|
||||
|
||||
await addServerAsync({
|
||||
name: serverId,
|
||||
config: {
|
||||
type: serverType,
|
||||
enabled,
|
||||
command: serverType === 'local' ? command.split(' ').filter(arg => arg.trim()) : undefined,
|
||||
url: serverType === 'remote' ? url.trim() : undefined,
|
||||
environment: serverType === 'local' && Object.keys(environment).length > 0
|
||||
? environment.reduce((acc, env) => {
|
||||
if (env.key.trim() && env.value.trim()) {
|
||||
acc[env.key.trim()] = env.value.trim()
|
||||
}
|
||||
return acc
|
||||
}, {} as Record<string, string>)
|
||||
: undefined,
|
||||
timeout: timeout && parseInt(timeout) ? parseInt(timeout) : undefined,
|
||||
oauth: buildOauthField(),
|
||||
}
|
||||
})
|
||||
await addServerAsync({ name: serverId, config: mcpServerConfig })
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
@@ -339,7 +329,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
|
||||
className="bg-background border-border"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Timeout in milliseconds for fetching tools (default: 5000)
|
||||
Timeout in milliseconds for listing and calling tools
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user