π¬ 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
feat(voice): persist narration as step descriptions
Luis Ortiz724f19c60b3b
diff --git a/src/core/capture/voice/__tests__/narration-updates.test.ts b/src/core/capture/voice/__tests__/narration-updates.test.tsnew file mode 100644index 0000000..4cf3f9a--- /dev/null+++ b/src/core/capture/voice/__tests__/narration-updates.test.ts@@ -0,0 +1,77 @@+import { describe, expect, it } from 'vitest';+import { narrationUpdates } from '../narration-updates';+import type { NarrationResult, NarrationStats } from '../types';++const STATS: NarrationStats = {+ batches: 0,+ failedBatches: 0,+ droppedBatches: 0,+ verbatimSegments: 0,+ splitSegments: 0,+ rejectedSegments: 0,+};++function result(descriptions: NarrationResult['descriptions']): NarrationResult {+ return { descriptions, stats: STATS };+}++describe('narrationUpdates', () => {+ it('maps narration onto the steps that own it', () => {+ const updates = narrationUpdates(+ result([+ { stepId: 'a', text: 'Open the settings page' },+ { stepId: 'c', text: 'Save the changes' },+ ]),+ ['a', 'b', 'c'],+ );+ expect(updates).toEqual([+ { stepId: 'a', description: 'Open the settings page' },+ { stepId: 'c', description: 'Save the changes' },+ ]);+ });++ it('produces no update for a step with no narration', () => {+ const updates = narrationUpdates(result([{ stepId: 'b', text: 'Only this one' }]), ['a', 'b', 'c']);+ expect(updates.map((u) => u.stepId)).toEqual(['b']);+ });++ it('returns nothing when there is no narration at all', () => {+ expect(narrationUpdates(result([]), ['a', 'b'])).toEqual([]);+ });++ it('skips narration that is only whitespace', () => {+ expect(narrationUpdates(result([{ stepId: 'a', text: ' \n ' }]), ['a'])).toEqual([]);+ });++ it('trims surrounding whitespace from narration', () => {+ expect(narrationUpdates(result([{ stepId: 'a', text: ' Click save ' }]), ['a'])).toEqual([+ { stepId: 'a', description: 'Click save' },+ ]);+ });++ it('drops narration for steps that no longer belong to the guide', () => {+ const updates = narrationUpdates(+ result([+ { stepId: 'a', text: 'Kept' },+ { stepId: 'deleted', text: 'Dropped' },+ ]),+ ['a'],+ );+ expect(updates).toEqual([{ stepId: 'a', description: 'Kept' }]);+ });++ it('joins repeated entries for the same step instead of losing speech', () => {+ const updates = narrationUpdates(+ result([+ { stepId: 'a', text: 'First half' },+ { stepId: 'a', text: 'second half' },+ ]),+ ['a'],+ );+ expect(updates).toEqual([{ stepId: 'a', description: 'First half second half' }]);+ });++ it('returns nothing when the guide has no steps', () => {+ expect(narrationUpdates(result([{ stepId: 'a', text: 'Orphan' }]), [])).toEqual([]);+ });+});diff --git a/src/core/capture/voice/narration-updates.ts b/src/core/capture/voice/narration-updates.tsnew file mode 100644index 0000000..a1778fc--- /dev/null+++ b/src/core/capture/voice/narration-updates.ts@@ -0,0 +1,21 @@+import type { NarrationResult } from './types';++export interface NarrationUpdate {+ stepId: string;+ description: string;+}++export function narrationUpdates(result: NarrationResult, stepIds: readonly string[]): NarrationUpdate[] {+ const known = new Set(stepIds);+ const collected = new Map<string, string[]>();++ for (const { stepId, text } of result.descriptions) {+ const description = text.trim();+ if (!description || !known.has(stepId)) continue;+ const existing = collected.get(stepId);+ if (existing) existing.push(description);+ else collected.set(stepId, [description]);+ }++ return [...collected].map(([stepId, texts]) => ({ stepId, description: texts.join(' ') }));+}diff --git a/src/core/guides/service.ts b/src/core/guides/service.tsindex dfc919b..a257254 100644--- a/src/core/guides/service.ts+++ b/src/core/guides/service.ts@@ -1,4 +1,5 @@import { i18n } from '#imports';+import type { NarrationUpdate } from '@/core/capture/voice/narration-updates';import { db } from './db';import type { Guide, Screenshot, Step } from './types';@@ -126,6 +127,16 @@ export async function updateStepDescription(stepId: string, description: string)await db.steps.update(stepId, { description });}+export async function applyNarrationToSteps(updates: readonly NarrationUpdate[]): Promise<void> {+ if (updates.length === 0) return;+ await db.transaction('rw', db.steps, async () => {+ for (const { stepId, description } of updates) {+ await db.steps.update(stepId, { description, descriptionSource: 'narration' });+ }+ });+ notifyGuidesChanged({ type: 'mutated' });+}+export async function getStepsForGuide(guideId: string): Promise<Step[]> {return db.steps.where('guideId').equals(guideId).sortBy('index');}diff --git a/src/core/guides/types.ts b/src/core/guides/types.tsindex 8343194..b8aa372 100644--- a/src/core/guides/types.ts+++ b/src/core/guides/types.ts@@ -10,6 +10,8 @@ export interface Guide {deletedAt: number | null;}+export type DescriptionSource = 'narration' | 'ai' | 'heuristic';+export interface Step {id: string;guideId: string;@@ -21,6 +23,7 @@ export interface Step {screenshotId?: string;elementMeta?: ElementMeta;inputValue?: string;+ descriptionSource?: DescriptionSource;}export interface ScreenshotBounds {