()
| 2 | import * as readline from "node:readline"; |
| 3 | |
| 4 | async function main() { |
| 5 | const client = new CopilotClient(); |
| 6 | const session = await client.createSession({ |
| 7 | onPermissionRequest: approveAll, |
| 8 | }); |
| 9 | |
| 10 | session.on((event: SessionEvent) => { |
| 11 | let output: string | null = null; |
| 12 | if (event.type === "assistant.reasoning") { |
| 13 | output = `[reasoning: ${event.data.content}]`; |
| 14 | } else if (event.type === "tool.execution_start") { |
| 15 | output = `[tool: ${event.data.toolName}]`; |
| 16 | } |
| 17 | if (output) console.log(`\x1b[34m${output}\x1b[0m`); |
| 18 | }); |
| 19 | |
| 20 | const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); |
| 21 | const prompt = (q: string) => new Promise<string>((r) => rl.question(q, r)); |
| 22 | |
| 23 | console.log("Chat with Copilot (Ctrl+C to exit)\n"); |
| 24 | |
| 25 | while (true) { |
| 26 | const input = await prompt("You: "); |
| 27 | if (!input.trim()) continue; |
| 28 | console.log(); |
| 29 | |
| 30 | const reply = await session.sendAndWait({ prompt: input }); |
| 31 | console.log(`\nAssistant: ${reply?.data.content}\n`); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | main().catch(console.error); |
no test coverage detected
searching dependent graphs…