mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-23 11:55:12 +00:00
Moving the copilot-sdk cookbook content in here
This commit is contained in:
37
cookbook/copilot-sdk/nodejs/recipe/persisting-sessions.ts
Normal file
37
cookbook/copilot-sdk/nodejs/recipe/persisting-sessions.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { CopilotClient } from "@github/copilot-sdk";
|
||||
|
||||
const client = new CopilotClient();
|
||||
await client.start();
|
||||
|
||||
// Create a session with a memorable ID
|
||||
const session = await client.createSession({
|
||||
sessionId: "user-123-conversation",
|
||||
model: "gpt-5",
|
||||
});
|
||||
|
||||
await session.sendAndWait({ prompt: "Let's discuss TypeScript generics" });
|
||||
console.log(`Session created: ${session.sessionId}`);
|
||||
|
||||
// Destroy session but keep data on disk
|
||||
await session.destroy();
|
||||
console.log("Session destroyed (state persisted)");
|
||||
|
||||
// Resume the previous session
|
||||
const resumed = await client.resumeSession("user-123-conversation");
|
||||
console.log(`Resumed: ${resumed.sessionId}`);
|
||||
|
||||
await resumed.sendAndWait({ prompt: "What were we discussing?" });
|
||||
|
||||
// List sessions
|
||||
const sessions = await client.listSessions();
|
||||
console.log(
|
||||
"Sessions:",
|
||||
sessions.map((s) => s.sessionId)
|
||||
);
|
||||
|
||||
// Delete session permanently
|
||||
await client.deleteSession("user-123-conversation");
|
||||
console.log("Session deleted");
|
||||
|
||||
await resumed.destroy();
|
||||
await client.stop();
|
||||
Reference in New Issue
Block a user