( contexts: ChatContext[] | undefined, userId: string, userMessage?: string, currentWorkspaceId?: string, chatId?: string )
| 62 | |
| 63 | // Server-side variant (recommended for use in API routes) |
| 64 | export async function processContextsServer( |
| 65 | contexts: ChatContext[] | undefined, |
| 66 | userId: string, |
| 67 | userMessage?: string, |
| 68 | currentWorkspaceId?: string, |
| 69 | chatId?: string |
| 70 | ): Promise<AgentContext[]> { |
| 71 | if (!Array.isArray(contexts) || contexts.length === 0) return [] |
| 72 | const tasks = contexts.map(async (ctx) => { |
| 73 | try { |
| 74 | if (ctx.kind === 'skill' && ctx.skillId && currentWorkspaceId) { |
| 75 | return await processSkillFromDb( |
| 76 | ctx.skillId, |
| 77 | currentWorkspaceId, |
| 78 | ctx.label ? `@${ctx.label}` : '@' |
| 79 | ) |
| 80 | } |
| 81 | if (ctx.kind === 'past_chat' && ctx.chatId) { |
| 82 | return await processPastChatFromDb( |
| 83 | ctx.chatId, |
| 84 | userId, |
| 85 | ctx.label ? `@${ctx.label}` : '@', |
| 86 | currentWorkspaceId |
| 87 | ) |
| 88 | } |
| 89 | if ((ctx.kind === 'workflow' || ctx.kind === 'current_workflow') && ctx.workflowId) { |
| 90 | return await processWorkflowFromDb( |
| 91 | ctx.workflowId, |
| 92 | userId, |
| 93 | ctx.label ? `@${ctx.label}` : '@', |
| 94 | ctx.kind, |
| 95 | currentWorkspaceId, |
| 96 | chatId |
| 97 | ) |
| 98 | } |
| 99 | if (ctx.kind === 'knowledge' && ctx.knowledgeId) { |
| 100 | return await processKnowledgeFromDb( |
| 101 | ctx.knowledgeId, |
| 102 | userId, |
| 103 | ctx.label ? `@${ctx.label}` : '@', |
| 104 | currentWorkspaceId |
| 105 | ) |
| 106 | } |
| 107 | if (ctx.kind === 'blocks' && ctx.blockIds?.length > 0) { |
| 108 | return await processBlockMetadata( |
| 109 | ctx.blockIds[0], |
| 110 | ctx.label ? `@${ctx.label}` : '@', |
| 111 | userId, |
| 112 | currentWorkspaceId |
| 113 | ) |
| 114 | } |
| 115 | if (ctx.kind === 'logs' && ctx.executionId) { |
| 116 | return await processExecutionLogFromDb( |
| 117 | ctx.executionId, |
| 118 | userId, |
| 119 | ctx.label ? `@${ctx.label}` : '@', |
| 120 | currentWorkspaceId |
| 121 | ) |
no test coverage detected