🎬 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(ai): write prompt examples and instructions in the description language
davbio0b37ca9b4cb7
diff --git a/src/core/capture/ai/description.ts b/src/core/capture/ai/description.tsindex e2b4c93..477e786 100644--- a/src/core/capture/ai/description.ts+++ b/src/core/capture/ai/description.ts@@ -2,6 +2,7 @@ import { generateText } from 'ai';import { localStorage } from '@/lib/browser-api';import type { DOMContext } from '../dom/context';import { serializeDOMContext } from '../dom/context';+import { formatExamples, resolveExamples } from './examples';import { getLanguageSuffix, STEP_DESCRIPTION_PROMPT } from './prompts';import { createModel } from './provider';@@ -14,9 +15,14 @@ export async function getAIDescription(): Promise<string | null> {const settings = await localStorage.get(['aiLanguage']);const locale = (settings.aiLanguage as string) || 'en';+ const context = serializeDOMContext(domContext);+ const prompt = STEP_DESCRIPTION_PROMPT.replace('{{examples}}', formatExamples(resolveExamples(locale).steps)).replace(+ '{{context}}',+ () => context,+ );const { text } = await generateText({model: createModel(provider, model, apiKey, baseUrl),- prompt: STEP_DESCRIPTION_PROMPT.replace('{{context}}', serializeDOMContext(domContext)) + getLanguageSuffix(locale),+ prompt: prompt + getLanguageSuffix(locale),maxOutputTokens: 50,});return text.trim().replace(/^"|"$/g, '') || null;diff --git a/src/core/capture/ai/meta.ts b/src/core/capture/ai/meta.tsindex 7e6a4d6..3c697dd 100644--- a/src/core/capture/ai/meta.ts+++ b/src/core/capture/ai/meta.ts@@ -2,6 +2,7 @@ import { generateObject, generateText, jsonSchema } from 'ai';import { MAX_TITLE_LENGTH, sanitizeGuideTitle } from '@/core/guides/title';import { localStorage } from '@/lib/browser-api';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';@@ -65,7 +66,11 @@ export async function generateGuideMeta(const formatted = steps.map((s, i) => `${i + 1}. [${s.url}] ${s.description}`).join('\n');const settings = await localStorage.get(['aiLanguage']);const locale = (settings.aiLanguage as string) || 'en';- const prompt = GUIDE_META_PROMPT.replace('{{steps}}', formatted) + getLanguageSuffix(locale);+ const examples = resolveExamples(locale);+ const prompt =+ GUIDE_META_PROMPT.replace('{{titleExamples}}', formatExamples(examples.titles))+ .replace('{{descriptionExamples}}', formatExamples(examples.descriptions))+ .replace('{{steps}}', () => formatted) + getLanguageSuffix(locale);const aiModel = createModel(provider, model, apiKey, baseUrl);try {diff --git a/src/core/capture/ai/prompts.ts b/src/core/capture/ai/prompts.tsindex d07b350..ec779c1 100644--- a/src/core/capture/ai/prompts.ts+++ b/src/core/capture/ai/prompts.ts@@ -3,10 +3,9 @@ export const STEP_DESCRIPTION_PROMPT = `You are describing steps in a browser wo{{context}}Examples of good descriptions:-- "Click the Submit button"-- "Enter email address in the Email field"-- "Select 'Admin' from the Role dropdown"-- "Navigate to the Settings page"+{{examples}}++Copy button labels, field names, and menu items exactly as they appear on the page. Never translate them.Write only the description, no preamble.`;@@ -19,16 +18,14 @@ Write a title and a description for this workflow.TITLE: specific and descriptive. Mention the application or website name and the specific task performed. Reference specific pages, features, or items that were interacted with. MUST be under 60 characters.Examples of good titles:-- "Review claude-code Pull Requests"-- "Configure Slack Notification Preferences"-- "Submit Expense Report in Workday"-- "Create Repository in GitHub Organization"+{{titleExamples}}DESCRIPTION: one or two sentences stating what the workflow accomplishes and who would follow it. Do not repeat the title. Do not list the individual steps. Do not mention any UI element that does not appear in the steps above.Examples of good descriptions:-- "Reset a locked-out user's password from the Okta admin panel. For IT support staff."-- "Configure which Slack channels send desktop notifications, and set a do-not-disturb schedule."`;+{{descriptionExamples}}++Copy application names, page names, and UI labels exactly as they appear in the steps. Never translate them.`;export const GUIDE_META_JSON_SUFFIX = `@@ -82,8 +79,27 @@ const LANGUAGE_NAMES: Record<string, string> = {zh: 'Chinese',};+const LANGUAGE_INSTRUCTIONS: Record<Exclude<AILanguageCode, 'en'>, string> = {+ es: '\nIMPORTANTE: escribe el resultado en español. No traduzcas los nombres de botones, campos ni páginas.',+ fr: '\nIMPORTANT : rédige le résultat en français. Ne traduis pas les noms de boutons, de champs ni de pages.',+ 'pt-BR': '\nIMPORTANTE: escreva o resultado em português do Brasil. Não traduza nomes de botões, campos ou páginas.',+ de: '\nWICHTIG: Schreibe die Ausgabe auf Deutsch. Übersetze keine Schaltflächen-, Feld- oder Seitennamen.',+ 'zh-CN': '\n重要:请用中文输出。不要翻译按钮、字段和页面的名称。',+};+export function getLanguageSuffix(locale: string): string {if (locale.startsWith('en')) return '';- const lang = LANGUAGE_NAMES[locale.split('-')[0]] || locale;- return `\nIMPORTANT: Write the output in ${lang}.`;++ const instructions: Record<string, string | undefined> = LANGUAGE_INSTRUCTIONS;++ const exact = instructions[locale];+ if (exact) return exact;++ const base = locale.split('-')[0];+ for (const [code, instruction] of Object.entries(LANGUAGE_INSTRUCTIONS)) {+ if (code.split('-')[0] === base) return instruction;+ }++ const lang = LANGUAGE_NAMES[base] || locale;+ return `\nIMPORTANT: Write the output in ${lang}. Never translate button, field, or page names.`;}