INNER CODE UNIT · TypeScript
lookupReply
rowboatlabs/rowboat · apps/harbor/packages/server/src/connectors/attio/index.ts:73
function lookupReply<T>(records: T[], noun: string, query: string, format: (record: T) => string): string {
const subject = plainText(query, 254);
if (!records.length) return `No ${noun} found for **${subject}**.`;
const heading = records.length === 1 ? '' : records.length > LOOKUP_LIMIT
? `More than ${LOOKUP_LIMIT} ${noun} match **${subject}**. Showing the first ${LOOKUP_LIMIT}; open Attio to review all matches.\n\n`
: `${records.length} ${noun} match **${subject}**.\n\n`;
return heading + records.slice(0, LOOKUP_LIMIT).map(format).join('\n\n---\n\n');
}
function attributeText(value: unknown): string | undefined {
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
const v = value as Record<string, unknown>;
if (v.active_until != null) return undefined;
const text = (key: string) => typeof v[key] === 'string' ? v[key] as string : undefined;
const title = (key: string) => {
const nested = v[key];
if (nested && typeof nested === 'object' && 'title' in nested && typeof nested.title === 'string') return nested.title;
return undefined;