AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { assertNotNullOrUndefined, isNil } from '@activepieces/core-utils'
import { createBullBoard } from '@bull-board/api'
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter'
import { FastifyAdapter } from '@bull-board/fastify'
import basicAuth from '@fastify/basic-auth'
import { FastifyInstance } from 'fastify'
import { runsMetadataQueue } from '../../flows/flow-run/flow-runs-queue'
import { system } from '../../helper/system/system'
import { AppSystemProp } from '../../helper/system/system-props'
import { systemJobsQueue } from '../../helper/system-jobs/system-job'
import { jobQueue } from './job-queue'
const QUEUE_BASE_PATH = '/ui'
const QUEUE_UI_FULL_PATH = `/api${QUEUE_BASE_PATH}`
export async function setupBullMQBoard(app: FastifyInstance): Promise<void> {
const isQueueEnabled = (system.getBoolean(AppSystemProp.QUEUE_UI_ENABLED) ?? false)
if (!isQueueEnabled) {
app.log.info('[setupBullMQBoard] Queue UI is disabled')
return
}
const queueUsername = system.getOrThrow(AppSystemProp.QUEUE_UI_USERNAME)
const queuePassword = system.getOrThrow(AppSystemProp.QUEUE_UI_PASSWORD)
app.log.info(
`[setupBullMQBoard] Setting up bull board, visit ${QUEUE_UI_FULL_PATH} to see the queues`,
)
await app.register(basicAuth, {
validate: (username, password, _req, _reply, done) => {
if (username === queueUsername && password === queuePassword) {
done()
}
else {
done(new Error('Unauthorized'))
}
},
authenticate: true,
})
const jobQueues = jobQueue(app.log).getAllQueues()
assertNotNullOrUndefined(jobQueues.length > 0, 'No job queues available')
assertNotNullOrUndefined(runsMetadataQueue(app.log).get(), 'runsMetadataQueueInstance')
const jobQueueAdapters = jobQueues.map(queue => new BullMQAdapter(queue))
const allQueues = [
...jobQueueAdapters,
new BullMQAdapter(systemJobsQueue),
new BullMQAdapter(runsMetadataQueue(app.log).get()),
]
const serverAdapter = new FastifyAdapter()
createBullBoard({
queues: allQueues,
serverAdapter,
})
serverAdapter.setBasePath(QUEUE_UI_FULL_PATH)
app.addHook('onRequest', (req, reply, next) => {
const routerPath = req.routeOptions.url
assertNotNullOrUndefined(routerPath, 'routerPath is undefined' )
if (!routerPath.startsWith(QUEUE_UI_FULL_PATH)) {
next()
}
else {
app.basicAuth(req, reply, function (error?: unknown) {
const castedError = error as { statusCode: number, name: string }
if (!isNil(castedError)) {
void reply
.code(castedError.statusCode || 500)
.send({ error: castedError.name })
}
else {
next()
}
})
}
})
await app.register(serverAdapter.registerPlugin(), { prefix: QUEUE_BASE_PATH })
}