Add generate_image tool and show Codex images inline
This commit is contained in:
@@ -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("", 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 {
|
||||
|
||||
Reference in New Issue
Block a user