MCPcopy Index your code
hub / github.com/github/copilot-sdk / main

Function main

nodejs/samples/chat.ts:4–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import * as readline from "node:readline";
3
4async 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
35main().catch(console.error);

Callers 1

chat.tsFile · 0.70

Calls 5

createSessionMethod · 0.95
promptFunction · 0.85
onMethod · 0.45
logMethod · 0.45
sendAndWaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…