prependAgentChatContextSentinelIfNeeded adds an empty context-file part when the request only carries skills. The turn pipeline uses the sentinel's agent metadata to trust the skill parts.
( parts []codersdk.ChatMessagePart, agentID uuid.UUID, operatingSystem string, directory string, )
| 2867 | // part when the request only carries skills. The turn pipeline uses |
| 2868 | // the sentinel's agent metadata to trust the skill parts. |
| 2869 | func prependAgentChatContextSentinelIfNeeded( |
| 2870 | parts []codersdk.ChatMessagePart, |
| 2871 | agentID uuid.UUID, |
| 2872 | operatingSystem string, |
| 2873 | directory string, |
| 2874 | ) []codersdk.ChatMessagePart { |
| 2875 | hasContextFile := false |
| 2876 | hasSkill := false |
| 2877 | for _, part := range parts { |
| 2878 | switch part.Type { |
| 2879 | case codersdk.ChatMessagePartTypeContextFile: |
| 2880 | hasContextFile = true |
| 2881 | case codersdk.ChatMessagePartTypeSkill: |
| 2882 | hasSkill = true |
| 2883 | } |
| 2884 | if hasContextFile && hasSkill { |
| 2885 | return parts |
| 2886 | } |
| 2887 | } |
| 2888 | if !hasSkill || hasContextFile { |
| 2889 | return parts |
| 2890 | } |
| 2891 | return append([]codersdk.ChatMessagePart{{ |
| 2892 | Type: codersdk.ChatMessagePartTypeContextFile, |
| 2893 | ContextFilePath: chatd.AgentChatContextSentinelPath, |
| 2894 | ContextFileAgentID: uuid.NullUUID{ |
| 2895 | UUID: agentID, |
| 2896 | Valid: true, |
| 2897 | }, |
| 2898 | ContextFileOS: operatingSystem, |
| 2899 | ContextFileDirectory: directory, |
| 2900 | }}, parts...) |
| 2901 | } |
| 2902 | |
| 2903 | func sortChatMessagesByCreatedAtAndID(messages []database.ChatMessage) { |
| 2904 | sort.SliceStable(messages, func(i, j int) bool { |
no outgoing calls
no test coverage detected