The open source coding agent.
TypeScript
fix: image reading
adamdottvf31cbf2744cd
diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.tsindex 41454307cf0..ed9dff24ad4 100644--- a/packages/opencode/src/session/index.ts+++ b/packages/opencode/src/session/index.ts@@ -372,11 +372,11 @@ export namespace Session {return [{type: "text",- text: ["Called the Read tool on " + url.pathname].join("\n"),+ text: `Called the Read tool with the following input: {\"filePath\":\"${url.pathname}\"}`,},{type: "file",- url: `data:${part.mime};base64,` + Buffer.from(await file.bytes()).toString("base64url"),+ url: `data:${part.mime};base64,` + Buffer.from(await file.bytes()).toString("base64"),mime: part.mime,filename: part.filename!,},diff --git a/packages/opencode/src/tool/read.txt b/packages/opencode/src/tool/read.txtindex d1bf8c5d930..be9e9e0c35c 100644--- a/packages/opencode/src/tool/read.txt+++ b/packages/opencode/src/tool/read.txt@@ -2,7 +2,7 @@ Reads a file from the local filesystem. You can access any file directly by usinAssume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.Usage:-- The file_path parameter must be an absolute path, not a relative path+- The filePath parameter must be an absolute path, not a relative path- By default, it reads up to 2000 lines starting from the beginning of the file- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters- Any lines longer than 2000 characters will be truncateddiff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.goindex cc31fbef21c..82b3bf71e5a 100644--- a/packages/tui/internal/components/chat/editor.go+++ b/packages/tui/internal/components/chat/editor.go@@ -104,13 +104,19 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {}base64EncodedFile := base64.StdEncoding.EncodeToString(fileBytes)url := fmt.Sprintf("data:%s;base64,%s", mediaType, base64EncodedFile)+ attachmentCount := len(m.textarea.GetAttachments())+ attachmentIndex := attachmentCount + 1+ label := "File"+ if strings.HasPrefix(mediaType, "image/") {+ label = "Image"+ }attachment := &textarea.Attachment{ID: uuid.NewString(),- Display: fmt.Sprintf("<%s>", filePath),+ MediaType: mediaType,+ Display: fmt.Sprintf("[%s #%d]", label, attachmentIndex),URL: url,Filename: filePath,- MediaType: mediaType,}m.textarea.InsertAttachment(attachment)m.textarea.InsertString(" ")@@ -325,12 +331,14 @@ func (m *editorComponent) Clear() (tea.Model, tea.Cmd) {func (m *editorComponent) Paste() (tea.Model, tea.Cmd) {imageBytes := clipboard.Read(clipboard.FmtImage)if imageBytes != nil {+ attachmentCount := len(m.textarea.GetAttachments())+ attachmentIndex := attachmentCount + 1base64EncodedFile := base64.StdEncoding.EncodeToString(imageBytes)attachment := &textarea.Attachment{ID: uuid.NewString(),- Display: "<clipboard-image>",- Filename: "clipboard-image",MediaType: "image/png",+ Display: fmt.Sprintf("[Image #%d]", attachmentIndex),+ Filename: fmt.Sprintf("image-%d.png", attachmentIndex),URL: fmt.Sprintf("data:image/png;base64,%s", base64EncodedFile),}m.textarea.InsertAttachment(attachment)diff --git a/packages/tui/sdk/packages/ssestream/ssestream.go b/packages/tui/sdk/packages/ssestream/ssestream.goindex 81adbd69b57..87ab56f2cc0 100644--- a/packages/tui/sdk/packages/ssestream/ssestream.go+++ b/packages/tui/sdk/packages/ssestream/ssestream.go@@ -29,7 +29,7 @@ func NewDecoder(res *http.Response) Decoder {decoder = t(res.Body)} else {scn := bufio.NewScanner(res.Body)- scn.Buffer(nil, bufio.MaxScanTokenSize<<4)+ scn.Buffer(nil, (bufio.MaxScanTokenSize<<4)*10)decoder = &eventStreamDecoder{rc: res.Body, scn: scn}}return decoder