|
| 1 | +import { Button } from "components/Button/Button"; |
| 2 | +import { |
| 3 | + Collapsible, |
| 4 | + CollapsibleContent, |
| 5 | + CollapsibleTrigger, |
| 6 | +} from "components/Collapsible/Collapsible"; |
| 7 | +import { Link } from "components/Link/Link"; |
| 8 | +import { Stack } from "components/Stack/Stack"; |
| 9 | +import { ChevronRightIcon } from "lucide-react"; |
| 10 | +import type { FC } from "react"; |
| 11 | +import { Link as RouterLink } from "react-router-dom"; |
| 12 | +import { docs } from "utils/docs"; |
| 13 | +import MuiLink from "@mui/material/Link"; |
| 14 | +import { type Interpolation, type Theme } from "@emotion/react"; |
| 15 | +import dayjs from "dayjs"; |
| 16 | + |
| 17 | +interface ManagedAgentsConsumptionProps { |
| 18 | + usage: number; |
| 19 | + included: number; |
| 20 | + limit: number; |
| 21 | + startDate: string; |
| 22 | + endDate: string; |
| 23 | + enabled?: boolean; |
| 24 | +} |
| 25 | + |
| 26 | +export const ManagedAgentsConsumption: FC<ManagedAgentsConsumptionProps> = ({ |
| 27 | + usage, |
| 28 | + included, |
| 29 | + limit, |
| 30 | + startDate, |
| 31 | + endDate, |
| 32 | + enabled = true, |
| 33 | +}) => { |
| 34 | + // If feature is disabled, show disabled state |
| 35 | + if (!enabled) { |
| 36 | + return ( |
| 37 | + <div css={styles.disabledRoot}> |
| 38 | + <Stack alignItems="center" spacing={1}> |
| 39 | + <Stack alignItems="center" spacing={0.5}> |
| 40 | + <span css={styles.disabledTitle}> |
| 41 | + Managed AI Agent Feature Disabled |
| 42 | + </span> |
| 43 | + <span css={styles.disabledDescription}> |
| 44 | + The managed AI agent feature is not included in your current license. |
| 45 | + Contact{" "} |
| 46 | + <MuiLink href="mailto:sales@coder.com">sales</MuiLink> to |
| 47 | + upgrade your license and unlock this feature. |
| 48 | + </span> |
| 49 | + </Stack> |
| 50 | + </Stack> |
| 51 | + </div> |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + // Calculate percentages for the progress bar |
| 56 | + const usagePercentage = Math.min((usage / limit) * 100, 100); |
| 57 | + const includedPercentage = Math.min((included / limit) * 100, 100); |
| 58 | + const remainingPercentage = Math.max(100 - includedPercentage, 0); |
| 59 | + |
| 60 | + return ( |
| 61 | + <section className="border border-solid rounded"> |
| 62 | + <div className="p-4"> |
| 63 | + <Collapsible> |
| 64 | + <header className="flex flex-col gap-2 items-start"> |
| 65 | + <h3 className="text-md m-0 font-medium"> |
| 66 | + Managed agents consumption |
| 67 | + </h3> |
| 68 | + |
| 69 | + <CollapsibleTrigger asChild> |
| 70 | + <Button |
| 71 | + className={` |
| 72 | + h-auto p-0 border-0 bg-transparent font-medium text-content-secondary |
| 73 | + hover:bg-transparent hover:text-content-primary |
| 74 | + [&[data-state=open]_svg]:rotate-90 |
| 75 | + `} |
| 76 | + > |
| 77 | + <ChevronRightIcon /> |
| 78 | + How we calculate managed agent consumption |
| 79 | + </Button> |
| 80 | + </CollapsibleTrigger> |
| 81 | + </header> |
| 82 | + |
| 83 | + <CollapsibleContent |
| 84 | + className={` |
| 85 | + pt-2 pl-7 pr-5 space-y-4 font-medium max-w-[720px] |
| 86 | + text-sm text-content-secondary |
| 87 | + [&_p]:m-0 [&_ul]:m-0 [&_ul]:p-0 [&_ul]:list-none |
| 88 | + `} |
| 89 | + > |
| 90 | + <p> |
| 91 | + Managed agents are counted based on active agent connections during the billing period. |
| 92 | + Each unique agent that connects to your deployment consumes one managed agent seat. |
| 93 | + </p> |
| 94 | + <ul> |
| 95 | + <li className="flex items-center gap-2"> |
| 96 | + <div |
| 97 | + className="rounded-[2px] bg-highlight-green size-3 inline-block" |
| 98 | + aria-label="Legend for current usage in the chart" |
| 99 | + /> |
| 100 | + Current usage represents active managed agents during this period. |
| 101 | + </li> |
| 102 | + <li className="flex items-center gap-2"> |
| 103 | + <div |
| 104 | + className="rounded-[2px] bg-content-disabled size-3 inline-block" |
| 105 | + aria-label="Legend for included allowance in the chart" |
| 106 | + /> |
| 107 | + Included allowance from your current license plan. |
| 108 | + </li> |
| 109 | + <li className="flex items-center gap-2"> |
| 110 | + <div |
| 111 | + className="size-3 inline-flex items-center justify-center" |
| 112 | + aria-label="Legend for total limit in the chart" |
| 113 | + > |
| 114 | + <div className="w-full border-b-1 border-t-1 border-dashed border-content-disabled" /> |
| 115 | + </div> |
| 116 | + Total limit including any additional purchased capacity. |
| 117 | + </li> |
| 118 | + </ul> |
| 119 | + <div> |
| 120 | + You might also check: |
| 121 | + <ul> |
| 122 | + <li> |
| 123 | + <Link asChild> |
| 124 | + <RouterLink to="/deployment/overview"> |
| 125 | + Deployment overview |
| 126 | + </RouterLink> |
| 127 | + </Link> |
| 128 | + </li> |
| 129 | + <li> |
| 130 | + <Link |
| 131 | + href={docs("/admin/managed-agents")} |
| 132 | + target="_blank" |
| 133 | + rel="noreferrer" |
| 134 | + > |
| 135 | + More details on managed agents |
| 136 | + </Link> |
| 137 | + </li> |
| 138 | + </ul> |
| 139 | + </div> |
| 140 | + </CollapsibleContent> |
| 141 | + </Collapsible> |
| 142 | + </div> |
| 143 | + |
| 144 | + <div className="p-6 border-0 border-t border-solid"> |
| 145 | + {/* Date range */} |
| 146 | + <div className="flex justify-between text-sm text-content-secondary mb-4"> |
| 147 | + <span>{startDate ? dayjs(startDate).format("MMMM D, YYYY") : ""}</span> |
| 148 | + <span>{endDate ? dayjs(endDate).format("MMMM D, YYYY") : ""}</span> |
| 149 | + </div> |
| 150 | + |
| 151 | + {/* Progress bar container */} |
| 152 | + <div className="relative h-6 bg-surface-secondary rounded overflow-hidden"> |
| 153 | + {/* Usage bar (green) */} |
| 154 | + <div |
| 155 | + className="absolute top-0 left-0 h-full bg-highlight-green transition-all duration-300" |
| 156 | + style={{ width: `${usagePercentage}%` }} |
| 157 | + /> |
| 158 | + |
| 159 | + {/* Included allowance background (darker) */} |
| 160 | + <div |
| 161 | + className="absolute top-0 h-full bg-content-disabled opacity-30" |
| 162 | + style={{ |
| 163 | + left: `${includedPercentage}%`, |
| 164 | + width: `${remainingPercentage}%`, |
| 165 | + }} |
| 166 | + /> |
| 167 | + </div> |
| 168 | + |
| 169 | + {/* Labels */} |
| 170 | + <div className="flex justify-between mt-4 text-sm"> |
| 171 | + <div className="flex flex-col items-start"> |
| 172 | + <span className="text-content-secondary">Usage:</span> |
| 173 | + <span className="font-medium">{usage.toLocaleString()}</span> |
| 174 | + </div> |
| 175 | + <div className="flex flex-col items-center"> |
| 176 | + <span className="text-content-secondary">Included:</span> |
| 177 | + <span className="font-medium">{included.toLocaleString()}</span> |
| 178 | + </div> |
| 179 | + <div className="flex flex-col items-end"> |
| 180 | + <span className="text-content-secondary">Limit:</span> |
| 181 | + <span className="font-medium">{limit.toLocaleString()}</span> |
| 182 | + </div> |
| 183 | + </div> |
| 184 | + </div> |
| 185 | + </section> |
| 186 | + ); |
| 187 | +}; |
| 188 | + |
| 189 | +const styles = { |
| 190 | + disabledTitle: { |
| 191 | + fontSize: 16, |
| 192 | + }, |
| 193 | + |
| 194 | + disabledRoot: (theme) => ({ |
| 195 | + minHeight: 240, |
| 196 | + display: "flex", |
| 197 | + alignItems: "center", |
| 198 | + justifyContent: "center", |
| 199 | + borderRadius: 8, |
| 200 | + border: `1px solid ${theme.palette.divider}`, |
| 201 | + padding: 48, |
| 202 | + }), |
| 203 | + |
| 204 | + disabledDescription: (theme) => ({ |
| 205 | + color: theme.palette.text.secondary, |
| 206 | + textAlign: "center", |
| 207 | + maxWidth: 464, |
| 208 | + marginTop: 8, |
| 209 | + }), |
| 210 | +} satisfies Record<string, Interpolation<Theme>>; |
0 commit comments