Files
sam 4728c8c253 feat(usage): report model usage per org with identity and cost (#1855)
Model usage was recorded per call and never read, so an org could not see
what it spent. Add the read side:

- model_usage carries identity_id. Task calls take it from the task row,
  chat and curator calls from the calling principal carried in the usage
  record, so an outbox replay keeps its attribution. Existing task rows are
  backfilled from tasks.
- StatsService.UsageTotals sums the caller org's rows by UTC day, source,
  provider, model and identity. The org comes from the principal, with no
  org parameter, so cross-org reads do not exist.
- GET /api/usage prices tokens at the catalog's list rate, netting cache
  hits, and reports calls to unpriced models as tokens only. The published
  catalog view now carries each model's cost.
- A new org Usage page behind a read_usage grant: admin and owner only,
  with a 7, 30 or 90 day range, totals, the daily series, and model, source
  and identity breakdowns. The org shell keeps it on the caller's own org.
2026-11-11 02:15:29 +11:00

274 lines
11 KiB
Go

// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.2
// - protoc (unknown)
// source: state/v1/stats.proto
package statev1
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
StatsService_StatusCounts_FullMethodName = "/state.v1.StatsService/StatusCounts"
StatsService_WorkflowStats_FullMethodName = "/state.v1.StatsService/WorkflowStats"
StatsService_StageStats_FullMethodName = "/state.v1.StatsService/StageStats"
StatsService_TokensByDay_FullMethodName = "/state.v1.StatsService/TokensByDay"
StatsService_UsageTotals_FullMethodName = "/state.v1.StatsService/UsageTotals"
)
// StatsServiceClient is the client API for StatsService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type StatsServiceClient interface {
StatusCounts(ctx context.Context, in *StatusCountsRequest, opts ...grpc.CallOption) (*StatusCountsResponse, error)
WorkflowStats(ctx context.Context, in *WorkflowStatsRequest, opts ...grpc.CallOption) (*WorkflowStatsResponse, error)
StageStats(ctx context.Context, in *StageStatsRequest, opts ...grpc.CallOption) (*StageStatsResponse, error)
TokensByDay(ctx context.Context, in *TokensByDayRequest, opts ...grpc.CallOption) (*TokensByDayResponse, error)
UsageTotals(ctx context.Context, in *UsageTotalsRequest, opts ...grpc.CallOption) (*UsageTotalsResponse, error)
}
type statsServiceClient struct {
cc grpc.ClientConnInterface
}
func NewStatsServiceClient(cc grpc.ClientConnInterface) StatsServiceClient {
return &statsServiceClient{cc}
}
func (c *statsServiceClient) StatusCounts(ctx context.Context, in *StatusCountsRequest, opts ...grpc.CallOption) (*StatusCountsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusCountsResponse)
err := c.cc.Invoke(ctx, StatsService_StatusCounts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *statsServiceClient) WorkflowStats(ctx context.Context, in *WorkflowStatsRequest, opts ...grpc.CallOption) (*WorkflowStatsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(WorkflowStatsResponse)
err := c.cc.Invoke(ctx, StatsService_WorkflowStats_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *statsServiceClient) StageStats(ctx context.Context, in *StageStatsRequest, opts ...grpc.CallOption) (*StageStatsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StageStatsResponse)
err := c.cc.Invoke(ctx, StatsService_StageStats_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *statsServiceClient) TokensByDay(ctx context.Context, in *TokensByDayRequest, opts ...grpc.CallOption) (*TokensByDayResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(TokensByDayResponse)
err := c.cc.Invoke(ctx, StatsService_TokensByDay_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *statsServiceClient) UsageTotals(ctx context.Context, in *UsageTotalsRequest, opts ...grpc.CallOption) (*UsageTotalsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UsageTotalsResponse)
err := c.cc.Invoke(ctx, StatsService_UsageTotals_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// StatsServiceServer is the server API for StatsService service.
// All implementations must embed UnimplementedStatsServiceServer
// for forward compatibility.
type StatsServiceServer interface {
StatusCounts(context.Context, *StatusCountsRequest) (*StatusCountsResponse, error)
WorkflowStats(context.Context, *WorkflowStatsRequest) (*WorkflowStatsResponse, error)
StageStats(context.Context, *StageStatsRequest) (*StageStatsResponse, error)
TokensByDay(context.Context, *TokensByDayRequest) (*TokensByDayResponse, error)
UsageTotals(context.Context, *UsageTotalsRequest) (*UsageTotalsResponse, error)
mustEmbedUnimplementedStatsServiceServer()
}
// UnimplementedStatsServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedStatsServiceServer struct{}
func (UnimplementedStatsServiceServer) StatusCounts(context.Context, *StatusCountsRequest) (*StatusCountsResponse, error) {
return nil, status.Error(codes.Unimplemented, "method StatusCounts not implemented")
}
func (UnimplementedStatsServiceServer) WorkflowStats(context.Context, *WorkflowStatsRequest) (*WorkflowStatsResponse, error) {
return nil, status.Error(codes.Unimplemented, "method WorkflowStats not implemented")
}
func (UnimplementedStatsServiceServer) StageStats(context.Context, *StageStatsRequest) (*StageStatsResponse, error) {
return nil, status.Error(codes.Unimplemented, "method StageStats not implemented")
}
func (UnimplementedStatsServiceServer) TokensByDay(context.Context, *TokensByDayRequest) (*TokensByDayResponse, error) {
return nil, status.Error(codes.Unimplemented, "method TokensByDay not implemented")
}
func (UnimplementedStatsServiceServer) UsageTotals(context.Context, *UsageTotalsRequest) (*UsageTotalsResponse, error) {
return nil, status.Error(codes.Unimplemented, "method UsageTotals not implemented")
}
func (UnimplementedStatsServiceServer) mustEmbedUnimplementedStatsServiceServer() {}
func (UnimplementedStatsServiceServer) testEmbeddedByValue() {}
// UnsafeStatsServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to StatsServiceServer will
// result in compilation errors.
type UnsafeStatsServiceServer interface {
mustEmbedUnimplementedStatsServiceServer()
}
func RegisterStatsServiceServer(s grpc.ServiceRegistrar, srv StatsServiceServer) {
// If the following call panics, it indicates UnimplementedStatsServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&StatsService_ServiceDesc, srv)
}
func _StatsService_StatusCounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(StatusCountsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(StatsServiceServer).StatusCounts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: StatsService_StatusCounts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(StatsServiceServer).StatusCounts(ctx, req.(*StatusCountsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _StatsService_WorkflowStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(WorkflowStatsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(StatsServiceServer).WorkflowStats(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: StatsService_WorkflowStats_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(StatsServiceServer).WorkflowStats(ctx, req.(*WorkflowStatsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _StatsService_StageStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(StageStatsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(StatsServiceServer).StageStats(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: StatsService_StageStats_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(StatsServiceServer).StageStats(ctx, req.(*StageStatsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _StatsService_TokensByDay_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(TokensByDayRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(StatsServiceServer).TokensByDay(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: StatsService_TokensByDay_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(StatsServiceServer).TokensByDay(ctx, req.(*TokensByDayRequest))
}
return interceptor(ctx, in, info, handler)
}
func _StatsService_UsageTotals_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UsageTotalsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(StatsServiceServer).UsageTotals(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: StatsService_UsageTotals_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(StatsServiceServer).UsageTotals(ctx, req.(*UsageTotalsRequest))
}
return interceptor(ctx, in, info, handler)
}
// StatsService_ServiceDesc is the grpc.ServiceDesc for StatsService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var StatsService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "state.v1.StatsService",
HandlerType: (*StatsServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "StatusCounts",
Handler: _StatsService_StatusCounts_Handler,
},
{
MethodName: "WorkflowStats",
Handler: _StatsService_WorkflowStats_Handler,
},
{
MethodName: "StageStats",
Handler: _StatsService_StageStats_Handler,
},
{
MethodName: "TokensByDay",
Handler: _StatsService_TokensByDay_Handler,
},
{
MethodName: "UsageTotals",
Handler: _StatsService_UsageTotals_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "state/v1/stats.proto",
}