This commit is contained in:
Ian Gulliver
2026-10-21 10:23:02 -07:00
parent 3dfd59115e
commit e2faadf61e
2 changed files with 13 additions and 23 deletions
+9 -19
View File
@@ -7,7 +7,6 @@ import (
"fmt"
"log/slog"
"strings"
"sync"
"time"
"g.fc.run/ai/byre/internal/antigravity"
@@ -15,16 +14,11 @@ import (
)
type agySteps struct {
mu sync.Mutex
text map[int]*strings.Builder
tools map[string]bool
}
func newAgySteps() *agySteps {
return &agySteps{text: map[int]*strings.Builder{}, tools: map[string]bool{}}
}
func (m *Manager) handleAntigravity(ctx context.Context, l *live, p antigravityProcess, ev antigravity.Event) error {
func (m *Manager) handleAntigravity(ctx context.Context, l *live, p antigravityProcess, steps *agySteps, ev antigravity.Event) error {
switch ev.Kind {
case "init":
return nil
@@ -34,7 +28,7 @@ func (m *Manager) handleAntigravity(ctx context.Context, l *live, p antigravityP
if err != nil {
return err
}
return m.agyStep(ctx, l, p, ev, su)
return m.agyStep(ctx, l, steps, ev, su)
case "result":
res, err := ev.Result()
@@ -52,24 +46,22 @@ func (m *Manager) handleAntigravity(ctx context.Context, l *live, p antigravityP
return m.emit(ctx, l, agentActor, "agent.vendor", raw)
}
func (m *Manager) agyStep(ctx context.Context, l *live, p antigravityProcess, ev antigravity.Event, su antigravity.StepUpdate) error {
func (m *Manager) agyStep(ctx context.Context, l *live, steps *agySteps, ev antigravity.Event, su antigravity.StepUpdate) error {
switch su.StepType {
case "user_input":
return nil
case "agent_response":
p.steps.mu.Lock()
b := p.steps.text[su.StepIndex]
b := steps.text[su.StepIndex]
if b == nil {
b = &strings.Builder{}
p.steps.text[su.StepIndex] = b
steps.text[su.StepIndex] = b
}
b.WriteString(su.TextDelta)
done := su.State != "ACTIVE"
if done {
delete(p.steps.text, su.StepIndex)
delete(steps.text, su.StepIndex)
}
p.steps.mu.Unlock()
if su.TextDelta != "" {
m.store.Broadcast(m.event(l, agentActor, "agent.delta", map[string]any{"text": su.TextDelta}))
@@ -89,13 +81,11 @@ func (m *Manager) agyStep(ctx context.Context, l *live, p antigravityProcess, ev
if su.ToolInfo != nil {
info = *su.ToolInfo
}
p.steps.mu.Lock()
called := p.steps.tools[id]
p.steps.tools[id] = su.State == "ACTIVE"
called := steps.tools[id]
steps.tools[id] = su.State == "ACTIVE"
if su.State != "ACTIVE" {
delete(p.steps.tools, id)
delete(steps.tools, id)
}
p.steps.mu.Unlock()
if !called {
name, input, err := agyToolCall(su.ToolName, info.Parameters)
+4 -4
View File
@@ -260,8 +260,7 @@ func (p codexProcess) drive(m *Manager, l *live) {
}
type antigravityProcess struct {
s *antigravity.Session
steps *agySteps
s *antigravity.Session
}
func (m *Manager) startAntigravity(ctx context.Context, sess api.AgentSession, l *live, g string, servers []*mcp.Server, stdio []mcp.Stdio, env []string) (agentProcess, error) {
@@ -293,7 +292,7 @@ func (m *Manager) startAntigravity(ctx context.Context, sess api.AgentSession, l
return nil, err
}
}
return antigravityProcess{s: s, steps: newAgySteps()}, nil
return antigravityProcess{s: s}, nil
}
func (p antigravityProcess) send(ctx context.Context, text string, images []image) error {
@@ -324,12 +323,13 @@ func (p antigravityProcess) discard() {
func (p antigravityProcess) drive(m *Manager, l *live) {
ctx := context.Background()
steps := &agySteps{text: map[int]*strings.Builder{}, tools: map[string]bool{}}
for ev := range p.s.Events() {
start := time.Now()
if wait := start.Sub(ev.Read); wait > 200*time.Millisecond {
slog.Info("agent event waited", "session", l.id, "event", ev.Kind, "wait", wait)
}
err := m.handleAntigravity(ctx, l, p, ev)
err := m.handleAntigravity(ctx, l, p, steps, ev)
if err != nil {
slog.Error("record agent event", "session", l.id, "event", ev.Kind, "err", err)
}