ai-details.ts59 lines · main
| 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 | |
| 9 | export const getOrgAIDetails = async ({ |
| 10 | orgSlug, |
| 11 | authorization, |
| 12 | }: { |
| 13 | orgSlug: string |
| 14 | authorization: string |
| 15 | }) => { |
| 16 | const headers = { |
| 17 | 'Content-Type': 'application/json', |
| 18 | ...(authorization && { Authorization: authorization }), |
| 19 | } |
| 20 | |
| 21 | const [organizations, subscription, advanceModelAccess] = await Promise.all([ |
| 22 | getOrganizations({ headers }), |
| 23 | getOrgSubscription({ orgSlug }, undefined, headers), |
| 24 | checkEntitlement(orgSlug, 'assistant.advance_model', undefined, headers), |
| 25 | ]) |
| 26 | |
| 27 | const selectedOrg = organizations.find((org) => org.slug === orgSlug) |
| 28 | |
| 29 | return { |
| 30 | aiOptInLevel: getAiOptInLevel(selectedOrg?.opt_in_tags), |
| 31 | hasAccessToAdvanceModel: advanceModelAccess.hasAccess, |
| 32 | hasHipaaAddon: subscriptionHasHipaaAddon(subscription), |
| 33 | orgId: selectedOrg?.id, |
| 34 | planId: selectedOrg?.plan.id, |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export const getProjectAIDetails = async ({ |
| 39 | projectRef, |
| 40 | authorization, |
| 41 | }: { |
| 42 | projectRef: string |
| 43 | authorization: string |
| 44 | }) => { |
| 45 | const headers = { |
| 46 | 'Content-Type': 'application/json', |
| 47 | ...(authorization && { Authorization: authorization }), |
| 48 | } |
| 49 | |
| 50 | const [selectedProject, projectSettings] = await Promise.all([ |
| 51 | getProjectDetail({ ref: projectRef }, undefined, headers), |
| 52 | getProjectSettings({ projectRef }, undefined, headers), |
| 53 | ]) |
| 54 | |
| 55 | return { |
| 56 | region: selectedProject?.region, |
| 57 | isSensitive: projectSettings?.is_sensitive, |
| 58 | } |
| 59 | } |