Skip to content

Commit 167e474

Browse files
committed
fix: update recording endpoints and fix recall initialization
1 parent 0a87688 commit 167e474

File tree

5 files changed

+101
-80
lines changed

5 files changed

+101
-80
lines changed

src/api/posthogClient.ts

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,6 @@ export class PostHogAPIClient {
321321
return await response.json();
322322
}
323323

324-
async getDesktopRecordingTranscript(recordingId: string) {
325-
this.validateRecordingId(recordingId);
326-
const teamId = await this.getTeamId();
327-
const url = new URL(
328-
`${this.api.baseUrl}/api/environments/${teamId}/desktop_recordings/${recordingId}/transcript/`,
329-
);
330-
const response = await this.api.fetcher.fetch({
331-
method: "get",
332-
url,
333-
path: `/api/environments/${teamId}/desktop_recordings/${recordingId}/transcript/`,
334-
});
335-
336-
if (!response.ok) {
337-
throw new Error(`Failed to fetch transcript: ${response.statusText}`);
338-
}
339-
340-
return await response.json();
341-
}
342-
343324
async listDesktopRecordings(filters?: {
344325
platform?: string;
345326
status?: string;
@@ -405,28 +386,18 @@ export class PostHogAPIClient {
405386
return data;
406387
}
407388

408-
async updateDesktopRecordingTranscript(
389+
async appendSegments(
409390
recordingId: string,
410-
updates: {
411-
segments?: Array<{
412-
timestamp_ms: number;
413-
speaker: string | null;
414-
text: string;
415-
confidence: number | null;
416-
is_final: boolean;
417-
}>;
418-
full_text?: string;
419-
},
420-
) {
391+
segments: Array<Schemas.TranscriptSegment>,
392+
): Promise<Schemas.DesktopRecording> {
421393
this.validateRecordingId(recordingId);
422394
const teamId = await this.getTeamId();
423395

424396
const data = await this.api.post(
425-
//@ts-expect-error not in the generated client
426-
"/api/environments/{project_id}/desktop_recordings/{id}/transcript/",
397+
"/api/environments/{project_id}/desktop_recordings/{id}/append_segments/",
427398
{
428399
path: { project_id: teamId.toString(), id: recordingId },
429-
body: updates as any,
400+
body: { segments } as Schemas.AppendSegments,
430401
},
431402
);
432403

src/main/services/recallRecording.ts

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ export function initializeRecallSDK(
9494
posthogKey: string,
9595
posthogHost: string,
9696
) {
97+
console.log("[Recall SDK] initializeRecallSDK called with:", {
98+
recallApiUrl,
99+
posthogHost,
100+
hasKey: !!posthogKey,
101+
});
102+
97103
if (sdkInitialized) {
98104
console.warn("[Recall SDK] Already initialized, skipping");
99105
return;
@@ -106,28 +112,17 @@ export function initializeRecallSDK(
106112
return;
107113
}
108114

109-
console.log("[Recall SDK] Initializing...");
110-
111-
sdkInitialized = true;
112-
posthogClient = new PostHogAPIClient(posthogKey, posthogHost);
113-
114-
RecallAiSdk.init({
115-
apiUrl: recallApiUrl,
116-
acquirePermissionsOnStartup: [
117-
"accessibility",
118-
"screen-capture",
119-
"microphone",
120-
],
121-
restartOnError: true,
122-
});
115+
console.log("[Recall SDK] Setting up event listeners...");
123116

124-
console.log("[Recall SDK] Ready. Listening for meetings...");
117+
// IMPORTANT: Register ALL event listeners BEFORE calling init()
118+
// This is required by Recall SDK
125119

126120
RecallAiSdk.addEventListener("permissions-granted", async () => {
127121
console.log("[Recall SDK] Permissions granted");
128122
});
129123

130124
RecallAiSdk.addEventListener("permission-status", async (evt) => {
125+
console.log("[Recall SDK] Permission status:", evt.permission, evt.status);
131126
if (evt.status === "denied" || evt.status === "error") {
132127
console.warn(`[Recall SDK] Permission ${evt.permission}: ${evt.status}`);
133128
}
@@ -385,6 +380,34 @@ export function initializeRecallSDK(
385380
);
386381
}
387382
});
383+
384+
console.log("[Recall SDK] All event listeners registered");
385+
386+
// NOW initialize the SDK (after all event listeners are set up)
387+
console.log("[Recall SDK] Initializing SDK...");
388+
sdkInitialized = true;
389+
posthogClient = new PostHogAPIClient(posthogKey, posthogHost);
390+
console.log("[Recall SDK] PostHog client created");
391+
392+
try {
393+
RecallAiSdk.init({
394+
apiUrl: recallApiUrl,
395+
acquirePermissionsOnStartup: [
396+
"accessibility",
397+
"screen-capture",
398+
"microphone",
399+
],
400+
restartOnError: true,
401+
});
402+
console.log("[Recall SDK] RecallAiSdk.init() completed successfully");
403+
} catch (error) {
404+
console.error("[Recall SDK] Failed to initialize SDK:", error);
405+
sdkInitialized = false;
406+
posthogClient = null;
407+
throw error;
408+
}
409+
410+
console.log("[Recall SDK] ✓ Ready. Listening for meetings...");
388411
}
389412

390413
export function requestRecallPermission(
@@ -398,18 +421,37 @@ export function shutdownRecallSDK() {
398421
}
399422

400423
export function registerRecallIPCHandlers() {
424+
console.log("[Recall SDK] Registering IPC handlers...");
425+
401426
ipcMain.handle(
402427
"recall:initialize",
403428
async (_event, recallApiUrl, posthogKey, posthogHost) => {
404-
initializeRecallSDK(recallApiUrl, posthogKey, posthogHost);
429+
console.log("[Recall SDK] IPC handler 'recall:initialize' called");
430+
try {
431+
initializeRecallSDK(recallApiUrl, posthogKey, posthogHost);
432+
console.log("[Recall SDK] IPC handler 'recall:initialize' completed");
433+
} catch (error) {
434+
console.error(
435+
"[Recall SDK] IPC handler 'recall:initialize' error:",
436+
error,
437+
);
438+
throw error;
439+
}
405440
},
406441
);
407442

408443
ipcMain.handle("recall:request-permission", async (_event, permission) => {
444+
console.log(
445+
"[Recall SDK] IPC handler 'recall:request-permission' called:",
446+
permission,
447+
);
409448
requestRecallPermission(permission);
410449
});
411450

412451
ipcMain.handle("recall:shutdown", async () => {
452+
console.log("[Recall SDK] IPC handler 'recall:shutdown' called");
413453
shutdownRecallSDK();
414454
});
455+
456+
console.log("[Recall SDK] IPC handlers registered successfully");
415457
}

src/renderer/features/auth/stores/authStore.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ import {
1111

1212
const RECALL_API_URL = "https://us-west-2.recall.ai";
1313

14+
// Helper function to initialize Recall SDK
15+
async function initializeRecallSDK(
16+
accessToken: string,
17+
apiHost: string,
18+
): Promise<void> {
19+
try {
20+
console.log("[Auth] Calling recallInitialize with:", {
21+
url: RECALL_API_URL,
22+
host: apiHost,
23+
hasToken: !!accessToken,
24+
});
25+
await window.electronAPI.recallInitialize(
26+
RECALL_API_URL,
27+
accessToken,
28+
apiHost,
29+
);
30+
console.log("[Auth] recallInitialize completed successfully");
31+
} catch (error) {
32+
console.error("[Auth] Failed to initialize Recall SDK:", error);
33+
// Don't throw - Recall SDK failure shouldn't block authentication
34+
}
35+
}
36+
1437
interface AuthState {
1538
// OAuth state
1639
oauthAccessToken: string | null;
@@ -137,19 +160,8 @@ export const useAuthStore = create<AuthState>()(
137160
throw new Error("Failed to authenticate with PostHog");
138161
}
139162

140-
try {
141-
window.electronAPI
142-
.recallInitialize(
143-
RECALL_API_URL,
144-
tokenResponse.access_token,
145-
apiHost,
146-
)
147-
.catch((error) => {
148-
console.error("[Auth] Failed to initialize Recall SDK:", error);
149-
});
150-
} catch (_error) {
151-
throw new Error("Invalid API key or host");
152-
}
163+
// Initialize Recall SDK for meeting detection
164+
await initializeRecallSDK(tokenResponse.access_token, apiHost);
153165
},
154166

155167
refreshAccessToken: async () => {
@@ -332,6 +344,9 @@ export const useAuthStore = create<AuthState>()(
332344
}
333345
}
334346

347+
// Initialize Recall SDK for meeting detection (session restore)
348+
await initializeRecallSDK(tokens.accessToken, apiHost);
349+
335350
return true;
336351
} catch (error) {
337352
console.error("Failed to validate OAuth session:", error);

src/renderer/features/notetaker/components/RecordingView.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ export function RecordingView({ recordingItem }: RecordingViewProps) {
1414
const segments: TranscriptSegment[] =
1515
recordingItem.type === "active"
1616
? recordingItem.recording.segments || []
17-
: (
18-
recordingItem.recording.transcript_segments as Array<{
19-
timestamp_ms: number;
20-
speaker: string | null;
21-
text: string;
22-
confidence: number | null;
23-
is_final: boolean;
24-
}>
25-
)?.map((seg) => ({
26-
timestamp: seg.timestamp_ms,
27-
speaker: seg.speaker,
17+
: recordingItem.recording.transcript_segments?.map((seg) => ({
18+
timestamp: seg.timestamp ?? 0,
19+
speaker: seg.speaker ?? null,
2820
text: seg.text,
29-
confidence: seg.confidence,
30-
is_final: seg.is_final,
21+
confidence: seg.confidence ?? null,
22+
is_final: seg.is_final ?? false,
3123
})) || [];
3224

3325
useEffect(() => {

src/renderer/services/recordingService.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,16 @@ async function uploadPendingSegments(recordingId: string): Promise<void> {
173173
throw new Error("PostHog client not initialized");
174174
}
175175

176-
await client.updateDesktopRecordingTranscript(recordingId, {
177-
segments: pendingSegments.map((seg) => ({
178-
timestamp_ms: seg.timestamp,
176+
await client.appendSegments(
177+
recordingId,
178+
pendingSegments.map((seg) => ({
179+
timestamp: seg.timestamp,
179180
speaker: seg.speaker,
180181
text: seg.text,
181182
confidence: seg.confidence,
182183
is_final: seg.is_final,
183184
})),
184-
});
185+
);
185186

186187
const newIndex =
187188
recording.lastUploadedSegmentIndex + pendingSegments.length;

0 commit comments

Comments
 (0)