π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
fix(ai): send nothing to the provider for steps when AI is off for steps
Luis Ortiz6be35e8fe879
diff --git a/packages/core/src/capture/ai/__tests__/describe-step.test.ts b/packages/core/src/capture/ai/__tests__/describe-step.test.tsnew file mode 100644index 0000000..07acc8c--- /dev/null+++ b/packages/core/src/capture/ai/__tests__/describe-step.test.ts@@ -0,0 +1,34 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++let aiForSteps = true;++vi.mock('../read-ai-credentials', () => ({+ readAiCredentials: vi.fn(async () => ({ provider: 'openai', model: 'm', apiKey: 'k' })),+}));+vi.mock('../read-ai-use', () => ({ readAiUse: vi.fn(async () => ({ steps: aiForSteps, guide: true })) }));+vi.mock('../description', () => ({ getAIDescription: vi.fn(async () => 'Type your name in Name') }));++import { describeStep } from '../describe-step';+import { getAIDescription } from '../description';++beforeEach(() => {+ vi.clearAllMocks();+ aiForSteps = true;+});++describe('describeStep', () => {+ it('sends nothing to the provider when AI is off for steps', async () => {+ aiForSteps = false;++ await expect(describeStep('field Name, typed "Ada"')).resolves.toEqual({ text: null, failure: null });+ expect(getAIDescription).not.toHaveBeenCalled();+ });++ it('asks the provider when AI is on for steps', async () => {+ await expect(describeStep('field Name, typed "Ada"')).resolves.toEqual({+ text: 'Type your name in Name',+ failure: null,+ });+ expect(getAIDescription).toHaveBeenCalledOnce();+ });+});diff --git a/packages/core/src/capture/ai/describe-step.ts b/packages/core/src/capture/ai/describe-step.tsindex 8f59905..f4cd4c1 100644--- a/packages/core/src/capture/ai/describe-step.ts+++ b/packages/core/src/capture/ai/describe-step.ts@@ -2,6 +2,7 @@ import { logger } from '@/core/logger';import { getAIDescription } from './description';import { type AiFailureUpdate, describeAiFailure } from './errors';import { readAiCredentials } from './read-ai-credentials';+import { readAiUse } from './read-ai-use';export interface StepDescription {text: string | null;@@ -9,8 +10,8 @@ export interface StepDescription {}export async function describeStep(context: string, prompt?: string): Promise<StepDescription> {- const keys = await readAiCredentials();- if (!keys) return { text: null, failure: null };+ const [keys, use] = await Promise.all([readAiCredentials(), readAiUse()]);+ if (!keys || !use.steps) return { text: null, failure: null };try {const text = await getAIDescription(context, keys.provider, keys.model, keys.apiKey, keys.baseUrl, prompt);return { text: text || null, failure: null };