mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-22 18:45:19 +02:00
log billing usage
This commit is contained in:
parent
7592df8068
commit
b3a245484f
1 changed files with 13 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { Turn, TurnEvent } from "@/src/entities/models/turn";
|
import { Turn, TurnEvent } from "@/src/entities/models/turn";
|
||||||
import { USE_BILLING } from "@/app/lib/feature_flags";
|
import { USE_BILLING } from "@/app/lib/feature_flags";
|
||||||
import { authorize, getCustomerIdForProject } from "@/app/lib/billing";
|
import { authorize, getCustomerIdForProject, logUsage } from "@/app/lib/billing";
|
||||||
import { NotFoundError } from '@/src/entities/errors/common';
|
import { NotFoundError } from '@/src/entities/errors/common';
|
||||||
import { IConversationsRepository } from "@/src/application/repositories/conversations.repository.interface";
|
import { IConversationsRepository } from "@/src/application/repositories/conversations.repository.interface";
|
||||||
import { streamResponse } from "@/app/lib/agents";
|
import { streamResponse } from "@/app/lib/agents";
|
||||||
|
|
@ -63,14 +63,15 @@ export class RunConversationTurnUseCase implements IRunConversationTurnUseCase {
|
||||||
await this.usageQuotaPolicy.assertAndConsume(projectId);
|
await this.usageQuotaPolicy.assertAndConsume(projectId);
|
||||||
|
|
||||||
// Check billing auth
|
// Check billing auth
|
||||||
|
let billingCustomerId: string | null = null;
|
||||||
if (USE_BILLING) {
|
if (USE_BILLING) {
|
||||||
// get billing customer id for project
|
// get billing customer id for project
|
||||||
const customerId = await getCustomerIdForProject(projectId);
|
billingCustomerId = await getCustomerIdForProject(projectId);
|
||||||
const agentModels = conversation.workflow.agents.reduce((acc, agent) => {
|
const agentModels = conversation.workflow.agents.reduce((acc, agent) => {
|
||||||
acc.push(agent.model);
|
acc.push(agent.model);
|
||||||
return acc;
|
return acc;
|
||||||
}, [] as string[]);
|
}, [] as string[]);
|
||||||
const response = await authorize(customerId, {
|
const response = await authorize(billingCustomerId, {
|
||||||
type: 'agent_response',
|
type: 'agent_response',
|
||||||
data: {
|
data: {
|
||||||
agentModels,
|
agentModels,
|
||||||
|
|
@ -141,5 +142,13 @@ export class RunConversationTurnUseCase implements IRunConversationTurnUseCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log billing usage
|
||||||
|
if (USE_BILLING && billingCustomerId) {
|
||||||
|
await logUsage(billingCustomerId, {
|
||||||
|
type: "agent_messages",
|
||||||
|
amount: outputMessages.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue