* Converts an Airtable record to an ExternalDocument.
( record: AirtableRecord, baseId: string, tableIdOrName: string, titleField: string | undefined, fieldNames: Map<string, string> )
| 260 | * Converts an Airtable record to an ExternalDocument. |
| 261 | */ |
| 262 | async function recordToDocument( |
| 263 | record: AirtableRecord, |
| 264 | baseId: string, |
| 265 | tableIdOrName: string, |
| 266 | titleField: string | undefined, |
| 267 | fieldNames: Map<string, string> |
| 268 | ): Promise<ExternalDocument> { |
| 269 | const plainText = recordToPlainText(record.fields, fieldNames) |
| 270 | const contentHash = await computeContentHash(plainText) |
| 271 | const title = extractTitle(record.fields, titleField) |
| 272 | |
| 273 | const encodedTable = encodeURIComponent(tableIdOrName) |
| 274 | const sourceUrl = `https://airtable.com/${baseId}/${encodedTable}/${record.id}` |
| 275 | |
| 276 | return { |
| 277 | externalId: record.id, |
| 278 | title, |
| 279 | content: plainText, |
| 280 | mimeType: 'text/plain', |
| 281 | sourceUrl, |
| 282 | contentHash, |
| 283 | metadata: { |
| 284 | createdTime: record.createdTime, |
| 285 | }, |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Fetches the table schema to build a field ID → field name mapping. |
no test coverage detected