Skip to content

Commit 039ecec

Browse files
Implement review suggestions
Signed-off-by: Leslie Lazzarino <leslie.lazzarino@gmail.com>
1 parent 99c1368 commit 039ecec

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/__tests__/testUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ export function mockBrowser(args: mockBrowserArgs) {
134134
commands: {
135135
getAll: async () => allShortcuts,
136136
},
137-
// @ts-ignore
138137
alarms: {
139138
create: vi.fn(),
140139
clear: vi.fn(),

src/llmConnection.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ async function callLlmApi(
106106
// Listen to the user's abort signal
107107
const abortHandler = () => combinedAbortController.abort(signal.reason);
108108
signal.addEventListener("abort", abortHandler);
109+
// Handle signals that were already aborted before the listener was registered
110+
if (signal.aborted) {
111+
combinedAbortController.abort(signal.reason);
112+
}
109113

110114
// Set up timeout if specified
111115
if (timeout !== undefined && timeout > 0) {
@@ -119,9 +123,9 @@ async function callLlmApi(
119123
}, timeout);
120124
}
121125

122-
await startKeepAlive();
123126
try {
124-
console.log(`LLM-CONNECTION: Sending request to LLM: POST ${url} with body:\n`, JSON.stringify(requestBody));
127+
await startKeepAlive();
128+
console.log(`LLM-CONNECTION: Sending request to LLM: POST ${url} (body redacted)`);
125129
const response = await fetch(url, {
126130
signal: combinedAbortController.signal,
127131
method: "POST",
@@ -137,12 +141,16 @@ async function callLlmApi(
137141

138142
return responseBody;
139143
} finally {
140-
await stopKeepAlive();
141-
// Clean up
144+
// Synchronous cleanup first to guarantee it always runs
142145
signal.removeEventListener("abort", abortHandler);
143146
if (timeoutId !== undefined) {
144147
clearTimeout(timeoutId);
145148
}
149+
try {
150+
await stopKeepAlive();
151+
} catch (err) {
152+
console.error("LLM-CONNECTION: Error stopping keep-alive:", err);
153+
}
146154
}
147155
}
148156

src/thunderbird-alarms.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ declare namespace browser {
1010
scheduledTime: number;
1111
periodInMinutes?: number;
1212
}
13-
function create(name: string, alarmInfo: { periodInMinutes: number }): void;
13+
function create(
14+
name: string,
15+
alarmInfo: { when?: number; delayInMinutes?: number; periodInMinutes?: number },
16+
): void;
1417
function clear(name: string): Promise<boolean>;
1518
const onAlarm: WebExtEvent<(alarm: Alarm) => void>;
1619
}
@@ -23,7 +26,10 @@ declare namespace messenger {
2326
scheduledTime: number;
2427
periodInMinutes?: number;
2528
}
26-
function create(name: string, alarmInfo: { periodInMinutes: number }): void;
29+
function create(
30+
name: string,
31+
alarmInfo: { when?: number; delayInMinutes?: number; periodInMinutes?: number },
32+
): void;
2733
function clear(name: string): Promise<boolean>;
2834
const onAlarm: WebExtEvent<(alarm: Alarm) => void>;
2935
}

0 commit comments

Comments
 (0)