MCPcopy Create free account
hub / github.com/coder/coder / ExtractFileID

Function ExtractFileID

coderd/x/chatd/chatprompt/chatprompt.go:76–93  ·  view source on GitHub ↗

ExtractFileID parses the file_id from a serialized file content block envelope. Returns uuid.Nil and an error when the block is not a file-type block or has no file_id.

(raw json.RawMessage)

Source from the content-addressed store, hash-verified

74// block envelope. Returns uuid.Nil and an error when the block is
75// not a file-type block or has no file_id.
76func ExtractFileID(raw json.RawMessage) (uuid.UUID, error) {
77 var envelope struct {
78 Type string `json:"type"`
79 Data struct {
80 FileID string `json:"file_id"`
81 } `json:"data"`
82 }
83 if err := json.Unmarshal(raw, &envelope); err != nil {
84 return uuid.Nil, xerrors.Errorf("unmarshal content block: %w", err)
85 }
86 if !strings.EqualFold(envelope.Type, string(fantasy.ContentTypeFile)) {
87 return uuid.Nil, xerrors.Errorf("not a file content block: %s", envelope.Type)
88 }
89 if envelope.Data.FileID == "" {
90 return uuid.Nil, xerrors.New("no file_id")
91 }
92 return uuid.Parse(envelope.Data.FileID)
93}
94
95// ConvertMessagesWithFiles converts persisted chat messages into LLM
96// prompt messages, resolving user file references via the provided

Callers 1

parseLegacyUserBlocksFunction · 0.85

Calls 4

NewMethod · 0.65
ParseMethod · 0.65
UnmarshalMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected