Purpose: Template method pattern for AI tool adapters
Last Updated: 2026-02-04
Template Method: BaseAdapter defines algorithm structure, subclasses implement tool-specific details
export abstract class BaseAdapter {
abstract name: string
abstract displayName: string
// Must implement
abstract toOAC(source: string): Promise<OpenAgent>
abstract fromOAC(agent: OpenAgent): Promise<ConversionResult>
abstract getConfigPath(): string
abstract getCapabilities(): ToolCapabilities
abstract validateConversion(agent: OpenAgent): string[]
// Shared utilities
supportsFeature(feature: keyof ToolCapabilities): boolean
warn(message: string): void
createSuccessResult(configs, warnings): ConversionResult
safeParseJSON(content, filename): unknown | null
unsupportedFeatureWarning(feature, value): string
degradedFeatureWarning(feature, from, to): string
}
export class WindsurfAdapter extends BaseAdapter {
name = 'windsurf'
displayName = 'Windsurf'
async toOAC(source: string): Promise<OpenAgent> {
const config = this.safeParseJSON(source, 'config.json')
return {
frontmatter: {
name: config.name,
model: this.mapWindsurfModelToOAC(config.model),
tools: this.parseWindsurfTools(config.tools),
temperature: this.mapCreativityToTemperature(config.creativity)
},
systemPrompt: config.systemPrompt,
contexts: []
}
}
async fromOAC(agent: OpenAgent): Promise<ConversionResult> {
const warnings: string[] = []
// Warn on unsupported features
if (agent.frontmatter.hooks) {
warnings.push(this.unsupportedFeatureWarning('hooks', 'lost'))
}
const config = {
name: agent.frontmatter.name,
model: this.mapOACModelToWindsurf(agent.frontmatter.model),
creativity: this.mapTemperatureToCreativity(agent.frontmatter.temperature)
}
return this.createSuccessResult([
{ fileName: '.windsurf/config.json', content: JSON.stringify(config) }
], warnings)
}
getCapabilities(): ToolCapabilities {
return {
supportsMultipleAgents: true,
supportsHooks: false,
supportsTemperature: true // via creativity
}
}
}
Parse tool format → OpenAgent object
Convert OpenAgent → tool format
Declare supported features (used for validation)
// Safe parsing
const config = this.safeParseJSON(content, 'config.json')
// Feature checks
if (this.supportsFeature('supportsTemperature')) {
config.temperature = agent.frontmatter.temperature
}
// Warnings
if (!this.supportsFeature('supportsHooks')) {
warnings.push(this.unsupportedFeatureWarning('hooks'))
}
// Results
return this.createSuccessResult([{ fileName, content }], warnings)
Implementation: packages/compatibility-layer/src/adapters/BaseAdapter.ts
Concrete Adapters:
Related: