({
className,
children,
...props
}: ContextInputUsageProps)
| 233 | export type ContextInputUsageProps = ComponentProps<"div">; |
| 234 | |
| 235 | export const ContextInputUsage = ({ |
| 236 | className, |
| 237 | children, |
| 238 | ...props |
| 239 | }: ContextInputUsageProps) => { |
| 240 | const { usage, modelId } = useContextValue(); |
| 241 | const inputTokens = usage?.inputTokens ?? 0; |
| 242 | |
| 243 | if (children) { |
| 244 | return children; |
| 245 | } |
| 246 | |
| 247 | if (!inputTokens) { |
| 248 | return null; |
| 249 | } |
| 250 | |
| 251 | const inputCost = modelId |
| 252 | ? getUsage({ |
| 253 | modelId, |
| 254 | usage: { input: inputTokens, output: 0 }, |
| 255 | }).costUSD?.totalUSD |
| 256 | : undefined; |
| 257 | const inputCostText = new Intl.NumberFormat("en-US", { |
| 258 | currency: "USD", |
| 259 | style: "currency", |
| 260 | }).format(inputCost ?? 0); |
| 261 | |
| 262 | return ( |
| 263 | <div |
| 264 | className={cn("flex items-center justify-between text-xs", className)} |
| 265 | {...props} |
| 266 | > |
| 267 | <span className="text-muted-foreground">Input</span> |
| 268 | <TokensWithCost costText={inputCostText} tokens={inputTokens} /> |
| 269 | </div> |
| 270 | ); |
| 271 | }; |
| 272 | |
| 273 | export type ContextOutputUsageProps = ComponentProps<"div">; |
| 274 |
nothing calls this directly
no test coverage detected