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

Function storeWorkspaceAttachment

coderd/x/chatd/chattool/attachment.go:76–112  ·  view source on GitHub ↗
(
	ctx context.Context,
	conn workspacesdk.AgentConn,
	path string,
	name string,
	storeFile StoreFileFunc,
)

Source from the content-addressed store, hash-verified

74}
75
76func storeWorkspaceAttachment(
77 ctx context.Context,
78 conn workspacesdk.AgentConn,
79 path string,
80 name string,
81 storeFile StoreFileFunc,
82) (AttachmentMetadata, int, error) {
83 if conn == nil {
84 return AttachmentMetadata{}, 0, xerrors.New("workspace connection is not configured")
85 }
86 if strings.TrimSpace(path) == "" {
87 return AttachmentMetadata{}, 0, xerrors.New("path is required")
88 }
89 reader, _, err := conn.ReadFile(ctx, path, 0, maxAttachmentSize+1)
90 if err != nil {
91 return AttachmentMetadata{}, 0, err
92 }
93 defer reader.Close()
94
95 data, err := io.ReadAll(io.LimitReader(reader, maxAttachmentSize+1))
96 if err != nil {
97 return AttachmentMetadata{}, 0, err
98 }
99 if strings.TrimSpace(name) == "" {
100 path = strings.TrimRight(path, "/\\")
101 if idx := strings.LastIndexAny(path, "/\\"); idx >= 0 {
102 name = path[idx+1:]
103 } else {
104 name = path
105 }
106 }
107 attachment, err := storeAttachmentData(ctx, storeFile, name, path, data)
108 if err != nil {
109 return AttachmentMetadata{}, 0, err
110 }
111 return attachment, len(data), nil
112}
113
114func storeScreenshotAttachment(
115 ctx context.Context,

Callers 1

executeAttachFileToolFunction · 0.85

Calls 5

storeAttachmentDataFunction · 0.85
NewMethod · 0.65
ReadFileMethod · 0.65
CloseMethod · 0.65
ReadAllMethod · 0.45

Tested by

no test coverage detected