mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 6: Phase 6: Config.Info validation owner and v2 config types in
This commit is contained in:
1 parent
66b5d1ac06
commit
48ca38c4e3
16 files changed
+232
-79
No files matched your search
@@ -18,11 +18,13 @@
|
||||
"./notifications": "./src/notifications/index.ts",
|
||||
"./project-id": "./src/project-id-resolver.ts",
|
||||
"./opencode": "./src/opencode/index.ts",
|
||||
"./opencode/config-validation": "./src/opencode/config-validation.ts",
|
||||
"./themes": "./src/themes/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opencode/client": "2.2.1",
|
||||
"@opencode/schema": "2.2.1",
|
||||
"effect": "4.0.1",
|
||||
"jsonc-parser": "^3.3.1",
|
||||
"zod": "^4.1.12"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Info } from '@opencode/schema/config'
|
||||
import { Schema } from 'effect'
|
||||
|
||||
export interface OpenCodeConfigValidationIssue {
|
||||
path: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export type OpenCodeConfigValidationResult =
|
||||
| { success: true }
|
||||
| { success: false; issues: OpenCodeConfigValidationIssue[] }
|
||||
|
||||
const standardSchema = Schema.toStandardSchemaV1(Info, {
|
||||
parseOptions: { errors: 'all', onExcessProperty: 'ignore' },
|
||||
})
|
||||
|
||||
function toIssuePath(path: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }> | undefined): string {
|
||||
if (!path || path.length === 0) return 'root'
|
||||
return path
|
||||
.map((segment) => String(typeof segment === 'object' ? segment.key : segment))
|
||||
.join('.')
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a parsed OpenCode config document against the v2 `Config.Info` schema, ignoring
|
||||
* unknown keys so v1-only fields in existing files stay loadable.
|
||||
*/
|
||||
export function validateOpenCodeConfig(value: unknown): OpenCodeConfigValidationResult {
|
||||
const result = standardSchema['~standard'].validate(value)
|
||||
if (result instanceof Promise) {
|
||||
throw new Error('OpenCode config validation must be synchronous')
|
||||
}
|
||||
if (!result.issues) return { success: true }
|
||||
return {
|
||||
success: false,
|
||||
issues: result.issues.map((issue) => ({
|
||||
path: toIssuePath(issue.path),
|
||||
message: issue.message,
|
||||
})),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { ConfigEntry } from '@opencode/client'
|
||||
|
||||
export type OpenCodeConfigInfo = Extract<ConfigEntry, { type: 'document' }>['info']
|
||||
|
||||
export type OpenCodeAgentConfig = NonNullable<OpenCodeConfigInfo['agents']>[string]
|
||||
|
||||
export type OpenCodeCommandConfig = NonNullable<OpenCodeConfigInfo['commands']>[string]
|
||||
|
||||
export type OpenCodeProviderConfig = NonNullable<OpenCodeConfigInfo['providers']>[string]
|
||||
|
||||
export type OpenCodeProviderModelConfig = NonNullable<OpenCodeProviderConfig['models']>[string]
|
||||
|
||||
export type OpenCodePermissionRule = NonNullable<OpenCodeConfigInfo['permissions']>[number]
|
||||
@@ -22,6 +22,7 @@ export type {
|
||||
ModelInfo,
|
||||
ModelRef,
|
||||
PermissionRequest,
|
||||
PermissionReply,
|
||||
PromptAgentAttachment,
|
||||
PromptFileAttachment,
|
||||
PromptMention,
|
||||
@@ -51,6 +52,15 @@ export { ClientError, isIntegrationNotFoundError, isMcpServerNotFoundError, isSe
|
||||
|
||||
export { assistantText, sessionIDFromEvent, toolContentText } from './content'
|
||||
|
||||
export type {
|
||||
OpenCodeAgentConfig,
|
||||
OpenCodeCommandConfig,
|
||||
OpenCodeConfigInfo,
|
||||
OpenCodePermissionRule,
|
||||
OpenCodeProviderConfig,
|
||||
OpenCodeProviderModelConfig,
|
||||
} from './config'
|
||||
|
||||
export {
|
||||
GOAL_CHANGED_EVENT_TYPE,
|
||||
GOAL_COMMAND_NAME,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { ConfigEntry, McpServer } from '@opencode/client'
|
||||
import type { McpServer } from '@opencode/client'
|
||||
import type { OpenCodeConfigInfo } from './config'
|
||||
import { isRecord } from '../utils/record'
|
||||
|
||||
export const MCP_OAUTH_CALLBACK_PATH = '/api/mcp-oauth-proxy/callback'
|
||||
|
||||
type ConfigDocumentInfo = Extract<ConfigEntry, { type: 'document' }>['info']
|
||||
|
||||
type McpConfig = NonNullable<ConfigDocumentInfo['mcp']>
|
||||
type McpConfig = NonNullable<OpenCodeConfigInfo['mcp']>
|
||||
|
||||
export type McpServerConfig = NonNullable<McpConfig['servers']>[string]
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ConfigEntry, ModelRef } from '@opencode/client'
|
||||
import type { OpenCodeConfigInfo } from './config'
|
||||
|
||||
type ConfigDocumentModel = Extract<ConfigEntry, { type: 'document' }>['info']['model']
|
||||
type ConfigDocumentModel = OpenCodeConfigInfo['model']
|
||||
|
||||
export function parseOpenCodeModelRef(model: string): ModelRef | undefined {
|
||||
const providerEnd = model.indexOf('/')
|
||||
|
||||
Reference in new issue
Block a user