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

Method storeChatAttachment

coderd/x/chatd/store_chat_attachment.go:30–71  ·  view source on GitHub ↗
(
	ctx context.Context,
	chatSnapshot database.Chat,
	name string,
	detectName string,
	data []byte,
)

Source from the content-addressed store, hash-verified

28}
29
30func (p *Server) storeChatAttachment(
31 ctx context.Context,
32 chatSnapshot database.Chat,
33 name string,
34 detectName string,
35 data []byte,
36) (chattool.AttachmentMetadata, error) {
37 if !chatSnapshot.WorkspaceID.Valid {
38 return chattool.AttachmentMetadata{}, xerrors.New("no workspace is associated with this chat. Use the create_workspace tool to create one")
39 }
40
41 storedName, mediaType, err := chatfiles.PrepareStoredFile(name, detectName, data)
42 if err != nil {
43 return chattool.AttachmentMetadata{}, err
44 }
45
46 // Insert and link in one transaction so a cap rejection or linking
47 // failure does not leave behind an unlinked chat file row.
48 var attachment chattool.AttachmentMetadata
49 err = p.db.InTx(func(tx database.Store) error {
50 ws, err := tx.GetWorkspaceByID(ctx, chatSnapshot.WorkspaceID.UUID)
51 if err != nil {
52 return xerrors.Errorf("resolve workspace: %w", err)
53 }
54
55 attachment, err = storeLinkedChatFileTx(
56 ctx,
57 tx,
58 chatSnapshot.ID,
59 chatSnapshot.OwnerID,
60 ws.OrganizationID,
61 storedName,
62 mediaType,
63 data,
64 )
65 return err
66 }, database.DefaultTXOptions().WithID("store_chat_attachment"))
67 if err != nil {
68 return chattool.AttachmentMetadata{}, err
69 }
70 return attachment, nil
71}
72
73func storeLinkedChatFileTx(
74 ctx context.Context,

Calls 8

PrepareStoredFileFunction · 0.92
DefaultTXOptionsFunction · 0.92
storeLinkedChatFileTxFunction · 0.85
NewMethod · 0.65
InTxMethod · 0.65
GetWorkspaceByIDMethod · 0.65
ErrorfMethod · 0.45
WithIDMethod · 0.45