(label: string, f: () => Promise<A[]>)
| 1005 | } |
| 1006 | |
| 1007 | async function maybe<A>(label: string, f: () => Promise<A[]>): Promise<A[]> { |
| 1008 | const startTime = Date.now() |
| 1009 | try { |
| 1010 | const result = await f() |
| 1011 | const duration = Date.now() - startTime |
| 1012 | // Log only 5% of events to reduce volume |
| 1013 | if (Math.random() < 0.05) { |
| 1014 | // jsonStringify(undefined) returns undefined, so .length would throw |
| 1015 | const attachmentSizeBytes = result |
| 1016 | .filter(a => a !== undefined && a !== null) |
| 1017 | .reduce((total, attachment) => { |
| 1018 | return total + jsonStringify(attachment).length |
| 1019 | }, 0) |
| 1020 | logEvent('ncode_attachment_compute_duration', { |
| 1021 | label, |
| 1022 | duration_ms: duration, |
| 1023 | attachment_size_bytes: attachmentSizeBytes, |
| 1024 | attachment_count: result.length, |
| 1025 | } as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS) |
| 1026 | } |
| 1027 | return result |
| 1028 | } catch (e) { |
| 1029 | const duration = Date.now() - startTime |
| 1030 | // Log only 5% of events to reduce volume |
| 1031 | if (Math.random() < 0.05) { |
| 1032 | logEvent('ncode_attachment_compute_duration', { |
| 1033 | label, |
| 1034 | duration_ms: duration, |
| 1035 | error: true, |
| 1036 | } as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS) |
| 1037 | } |
| 1038 | logError(e) |
| 1039 | // For Ant users, log the full error to help with debugging |
| 1040 | logAntError(`Attachment error in ${label}`, e) |
| 1041 | |
| 1042 | return [] |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | const INLINE_NOTIFICATION_MODES = new Set(['prompt', 'task-notification']) |
| 1047 |
no test coverage detected