(params: {
contexts?: UnifiedChatRequest['contexts']
resourceAttachments?: UnifiedChatRequest['resourceAttachments']
userId: string
message: string
workspaceId?: string
chatId?: string
requestId: string
})
| 238 | } |
| 239 | |
| 240 | async function resolveAgentContexts(params: { |
| 241 | contexts?: UnifiedChatRequest['contexts'] |
| 242 | resourceAttachments?: UnifiedChatRequest['resourceAttachments'] |
| 243 | userId: string |
| 244 | message: string |
| 245 | workspaceId?: string |
| 246 | chatId?: string |
| 247 | requestId: string |
| 248 | }): Promise<Array<{ type: string; content: string; tag?: string; path?: string }>> { |
| 249 | const { contexts, resourceAttachments, userId, message, workspaceId, chatId, requestId } = params |
| 250 | |
| 251 | let agentContexts: Array<{ type: string; content: string; tag?: string; path?: string }> = [] |
| 252 | |
| 253 | if (Array.isArray(contexts) && contexts.length > 0) { |
| 254 | try { |
| 255 | agentContexts = await processContextsServer( |
| 256 | contexts as ChatContext[], |
| 257 | userId, |
| 258 | message, |
| 259 | workspaceId, |
| 260 | chatId |
| 261 | ) |
| 262 | } catch (error) { |
| 263 | logger.error(`[${requestId}] Failed to process contexts`, error) |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | if (Array.isArray(resourceAttachments) && resourceAttachments.length > 0 && workspaceId) { |
| 268 | const results = await Promise.allSettled( |
| 269 | resourceAttachments.map(async (resource) => { |
| 270 | const ctx = await resolveActiveResourceContext( |
| 271 | resource.type, |
| 272 | resource.id, |
| 273 | workspaceId, |
| 274 | userId, |
| 275 | chatId |
| 276 | ) |
| 277 | if (!ctx) return null |
| 278 | return { ...ctx, tag: resource.active ? '@active_tab' : '@open_tab' } |
| 279 | }) |
| 280 | ) |
| 281 | |
| 282 | for (const result of results) { |
| 283 | if (result.status === 'fulfilled' && result.value) { |
| 284 | agentContexts.push(result.value) |
| 285 | } else if (result.status === 'rejected') { |
| 286 | logger.error(`[${requestId}] Failed to resolve resource attachment`, result.reason) |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | return agentContexts |
| 292 | } |
| 293 | |
| 294 | async function persistUserMessage(params: { |
| 295 | chatId?: string |
no test coverage detected