import type { HumanIdentity } from './protocol.js'; export function mentionToken(textBeforeCursor: string): string | null { const match = /(?:^|[\s(])@([A-Za-z0-9-]*)$/.exec(textBeforeCursor); return match ? match[1]! : null; } function fuzzyMatch(handle: string, query: string): boolean { let offset = 0; for (const character of query.toLowerCase()) { offset = handle.toLowerCase().indexOf(character, offset); if (offset < 0) return false; offset++; } return true; } export function completionItems(participants: readonly HumanIdentity[], query: string) { return participants .filter((participant) => fuzzyMatch(participant.handle, query)) .slice(0, 20) .map((participant) => ({ value: `@${participant.handle}`, label: `@${participant.handle}`, description: 'Authenticated Chi participant' })); }