@@ -11,9 +11,10 @@ import (
1111 "github.com/co-browser/agent-browser/internal/events"
1212 "github.com/co-browser/agent-browser/internal/log"
1313 "github.com/co-browser/agent-browser/internal/mcp"
14- "github.com/co-browser/agent-browser/internal/mcp/config"
14+ mcpConfig "github.com/co-browser/agent-browser/internal/mcp/config"
1515 "github.com/co-browser/agent-browser/internal/web"
1616 "github.com/co-browser/agent-browser/internal/web/client"
17+ webConfig "github.com/co-browser/agent-browser/internal/web/config"
1718 "github.com/co-browser/agent-browser/internal/web/handlers"
1819
1920 "go.uber.org/fx"
@@ -61,7 +62,7 @@ var DatabaseModule = fx.Module("database",
6162// Currently loads MCP configuration.
6263var ConfigModule = fx .Module ("config" ,
6364 fx .Provide (
64- config .NewConfig ,
65+ mcpConfig .NewConfig ,
6566 ),
6667)
6768
@@ -94,44 +95,42 @@ var BackendModule = fx.Module("backend",
9495 */
9596)
9697
97- // MCPClientModule provides the components responsible for connecting *to* remote MCP servers.
98- // This includes the ConnectionManager and the API client used by the ConnectionManager
99- // to update this agent's status and sync tools via its own web API.
98+ // MCPClientModule provides the components responsible for connecting to remote MCP servers.
10099var MCPClientModule = fx .Module ("mcp_client" ,
101100 fx .Provide (
102- // Provide the web API client used by MCP components
101+ // Provide the web API client
103102 func (logger log.Logger ) * client.Client {
104- // TODO: Make API client base URL configurable
105- config := client .DefaultConfig ()
106- // DefaultConfig likely points to localhost, which is correct for the agent
107- // calling its own API.
103+ config := webConfig.ClientConfig {
104+ BaseURL : "http://localhost:8080" ,
105+ TimeoutSec : 10 ,
106+ MaxRetries : 3 ,
107+ RetryDelaySec : 1 ,
108+ }
108109 return client .NewClient (config , logger )
109110 },
110- // Provide MCP components (like ConnectionManager)
111+ // Provide MCP components
111112 mcp .NewMCPComponents ,
112113 ),
113- // Register lifecycle hooks for starting/stopping the MCP ConnectionManager
114+ // Register lifecycle hooks
114115 fx .Invoke (mcp .RegisterMCPServerHooks ),
115- // Register event subscribers for the ConnectionManager
116+ // Register event subscribers
116117 fx .Invoke (mcp .RegisterEventSubscribers ),
117118)
118119
119120// WebModule provides the HTTP server, API handlers, UI handlers, and SSE handler.
120121var WebModule = fx .Module ("web" ,
121122 fx .Provide (
122- // Provide UI handler struct (depends on Logger, BackendService)
123+ // Provide UI handler struct
123124 handlers .NewUIHandler ,
124- // Provide API handlers (depends on BackendService, Logger)
125+
126+ // Provide API handlers
125127 func (bs backend.Service , logger log.Logger ) * handlers.APIHandlers {
126128 return handlers .NewAPIHandlers (bs , logger )
127129 },
128- // Provide SSE handler (depends on Logger, EventBus, BackendService)
129- // Note: Fx automatically provides context.Background() if context.Context is needed.
130+
131+ // Provide SSE handler
130132 func (lc fx.Lifecycle , logger log.Logger , bus events.Bus , bs backend.Service ) * handlers.SSEHandler {
131- // Create handler with background context
132- // The handler manages its own internal context cancellation via Stop().
133133 sseHandler := handlers .NewSSEHandler (context .Background (), logger , bus , bs )
134- // Register Stop hook
135134 lc .Append (fx.Hook {
136135 OnStop : func (_ context.Context ) error {
137136 logger .Info ().Msg ("Stopping SSE handler..." )
@@ -141,42 +140,33 @@ var WebModule = fx.Module("web",
141140 })
142141 return sseHandler
143142 },
144- // Provide the HTTP request router (ServeMux)
145- // Pass apiHandler and uiHandler explicitly if NewMux requires them.
146- // Assuming NewMux takes no arguments for now as per web/server.go structure.
147- // We register handlers via fx.Invoke later.
143+
144+ // Provide the HTTP router
148145 func () * http.ServeMux {
149146 return http .NewServeMux ()
150147 },
151- // Provide the HTTP server itself (depends on ServeMux)
148+
149+ // Provide the HTTP server
152150 web .NewServer ,
153151 ),
152+
154153 // Register handlers with the router
155154 fx .Invoke (func (mux * http.ServeMux , apiHandlers * handlers.APIHandlers , uiHandler * handlers.UIHandler , sseHandler * handlers.SSEHandler ) {
156- // API Routes (includes Swagger/OpenAPI docs)
155+ // API Routes
157156 apiHandlers .RegisterRoutes (mux )
158157
159- // --- UI Routes (Registered directly) ---
160- mux .HandleFunc ("/ui/" , uiHandler .ServeIndex ) // Note trailing slash
161- // mux.HandleFunc("/ui/add", uiHandler.ServeAddPage) // Removed
162- // mux.HandleFunc("/ui/success", uiHandler.ServeSuccessPage) // Removed
163- // mux.HandleFunc("/ui/error", uiHandler.ServeErrorPage) // Removed
158+ // UI Routes
159+ mux .HandleFunc ("/ui/" , uiHandler .ServeIndex )
164160
165- // --- Root Redirect ---
166- // Use mux.Handle for http.RedirectHandler as it returns an http.Handler
161+ // Root Redirect
167162 mux .Handle ("/" , http .RedirectHandler ("/ui/" , http .StatusMovedPermanently ))
168163
169- // --- SSE Route ---
164+ // SSE Route
170165 mux .HandleFunc ("/api/events" , sseHandler .ServeHTTP )
171-
172- // Metrics Route (example, if needed)
173- // mux.Handle("/metrics", promhttp.Handler())
174166 }),
175- // Register web server lifecycle hooks for starting/stopping the server
167+
168+ // Register web server lifecycle hooks
176169 fx .Invoke (web .RegisterWebServerHooks ),
177- // Invoke the SSE handler's event listener setup explicitly if needed,
178- // but NewSSEHandler already starts the listener goroutine.
179- // fx.Invoke(func(sse *handlers.SSEHandler) { /* SSE Listener already started in New */ }),
180170)
181171
182172// CursorModule manages interaction with the ~/.cursor/mcp.json file.
0 commit comments