contextFileAgentID extracts the workspace agent ID from the most recent persisted instruction-file parts. The skill-only sentinel is ignored because it does not represent persisted instruction content. Returns uuid.Nil, false if no instruction-file parts exist.
(messages []database.ChatMessage)
| 8905 | // ignored because it does not represent persisted instruction content. |
| 8906 | // Returns uuid.Nil, false if no instruction-file parts exist. |
| 8907 | func contextFileAgentID(messages []database.ChatMessage) (uuid.UUID, bool) { |
| 8908 | var lastID uuid.UUID |
| 8909 | found := false |
| 8910 | for _, msg := range messages { |
| 8911 | if !msg.Content.Valid || !bytes.Contains(msg.Content.RawMessage, []byte(`"context-file"`)) { |
| 8912 | continue |
| 8913 | } |
| 8914 | var parts []codersdk.ChatMessagePart |
| 8915 | if err := json.Unmarshal(msg.Content.RawMessage, &parts); err != nil { |
| 8916 | continue |
| 8917 | } |
| 8918 | for _, p := range parts { |
| 8919 | if p.Type != codersdk.ChatMessagePartTypeContextFile || |
| 8920 | !p.ContextFileAgentID.Valid || |
| 8921 | p.ContextFilePath == AgentChatContextSentinelPath { |
| 8922 | continue |
| 8923 | } |
| 8924 | lastID = p.ContextFileAgentID.UUID |
| 8925 | found = true |
| 8926 | break |
| 8927 | } |
| 8928 | } |
| 8929 | return lastID, found |
| 8930 | } |
| 8931 | |
| 8932 | // fetchWorkspaceContext retrieves fresh instruction files and |
| 8933 | // skills from the workspace agent without persisting. It handles |