// Answers where the web composer offers skill completion, for the // skill_mentions contract (robot-docs/testing.md#cross-language-contracts). // Reads one JSON array of {text, cursor} per line, the cursor in UTF-16 units, // and writes one line per batch: null, or {prefix, start, end} per case. import { readFile } from 'node:fs/promises'; import { stripTypeScriptTypes } from 'node:module'; import { createInterface } from 'node:readline'; process.removeAllListeners('warning'); const source = stripTypeScriptTypes( await readFile( new URL('../src/lib/skill-mentions.ts', import.meta.url), 'utf8', ), { mode: 'transform' }, ); const { skillMentionAt } = await import( `data:text/javascript;base64,${Buffer.from(source).toString('base64')}` ); for await (const line of createInterface({ input: process.stdin })) { const answers = JSON.parse(line).map(({ text, cursor }) => skillMentionAt(text, cursor), ); process.stdout.write(JSON.stringify(answers) + '\n'); }