Add generate_image tool and show Codex images inline

This commit is contained in:
Ian Gulliver
2026-10-22 19:16:47 -07:00
parent ff589f954c
commit 2aba745531
4 changed files with 163 additions and 0 deletions
+22
View File
@@ -3,6 +3,7 @@ package agents
import (
"context"
"encoding/json"
"fmt"
"log/slog"
"os"
"strings"
@@ -143,6 +144,16 @@ func (m *Manager) codexItemCompleted(ctx context.Context, l *live, s *codex.Sess
return nil
}
return m.emit(ctx, l, agentActor, "agent.thinking", map[string]any{"text": text})
case codex.ThreadItemTypeImageGeneration:
if item.SavedPath == "" || l.reviewID != "" || l.owner != "" {
return nil
}
path, err := copyToMedia(MediaDir(l.dir), string(item.SavedPath))
if err != nil {
return err
}
return m.emit(ctx, l, agentActor, "agent.message", map[string]any{"text": fmt.Sprintf("![%s](<%s>)", imageAlt(item.RevisedPrompt), path)})
}
if !codexToolItems[item.Type] {
@@ -188,6 +199,17 @@ func (m *Manager) codexItemCompleted(ctx context.Context, l *live, s *codex.Sess
return nil
}
func imageAlt(prompt string) string {
alt := strings.NewReplacer("[", "", "]", "", "\n", " ").Replace(strings.TrimSpace(prompt))
if r := []rune(alt); len(r) > 120 {
alt = string(r[:120]) + "…"
}
if alt == "" {
return "generated image"
}
return alt
}
func codexToolResult(item codex.ThreadItem) (string, bool) {
status := codexStatus(item)
switch item.Type {