(text: string, mentions: MentionData[], selectedSearchScopes: SearchScope[], disabledMcpServerIds: string[] = [])
| 188 | } |
| 189 | |
| 190 | export const createUIMessage = (text: string, mentions: MentionData[], selectedSearchScopes: SearchScope[], disabledMcpServerIds: string[] = []): CreateUIMessage<SBChatMessage> => { |
| 191 | // Converts applicable mentions into sources. |
| 192 | const sources: Source[] = mentions |
| 193 | .map((mention) => { |
| 194 | if (mention.type === 'file') { |
| 195 | const fileSource: FileSource = { |
| 196 | type: 'file', |
| 197 | path: mention.path, |
| 198 | repo: mention.repo, |
| 199 | name: mention.name, |
| 200 | revision: mention.revision, |
| 201 | } |
| 202 | return fileSource; |
| 203 | } |
| 204 | |
| 205 | return undefined; |
| 206 | }) |
| 207 | .filter((source) => source !== undefined); |
| 208 | |
| 209 | return { |
| 210 | role: 'user', |
| 211 | parts: [ |
| 212 | { |
| 213 | type: 'text', |
| 214 | text, |
| 215 | }, |
| 216 | ...sources.map((data) => ({ |
| 217 | type: 'data-source', |
| 218 | data, |
| 219 | })) as UIMessagePart<{ source: Source }, SBChatMessageToolTypes>[], |
| 220 | ], |
| 221 | metadata: { |
| 222 | selectedSearchScopes, |
| 223 | disabledMcpServerIds, |
| 224 | }, |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | export const getFileReferenceId = ({ repo, path, range }: Omit<FileReference, 'type' | 'id'>) => { |
| 229 | return `file-reference-${repo}::${path}${range ? `-${range.startLine}-${range.endLine}` : ''}`; |
no outgoing calls
no test coverage detected