feat(opencode-config): redact secrets and add MCP listing to the internal config API (#366)

This commit is contained in:
Chris Scott authored and GitHub committed 2026-09-28 23:52:41 -04:00
1 parent 68b13c8e35
commit a1b7f58aae
31 files changed
+1238 -181

No files matched your search

+2
View File
@@ -53,12 +53,14 @@ export { formatOpenCodeModelRef, parseOpenCodeModelRef } from './modelRef'
export {
MCP_OAUTH_CALLBACK_PATH,
mcpOAuthRedirectUri,
mcpServerViewsFromConfig,
mcpServersFromConfig,
mcpStatusByName,
} from './mcp'
export type {
McpServerConfig,
McpServerView,
McpStatus,
McpStatusMap,
McpTimeoutConfig,
+39
View File
@@ -31,6 +31,45 @@ export function mcpServersFromConfig(mcp: unknown): Record<string, McpServerConf
return Object.fromEntries(Object.entries(mcp.servers).filter((entry): entry is [string, McpServerConfig] => isMcpServerConfig(entry[1])))
}
export type McpServerShape = 'servers' | 'legacy'
export interface McpServerView {
name: string
type: 'local' | 'remote'
command?: string[]
url?: string
enabled: boolean
shape: McpServerShape
}
function toMcpServerView(
name: string,
config: McpServerConfig,
enabled: boolean,
shape: McpServerShape,
): McpServerView {
return {
name,
type: config.type,
...(config.type === 'local' ? { command: config.command } : { url: config.url }),
enabled,
shape,
}
}
export function mcpServerViewsFromConfig(mcp: unknown): McpServerView[] {
if (!isRecord(mcp)) return []
const nativeViews = Object.entries(mcpServersFromConfig(mcp)).map(([name, config]) =>
toMcpServerView(name, config, config.disabled !== true, 'servers'),
)
const legacyViews = Object.entries(mcp).flatMap(([name, value]) => {
if (name === 'servers' || name === 'timeout' || !isMcpServerConfig(value)) return []
const enabled = (value as { enabled?: unknown }).enabled !== false
return [toMcpServerView(name, value, enabled, 'legacy')]
})
return [...nativeViews, ...legacyViews].sort((left, right) => left.name.localeCompare(right.name))
}
export function mcpStatusByName(servers: McpServer[]): McpStatusMap {
return Object.fromEntries(
servers.map((server) => [
+7
View File
@@ -422,3 +422,10 @@ export const UpdateOpenCodeConfigRequestSchema = z.object({
source: OpenCodeConfigSourceNameSchema.optional(),
expectedRevision: z.string().optional(),
});
export const UpdateOpenCodeConfigPatchRequestSchema = z.object({
patch: z.record(z.string(), z.unknown()),
source: OpenCodeConfigSourceNameSchema.optional(),
expectedRevision: z.string().optional(),
});