({
model,
providerOptions,
temperature,
inputMessages,
inputSources,
selectedRepos,
disabledMcpServerIds,
onWriteSource,
onMcpServerDiscovered,
onMcpServerFailed,
traceId,
chatId,
prisma,
userId,
orgId,
}: AgentOptions)
| 237 | } |
| 238 | |
| 239 | const createAgentStream = async ({ |
| 240 | model, |
| 241 | providerOptions, |
| 242 | temperature, |
| 243 | inputMessages, |
| 244 | inputSources, |
| 245 | selectedRepos, |
| 246 | disabledMcpServerIds, |
| 247 | onWriteSource, |
| 248 | onMcpServerDiscovered, |
| 249 | onMcpServerFailed, |
| 250 | traceId, |
| 251 | chatId, |
| 252 | prisma, |
| 253 | userId, |
| 254 | orgId, |
| 255 | }: AgentOptions) => { |
| 256 | // For every file source, resolve the source code so that we can include it in the system prompt. |
| 257 | const fileSources = inputSources.filter((source) => source.type === 'file'); |
| 258 | const resolvedFileSources = ( |
| 259 | await Promise.all(fileSources.map(async (source) => { |
| 260 | const fileSource = await getFileSource({ |
| 261 | path: source.path, |
| 262 | repo: source.repo, |
| 263 | ref: source.revision, |
| 264 | }, { source: 'sourcebot-ask-agent' }); |
| 265 | |
| 266 | if (isServiceError(fileSource)) { |
| 267 | logger.error("Error fetching file source:", fileSource); |
| 268 | return undefined; |
| 269 | } |
| 270 | |
| 271 | return { |
| 272 | path: fileSource.path, |
| 273 | source: fileSource.source, |
| 274 | repo: fileSource.repo, |
| 275 | language: fileSource.language, |
| 276 | revision: source.revision, |
| 277 | }; |
| 278 | })) |
| 279 | ).filter((source) => source !== undefined); |
| 280 | |
| 281 | let mcpToolSetsObj: McpToolsResult = { tools: {}, failedServers: [], serverFaviconUrls: {}, cleanup: async () => {} }; |
| 282 | if (userId && orgId && await hasEntitlement('ask') && disabledMcpServerIds !== undefined) { |
| 283 | try { |
| 284 | const allMcpClients = await getConnectedMcpClients(prisma, userId, orgId); |
| 285 | const mcpClients = allMcpClients.filter((c) => !disabledMcpServerIds.includes(c.serverId)); |
| 286 | mcpToolSetsObj = await getMcpTools(mcpClients, { |
| 287 | chatId, |
| 288 | traceId, |
| 289 | source: 'sourcebot-ask-agent', |
| 290 | }); |
| 291 | |
| 292 | for (const [sanitizedName, faviconUrl] of Object.entries(mcpToolSetsObj.serverFaviconUrls)) { |
| 293 | onMcpServerDiscovered(sanitizedName, faviconUrl); |
| 294 | } |
| 295 | |
| 296 | if (mcpClients.length > 0) { |
no test coverage detected