@@ -18,8 +18,6 @@ import (
1818 "github.com/docker/docker-agent/pkg/config/types"
1919 "github.com/docker/docker-agent/pkg/hooks"
2020 "github.com/docker/docker-agent/pkg/modelsdev"
21- "github.com/docker/docker-agent/pkg/rag"
22- ragtypes "github.com/docker/docker-agent/pkg/rag/types"
2321 "github.com/docker/docker-agent/pkg/session"
2422 "github.com/docker/docker-agent/pkg/sessiontitle"
2523 "github.com/docker/docker-agent/pkg/team"
@@ -163,12 +161,6 @@ type ModelStore interface {
163161 GetDatabase (ctx context.Context ) (* modelsdev.Database , error )
164162}
165163
166- // RAGInitializer is implemented by runtimes that support background RAG initialization.
167- // Local runtimes use this to start indexing early; remote runtimes typically do not.
168- type RAGInitializer interface {
169- StartBackgroundRAGInit (ctx context.Context , sendEvent func (Event ))
170- }
171-
172164// ToolsChangeSubscriber is implemented by runtimes that can notify when
173165// toolsets report a change in their tool list (e.g. after an MCP
174166// ToolListChanged notification). The provided callback is invoked
@@ -340,107 +332,6 @@ func NewLocalRuntime(agents *team.Team, opts ...Opt) (*LocalRuntime, error) {
340332 return r , nil
341333}
342334
343- // StartBackgroundRAGInit initializes RAG in background and forwards events
344- // Should be called early (e.g., by App) to start indexing before RunStream
345- func (r * LocalRuntime ) StartBackgroundRAGInit (ctx context.Context , sendEvent func (Event )) {
346- if r .ragInitialized .Swap (true ) {
347- return
348- }
349-
350- ragManagers := r .team .RAGManagers ()
351- if len (ragManagers ) == 0 {
352- return
353- }
354-
355- slog .Debug ("Starting background RAG initialization with event forwarding" , "manager_count" , len (ragManagers ))
356-
357- // Set up event forwarding BEFORE starting initialization
358- // This ensures all events are captured
359- r .forwardRAGEvents (ctx , ragManagers , sendEvent )
360-
361- // Now start initialization (events will be forwarded)
362- r .team .InitializeRAG (ctx )
363- r .team .StartRAGFileWatchers (ctx )
364- }
365-
366- // forwardRAGEvents forwards RAG manager events to the given callback
367- // Consolidates duplicated event forwarding logic
368- func (r * LocalRuntime ) forwardRAGEvents (ctx context.Context , ragManagers map [string ]* rag.Manager , sendEvent func (Event )) {
369- for _ , mgr := range ragManagers {
370- go func (mgr * rag.Manager ) {
371- ragName := mgr .Name ()
372- slog .Debug ("Starting RAG event forwarder goroutine" , "rag" , ragName )
373- for {
374- select {
375- case <- ctx .Done ():
376- slog .Debug ("RAG event forwarder stopped" , "rag" , ragName )
377- return
378- case ragEvent , ok := <- mgr .Events ():
379- if ! ok {
380- slog .Debug ("RAG events channel closed" , "rag" , ragName )
381- return
382- }
383-
384- agentName := r .CurrentAgentName ()
385- slog .Debug ("Forwarding RAG event" , "type" , ragEvent .Type , "rag" , ragName , "agent" , agentName )
386-
387- switch ragEvent .Type {
388- case ragtypes .EventTypeIndexingStarted :
389- sendEvent (RAGIndexingStarted (ragName , ragEvent .StrategyName , agentName ))
390- case ragtypes .EventTypeIndexingProgress :
391- if ragEvent .Progress != nil {
392- sendEvent (RAGIndexingProgress (ragName , ragEvent .StrategyName , ragEvent .Progress .Current , ragEvent .Progress .Total , agentName ))
393- }
394- case ragtypes .EventTypeIndexingComplete :
395- sendEvent (RAGIndexingCompleted (ragName , ragEvent .StrategyName , agentName ))
396- case ragtypes .EventTypeUsage :
397- // Convert RAG usage to TokenUsageEvent so TUI displays it
398- sendEvent (NewTokenUsageEvent ("" , agentName , & Usage {
399- InputTokens : ragEvent .TotalTokens ,
400- ContextLength : ragEvent .TotalTokens ,
401- Cost : ragEvent .Cost ,
402- }))
403- case ragtypes .EventTypeError :
404- if ragEvent .Error != nil {
405- sendEvent (Error (fmt .Sprintf ("RAG %s error: %v" , ragName , ragEvent .Error )))
406- }
407- default :
408- // Log unhandled events for debugging
409- slog .Debug ("Unhandled RAG event type" , "type" , ragEvent .Type , "rag" , ragName )
410- }
411- }
412- }
413- }(mgr )
414- }
415- }
416-
417- // InitializeRAG is called within RunStream as a fallback when background init wasn't used
418- // (e.g., for exec command or API mode where there's no App)
419- func (r * LocalRuntime ) InitializeRAG (ctx context.Context , events chan Event ) {
420- // If already initialized via StartBackgroundRAGInit, skip entirely
421- // Event forwarding was already set up there
422- if r .ragInitialized .Swap (true ) {
423- slog .Debug ("RAG already initialized, event forwarding already active" , "manager_count" , len (r .team .RAGManagers ()))
424- return
425- }
426-
427- ragManagers := r .team .RAGManagers ()
428- if len (ragManagers ) == 0 {
429- return
430- }
431-
432- slog .Debug ("Setting up RAG initialization (fallback path for non-TUI)" , "manager_count" , len (ragManagers ))
433-
434- // Set up event forwarding BEFORE starting initialization
435- r .forwardRAGEvents (ctx , ragManagers , func (event Event ) {
436- events <- event
437- })
438-
439- // Start initialization and file watchers
440- r .team .InitializeRAG (ctx )
441- r .team .StartRAGFileWatchers (ctx )
442- }
443-
444335func (r * LocalRuntime ) CurrentAgentName () string {
445336 r .currentAgentMu .RLock ()
446337 defer r .currentAgentMu .RUnlock ()
0 commit comments