Files
calendar/packages/features/calAIPhone/interfaces/AIPhoneService.interface.ts
T
d4bff9d6b1 feat: Cal.ai Self Serve #2 (#22995)
* feat: Cal.ai Self Serve #2

* chore: fix import and remove logs

* fix: update checkout session

* fix: type errors and test

* fix: imports

* fix: type err

* fix: type error

* fix: tests

* chore: save progress

* fix: workflow flow

* fix: workflow update bug

* tests: add unit tests for retell ai webhoo

* fix: status code

* fix: test and delete bug

* fix: add dynamic variables

* fix: type err

* chore: update unit test

* fix: type error

* chore: update default prompt

* fix: type errors

* fix: workflow permissions

* fix: workflow page

* fix: translations

* feat: add call duration

* chore: add booking uid

* fix: button positioning

* chore: update tests

* chore: improvements

* chore: some more improvements

* refactor: improvements

* refactor: code feedback

* refactor: improvements

* feat: enable credits for orgs (#23077)

* Show credits UI for orgs

* fix stripe callback url when buying credits

* give orgs 20% credits

* add test for calulating credits

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>

* fix: types

* fix: types

* chore: error

* fix: type error

* fix: type error

* chore: mock env

* feat: add idempotency key to prevent double charging

* chore: add userId and teamId

* fix: skip inbound calls

* chore: update tests

* feat: add feature flag for voice agent

* feat: finish test call and other improvements

* chore: add alert

* chore: update .env.example

* chore: improvements

* fix: update tests

* refactor: remove un necessary

* feat: add setup badge

* chore: improvements

* fix: use referene id

* chore: improvements

* fix: type error

* fix: type

* refactor: change pricing logic

* refactor: update tests

* fix: conflicts

* fix: billing link for orgs

* fix: types

* refactor: move feature flag up

* fix: alert and test call credit check

* fix: update unit tests

* fix: feedback

* refactor: improvements

* refactor: move handlers to separate files

* fix: types

* fix: missing import

* fix: type

* refactor: change general tools functions handling

* refactor: use repository

* refactor: improvements

* fix: types

* fix: type errorr

* fix: auth check

* feat: add creditFor

* fix: update defualt prompt

* fix: throw error on frontend

* fix: update unit tests

* fix: use deleteAllWorkflowReminders

* refactor: add connect phone number

* refactor: improvements

* chore: translation

* chore: update message

* chore: translation

* design improvements buy number dialog

* add translation for error message

* use translation key in error message

* refactor: improve connect phone number tab

* feat: support un saved workflow to tests

* chore: remove un used

* fix: remove un used

* fix: remove un used

* refactor: similify billing

---------

Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2025-08-29 05:04:05 +01:00

362 lines
9.9 KiB
TypeScript

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<AIPhoneServiceProviderType.RETELL_AI>
* - 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<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> =
AIPhoneServiceProviderTypeMap[T]["Configuration"];
export type AIPhoneServiceUpdateModelParams<
T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType
> = AIPhoneServiceProviderTypeMap[T]["UpdateModelParams"];
export type AIPhoneServiceModel<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> =
AIPhoneServiceProviderTypeMap[T]["Model"];
export type AIPhoneServiceAgent<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> =
AIPhoneServiceProviderTypeMap[T]["Agent"];
export type AIPhoneServiceCall<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> =
AIPhoneServiceProviderTypeMap[T]["Call"];
export type AIPhoneServicePhoneNumber<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> =
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<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> =
AIPhoneServiceProviderTypeMap[T]["Tools"];
export type AIPhoneServiceCreatePhoneCallParams<
T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType
> = AIPhoneServiceProviderTypeMap[T]["CreatePhoneCallParams"];
export type AIPhoneServiceAgentWithDetails<
T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType
> = AIPhoneServiceProviderTypeMap[T]["AgentWithDetails"];
export interface AIPhoneServiceDeletion {
modelId?: string;
agentId?: string;
}
export interface AIPhoneServiceDeletionResult {
success: boolean;
errors: string[];
deleted: {
model: boolean;
agent: boolean;
};
}
export type AIPhoneServiceCallData<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> =
AIPhoneServiceCreatePhoneCallParams<T>;
// Extended import phone number params with additional fields
export type AIPhoneServiceImportPhoneNumberParamsExtended<
T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType
> = AIPhoneServiceImportPhoneNumberParams<T> & {
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<T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType> {
/**
* Setup AI configuration
*/
setupConfiguration(config: AIPhoneServiceConfiguration<T>): Promise<{
modelId: string;
agentId: string;
}>;
/**
* Delete AI configuration
*/
deleteConfiguration(config: AIPhoneServiceDeletion): Promise<AIPhoneServiceDeletionResult>;
/**
* Update model configuration
*/
updateModelConfiguration(
modelId: string,
data: AIPhoneServiceUpdateModelParams<T>
): Promise<AIPhoneServiceModel<T>>;
/**
* Get model details
*/
getModelDetails(modelId: string): Promise<AIPhoneServiceModel<T>>;
/**
* Get agent details
*/
getAgent(agentId: string): Promise<AIPhoneServiceAgent<T>>;
/**
* Update agent configuration
*/
updateAgent(agentId: string, data: AIPhoneServiceUpdateAgentParams<T>): Promise<AIPhoneServiceAgent<T>>;
/**
* Create a phone call
*/
createPhoneCall(data: AIPhoneServiceCallData<T>): Promise<AIPhoneServiceCall<T>>;
/**
* Create a phone number
*/
createPhoneNumber(
data: AIPhoneServiceCreatePhoneNumberParams<T>
): Promise<AIPhoneServicePhoneNumber<T> & { provider: string }>;
/**
* Delete a phone number
*/
deletePhoneNumber(params: {
phoneNumber: string;
userId: number;
teamId?: number;
deleteFromDB: boolean;
}): Promise<void>;
/**
* Get phone number details
*/
getPhoneNumber(phoneNumber: string): Promise<AIPhoneServicePhoneNumber<T>>;
/**
* Update phone number configuration
*/
updatePhoneNumber(
phoneNumber: string,
data: AIPhoneServiceUpdatePhoneNumberParams<T>
): Promise<AIPhoneServicePhoneNumber<T>>;
/**
* Import a phone number
*/
importPhoneNumber(
data: AIPhoneServiceImportPhoneNumberParamsExtended<T>
): Promise<AIPhoneServicePhoneNumber<T>>;
/**
* 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<AIPhoneServiceAgentWithDetails<T>>;
/**
* Create a new agent
*/
createAgent(params: {
name?: string;
userId: number;
teamId?: number;
workflowStepId?: number;
generalPrompt?: string;
beginMessage?: string;
generalTools?: AIPhoneServiceTools<T>;
voiceId?: string;
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<T>;
voiceId?: 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;
}>;
/**
* Update tools from event type ID
*/
updateToolsFromAgentId(
agentId: string,
data: { eventTypeId: number | null; timeZone: string; userId: number | null; teamId?: number | null }
): Promise<void>;
/**
* Remove tools for event types
*/
removeToolsForEventTypes(agentId: string, eventTypeIds: number[]): Promise<void>;
}
/**
* Configuration for AI phone service providers
*/
export interface AIPhoneServiceProviderConfig {
apiKey?: string;
baseUrl?: string;
enableLogging?: boolean;
logger?: Logger<unknown>;
}
/**
* Factory interface for creating AI phone service providers
*/
export interface AIPhoneServiceProviderFactory<
T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType
> {
create(config: AIPhoneServiceProviderConfig): AIPhoneServiceProvider<T>;
}