🎬 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): unwrap only the quotes that wrap a whole description
davbio68461fcca9f8
diff --git a/src/core/capture/ai/__tests__/text.test.ts b/src/core/capture/ai/__tests__/text.test.tsnew file mode 100644index 0000000..65503a8--- /dev/null+++ b/src/core/capture/ai/__tests__/text.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from 'vitest';+import { unwrapQuotes } from '../text';++describe('unwrapQuotes', () => {+ it('unwraps a description the model wrapped whole', () => {+ expect(unwrapQuotes('"Click the Submit button"')).toBe('Click the Submit button');+ });++ it('trims before and after unwrapping', () => {+ expect(unwrapQuotes(' "Click Submit" ')).toBe('Click Submit');+ });++ it('leaves a sentence that merely starts with a quoted value', () => {+ expect(unwrapQuotes('"abc" in das Feld Email eingeben')).toBe('"abc" in das Feld Email eingeben');+ });++ it('leaves a sentence that merely ends with a quoted value', () => {+ expect(unwrapQuotes('在 Email 字段中输入 "abc"')).toBe('在 Email 字段中输入 "abc"');+ });++ it('leaves a sentence quoted at both ends but holding two separate spans', () => {+ expect(unwrapQuotes('"Admin" in der Liste "Role"')).toBe('"Admin" in der Liste "Role"');+ });++ it('leaves an unquoted sentence alone', () => {+ expect(unwrapQuotes('Type "abc" in Email')).toBe('Type "abc" in Email');+ });++ it('handles a bare quote without dropping it', () => {+ expect(unwrapQuotes('"')).toBe('"');+ });++ it('returns an empty string for blank input', () => {+ expect(unwrapQuotes(' ')).toBe('');+ });+});diff --git a/src/core/capture/ai/description.ts b/src/core/capture/ai/description.tsindex 477e786..8d0c114 100644--- a/src/core/capture/ai/description.ts+++ b/src/core/capture/ai/description.ts@@ -5,6 +5,7 @@ import { serializeDOMContext } from '../dom/context';import { formatExamples, resolveExamples } from './examples';import { getLanguageSuffix, STEP_DESCRIPTION_PROMPT } from './prompts';import { createModel } from './provider';+import { unwrapQuotes } from './text';export async function getAIDescription(domContext: DOMContext,@@ -25,5 +26,5 @@ export async function getAIDescription(prompt: prompt + getLanguageSuffix(locale),maxOutputTokens: 50,});- return text.trim().replace(/^"|"$/g, '') || null;+ return unwrapQuotes(text) || null;}diff --git a/src/core/capture/ai/meta.ts b/src/core/capture/ai/meta.tsindex 3c697dd..37fc252 100644--- a/src/core/capture/ai/meta.ts+++ b/src/core/capture/ai/meta.ts@@ -5,6 +5,7 @@ import { logger } from '@/lib/logger';import { formatExamples, resolveExamples } from './examples';import { GUIDE_META_JSON_SUFFIX, GUIDE_META_PROMPT, getLanguageSuffix } from './prompts';import { createModel } from './provider';+import { unwrapQuotes } from './text';export interface GuideMeta {title: string;@@ -25,12 +26,11 @@ const guideMetaSchema = jsonSchema<{ title: string; description?: string | null});function toGuideMeta(rawTitle: unknown, rawDescription: unknown): GuideMeta | null {- let title = typeof rawTitle === 'string' ? sanitizeGuideTitle(rawTitle).replace(/^"|"$/g, '') : '';+ let title = typeof rawTitle === 'string' ? unwrapQuotes(sanitizeGuideTitle(rawTitle)) : '';if (!title) return null;if (title.length > MAX_TITLE_LENGTH) title = `${title.slice(0, MAX_TITLE_LENGTH - 3)}...`;- const description =- typeof rawDescription === 'string' ? rawDescription.trim().replace(/^"|"$/g, '') || undefined : undefined;+ const description = typeof rawDescription === 'string' ? unwrapQuotes(rawDescription) || undefined : undefined;return { title, description };}diff --git a/src/core/capture/ai/text.ts b/src/core/capture/ai/text.tsnew file mode 100644index 0000000..215ec1e--- /dev/null+++ b/src/core/capture/ai/text.ts@@ -0,0 +1,6 @@+export function unwrapQuotes(text: string): string {+ const trimmed = text.trim();+ const wrapped =+ trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"') && !trimmed.slice(1, -1).includes('"');+ return wrapped ? trimmed.slice(1, -1).trim() : trimmed;+}