( ctx context.Context, storeFile StoreFileFunc, name string, encodedPNG string, )
| 112 | } |
| 113 | |
| 114 | func storeScreenshotAttachment( |
| 115 | ctx context.Context, |
| 116 | storeFile StoreFileFunc, |
| 117 | name string, |
| 118 | encodedPNG string, |
| 119 | ) (AttachmentMetadata, error) { |
| 120 | if strings.TrimSpace(encodedPNG) == "" { |
| 121 | return AttachmentMetadata{}, xerrors.New("screenshot data is empty") |
| 122 | } |
| 123 | decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(encodedPNG)) |
| 124 | data, err := io.ReadAll(io.LimitReader(decoder, maxAttachmentSize+1)) |
| 125 | if err != nil { |
| 126 | return AttachmentMetadata{}, xerrors.Errorf("decode screenshot: %w", err) |
| 127 | } |
| 128 | if strings.TrimSpace(name) == "" { |
| 129 | name = "screenshot.png" |
| 130 | } |
| 131 | return storeAttachmentData(ctx, storeFile, name, name, data) |
| 132 | } |
| 133 | |
| 134 | // WithAttachments stores durable attachment metadata on a tool response so the |
| 135 | // persistence layer can promote the files into assistant chat attachments. |
no test coverage detected