2026-02-08 13:57:26 +09:00
|
|
|
import type { AgentConfig } from "@opencode-ai/sdk"
|
|
|
|
|
import type { AgentFactory } from "./types"
|
2026-04-27 17:18:37 +09:00
|
|
|
import type { CategoriesConfig, CategoryConfig } from "../config/schema"
|
2026-02-11 13:52:06 +09:00
|
|
|
import { mergeCategories } from "../shared/merge-categories"
|
2026-02-08 13:57:26 +09:00
|
|
|
|
|
|
|
|
export type AgentSource = AgentFactory | AgentConfig
|
|
|
|
|
|
|
|
|
|
export function isFactory(source: AgentSource): source is AgentFactory {
|
|
|
|
|
return typeof source === "function"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function buildAgent(
|
|
|
|
|
source: AgentSource,
|
|
|
|
|
model: string,
|
2026-04-27 17:18:37 +09:00
|
|
|
categories?: CategoriesConfig
|
2026-02-08 13:57:26 +09:00
|
|
|
): AgentConfig {
|
2026-02-08 15:31:32 +09:00
|
|
|
const base = isFactory(source) ? source(model) : { ...source }
|
2026-02-11 13:52:06 +09:00
|
|
|
const categoryConfigs: Record<string, CategoryConfig> = mergeCategories(categories)
|
2026-02-08 13:57:26 +09:00
|
|
|
|
|
|
|
|
const agentWithCategory = base as AgentConfig & { category?: string; skills?: string[]; variant?: string }
|
|
|
|
|
if (agentWithCategory.category) {
|
|
|
|
|
const categoryConfig = categoryConfigs[agentWithCategory.category]
|
|
|
|
|
if (categoryConfig) {
|
|
|
|
|
if (!base.model) {
|
|
|
|
|
base.model = categoryConfig.model
|
|
|
|
|
}
|
|
|
|
|
if (base.temperature === undefined && categoryConfig.temperature !== undefined) {
|
|
|
|
|
base.temperature = categoryConfig.temperature
|
|
|
|
|
}
|
|
|
|
|
if (base.variant === undefined && categoryConfig.variant !== undefined) {
|
|
|
|
|
base.variant = categoryConfig.variant
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 16:18:41 +02:00
|
|
|
if (isFactory(source) && (base as AgentConfig & { mode?: string }).mode === undefined) {
|
|
|
|
|
;(base as AgentConfig & { mode?: string }).mode = source.mode
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-08 13:57:26 +09:00
|
|
|
return base
|
|
|
|
|
}
|