@intlayer/backend 3.5.5 → 3.5.7
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/dist/cjs/controllers/ai.controller.cjs +175 -7
- package/dist/cjs/controllers/ai.controller.cjs.map +1 -1
- package/dist/cjs/controllers/dictionary.controller.cjs +50 -17
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
- package/dist/cjs/controllers/project.controller.cjs +2 -6
- package/dist/cjs/controllers/project.controller.cjs.map +1 -1
- package/dist/cjs/controllers/tag.controller.cjs +235 -0
- package/dist/cjs/controllers/tag.controller.cjs.map +1 -0
- package/dist/cjs/controllers/user.controller.cjs +1 -0
- package/dist/cjs/controllers/user.controller.cjs.map +1 -1
- package/dist/cjs/export.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/models/tag.model.cjs +31 -0
- package/dist/cjs/models/tag.model.cjs.map +1 -0
- package/dist/cjs/routes/ai.routes.cjs +37 -4
- package/dist/cjs/routes/ai.routes.cjs.map +1 -1
- package/dist/cjs/routes/dictionary.routes.cjs +4 -4
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
- package/dist/cjs/routes/tags.routes.cjs +60 -0
- package/dist/cjs/routes/tags.routes.cjs.map +1 -0
- package/dist/cjs/schemas/dictionary.schema.cjs +31 -6
- package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
- package/dist/cjs/schemas/project.schema.cjs +5 -0
- package/dist/cjs/schemas/project.schema.cjs.map +1 -1
- package/dist/cjs/schemas/tag.schema.cjs +64 -0
- package/dist/cjs/schemas/tag.schema.cjs.map +1 -0
- package/dist/cjs/services/dictionary.service.cjs +138 -27
- package/dist/cjs/services/dictionary.service.cjs.map +1 -1
- package/dist/cjs/services/project.service.cjs +13 -5
- package/dist/cjs/services/project.service.cjs.map +1 -1
- package/dist/cjs/services/tag.service.cjs +91 -0
- package/dist/cjs/services/tag.service.cjs.map +1 -0
- package/dist/cjs/types/dictionary.types.cjs.map +1 -1
- package/dist/cjs/types/tag.types.cjs +17 -0
- package/dist/cjs/types/tag.types.cjs.map +1 -0
- package/dist/cjs/utils/AI/askDocQuestion.cjs +185 -0
- package/dist/cjs/utils/AI/askDocQuestion.cjs.map +1 -0
- package/dist/cjs/utils/AI/embeddings.json +150583 -0
- package/dist/cjs/utils/{audit → auditDictionary}/PROMPT.md +6 -1
- package/dist/cjs/utils/{audit → auditDictionary}/index.cjs +10 -8
- package/dist/cjs/utils/auditDictionary/index.cjs.map +1 -0
- package/dist/cjs/utils/auditDictionaryField/PROMPT.md +115 -0
- package/dist/cjs/utils/auditDictionaryField/index.cjs +80 -0
- package/dist/cjs/utils/auditDictionaryField/index.cjs.map +1 -0
- package/dist/cjs/utils/auditDictionaryMetadata/PROMPT.md +76 -0
- package/dist/cjs/utils/auditDictionaryMetadata/index.cjs +76 -0
- package/dist/cjs/utils/auditDictionaryMetadata/index.cjs.map +1 -0
- package/dist/cjs/utils/auditTag/PROMPT.md +34 -0
- package/dist/cjs/utils/auditTag/index.cjs +72 -0
- package/dist/cjs/utils/auditTag/index.cjs.map +1 -0
- package/dist/cjs/utils/ensureArrayQueryFilter.cjs +39 -0
- package/dist/cjs/utils/ensureArrayQueryFilter.cjs.map +1 -0
- package/dist/cjs/utils/ensureMongoDocumentToObject.cjs +35 -0
- package/dist/cjs/utils/ensureMongoDocumentToObject.cjs.map +1 -0
- package/dist/cjs/utils/errors/errorCodes.cjs +91 -0
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +10 -11
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +6 -10
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +6 -10
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs +51 -0
- package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +2 -9
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/mapper/dictionary.cjs +8 -4
- package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -1
- package/dist/cjs/utils/mapper/organization.cjs +2 -4
- package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
- package/dist/cjs/utils/mapper/project.cjs +2 -4
- package/dist/cjs/utils/mapper/project.cjs.map +1 -1
- package/dist/cjs/utils/mapper/tag.cjs +37 -0
- package/dist/cjs/utils/mapper/tag.cjs.map +1 -0
- package/dist/cjs/utils/mapper/user.cjs +2 -4
- package/dist/cjs/utils/mapper/user.cjs.map +1 -1
- package/dist/cjs/utils/removeObjectKeys.cjs +35 -0
- package/dist/cjs/utils/removeObjectKeys.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateProject.cjs +17 -10
- package/dist/cjs/utils/validation/validateProject.cjs.map +1 -1
- package/dist/cjs/utils/validation/validateTag.cjs +93 -0
- package/dist/cjs/utils/validation/validateTag.cjs.map +1 -0
- package/dist/esm/controllers/ai.controller.mjs +170 -6
- package/dist/esm/controllers/ai.controller.mjs.map +1 -1
- package/dist/esm/controllers/dictionary.controller.mjs +50 -17
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +2 -6
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/tag.controller.mjs +203 -0
- package/dist/esm/controllers/tag.controller.mjs.map +1 -0
- package/dist/esm/controllers/user.controller.mjs +1 -0
- package/dist/esm/controllers/user.controller.mjs.map +1 -1
- package/dist/esm/export.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/models/tag.model.mjs +7 -0
- package/dist/esm/models/tag.model.mjs.map +1 -0
- package/dist/esm/routes/ai.routes.mjs +44 -5
- package/dist/esm/routes/ai.routes.mjs.map +1 -1
- package/dist/esm/routes/dictionary.routes.mjs +4 -4
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
- package/dist/esm/routes/tags.routes.mjs +40 -0
- package/dist/esm/routes/tags.routes.mjs.map +1 -0
- package/dist/esm/schemas/dictionary.schema.mjs +31 -6
- package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
- package/dist/esm/schemas/project.schema.mjs +5 -0
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/schemas/tag.schema.mjs +45 -0
- package/dist/esm/schemas/tag.schema.mjs.map +1 -0
- package/dist/esm/services/dictionary.service.mjs +136 -27
- package/dist/esm/services/dictionary.service.mjs.map +1 -1
- package/dist/esm/services/project.service.mjs +13 -5
- package/dist/esm/services/project.service.mjs.map +1 -1
- package/dist/esm/services/tag.service.mjs +61 -0
- package/dist/esm/services/tag.service.mjs.map +1 -0
- package/dist/esm/types/tag.types.mjs +1 -0
- package/dist/esm/types/tag.types.mjs.map +1 -0
- package/dist/esm/utils/AI/askDocQuestion.mjs +148 -0
- package/dist/esm/utils/AI/askDocQuestion.mjs.map +1 -0
- package/dist/esm/utils/AI/embeddings.json +150583 -0
- package/dist/esm/utils/{audit → auditDictionary}/PROMPT.md +6 -1
- package/dist/esm/utils/{audit → auditDictionary}/index.mjs +6 -4
- package/dist/esm/utils/auditDictionary/index.mjs.map +1 -0
- package/dist/esm/utils/auditDictionaryField/PROMPT.md +115 -0
- package/dist/esm/utils/auditDictionaryField/index.mjs +55 -0
- package/dist/esm/utils/auditDictionaryField/index.mjs.map +1 -0
- package/dist/esm/utils/auditDictionaryMetadata/PROMPT.md +76 -0
- package/dist/esm/utils/auditDictionaryMetadata/index.mjs +51 -0
- package/dist/esm/utils/auditDictionaryMetadata/index.mjs.map +1 -0
- package/dist/esm/utils/auditTag/PROMPT.md +34 -0
- package/dist/esm/utils/auditTag/index.mjs +47 -0
- package/dist/esm/utils/auditTag/index.mjs.map +1 -0
- package/dist/esm/utils/ensureArrayQueryFilter.mjs +15 -0
- package/dist/esm/utils/ensureArrayQueryFilter.mjs.map +1 -0
- package/dist/esm/utils/ensureMongoDocumentToObject.mjs +11 -0
- package/dist/esm/utils/ensureMongoDocumentToObject.mjs.map +1 -0
- package/dist/esm/utils/errors/errorCodes.mjs +91 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +10 -11
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +6 -10
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +6 -10
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs +29 -0
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +2 -9
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/mapper/dictionary.mjs +8 -4
- package/dist/esm/utils/mapper/dictionary.mjs.map +1 -1
- package/dist/esm/utils/mapper/organization.mjs +2 -4
- package/dist/esm/utils/mapper/organization.mjs.map +1 -1
- package/dist/esm/utils/mapper/project.mjs +2 -4
- package/dist/esm/utils/mapper/project.mjs.map +1 -1
- package/dist/esm/utils/mapper/tag.mjs +12 -0
- package/dist/esm/utils/mapper/tag.mjs.map +1 -0
- package/dist/esm/utils/mapper/user.mjs +2 -4
- package/dist/esm/utils/mapper/user.mjs.map +1 -1
- package/dist/esm/utils/removeObjectKeys.mjs +11 -0
- package/dist/esm/utils/removeObjectKeys.mjs.map +1 -0
- package/dist/esm/utils/validation/validateProject.mjs +17 -10
- package/dist/esm/utils/validation/validateProject.mjs.map +1 -1
- package/dist/esm/utils/validation/validateTag.mjs +65 -0
- package/dist/esm/utils/validation/validateTag.mjs.map +1 -0
- package/dist/types/controllers/ai.controller.d.ts +51 -4
- package/dist/types/controllers/ai.controller.d.ts.map +1 -1
- package/dist/types/controllers/dictionary.controller.d.ts +6 -3
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/project.controller.d.ts +2 -4
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/controllers/tag.controller.d.ts +39 -0
- package/dist/types/controllers/tag.controller.d.ts.map +1 -0
- package/dist/types/controllers/user.controller.d.ts.map +1 -1
- package/dist/types/export.d.ts +2 -0
- package/dist/types/export.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/models/dictionary.model.d.ts +1 -0
- package/dist/types/models/dictionary.model.d.ts.map +1 -1
- package/dist/types/models/tag.model.d.ts +3 -0
- package/dist/types/models/tag.model.d.ts.map +1 -0
- package/dist/types/routes/ai.routes.d.ts +21 -1
- package/dist/types/routes/ai.routes.d.ts.map +1 -1
- package/dist/types/routes/dictionary.routes.d.ts +6 -2
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
- package/dist/types/routes/tags.routes.d.ts +29 -0
- package/dist/types/routes/tags.routes.d.ts.map +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
- package/dist/types/schemas/project.schema.d.ts.map +1 -1
- package/dist/types/schemas/tag.schema.d.ts +16 -0
- package/dist/types/schemas/tag.schema.d.ts.map +1 -0
- package/dist/types/services/dictionary.service.d.ts +10 -2
- package/dist/types/services/dictionary.service.d.ts.map +1 -1
- package/dist/types/services/project.service.d.ts.map +1 -1
- package/dist/types/services/tag.service.d.ts +45 -0
- package/dist/types/services/tag.service.d.ts.map +1 -0
- package/dist/types/types/dictionary.types.d.ts +14 -4
- package/dist/types/types/dictionary.types.d.ts.map +1 -1
- package/dist/types/types/tag.types.d.ts +26 -0
- package/dist/types/types/tag.types.d.ts.map +1 -0
- package/dist/types/utils/AI/askDocQuestion.d.ts +38 -0
- package/dist/types/utils/AI/askDocQuestion.d.ts.map +1 -0
- package/dist/types/utils/auditDictionary/index.d.ts +24 -0
- package/dist/types/utils/auditDictionary/index.d.ts.map +1 -0
- package/dist/types/utils/auditDictionaryField/index.d.ts +24 -0
- package/dist/types/utils/auditDictionaryField/index.d.ts.map +1 -0
- package/dist/types/utils/auditDictionaryMetadata/index.d.ts +21 -0
- package/dist/types/utils/auditDictionaryMetadata/index.d.ts.map +1 -0
- package/dist/types/utils/{audit → auditTag}/index.d.ts +5 -6
- package/dist/types/utils/auditTag/index.d.ts.map +1 -0
- package/dist/types/utils/ensureArrayQueryFilter.d.ts +2 -0
- package/dist/types/utils/ensureArrayQueryFilter.d.ts.map +1 -0
- package/dist/types/utils/ensureMongoDocumentToObject.d.ts +8 -0
- package/dist/types/utils/ensureMongoDocumentToObject.d.ts.map +1 -0
- package/dist/types/utils/errors/errorCodes.d.ts +91 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +2 -0
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +24 -0
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/mapper/dictionary.d.ts +1 -1
- package/dist/types/utils/mapper/dictionary.d.ts.map +1 -1
- package/dist/types/utils/mapper/organization.d.ts.map +1 -1
- package/dist/types/utils/mapper/project.d.ts.map +1 -1
- package/dist/types/utils/mapper/tag.d.ts +16 -0
- package/dist/types/utils/mapper/tag.d.ts.map +1 -0
- package/dist/types/utils/mapper/user.d.ts +2 -2
- package/dist/types/utils/mapper/user.d.ts.map +1 -1
- package/dist/types/utils/removeObjectKeys.d.ts +2 -0
- package/dist/types/utils/removeObjectKeys.d.ts.map +1 -0
- package/dist/types/utils/validation/validateProject.d.ts.map +1 -1
- package/dist/types/utils/validation/validateTag.d.ts +16 -0
- package/dist/types/utils/validation/validateTag.d.ts.map +1 -0
- package/package.json +11 -10
- package/dist/cjs/utils/audit/index.cjs.map +0 -1
- package/dist/esm/utils/audit/index.mjs.map +0 -1
- package/dist/types/utils/audit/index.d.ts.map +0 -1
- /package/dist/cjs/utils/{audit → auditDictionary}/CJS_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/JSON_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/JSX_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/MJS_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/TSX_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/TS_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/CJS_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/JSON_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/JSX_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/MJS_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/TSX_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/TS_FORMAT.md +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
You are an expert in internationalization and content management. Your task is to audit the content declaration files in the project and identify any potential issues or inconsistencies. Provide a detailed report of any issues found, including the file path, line number, and a brief explanation of the issue.
|
|
1
|
+
You are an expert in internationalization, copy writing and content management. Your task is to audit the content declaration files in the project and identify any potential issues or inconsistencies. Provide a detailed report of any issues found, including the file path, line number, and a brief explanation of the issue.
|
|
2
2
|
|
|
3
3
|
**Instructions:**
|
|
4
4
|
|
|
@@ -33,6 +33,7 @@ You are an expert in internationalization and content management. Your task is t
|
|
|
33
33
|
- **Manage Localizations:** If the required languages contains similar languages, as `en` and `en-GB`, consider `en` as English US and `en-GB` as English UK, and insert or review both translations to maintain clarity and correctness.
|
|
34
34
|
- **Order Translations:** If the translations are not in the same order as the required languages list, consider reordering the translations to maintain clarity and correctness.
|
|
35
35
|
- **Escape Special Characters:** If the translations contain special characters, escape them using the appropriate escape sequence.
|
|
36
|
+
- **Respect the tags instructions:** If the tags instructions are provided, ensure that the audited file adheres to them.
|
|
36
37
|
|
|
37
38
|
6. **Example Scenario:**
|
|
38
39
|
|
|
@@ -137,6 +138,10 @@ You are an expert in internationalization and content management. Your task is t
|
|
|
137
138
|
- The import of the `t` function was imported from `react-intlayer` instead of `intlayer`.
|
|
138
139
|
- A type `DeclarationContent` was added to the file to strengthen the content declaration.
|
|
139
140
|
|
|
141
|
+
**Tags Instructions:**
|
|
142
|
+
|
|
143
|
+
{{tagsInstructions}}
|
|
144
|
+
|
|
140
145
|
**File to Audit:**
|
|
141
146
|
|
|
142
147
|
{{fileContent}}
|
|
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var auditDictionary_exports = {};
|
|
20
|
+
__export(auditDictionary_exports, {
|
|
21
|
+
auditDictionary: () => auditDictionary
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(auditDictionary_exports);
|
|
24
24
|
var import_fs = require("fs");
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_url = require("url");
|
|
@@ -48,14 +48,16 @@ const formatLocaleWithName = (locale) => {
|
|
|
48
48
|
const localeName = (0, import_core.getLocaleName)(locale);
|
|
49
49
|
return `${locale}: ${localeName}`;
|
|
50
50
|
};
|
|
51
|
-
const
|
|
51
|
+
const formatTagInstructions = (tags = []) => tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join("\n\n");
|
|
52
|
+
const auditDictionary = async ({
|
|
52
53
|
fileContent,
|
|
53
54
|
filePath,
|
|
54
55
|
model,
|
|
55
56
|
openAiApiKey,
|
|
56
57
|
customPrompt,
|
|
57
58
|
locales,
|
|
58
|
-
defaultLocale
|
|
59
|
+
defaultLocale,
|
|
60
|
+
tags
|
|
59
61
|
}) => {
|
|
60
62
|
try {
|
|
61
63
|
const openai = new import_openai.OpenAI({
|
|
@@ -72,7 +74,7 @@ const auditFile = async ({
|
|
|
72
74
|
).replace(
|
|
73
75
|
"{{declarationsContentTemplate}}",
|
|
74
76
|
FILE_TEMPLATE[fileExtension]
|
|
75
|
-
).replace("{{fileContent}}", fileContent);
|
|
77
|
+
).replace("{{fileContent}}", fileContent).replace("{{tagsInstructions}}", formatTagInstructions(tags));
|
|
76
78
|
const chatCompletion = await openai.chat.completions.create({
|
|
77
79
|
model: model ?? "gpt-4o-mini",
|
|
78
80
|
messages: [{ role: "system", content: prompt }]
|
|
@@ -91,6 +93,6 @@ const auditFile = async ({
|
|
|
91
93
|
};
|
|
92
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
93
95
|
0 && (module.exports = {
|
|
94
|
-
|
|
96
|
+
auditDictionary
|
|
95
97
|
});
|
|
96
98
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditDictionary/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { getLocaleName } from '@intlayer/core';\nimport { logger } from '@logger';\nimport { Locales } from 'intlayer';\nimport { OpenAI } from 'openai';\nimport { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AuditOptions = {\n locales: Locales[];\n defaultLocale: Locales;\n fileContent: string;\n filePath?: string;\n model?: string;\n openAiApiKey: string;\n customPrompt?: string;\n tags?: Tag[];\n};\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\nconst FILE_TEMPLATE: Record<string, string> = {\n ts: getFileContent('./TS_FORMAT.md'),\n tsx: getFileContent('./TSX_FORMAT.md'),\n js: getFileContent('./MJS_FORMAT.md'),\n mjs: getFileContent('./MJS_FORMAT.md'),\n cjs: getFileContent('./CJS_FORMAT.md'),\n jsx: getFileContent('./JSX_FORMAT.md'),\n json: getFileContent('./JSON_FORMAT.md'),\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Formats a locale with its full name and returns a string representation.\n *\n * @function\n * @param locale - A locale from the project's configuration (e.g., 'en-US', 'fr-FR').\n * @returns A formatted string combining the locale's name and code. Example: \"English (US): en-US\".\n */\nconst formatLocaleWithName = (locale: Locales): string => {\n // getLocaleName returns a human-readable name for the locale.\n const localeName = getLocaleName(locale);\n\n // Concatenate both the readable name and the locale code.\n return `${locale}: ${localeName}`;\n};\n\n/**\n * Formats an array of tags with their keys and instructions.\n *\n * @function\n * @param tags - An array of tags from the project's configuration.\n * @returns A string representation of the tags, with their keys and instructions.\n */\nconst formatTagInstructions = (tags: Tag[] = []) =>\n tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join('\\n\\n');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n */\nexport const auditDictionary = async ({\n fileContent,\n filePath,\n model,\n openAiApiKey,\n customPrompt,\n locales,\n defaultLocale,\n tags,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey,\n });\n\n // Read the file's content.\n const splitted = (filePath ?? '.json').split('.');\n const fileExtension = splitted[splitted.length - 1];\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace('{{filePath}}', filePath ?? 'Not provided')\n .replace(\n '{{defaultLocale}}',\n `{${formatLocaleWithName(defaultLocale)}}`\n )\n .replace(\n '{{otherLocales}}',\n `{${locales.map(formatLocaleWithName).join(', ')}}`\n )\n .replace(\n '{{declarationsContentTemplate}}',\n FILE_TEMPLATE[fileExtension]\n )\n .replace('{{fileContent}}', fileContent)\n .replace('{{tagsInstructions}}', formatTagInstructions(tags));\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: model ?? 'gpt-4o-mini',\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA6B;AAC7B,kBAA8B;AAC9B,iBAA8B;AAC9B,kBAA8B;AAC9B,oBAAuB;AAEvB,oBAAuB;AANvB;AASA,MAAM,gBAAY,yBAAQ,0BAAc,YAAY,GAAG,CAAC;AAqBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,mBAAe,kBAAK,WAAW,gBAAgB;AACrD,QAAM,kBAAc,wBAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAEA,MAAM,gBAAwC;AAAA,EAC5C,IAAI,eAAe,gBAAgB;AAAA,EACnC,KAAK,eAAe,iBAAiB;AAAA,EACrC,IAAI,eAAe,iBAAiB;AAAA,EACpC,KAAK,eAAe,iBAAiB;AAAA,EACrC,KAAK,eAAe,iBAAiB;AAAA,EACrC,KAAK,eAAe,iBAAiB;AAAA,EACrC,MAAM,eAAe,kBAAkB;AACzC;AAGA,MAAM,kBAAkB,eAAe,aAAa;AASpD,MAAM,uBAAuB,CAAC,WAA4B;AAExD,QAAM,iBAAa,2BAAc,MAAM;AAGvC,SAAO,GAAG,MAAM,KAAK,UAAU;AACjC;AASA,MAAM,wBAAwB,CAAC,OAAc,CAAC,MAC5C,KAAK,IAAI,CAAC,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,YAAY,EAAE,EAAE,KAAK,MAAM;AAQ7D,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA8D;AAC5D,MAAI;AAIF,UAAM,SAAS,IAAI,qBAAO;AAAA,MACxB,QAAQ;AAAA,IACV,CAAC;AAGD,UAAM,YAAY,YAAY,SAAS,MAAM,GAAG;AAChD,UAAM,gBAAgB,SAAS,SAAS,SAAS,CAAC;AAGlD,UAAM,SACJ,gBACA,gBAAgB,QAAQ,gBAAgB,YAAY,cAAc,EAC/D;AAAA,MACC;AAAA,MACA,IAAI,qBAAqB,aAAa,CAAC;AAAA,IACzC,EACC;AAAA,MACC;AAAA,MACA,IAAI,QAAQ,IAAI,oBAAoB,EAAE,KAAK,IAAI,CAAC;AAAA,IAClD,EACC;AAAA,MACC;AAAA,MACA,cAAc,aAAa;AAAA,IAC7B,EACC,QAAQ,mBAAmB,WAAW,EACtC,QAAQ,wBAAwB,sBAAsB,IAAI,CAAC;AAGhE,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,SAAS;AAAA,MAChB,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,yBAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
You are an expert in internationalization, copy writing and content management. Your task is to audit the given element into the content declaration file. If the element is not declared, review it. If this element is missing, write it by considering the given context of the content declaration, and by following instructions.
|
|
2
|
+
|
|
3
|
+
**Instructions:**
|
|
4
|
+
|
|
5
|
+
1. **Terminology:**
|
|
6
|
+
|
|
7
|
+
- **Content Declaration:** A content declaration is a is a file (.ts, .js or .json) that contains the multilingual declaration related to a specific content. A content declaration file is usually related to a specific component, or page or section of a website.
|
|
8
|
+
- **Tag:** A tag is attached to a content declaration and is used to group content declaration and harmonize them.
|
|
9
|
+
- **KeyPath** The KeyPath correspond to to the path to retrieve the targeted element from the `content` key of the content declaration file.
|
|
10
|
+
|
|
11
|
+
2. **Locales:**
|
|
12
|
+
|
|
13
|
+
- Required Locales: {{otherLocales}}
|
|
14
|
+
|
|
15
|
+
3. **Audit Requirements:**
|
|
16
|
+
|
|
17
|
+
- **Consistency:** Ensure that all keys have translations for all specified locales.
|
|
18
|
+
- **Missing Content:** Identify any missing translations and specify the expected content.
|
|
19
|
+
- **Misplaced Content:** Detect if any translations are placed under incorrect keys.
|
|
20
|
+
- **Type Compliance:** Verify that the content types match the declarations (e.g., strings, string arrays).
|
|
21
|
+
|
|
22
|
+
4. **Modification Guidelines:**
|
|
23
|
+
|
|
24
|
+
- **Return Only the Targeted Content:** Provide the updated targeted content as plain text without any markdown, additional comments or explanations.
|
|
25
|
+
- **Consider the locale context:** If the targeted field correspond to a specific language, contains similar languages, as `zh` or `en-GB`, consider return the content in this specified language.
|
|
26
|
+
- **Escape Special Characters:** If the translations contain special characters, escape them using the appropriate escape sequence.
|
|
27
|
+
- **Respect the tags instructions:** If the tags instructions are provided, ensure that the audited file adheres to them.
|
|
28
|
+
|
|
29
|
+
5. **Example Scenario:**
|
|
30
|
+
|
|
31
|
+
- **Example 1:**
|
|
32
|
+
|
|
33
|
+
- **Input File:**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
key: "creative-work-structured-data",
|
|
40
|
+
content: {
|
|
41
|
+
audienceType: t({
|
|
42
|
+
en: "Developers, Content Managers",
|
|
43
|
+
fr: "Développeurs, Responsables de contenu",
|
|
44
|
+
es: "",
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
} satisfies DeclarationContent;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **Input keyPath:**
|
|
51
|
+
|
|
52
|
+
`[{type: "object", key: "audienceType"},{type: "translation", key: "es"}]`
|
|
53
|
+
|
|
54
|
+
- **Expected Output:**
|
|
55
|
+
|
|
56
|
+
Desarrolladores, Gestores de Contenido
|
|
57
|
+
|
|
58
|
+
- **Example 2:**
|
|
59
|
+
|
|
60
|
+
- **Input File:**
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { t, enu, type DeclarationContent } from "intlayer";
|
|
64
|
+
|
|
65
|
+
const content = {
|
|
66
|
+
key: "creative-work-structured-data",
|
|
67
|
+
content: {
|
|
68
|
+
en: {
|
|
69
|
+
audienceType: t({
|
|
70
|
+
en: "Developers, Content Managers",
|
|
71
|
+
fr: "Développeurs, Responsables de contenu",
|
|
72
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
audienceType: {
|
|
76
|
+
object1: enu({
|
|
77
|
+
"1": t({
|
|
78
|
+
en: "Developers, Content Managers",
|
|
79
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
80
|
+
fr: "Développeurs, Responsables de contenu",
|
|
81
|
+
}),
|
|
82
|
+
">2": t({
|
|
83
|
+
en: "Developers, Content Managers",
|
|
84
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
85
|
+
fr: "Here content thst make no sense and should be replaced",
|
|
86
|
+
}),
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
} satisfies DeclarationContent;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- **Input target:**
|
|
94
|
+
|
|
95
|
+
`[{type: "object", key: "audienceType"},{type: "enumeration", key: ">2"},{type: "object", key: "audienceType"},{type: "translation", key: "es"}]`
|
|
96
|
+
|
|
97
|
+
- **Expected Output:**
|
|
98
|
+
|
|
99
|
+
Développeurs, Responsables de contenu
|
|
100
|
+
|
|
101
|
+
**Tags Instructions:**
|
|
102
|
+
|
|
103
|
+
{{tagsInstructions}}
|
|
104
|
+
|
|
105
|
+
**File to Audit:**
|
|
106
|
+
|
|
107
|
+
{{fileContent}}
|
|
108
|
+
|
|
109
|
+
**KeyPath:**
|
|
110
|
+
|
|
111
|
+
{{keyPath}}
|
|
112
|
+
|
|
113
|
+
**Expected Response:**
|
|
114
|
+
|
|
115
|
+
After auditing, provide only the targeted content as plain text without any Markdown or code block formatting. If no changes are needed, return the targeted content
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var auditDictionaryField_exports = {};
|
|
20
|
+
__export(auditDictionaryField_exports, {
|
|
21
|
+
auditDictionaryField: () => auditDictionaryField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(auditDictionaryField_exports);
|
|
24
|
+
var import_fs = require("fs");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_url = require("url");
|
|
27
|
+
var import_core = require("@intlayer/core");
|
|
28
|
+
var import_logger = require('./../../logger/index.cjs');
|
|
29
|
+
var import_openai = require("openai");
|
|
30
|
+
const import_meta = {};
|
|
31
|
+
const __dirname = (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
32
|
+
const getFileContent = (relativeFilePath) => {
|
|
33
|
+
const absolutePath = (0, import_path.join)(__dirname, relativeFilePath);
|
|
34
|
+
const fileContent = (0, import_fs.readFileSync)(absolutePath, "utf-8");
|
|
35
|
+
return fileContent;
|
|
36
|
+
};
|
|
37
|
+
const CHAT_GPT_PROMPT = getFileContent("./PROMPT.md");
|
|
38
|
+
const formatLocaleWithName = (locale) => {
|
|
39
|
+
const localeName = (0, import_core.getLocaleName)(locale);
|
|
40
|
+
return `${locale}: ${localeName}`;
|
|
41
|
+
};
|
|
42
|
+
const formatTagInstructions = (tags = []) => tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join("\n\n");
|
|
43
|
+
const auditDictionaryField = async ({
|
|
44
|
+
fileContent,
|
|
45
|
+
model,
|
|
46
|
+
openAiApiKey,
|
|
47
|
+
customPrompt,
|
|
48
|
+
locales,
|
|
49
|
+
keyPath,
|
|
50
|
+
tags
|
|
51
|
+
}) => {
|
|
52
|
+
try {
|
|
53
|
+
const openai = new import_openai.OpenAI({
|
|
54
|
+
apiKey: openAiApiKey
|
|
55
|
+
});
|
|
56
|
+
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace(
|
|
57
|
+
"{{otherLocales}}",
|
|
58
|
+
`{${locales.map(formatLocaleWithName).join(", ")}}`
|
|
59
|
+
).replace("{{keyPath}}", JSON.stringify(keyPath)).replace("{{fileContent}}", fileContent).replace("{{tagsInstructions}}", formatTagInstructions(tags));
|
|
60
|
+
const chatCompletion = await openai.chat.completions.create({
|
|
61
|
+
model: model ?? "gpt-4o-mini",
|
|
62
|
+
messages: [{ role: "system", content: prompt }]
|
|
63
|
+
});
|
|
64
|
+
const newContent = chatCompletion.choices[0].message?.content;
|
|
65
|
+
import_logger.logger.info(
|
|
66
|
+
`${chatCompletion.usage?.total_tokens} tokens used in the request`
|
|
67
|
+
);
|
|
68
|
+
return {
|
|
69
|
+
fileContent: newContent ?? "",
|
|
70
|
+
tokenUsed: chatCompletion.usage?.total_tokens ?? 0
|
|
71
|
+
};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
auditDictionaryField
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditDictionaryField/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { getLocaleName, type KeyPath } from '@intlayer/core';\nimport { logger } from '@logger';\nimport { Locales } from 'intlayer';\nimport { OpenAI } from 'openai';\nimport { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AuditDictionaryFieldOptions = {\n locales: Locales[];\n fileContent: string;\n model?: string;\n openAiApiKey: string;\n customPrompt?: string;\n keyPath: KeyPath[];\n tags?: Tag[];\n};\nexport type AuditDictionaryFieldResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Formats a locale with its full name and returns a string representation.\n *\n * @function\n * @param locale - A locale from the project's configuration (e.g., 'en-US', 'fr-FR').\n * @returns A formatted string combining the locale's name and code. Example: \"English (US): en-US\".\n */\nconst formatLocaleWithName = (locale: Locales): string => {\n // getLocaleName returns a human-readable name for the locale.\n const localeName = getLocaleName(locale);\n\n // Concatenate both the readable name and the locale code.\n return `${locale}: ${localeName}`;\n};\n\n/**\n * Formats an array of tags with their keys and instructions.\n *\n * @function\n * @param tags - An array of tags from the project's configuration.\n * @returns A string representation of the tags, with their keys and instructions.\n */\nconst formatTagInstructions = (tags: Tag[] = []) =>\n tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join('\\n\\n');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n */\nexport const auditDictionaryField = async ({\n fileContent,\n model,\n openAiApiKey,\n customPrompt,\n locales,\n keyPath,\n tags,\n}: AuditDictionaryFieldOptions): Promise<\n AuditDictionaryFieldResultData | undefined\n> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace(\n '{{otherLocales}}',\n `{${locales.map(formatLocaleWithName).join(', ')}}`\n )\n .replace('{{keyPath}}', JSON.stringify(keyPath))\n .replace('{{fileContent}}', fileContent)\n .replace('{{tagsInstructions}}', formatTagInstructions(tags));\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: model ?? 'gpt-4o-mini',\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA6B;AAC7B,kBAA8B;AAC9B,iBAA8B;AAC9B,kBAA4C;AAC5C,oBAAuB;AAEvB,oBAAuB;AANvB;AASA,MAAM,gBAAY,yBAAQ,0BAAc,YAAY,GAAG,CAAC;AAuBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,mBAAe,kBAAK,WAAW,gBAAgB;AACrD,QAAM,kBAAc,wBAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AASpD,MAAM,uBAAuB,CAAC,WAA4B;AAExD,QAAM,iBAAa,2BAAc,MAAM;AAGvC,SAAO,GAAG,MAAM,KAAK,UAAU;AACjC;AASA,MAAM,wBAAwB,CAAC,OAAc,CAAC,MAC5C,KAAK,IAAI,CAAC,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,YAAY,EAAE,EAAE,KAAK,MAAM;AAQ7D,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAEK;AACH,MAAI;AAIF,UAAM,SAAS,IAAI,qBAAO;AAAA,MACxB,QAAQ;AAAA,IACV,CAAC;AAGD,UAAM,SACJ,gBACA,gBAAgB;AAAA,MACd;AAAA,MACA,IAAI,QAAQ,IAAI,oBAAoB,EAAE,KAAK,IAAI,CAAC;AAAA,IAClD,EACG,QAAQ,eAAe,KAAK,UAAU,OAAO,CAAC,EAC9C,QAAQ,mBAAmB,WAAW,EACtC,QAAQ,wBAAwB,sBAAsB,IAAI,CAAC;AAGhE,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,SAAS;AAAA,MAChB,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,yBAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Your role is to review content declaration fields. Correct this fields if they are misspelled or do not match the expected content, and / or complete missing content.
|
|
2
|
+
|
|
3
|
+
1. **Terminology:**
|
|
4
|
+
|
|
5
|
+
- **Content Declaration:** A content declaration is a is a file (.ts, .js or .json) that contains the multilingual declaration related to a specific content. A content declaration file is usually related to a specific component, or page or section of a website.
|
|
6
|
+
- **Tag:** A tag is attached to a content declaration and is used to group content declaration and harmonize them.
|
|
7
|
+
|
|
8
|
+
2. **Audit Requirements:**
|
|
9
|
+
|
|
10
|
+
- **Do Not Alter Structure:** If the file structure is correct, do not modify it. Only add, update, or remove content declarations as necessary.
|
|
11
|
+
- **Misspelled Content:** If declared, detect each `title`, `description` and `tags` are not misspelled. If some content is misspelled, correct it.
|
|
12
|
+
|
|
13
|
+
3. **Fields functions:**
|
|
14
|
+
|
|
15
|
+
- **Title:** The title of the content declaration allows to easily identify it. It should be considered as a readable way to represent the `key` (example: `page-metadata` -> `Page metadata`). It should be a short and descriptive title that accurately reflects the dictionary.
|
|
16
|
+
- **Description:** The description of the content declaration provides a brief summary of the content declaration. It should be a concise and informative description that explains the purpose and content of the dictionary.
|
|
17
|
+
- **Tags:** The tags is an array of strings that represent the key of the tags associated with the content declaration.
|
|
18
|
+
|
|
19
|
+
**Expected Response:**
|
|
20
|
+
|
|
21
|
+
After completion, provide only the final title, description and tags fields in a JSON without any Markdown, code block formatting or any additional comments or explanations.
|
|
22
|
+
|
|
23
|
+
**Example of expected response:**
|
|
24
|
+
|
|
25
|
+
- Entry:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
29
|
+
import { Metadata } from "next";
|
|
30
|
+
|
|
31
|
+
const metadataContent = {
|
|
32
|
+
key: "pricing-metadata",
|
|
33
|
+
title: "",
|
|
34
|
+
description:
|
|
35
|
+
"here a description that doesn't make any sense and should be replaced",
|
|
36
|
+
content: {
|
|
37
|
+
title: t({
|
|
38
|
+
en: "Pricing | Intlayer",
|
|
39
|
+
fr: "Tarification | Intlayer",
|
|
40
|
+
es: "Precios | Intlayer",
|
|
41
|
+
}),
|
|
42
|
+
description: t({
|
|
43
|
+
en: "Discover our pricing plans and get access to premium features with Intlayer. Choose the plan that suits you best.",
|
|
44
|
+
fr: "Découvrez nos plans tarifaires et accédez aux fonctionnalités premium avec Intlayer. Choisissez le plan qui vous convient le mieux.",
|
|
45
|
+
es: "Descubre nuestros planes de precios y accede a funciones premium con Intlayer. Elige el plan que mejor te convenga.",
|
|
46
|
+
}),
|
|
47
|
+
keywords: t<string[]>({
|
|
48
|
+
en: ["Pricing", "Subscription"],
|
|
49
|
+
fr: ["Tarification", "Abonnement"],
|
|
50
|
+
es: ["Precios", "Suscripción"],
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
} satisfies DeclarationContent<Metadata>;
|
|
54
|
+
|
|
55
|
+
export default metadataContent;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Response:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"title": "Pricing page metadata",
|
|
63
|
+
"description": "Metadata related to the pricing page, includes title, description, keywords, metadata for SEO purpose. It will help search engines understand the content of the page.",
|
|
64
|
+
"tags": ["page metadata", "pricing page"]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**List of existing Tags:**
|
|
69
|
+
|
|
70
|
+
Here the list of existing tags as a context to help you to pick related ones.
|
|
71
|
+
|
|
72
|
+
{{tags}}
|
|
73
|
+
|
|
74
|
+
**Content Declaration to complete:**
|
|
75
|
+
|
|
76
|
+
{{contentDeclaration}}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var auditDictionaryMetadata_exports = {};
|
|
20
|
+
__export(auditDictionaryMetadata_exports, {
|
|
21
|
+
auditDictionaryMetadata: () => auditDictionaryMetadata
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(auditDictionaryMetadata_exports);
|
|
24
|
+
var import_fs = require("fs");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_url = require("url");
|
|
27
|
+
var import_logger = require('./../../logger/index.cjs');
|
|
28
|
+
var import_openai = require("openai");
|
|
29
|
+
const import_meta = {};
|
|
30
|
+
const __dirname = (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
31
|
+
const getFileContent = (relativeFilePath) => {
|
|
32
|
+
const absolutePath = (0, import_path.join)(__dirname, relativeFilePath);
|
|
33
|
+
const fileContent = (0, import_fs.readFileSync)(absolutePath, "utf-8");
|
|
34
|
+
return fileContent;
|
|
35
|
+
};
|
|
36
|
+
const CHAT_GPT_PROMPT = getFileContent("./PROMPT.md");
|
|
37
|
+
const auditDictionaryMetadata = async ({
|
|
38
|
+
model,
|
|
39
|
+
openAiApiKey,
|
|
40
|
+
customPrompt,
|
|
41
|
+
tags,
|
|
42
|
+
fileContent
|
|
43
|
+
}) => {
|
|
44
|
+
try {
|
|
45
|
+
const openai = new import_openai.OpenAI({
|
|
46
|
+
apiKey: openAiApiKey
|
|
47
|
+
});
|
|
48
|
+
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace(
|
|
49
|
+
"{{tags}}",
|
|
50
|
+
`${JSON.stringify(
|
|
51
|
+
tags.map(({ key, description }) => `- ${key}: ${description}`).join("\n\n"),
|
|
52
|
+
null,
|
|
53
|
+
2
|
|
54
|
+
)}`
|
|
55
|
+
).replace("{{contentDeclaration}}", fileContent);
|
|
56
|
+
const chatCompletion = await openai.chat.completions.create({
|
|
57
|
+
model: model ?? "gpt-4o-mini",
|
|
58
|
+
messages: [{ role: "system", content: prompt }]
|
|
59
|
+
});
|
|
60
|
+
const newContent = chatCompletion.choices[0].message?.content;
|
|
61
|
+
import_logger.logger.info(
|
|
62
|
+
`${chatCompletion.usage?.total_tokens} tokens used in the request`
|
|
63
|
+
);
|
|
64
|
+
return {
|
|
65
|
+
fileContent: newContent ?? "",
|
|
66
|
+
tokenUsed: chatCompletion.usage?.total_tokens ?? 0
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error(error);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
auditDictionaryMetadata
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditDictionaryMetadata/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { logger } from '@logger';\nimport { OpenAI } from 'openai';\nimport { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AuditOptions = {\n tags: Tag[];\n fileContent: string;\n model?: string;\n openAiApiKey: string;\n customPrompt?: string;\n};\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n */\nexport const auditDictionaryMetadata = async ({\n model,\n openAiApiKey,\n customPrompt,\n tags,\n fileContent,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace(\n '{{tags}}',\n `${JSON.stringify(\n tags\n .map(({ key, description }) => `- ${key}: ${description}`)\n .join('\\n\\n'),\n null,\n 2\n )}`\n ).replace('{{contentDeclaration}}', fileContent);\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: model ?? 'gpt-4o-mini',\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA6B;AAC7B,kBAA8B;AAC9B,iBAA8B;AAC9B,oBAAuB;AACvB,oBAAuB;AAJvB;AAOA,MAAM,gBAAY,yBAAQ,0BAAc,YAAY,GAAG,CAAC;AAkBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,mBAAe,kBAAK,WAAW,gBAAgB;AACrD,QAAM,kBAAc,wBAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AAS7C,MAAM,0BAA0B,OAAO;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA8D;AAC5D,MAAI;AAIF,UAAM,SAAS,IAAI,qBAAO;AAAA,MACxB,QAAQ;AAAA,IACV,CAAC;AAGD,UAAM,SACJ,gBACA,gBAAgB;AAAA,MACd;AAAA,MACA,GAAG,KAAK;AAAA,QACN,KACG,IAAI,CAAC,EAAE,KAAK,YAAY,MAAM,KAAK,GAAG,KAAK,WAAW,EAAE,EACxD,KAAK,MAAM;AAAA,QACd;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,EAAE,QAAQ,0BAA0B,WAAW;AAGjD,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,SAAS;AAAA,MAChB,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,yBAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Your role is to review a tag. A tag is attached to a content declaration and is used to group content declarations and harmonize them.
|
|
2
|
+
|
|
3
|
+
- Here an example of a tag of a random project:
|
|
4
|
+
|
|
5
|
+
````json
|
|
6
|
+
{
|
|
7
|
+
"key": "page-metadata",
|
|
8
|
+
"name": "Page metadata",
|
|
9
|
+
"description": "Contain all metadata related to the page, such as title, description, keywords, etc for SEO purpose. It will help search engines understand the content of the page.",
|
|
10
|
+
"instructions": "## Metadata Tag//## Content Declaration structure//A content declaration containing this tag should a least includes the following fields://- title/- description/- keywords//### Example of structure//```json/{/ \"key\": \"...\",/ \"content\": {/ \"title\": \"...\",/ \"description\": \"...\",/ \"keywords\": [\"...\", \"...\", \"...\"]/ }/}/```//## Fields instructions//### 1. **Title Tag**//#### **Purpose**//The title tag defines the title of your webpage. It's displayed on search engine results pages (SERPs) as the clickable headline and is essential for both SEO and user experience.//#### **Best Practices**//- **Length:** Aim for **50-60 characters**. Search engines typically display the first 50-60 characters of a title tag. Titles longer than this may be truncated./- **Keywords:** Include primary keywords relevant to the page content, preferably toward the beginning./- **Clarity and Relevance:** Ensure the title accurately reflects the content of the page./- **Branding:** If appropriate, include your brand name at the end of the title (e.g., \"How to Bake a Cake | YourBrand\")./- **Uniqueness:** Each page on your website should have a unique title to avoid confusion and duplication issues.//### 2. **Meta Description**//#### **Purpose**//The meta description provides a brief summary of the webpage's content. While not a direct ranking factor, a compelling meta description can improve click-through rates (CTR) from SERPs.//#### **Best Practices**//- **Length:** Keep it between **150-160 characters**. Descriptions longer than this may be cut off in search results./- **Engaging and Inviting:** Write a clear, concise, and enticing summary that encourages users to click./- **Include Keywords:** Incorporate relevant keywords naturally, as they may be bolded in SERPs when they match the search query./- **Call to Action (CTA):** Use action-oriented language (e.g., \"Learn more,\" \"Discover,\" \"Get started\")./- **Unique Descriptions:** Ensure each page has a unique meta description to differentiate it from others.//### 3. **Meta Keywords**//#### **Purpose**//Historically used to list important keywords for a webpage. However, most modern search engines no longer use meta keywords for ranking.//#### **Best Practices**//- **Page Related Keywords:** The provided keywords should be relevant to the content of the page./- **Uniqueness:** Each page on your website should have a unique set of keywords to avoid confusion and duplication issues./- **Keyword number:** The number of keywords should be between 3-10."
|
|
11
|
+
}
|
|
12
|
+
````
|
|
13
|
+
|
|
14
|
+
1. **Audit Requirements:**
|
|
15
|
+
|
|
16
|
+
- **Misplaced Content:** Detect each `title`, `description` and `instructions` are defined correct. If not, provide the expected content.
|
|
17
|
+
- **Ensure Conherence with dictionary:** Ensure that the key instruction make sense with the content declaration to which the given tag is attached. If the instructions doesn't looks appropriate, suggest a new one.
|
|
18
|
+
|
|
19
|
+
2. **Modification Guidelines:**
|
|
20
|
+
|
|
21
|
+
- **Do Not Alter Structure:** If the file structure is correct, do not modify it. Only add, update, or remove content declarations as necessary.
|
|
22
|
+
- **Return Only Final File Content:** Provide the updated file content without any additional comments or explanations.
|
|
23
|
+
|
|
24
|
+
**Tags to Audit:**
|
|
25
|
+
|
|
26
|
+
{{tag}}
|
|
27
|
+
|
|
28
|
+
**Content Declaration that attach the tag into:**
|
|
29
|
+
|
|
30
|
+
{{contentDeclarations}}
|
|
31
|
+
|
|
32
|
+
**Expected Response:**
|
|
33
|
+
|
|
34
|
+
After auditing, provide only the final content of the file as plain text without any Markdown or code block formatting. If no changes are needed, return the file content exactly as it is.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var auditTag_exports = {};
|
|
20
|
+
__export(auditTag_exports, {
|
|
21
|
+
auditTag: () => auditTag
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(auditTag_exports);
|
|
24
|
+
var import_fs = require("fs");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_url = require("url");
|
|
27
|
+
var import_logger = require('./../../logger/index.cjs');
|
|
28
|
+
var import_openai = require("openai");
|
|
29
|
+
const import_meta = {};
|
|
30
|
+
const __dirname = (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
31
|
+
const getFileContent = (relativeFilePath) => {
|
|
32
|
+
const absolutePath = (0, import_path.join)(__dirname, relativeFilePath);
|
|
33
|
+
const fileContent = (0, import_fs.readFileSync)(absolutePath, "utf-8");
|
|
34
|
+
return fileContent;
|
|
35
|
+
};
|
|
36
|
+
const CHAT_GPT_PROMPT = getFileContent("./PROMPT.md");
|
|
37
|
+
const auditTag = async ({
|
|
38
|
+
model,
|
|
39
|
+
openAiApiKey,
|
|
40
|
+
customPrompt,
|
|
41
|
+
tag,
|
|
42
|
+
dictionaries
|
|
43
|
+
}) => {
|
|
44
|
+
try {
|
|
45
|
+
const openai = new import_openai.OpenAI({
|
|
46
|
+
apiKey: openAiApiKey
|
|
47
|
+
});
|
|
48
|
+
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace("{{tag}}", `${JSON.stringify(tag)}`).replace(
|
|
49
|
+
"{{contentDeclarations}}",
|
|
50
|
+
dictionaries.map((dictionary) => `- ${JSON.stringify(dictionary)}`).join("\n\n")
|
|
51
|
+
);
|
|
52
|
+
const chatCompletion = await openai.chat.completions.create({
|
|
53
|
+
model: model ?? "gpt-4o-mini",
|
|
54
|
+
messages: [{ role: "system", content: prompt }]
|
|
55
|
+
});
|
|
56
|
+
const newContent = chatCompletion.choices[0].message?.content;
|
|
57
|
+
import_logger.logger.info(
|
|
58
|
+
`${chatCompletion.usage?.total_tokens} tokens used in the request`
|
|
59
|
+
);
|
|
60
|
+
return {
|
|
61
|
+
fileContent: newContent ?? "",
|
|
62
|
+
tokenUsed: chatCompletion.usage?.total_tokens ?? 0
|
|
63
|
+
};
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(error);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
auditTag
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditTag/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { logger } from '@logger';\nimport { OpenAI } from 'openai';\nimport { Dictionary } from '@/types/dictionary.types';\nimport { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AuditOptions = {\n tag: Tag;\n dictionaries: Dictionary[];\n model?: string;\n openAiApiKey: string;\n customPrompt?: string;\n};\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditTag = async ({\n model,\n openAiApiKey,\n customPrompt,\n tag,\n dictionaries,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace('{{tag}}', `${JSON.stringify(tag)}`).replace(\n '{{contentDeclarations}}',\n dictionaries\n .map((dictionary) => `- ${JSON.stringify(dictionary)}`)\n .join('\\n\\n')\n );\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: model ?? 'gpt-4o-mini',\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA6B;AAC7B,kBAA8B;AAC9B,iBAA8B;AAC9B,oBAAuB;AACvB,oBAAuB;AAJvB;AAQA,MAAM,gBAAY,yBAAQ,0BAAc,YAAY,GAAG,CAAC;AAkBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,mBAAe,kBAAK,WAAW,gBAAgB;AACrD,QAAM,kBAAc,wBAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AAc7C,MAAM,WAAW,OAAO;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA8D;AAC5D,MAAI;AAIF,UAAM,SAAS,IAAI,qBAAO;AAAA,MACxB,QAAQ;AAAA,IACV,CAAC;AAGD,UAAM,SACJ,gBACA,gBAAgB,QAAQ,WAAW,GAAG,KAAK,UAAU,GAAG,CAAC,EAAE,EAAE;AAAA,MAC3D;AAAA,MACA,aACG,IAAI,CAAC,eAAe,KAAK,KAAK,UAAU,UAAU,CAAC,EAAE,EACrD,KAAK,MAAM;AAAA,IAChB;AAGF,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,SAAS;AAAA,MAChB,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,yBAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var ensureArrayQueryFilter_exports = {};
|
|
20
|
+
__export(ensureArrayQueryFilter_exports, {
|
|
21
|
+
ensureArrayQueryFilter: () => ensureArrayQueryFilter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ensureArrayQueryFilter_exports);
|
|
24
|
+
const ensureArrayQueryFilter = (filter) => {
|
|
25
|
+
let idsArray;
|
|
26
|
+
if (typeof filter === "string") {
|
|
27
|
+
idsArray = filter.split(",");
|
|
28
|
+
} else if (Array.isArray(filter)) {
|
|
29
|
+
idsArray = filter;
|
|
30
|
+
} else {
|
|
31
|
+
idsArray = [];
|
|
32
|
+
}
|
|
33
|
+
return idsArray;
|
|
34
|
+
};
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
ensureArrayQueryFilter
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=ensureArrayQueryFilter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/ensureArrayQueryFilter.ts"],"sourcesContent":["export const ensureArrayQueryFilter = (\n filter: string | string[] | undefined\n): string[] | undefined => {\n let idsArray: string[];\n\n if (typeof filter === 'string') {\n idsArray = filter.split(',');\n } else if (Array.isArray(filter)) {\n idsArray = filter;\n } else {\n idsArray = [];\n }\n\n return idsArray;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,yBAAyB,CACpC,WACyB;AACzB,MAAI;AAEJ,MAAI,OAAO,WAAW,UAAU;AAC9B,eAAW,OAAO,MAAM,GAAG;AAAA,EAC7B,WAAW,MAAM,QAAQ,MAAM,GAAG;AAChC,eAAW;AAAA,EACb,OAAO;AACL,eAAW,CAAC;AAAA,EACd;AAEA,SAAO;AACT;","names":[]}
|