Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(ai): send groq keys to groq instead of falling back to openai

Luis Ortiz4d3cee45c6d4
diff --git a/src/core/capture/ai/__tests__/validate.test.ts b/src/core/capture/ai/__tests__/validate.test.ts
index fbf7867..ea4ef86 100644
--- a/src/core/capture/ai/__tests__/validate.test.ts
+++ b/src/core/capture/ai/__tests__/validate.test.ts
@@ -50,4 +50,17 @@ describe('validateApiKey', () => {
expect(url).toBe('https://api.openai.com/v1/models');
expect(init.headers.Authorization).toBe('Bearer sk-key');
});
+
+ it('checks a groq key against groq, not openai', async () => {
+ fetchMock.mockResolvedValue({ ok: true, status: 200 });
+ expect(await validateApiKey('groq', 'gsk-key')).toEqual({ valid: true });
+ const [url, init] = fetchMock.mock.calls[0];
+ expect(url).toBe('https://api.groq.com/openai/v1/models');
+ expect(init.headers.Authorization).toBe('Bearer gsk-key');
+ });
+
+ it('never sends a key to an unknown provider, and does not call it rejected', async () => {
+ expect(await validateApiKey('mystery', 'secret')).toEqual({ valid: false, reason: 'network' });
+ expect(fetchMock).not.toHaveBeenCalled();
+ });
});
diff --git a/src/core/capture/ai/validate.ts b/src/core/capture/ai/validate.ts
index c1dc49d..9fc2ae2 100644
--- a/src/core/capture/ai/validate.ts
+++ b/src/core/capture/ai/validate.ts
@@ -15,10 +15,18 @@ const ENDPOINTS: Record<string, { url: string; headers: (key: string) => Record<
'anthropic-dangerous-direct-browser-access': 'true',
}),
},
+ groq: {
+ url: 'https://api.groq.com/openai/v1/models',
+ headers: (key) => ({ Authorization: `Bearer ${key}` }),
+ },
};
export async function validateApiKey(provider: string, apiKey: string): Promise<KeyValidation> {
- const endpoint = ENDPOINTS[provider] ?? ENDPOINTS.openai;
+ const endpoint = ENDPOINTS[provider];
+ if (!endpoint) {
+ logger.error('No API key validation endpoint for provider', provider);
+ return { valid: false, reason: 'network' };
+ }
try {
const res = await fetch(endpoint.url, { headers: endpoint.headers(apiKey) });
if (res.ok) return { valid: true };