1+ import React , { ReactNode } from "react"
2+ import { AgentProvider , AgentProviderProps } from "@/lib/agent-context"
3+ import { Agent } from "@/lib/config"
4+ import { getRecommendedAgents } from "@/lib/agent-utils"
5+
6+ /**
7+ * Configuration interface for setting up the agent management system
8+ * This provides a simple, declarative way to configure agents in your application
9+ */
10+
11+ // Main configuration interface
12+ export interface AgentConfig {
13+ /** Initial agents to load */
14+ agents ?: Agent [ ]
15+ /** Whether to persist agents to localStorage */
16+ persistToLocalStorage ?: boolean
17+ /** Whether to load recommended agents if no agents are configured */
18+ useRecommendedAgents ?: boolean
19+ /** Custom agent provider props */
20+ providerProps ?: Partial < AgentProviderProps >
21+ }
22+
23+ // Props for the main configuration component
24+ export interface AgentConfigProviderProps extends AgentConfig {
25+ children : ReactNode
26+ }
27+
28+ /**
29+ * Main configuration component that sets up the agent management system
30+ * This is the recommended way to configure agents in your application
31+ */
32+ export function AgentConfigProvider ( {
33+ children,
34+ agents,
35+ persistToLocalStorage = true ,
36+ useRecommendedAgents = true ,
37+ providerProps = { } ,
38+ } : AgentConfigProviderProps ) {
39+ // Determine which agents to use
40+ let initialAgents : Agent [ ]
41+
42+ if ( agents && agents . length > 0 ) {
43+ // Use provided agents
44+ initialAgents = agents
45+ } else if ( useRecommendedAgents ) {
46+ // Use recommended agents
47+ initialAgents = getRecommendedAgents ( )
48+ } else {
49+ // Use default agent only
50+ initialAgents = [ ]
51+ }
52+
53+ return (
54+ < AgentProvider
55+ initialAgents = { initialAgents }
56+ persistToLocalStorage = { persistToLocalStorage }
57+ { ...providerProps }
58+ >
59+ { children }
60+ </ AgentProvider >
61+ )
62+ }
63+
64+ /**
65+ * Pre-configured agent setups for common scenarios
66+ */
67+
68+ // Development environment configuration
69+ export function DevelopmentAgentConfig ( { children } : { children : ReactNode } ) {
70+ return (
71+ < AgentConfigProvider
72+ agents = { [
73+ {
74+ id : "dev-local" ,
75+ name : "Local Development" ,
76+ url : "http://localhost:8787" ,
77+ } ,
78+ {
79+ id : "dev-docker" ,
80+ name : "Docker Development" ,
81+ url : "http://localhost:3000" ,
82+ } ,
83+ ] }
84+ persistToLocalStorage = { true }
85+ useRecommendedAgents = { false }
86+ >
87+ { children }
88+ </ AgentConfigProvider >
89+ )
90+ }
91+
92+ // Production environment configuration
93+ export function ProductionAgentConfig ( { children } : { children : ReactNode } ) {
94+ return (
95+ < AgentConfigProvider
96+ agents = { [
97+ {
98+ id : "prod-primary" ,
99+ name : "Primary Agent" ,
100+ url : "https://your-agent.your-domain.com" ,
101+ } ,
102+ {
103+ id : "prod-backup" ,
104+ name : "Backup Agent" ,
105+ url : "https://backup-agent.your-domain.com" ,
106+ } ,
107+ ] }
108+ persistToLocalStorage = { true }
109+ useRecommendedAgents = { false }
110+ >
111+ { children }
112+ </ AgentConfigProvider >
113+ )
114+ }
115+
116+ // Minimal configuration (just the default agent)
117+ export function MinimalAgentConfig ( { children } : { children : ReactNode } ) {
118+ return (
119+ < AgentConfigProvider
120+ agents = { [ ] }
121+ persistToLocalStorage = { false }
122+ useRecommendedAgents = { false }
123+ >
124+ { children }
125+ </ AgentConfigProvider >
126+ )
127+ }
128+
129+ // Configuration with only recommended agents
130+ export function RecommendedAgentConfig ( { children } : { children : ReactNode } ) {
131+ return (
132+ < AgentConfigProvider
133+ persistToLocalStorage = { true }
134+ useRecommendedAgents = { true }
135+ >
136+ { children }
137+ </ AgentConfigProvider >
138+ )
139+ }
140+
141+ // Testing configuration (no persistence)
142+ export function TestingAgentConfig ( { children } : { children : ReactNode } ) {
143+ return (
144+ < AgentConfigProvider
145+ agents = { [
146+ {
147+ id : "test-agent" ,
148+ name : "Test Agent" ,
149+ url : "http://localhost:9999" ,
150+ } ,
151+ ] }
152+ persistToLocalStorage = { false }
153+ useRecommendedAgents = { false }
154+ >
155+ { children }
156+ </ AgentConfigProvider >
157+ )
158+ }
159+
160+ /**
161+ * Hook for accessing agent configuration
162+ * This can be used to get configuration values in components
163+ */
164+ export function useAgentConfig ( ) {
165+ // For now, this just returns default values
166+ // In the future, this could read from a configuration context or settings
167+ return {
168+ maxAgents : 10 ,
169+ healthCheckInterval : 30000 , // 30 seconds
170+ connectionTimeout : 5000 , // 5 seconds
171+ enableAutoRefresh : true ,
172+ enableNotifications : true ,
173+ }
174+ }
175+
176+ /**
177+ * Utility functions for configuration management
178+ */
179+
180+ // Create a configuration from environment variables
181+ export function createConfigFromEnv ( ) : AgentConfig {
182+ const envAgents = process . env . NEXT_PUBLIC_AGENTS
183+ ? JSON . parse ( process . env . NEXT_PUBLIC_AGENTS )
184+ : undefined
185+
186+ return {
187+ agents : envAgents ,
188+ persistToLocalStorage : process . env . NEXT_PUBLIC_PERSIST_AGENTS !== "false" ,
189+ useRecommendedAgents : process . env . NEXT_PUBLIC_USE_RECOMMENDED_AGENTS !== "false" ,
190+ }
191+ }
192+
193+ // Validate configuration
194+ export function validateAgentConfig ( config : AgentConfig ) : { isValid : boolean ; errors : string [ ] } {
195+ const errors : string [ ] = [ ]
196+
197+ if ( config . agents && ! Array . isArray ( config . agents ) ) {
198+ errors . push ( "Agents must be an array" )
199+ }
200+
201+ if ( config . agents ) {
202+ config . agents . forEach ( ( agent , index ) => {
203+ if ( ! agent . id ) {
204+ errors . push ( `Agent at index ${ index } is missing an ID` )
205+ }
206+ if ( ! agent . name ) {
207+ errors . push ( `Agent at index ${ index } is missing a name` )
208+ }
209+ if ( ! agent . url ) {
210+ errors . push ( `Agent at index ${ index } is missing a URL` )
211+ }
212+ } )
213+ }
214+
215+ return {
216+ isValid : errors . length === 0 ,
217+ errors,
218+ }
219+ }
0 commit comments