MCPcopy Index your code
hub / github.com/coder/coder / storeScreenshotAttachment

Function storeScreenshotAttachment

coderd/x/chatd/chattool/attachment.go:114–132  ·  view source on GitHub ↗
(
	ctx context.Context,
	storeFile StoreFileFunc,
	name string,
	encodedPNG string,
)

Source from the content-addressed store, hash-verified

112}
113
114func 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.

Callers 1

Calls 4

storeAttachmentDataFunction · 0.85
NewMethod · 0.65
ReadAllMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected