import type { Logger } from "tslog"; import type { RetellAIPhoneServiceProviderTypeMap } from "../providers/retellAI"; /** * Enum for supported AI phone service providers */ export enum AIPhoneServiceProviderType { RETELL_AI = "retellAI", // Add other providers here as needed } /** * Generic type map for provider-specific types * This allows the interface layer to remain provider-agnostic while supporting type safety * * Usage examples: * - Retell AI provider: AIPhoneServiceProvider * - Generic usage: AIPhoneServiceProvider (defaults to union of all providers) * * Providers implement this by exporting a consolidated type map from their module: * ```typescript * // In providers/retellAI/index.ts * export interface RetellAIPhoneServiceProviderTypeMap { * Configuration: RetellAIConfigurationSetup; * Agent: RetellAgent; * AgentWithDetails: RetellAgentWithDetails; * // ... other types * } * * // In interfaces/AIPhoneService.interface.ts * import type { RetellAIPhoneServiceProviderTypeMap } from "../providers/retellAI"; * * export interface AIPhoneServiceProviderTypeMap { * [AIPhoneServiceProviderType.RETELL_AI]: RetellAIPhoneServiceProviderTypeMap; * } * ``` */ export interface AIPhoneServiceProviderTypeMap { [AIPhoneServiceProviderType.RETELL_AI]: RetellAIPhoneServiceProviderTypeMap; } /** * Generic types that resolve to provider-specific types based on the provider type parameter */ export type AIPhoneServiceConfiguration = AIPhoneServiceProviderTypeMap[T]["Configuration"]; export type AIPhoneServiceUpdateModelParams< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["UpdateModelParams"]; export type AIPhoneServiceModel = AIPhoneServiceProviderTypeMap[T]["Model"]; export type AIPhoneServiceAgent = AIPhoneServiceProviderTypeMap[T]["Agent"]; export type AIPhoneServiceCall = AIPhoneServiceProviderTypeMap[T]["Call"]; export type AIPhoneServicePhoneNumber = AIPhoneServiceProviderTypeMap[T]["PhoneNumber"]; export type AIPhoneServiceUpdatePhoneNumberParams< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["UpdatePhoneNumberParams"]; export type AIPhoneServiceCreatePhoneNumberParams< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["CreatePhoneNumberParams"]; export type AIPhoneServiceImportPhoneNumberParams< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["ImportPhoneNumberParams"]; export type AIPhoneServiceUpdateAgentParams< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["UpdateAgentParams"]; export type AIPhoneServiceTools = AIPhoneServiceProviderTypeMap[T]["Tools"]; export type AIPhoneServiceCreatePhoneCallParams< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["CreatePhoneCallParams"]; export type AIPhoneServiceAgentWithDetails< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["AgentWithDetails"]; export type AIPhoneServiceListCallsParams = AIPhoneServiceProviderTypeMap[T]["ListCallsParams"]; export type AIPhoneServiceListCallsResponse< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["ListCallsResponse"]; export type AIPhoneServiceVoice = AIPhoneServiceProviderTypeMap[T]["Voice"]; export interface AIPhoneServiceDeletion { modelId?: string; agentId?: string; } export interface AIPhoneServiceDeletionResult { success: boolean; errors: string[]; deleted: { model: boolean; agent: boolean; }; } export type AIPhoneServiceCallData = AIPhoneServiceCreatePhoneCallParams; // Extended import phone number params with additional fields export type AIPhoneServiceImportPhoneNumberParamsExtended< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceImportPhoneNumberParams & { userId: number; teamId?: number; agentId?: string | null; }; export interface AIPhoneServiceAgentListItem { id: string; name: string; providerAgentId: string; enabled: boolean; userId: number | null; teamId: number | null; createdAt: Date; updatedAt: Date; outboundPhoneNumbers: { id: number; phoneNumber: string; subscriptionStatus: string | null; provider: string | null; }[]; team: { id: number; name: string | null | undefined; slug: string | null | undefined; } | null; user: { id: number; name: string | null | undefined; email: string | null; } | null; } /** * Generic interface for AI phone service providers * This interface abstracts away provider-specific details using generics */ export interface AIPhoneServiceProvider { /** * Setup AI configuration */ setupConfiguration(config: AIPhoneServiceConfiguration): Promise<{ modelId: string; agentId: string; }>; /** * Delete AI configuration */ deleteConfiguration(config: AIPhoneServiceDeletion): Promise; /** * Update model configuration */ updateModelConfiguration( modelId: string, data: AIPhoneServiceUpdateModelParams ): Promise>; /** * Get model details */ getModelDetails(modelId: string): Promise>; /** * Get agent details */ getAgent(agentId: string): Promise>; /** * Update agent configuration */ updateAgent(agentId: string, data: AIPhoneServiceUpdateAgentParams): Promise>; /** * Create a phone call */ createPhoneCall(data: AIPhoneServiceCallData): Promise>; /** * Create a phone number */ createPhoneNumber( data: AIPhoneServiceCreatePhoneNumberParams ): Promise & { provider: string }>; /** * Delete a phone number */ deletePhoneNumber(params: { phoneNumber: string; userId: number; teamId?: number; deleteFromDB: boolean; }): Promise; /** * Get phone number details */ getPhoneNumber(phoneNumber: string): Promise>; /** * Update phone number configuration */ updatePhoneNumber( phoneNumber: string, data: AIPhoneServiceUpdatePhoneNumberParams ): Promise>; /** * Import a phone number */ importPhoneNumber( data: AIPhoneServiceImportPhoneNumberParamsExtended ): Promise>; /** * Generate a checkout session for phone number subscription */ generatePhoneNumberCheckoutSession(params: { userId: number; teamId?: number; agentId?: string | null; workflowId?: string; }): Promise<{ url: string; message: string }>; /** * Cancel a phone number subscription */ cancelPhoneNumberSubscription(params: { phoneNumberId: number; userId: number; teamId?: number; }): Promise<{ success: boolean; message: string }>; /** * Update phone number with agent assignments */ updatePhoneNumberWithAgents(params: { phoneNumber: string; userId: number; teamId?: number; inboundAgentId?: string | null; outboundAgentId?: string | null; }): Promise<{ message: string }>; /** * List agents with user access */ listAgents(params: { userId: number; teamId?: number; scope?: "personal" | "team" | "all" }): Promise<{ totalCount: number; filtered: AIPhoneServiceAgentListItem[]; }>; /** * Get agent with detailed information */ getAgentWithDetails(params: { id: string; userId: number; teamId?: number; }): Promise>; /** * Create a new agent */ createOutboundAgent(params: { name?: string; userId: number; teamId?: number; workflowStepId?: number; generalPrompt?: string; beginMessage?: string; generalTools?: AIPhoneServiceTools; voiceId?: string; userTimeZone: string; }): Promise<{ id: string; providerAgentId: string; message: string; }>; /** * Create a new inbound agent */ createInboundAgent(params: { name?: string; phoneNumber: string; userId: number; teamId?: number; workflowStepId: number; userTimeZone: string; }): Promise<{ id: string; providerAgentId: string; message: string; }>; /** * Update agent configuration */ updateAgentConfiguration(params: { id: string; userId: number; teamId?: number; name?: string; enabled?: boolean; generalPrompt?: string | null; beginMessage?: string | null; generalTools?: AIPhoneServiceTools; voiceId?: string; language?: string; }): Promise<{ message: string }>; /** * Delete an agent */ deleteAgent(params: { id: string; userId: number; teamId?: number }): Promise<{ message: string }>; /** * Create a test call */ createTestCall(params: { agentId: string; phoneNumber?: string; userId: number; teamId?: number; timeZone: string; eventTypeId: number; }): Promise<{ callId: string; status: string; message: string; }>; /** * Create a web call */ createWebCall(params: { agentId: string; userId: number; teamId?: number; timeZone: string; eventTypeId: number; }): Promise<{ callId: string; accessToken: string; agentId: string; }>; /** * Update tools from event type ID */ updateToolsFromAgentId( agentId: string, data: { eventTypeId: number | null; timeZone: string; userId: number | null; teamId?: number | null } ): Promise; /** * Remove tools for event types */ removeToolsForEventTypes(agentId: string, eventTypeIds: number[]): Promise; /** * List calls with optional filters */ listCalls(params: { limit?: number; offset?: number; filters: { fromNumber: string[]; toNumber?: string[]; startTimestamp?: { lower_threshold?: number; upper_threshold?: number }; }; }): Promise>; /** * List available voices */ listVoices(): Promise[]>; } /** * Configuration for AI phone service providers */ export interface AIPhoneServiceProviderConfig { apiKey?: string; baseUrl?: string; enableLogging?: boolean; logger?: Logger; } /** * Factory interface for creating AI phone service providers */ export interface AIPhoneServiceProviderFactory< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > { create(config: AIPhoneServiceProviderConfig): AIPhoneServiceProvider; }