chore: Lint extensions folder.

This commit is contained in:
cpojer
2026-01-31 22:13:48 +09:00
parent 4f2166c503
commit 230ca789e2
221 changed files with 4006 additions and 1583 deletions

View File

@@ -1,7 +1,6 @@
import crypto from "node:crypto";
import type { CallId, CallRecord, CallState, NormalizedEvent } from "../types.js";
import { TerminalStates } from "../types.js";
import type { CallRecord, CallState, NormalizedEvent } from "../types.js";
import type { CallManagerContext } from "./context.js";
import { findCall } from "./lookup.js";
import { addTranscriptEntry, transitionState } from "./state.js";
@@ -81,7 +80,9 @@ function createInboundCall(params: {
}
export function processEvent(ctx: CallManagerContext, event: NormalizedEvent): void {
if (ctx.processedEventIds.has(event.id)) return;
if (ctx.processedEventIds.has(event.id)) {
return;
}
ctx.processedEventIds.add(event.id);
let call = findCall({
@@ -107,7 +108,9 @@ export function processEvent(ctx: CallManagerContext, event: NormalizedEvent): v
event.callId = call.callId;
}
if (!call) return;
if (!call) {
return;
}
if (event.providerCallId && !call.providerCallId) {
call.providerCallId = event.providerCallId;
@@ -160,7 +163,9 @@ export function processEvent(ctx: CallManagerContext, event: NormalizedEvent): v
clearMaxDurationTimer(ctx, call.callId);
rejectTranscriptWaiter(ctx, call.callId, `Call ended: ${event.reason}`);
ctx.activeCalls.delete(call.callId);
if (call.providerCallId) ctx.providerCallIdMap.delete(call.providerCallId);
if (call.providerCallId) {
ctx.providerCallIdMap.delete(call.providerCallId);
}
break;
case "call.error":
@@ -171,7 +176,9 @@ export function processEvent(ctx: CallManagerContext, event: NormalizedEvent): v
clearMaxDurationTimer(ctx, call.callId);
rejectTranscriptWaiter(ctx, call.callId, `Call error: ${event.error}`);
ctx.activeCalls.delete(call.callId);
if (call.providerCallId) ctx.providerCallIdMap.delete(call.providerCallId);
if (call.providerCallId) {
ctx.providerCallIdMap.delete(call.providerCallId);
}
}
break;
}

View File

@@ -24,7 +24,9 @@ export function findCall(params: {
callIdOrProviderCallId: string;
}): CallRecord | undefined {
const directCall = params.activeCalls.get(params.callIdOrProviderCallId);
if (directCall) return directCall;
if (directCall) {
return directCall;
}
return getCallByProviderCallId({
activeCalls: params.activeCalls,
providerCallIdMap: params.providerCallIdMap,

View File

@@ -119,9 +119,15 @@ export async function speak(
text: string,
): Promise<{ success: boolean; error?: string }> {
const call = ctx.activeCalls.get(callId);
if (!call) return { success: false, error: "Call not found" };
if (!ctx.provider || !call.providerCallId) return { success: false, error: "Call not connected" };
if (TerminalStates.has(call.state)) return { success: false, error: "Call has ended" };
if (!call) {
return { success: false, error: "Call not found" };
}
if (!ctx.provider || !call.providerCallId) {
return { success: false, error: "Call not connected" };
}
if (TerminalStates.has(call.state)) {
return { success: false, error: "Call has ended" };
}
try {
transitionState(call, "speaking");
@@ -197,9 +203,15 @@ export async function continueCall(
prompt: string,
): Promise<{ success: boolean; transcript?: string; error?: string }> {
const call = ctx.activeCalls.get(callId);
if (!call) return { success: false, error: "Call not found" };
if (!ctx.provider || !call.providerCallId) return { success: false, error: "Call not connected" };
if (TerminalStates.has(call.state)) return { success: false, error: "Call has ended" };
if (!call) {
return { success: false, error: "Call not found" };
}
if (!ctx.provider || !call.providerCallId) {
return { success: false, error: "Call not connected" };
}
if (TerminalStates.has(call.state)) {
return { success: false, error: "Call has ended" };
}
try {
await speak(ctx, callId, prompt);
@@ -227,9 +239,15 @@ export async function endCall(
callId: CallId,
): Promise<{ success: boolean; error?: string }> {
const call = ctx.activeCalls.get(callId);
if (!call) return { success: false, error: "Call not found" };
if (!ctx.provider || !call.providerCallId) return { success: false, error: "Call not connected" };
if (TerminalStates.has(call.state)) return { success: true };
if (!call) {
return { success: false, error: "Call not found" };
}
if (!ctx.provider || !call.providerCallId) {
return { success: false, error: "Call not connected" };
}
if (TerminalStates.has(call.state)) {
return { success: true };
}
try {
await ctx.provider.hangupCall({
@@ -247,7 +265,9 @@ export async function endCall(
rejectTranscriptWaiter(ctx, callId, "Call ended: hangup-bot");
ctx.activeCalls.delete(callId);
if (call.providerCallId) ctx.providerCallIdMap.delete(call.providerCallId);
if (call.providerCallId) {
ctx.providerCallIdMap.delete(call.providerCallId);
}
return { success: true };
} catch (err) {

View File

@@ -13,7 +13,9 @@ const StateOrder: readonly CallState[] = [
export function transitionState(call: CallRecord, newState: CallState): void {
// No-op for same state or already terminal.
if (call.state === newState || TerminalStates.has(call.state)) return;
if (call.state === newState || TerminalStates.has(call.state)) {
return;
}
// Terminal states can always be reached from non-terminal.
if (TerminalStates.has(newState)) {

View File

@@ -32,7 +32,9 @@ export function loadActiveCallsFromStore(storePath: string): {
const callMap = new Map<CallId, CallRecord>();
for (const line of lines) {
if (!line.trim()) continue;
if (!line.trim()) {
continue;
}
try {
const call = CallRecordSchema.parse(JSON.parse(line));
callMap.set(call.callId, call);
@@ -46,7 +48,9 @@ export function loadActiveCallsFromStore(storePath: string): {
const processedEventIds = new Set<string>();
for (const [callId, call] of callMap) {
if (TerminalStates.has(call.state)) continue;
if (TerminalStates.has(call.state)) {
continue;
}
activeCalls.set(callId, call);
if (call.providerCallId) {
providerCallIdMap.set(call.providerCallId, callId);

View File

@@ -40,7 +40,9 @@ export function startMaxDurationTimer(params: {
export function clearTranscriptWaiter(ctx: CallManagerContext, callId: CallId): void {
const waiter = ctx.transcriptWaiters.get(callId);
if (!waiter) return;
if (!waiter) {
return;
}
clearTimeout(waiter.timeout);
ctx.transcriptWaiters.delete(callId);
}
@@ -51,7 +53,9 @@ export function rejectTranscriptWaiter(
reason: string,
): void {
const waiter = ctx.transcriptWaiters.get(callId);
if (!waiter) return;
if (!waiter) {
return;
}
clearTranscriptWaiter(ctx, callId);
waiter.reject(new Error(reason));
}
@@ -62,7 +66,9 @@ export function resolveTranscriptWaiter(
transcript: string,
): void {
const waiter = ctx.transcriptWaiters.get(callId);
if (!waiter) return;
if (!waiter) {
return;
}
clearTranscriptWaiter(ctx, callId);
waiter.resolve(transcript);
}