(input: {
provider: Provider.Info
sessionID?: string
timePeriod?: TimePeriod
})
| 440 | } |
| 441 | |
| 442 | async function fetchMinimaxUsage(input: { |
| 443 | provider: Provider.Info |
| 444 | sessionID?: string |
| 445 | timePeriod?: TimePeriod |
| 446 | }): Promise<Omit<Record, "providerID" | "providerName" | "fetchedAt">> { |
| 447 | const sessionData = await fetchSessionUsage(input) |
| 448 | |
| 449 | let limitSummary: |
| 450 | | { |
| 451 | planType?: string |
| 452 | allowed?: boolean |
| 453 | limitReached?: boolean |
| 454 | limits?: { primary?: RateLimitWindowSummary } |
| 455 | } |
| 456 | | undefined |
| 457 | let limitError: string | undefined |
| 458 | |
| 459 | const auth = await Auth.get(input.provider.id) |
| 460 | if (auth?.type === "api" && auth.groupId) { |
| 461 | const apiKey = auth.key || input.provider.key || input.provider.options?.apiKey |
| 462 | if (apiKey) { |
| 463 | limitSummary = await fetchMinimaxUsageLimits(auth.groupId, apiKey).catch((error) => { |
| 464 | limitError = error instanceof Error ? error.message : String(error) |
| 465 | return undefined |
| 466 | }) |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | const record: Omit<Record, "providerID" | "providerName" | "fetchedAt"> = { |
| 471 | ...sessionData, |
| 472 | } |
| 473 | |
| 474 | if (limitSummary) { |
| 475 | record.planType = limitSummary.planType |
| 476 | record.allowed = limitSummary.allowed |
| 477 | record.limitReached = limitSummary.limitReached |
| 478 | record.limits = limitSummary.limits |
| 479 | } |
| 480 | |
| 481 | if (limitError) { |
| 482 | record.error = limitError |
| 483 | } |
| 484 | |
| 485 | return record |
| 486 | } |
| 487 | |
| 488 | async function fetchMinimaxUsageLimits(groupId: string, apiKey: string): Promise<{ |
| 489 | planType?: string |
nothing calls this directly
no test coverage detected