import type { AgentConfig } from '../agent/agent'; import type { FrameworkConfig } from '../config/types'; export type VariableValue = string | number | boolean; type TemplateConfigContext = { defaultSystemMessage?: string; agentDirs?: string[]; }; type AgentTemplateContext = { id: string; model: string; platform: string; temperature?: number; maxTokens?: number; }; export type FrontmatterContext = { vars: Record; env: Record; config: TemplateConfigContext; }; export type BodyContext = FrontmatterContext & { agent: AgentTemplateContext; } & Record; const buildConfigNamespace = (fredConfig: Partial): TemplateConfigContext => ({ defaultSystemMessage: fredConfig.defaultSystemMessage, agentDirs: fredConfig.agentDirs ? [...fredConfig.agentDirs] : undefined, }); export const buildFrontmatterContext = ( globalVars: Record, filteredEnv: Record, fredConfig: Partial ): FrontmatterContext => ({ vars: { ...globalVars }, env: { ...filteredEnv }, config: buildConfigNamespace(fredConfig), }); export const buildBodyContext = ( globalVars: Record, filteredEnv: Record, agentConfig: Pick, fredConfig: Partial, customNamespaces: Record = {} ): BodyContext => ({ vars: { ...globalVars }, env: { ...filteredEnv }, config: buildConfigNamespace(fredConfig), agent: { id: agentConfig.id, model: agentConfig.model, platform: agentConfig.platform, temperature: agentConfig.temperature, maxTokens: agentConfig.maxTokens, }, ...customNamespaces, });