payload-ai 1.0.0 → 1.0.1
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/components/Translator/Translator.scss +19 -0
- package/dist/components/Translator/index.d.ts +12 -1
- package/dist/components/Translator/index.js +65 -37
- package/dist/components/Translator/index.js.map +1 -1
- package/dist/plugin.js +50 -31
- package/dist/plugin.js.map +1 -1
- package/dist/translateTextAndObjects.js +18 -2
- package/dist/translateTextAndObjects.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Translator/Translator.scss +19 -0
- package/src/components/Translator/index.tsx +110 -61
- package/src/plugin.ts +64 -45
- package/src/translateTextAndObjects.ts +29 -7
|
@@ -53,6 +53,25 @@
|
|
|
53
53
|
font-weight: 600;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
&__radio-group {
|
|
57
|
+
display: grid;
|
|
58
|
+
gap: calc(var(--base) * 0.25);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&__radio-option {
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: calc(var(--base) * 0.35);
|
|
65
|
+
font-size: 0.9rem;
|
|
66
|
+
color: var(--theme-elevation-900);
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
|
|
69
|
+
input[type='radio'] {
|
|
70
|
+
margin: 0;
|
|
71
|
+
accent-color: var(--theme-success-500);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
56
75
|
&__translation-buttons {
|
|
57
76
|
display: flex;
|
|
58
77
|
flex-wrap: wrap;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import './Translator.scss';
|
|
3
|
-
|
|
3
|
+
type LocaleShape = {
|
|
4
|
+
code: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
};
|
|
7
|
+
type TranslatorProps = {
|
|
8
|
+
localization?: {
|
|
9
|
+
defaultLocale?: string;
|
|
10
|
+
locales?: Array<string | LocaleShape>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const Translator: React.FC<TranslatorProps>;
|
|
14
|
+
export {};
|
|
@@ -64,22 +64,50 @@ exports.Translator = void 0;
|
|
|
64
64
|
var react_1 = __importStar(require("react"));
|
|
65
65
|
var ui_1 = require("@payloadcms/ui");
|
|
66
66
|
require("./Translator.scss");
|
|
67
|
-
var Translator = function () {
|
|
68
|
-
var
|
|
67
|
+
var Translator = function (_a) {
|
|
68
|
+
var _b, _c, _d, _e;
|
|
69
|
+
var localization = _a.localization;
|
|
69
70
|
var baseClass = 'ai-translator';
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
var _f = react_1.default.useState(false), isOpen = _f[0], setIsOpen = _f[1];
|
|
72
|
+
var _g = react_1.default.useState(false), isLoading = _g[0], setIsLoading = _g[1];
|
|
73
|
+
var _h = react_1.default.useState('default'), selectedModel = _h[0], setSelectedModel = _h[1];
|
|
74
|
+
var activeLocaleFromURL = react_1.default.useMemo(function () {
|
|
75
|
+
if (typeof window === 'undefined')
|
|
76
|
+
return undefined;
|
|
77
|
+
var url = new URL(window.location.href);
|
|
78
|
+
return url.searchParams.get('locale') || undefined;
|
|
79
|
+
}, []);
|
|
80
|
+
var defaultLocaleCode = (localization === null || localization === void 0 ? void 0 : localization.defaultLocale) || 'en';
|
|
81
|
+
var locales = react_1.default.useMemo(function () {
|
|
82
|
+
var localizationLocales = localization === null || localization === void 0 ? void 0 : localization.locales;
|
|
83
|
+
if (!Array.isArray(localizationLocales)) {
|
|
84
|
+
return [{ code: defaultLocaleCode, label: defaultLocaleCode }];
|
|
85
|
+
}
|
|
86
|
+
var normalizedLocales = [];
|
|
87
|
+
localizationLocales.forEach(function (localeEntry) {
|
|
88
|
+
if (typeof localeEntry === 'string') {
|
|
89
|
+
normalizedLocales.push({
|
|
90
|
+
code: localeEntry,
|
|
91
|
+
label: localeEntry,
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (localeEntry && typeof localeEntry === 'object' && localeEntry.code) {
|
|
96
|
+
normalizedLocales.push({
|
|
97
|
+
code: localeEntry.code,
|
|
98
|
+
label: localeEntry.label || localeEntry.code,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return normalizedLocales.length
|
|
103
|
+
? normalizedLocales
|
|
104
|
+
: [{ code: defaultLocaleCode, label: defaultLocaleCode }];
|
|
105
|
+
}, [defaultLocaleCode, localization === null || localization === void 0 ? void 0 : localization.locales]);
|
|
106
|
+
var activeLocaleCode = activeLocaleFromURL && locales.some(function (locale) { return locale.code === activeLocaleFromURL; })
|
|
107
|
+
? activeLocaleFromURL
|
|
108
|
+
: defaultLocaleCode;
|
|
109
|
+
var fallbackLocaleLabel = ((_b = locales.find(function (locale) { return locale.code === activeLocaleCode; })) === null || _b === void 0 ? void 0 : _b.label) || activeLocaleCode;
|
|
110
|
+
var _j = react_1.default.useState(activeLocaleCode), selectedSourceLocale = _j[0], setSelectedSourceLocal = _j[1];
|
|
83
111
|
var documentInfo = (0, ui_1.useDocumentInfo)();
|
|
84
112
|
var routeMatch = typeof window !== 'undefined'
|
|
85
113
|
? window.location.pathname.match(/\/admin\/collections\/([^/]+)\/([^/?#]+)/)
|
|
@@ -87,10 +115,10 @@ var Translator = function () {
|
|
|
87
115
|
var routeCollectionSlug = routeMatch === null || routeMatch === void 0 ? void 0 : routeMatch[1];
|
|
88
116
|
var routeDocumentId = routeMatch === null || routeMatch === void 0 ? void 0 : routeMatch[2];
|
|
89
117
|
var collectionSlug = (documentInfo === null || documentInfo === void 0 ? void 0 : documentInfo.collectionSlug) ||
|
|
90
|
-
((
|
|
91
|
-
((
|
|
118
|
+
((_c = documentInfo === null || documentInfo === void 0 ? void 0 : documentInfo.docConfig) === null || _c === void 0 ? void 0 : _c.slug) ||
|
|
119
|
+
((_d = documentInfo === null || documentInfo === void 0 ? void 0 : documentInfo.collection) === null || _d === void 0 ? void 0 : _d.slug) ||
|
|
92
120
|
routeCollectionSlug;
|
|
93
|
-
var documentId = (documentInfo === null || documentInfo === void 0 ? void 0 : documentInfo.id) || ((
|
|
121
|
+
var documentId = (documentInfo === null || documentInfo === void 0 ? void 0 : documentInfo.id) || ((_e = documentInfo === null || documentInfo === void 0 ? void 0 : documentInfo.data) === null || _e === void 0 ? void 0 : _e.id) || routeDocumentId;
|
|
94
122
|
var hasDocumentContext = Boolean(collectionSlug) &&
|
|
95
123
|
documentId !== undefined &&
|
|
96
124
|
documentId !== null &&
|
|
@@ -118,7 +146,7 @@ var Translator = function () {
|
|
|
118
146
|
_b.label = 1;
|
|
119
147
|
case 1:
|
|
120
148
|
_b.trys.push([1, 4, 5, 6]);
|
|
121
|
-
return [4 /*yield*/, fetch("/api/".concat(collectionSlug, "/translate?locale=").concat(
|
|
149
|
+
return [4 /*yield*/, fetch("/api/".concat(collectionSlug, "/translate?locale=").concat(activeLocaleCode), {
|
|
122
150
|
method: 'POST',
|
|
123
151
|
headers: {
|
|
124
152
|
'Content-Type': 'application/json',
|
|
@@ -154,48 +182,48 @@ var Translator = function () {
|
|
|
154
182
|
var handleCloseTranslator = (0, react_1.useCallback)(function () {
|
|
155
183
|
setIsOpen(false);
|
|
156
184
|
}, []);
|
|
157
|
-
var
|
|
185
|
+
var modelOptions = [
|
|
158
186
|
{
|
|
159
187
|
label: 'Default',
|
|
160
188
|
value: 'default',
|
|
161
189
|
},
|
|
162
190
|
{
|
|
163
|
-
label: 'GPT-
|
|
164
|
-
value: 'gpt-
|
|
191
|
+
label: 'GPT-5 Mini ($0.25 in / $2.00 out per 1M)',
|
|
192
|
+
value: 'gpt-5-mini',
|
|
165
193
|
},
|
|
166
194
|
{
|
|
167
|
-
label: 'GPT-3.
|
|
168
|
-
value: 'gpt-
|
|
195
|
+
label: 'GPT-4.1 Mini ($0.80 in / $3.20 out per 1M)',
|
|
196
|
+
value: 'gpt-4.1-mini',
|
|
169
197
|
},
|
|
170
198
|
{
|
|
171
|
-
label: '
|
|
172
|
-
value: '
|
|
199
|
+
label: 'o3 ($2.00 in / $8.00 out per 1M)',
|
|
200
|
+
value: 'o3',
|
|
173
201
|
},
|
|
174
202
|
{
|
|
175
|
-
label: 'GPT-
|
|
176
|
-
value: 'gpt-
|
|
203
|
+
label: 'GPT-5 ($1.25 in / $10.00 out per 1M)',
|
|
204
|
+
value: 'gpt-5',
|
|
177
205
|
},
|
|
178
206
|
];
|
|
179
|
-
var
|
|
180
|
-
label: locale.label
|
|
207
|
+
var sourceLocaleOptions = locales.map(function (locale) { return ({
|
|
208
|
+
label: locale.label,
|
|
181
209
|
value: locale.code,
|
|
182
210
|
}); });
|
|
183
211
|
var translatorControls = isLoading ? (react_1.default.createElement(ui_1.Button, { className: "".concat(baseClass, "__loading"), disabled: true }, "Results are loading...")) : (react_1.default.createElement("div", { className: "".concat(baseClass, "__content") },
|
|
184
212
|
react_1.default.createElement("p", { className: "".concat(baseClass, "__description") }, "Choose source locale and AI model, then start translation for this document."),
|
|
185
213
|
react_1.default.createElement("div", { className: "".concat(baseClass, "__field") },
|
|
186
214
|
react_1.default.createElement("p", { className: "".concat(baseClass, "__label") }, "Model"),
|
|
187
|
-
react_1.default.createElement(
|
|
188
|
-
|
|
189
|
-
|
|
215
|
+
react_1.default.createElement("div", { className: "".concat(baseClass, "__radio-group"), role: "radiogroup", "aria-label": "Model" }, modelOptions.map(function (option) { return (react_1.default.createElement("label", { key: option.value, className: "".concat(baseClass, "__radio-option") },
|
|
216
|
+
react_1.default.createElement("input", { type: "radio", name: "selectedModel", value: option.value, checked: selectedModel === option.value, onChange: function () { return setSelectedModel(option.value); } }),
|
|
217
|
+
react_1.default.createElement("span", null, option.label))); }))),
|
|
190
218
|
react_1.default.createElement("div", { className: "".concat(baseClass, "__field") },
|
|
191
219
|
react_1.default.createElement("p", { className: "".concat(baseClass, "__label") }, "Source locale"),
|
|
192
|
-
react_1.default.createElement(
|
|
193
|
-
|
|
194
|
-
|
|
220
|
+
react_1.default.createElement("div", { className: "".concat(baseClass, "__radio-group"), role: "radiogroup", "aria-label": "Source locale" }, sourceLocaleOptions.map(function (option) { return (react_1.default.createElement("label", { key: option.value, className: "".concat(baseClass, "__radio-option") },
|
|
221
|
+
react_1.default.createElement("input", { type: "radio", name: "sourceLocale", value: option.value, checked: selectedSourceLocale === option.value, onChange: function () { return setSelectedSourceLocal(option.value); } }),
|
|
222
|
+
react_1.default.createElement("span", null, option.label))); }))),
|
|
195
223
|
react_1.default.createElement("div", { className: "".concat(baseClass, "__translation-buttons") },
|
|
196
224
|
react_1.default.createElement(ui_1.Button, { buttonStyle: "primary", className: "".concat(baseClass, "__action"), disabled: isLoading || !hasDocumentContext, onClick: function () { return translate({}); } },
|
|
197
225
|
react_1.default.createElement("span", null, "Translate content to all languages")),
|
|
198
|
-
react_1.default.createElement(ui_1.Button, { buttonStyle: "secondary", className: "".concat(baseClass, "__action"), disabled: isLoading || !hasDocumentContext, onClick: function () { return translate({ codes: [
|
|
226
|
+
react_1.default.createElement(ui_1.Button, { buttonStyle: "secondary", className: "".concat(baseClass, "__action"), disabled: isLoading || !hasDocumentContext, onClick: function () { return translate({ codes: [activeLocaleCode] }); } },
|
|
199
227
|
react_1.default.createElement("span", null,
|
|
200
228
|
"Translate only ",
|
|
201
229
|
fallbackLocaleLabel)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Translator/index.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,6CAA0C;AAE1C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Translator/index.tsx"],"names":[],"mapp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AAW,EACvB,SAAS,EAAE,UAAG,SAAS,sBAAmB,EAC1C,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAC,OAAO,iBAGL;QAER,MAAM,IAAI,CACT,uCAAK,SAAS,EAAE,UAAG,SAAS,YAAS,EAAE,IAAI,EAAC,QAAQ,gBAAa,IAAI;YACnE,uCAAK,SAAS,EAAE,UAAG,SAAS,eAAY,EAAE,OAAO,EAAE,qBAAqB,GAAI;YAC5E,uCAAK,SAAS,EAAE,UAAG,SAAS,aAAU,IAAG,kBAAkB,CAAO,CAC9D,CACP,CACG,CACP,CAAA;AACH,CAAC,CAAA;AAjPY,QAAA,UAAU,cAiPtB"}
|
package/dist/plugin.js
CHANGED
|
@@ -70,7 +70,7 @@ var aiCaption_1 = __importDefault(require("./aiCaption"));
|
|
|
70
70
|
var aiTranslatorPlugin = function (pluginOptions) {
|
|
71
71
|
return function (incomingConfig) {
|
|
72
72
|
var _a, _b;
|
|
73
|
-
var allCollectionOptions = pluginOptions.collections
|
|
73
|
+
var allCollectionOptions = pluginOptions.collections;
|
|
74
74
|
var translatorComponentAbsolutePath = path_1.default.resolve(__dirname, './components/Translator/index.js');
|
|
75
75
|
if (translatorComponentAbsolutePath.includes("".concat(path_1.default.sep, ".next").concat(path_1.default.sep))) {
|
|
76
76
|
var fromRepoRootDist = path_1.default.resolve(process.cwd(), '../dist/components/Translator/index.js');
|
|
@@ -89,10 +89,58 @@ var aiTranslatorPlugin = function (pluginOptions) {
|
|
|
89
89
|
var translatorComponentPath = "".concat(translatorComponentPathFromBaseDir.startsWith('.')
|
|
90
90
|
? translatorComponentPathFromBaseDir
|
|
91
91
|
: "./".concat(translatorComponentPathFromBaseDir), "#Translator");
|
|
92
|
+
var localizationConfig = typeof incomingConfig.localization === 'object' && incomingConfig.localization
|
|
93
|
+
? incomingConfig.localization
|
|
94
|
+
: undefined;
|
|
95
|
+
var sanitizedLocalization = localizationConfig
|
|
96
|
+
? {
|
|
97
|
+
defaultLocale: localizationConfig.defaultLocale,
|
|
98
|
+
locales: Array.isArray(localizationConfig.locales)
|
|
99
|
+
? localizationConfig.locales
|
|
100
|
+
.map(function (locale) {
|
|
101
|
+
if (typeof locale === 'string') {
|
|
102
|
+
return {
|
|
103
|
+
code: locale,
|
|
104
|
+
label: locale,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (!locale || typeof locale !== 'object' || typeof locale.code !== 'string') {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
var rawLabel = locale.label;
|
|
111
|
+
var label = locale.code;
|
|
112
|
+
if (typeof rawLabel === 'string') {
|
|
113
|
+
label = rawLabel;
|
|
114
|
+
}
|
|
115
|
+
else if (rawLabel && typeof rawLabel === 'object') {
|
|
116
|
+
var defaultLocaleLabel = typeof localizationConfig.defaultLocale === 'string'
|
|
117
|
+
? rawLabel[localizationConfig.defaultLocale]
|
|
118
|
+
: undefined;
|
|
119
|
+
var firstStringLabel = Object.values(rawLabel).find(function (value) { return typeof value === 'string'; });
|
|
120
|
+
label =
|
|
121
|
+
(typeof defaultLocaleLabel === 'string'
|
|
122
|
+
? defaultLocaleLabel
|
|
123
|
+
: firstStringLabel) || locale.code;
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
code: locale.code,
|
|
127
|
+
label: label,
|
|
128
|
+
};
|
|
129
|
+
})
|
|
130
|
+
.filter(function (locale) { return Boolean(locale); })
|
|
131
|
+
: [],
|
|
132
|
+
}
|
|
133
|
+
: undefined;
|
|
134
|
+
var translatorComponent = {
|
|
135
|
+
path: translatorComponentPath,
|
|
136
|
+
clientProps: {
|
|
137
|
+
localization: sanitizedLocalization,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
92
140
|
var withTranslatorControl = function (collectionConfig) {
|
|
93
141
|
var _a, _b, _c, _d, _e, _f;
|
|
94
142
|
return (__assign(__assign({}, collectionConfig), { admin: __assign(__assign({}, (collectionConfig.admin || {})), { components: __assign(__assign({}, (((_a = collectionConfig.admin) === null || _a === void 0 ? void 0 : _a.components) || {})), { edit: __assign(__assign({}, (((_c = (_b = collectionConfig.admin) === null || _b === void 0 ? void 0 : _b.components) === null || _c === void 0 ? void 0 : _c.edit) || {})), { beforeDocumentControls: __spreadArray(__spreadArray([], (((_f = (_e = (_d = collectionConfig.admin) === null || _d === void 0 ? void 0 : _d.components) === null || _e === void 0 ? void 0 : _e.edit) === null || _f === void 0 ? void 0 : _f.beforeDocumentControls) || []), true), [
|
|
95
|
-
|
|
143
|
+
translatorComponent,
|
|
96
144
|
], false) }) }) }) }));
|
|
97
145
|
};
|
|
98
146
|
var config = __assign({}, incomingConfig);
|
|
@@ -108,32 +156,6 @@ var aiTranslatorPlugin = function (pluginOptions) {
|
|
|
108
156
|
config.collections = (config.collections || []).map(function (existingCollection) {
|
|
109
157
|
var _a;
|
|
110
158
|
var collectionOptions = allCollectionOptions[existingCollection.slug];
|
|
111
|
-
/*if (options?.adapter) {
|
|
112
|
-
const adapter = options.adapter({
|
|
113
|
-
collection: existingCollection,
|
|
114
|
-
prefix: options.prefix,
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
if (adapter.onInit) initFunctions.push(adapter.onInit)
|
|
118
|
-
|
|
119
|
-
const fields = getFields({
|
|
120
|
-
collection: existingCollection,
|
|
121
|
-
disablePayloadAccessControl: options.disablePayloadAccessControl,
|
|
122
|
-
generateFileURL: options.generateFileURL,
|
|
123
|
-
prefix: options.prefix,
|
|
124
|
-
adapter,
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
const handlers = [
|
|
128
|
-
...(typeof existingCollection.upload === 'object' &&
|
|
129
|
-
Array.isArray(existingCollection.upload.handlers)
|
|
130
|
-
? existingCollection.upload.handlers
|
|
131
|
-
: []),
|
|
132
|
-
]
|
|
133
|
-
|
|
134
|
-
if (!options.disablePayloadAccessControl) {
|
|
135
|
-
handlers.push(adapter.staticHandler)
|
|
136
|
-
}*/
|
|
137
159
|
if (!collectionOptions)
|
|
138
160
|
return existingCollection;
|
|
139
161
|
return __assign(__assign({}, withTranslatorControl(existingCollection)), { endpoints: __spreadArray(__spreadArray([], (existingCollection.endpoints || []), true), [
|
|
@@ -143,10 +165,7 @@ var aiTranslatorPlugin = function (pluginOptions) {
|
|
|
143
165
|
handler: (0, handleTranslate_1.createTranslatorHandler)(pluginOptions),
|
|
144
166
|
},
|
|
145
167
|
], false), hooks: __assign(__assign({}, (existingCollection.hooks || {})), { afterChange: __spreadArray([], (((_a = existingCollection.hooks) === null || _a === void 0 ? void 0 : _a.afterChange) || []), true) }), fields: __spreadArray([], (existingCollection.fields || []), true) });
|
|
146
|
-
//}
|
|
147
|
-
return existingCollection;
|
|
148
168
|
});
|
|
149
|
-
config.admin = __assign({}, (config.admin || {}));
|
|
150
169
|
// If the plugin is disabled, return the config without modifying it
|
|
151
170
|
// The order of this check is important, we still want any webpack extensions to be applied even if the plugin is disabled
|
|
152
171
|
if (pluginOptions.enabled === false) {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0CAAmB;AACnB,8CAAuB;AAEvB,qDAAmD;AAEnD,4EAAqD;AACrD,qDAA2D;AAC3D,+
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0CAAmB;AACnB,8CAAuB;AAEvB,qDAAmD;AAEnD,4EAAqD;AACrD,qDAA2D;AAC3D,+CAAoD;AACpD,0DAAuC;AAEhC,IAAM,kBAAkB,GAC7B,UAAC,aAA0B;IAC3B,OAAA,UAAA,cAAc;;QACJ,IAAa,oBAAoB,GAAK,aAAa,YAAlB,CAAkB;QAC3D,IAAI,+BAA+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AAC,CACxB,CAAA;QAED,MAAM,CAAC,SAAS,mCACX,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;YAC3B;gBACE,IAAI,EAAE,gBAAgB;gBACtB,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,IAAA,kCAAmB,EAAC,aAAa,CAAC;aAC5C;iBACF,CAAA;QAED,MAAM,CAAC,MAAM,GAAG,UAAM,OAAO;;;;6BACvB,cAAc,CAAC,MAAM,EAArB,wBAAqB;wBAAE,qBAAM,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;4BAC/D,mEAAmE;0BADJ;;wBAApC,SAAoC,CAAA;;;wBAC/D,mEAAmE;wBACnE,IAAA,iCAAe,EAAC,aAAa,EAAE,OAAO,CAAC,CAAA;;;;aACxC,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;AAjMD,CAiMC,CAAA;AAnMU,QAAA,kBAAkB,sBAmM5B"}
|
|
@@ -167,7 +167,7 @@ function translateTextOrObject(_a) {
|
|
|
167
167
|
function isTranslateNode(node, key) {
|
|
168
168
|
return (key === 'text' && typeof node[key] === 'string') || key === 'name';
|
|
169
169
|
}
|
|
170
|
-
var textAsString, openai, textMap, _f, promptFunc, namespace, localization, restSettings, languageIso, promptMessage, finalPrompt, chatCompletion, newText, newItemResult, error_1, newResult;
|
|
170
|
+
var textAsString, openai, textMap, _f, promptFunc, namespace, localization, restSettings, languageIso, promptMessage, finalPrompt, model, usesCompletionTokens, maxTokensFromSettings, maxCompletionTokensFromSettings, temperatureFromSettings, topPFromSettings, frequencyPenaltyFromSettings, presencePenaltyFromSettings, restCompletionSettings, chatCompletion, newText, newItemResult, error_1, newResult;
|
|
171
171
|
return __generator(this, function (_g) {
|
|
172
172
|
switch (_g.label) {
|
|
173
173
|
case 0:
|
|
@@ -206,7 +206,23 @@ function translateTextOrObject(_a) {
|
|
|
206
206
|
language: language,
|
|
207
207
|
settings: settings,
|
|
208
208
|
});
|
|
209
|
-
|
|
209
|
+
model = restSettings.model || 'gpt-4o';
|
|
210
|
+
usesCompletionTokens = /^(gpt-5|o[1-9])/i.test(model);
|
|
211
|
+
maxTokensFromSettings = restSettings.max_tokens, maxCompletionTokensFromSettings = restSettings.max_completion_tokens, temperatureFromSettings = restSettings.temperature, topPFromSettings = restSettings.top_p, frequencyPenaltyFromSettings = restSettings.frequency_penalty, presencePenaltyFromSettings = restSettings.presence_penalty, restCompletionSettings = __rest(restSettings, ["max_tokens", "max_completion_tokens", "temperature", "top_p", "frequency_penalty", "presence_penalty"]);
|
|
212
|
+
return [4 /*yield*/, openai.chat.completions.create(__assign(__assign(__assign({ model: model, messages: finalPrompt }, (!usesCompletionTokens
|
|
213
|
+
? {
|
|
214
|
+
temperature: temperatureFromSettings !== null && temperatureFromSettings !== void 0 ? temperatureFromSettings : 0,
|
|
215
|
+
top_p: topPFromSettings !== null && topPFromSettings !== void 0 ? topPFromSettings : 1,
|
|
216
|
+
frequency_penalty: frequencyPenaltyFromSettings !== null && frequencyPenaltyFromSettings !== void 0 ? frequencyPenaltyFromSettings : 0,
|
|
217
|
+
presence_penalty: presencePenaltyFromSettings !== null && presencePenaltyFromSettings !== void 0 ? presencePenaltyFromSettings : 0,
|
|
218
|
+
}
|
|
219
|
+
: {})), (usesCompletionTokens
|
|
220
|
+
? {
|
|
221
|
+
max_completion_tokens: maxCompletionTokensFromSettings || maxTokensFromSettings || 4096,
|
|
222
|
+
}
|
|
223
|
+
: {
|
|
224
|
+
max_tokens: maxTokensFromSettings || maxCompletionTokensFromSettings || 4096,
|
|
225
|
+
})), restCompletionSettings))];
|
|
210
226
|
case 2:
|
|
211
227
|
chatCompletion = _g.sent();
|
|
212
228
|
if ((_d = text === null || text === void 0 ? void 0 : text.root) === null || _d === void 0 ? void 0 : _d.children) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translateTextAndObjects.js","sourceRoot":"","sources":["../src/translateTextAndObjects.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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EAAE,OAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAApD,CAAoD,CAAC,EAAA;;oBAAlF,SAAkF,CAAA;oBAC3D,qBAAM,qBAAqB,CAAC;4BACjD,IAAI,MAAA;4BACJ,QAAQ,UAAA;4BACR,cAAc,gBAAA;4BACd,UAAU,EAAE,UAAU,GAAG,CAAC;4BAC1B,QAAQ,UAAA;yBACT,CAAC,EAAA;;oBANI,SAAS,GAAQ,SAMrB;oBAEF,sBAAO,SAAS,EAAA;;oBAEhB,OAAO,CAAC,GAAG,CACT,yBAAyB,EACzB,OAAK,CAAC,iDAAiD,CACxD,CAAA;;;;;;;CAGN;AAjID,sDAiIC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG"}
|
package/package.json
CHANGED
|
@@ -53,6 +53,25 @@
|
|
|
53
53
|
font-weight: 600;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
&__radio-group {
|
|
57
|
+
display: grid;
|
|
58
|
+
gap: calc(var(--base) * 0.25);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&__radio-option {
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: calc(var(--base) * 0.35);
|
|
65
|
+
font-size: 0.9rem;
|
|
66
|
+
color: var(--theme-elevation-900);
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
|
|
69
|
+
input[type='radio'] {
|
|
70
|
+
margin: 0;
|
|
71
|
+
accent-color: var(--theme-success-500);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
56
75
|
&__translation-buttons {
|
|
57
76
|
display: flex;
|
|
58
77
|
flex-wrap: wrap;
|
|
@@ -2,30 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { useCallback } from 'react'
|
|
4
4
|
|
|
5
|
-
import { Button,
|
|
5
|
+
import { Button, useDocumentInfo } from '@payloadcms/ui'
|
|
6
6
|
import './Translator.scss'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type LocaleShape = { code: string; label?: string }
|
|
9
|
+
|
|
10
|
+
type TranslatorProps = {
|
|
11
|
+
localization?: {
|
|
12
|
+
defaultLocale?: string
|
|
13
|
+
locales?: Array<string | LocaleShape>
|
|
14
|
+
}
|
|
15
|
+
}
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
export const Translator: React.FC<TranslatorProps> = ({ localization }) => {
|
|
18
|
+
const baseClass = 'ai-translator'
|
|
12
19
|
|
|
13
20
|
const [isOpen, setIsOpen] = React.useState(false)
|
|
14
21
|
const [isLoading, setIsLoading] = React.useState(false)
|
|
15
22
|
const [selectedModel, setSelectedModel] = React.useState<string>('default')
|
|
16
23
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const activeLocaleFromURL = React.useMemo(() => {
|
|
25
|
+
if (typeof window === 'undefined') return undefined
|
|
26
|
+
const url = new URL(window.location.href)
|
|
27
|
+
return url.searchParams.get('locale') || undefined
|
|
28
|
+
}, [])
|
|
29
|
+
|
|
30
|
+
const defaultLocaleCode = localization?.defaultLocale || 'en'
|
|
31
|
+
|
|
32
|
+
const locales = React.useMemo(() => {
|
|
33
|
+
const localizationLocales = localization?.locales
|
|
34
|
+
|
|
35
|
+
if (!Array.isArray(localizationLocales)) {
|
|
36
|
+
return [{ code: defaultLocaleCode, label: defaultLocaleCode }]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const normalizedLocales: LocaleShape[] = []
|
|
40
|
+
|
|
41
|
+
localizationLocales.forEach((localeEntry: any) => {
|
|
42
|
+
if (typeof localeEntry === 'string') {
|
|
43
|
+
normalizedLocales.push({
|
|
44
|
+
code: localeEntry,
|
|
45
|
+
label: localeEntry,
|
|
46
|
+
})
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (localeEntry && typeof localeEntry === 'object' && localeEntry.code) {
|
|
51
|
+
normalizedLocales.push({
|
|
52
|
+
code: localeEntry.code,
|
|
53
|
+
label: localeEntry.label || localeEntry.code,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return normalizedLocales.length
|
|
59
|
+
? normalizedLocales
|
|
60
|
+
: [{ code: defaultLocaleCode, label: defaultLocaleCode }]
|
|
61
|
+
}, [defaultLocaleCode, localization?.locales])
|
|
62
|
+
|
|
63
|
+
const activeLocaleCode =
|
|
64
|
+
activeLocaleFromURL && locales.some(locale => locale.code === activeLocaleFromURL)
|
|
65
|
+
? activeLocaleFromURL
|
|
66
|
+
: defaultLocaleCode
|
|
67
|
+
|
|
68
|
+
const fallbackLocaleLabel =
|
|
69
|
+
locales.find(locale => locale.code === activeLocaleCode)?.label || activeLocaleCode
|
|
70
|
+
|
|
71
|
+
const [selectedSourceLocale, setSelectedSourceLocal] = React.useState<string>(activeLocaleCode)
|
|
29
72
|
const documentInfo: any = useDocumentInfo()
|
|
30
73
|
const routeMatch =
|
|
31
74
|
typeof window !== 'undefined'
|
|
@@ -62,21 +105,18 @@ export const Translator: React.FC = () => {
|
|
|
62
105
|
}
|
|
63
106
|
setIsLoading(true)
|
|
64
107
|
try {
|
|
65
|
-
const response = await fetch(
|
|
66
|
-
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
headers: {
|
|
70
|
-
'Content-Type': 'application/json',
|
|
71
|
-
},
|
|
72
|
-
body: JSON.stringify({
|
|
73
|
-
id: documentId,
|
|
74
|
-
locale: selectedSourceLocale,
|
|
75
|
-
codes,
|
|
76
|
-
settings,
|
|
77
|
-
}),
|
|
108
|
+
const response = await fetch(`/api/${collectionSlug}/translate?locale=${activeLocaleCode}`, {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
headers: {
|
|
111
|
+
'Content-Type': 'application/json',
|
|
78
112
|
},
|
|
79
|
-
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
id: documentId,
|
|
115
|
+
locale: selectedSourceLocale,
|
|
116
|
+
codes,
|
|
117
|
+
settings,
|
|
118
|
+
}),
|
|
119
|
+
})
|
|
80
120
|
|
|
81
121
|
await response.json()
|
|
82
122
|
} catch (error) {
|
|
@@ -94,32 +134,31 @@ export const Translator: React.FC = () => {
|
|
|
94
134
|
setIsOpen(false)
|
|
95
135
|
}, [])
|
|
96
136
|
|
|
97
|
-
const
|
|
137
|
+
const modelOptions = [
|
|
98
138
|
{
|
|
99
139
|
label: 'Default',
|
|
100
140
|
value: 'default',
|
|
101
141
|
},
|
|
102
142
|
{
|
|
103
|
-
label: 'GPT-
|
|
104
|
-
value: 'gpt-
|
|
143
|
+
label: 'GPT-5 Mini ($0.25 in / $2.00 out per 1M)',
|
|
144
|
+
value: 'gpt-5-mini',
|
|
105
145
|
},
|
|
106
146
|
{
|
|
107
|
-
label: 'GPT-3.
|
|
108
|
-
value: 'gpt-
|
|
147
|
+
label: 'GPT-4.1 Mini ($0.80 in / $3.20 out per 1M)',
|
|
148
|
+
value: 'gpt-4.1-mini',
|
|
109
149
|
},
|
|
110
150
|
{
|
|
111
|
-
label: '
|
|
112
|
-
value: '
|
|
151
|
+
label: 'o3 ($2.00 in / $8.00 out per 1M)',
|
|
152
|
+
value: 'o3',
|
|
113
153
|
},
|
|
114
|
-
|
|
115
154
|
{
|
|
116
|
-
label: 'GPT-
|
|
117
|
-
value: 'gpt-
|
|
155
|
+
label: 'GPT-5 ($1.25 in / $10.00 out per 1M)',
|
|
156
|
+
value: 'gpt-5',
|
|
118
157
|
},
|
|
119
158
|
]
|
|
120
159
|
|
|
121
|
-
const
|
|
122
|
-
label: locale.label
|
|
160
|
+
const sourceLocaleOptions = locales.map((locale: any) => ({
|
|
161
|
+
label: locale.label,
|
|
123
162
|
value: locale.code,
|
|
124
163
|
}))
|
|
125
164
|
|
|
@@ -135,28 +174,38 @@ export const Translator: React.FC = () => {
|
|
|
135
174
|
|
|
136
175
|
<div className={`${baseClass}__field`}>
|
|
137
176
|
<p className={`${baseClass}__label`}>Model</p>
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
177
|
+
<div className={`${baseClass}__radio-group`} role="radiogroup" aria-label="Model">
|
|
178
|
+
{modelOptions.map(option => (
|
|
179
|
+
<label key={option.value} className={`${baseClass}__radio-option`}>
|
|
180
|
+
<input
|
|
181
|
+
type="radio"
|
|
182
|
+
name="selectedModel"
|
|
183
|
+
value={option.value}
|
|
184
|
+
checked={selectedModel === option.value}
|
|
185
|
+
onChange={() => setSelectedModel(option.value)}
|
|
186
|
+
/>
|
|
187
|
+
<span>{option.label}</span>
|
|
188
|
+
</label>
|
|
189
|
+
))}
|
|
190
|
+
</div>
|
|
147
191
|
</div>
|
|
148
192
|
|
|
149
193
|
<div className={`${baseClass}__field`}>
|
|
150
194
|
<p className={`${baseClass}__label`}>Source locale</p>
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
195
|
+
<div className={`${baseClass}__radio-group`} role="radiogroup" aria-label="Source locale">
|
|
196
|
+
{sourceLocaleOptions.map(option => (
|
|
197
|
+
<label key={option.value} className={`${baseClass}__radio-option`}>
|
|
198
|
+
<input
|
|
199
|
+
type="radio"
|
|
200
|
+
name="sourceLocale"
|
|
201
|
+
value={option.value}
|
|
202
|
+
checked={selectedSourceLocale === option.value}
|
|
203
|
+
onChange={() => setSelectedSourceLocal(option.value)}
|
|
204
|
+
/>
|
|
205
|
+
<span>{option.label}</span>
|
|
206
|
+
</label>
|
|
207
|
+
))}
|
|
208
|
+
</div>
|
|
160
209
|
</div>
|
|
161
210
|
|
|
162
211
|
<div className={`${baseClass}__translation-buttons`}>
|
|
@@ -172,7 +221,7 @@ export const Translator: React.FC = () => {
|
|
|
172
221
|
buttonStyle="secondary"
|
|
173
222
|
className={`${baseClass}__action`}
|
|
174
223
|
disabled={isLoading || !hasDocumentContext}
|
|
175
|
-
onClick={() => translate({ codes: [
|
|
224
|
+
onClick={() => translate({ codes: [activeLocaleCode] })}
|
|
176
225
|
>
|
|
177
226
|
<span>Translate only {fallbackLocaleLabel}</span>
|
|
178
227
|
</Button>
|
package/src/plugin.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from 'payload'
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
|
|
@@ -6,15 +6,13 @@ import { onInitExtension } from './onInitExtension'
|
|
|
6
6
|
import type { PluginTypes } from './types'
|
|
7
7
|
import stringTranslations from './stringTranslations'
|
|
8
8
|
import { createTranslatorHandler } from './handleTranslate'
|
|
9
|
-
import {
|
|
9
|
+
import { generateTextHandler } from './generateText'
|
|
10
10
|
import aiCaptionHook from './aiCaption'
|
|
11
11
|
|
|
12
|
-
type PluginType = (pluginOptions: PluginTypes) => Plugin
|
|
13
|
-
|
|
14
12
|
export const aiTranslatorPlugin =
|
|
15
13
|
(pluginOptions: PluginTypes): Plugin =>
|
|
16
14
|
incomingConfig => {
|
|
17
|
-
const { collections: allCollectionOptions
|
|
15
|
+
const { collections: allCollectionOptions } = pluginOptions
|
|
18
16
|
let translatorComponentAbsolutePath = path.resolve(
|
|
19
17
|
__dirname,
|
|
20
18
|
'./components/Translator/index.js',
|
|
@@ -42,6 +40,65 @@ export const aiTranslatorPlugin =
|
|
|
42
40
|
: `./${translatorComponentPathFromBaseDir}`
|
|
43
41
|
}#Translator`
|
|
44
42
|
|
|
43
|
+
const localizationConfig =
|
|
44
|
+
typeof incomingConfig.localization === 'object' && incomingConfig.localization
|
|
45
|
+
? incomingConfig.localization
|
|
46
|
+
: undefined
|
|
47
|
+
|
|
48
|
+
const sanitizedLocalization = localizationConfig
|
|
49
|
+
? {
|
|
50
|
+
defaultLocale: localizationConfig.defaultLocale,
|
|
51
|
+
locales: Array.isArray(localizationConfig.locales)
|
|
52
|
+
? localizationConfig.locales
|
|
53
|
+
.map((locale: any) => {
|
|
54
|
+
if (typeof locale === 'string') {
|
|
55
|
+
return {
|
|
56
|
+
code: locale,
|
|
57
|
+
label: locale,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!locale || typeof locale !== 'object' || typeof locale.code !== 'string') {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const rawLabel = locale.label
|
|
66
|
+
let label = locale.code
|
|
67
|
+
|
|
68
|
+
if (typeof rawLabel === 'string') {
|
|
69
|
+
label = rawLabel
|
|
70
|
+
} else if (rawLabel && typeof rawLabel === 'object') {
|
|
71
|
+
const defaultLocaleLabel =
|
|
72
|
+
typeof localizationConfig.defaultLocale === 'string'
|
|
73
|
+
? rawLabel[localizationConfig.defaultLocale]
|
|
74
|
+
: undefined
|
|
75
|
+
const firstStringLabel = Object.values(rawLabel).find(
|
|
76
|
+
value => typeof value === 'string',
|
|
77
|
+
) as string | undefined
|
|
78
|
+
|
|
79
|
+
label =
|
|
80
|
+
(typeof defaultLocaleLabel === 'string'
|
|
81
|
+
? defaultLocaleLabel
|
|
82
|
+
: firstStringLabel) || locale.code
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
code: locale.code,
|
|
87
|
+
label,
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
.filter((locale): locale is { code: string; label: string } => Boolean(locale))
|
|
91
|
+
: [],
|
|
92
|
+
}
|
|
93
|
+
: undefined
|
|
94
|
+
|
|
95
|
+
const translatorComponent = {
|
|
96
|
+
path: translatorComponentPath,
|
|
97
|
+
clientProps: {
|
|
98
|
+
localization: sanitizedLocalization,
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
|
|
45
102
|
const withTranslatorControl = (collectionConfig: any) => ({
|
|
46
103
|
...collectionConfig,
|
|
47
104
|
admin: {
|
|
@@ -52,7 +109,7 @@ export const aiTranslatorPlugin =
|
|
|
52
109
|
...(collectionConfig.admin?.components?.edit || {}),
|
|
53
110
|
beforeDocumentControls: [
|
|
54
111
|
...(collectionConfig.admin?.components?.edit?.beforeDocumentControls || []),
|
|
55
|
-
|
|
112
|
+
translatorComponent,
|
|
56
113
|
],
|
|
57
114
|
},
|
|
58
115
|
},
|
|
@@ -89,33 +146,6 @@ export const aiTranslatorPlugin =
|
|
|
89
146
|
config.collections = (config.collections || []).map(existingCollection => {
|
|
90
147
|
const collectionOptions = allCollectionOptions[existingCollection.slug]
|
|
91
148
|
|
|
92
|
-
/*if (options?.adapter) {
|
|
93
|
-
const adapter = options.adapter({
|
|
94
|
-
collection: existingCollection,
|
|
95
|
-
prefix: options.prefix,
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
if (adapter.onInit) initFunctions.push(adapter.onInit)
|
|
99
|
-
|
|
100
|
-
const fields = getFields({
|
|
101
|
-
collection: existingCollection,
|
|
102
|
-
disablePayloadAccessControl: options.disablePayloadAccessControl,
|
|
103
|
-
generateFileURL: options.generateFileURL,
|
|
104
|
-
prefix: options.prefix,
|
|
105
|
-
adapter,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const handlers = [
|
|
109
|
-
...(typeof existingCollection.upload === 'object' &&
|
|
110
|
-
Array.isArray(existingCollection.upload.handlers)
|
|
111
|
-
? existingCollection.upload.handlers
|
|
112
|
-
: []),
|
|
113
|
-
]
|
|
114
|
-
|
|
115
|
-
if (!options.disablePayloadAccessControl) {
|
|
116
|
-
handlers.push(adapter.staticHandler)
|
|
117
|
-
}*/
|
|
118
|
-
|
|
119
149
|
if (!collectionOptions) return existingCollection
|
|
120
150
|
|
|
121
151
|
return {
|
|
@@ -139,15 +169,8 @@ export const aiTranslatorPlugin =
|
|
|
139
169
|
},
|
|
140
170
|
fields: [...(existingCollection.fields || [])],
|
|
141
171
|
}
|
|
142
|
-
//}
|
|
143
|
-
|
|
144
|
-
return existingCollection
|
|
145
172
|
})
|
|
146
173
|
|
|
147
|
-
config.admin = {
|
|
148
|
-
...(config.admin || {}),
|
|
149
|
-
}
|
|
150
|
-
|
|
151
174
|
// If the plugin is disabled, return the config without modifying it
|
|
152
175
|
// The order of this check is important, we still want any webpack extensions to be applied even if the plugin is disabled
|
|
153
176
|
if (pluginOptions.enabled === false) {
|
|
@@ -159,14 +182,10 @@ export const aiTranslatorPlugin =
|
|
|
159
182
|
withTranslatorControl(stringTranslations(pluginOptions)),
|
|
160
183
|
]
|
|
161
184
|
|
|
162
|
-
config.globals = [
|
|
163
|
-
...(config.globals || []),
|
|
164
|
-
// Add additional globals here
|
|
165
|
-
]
|
|
185
|
+
config.globals = [...(config.globals || [])]
|
|
166
186
|
|
|
167
187
|
config.hooks = {
|
|
168
188
|
...(config.hooks || {}),
|
|
169
|
-
// Add additional hooks here
|
|
170
189
|
}
|
|
171
190
|
|
|
172
191
|
config.endpoints = [
|
|
@@ -192,15 +192,37 @@ export async function translateTextOrObject({
|
|
|
192
192
|
settings,
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
+
const model = restSettings.model || 'gpt-4o'
|
|
196
|
+
const usesCompletionTokens = /^(gpt-5|o[1-9])/i.test(model)
|
|
197
|
+
const {
|
|
198
|
+
max_tokens: maxTokensFromSettings,
|
|
199
|
+
max_completion_tokens: maxCompletionTokensFromSettings,
|
|
200
|
+
temperature: temperatureFromSettings,
|
|
201
|
+
top_p: topPFromSettings,
|
|
202
|
+
frequency_penalty: frequencyPenaltyFromSettings,
|
|
203
|
+
presence_penalty: presencePenaltyFromSettings,
|
|
204
|
+
...restCompletionSettings
|
|
205
|
+
} = restSettings
|
|
206
|
+
|
|
195
207
|
const chatCompletion = await openai.chat.completions.create({
|
|
196
|
-
model
|
|
208
|
+
model, // default remains gpt-4o unless overridden via settings.model
|
|
197
209
|
messages: finalPrompt,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
210
|
+
...(!usesCompletionTokens
|
|
211
|
+
? {
|
|
212
|
+
temperature: temperatureFromSettings ?? 0,
|
|
213
|
+
top_p: topPFromSettings ?? 1,
|
|
214
|
+
frequency_penalty: frequencyPenaltyFromSettings ?? 0,
|
|
215
|
+
presence_penalty: presencePenaltyFromSettings ?? 0,
|
|
216
|
+
}
|
|
217
|
+
: {}),
|
|
218
|
+
...(usesCompletionTokens
|
|
219
|
+
? {
|
|
220
|
+
max_completion_tokens: maxCompletionTokensFromSettings || maxTokensFromSettings || 4096,
|
|
221
|
+
}
|
|
222
|
+
: {
|
|
223
|
+
max_tokens: maxTokensFromSettings || maxCompletionTokensFromSettings || 4096,
|
|
224
|
+
}),
|
|
225
|
+
...restCompletionSettings,
|
|
204
226
|
})
|
|
205
227
|
|
|
206
228
|
if (text?.root?.children) {
|