All files / src/entities agent_token_usage.ts

91.17% Statements 31/34
0% Branches 0/8
50% Functions 1/2
90.62% Lines 29/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 891x 1x 1x 1x 1x 1x             1x 1x 1x 1x   1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x                                     1x  
import { Entity } from '../entity.js';
import { Company } from './company.js';
import { Domain } from './domain.js';
import { User } from './user.js';
import { AgentConversation } from './agent_conversation.js';
import { SupportConversation } from './support_conversation.js';
import type {
  AgentTokenUsageRecordPayload,
  AgentTokenUsageRecordResponse,
} from './agent_token_analytics.js';
import type { RequestOptions } from '../request.js';
 
export class AgentTokenUsage extends Entity {
  protected static resourceName = 'agent_token_usage';
  protected static singularName = 'agentTokenUsage';
  protected static pluralName = 'agentTokenUsage';
 
  @AgentTokenUsage.property()
  public id?: number;
 
  @AgentTokenUsage.property({type: Date})
  public createdAt?: Date | null;
 
  @AgentTokenUsage.property()
  public companyId?: number;
 
  @AgentTokenUsage.property()
  public domainId?: number;
 
  @AgentTokenUsage.property()
  public userId?: number;
 
  @AgentTokenUsage.property({type: Company})
  public company?: Company | null;
 
  @AgentTokenUsage.property({type: Domain})
  public domain?: Domain | null;
 
  @AgentTokenUsage.property({type: User})
  public user?: User | null;
 
  @AgentTokenUsage.property({type: AgentConversation})
  public agentConversation?: AgentConversation | null;
 
  @AgentTokenUsage.property({type: SupportConversation})
  public supportConversation?: SupportConversation | null;
 
  @AgentTokenUsage.property()
  public agentConversationId?: number;
 
  @AgentTokenUsage.property()
  public supportConversationId?: number;
 
  @AgentTokenUsage.property()
  public sourceType?: string;
 
  @AgentTokenUsage.property()
  public modelName?: string;
 
  @AgentTokenUsage.property()
  public promptTokens?: number;
 
  @AgentTokenUsage.property()
  public completionTokens?: number;
 
  @AgentTokenUsage.property()
  public totalTokens?: number;
 
  public static record = (
    payload: AgentTokenUsageRecordPayload,
    fetchOptions?: RequestOptions
  ): Promise<AgentTokenUsageRecordResponse> => {
    const Constructor = this as typeof AgentTokenUsage;
    const fetchOpts: RequestOptions = {
      ...(fetchOptions || {}),
      method: 'POST',
      body: JSON.stringify(payload),
      headers: {
        ...(fetchOptions?.headers || {}),
        'Content-Type': 'application/json',
      },
    };
    return Constructor.merchi.authenticatedFetch(
      '/agent_token_usage/',
      fetchOpts
    ) as Promise<AgentTokenUsageRecordResponse>;
  };
}