summaryrefslogtreecommitdiffhomepage
path: root/internal/llm
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-08 12:03:59 -0500
committeradamdottv <[email protected]>2025-05-08 12:03:59 -0500
commitf41b7bbd0a0cc731fd7c471b7ee8b26f14a21755 (patch)
treebd34e77a07516735a220c210d4930fbe2132a63b /internal/llm
parente35ea2d448d1a3c9cf0a6fba1318e522fc61d1eb (diff)
downloadopencode-f41b7bbd0a0cc731fd7c471b7ee8b26f14a21755.tar.gz
opencode-f41b7bbd0a0cc731fd7c471b7ee8b26f14a21755.zip
chore: refactoring status updates
Diffstat (limited to 'internal/llm')
-rw-r--r--internal/llm/agent/agent.go23
-rw-r--r--internal/llm/provider/anthropic.go5
-rw-r--r--internal/llm/provider/gemini.go5
-rw-r--r--internal/llm/provider/openai.go5
-rw-r--r--internal/llm/tools/shell/shell.go4
5 files changed, 23 insertions, 19 deletions
diff --git a/internal/llm/agent/agent.go b/internal/llm/agent/agent.go
index 81b8cf1db..695826cdf 100644
--- a/internal/llm/agent/agent.go
+++ b/internal/llm/agent/agent.go
@@ -17,6 +17,7 @@ import (
"github.com/opencode-ai/opencode/internal/message"
"github.com/opencode-ai/opencode/internal/permission"
"github.com/opencode-ai/opencode/internal/session"
+ "github.com/opencode-ai/opencode/internal/status"
)
// Common errors
@@ -96,7 +97,7 @@ func NewAgent(
func (a *agent) Cancel(sessionID string) {
if cancelFunc, exists := a.activeRequests.LoadAndDelete(sessionID); exists {
if cancel, ok := cancelFunc.(context.CancelFunc); ok {
- logging.InfoPersist(fmt.Sprintf("Request cancellation initiated for session: %s", sessionID))
+ status.Info(fmt.Sprintf("Request cancellation initiated for session: %s", sessionID))
cancel()
}
}
@@ -186,7 +187,7 @@ func (a *agent) Run(ctx context.Context, sessionID string, content string, attac
}
result := a.processGeneration(genCtx, sessionID, content, attachmentParts)
if result.Err() != nil && !errors.Is(result.Err(), ErrRequestCancelled) && !errors.Is(result.Err(), context.Canceled) {
- logging.ErrorPersist(result.Err().Error())
+ status.Error(result.Err().Error())
}
logging.Debug("Request completed", "sessionID", sessionID)
a.activeRequests.Delete(sessionID)
@@ -224,11 +225,11 @@ func (a *agent) processGeneration(ctx context.Context, sessionID, content string
if len(sessionMessages) == 0 && currentSession.Summary == "" {
go func() {
defer logging.RecoverPanic("agent.Run", func() {
- logging.ErrorPersist("panic while generating title")
+ status.Error("panic while generating title")
})
titleErr := a.generateTitle(context.Background(), sessionID, content)
if titleErr != nil {
- logging.ErrorPersist(fmt.Sprintf("failed to generate title: %v", titleErr))
+ status.Error(fmt.Sprintf("failed to generate title: %v", titleErr))
}
}()
}
@@ -308,11 +309,11 @@ func (a *agent) streamAndHandleEvents(ctx context.Context, sessionID string, msg
// If we're approaching the context window limit, trigger auto-compaction
if false && (*usage+maxTokens) >= threshold {
- logging.InfoPersist(fmt.Sprintf("Auto-compaction triggered for session %s. Estimated tokens: %d, Threshold: %d", sessionID, usage, threshold))
+ status.Info(fmt.Sprintf("Auto-compaction triggered for session %s. Estimated tokens: %d, Threshold: %d", sessionID, usage, threshold))
// Perform compaction with pause/resume to ensure safety
if err := a.CompactSession(ctx, sessionID); err != nil {
- logging.ErrorPersist(fmt.Sprintf("Auto-compaction failed: %v", err))
+ status.Error(fmt.Sprintf("Auto-compaction failed: %v", err))
// Continue with the request even if compaction fails
} else {
// Re-fetch session details after compaction
@@ -495,10 +496,10 @@ func (a *agent) processEvent(ctx context.Context, sessionID string, assistantMsg
return a.messages.Update(ctx, *assistantMsg)
case provider.EventError:
if errors.Is(event.Error, context.Canceled) {
- logging.InfoPersist(fmt.Sprintf("Event processing canceled for session: %s", sessionID))
+ status.Info(fmt.Sprintf("Event processing canceled for session: %s", sessionID))
return context.Canceled
}
- logging.ErrorPersist(event.Error.Error())
+ status.Error(event.Error.Error())
return event.Error
case provider.EventComplete:
assistantMsg.SetToolCalls(event.Response.ToolCalls)
@@ -570,7 +571,7 @@ func (a *agent) PauseSession(sessionID string) error {
return nil // Session is not active, no need to pause
}
- logging.InfoPersist(fmt.Sprintf("Pausing session: %s", sessionID))
+ status.Info(fmt.Sprintf("Pausing session: %s", sessionID))
a.pauseLock.Lock() // Acquire write lock to block new operations
return nil
}
@@ -578,7 +579,7 @@ func (a *agent) PauseSession(sessionID string) error {
// ResumeSession resumes message processing for a session
// This should be called after completing operations that required exclusive access
func (a *agent) ResumeSession(sessionID string) error {
- logging.InfoPersist(fmt.Sprintf("Resuming session: %s", sessionID))
+ status.Info(fmt.Sprintf("Resuming session: %s", sessionID))
a.pauseLock.Unlock() // Release write lock to allow operations to continue
return nil
}
@@ -592,7 +593,7 @@ func (a *agent) CompactSession(ctx context.Context, sessionID string) error {
}
// Make sure to resume the session when we're done
defer a.ResumeSession(sessionID)
- logging.InfoPersist(fmt.Sprintf("Session %s paused for compaction", sessionID))
+ status.Info(fmt.Sprintf("Session %s paused for compaction", sessionID))
}
// Create a cancellable context
diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go
index cb78ddf55..edd1c1d70 100644
--- a/internal/llm/provider/anthropic.go
+++ b/internal/llm/provider/anthropic.go
@@ -17,6 +17,7 @@ import (
"github.com/opencode-ai/opencode/internal/llm/tools"
"github.com/opencode-ai/opencode/internal/logging"
"github.com/opencode-ai/opencode/internal/message"
+ "github.com/opencode-ai/opencode/internal/status"
)
type anthropicOptions struct {
@@ -227,7 +228,7 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message,
return nil, retryErr
}
if retry {
- logging.WarnPersist(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), logging.PersistTimeArg, time.Millisecond*time.Duration(after+100))
+ status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
select {
case <-ctx.Done():
return nil, ctx.Err()
@@ -365,7 +366,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
return
}
if retry {
- logging.WarnPersist(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), logging.PersistTimeArg, time.Millisecond*time.Duration(after+100))
+ status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
select {
case <-ctx.Done():
// context cancelled
diff --git a/internal/llm/provider/gemini.go b/internal/llm/provider/gemini.go
index 9aee8e53a..2986c715e 100644
--- a/internal/llm/provider/gemini.go
+++ b/internal/llm/provider/gemini.go
@@ -15,6 +15,7 @@ import (
"github.com/opencode-ai/opencode/internal/llm/tools"
"github.com/opencode-ai/opencode/internal/logging"
"github.com/opencode-ai/opencode/internal/message"
+ "github.com/opencode-ai/opencode/internal/status"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
@@ -195,7 +196,7 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too
return nil, retryErr
}
if retry {
- logging.WarnPersist(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), logging.PersistTimeArg, time.Millisecond*time.Duration(after+100))
+ status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
select {
case <-ctx.Done():
return nil, ctx.Err()
@@ -297,7 +298,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
return
}
if retry {
- logging.WarnPersist(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), logging.PersistTimeArg, time.Millisecond*time.Duration(after+100))
+ status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
select {
case <-ctx.Done():
if ctx.Err() != nil {
diff --git a/internal/llm/provider/openai.go b/internal/llm/provider/openai.go
index 0b690e3c2..3bf8a6d42 100644
--- a/internal/llm/provider/openai.go
+++ b/internal/llm/provider/openai.go
@@ -16,6 +16,7 @@ import (
"github.com/opencode-ai/opencode/internal/llm/tools"
"github.com/opencode-ai/opencode/internal/logging"
"github.com/opencode-ai/opencode/internal/message"
+ "github.com/opencode-ai/opencode/internal/status"
)
type openaiOptions struct {
@@ -214,7 +215,7 @@ func (o *openaiClient) send(ctx context.Context, messages []message.Message, too
return nil, retryErr
}
if retry {
- logging.WarnPersist(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), logging.PersistTimeArg, time.Millisecond*time.Duration(after+100))
+ status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
select {
case <-ctx.Done():
return nil, ctx.Err()
@@ -320,7 +321,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
return
}
if retry {
- logging.WarnPersist(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), logging.PersistTimeArg, time.Millisecond*time.Duration(after+100))
+ status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries))
select {
case <-ctx.Done():
// context cancelled
diff --git a/internal/llm/tools/shell/shell.go b/internal/llm/tools/shell/shell.go
index 668a69fa1..21c283668 100644
--- a/internal/llm/tools/shell/shell.go
+++ b/internal/llm/tools/shell/shell.go
@@ -12,7 +12,7 @@ import (
"syscall"
"time"
- "github.com/opencode-ai/opencode/internal/logging"
+ "github.com/opencode-ai/opencode/internal/status"
)
type PersistentShell struct {
@@ -101,7 +101,7 @@ func newPersistentShell(cwd string) *PersistentShell {
go func() {
err := cmd.Wait()
if err != nil {
- logging.ErrorPersist(fmt.Sprintf("Shell process exited with error: %v", err))
+ status.Error(fmt.Sprintf("Shell process exited with error: %v", err))
}
shell.isAlive = false
close(shell.commandQueue)