Skip to content

Commit e1dde28

Browse files
committed
chore(search): diagnose unsupported Fireflies response shapes
1 parent 1d9cc32 commit e1dde28

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

‎apps/sim/lib/sim-search/live/fireflies-mcp.ts‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createLogger } from '@sim/logger'
12
import { toArray, toRecord } from '@sim/utils/object'
23
import { nativeText } from '@/lib/sim-search/live/dates'
34
import { NativeSearchError, string } from '@/lib/sim-search/live/http'
@@ -7,6 +8,45 @@ import type { NativeDocument, NativePage, NativeSearchInput } from '@/lib/sim-se
78

89
const MAX_MEETING_CONTENT = 200_000
910
const UTC_DAY_MS = 86_400_000
11+
const logger = createLogger('FirefliesMcpSearch')
12+
13+
/** Only fixed envelope keys and value kinds may enter diagnostics, never provider keys or values. */
14+
function responseShape(value: unknown) {
15+
const record = toRecord(value)
16+
const kind = (entry: unknown) =>
17+
entry === null ? 'null' : Array.isArray(entry) ? 'array' : typeof entry
18+
return {
19+
type: kind(value),
20+
fields: Object.fromEntries(
21+
[
22+
'transcripts',
23+
'data',
24+
'result',
25+
'results',
26+
'items',
27+
'output',
28+
'text',
29+
'error',
30+
'errors',
31+
].flatMap((key) => (Object.hasOwn(record, key) ? [[key, kind(record[key])]] : []))
32+
),
33+
}
34+
}
35+
36+
function responseTextShape(value: unknown) {
37+
if (typeof value !== 'string') return undefined
38+
const text = value.trim()
39+
const fenced = text.match(/^```(?:json)?\r?\n([\s\S]*)\r?\n```$/i)?.[1]
40+
let jsonShape: ReturnType<typeof responseShape> | undefined
41+
try {
42+
jsonShape = responseShape(JSON.parse(fenced ?? text))
43+
} catch {}
44+
return {
45+
length: value.length,
46+
format: fenced !== undefined ? 'code_fence' : jsonShape ? 'json' : 'text',
47+
...(jsonShape ? { jsonShape } : {}),
48+
}
49+
}
1050

1151
function requireMeetingId(id: string): string {
1252
if (!/^[\w-]{1,200}$/.test(id))
@@ -139,11 +179,19 @@ export async function searchFirefliesMcp(
139179
const rows = Array.isArray(result)
140180
? result
141181
: (data.transcripts ?? toRecord(data.data).transcripts)
142-
if (!Array.isArray(rows))
182+
if (!Array.isArray(rows)) {
183+
logger.warn('Unsupported Fireflies transcript list response shape', {
184+
response: responseShape(result),
185+
data: responseShape(data.data),
186+
result: responseShape(data.result),
187+
output: responseShape(data.output),
188+
text: responseTextShape(typeof result === 'string' ? result : data.text),
189+
})
143190
throw new NativeSearchError(
144191
'unavailable',
145192
'Fireflies returned an unsupported transcript list format.'
146193
)
194+
}
147195
const documents = rows.slice(0, limit).flatMap((value) => {
148196
const document = meetingDocument(toRecord(value))
149197
return document ? [document] : []

0 commit comments

Comments
 (0)