mirror of
https://github.com/cline/cline.git
synced 2026-09-21 05:10:09 +08:00
* Working organization and personal inference, account switching, and usage/credit reporting. * Organization dropdown tweaks (#4710) * organization dropdown tweaks * reverted AuthService * Update Firebase Provider and Auth Service to support re-hydration of the user credentials * Add Github Auth Flow * Fix merge conflicts * Fix some dumb typing * recreate dropdown value when initialized (#4716) * added changeset * Update urls to production and handle some PR concerns * Get user credits when signing in (#4736) * get user balance when signing in instead of when there is no active org * swapped order of getUserCredits, made calls async * async changes continued, moved setIsLoading to finally --------- Co-authored-by: canvrno <46584286+canvrno@users.noreply.github.com> Co-authored-by: pashpashpash <nik@cline.bot>
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import type { Controller } from "../index"
|
|
import { GetOrganizationCreditsRequest, OrganizationCreditsData, OrganizationUsageTransaction } from "@shared/proto/account"
|
|
|
|
/**
|
|
* Handles fetching all organization credits data (balance, usage, payments)
|
|
* @param controller The controller instance
|
|
* @param request Organization credits request
|
|
* @returns Organization credits data response
|
|
*/
|
|
export async function getOrganizationCredits(
|
|
controller: Controller,
|
|
request: GetOrganizationCreditsRequest,
|
|
): Promise<OrganizationCreditsData> {
|
|
try {
|
|
if (!controller.accountService) {
|
|
throw new Error("Account service not available")
|
|
}
|
|
|
|
// Call the individual RPC variants in parallel
|
|
const [balanceData, usageTransactions] = await Promise.all([
|
|
controller.accountService.fetchOrganizationCreditsRPC(request.organizationId),
|
|
controller.accountService.fetchOrganizationUsageTransactionsRPC(request.organizationId),
|
|
])
|
|
|
|
return OrganizationCreditsData.create({
|
|
balance: balanceData ? { currentBalance: balanceData.balance / 100 } : { currentBalance: 0 },
|
|
organizationId: balanceData?.organizationId || "",
|
|
usageTransactions:
|
|
usageTransactions?.map((tx) =>
|
|
OrganizationUsageTransaction.create({
|
|
aiInferenceProviderName: tx.aiInferenceProviderName,
|
|
aiModelName: tx.aiModelName,
|
|
aiModelTypeName: tx.aiModelTypeName,
|
|
completionTokens: tx.completionTokens,
|
|
costUsd: tx.costUsd,
|
|
createdAt: tx.createdAt,
|
|
creditsUsed: tx.creditsUsed,
|
|
generationId: tx.generationId,
|
|
organizationId: tx.organizationId,
|
|
promptTokens: tx.promptTokens,
|
|
totalTokens: tx.totalTokens,
|
|
userId: tx.userId,
|
|
}),
|
|
) || [],
|
|
})
|
|
} catch (error) {
|
|
console.error(`Failed to fetch organization credits data: ${error}`)
|
|
throw error
|
|
}
|
|
}
|