fix(codex): accept prepared chat attachments with model overrides
This commit is contained in:
+29
-4
@@ -14,6 +14,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -21,6 +22,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/coder/websocket"
|
||||
)
|
||||
@@ -332,12 +334,24 @@ func (c *Chat) PromptWithMessageID(ctx context.Context, id, text, messageID stri
|
||||
// PromptWithMessageIDModel applies a persisted per-chat choice at the explicit
|
||||
// next-turn boundary. It does not resume a thread or edit global configuration.
|
||||
func (c *Chat) PromptWithMessageIDModel(ctx context.Context, id, text, messageID, model string) error {
|
||||
if strings.TrimSpace(text) == "" {
|
||||
return errors.New("empty chat prompt")
|
||||
return c.PromptWithMessageIDModelFiles(ctx, id, text, messageID, model, nil)
|
||||
}
|
||||
|
||||
// PromptWithMessageIDFiles submits server-prepared attachments without changing
|
||||
// provider policy or configuration.
|
||||
func (c *Chat) PromptWithMessageIDFiles(ctx context.Context, id, text, messageID string, files []opencode.PromptFile) error {
|
||||
return c.PromptWithMessageIDModelFiles(ctx, id, text, messageID, "", files)
|
||||
}
|
||||
|
||||
// PromptWithMessageIDModelFiles keeps attachment and model overrides on one turn.
|
||||
func (c *Chat) PromptWithMessageIDModelFiles(ctx context.Context, id, text, messageID, model string, files []opencode.PromptFile) error {
|
||||
input, err := promptInput(text, files)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params := map[string]any{
|
||||
"threadId": id,
|
||||
"input": []any{map[string]any{"type": "text", "text": text}},
|
||||
"input": input,
|
||||
}
|
||||
if messageID != "" {
|
||||
params["clientUserMessageId"] = messageID
|
||||
@@ -345,7 +359,7 @@ func (c *Chat) PromptWithMessageIDModel(ctx context.Context, id, text, messageID
|
||||
if model != "" {
|
||||
params["model"] = model
|
||||
}
|
||||
_, err := c.call(ctx, "turn/start", params)
|
||||
_, err = c.call(ctx, "turn/start", params)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -799,11 +813,22 @@ func (i item) chatMessage(sessionID string) (protocol.ChatMessage, bool) {
|
||||
var content []struct {
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
_ = json.Unmarshal(i.Content, &content)
|
||||
for _, part := range content {
|
||||
if part.Type == "text" && part.Text != "" {
|
||||
msg.Parts = append(msg.Parts, protocol.ChatPart{Type: protocol.ChatPartText, Text: part.Text})
|
||||
} else if (part.Type == "mention" || part.Type == "localImage") && filepath.IsAbs(part.Path) {
|
||||
name := part.Name
|
||||
if name == "" {
|
||||
name = filepath.Base(part.Path)
|
||||
}
|
||||
msg.Parts = append(msg.Parts, protocol.ChatPart{Type: protocol.ChatPartFile, Name: name, URI: (&url.URL{Scheme: "file", Path: part.Path}).String()})
|
||||
} else if part.Type == "image" && part.URL != "" {
|
||||
msg.Parts = append(msg.Parts, protocol.ChatPart{Type: protocol.ChatPartFile, Name: "image", URI: part.URL})
|
||||
}
|
||||
}
|
||||
case "agentMessage":
|
||||
|
||||
Reference in New Issue
Block a user