ai-details.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { subscriptionHasHipaaAddon } from '@/components/interfaces/Billing/Subscription/Subscription.utils'
  2. import { getProjectSettings } from '@/data/config/project-settings-v2-query'
  3. import { checkEntitlement } from '@/data/entitlements/entitlements-query'
  4. import { getOrganizations } from '@/data/organizations/organizations-query'
  5. import { getProjectDetail } from '@/data/projects/project-detail-query'
  6. import { getOrgSubscription } from '@/data/subscriptions/org-subscription-query'
  7. import { getAiOptInLevel } from '@/hooks/misc/useOrgOptedIntoAi'
  8. export const getOrgAIDetails = async ({
  9. orgSlug,
  10. authorization,
  11. }: {
  12. orgSlug: string
  13. authorization: string
  14. }) => {
  15. const headers = {
  16. 'Content-Type': 'application/json',
  17. ...(authorization && { Authorization: authorization }),
  18. }
  19. const [organizations, subscription, advanceModelAccess] = await Promise.all([
  20. getOrganizations({ headers }),
  21. getOrgSubscription({ orgSlug }, undefined, headers),
  22. checkEntitlement(orgSlug, 'assistant.advance_model', undefined, headers),
  23. ])
  24. const selectedOrg = organizations.find((org) => org.slug === orgSlug)
  25. return {
  26. aiOptInLevel: getAiOptInLevel(selectedOrg?.opt_in_tags),
  27. hasAccessToAdvanceModel: advanceModelAccess.hasAccess,
  28. hasHipaaAddon: subscriptionHasHipaaAddon(subscription),
  29. orgId: selectedOrg?.id,
  30. planId: selectedOrg?.plan.id,
  31. }
  32. }
  33. export const getProjectAIDetails = async ({
  34. projectRef,
  35. authorization,
  36. }: {
  37. projectRef: string
  38. authorization: string
  39. }) => {
  40. const headers = {
  41. 'Content-Type': 'application/json',
  42. ...(authorization && { Authorization: authorization }),
  43. }
  44. const [selectedProject, projectSettings] = await Promise.all([
  45. getProjectDetail({ ref: projectRef }, undefined, headers),
  46. getProjectSettings({ projectRef }, undefined, headers),
  47. ])
  48. return {
  49. region: selectedProject?.region,
  50. isSensitive: projectSettings?.is_sensitive,
  51. }
  52. }