@prenta/plugin-ai 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.md +16 -3
- package/dist/__tests__/index.test.js +30 -30
- package/dist/__tests__/index.test.js.map +1 -1
- package/dist/audit/document-auditor.d.ts +2 -1
- package/dist/audit/document-auditor.d.ts.map +1 -1
- package/dist/index.d.ts +12 -64
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -62
- package/dist/index.js.map +1 -1
- package/dist/scoring/readability.d.ts +0 -6
- package/dist/scoring/readability.d.ts.map +1 -1
- package/dist/scoring/readability.js +3 -3
- package/dist/scoring/readability.js.map +1 -1
- package/dist/scoring/seo-score.d.ts.map +1 -1
- package/dist/scoring/seo-score.js +1 -0
- package/dist/scoring/seo-score.js.map +1 -1
- package/package.json +4 -5
- package/dist/__tests__/alt-text-prompt.test.d.ts +0 -2
- package/dist/__tests__/alt-text-prompt.test.d.ts.map +0 -1
- package/dist/__tests__/alt-text-prompt.test.js +0 -15
- package/dist/__tests__/alt-text-prompt.test.js.map +0 -1
- package/dist/__tests__/content-generator.test.d.ts +0 -2
- package/dist/__tests__/content-generator.test.d.ts.map +0 -1
- package/dist/__tests__/content-generator.test.js +0 -200
- package/dist/__tests__/content-generator.test.js.map +0 -1
- package/dist/__tests__/hooks-embedding-noprovider.test.d.ts +0 -2
- package/dist/__tests__/hooks-embedding-noprovider.test.d.ts.map +0 -1
- package/dist/__tests__/hooks-embedding-noprovider.test.js +0 -32
- package/dist/__tests__/hooks-embedding-noprovider.test.js.map +0 -1
- package/dist/__tests__/hooks.test.d.ts +0 -2
- package/dist/__tests__/hooks.test.d.ts.map +0 -1
- package/dist/__tests__/hooks.test.js +0 -124
- package/dist/__tests__/hooks.test.js.map +0 -1
- package/dist/__tests__/http.test.d.ts +0 -2
- package/dist/__tests__/http.test.d.ts.map +0 -1
- package/dist/__tests__/http.test.js +0 -44
- package/dist/__tests__/http.test.js.map +0 -1
- package/dist/__tests__/media-vision.test.d.ts +0 -2
- package/dist/__tests__/media-vision.test.d.ts.map +0 -1
- package/dist/__tests__/media-vision.test.js +0 -83
- package/dist/__tests__/media-vision.test.js.map +0 -1
- package/dist/__tests__/meta-generator.test.d.ts +0 -2
- package/dist/__tests__/meta-generator.test.d.ts.map +0 -1
- package/dist/__tests__/meta-generator.test.js +0 -28
- package/dist/__tests__/meta-generator.test.js.map +0 -1
- package/dist/__tests__/plugin-config.test.d.ts +0 -2
- package/dist/__tests__/plugin-config.test.d.ts.map +0 -1
- package/dist/__tests__/plugin-config.test.js +0 -104
- package/dist/__tests__/plugin-config.test.js.map +0 -1
- package/dist/__tests__/prompt.test.d.ts +0 -2
- package/dist/__tests__/prompt.test.d.ts.map +0 -1
- package/dist/__tests__/prompt.test.js +0 -28
- package/dist/__tests__/prompt.test.js.map +0 -1
- package/dist/admin/AIScorePanel.d.ts +0 -19
- package/dist/admin/AIScorePanel.d.ts.map +0 -1
- package/dist/admin/AIScorePanel.js +0 -52
- package/dist/admin/AIScorePanel.js.map +0 -1
- package/dist/admin/BrandVoiceSettings.d.ts +0 -11
- package/dist/admin/BrandVoiceSettings.d.ts.map +0 -1
- package/dist/admin/BrandVoiceSettings.js +0 -162
- package/dist/admin/BrandVoiceSettings.js.map +0 -1
- package/dist/admin/ContentScoreDashboard.d.ts +0 -15
- package/dist/admin/ContentScoreDashboard.d.ts.map +0 -1
- package/dist/admin/ContentScoreDashboard.js +0 -64
- package/dist/admin/ContentScoreDashboard.js.map +0 -1
- package/dist/admin/WritingAssistantToolbar.d.ts +0 -13
- package/dist/admin/WritingAssistantToolbar.d.ts.map +0 -1
- package/dist/admin/WritingAssistantToolbar.js +0 -49
- package/dist/admin/WritingAssistantToolbar.js.map +0 -1
- package/dist/brand/consistency-checker.d.ts +0 -17
- package/dist/brand/consistency-checker.d.ts.map +0 -1
- package/dist/brand/consistency-checker.js +0 -47
- package/dist/brand/consistency-checker.js.map +0 -1
- package/dist/brand/profile-builder.d.ts +0 -10
- package/dist/brand/profile-builder.d.ts.map +0 -1
- package/dist/brand/profile-builder.js +0 -94
- package/dist/brand/profile-builder.js.map +0 -1
- package/dist/brand/voice-profile.d.ts +0 -30
- package/dist/brand/voice-profile.d.ts.map +0 -1
- package/dist/brand/voice-profile.js +0 -2
- package/dist/brand/voice-profile.js.map +0 -1
- package/dist/collections.d.ts +0 -3
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -2
- package/dist/collections.js.map +0 -1
- package/dist/fields.d.ts +0 -3
- package/dist/fields.d.ts.map +0 -1
- package/dist/fields.js +0 -2
- package/dist/fields.js.map +0 -1
- package/dist/hooks.d.ts +0 -3
- package/dist/hooks.d.ts.map +0 -1
- package/dist/hooks.js +0 -84
- package/dist/hooks.js.map +0 -1
- package/dist/media/alt-text-generator.d.ts +0 -27
- package/dist/media/alt-text-generator.d.ts.map +0 -1
- package/dist/media/alt-text-generator.js +0 -68
- package/dist/media/alt-text-generator.js.map +0 -1
- package/dist/media/alt-text-prompt.d.ts +0 -6
- package/dist/media/alt-text-prompt.d.ts.map +0 -1
- package/dist/media/alt-text-prompt.js +0 -32
- package/dist/media/alt-text-prompt.js.map +0 -1
- package/dist/media/auto-tagger.d.ts +0 -30
- package/dist/media/auto-tagger.d.ts.map +0 -1
- package/dist/media/auto-tagger.js +0 -54
- package/dist/media/auto-tagger.js.map +0 -1
- package/dist/media/json.d.ts +0 -4
- package/dist/media/json.d.ts.map +0 -1
- package/dist/media/json.js +0 -8
- package/dist/media/json.js.map +0 -1
- package/dist/prompt.d.ts +0 -30
- package/dist/prompt.d.ts.map +0 -1
- package/dist/prompt.js +0 -46
- package/dist/prompt.js.map +0 -1
- package/dist/providers/anthropic.d.ts +0 -8
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js +0 -156
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/http.d.ts +0 -25
- package/dist/providers/http.d.ts.map +0 -1
- package/dist/providers/http.js +0 -40
- package/dist/providers/http.js.map +0 -1
- package/dist/providers/index.d.ts +0 -49
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -35
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/openai.d.ts +0 -7
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js +0 -143
- package/dist/providers/openai.js.map +0 -1
- package/dist/scoring/brand-alignment.d.ts +0 -12
- package/dist/scoring/brand-alignment.d.ts.map +0 -1
- package/dist/scoring/brand-alignment.js +0 -48
- package/dist/scoring/brand-alignment.js.map +0 -1
- package/dist/search/clustering.d.ts +0 -20
- package/dist/search/clustering.d.ts.map +0 -1
- package/dist/search/clustering.js +0 -89
- package/dist/search/clustering.js.map +0 -1
- package/dist/search/embeddings.d.ts +0 -14
- package/dist/search/embeddings.d.ts.map +0 -1
- package/dist/search/embeddings.js +0 -42
- package/dist/search/embeddings.js.map +0 -1
- package/dist/search/semantic-search.d.ts +0 -31
- package/dist/search/semantic-search.d.ts.map +0 -1
- package/dist/search/semantic-search.js +0 -59
- package/dist/search/semantic-search.js.map +0 -1
- package/dist/translation/translator.d.ts +0 -24
- package/dist/translation/translator.d.ts.map +0 -1
- package/dist/translation/translator.js +0 -48
- package/dist/translation/translator.js.map +0 -1
- package/dist/writing/assistant.d.ts +0 -28
- package/dist/writing/assistant.d.ts.map +0 -1
- package/dist/writing/assistant.js +0 -126
- package/dist/writing/assistant.js.map +0 -1
- package/dist/writing/content-generator.d.ts +0 -107
- package/dist/writing/content-generator.d.ts.map +0 -1
- package/dist/writing/content-generator.js +0 -290
- package/dist/writing/content-generator.js.map +0 -1
- package/dist/writing/inline-suggestions.d.ts +0 -18
- package/dist/writing/inline-suggestions.d.ts.map +0 -1
- package/dist/writing/inline-suggestions.js +0 -41
- package/dist/writing/inline-suggestions.js.map +0 -1
- package/dist/writing/meta-generator.d.ts +0 -19
- package/dist/writing/meta-generator.d.ts.map +0 -1
- package/dist/writing/meta-generator.js +0 -68
- package/dist/writing/meta-generator.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WritingAssistantToolbar.js","sourceRoot":"","sources":["../../src/admin/WritingAssistantToolbar.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAqBZ,MAAM,OAAO,GAAoB;IAC/B,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE;IACtD,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE;IAC3E,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,IAAI,EAAE;IAC/E,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,IAAI,EAAE;IAC7E,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,IAAI,EAAE;CAClF,CAAA;AAED,4EAA4E;AAC5E,MAAM,UAAU,uBAAuB,CAAC,EACtC,UAAU,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,YAAY,GACiB;IAC7B,MAAM,QAAQ,GAA+B;QAC3C,UAAU;QACV,QAAQ;QACR,UAAU;QACV,SAAS;QACT,WAAW;KACZ,CAAA;IAED,OAAO,CACL,eACE,KAAK,EAAE;YACL,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,CAAC;YACN,OAAO,EAAE,SAAS;YAClB,YAAY,EAAE,CAAC;YACf,MAAM,EAAE,mBAAmB;YAC3B,eAAe,EAAE,SAAS;SAC3B,aAED,eAAM,KAAK,EAAE,EAAE,QA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,CAAC,EACD,YAAY,IAAI,CACf,eAAM,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,EAAE,8BAAsB,CACrF,IACG,CACP,CAAA;AACH,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { BrandVoiceProfile } from './voice-profile.js';
|
|
2
|
-
export interface ConsistencyResult {
|
|
3
|
-
score: number;
|
|
4
|
-
issues: Array<{
|
|
5
|
-
type: string;
|
|
6
|
-
location: string;
|
|
7
|
-
suggestion: string;
|
|
8
|
-
severity: 'low' | 'medium' | 'high';
|
|
9
|
-
}>;
|
|
10
|
-
highlights: Array<{
|
|
11
|
-
text: string;
|
|
12
|
-
type: 'good' | 'off-brand';
|
|
13
|
-
}>;
|
|
14
|
-
}
|
|
15
|
-
/** Checks content for consistency against a brand voice profile. */
|
|
16
|
-
export declare function checkConsistency(content: string, profile: BrandVoiceProfile): Promise<ConsistencyResult>;
|
|
17
|
-
//# sourceMappingURL=consistency-checker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consistency-checker.d.ts","sourceRoot":"","sources":["../../src/brand/consistency-checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,MAAM,CAAA;QAChB,UAAU,EAAE,MAAM,CAAA;QAClB,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;KACpC,CAAC,CAAA;IACF,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,CAAC,CAAA;CAChE;AAED,oEAAoE;AACpE,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAkD5B"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/** Checks content for consistency against a brand voice profile. */
|
|
2
|
-
export async function checkConsistency(content, profile) {
|
|
3
|
-
const issues = [];
|
|
4
|
-
const highlights = [];
|
|
5
|
-
for (const avoided of profile.vocabulary.avoided) {
|
|
6
|
-
const regex = new RegExp(`\\b${avoided}\\b`, 'gi');
|
|
7
|
-
let match;
|
|
8
|
-
while ((match = regex.exec(content)) !== null) {
|
|
9
|
-
issues.push({
|
|
10
|
-
type: 'vocabulary',
|
|
11
|
-
location: `character ${match.index}`,
|
|
12
|
-
suggestion: `Replace "${avoided}" with a brand-appropriate alternative`,
|
|
13
|
-
severity: 'medium',
|
|
14
|
-
});
|
|
15
|
-
highlights.push({ text: match[0], type: 'off-brand' });
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
for (const preferred of profile.vocabulary.preferred) {
|
|
19
|
-
if (content.toLowerCase().includes(preferred.toLowerCase())) {
|
|
20
|
-
highlights.push({ text: preferred, type: 'good' });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const sentences = content.split(/[.!?]+/).filter(Boolean);
|
|
24
|
-
const targetLengths = {
|
|
25
|
-
short: [5, 15],
|
|
26
|
-
medium: [10, 25],
|
|
27
|
-
long: [20, 40],
|
|
28
|
-
varied: [5, 40],
|
|
29
|
-
};
|
|
30
|
-
const [minLen, maxLen] = targetLengths[profile.style.sentenceLength] ?? [5, 40];
|
|
31
|
-
for (let i = 0; i < sentences.length; i++) {
|
|
32
|
-
const wordCount = sentences[i].trim().split(/\s+/).filter(Boolean).length;
|
|
33
|
-
if (wordCount < minLen || wordCount > maxLen) {
|
|
34
|
-
issues.push({
|
|
35
|
-
type: 'sentence-length',
|
|
36
|
-
location: `sentence ${i + 1}`,
|
|
37
|
-
suggestion: `Sentence has ${wordCount} words — target is ${minLen}-${maxLen}`,
|
|
38
|
-
severity: 'low',
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const totalPossibleIssues = sentences.length + profile.vocabulary.avoided.length;
|
|
43
|
-
const issueRatio = totalPossibleIssues > 0 ? issues.length / totalPossibleIssues : 0;
|
|
44
|
-
const score = Math.round(Math.max(0, Math.min(100, 100 - issueRatio * 100)));
|
|
45
|
-
return { score, issues, highlights };
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=consistency-checker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consistency-checker.js","sourceRoot":"","sources":["../../src/brand/consistency-checker.ts"],"names":[],"mappings":"AAaA,oEAAoE;AACpE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAe,EACf,OAA0B;IAE1B,MAAM,MAAM,GAAgC,EAAE,CAAA;IAC9C,MAAM,UAAU,GAAoC,EAAE,CAAA;IAEtD,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACjD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,OAAO,KAAK,EAAE,IAAI,CAAC,CAAA;QAClD,IAAI,KAA6B,CAAA;QACjC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAC9C,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,aAAa,KAAK,CAAC,KAAK,EAAE;gBACpC,UAAU,EAAE,YAAY,OAAO,wCAAwC;gBACvE,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAA;YACF,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;IAED,KAAK,MAAM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E,QAAQ,EAAE,KAAK;aAChB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,MAAM,mBAAmB,GAAG,SAAS,CAAC,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAA;IAChF,MAAM,UAAU,GAAG,mBAAmB,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAA;IACpF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;IAE5E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAA;AACtC,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AIProvider } from '../providers/index.js';
|
|
2
|
-
import type { BrandVoiceProfile } from './voice-profile.js';
|
|
3
|
-
export interface ProfileBuilderOptions {
|
|
4
|
-
name: string;
|
|
5
|
-
sampleSize?: number;
|
|
6
|
-
provider?: AIProvider;
|
|
7
|
-
}
|
|
8
|
-
/** Analyzes content samples to build a brand voice profile. */
|
|
9
|
-
export declare function buildBrandProfile(content: string[], options?: ProfileBuilderOptions): Promise<BrandVoiceProfile>;
|
|
10
|
-
//# sourceMappingURL=profile-builder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profile-builder.d.ts","sourceRoot":"","sources":["../../src/brand/profile-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,UAAU,CAAA;CACtB;AAED,+DAA+D;AAC/D,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CA0G5B"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/** Analyzes content samples to build a brand voice profile. */
|
|
2
|
-
export async function buildBrandProfile(content, options) {
|
|
3
|
-
const samples = options?.sampleSize ? content.slice(0, options.sampleSize) : content;
|
|
4
|
-
const totalWords = samples.reduce((sum, s) => sum + s.split(/\s+/).filter(Boolean).length, 0);
|
|
5
|
-
const totalSentences = samples.reduce((sum, s) => sum + (s.match(/[.!?]+/g)?.length ?? 1), 0);
|
|
6
|
-
const avgSentenceLength = totalSentences > 0 ? totalWords / totalSentences : 15;
|
|
7
|
-
let sentenceLength;
|
|
8
|
-
if (avgSentenceLength < 12)
|
|
9
|
-
sentenceLength = 'short';
|
|
10
|
-
else if (avgSentenceLength < 22)
|
|
11
|
-
sentenceLength = 'medium';
|
|
12
|
-
else if (avgSentenceLength < 30)
|
|
13
|
-
sentenceLength = 'long';
|
|
14
|
-
else
|
|
15
|
-
sentenceLength = 'varied';
|
|
16
|
-
const baseProfile = {
|
|
17
|
-
id: crypto.randomUUID(),
|
|
18
|
-
name: options?.name ?? 'Untitled Profile',
|
|
19
|
-
tone: [
|
|
20
|
-
{ dimension: 'professional', value: 0.7 },
|
|
21
|
-
{ dimension: 'friendly', value: 0.5 },
|
|
22
|
-
{ dimension: 'authoritative', value: 0.6 },
|
|
23
|
-
],
|
|
24
|
-
vocabulary: {
|
|
25
|
-
preferred: [],
|
|
26
|
-
avoided: [],
|
|
27
|
-
jargonLevel: 'minimal',
|
|
28
|
-
},
|
|
29
|
-
style: {
|
|
30
|
-
sentenceLength,
|
|
31
|
-
paragraphLength: 'medium',
|
|
32
|
-
formality: 0.6,
|
|
33
|
-
activeVoiceRatio: 0.7,
|
|
34
|
-
},
|
|
35
|
-
audience: {
|
|
36
|
-
expertise: 'intermediate',
|
|
37
|
-
},
|
|
38
|
-
examples: samples.slice(0, 3).map((text) => ({
|
|
39
|
-
text: text.slice(0, 200),
|
|
40
|
-
score: 0.8,
|
|
41
|
-
})),
|
|
42
|
-
};
|
|
43
|
-
if (!options?.provider) {
|
|
44
|
-
return baseProfile;
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const analysis = await options.provider.generateText(`Analyze the tone, style, and voice of the following content samples. Return a JSON object with:
|
|
48
|
-
- "tone": array of { "dimension": string, "value": number (0-1) } for dimensions like professional, friendly, authoritative, casual, technical, empathetic
|
|
49
|
-
- "preferred": array of commonly used words/phrases to keep
|
|
50
|
-
- "avoided": array of words/phrases that don't fit the voice
|
|
51
|
-
- "jargonLevel": "none" | "minimal" | "moderate" | "heavy"
|
|
52
|
-
- "formality": number 0-1 (0 = very casual, 1 = very formal)
|
|
53
|
-
- "activeVoiceRatio": estimated ratio 0-1 of active vs passive voice
|
|
54
|
-
- "expertise": "beginner" | "intermediate" | "expert"
|
|
55
|
-
|
|
56
|
-
Content samples:
|
|
57
|
-
${samples.slice(0, 5).join('\n---\n')}`, {
|
|
58
|
-
systemPrompt: 'You are a brand voice analyst. Analyze writing patterns and return valid JSON only.',
|
|
59
|
-
maxTokens: 1024,
|
|
60
|
-
temperature: 0.3,
|
|
61
|
-
});
|
|
62
|
-
const cleaned = analysis.text
|
|
63
|
-
.replace(/```json?\n?/g, '')
|
|
64
|
-
.replace(/```/g, '')
|
|
65
|
-
.trim();
|
|
66
|
-
const parsed = JSON.parse(cleaned);
|
|
67
|
-
if (parsed.tone?.length) {
|
|
68
|
-
baseProfile.tone = parsed.tone;
|
|
69
|
-
}
|
|
70
|
-
if (parsed.preferred?.length) {
|
|
71
|
-
baseProfile.vocabulary.preferred = parsed.preferred;
|
|
72
|
-
}
|
|
73
|
-
if (parsed.avoided?.length) {
|
|
74
|
-
baseProfile.vocabulary.avoided = parsed.avoided;
|
|
75
|
-
}
|
|
76
|
-
if (parsed.jargonLevel) {
|
|
77
|
-
baseProfile.vocabulary.jargonLevel = parsed.jargonLevel;
|
|
78
|
-
}
|
|
79
|
-
if (typeof parsed.formality === 'number') {
|
|
80
|
-
baseProfile.style.formality = parsed.formality;
|
|
81
|
-
}
|
|
82
|
-
if (typeof parsed.activeVoiceRatio === 'number') {
|
|
83
|
-
baseProfile.style.activeVoiceRatio = parsed.activeVoiceRatio;
|
|
84
|
-
}
|
|
85
|
-
if (parsed.expertise) {
|
|
86
|
-
baseProfile.audience.expertise = parsed.expertise;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
// Fall back to heuristic profile if LLM analysis fails
|
|
91
|
-
}
|
|
92
|
-
return baseProfile;
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=profile-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profile-builder.js","sourceRoot":"","sources":["../../src/brand/profile-builder.ts"],"names":[],"mappings":"AASA,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiB,EACjB,OAA+B;IAE/B,MAAM,OAAO,GAAG,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;IAEpF,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAC7F,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EA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AO,MAAM,CAAC,gBAAgB,KAAK,QAAQ,EAAE,CAAC;YAChD,WAAW,CAAC,KAAK,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAA;QAC9D,CAAC;QACD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,WAAW,CAAC,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,SAAgB,CAAA;QAC1D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,uDAAuD;IACzD,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface BrandVoiceProfile {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
tone: Array<{
|
|
5
|
-
dimension: string;
|
|
6
|
-
value: number;
|
|
7
|
-
}>;
|
|
8
|
-
vocabulary: {
|
|
9
|
-
preferred: string[];
|
|
10
|
-
avoided: string[];
|
|
11
|
-
jargonLevel: 'none' | 'minimal' | 'moderate' | 'technical';
|
|
12
|
-
};
|
|
13
|
-
style: {
|
|
14
|
-
sentenceLength: 'short' | 'medium' | 'long' | 'varied';
|
|
15
|
-
paragraphLength: 'short' | 'medium' | 'long';
|
|
16
|
-
formality: number;
|
|
17
|
-
activeVoiceRatio: number;
|
|
18
|
-
};
|
|
19
|
-
audience: {
|
|
20
|
-
expertise: 'beginner' | 'intermediate' | 'expert';
|
|
21
|
-
ageRange?: string;
|
|
22
|
-
persona?: string;
|
|
23
|
-
};
|
|
24
|
-
examples: Array<{
|
|
25
|
-
text: string;
|
|
26
|
-
score: number;
|
|
27
|
-
notes?: string;
|
|
28
|
-
}>;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=voice-profile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"voice-profile.d.ts","sourceRoot":"","sources":["../../src/brand/voice-profile.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACjD,UAAU,EAAE;QACV,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,OAAO,EAAE,MAAM,EAAE,CAAA;QACjB,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAA;KAC3D,CAAA;IACD,KAAK,EAAE;QACL,cAAc,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;QACtD,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;QAC5C,SAAS,EAAE,MAAM,CAAA;QACjB,gBAAgB,EAAE,MAAM,CAAA;KACzB,CAAA;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,UAAU,GAAG,cAAc,GAAG,QAAQ,CAAA;QACjD,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,CAAA;IACD,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACjE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"voice-profile.js","sourceRoot":"","sources":["../../src/brand/voice-profile.ts"],"names":[],"mappings":""}
|
package/dist/collections.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAExD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAM,CAAA"}
|
package/dist/collections.js
DELETED
package/dist/collections.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAyC,EAAE,CAAA"}
|
package/dist/fields.d.ts
DELETED
package/dist/fields.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEnD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAM,CAAA"}
|
package/dist/fields.js
DELETED
package/dist/fields.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAAoC,EAAE,CAAA"}
|
package/dist/hooks.d.ts
DELETED
package/dist/hooks.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,eAAO,MAAM,OAAO,EAAE,UAAU,EAoF/B,CAAA"}
|
package/dist/hooks.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { calculateCompositeScore } from './scoring/composite.js';
|
|
2
|
-
import { getReadabilityScore } from './scoring/readability.js';
|
|
3
|
-
import { calculateSEOScore } from './scoring/seo-score.js';
|
|
4
|
-
import { calculateAccessibilityScore } from './scoring/accessibility.js';
|
|
5
|
-
import { getAIProvider } from './providers/index.js';
|
|
6
|
-
import { generateEmbedding } from './search/embeddings.js';
|
|
7
|
-
export const aiHooks = [
|
|
8
|
-
{
|
|
9
|
-
event: 'afterUpdate',
|
|
10
|
-
handler: async (document) => {
|
|
11
|
-
const doc = document;
|
|
12
|
-
const body = doc.body ?? doc.data?.body ?? '';
|
|
13
|
-
const title = doc.title ?? doc.data?.title ?? '';
|
|
14
|
-
if (!body)
|
|
15
|
-
return;
|
|
16
|
-
try {
|
|
17
|
-
const readability = getReadabilityScore(body);
|
|
18
|
-
const seo = calculateSEOScore({
|
|
19
|
-
title,
|
|
20
|
-
metaDescription: doc.data?.metaDescription ?? '',
|
|
21
|
-
body,
|
|
22
|
-
});
|
|
23
|
-
// Match each <img> tag, then pull `src`/`alt` out separately. A single
|
|
24
|
-
// combined regex fails here: a greedy `[^>]*` before an optional
|
|
25
|
-
// `alt="…"` group consumes the whole tag, so `alt` is never captured and
|
|
26
|
-
// every image looks like it's missing alt text regardless of order.
|
|
27
|
-
const imgTagRegex = /<img\s[^>]*>/gi;
|
|
28
|
-
const images = [];
|
|
29
|
-
let imgMatch;
|
|
30
|
-
while ((imgMatch = imgTagRegex.exec(body)) !== null) {
|
|
31
|
-
const tag = imgMatch[0];
|
|
32
|
-
const src = /\ssrc="([^"]*)"/i.exec(tag)?.[1] ?? '';
|
|
33
|
-
const altAttr = /\salt="([^"]*)"/i.exec(tag);
|
|
34
|
-
images.push({ src, alt: altAttr ? altAttr[1] : undefined });
|
|
35
|
-
}
|
|
36
|
-
const linkRegex = /<a\s[^>]*href="([^"]*)"[^>]*>([^<]*)<\/a>/gi;
|
|
37
|
-
const links = [];
|
|
38
|
-
let linkMatch;
|
|
39
|
-
while ((linkMatch = linkRegex.exec(body)) !== null) {
|
|
40
|
-
links.push({ text: linkMatch[2] ?? '', href: linkMatch[1] ?? '' });
|
|
41
|
-
}
|
|
42
|
-
const headingRegex = /<(h[1-6])\b[^>]*>/gi;
|
|
43
|
-
const headings = [];
|
|
44
|
-
let hMatch;
|
|
45
|
-
while ((hMatch = headingRegex.exec(body)) !== null) {
|
|
46
|
-
headings.push(hMatch[1] ?? '');
|
|
47
|
-
}
|
|
48
|
-
const a11y = calculateAccessibilityScore({ html: body, images, links, headings });
|
|
49
|
-
const score = calculateCompositeScore({
|
|
50
|
-
readability: Math.max(0, 100 - readability.averageGradeLevel * 5),
|
|
51
|
-
seo: seo.score,
|
|
52
|
-
accessibility: a11y.score,
|
|
53
|
-
});
|
|
54
|
-
// Store score on the document data for the admin UI
|
|
55
|
-
if (doc.data && typeof doc.data === 'object') {
|
|
56
|
-
;
|
|
57
|
-
doc.data._aiScore = score;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch { }
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
event: 'afterCreate',
|
|
65
|
-
handler: async (document) => {
|
|
66
|
-
const doc = document;
|
|
67
|
-
const body = doc.body ?? doc.data?.body ?? '';
|
|
68
|
-
if (!body)
|
|
69
|
-
return;
|
|
70
|
-
const provider = getAIProvider();
|
|
71
|
-
if (!provider)
|
|
72
|
-
return;
|
|
73
|
-
try {
|
|
74
|
-
const embedding = await generateEmbedding(body.slice(0, 8000), provider);
|
|
75
|
-
if (doc.data && typeof doc.data === 'object') {
|
|
76
|
-
;
|
|
77
|
-
doc.data._embedding = embedding.vector;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch { }
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAs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;oBAC7C,CAAC;oBAAC,GAAG,CAAC,IAAY,CAAC,QAAQ,GAAG,KAAK,CAAA;gBACrC,CAAC;YACH,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACZ,CAAC;KACF;IACD;QACE,KAAK,EAAE,aAAa;QACpB,OAAO,EAAE,KAAK,EAAE,QAAiB,EAAE,EAAE;YACnC,MAAM,GAAG,GAAG,QAAyE,CAAA;YACrF,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAK,GAAG,CAAC,IAAI,EAAE,IAAe,IAAI,EAAE,CAAA;YACzD,IAAI,CAAC,IAAI;gBAAE,OAAM;YAEjB,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAA;YAChC,IAAI,CAAC,QAAQ;gBAAE,OAAM;YAErB,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAA;gBAExE,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;oBAC7C,CAAC;oBAAC,GAAG,CAAC,IAAY,CAAC,UAAU,GAAG,SAAS,CAAC,MAAM,CAAA;gBAClD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACZ,CAAC;KACF;CACF,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { AIProvider, ImageInput } from '../providers/index.js';
|
|
2
|
-
export interface AltTextContext {
|
|
3
|
-
pageTitle?: string;
|
|
4
|
-
surroundingText?: string;
|
|
5
|
-
purpose?: 'decorative' | 'informative' | 'functional';
|
|
6
|
-
provider?: AIProvider;
|
|
7
|
-
/**
|
|
8
|
-
* Raw image bytes. When supplied AND the provider supports vision
|
|
9
|
-
* (`analyzeImage`), the model actually sees the image. Without it the result
|
|
10
|
-
* is only a heuristic inferred from `pageTitle`/`surroundingText`, so
|
|
11
|
-
* `usedVision` is false and confidence is capped low.
|
|
12
|
-
*/
|
|
13
|
-
image?: ImageInput;
|
|
14
|
-
}
|
|
15
|
-
export interface AltTextResult {
|
|
16
|
-
altText: string;
|
|
17
|
-
isDecorative: boolean;
|
|
18
|
-
confidence: number;
|
|
19
|
-
alternatives: string[];
|
|
20
|
-
/** True only when a real vision model analyzed the image bytes. */
|
|
21
|
-
usedVision: boolean;
|
|
22
|
-
}
|
|
23
|
-
/** Generates accessible alt text. Uses a vision model when image bytes + a
|
|
24
|
-
* vision-capable provider are available; otherwise falls back to a clearly-
|
|
25
|
-
* labeled heuristic over the supplied context. */
|
|
26
|
-
export declare function generateAltText(imageUrl: string, context?: AltTextContext): Promise<AltTextResult>;
|
|
27
|
-
//# sourceMappingURL=alt-text-generator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"alt-text-generator.d.ts","sourceRoot":"","sources":["../../src/media/alt-text-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AASnE,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,YAAY,GAAG,aAAa,GAAG,YAAY,CAAA;IACrD,QAAQ,CAAC,EAAE,UAAU,CAAA;IACrB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,OAAO,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,mEAAmE;IACnE,UAAU,EAAE,OAAO,CAAA;CACpB;AAKD;;kDAEkD;AAClD,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,aAAa,CAAC,CAqExB"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { requireAIProvider } from '../providers/index.js';
|
|
2
|
-
import { ALT_TEXT_JSON_SHAPE, ALT_TEXT_SYSTEM_PROMPT, normalizeGeneratedAltText, } from './alt-text-prompt.js';
|
|
3
|
-
import { clampConfidence, stripJsonFences } from './json.js';
|
|
4
|
-
/** Max confidence we'll report for a text-only (no real image) heuristic. */
|
|
5
|
-
const HEURISTIC_MAX_CONFIDENCE = 0.4;
|
|
6
|
-
/** Generates accessible alt text. Uses a vision model when image bytes + a
|
|
7
|
-
* vision-capable provider are available; otherwise falls back to a clearly-
|
|
8
|
-
* labeled heuristic over the supplied context. */
|
|
9
|
-
export async function generateAltText(imageUrl, context) {
|
|
10
|
-
if (context?.purpose === 'decorative') {
|
|
11
|
-
return { altText: '', isDecorative: true, confidence: 1.0, alternatives: [], usedVision: false };
|
|
12
|
-
}
|
|
13
|
-
const ai = context?.provider ?? requireAIProvider();
|
|
14
|
-
const canSeeImage = !!context?.image && typeof ai.analyzeImage === 'function';
|
|
15
|
-
const contextInfo = [
|
|
16
|
-
context?.pageTitle && `Page title: ${context.pageTitle}`,
|
|
17
|
-
context?.surroundingText && `Nearby text: ${context.surroundingText.slice(0, 300)}`,
|
|
18
|
-
context?.purpose && `Purpose: ${context.purpose}`,
|
|
19
|
-
]
|
|
20
|
-
.filter(Boolean)
|
|
21
|
-
.join('\n');
|
|
22
|
-
let result;
|
|
23
|
-
if (canSeeImage) {
|
|
24
|
-
const prompt = `Analyze the attached image and generate accessible alt text.\n\n${contextInfo ? `Context:\n${contextInfo}\n\n` : ''}${ALT_TEXT_JSON_SHAPE}`;
|
|
25
|
-
result = await ai.analyzeImage(context.image, prompt, {
|
|
26
|
-
systemPrompt: ALT_TEXT_SYSTEM_PROMPT,
|
|
27
|
-
maxTokens: 512,
|
|
28
|
-
temperature: 0.3,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
// No vision: infer ONLY from context. Be explicit so the model doesn't
|
|
33
|
-
// fabricate visual detail it cannot possibly know.
|
|
34
|
-
const prompt = `You CANNOT see the image. Based only on the context below and the file name, suggest plausible accessible alt text, set isDecorative false unless context clearly indicates ornamentation, and report low confidence since the image was not analyzed.\n\n${contextInfo ? `Context:\n${contextInfo}\n` : ''}File: ${imageUrl}\n\n${ALT_TEXT_JSON_SHAPE}`;
|
|
35
|
-
result = await ai.generateText(prompt, {
|
|
36
|
-
systemPrompt: ALT_TEXT_SYSTEM_PROMPT,
|
|
37
|
-
maxTokens: 512,
|
|
38
|
-
temperature: 0.3,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const parsed = JSON.parse(stripJsonFences(result.text));
|
|
43
|
-
const isDecorative = parsed.isDecorative === true;
|
|
44
|
-
const altText = normalizeGeneratedAltText(parsed.altText ?? '', isDecorative);
|
|
45
|
-
const rawConfidence = clampConfidence(parsed.confidence, canSeeImage ? 0.7 : 0.3);
|
|
46
|
-
const alternatives = isDecorative
|
|
47
|
-
? []
|
|
48
|
-
: (Array.isArray(parsed.alternatives) ? parsed.alternatives : [])
|
|
49
|
-
.map((a) => normalizeGeneratedAltText(String(a ?? ''), false))
|
|
50
|
-
.filter(Boolean)
|
|
51
|
-
.slice(0, 2);
|
|
52
|
-
return {
|
|
53
|
-
altText,
|
|
54
|
-
isDecorative,
|
|
55
|
-
confidence: isDecorative
|
|
56
|
-
? 1
|
|
57
|
-
: canSeeImage
|
|
58
|
-
? rawConfidence
|
|
59
|
-
: Math.min(rawConfidence, HEURISTIC_MAX_CONFIDENCE),
|
|
60
|
-
alternatives,
|
|
61
|
-
usedVision: canSeeImage,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return { altText: '', isDecorative: false, confidence: 0, alternatives: [], usedVision: false };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=alt-text-generator.js.map
|
|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EAAE,EAAE,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;iBAC7D,MAAM,CAAC,OAAO,CAAC;iBACf,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAClB,OAAO;YACL,OAAO;YACP,YAAY;YACZ,UAAU,EAAE,YAAY;gBACtB,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,WAAW;oBACX,CAAC,CAAC,aAAa;oBACf,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,wBAAwB,CAAC;YACvD,YAAY;YACZ,UAAU,EAAE,WAAW;SACxB,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;IACjG,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** WCAG-aligned alt-text guidance shared by vision and heuristic paths. */
|
|
2
|
-
export declare const ALT_TEXT_SYSTEM_PROMPT = "You are an accessibility specialist writing alt text for web images (WCAG 2.1 / W3C best practices).\n\nRules:\n- Describe what matters for the image's purpose in context \u2014 not every visual detail.\n- Be concise: target \u2264125 characters; never exceed 125.\n- Do NOT start with \"image of\", \"photo of\", \"picture of\", or \"graphic of\" \u2014 screen readers already announce it as an image.\n- Do NOT include file names, dimensions, or SEO keyword stuffing.\n- Include visible text in the image when it is essential to understanding.\n- For people: describe relevant appearance only when needed for context; avoid speculative identity or sensitive traits.\n- If the image is purely decorative (borders, spacers, visual flourish with no informational value), set isDecorative true and altText to \"\".\n- For functional images (icons/buttons), describe the action or destination, not the pixel art.\n- When page context is provided, prefer alt text that fits the surrounding content.\n\nReturn valid JSON only.";
|
|
3
|
-
export declare const ALT_TEXT_JSON_SHAPE = "Return a JSON object with:\n- \"altText\": string (empty when decorative)\n- \"isDecorative\": boolean\n- \"alternatives\": array of exactly 2 alternative alt text options (empty strings when decorative)\n- \"confidence\": number 0-1";
|
|
4
|
-
/** Normalize model output to publishing-ready alt text. */
|
|
5
|
-
export declare function normalizeGeneratedAltText(raw: string, isDecorative: boolean): string;
|
|
6
|
-
//# sourceMappingURL=alt-text-prompt.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"alt-text-prompt.d.ts","sourceRoot":"","sources":["../../src/media/alt-text-prompt.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,kgCAaX,CAAA;AAExB,eAAO,MAAM,mBAAmB,8OAIL,CAAA;AAE3B,2DAA2D;AAC3D,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,MAAM,CAOpF"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/** WCAG-aligned alt-text guidance shared by vision and heuristic paths. */
|
|
2
|
-
export const ALT_TEXT_SYSTEM_PROMPT = `You are an accessibility specialist writing alt text for web images (WCAG 2.1 / W3C best practices).
|
|
3
|
-
|
|
4
|
-
Rules:
|
|
5
|
-
- Describe what matters for the image's purpose in context — not every visual detail.
|
|
6
|
-
- Be concise: target ≤125 characters; never exceed 125.
|
|
7
|
-
- Do NOT start with "image of", "photo of", "picture of", or "graphic of" — screen readers already announce it as an image.
|
|
8
|
-
- Do NOT include file names, dimensions, or SEO keyword stuffing.
|
|
9
|
-
- Include visible text in the image when it is essential to understanding.
|
|
10
|
-
- For people: describe relevant appearance only when needed for context; avoid speculative identity or sensitive traits.
|
|
11
|
-
- If the image is purely decorative (borders, spacers, visual flourish with no informational value), set isDecorative true and altText to "".
|
|
12
|
-
- For functional images (icons/buttons), describe the action or destination, not the pixel art.
|
|
13
|
-
- When page context is provided, prefer alt text that fits the surrounding content.
|
|
14
|
-
|
|
15
|
-
Return valid JSON only.`;
|
|
16
|
-
export const ALT_TEXT_JSON_SHAPE = `Return a JSON object with:
|
|
17
|
-
- "altText": string (empty when decorative)
|
|
18
|
-
- "isDecorative": boolean
|
|
19
|
-
- "alternatives": array of exactly 2 alternative alt text options (empty strings when decorative)
|
|
20
|
-
- "confidence": number 0-1`;
|
|
21
|
-
/** Normalize model output to publishing-ready alt text. */
|
|
22
|
-
export function normalizeGeneratedAltText(raw, isDecorative) {
|
|
23
|
-
if (isDecorative)
|
|
24
|
-
return '';
|
|
25
|
-
let s = raw.trim();
|
|
26
|
-
s = s.replace(/^(an?\s+)?(image|photo|picture|graphic|screenshot)\s+of\s+/i, '');
|
|
27
|
-
s = s.replace(/\s+/g, ' ').trim();
|
|
28
|
-
if (s.length > 125)
|
|
29
|
-
s = `${s.slice(0, 122).trim()}…`;
|
|
30
|
-
return s;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=alt-text-prompt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"alt-text-prompt.js","sourceRoot":"","sources":["../../src/media/alt-text-prompt.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;wBAad,CAAA;AAExB,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;2BAIR,CAAA;AAE3B,2DAA2D;AAC3D,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,YAAqB;IAC1E,IAAI,YAAY;QAAE,OAAO,EAAE,CAAA;IAC3B,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IAClB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,6DAA6D,EAAE,EAAE,CAAC,CAAA;IAChF,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACjC,IAAI,CAAC,CAAC,MAAM,GAAG,GAAG;QAAE,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,CAAA;IACpD,OAAO,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AIProvider, ImageInput } from '../providers/index.js';
|
|
2
|
-
export interface TaggingOptions {
|
|
3
|
-
maxTags?: number;
|
|
4
|
-
language?: string;
|
|
5
|
-
categories?: string[];
|
|
6
|
-
provider?: AIProvider;
|
|
7
|
-
/**
|
|
8
|
-
* Raw image bytes. When supplied AND the provider supports vision, the model
|
|
9
|
-
* actually analyzes the image; otherwise tags are inferred from the file name
|
|
10
|
-
* only and `usedVision` is false.
|
|
11
|
-
*/
|
|
12
|
-
image?: ImageInput;
|
|
13
|
-
}
|
|
14
|
-
export interface ImageTags {
|
|
15
|
-
tags: Array<{
|
|
16
|
-
label: string;
|
|
17
|
-
confidence: number;
|
|
18
|
-
}>;
|
|
19
|
-
categories: string[];
|
|
20
|
-
dominantColors: string[];
|
|
21
|
-
safeSearch: {
|
|
22
|
-
isSafe: boolean;
|
|
23
|
-
};
|
|
24
|
-
/** True only when a real vision model analyzed the image bytes. */
|
|
25
|
-
usedVision: boolean;
|
|
26
|
-
}
|
|
27
|
-
/** Automatically tags an image. Uses a vision model when image bytes + a
|
|
28
|
-
* vision-capable provider are available; otherwise infers from the file name. */
|
|
29
|
-
export declare function autoTagImage(imageUrl: string, options?: TaggingOptions): Promise<ImageTags>;
|
|
30
|
-
//# sourceMappingURL=auto-tagger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-tagger.d.ts","sourceRoot":"","sources":["../../src/media/auto-tagger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAInE,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,UAAU,CAAA;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAClD,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,UAAU,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAA;IAC/B,mEAAmE;IACnE,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;iFACiF;AACjF,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAyDjG"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { requireAIProvider } from '../providers/index.js';
|
|
2
|
-
import { stripJsonFences } from './json.js';
|
|
3
|
-
/** Automatically tags an image. Uses a vision model when image bytes + a
|
|
4
|
-
* vision-capable provider are available; otherwise infers from the file name. */
|
|
5
|
-
export async function autoTagImage(imageUrl, options) {
|
|
6
|
-
const ai = options?.provider ?? requireAIProvider();
|
|
7
|
-
const maxTags = options?.maxTags ?? 10;
|
|
8
|
-
const canSeeImage = !!options?.image && typeof ai.analyzeImage === 'function';
|
|
9
|
-
const categoryContext = options?.categories?.length
|
|
10
|
-
? `\nAvailable categories to choose from: ${options.categories.join(', ')}`
|
|
11
|
-
: '';
|
|
12
|
-
const jsonShape = `Return a JSON object with:
|
|
13
|
-
- "tags": array of objects with "label" and "confidence" (0-1), maximum ${maxTags} tags
|
|
14
|
-
- "categories": array of broad category strings (e.g., "nature", "technology", "people")
|
|
15
|
-
- "dominantColors": array of hex color strings for the dominant colors
|
|
16
|
-
- "isSafe": boolean indicating if the image is safe for work`;
|
|
17
|
-
const systemPrompt = `You are an image analysis expert. Analyze images and return structured tags.${options?.language ? ` Respond in ${options.language}.` : ''} Return valid JSON only.`;
|
|
18
|
-
let result;
|
|
19
|
-
if (canSeeImage) {
|
|
20
|
-
const prompt = `Analyze the attached image and provide tags, categories, and color information.${categoryContext}\n\n${jsonShape}`;
|
|
21
|
-
result = await ai.analyzeImage(options.image, prompt, {
|
|
22
|
-
systemPrompt,
|
|
23
|
-
maxTokens: 512,
|
|
24
|
-
temperature: 0.2,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const prompt = `You CANNOT see the image. Based only on the file name, suggest plausible tags/categories with LOW confidence. If you cannot determine whether the content is safe for work, set "isSafe" to false.${categoryContext}\n\nFile: ${imageUrl}\n\n${jsonShape}`;
|
|
29
|
-
result = await ai.generateText(prompt, { systemPrompt, maxTokens: 512, temperature: 0.2 });
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const parsed = JSON.parse(stripJsonFences(result.text));
|
|
33
|
-
return {
|
|
34
|
-
tags: (parsed.tags ?? []).slice(0, maxTags),
|
|
35
|
-
categories: parsed.categories ?? [],
|
|
36
|
-
dominantColors: parsed.dominantColors ?? [],
|
|
37
|
-
// SECURITY: fail CLOSED — only treat as safe when the model explicitly
|
|
38
|
-
// says so. A missing/invalid flag must not pass content as safe-for-work.
|
|
39
|
-
safeSearch: { isSafe: parsed.isSafe === true },
|
|
40
|
-
usedVision: canSeeImage,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// Parse failure → fail closed on safety.
|
|
45
|
-
return {
|
|
46
|
-
tags: [],
|
|
47
|
-
categories: [],
|
|
48
|
-
dominantColors: [],
|
|
49
|
-
safeSearch: { isSafe: false },
|
|
50
|
-
usedVision: canSeeImage,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=auto-tagger.js.map
|