MCPcopy
hub / github.com/CopilotKit/CopilotKit / MockAgent

Class MockAgent

packages/sqlite-runner/src/__tests__/sqlite-runner.test.ts:28–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26};
27
28class MockAgent extends AbstractAgent {
29 constructor(
30 private readonly events: BaseEvent[] = [],
31 private readonly emitDefaultRunStarted = true,
32 ) {
33 super();
34 }
35
36 async runAgent(input: RunAgentInput, callbacks: RunCallbacks): Promise<void> {
37 if (this.emitDefaultRunStarted) {
38 const runStarted: RunStartedEvent = {
39 type: EventType.RUN_STARTED,
40 threadId: input.threadId,
41 runId: input.runId,
42 };
43 await callbacks.onEvent({ event: runStarted });
44 await callbacks.onRunStartedEvent?.();
45 }
46
47 for (const event of this.events) {
48 await callbacks.onEvent({ event });
49 }
50
51 const hasTerminalEvent = this.events.some(
52 (event) =>
53 event.type === EventType.RUN_FINISHED ||
54 event.type === EventType.RUN_ERROR,
55 );
56
57 if (!hasTerminalEvent) {
58 const runFinished: RunFinishedEvent = {
59 type: EventType.RUN_FINISHED,
60 threadId: input.threadId,
61 runId: input.runId,
62 };
63 await callbacks.onEvent({ event: runFinished });
64 }
65 }
66
67 protected run(): ReturnType<AbstractAgent["run"]> {
68 return EMPTY;
69 }
70
71 protected connect(): ReturnType<AbstractAgent["connect"]> {
72 return EMPTY;
73 }
74
75 clone(): AbstractAgent {
76 return new MockAgent(this.events, this.emitDefaultRunStarted);
77 }
78}
79
80class StoppableAgent extends AbstractAgent {
81 private shouldStop = false;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…