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 { ApId } from '@activepieces/core-utils'
import { CreatePlatformModelTierRequest, DeletePlatformModelTierRequest, PlatformModelTier, PlatformModelTierSummary, PrincipalType, ReorderPlatformModelTiersRequest, SERVICE_KEY_SECURITY_OPENAPI, UpdatePlatformModelTierRequest } from '@activepieces/shared'
import { FastifyRequest } from 'fastify'
import { FastifyPluginAsyncZod } from 'fastify-type-provider-zod'
import { StatusCodes } from 'http-status-codes'
import { z } from 'zod'
import { ProjectResourceType } from '../core/security/authorization/common'
import { securityAccess } from '../core/security/authorization/fastify-security'
import { aiProviderService } from './ai-provider-service'
import { platformModelTierService } from './platform-model-tier-service'
export const platformModelTierController: FastifyPluginAsyncZod = async (app) => {
app.get('/', ListPlatformModelTiers, async (request) => {
return platformModelTierService.listSummaries({ platformId: request.principal.platform.id, scope: { type: 'project', projectId: request.projectId } })
})
app.get('/admin', ListPlatformModelTiersForAdmin, async (request) => {
return platformModelTierService.list({ platformId: request.principal.platform.id })
})
app.post('/', CreatePlatformModelTier, async (request) => {
return platformModelTierService.create({ platformId: request.principal.platform.id, request: request.body })
})
app.post('/reorder', ReorderPlatformModelTiers, async (request) => {
return platformModelTierService.reorder({ platformId: request.principal.platform.id, tierIds: request.body.tierIds })
})
app.post('/:id', UpdatePlatformModelTier, async (request) => {
return platformModelTierService.update({ platformId: request.principal.platform.id, id: request.params.id, request: request.body })
})
app.delete('/:id', DeletePlatformModelTier, async (request, reply) => {
await platformModelTierService.delete({ platformId: request.principal.platform.id, id: request.params.id, replacedBy: request.query.replacedBy })
return reply.status(StatusCodes.NO_CONTENT).send()
})
}
const TierIdParams = z.object({
id: ApId,
})
const ListPlatformModelTiers = {
config: {
security: securityAccess.project([PrincipalType.USER, PrincipalType.ENGINE], undefined, { type: ProjectResourceType.QUERY }),
},
schema: {
querystring: z.object({
projectId: z.string().optional(),
}),
response: {
[StatusCodes.OK]: z.array(PlatformModelTierSummary),
},
},
}
const ListPlatformModelTiersForAdmin = {
config: {
security: securityAccess.platformAdminOnly([PrincipalType.USER, PrincipalType.SERVICE]),
},
schema: {
tags: ['ai-model-tiers'],
security: [SERVICE_KEY_SECURITY_OPENAPI],
description: 'List the platform model tiers with their main model and fallbacks.',
response: {
[StatusCodes.OK]: z.array(PlatformModelTier),
},
},
}
const CreatePlatformModelTier = {
config: {
security: securityAccess.platformAdminOnly([PrincipalType.USER, PrincipalType.SERVICE]),
},
preHandler: (request: FastifyRequest): Promise<void> => aiProviderService(request.log).assertAiProvidersPlan(request.principal.platform.id),
schema: {
tags: ['ai-model-tiers'],
security: [SERVICE_KEY_SECURITY_OPENAPI],
description: 'Create a model tier: a named main model with fallbacks that builders pick.',
body: CreatePlatformModelTierRequest,
response: {
[StatusCodes.OK]: PlatformModelTier,
},
},
}
const ReorderPlatformModelTiers = {
config: {
security: securityAccess.platformAdminOnly([PrincipalType.USER, PrincipalType.SERVICE]),
},
preHandler: (request: FastifyRequest): Promise<void> => aiProviderService(request.log).assertAiProvidersPlan(request.principal.platform.id),
schema: {
tags: ['ai-model-tiers'],
security: [SERVICE_KEY_SECURITY_OPENAPI],
description: 'Set the order tiers appear in for builders.',
body: ReorderPlatformModelTiersRequest,
response: {
[StatusCodes.OK]: z.array(PlatformModelTier),
},
},
}
const UpdatePlatformModelTier = {
config: {
security: securityAccess.platformAdminOnly([PrincipalType.USER, PrincipalType.SERVICE]),
},
preHandler: (request: FastifyRequest): Promise<void> => aiProviderService(request.log).assertAiProvidersPlan(request.principal.platform.id),
schema: {
tags: ['ai-model-tiers'],
security: [SERVICE_KEY_SECURITY_OPENAPI],
description: 'Update a model tier: its name, models, fallbacks or default flags.',
params: TierIdParams,
body: UpdatePlatformModelTierRequest,
response: {
[StatusCodes.OK]: PlatformModelTier,
},
},
}
const DeletePlatformModelTier = {
config: {
security: securityAccess.platformAdminOnly([PrincipalType.USER, PrincipalType.SERVICE]),
},
schema: {
tags: ['ai-model-tiers'],
security: [SERVICE_KEY_SECURITY_OPENAPI],
description: 'Delete a model tier.',
params: TierIdParams,
querystring: DeletePlatformModelTierRequest,
response: {
[StatusCodes.NO_CONTENT]: z.never(),
},
},
}