Open History to see the last commit
1let mockInstance: any = null
2let startPromise: Promise<any> | null = null
3
4export async function ensureLLMock() {
5 if (!process.env.LLMOCK_RECORD) {
6 return null
7 }
8
9 if (mockInstance) return mockInstance
10 if (startPromise) return startPromise
11
12 startPromise = (async () => {
13 const { LLMock } = await import('@copilotkit/aimock')
14
15 // aimock 1.17+ moved the record options under `record: RecordConfig`.
16 // Provider keys must come from RecordProviderKey — `elevenlabs` is in that
17 // union so we can proxy api.elevenlabs.io for music + SFX recording when
18 // ELEVENLABS_API_KEY is set.
19 mockInstance = new LLMock({
20 port: 4010,
21 host: '127.0.0.1',
22 logLevel: 'info',
23 record: {
24 providers: {
25 openai: process.env.OPENAI_API_KEY,
26 anthropic: process.env.ANTHROPIC_API_KEY,
27 gemini: process.env.GOOGLE_API_KEY,
28 ollama: 'http://localhost:11434',
29 elevenlabs: process.env.ELEVENLABS_API_KEY,
30 },
31 fixturePath: './fixtures/recorded',
32 },
33 })
34
35 await mockInstance.start()
36 console.log(`[llmock] Record mode started at http://127.0.0.1:4010`)
37 return mockInstance
38 })()
39
40 return startPromise
41}