import { type Database } from "./database.js"; /** How long a call rings before it counts as missed. */ export declare const AGENT_CALL_RING_SECONDS = 40; /** At most this many calls from one chat within an hour. */ export declare const AGENT_CALL_HOURLY_LIMIT = 3; /** After a decline, the same chat cannot ring that person again for this long. */ export declare const AGENT_CALL_DECLINE_COOLDOWN_MINUTES = 15; /** * An answer that arrives this soon after the deadline still wins (network * latency); a call only counts as missed once this grace has passed too. */ export declare const AGENT_CALL_ANSWER_GRACE_SECONDS = 5; export type AgentCallState = "ringing" | "answered" | "declined" | "missed" | "cancelled"; export type AgentCallOutcome = Exclude; export type AgentCallRow = { id: string; accountId: string; workspaceId: string; sessionId: string; calleeSubjectId: string; callerSubjectId: string | null; callerLabel: string | null; reason: string; state: AgentCallState; devices: number; ringUntil: string; answeredBy: string | null; realtimeId: string | null; createdAt: string; endedAt: string | null; }; export type AgentCallScope = { accountId: string; workspaceId: string; }; /** Why a call did not ring. Each is an expected outcome the agent is told about. */ export type AgentCallRefusal = /** No phone of the callee lets agents call it. */ "no_phone" /** Another call is ringing them right now. */ | "busy" /** This chat already called AGENT_CALL_HOURLY_LIMIT times in the last hour. */ | "rate_limited" /** They declined a call from this chat a moment ago. */ | "declined_recently"; export type PlaceAgentCallResult = { placed: true; call: AgentCallRow; /** Of `call.devices`, the phones Opengeni rang itself (the rest the embedding product rings). */ nativeDevices: number; } | { placed: false; refusal: AgentCallRefusal; }; /** * The phones a product embedding Opengeni rings for agent calls itself, as * the person stated through it (`1143_agent_call_host_phones`). Null when they stated none. */ export type AgentCallHostPhones = { phones: number; teammates: boolean; updatedAt: string; }; /** Most phones a product can state it rings for one person. */ export declare const AGENT_CALL_HOST_PHONES_MAX = 20; export declare function getAgentCallHostPhones(db: Database, input: { accountId: string; subjectId: string; }): Promise; /** * Record how many of the person's phones the embedding product rings for * agents (0 removes them), and whether teammates' agents may ring them. */ export declare function setAgentCallHostPhones(db: Database, input: { accountId: string; subjectId: string; phones: number; teammates: boolean; }): Promise; /** * How many of a person's Opengeni app phones an agent may ring (for their * own agents, or a teammate's). */ export declare function countAgentCallDevices(db: Database, input: { calleeSubjectId: string; member: boolean; }): Promise; /** * Ring the callee's phones, when their settings and the limits allow. The * call row and its rings commit together; the push dispatcher sends them. * `member` is true when the agent works for someone else than the callee. */ export declare function placeAgentCall(db: Database, input: AgentCallScope & { sessionId: string; calleeSubjectId: string; callerSubjectId: string | null; callerLabel: string | null; reason: string; member: boolean; ringSeconds?: number; }): Promise; export declare function getAgentCall(db: Database, input: AgentCallScope & { callId: string; }): Promise; /** * Move a ringing call to its outcome. Only the first transition wins: it * returns the settled call, and every later or late attempt returns null. * An answer must come from the callee within the ring (plus a short grace); * `missed` only applies once the deadline and that grace have passed. */ export declare function settleAgentCall(db: Database, input: AgentCallScope & { callId: string; outcome: AgentCallOutcome; /** The person answering or declining; must be the callee. */ calleeSubjectId?: string; /** The app session that answered. */ answeredBy?: string; }): Promise; /** * The call this person answered in this session moments ago that no voice * call has opened with yet; claims it for `realtimeId`. Runs inside the * realtime start transaction (which holds the workspace RLS context). */ export declare function claimAnsweredAgentCallForRealtimeInTransaction(db: Database, input: AgentCallScope & { sessionId: string; calleeSubjectId: string; realtimeId: string; callId?: string | undefined; withinSeconds?: number; }): Promise;