MCPcopy Create free account
hub / github.com/github/copilot-sdk / getNextSessionEvent

Function getNextSessionEvent

nodejs/test/e2e/compaction.e2e.test.ts:7–35  ·  view source on GitHub ↗
(
    session: CopilotSession,
    eventType: TEventType,
    description: string,
    predicate: (event: Extract<SessionEvent, { type: TEventType }>) => boolean = () => true
)

Source from the content-addressed store, hash-verified

5const compactionTimeoutMs = 60_000;
6
7function getNextSessionEvent<TEventType extends SessionEvent["type"]>(
8 session: CopilotSession,
9 eventType: TEventType,
10 description: string,
11 predicate: (event: Extract<SessionEvent, { type: TEventType }>) => boolean = () => true
12): Promise<Extract<SessionEvent, { type: TEventType }>> {
13 return new Promise((resolve, reject) => {
14 let unsubscribe: () => void = () => {};
15 const timeout = setTimeout(() => {
16 unsubscribe();
17 reject(new Error(`Timed out waiting for ${description}`));
18 }, compactionTimeoutMs);
19
20 unsubscribe = session.on((event) => {
21 if (event.type === eventType) {
22 const typedEvent = event as Extract<SessionEvent, { type: TEventType }>;
23 if (predicate(typedEvent)) {
24 clearTimeout(timeout);
25 unsubscribe();
26 resolve(typedEvent);
27 }
28 } else if (event.type === "session.error") {
29 clearTimeout(timeout);
30 unsubscribe();
31 reject(new Error(`${event.data.message}\n${event.data.stack}`));
32 }
33 });
34 });
35}
36
37describe("Compaction", async () => {
38 const { copilotClient: client } = await createSdkTestContext();

Callers 1

Calls 3

predicateFunction · 0.85
unsubscribeFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…