MCPcopy
hub / github.com/codeaashu/claude-code / maybe

Function maybe

src/utils/attachments.ts:1005–1042  ·  view source on GitHub ↗
(label: string, f: () => Promise<A[]>)

Source from the content-addressed store, hash-verified

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

Callers 1

getAttachmentsFunction · 0.85

Calls 5

jsonStringifyFunction · 0.85
logEventFunction · 0.85
logAntErrorFunction · 0.85
logErrorFunction · 0.70
fFunction · 0.50

Tested by

no test coverage detected