π¬ 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(recording): write the fallback title without waiting on narration
davbiocc74b3b51044
diff --git a/src/entrypoints/background/__tests__/guide-meta.test.ts b/src/entrypoints/background/__tests__/guide-meta.test.tsindex 895c422..32426e3 100644--- a/src/entrypoints/background/__tests__/guide-meta.test.ts+++ b/src/entrypoints/background/__tests__/guide-meta.test.ts@@ -8,6 +8,7 @@ const {localStorageGetMock,updateGuideDescriptionMock,updateGuideTitleMock,+ whenNarrationSettledMock,} = vi.hoisted(() => ({clearStepAiPendingMock: vi.fn(),generateGuideMetaMock: vi.fn(),@@ -16,6 +17,7 @@ const {localStorageGetMock: vi.fn(),updateGuideDescriptionMock: vi.fn(),updateGuideTitleMock: vi.fn(),+ whenNarrationSettledMock: vi.fn(),}));vi.mock('@/core/capture/ai/meta', () => ({ generateGuideMeta: generateGuideMetaMock }));@@ -30,6 +32,8 @@ vi.mock('@/core/guides/service', () => ({vi.mock('@/lib/browser-api', () => ({ localStorage: { get: localStorageGetMock } }));+vi.mock('../voice', () => ({ whenNarrationSettled: whenNarrationSettledMock }));+import { AI_PROVIDERS } from '@/core/capture/ai/models';import { generateDescriptionOnDemand, generateGuideMetaOnStop } from '../guide-meta';@@ -56,6 +60,7 @@ describe('background guide-meta', () => {updateGuideTitleMock.mockResolvedValue(undefined);updateGuideDescriptionMock.mockResolvedValue(undefined);generateGuideMetaMock.mockResolvedValue({ title: 'Generated Title', description: 'Generated description.' });+ whenNarrationSettledMock.mockResolvedValue(undefined);});describe('input resolution shared by both entry points', () => {@@ -130,6 +135,85 @@ describe('background guide-meta', () => {expect(updateGuideTitleMock).toHaveBeenCalledWith(GUIDE_ID, 'background.guideOnDomain[example.com]');});+ it('writes the fallback title before narration settles when no key is set', async () => {+ localStorageGetMock.mockResolvedValue({});+ let settle!: () => void;+ whenNarrationSettledMock.mockReturnValue(+ new Promise<void>((resolve) => {+ settle = resolve;+ }),+ );+ getStepsForGuideMock.mockResolvedValue([+ { id: 'step-1', description: '', url: 'https://example.com', aiPending: true },+ ]);++ const run = generateGuideMetaOnStop(GUIDE_ID);+ await vi.waitFor(() =>+ expect(updateGuideTitleMock).toHaveBeenCalledWith(GUIDE_ID, 'background.guideOnDomain[example.com]'),+ );+ expect(clearStepAiPendingMock).not.toHaveBeenCalled();++ settle();+ await run;+ expect(clearStepAiPendingMock).toHaveBeenCalledWith('step-1');+ });++ it('waits for narration before generating a title when a key is set', async () => {+ let settle!: () => void;+ whenNarrationSettledMock.mockReturnValue(+ new Promise<void>((resolve) => {+ settle = resolve;+ }),+ );+ getStepsForGuideMock.mockResolvedValue([+ { id: 'step-1', description: 'step 1', url: 'https://example.com', aiPending: true },+ ]);++ const run = generateGuideMetaOnStop(GUIDE_ID);+ await new Promise((resolve) => setTimeout(resolve, 0));+ expect(generateGuideMetaMock).not.toHaveBeenCalled();+ expect(updateGuideTitleMock).not.toHaveBeenCalled();++ settle();+ await run;+ expect(clearStepAiPendingMock).toHaveBeenCalledWith('step-1');+ expect(updateGuideTitleMock).toHaveBeenCalledWith(GUIDE_ID, 'Generated Title');+ });++ it('still clears aiPending when the fallback title write fails', async () => {+ localStorageGetMock.mockResolvedValue({});+ updateGuideTitleMock.mockRejectedValue(new Error('DatabaseClosedError'));+ getStepsForGuideMock.mockResolvedValue([+ { id: 'step-1', description: '', url: 'https://example.com', aiPending: true },+ ]);++ await expect(generateGuideMetaOnStop(GUIDE_ID)).resolves.toBeUndefined();++ expect(clearStepAiPendingMock).toHaveBeenCalledWith('step-1');+ });++ it('writes the fallback title only once when settling fails, so a rename in the meantime survives', async () => {+ localStorageGetMock.mockResolvedValue({});+ getStepsForGuideMock.mockRejectedValue(new Error('DatabaseClosedError'));++ await expect(generateGuideMetaOnStop(GUIDE_ID)).resolves.toBeUndefined();++ expect(updateGuideTitleMock).toHaveBeenCalledTimes(1);+ });++ it('applies the fallback title and settles when the key cannot be read', async () => {+ localStorageGetMock.mockRejectedValue(new Error('DatabaseClosedError'));+ getStepsForGuideMock.mockResolvedValue([+ { id: 'step-1', description: '', url: 'https://example.com', aiPending: true },+ ]);++ await generateGuideMetaOnStop(GUIDE_ID);++ expect(generateGuideMetaMock).not.toHaveBeenCalled();+ expect(updateGuideTitleMock).toHaveBeenCalledWith(GUIDE_ID, 'background.guideOnDomain[example.com]');+ expect(clearStepAiPendingMock).toHaveBeenCalledWith('step-1');+ });+it('falls back to the generic title when the guide has no domain', async () => {localStorageGetMock.mockResolvedValue({});getGuideDomainMock.mockResolvedValue('');diff --git a/src/entrypoints/background/guide-meta.ts b/src/entrypoints/background/guide-meta.tsindex f86dd34..d949a6b 100644--- a/src/entrypoints/background/guide-meta.ts+++ b/src/entrypoints/background/guide-meta.ts@@ -1,5 +1,5 @@import { i18n } from '#imports';-import { resolveAiKey } from '@/core/capture/ai/keys';+import { AI_KEY_SETTINGS, resolveAiKey } from '@/core/capture/ai/keys';import { generateGuideMeta } from '@/core/capture/ai/meta';import { AI_PROVIDERS } from '@/core/capture/ai/models';import { actionSteps } from '@/core/guides/blocks';@@ -29,6 +29,10 @@ type GuideMetaInputs =}| { ok: false; reason: ResolveFailure };+async function hasAiKey(): Promise<boolean> {+ return Boolean(resolveAiKey(await localStorage.get([...AI_KEY_SETTINGS])).apiKey);+}+async function resolveGuideMetaInputs(guideId: string): Promise<GuideMetaInputs> {const settings = await localStorage.get(['aiApiKeys', 'aiApiKey', 'aiProvider', 'aiModel', 'aiBaseUrl']);const { provider, apiKey } = resolveAiKey(settings);@@ -63,7 +67,18 @@ export async function settlePendingDescriptions(guideId: string) {await Promise.all(pending.map((s) => clearStepAiPending(s.id)));}+async function applyFallbackTitleThenSettle(guideId: string) {+ const titled = applyFallbackTitle(guideId).catch((err) => logger.error('Fallback title write failed', err));+ await settlePendingDescriptions(guideId).catch((err) => logger.error('Settling step descriptions failed', err));+ await titled;+}+export async function generateGuideMetaOnStop(guideId: string) {+ if (!(await hasAiKey().catch(() => false))) {+ await applyFallbackTitleThenSettle(guideId);+ return;+ }+try {await settlePendingDescriptions(guideId);const inputs = await resolveGuideMetaInputs(guideId);