Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(ai): normalise a generated title with the shared rules

davbio4785d38873e2
diff --git a/src/core/capture/ai/__tests__/meta.test.ts b/src/core/capture/ai/__tests__/meta.test.ts
index e2fbf41..2ffee00 100644
--- a/src/core/capture/ai/__tests__/meta.test.ts
+++ b/src/core/capture/ai/__tests__/meta.test.ts
@@ -157,6 +157,10 @@ describe('parseGuideMeta', () => {
});
});
+ it('collapses a newline the model put inside the title', () => {
+ expect(parseGuideMeta('{"title": "Okta\\nReset"}')?.title).toBe('Okta Reset');
+ });
+
it('unwraps a fenced code block the model added anyway', () => {
expect(parseGuideMeta('```json\n{"title": "Okta Reset"}\n```')).toEqual({
title: 'Okta Reset',
diff --git a/src/core/capture/ai/meta.ts b/src/core/capture/ai/meta.ts
index e786de2..7e6a4d6 100644
--- a/src/core/capture/ai/meta.ts
+++ b/src/core/capture/ai/meta.ts
@@ -1,4 +1,5 @@
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 { GUIDE_META_JSON_SUFFIX, GUIDE_META_PROMPT, getLanguageSuffix } from './prompts';
@@ -9,7 +10,6 @@ export interface GuideMeta {
description?: string;
}
-const MAX_TITLE_LENGTH = 70;
const MAX_BARE_TITLE_LENGTH = 100;
const FENCE = /^```(?:json)?\s*|\s*```$/g;
@@ -24,7 +24,7 @@ const guideMetaSchema = jsonSchema<{ title: string; description?: string | null
});
function toGuideMeta(rawTitle: unknown, rawDescription: unknown): GuideMeta | null {
- let title = typeof rawTitle === 'string' ? rawTitle.trim().replace(/^"|"$/g, '') : '';
+ let title = typeof rawTitle === 'string' ? sanitizeGuideTitle(rawTitle).replace(/^"|"$/g, '') : '';
if (!title) return null;
if (title.length > MAX_TITLE_LENGTH) title = `${title.slice(0, MAX_TITLE_LENGTH - 3)}...`;