* Extracts a human-readable title from a record's fields. * Prefers the configured title field, then falls back to common field names.
(fields: Record<string, unknown>, titleField?: string)
| 46 | * Prefers the configured title field, then falls back to common field names. |
| 47 | */ |
| 48 | function extractTitle(fields: Record<string, unknown>, titleField?: string): string { |
| 49 | if (titleField && fields[titleField] != null) { |
| 50 | return String(fields[titleField]) |
| 51 | } |
| 52 | const candidates = ['Name', 'Title', 'name', 'title', 'Summary', 'summary'] |
| 53 | for (const candidate of candidates) { |
| 54 | if (fields[candidate] != null) { |
| 55 | return String(fields[candidate]) |
| 56 | } |
| 57 | } |
| 58 | for (const value of Object.values(fields)) { |
| 59 | if (typeof value === 'string' && value.trim()) { |
| 60 | return value.length > 80 ? `${value.slice(0, 80)}…` : value |
| 61 | } |
| 62 | } |
| 63 | return 'Untitled' |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Parses the cursor format: "offset:<airtable_offset>" |