@strapi-ai/translator 0.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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/admin/SettingsPage-C5nm32bD.mjs +466 -0
- package/dist/admin/SettingsPage-CD90jfwT.js +466 -0
- package/dist/admin/en-CU6ocWlA.mjs +97 -0
- package/dist/admin/en-I9cvzxfF.js +97 -0
- package/dist/admin/index-CS0LCA35.mjs +1694 -0
- package/dist/admin/index-DQ3-ym--.js +1693 -0
- package/dist/admin/index.js +4 -0
- package/dist/admin/index.mjs +4 -0
- package/dist/admin/src/components/DiffView.d.ts +31 -0
- package/dist/admin/src/components/Initializer.d.ts +3 -0
- package/dist/admin/src/components/PluginIcon.d.ts +4 -0
- package/dist/admin/src/components/ProgressBar.d.ts +7 -0
- package/dist/admin/src/components/TranslationModal.d.ts +23 -0
- package/dist/admin/src/components/TranslationPanel.d.ts +4 -0
- package/dist/admin/src/components/TranslationWorkflow.d.ts +2 -0
- package/dist/admin/src/components/settings/ProviderConnectionFields.d.ts +12 -0
- package/dist/admin/src/components/settings/TranslationSettingsFields.d.ts +7 -0
- package/dist/admin/src/hooks/useProviderModels.d.ts +13 -0
- package/dist/admin/src/hooks/useTranslationConfig.d.ts +8 -0
- package/dist/admin/src/index.d.ts +12 -0
- package/dist/admin/src/pages/SettingsPage.d.ts +2 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/utils/clampNumber.d.ts +1 -0
- package/dist/admin/src/utils/configPayload.d.ts +23 -0
- package/dist/admin/src/utils/contentManagerLocale.d.ts +1 -0
- package/dist/admin/src/utils/getTranslation.d.ts +1 -0
- package/dist/admin/src/utils/providerDefaults.d.ts +10 -0
- package/dist/admin/src/utils/sse.d.ts +2 -0
- package/dist/admin/src/utils/translatableFields.d.ts +3 -0
- package/dist/admin/src/utils/translationPatch.d.ts +13 -0
- package/dist/server/index.js +1217 -0
- package/dist/server/index.mjs +1217 -0
- package/dist/server/src/application/assemble-translation-patch.d.ts +3 -0
- package/dist/server/src/application/extract-translatable-units.d.ts +9 -0
- package/dist/server/src/application/translate-entry.d.ts +17 -0
- package/dist/server/src/application/translation-provider.d.ts +33 -0
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/config/index.d.ts +5 -0
- package/dist/server/src/controllers/index.d.ts +27 -0
- package/dist/server/src/controllers/translation.controller.d.ts +28 -0
- package/dist/server/src/domain/field-path.d.ts +6 -0
- package/dist/server/src/domain/translation-config.d.ts +27 -0
- package/dist/server/src/domain/translation-event.d.ts +59 -0
- package/dist/server/src/domain/translation-patch.d.ts +11 -0
- package/dist/server/src/domain/translation-unit.d.ts +28 -0
- package/dist/server/src/domain/value-codecs/index.d.ts +3 -0
- package/dist/server/src/domain/value-codecs/string-codec.d.ts +2 -0
- package/dist/server/src/domain/value-codecs/structured-value-codec.d.ts +3 -0
- package/dist/server/src/domain/value-codecs/types.d.ts +11 -0
- package/dist/server/src/index.d.ts +64 -0
- package/dist/server/src/infrastructure/llm/chat-completion-client.d.ts +18 -0
- package/dist/server/src/infrastructure/llm/llm-translation-provider.d.ts +15 -0
- package/dist/server/src/infrastructure/llm/model-list-client.d.ts +19 -0
- package/dist/server/src/infrastructure/llm/openai-chat-completion-client.d.ts +6 -0
- package/dist/server/src/infrastructure/strapi/reconcile-schema.d.ts +7 -0
- package/dist/server/src/infrastructure/strapi/secret-cipher.d.ts +8 -0
- package/dist/server/src/infrastructure/strapi/translation-config-repository.d.ts +16 -0
- package/dist/server/src/infrastructure/strapi/translation-session-service.d.ts +37 -0
- package/dist/server/src/routes/index.d.ts +19 -0
- package/dist/server/src/services/index.d.ts +7 -0
- package/package.json +87 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { TranslatableUnit, TranslatedUnit } from '../domain/translation-unit';
|
|
2
|
+
import { TranslationPatch } from '../domain/translation-patch';
|
|
3
|
+
export declare const assembleTranslationPatch: (sourceUnits: TranslatableUnit[], translatedUnits: TranslatedUnit[]) => TranslationPatch;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TranslatableUnit } from '../domain/translation-unit';
|
|
2
|
+
import { ValueCodec } from '../domain/value-codecs';
|
|
3
|
+
type Schema = Record<string, any>;
|
|
4
|
+
export interface ExtractTranslatableUnitsOptions {
|
|
5
|
+
excludeFieldNames?: string[];
|
|
6
|
+
valueCodecs?: ValueCodec[];
|
|
7
|
+
}
|
|
8
|
+
export declare const extractTranslatableUnits: (contentType: Schema, entry: Record<string, any>, components?: Record<string, Schema>, options?: ExtractTranslatableUnitsOptions) => TranslatableUnit[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TranslationSessionEvent } from '../domain/translation-event';
|
|
2
|
+
import { FieldPath } from '../domain/field-path';
|
|
3
|
+
import { TranslationProvider } from './translation-provider';
|
|
4
|
+
type Schema = Record<string, any>;
|
|
5
|
+
export interface TranslateEntryInput {
|
|
6
|
+
contentType: Schema;
|
|
7
|
+
entry: Record<string, any>;
|
|
8
|
+
components?: Record<string, Schema>;
|
|
9
|
+
sourceLocale?: string;
|
|
10
|
+
targetLocale: string;
|
|
11
|
+
translator: TranslationProvider;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
include?: FieldPath[];
|
|
14
|
+
concurrency?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function translateEntry(input: TranslateEntryInput): AsyncGenerator<TranslationSessionEvent>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TranslatableUnit } from '../domain/translation-unit';
|
|
2
|
+
export interface TranslationProviderContext {
|
|
3
|
+
sourceLocale?: string;
|
|
4
|
+
targetLocale: string;
|
|
5
|
+
}
|
|
6
|
+
export type TranslationProviderEvent = {
|
|
7
|
+
type: 'delta';
|
|
8
|
+
delta: string;
|
|
9
|
+
content: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'completed';
|
|
12
|
+
translatedText: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'retry_scheduled';
|
|
15
|
+
attempt: number;
|
|
16
|
+
delayMs: number;
|
|
17
|
+
reason: string;
|
|
18
|
+
status?: number;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'fallback_used';
|
|
21
|
+
fromModel: string;
|
|
22
|
+
toModel: string;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
export declare class TranslationCredentialError extends Error {
|
|
26
|
+
readonly cause?: unknown;
|
|
27
|
+
constructor(message: string, options?: {
|
|
28
|
+
cause?: unknown;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export interface TranslationProvider {
|
|
32
|
+
translateUnit(unit: TranslatableUnit, context: TranslationProviderContext, signal?: AbortSignal): AsyncGenerator<TranslationProviderEvent>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
translation: ({ strapi }: {
|
|
3
|
+
strapi: import('@strapi/types/dist/core').Strapi;
|
|
4
|
+
}) => {
|
|
5
|
+
getConfig(ctx: Omit<import('koa').Context, "request"> & {
|
|
6
|
+
request: import('koa').Request & {
|
|
7
|
+
body?: unknown;
|
|
8
|
+
};
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
setConfig(ctx: Omit<import('koa').Context, "request"> & {
|
|
11
|
+
request: import('koa').Request & {
|
|
12
|
+
body?: unknown;
|
|
13
|
+
};
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
listModels(ctx: Omit<import('koa').Context, "request"> & {
|
|
16
|
+
request: import('koa').Request & {
|
|
17
|
+
body?: import('./translation.controller').ListModelsRequest;
|
|
18
|
+
};
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
translate(ctx: Omit<import('koa').Context, "request"> & {
|
|
21
|
+
request: import('koa').Request & {
|
|
22
|
+
body?: import('./translation.controller').TranslateRequest;
|
|
23
|
+
};
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Context } from 'koa';
|
|
2
|
+
import { Core } from '@strapi/strapi';
|
|
3
|
+
type AdminRequestContext<Body = unknown> = Omit<Context, 'request'> & {
|
|
4
|
+
request: Context['request'] & {
|
|
5
|
+
body?: Body;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export interface TranslateRequest {
|
|
9
|
+
contentType?: Record<string, any>;
|
|
10
|
+
entry?: Record<string, any>;
|
|
11
|
+
components?: Record<string, any>;
|
|
12
|
+
sourceLocale?: string;
|
|
13
|
+
targetLocale?: string;
|
|
14
|
+
include?: Array<Array<string | number>>;
|
|
15
|
+
}
|
|
16
|
+
export interface ListModelsRequest {
|
|
17
|
+
apiKey?: string;
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
declare const controllers: ({ strapi }: {
|
|
21
|
+
strapi: Core.Strapi;
|
|
22
|
+
}) => {
|
|
23
|
+
getConfig(ctx: AdminRequestContext): Promise<void>;
|
|
24
|
+
setConfig(ctx: AdminRequestContext): Promise<void>;
|
|
25
|
+
listModels(ctx: AdminRequestContext<ListModelsRequest>): Promise<void>;
|
|
26
|
+
translate(ctx: AdminRequestContext<TranslateRequest>): Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
export default controllers;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type FieldPathSegment = string | number;
|
|
2
|
+
export type FieldPath = readonly FieldPathSegment[];
|
|
3
|
+
export declare const pathToId: (path: FieldPath) => string;
|
|
4
|
+
export declare const sanitizeFieldPaths: (value: unknown) => FieldPath[] | undefined;
|
|
5
|
+
export declare const pathsEqual: (left: FieldPath, right: FieldPath) => boolean;
|
|
6
|
+
export declare const cloneWithSetByPath: <T>(source: T, path: FieldPath, value: unknown) => T;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface TranslationConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
model: string;
|
|
5
|
+
fallbackModel: string;
|
|
6
|
+
systemPrompt: string;
|
|
7
|
+
temperature: number;
|
|
8
|
+
maxTokens: number;
|
|
9
|
+
concurrency: number;
|
|
10
|
+
maxRetries: number;
|
|
11
|
+
retryBaseDelayMs: number;
|
|
12
|
+
retryMaxDelayMs: number;
|
|
13
|
+
}
|
|
14
|
+
export type EditableTranslationConfig = Omit<TranslationConfig, 'apiKey'>;
|
|
15
|
+
export interface TranslationConfigUpdateInput extends Partial<EditableTranslationConfig> {
|
|
16
|
+
apiKey?: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface PublicTranslationConfig extends EditableTranslationConfig {
|
|
19
|
+
apiKeyConfigured: boolean;
|
|
20
|
+
apiKeyPreview: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const DEFAULT_TRANSLATION_CONFIG: TranslationConfig;
|
|
23
|
+
export declare const pickEditableTranslationConfig: (input: Record<string, unknown> | null | undefined) => Partial<EditableTranslationConfig>;
|
|
24
|
+
export declare const normalizeTranslationConfig: (input?: Partial<TranslationConfig>) => TranslationConfig;
|
|
25
|
+
export declare const selectEditableTranslationConfig: (config: TranslationConfig) => EditableTranslationConfig;
|
|
26
|
+
export declare const normalizeEditableTranslationConfig: (input?: Partial<EditableTranslationConfig>) => EditableTranslationConfig;
|
|
27
|
+
export declare const toPublicTranslationConfig: (config: TranslationConfig) => PublicTranslationConfig;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FieldPath } from './field-path';
|
|
2
|
+
import { TranslationPatch } from './translation-patch';
|
|
3
|
+
import { TranslatableUnit } from './translation-unit';
|
|
4
|
+
export interface TranslationSessionSummary {
|
|
5
|
+
totalUnits: number;
|
|
6
|
+
succeededUnits: number;
|
|
7
|
+
failedUnits: number;
|
|
8
|
+
failedUnitIds: string[];
|
|
9
|
+
}
|
|
10
|
+
export type TranslationSessionEvent = {
|
|
11
|
+
type: 'session_started';
|
|
12
|
+
sourceLocale?: string;
|
|
13
|
+
targetLocale: string;
|
|
14
|
+
totalUnits: number;
|
|
15
|
+
unitPaths: FieldPath[];
|
|
16
|
+
} | {
|
|
17
|
+
type: 'unit_started';
|
|
18
|
+
unit: TranslatableUnit;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'unit_delta';
|
|
21
|
+
unitId: string;
|
|
22
|
+
path: FieldPath;
|
|
23
|
+
delta: string;
|
|
24
|
+
content: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'unit_retry_scheduled';
|
|
27
|
+
unitId: string;
|
|
28
|
+
path: FieldPath;
|
|
29
|
+
attempt: number;
|
|
30
|
+
delayMs: number;
|
|
31
|
+
reason: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'unit_fallback_used';
|
|
34
|
+
unitId: string;
|
|
35
|
+
path: FieldPath;
|
|
36
|
+
fromModel: string;
|
|
37
|
+
toModel: string;
|
|
38
|
+
reason: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'unit_completed';
|
|
41
|
+
unitId: string;
|
|
42
|
+
path: FieldPath;
|
|
43
|
+
translatedText: string;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'unit_failed';
|
|
46
|
+
unitId: string;
|
|
47
|
+
path: FieldPath;
|
|
48
|
+
error: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'session_completed';
|
|
51
|
+
patch: TranslationPatch;
|
|
52
|
+
summary: TranslationSessionSummary;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'session_aborted';
|
|
55
|
+
summary: TranslationSessionSummary;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'session_failed';
|
|
58
|
+
error: string;
|
|
59
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FieldPath } from './field-path';
|
|
2
|
+
export interface TranslationPatchOperation {
|
|
3
|
+
unitId: string;
|
|
4
|
+
path: FieldPath;
|
|
5
|
+
value: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface TranslationPatch {
|
|
8
|
+
operations: TranslationPatchOperation[];
|
|
9
|
+
}
|
|
10
|
+
export declare const createEmptyTranslationPatch: () => TranslationPatch;
|
|
11
|
+
export declare const applyTranslationPatch: <T>(source: T, patch: TranslationPatch) => T;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FieldPath } from './field-path';
|
|
2
|
+
export type TranslatableFieldType = 'string' | 'text' | 'richtext' | 'blocks' | 'json';
|
|
3
|
+
export interface TranslatableUnit {
|
|
4
|
+
id: string;
|
|
5
|
+
path: FieldPath;
|
|
6
|
+
fieldName: string;
|
|
7
|
+
fieldType: TranslatableFieldType;
|
|
8
|
+
sourceValue: unknown;
|
|
9
|
+
encodedText: string;
|
|
10
|
+
metadata: {
|
|
11
|
+
schemaType: string;
|
|
12
|
+
component?: string;
|
|
13
|
+
dynamicZoneComponent?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface TranslatedUnit {
|
|
17
|
+
id: string;
|
|
18
|
+
path: FieldPath;
|
|
19
|
+
translatedText: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const createTranslatableUnit: (input: {
|
|
22
|
+
path: FieldPath;
|
|
23
|
+
fieldName: string;
|
|
24
|
+
fieldType: TranslatableFieldType;
|
|
25
|
+
sourceValue: unknown;
|
|
26
|
+
encodedText: string;
|
|
27
|
+
metadata?: TranslatableUnit["metadata"];
|
|
28
|
+
}) => TranslatableUnit;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FieldPath } from '../field-path';
|
|
2
|
+
import { TranslatableFieldType } from '../translation-unit';
|
|
3
|
+
export interface EncodedValueUnit {
|
|
4
|
+
pathSuffix: FieldPath;
|
|
5
|
+
sourceValue: string;
|
|
6
|
+
encodedText: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ValueCodec {
|
|
9
|
+
fieldTypes: TranslatableFieldType[];
|
|
10
|
+
extract(value: unknown): EncodedValueUnit[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
register(): void;
|
|
3
|
+
bootstrap: ({ strapi }: {
|
|
4
|
+
strapi: import('@strapi/types/dist/core').Strapi;
|
|
5
|
+
}) => void;
|
|
6
|
+
destroy(): void;
|
|
7
|
+
config: {
|
|
8
|
+
default: () => import('./domain/translation-config').EditableTranslationConfig;
|
|
9
|
+
validator(config: Record<string, unknown>): void;
|
|
10
|
+
};
|
|
11
|
+
controllers: {
|
|
12
|
+
translation: ({ strapi }: {
|
|
13
|
+
strapi: import('@strapi/types/dist/core').Strapi;
|
|
14
|
+
}) => {
|
|
15
|
+
getConfig(ctx: Omit<import('koa').Context, "request"> & {
|
|
16
|
+
request: import('koa').Request & {
|
|
17
|
+
body?: unknown;
|
|
18
|
+
};
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
setConfig(ctx: Omit<import('koa').Context, "request"> & {
|
|
21
|
+
request: import('koa').Request & {
|
|
22
|
+
body?: unknown;
|
|
23
|
+
};
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
listModels(ctx: Omit<import('koa').Context, "request"> & {
|
|
26
|
+
request: import('koa').Request & {
|
|
27
|
+
body?: import('./controllers/translation.controller').ListModelsRequest;
|
|
28
|
+
};
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
translate(ctx: Omit<import('koa').Context, "request"> & {
|
|
31
|
+
request: import('koa').Request & {
|
|
32
|
+
body?: import('./controllers/translation.controller').TranslateRequest;
|
|
33
|
+
};
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
routes: {
|
|
38
|
+
admin: {
|
|
39
|
+
type: string;
|
|
40
|
+
routes: {
|
|
41
|
+
method: string;
|
|
42
|
+
path: string;
|
|
43
|
+
handler: string;
|
|
44
|
+
config: {
|
|
45
|
+
policies: {
|
|
46
|
+
name: string;
|
|
47
|
+
config: {
|
|
48
|
+
actions: string[];
|
|
49
|
+
};
|
|
50
|
+
}[];
|
|
51
|
+
};
|
|
52
|
+
}[];
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
services: {
|
|
56
|
+
'translation-session-service': ({ strapi }: {
|
|
57
|
+
strapi: import('@strapi/types/dist/core').Strapi;
|
|
58
|
+
}) => import('./infrastructure/strapi/translation-session-service').TranslationSessionService;
|
|
59
|
+
};
|
|
60
|
+
contentTypes: {};
|
|
61
|
+
policies: {};
|
|
62
|
+
middlewares: {};
|
|
63
|
+
};
|
|
64
|
+
export default _default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ChatMessage {
|
|
2
|
+
role: 'system' | 'user' | 'assistant';
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ChatCompletionRequest {
|
|
6
|
+
model: string;
|
|
7
|
+
messages: ChatMessage[];
|
|
8
|
+
temperature: number;
|
|
9
|
+
maxTokens?: number;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
export interface ChatCompletionStreamChunk {
|
|
13
|
+
delta: string;
|
|
14
|
+
finishReason?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ChatCompletionClient {
|
|
17
|
+
streamCompletion(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionStreamChunk>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TranslationProvider } from '../../application/translation-provider';
|
|
2
|
+
import { ChatCompletionClient } from './chat-completion-client';
|
|
3
|
+
export interface LLMTranslationProviderConfig {
|
|
4
|
+
client: ChatCompletionClient;
|
|
5
|
+
model: string;
|
|
6
|
+
fallbackModel?: string;
|
|
7
|
+
systemPrompt: string;
|
|
8
|
+
temperature: number;
|
|
9
|
+
maxTokens?: number;
|
|
10
|
+
maxRetries: number;
|
|
11
|
+
retryBaseDelayMs?: number;
|
|
12
|
+
retryMaxDelayMs?: number;
|
|
13
|
+
sleep?: (ms: number) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const createLLMTranslationProvider: (config: LLMTranslationProviderConfig) => TranslationProvider;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ProviderModel {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
}
|
|
5
|
+
export type ModelListFetch = (input: string, init?: {
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
ok: boolean;
|
|
10
|
+
status: number;
|
|
11
|
+
statusText: string;
|
|
12
|
+
json: () => Promise<unknown>;
|
|
13
|
+
}>;
|
|
14
|
+
export interface ModelListClientConfig {
|
|
15
|
+
apiKey: string;
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
fetch?: ModelListFetch;
|
|
18
|
+
}
|
|
19
|
+
export declare const listOpenAICompatibleModels: (config: ModelListClientConfig) => Promise<ProviderModel[]>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ChatCompletionClient } from './chat-completion-client';
|
|
2
|
+
export interface OpenAIChatCompletionClientConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const createOpenAIChatCompletionClient: (config: OpenAIChatCompletionClientConfig) => ChatCompletionClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Core } from '@strapi/strapi';
|
|
2
|
+
type Schema = Record<string, any>;
|
|
3
|
+
export declare const reconcileContentTypeSchema: (strapi: Core.Strapi, contentType: Schema, components?: Record<string, Schema>) => {
|
|
4
|
+
contentType: Schema;
|
|
5
|
+
components: Record<string, Schema>;
|
|
6
|
+
};
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Core } from '@strapi/strapi';
|
|
2
|
+
import { PublicTranslationConfig, TranslationConfig, TranslationConfigUpdateInput } from '../../domain/translation-config';
|
|
3
|
+
import { SecretCipher } from './secret-cipher';
|
|
4
|
+
export declare const PLUGIN_ID = "ai-translator";
|
|
5
|
+
type StrapiConfigRepositoryOptions = {
|
|
6
|
+
pluginId?: string;
|
|
7
|
+
storeKey?: string;
|
|
8
|
+
cipher?: SecretCipher;
|
|
9
|
+
};
|
|
10
|
+
export interface TranslationConfigRepository {
|
|
11
|
+
getConfig: () => Promise<TranslationConfig>;
|
|
12
|
+
getPublicConfig: () => Promise<PublicTranslationConfig>;
|
|
13
|
+
setEditableConfig: (input: TranslationConfigUpdateInput) => Promise<PublicTranslationConfig>;
|
|
14
|
+
}
|
|
15
|
+
export declare const createTranslationConfigRepository: (strapi: Core.Strapi, options?: StrapiConfigRepositoryOptions) => TranslationConfigRepository;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Core } from '@strapi/strapi';
|
|
2
|
+
import { TranslationProvider } from '../../application/translation-provider';
|
|
3
|
+
import { TranslationSessionEvent } from '../../domain/translation-event';
|
|
4
|
+
import { PublicTranslationConfig, TranslationConfigUpdateInput } from '../../domain/translation-config';
|
|
5
|
+
import { ChatCompletionClient } from '../llm/chat-completion-client';
|
|
6
|
+
import { LLMTranslationProviderConfig } from '../llm/llm-translation-provider';
|
|
7
|
+
import { OpenAIChatCompletionClientConfig } from '../llm/openai-chat-completion-client';
|
|
8
|
+
import { ModelListClientConfig, ProviderModel } from '../llm/model-list-client';
|
|
9
|
+
import { TranslationConfigRepository } from './translation-config-repository';
|
|
10
|
+
type Schema = Record<string, any>;
|
|
11
|
+
export interface TranslationSessionInput {
|
|
12
|
+
contentType: Schema;
|
|
13
|
+
entry: Record<string, any>;
|
|
14
|
+
components?: Record<string, Schema>;
|
|
15
|
+
sourceLocale?: string;
|
|
16
|
+
targetLocale: string;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
include?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface ListModelsDraftCredentials {
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface TranslationSessionService {
|
|
25
|
+
getConfig: () => Promise<PublicTranslationConfig>;
|
|
26
|
+
updateConfig: (input: TranslationConfigUpdateInput) => Promise<PublicTranslationConfig>;
|
|
27
|
+
listModels: (draft?: ListModelsDraftCredentials) => Promise<ProviderModel[]>;
|
|
28
|
+
createTranslationStream: (input: TranslationSessionInput) => AsyncGenerator<TranslationSessionEvent>;
|
|
29
|
+
}
|
|
30
|
+
interface TranslationSessionServiceDependencies {
|
|
31
|
+
configRepository?: TranslationConfigRepository;
|
|
32
|
+
createChatClient?: (config: OpenAIChatCompletionClientConfig) => ChatCompletionClient;
|
|
33
|
+
createTranslationProvider?: (config: LLMTranslationProviderConfig) => TranslationProvider;
|
|
34
|
+
listModels?: (config: ModelListClientConfig) => Promise<ProviderModel[]>;
|
|
35
|
+
}
|
|
36
|
+
export declare const createTranslationSessionService: (strapi: Core.Strapi, dependencies?: TranslationSessionServiceDependencies) => TranslationSessionService;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
admin: {
|
|
3
|
+
type: string;
|
|
4
|
+
routes: {
|
|
5
|
+
method: string;
|
|
6
|
+
path: string;
|
|
7
|
+
handler: string;
|
|
8
|
+
config: {
|
|
9
|
+
policies: {
|
|
10
|
+
name: string;
|
|
11
|
+
config: {
|
|
12
|
+
actions: string[];
|
|
13
|
+
};
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@strapi-ai/translator",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "AI translation workflow plugin for Strapi",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"strapi",
|
|
7
|
+
"plugin",
|
|
8
|
+
"translation",
|
|
9
|
+
"ai",
|
|
10
|
+
"llm"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "brighill (https://github.com/brighill)",
|
|
14
|
+
"homepage": "https://github.com/strapi-ai/translator#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/strapi-ai/translator.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/strapi-ai/translator/issues"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20.0.0 <=24.x.x"
|
|
24
|
+
},
|
|
25
|
+
"type": "commonjs",
|
|
26
|
+
"exports": {
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
"./strapi-admin": {
|
|
29
|
+
"types": "./dist/admin/src/index.d.ts",
|
|
30
|
+
"source": "./admin/src/index.ts",
|
|
31
|
+
"import": "./dist/admin/index.mjs",
|
|
32
|
+
"require": "./dist/admin/index.js",
|
|
33
|
+
"default": "./dist/admin/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./strapi-server": {
|
|
36
|
+
"types": "./dist/server/src/index.d.ts",
|
|
37
|
+
"source": "./server/src/index.ts",
|
|
38
|
+
"import": "./dist/server/index.mjs",
|
|
39
|
+
"require": "./dist/server/index.js",
|
|
40
|
+
"default": "./dist/server/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "strapi-plugin build",
|
|
48
|
+
"watch": "strapi-plugin watch",
|
|
49
|
+
"check": "tsc --noEmit -p server/tsconfig.json && tsc --noEmit -p admin/tsconfig.json",
|
|
50
|
+
"verify": "strapi-plugin verify"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"openai": "^6.46.0",
|
|
54
|
+
"react-intl": "^7.1.11"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@strapi/design-system": "^2.2.2",
|
|
58
|
+
"@strapi/icons": "^2.2.2",
|
|
59
|
+
"@strapi/sdk-plugin": "^6.1.1",
|
|
60
|
+
"@strapi/strapi": "^5.50.1",
|
|
61
|
+
"@strapi/typescript-utils": "^5.50.1",
|
|
62
|
+
"@strapi/utils": "^5.50.1",
|
|
63
|
+
"@types/react": "^18.3.31",
|
|
64
|
+
"@types/react-dom": "^18.3.7",
|
|
65
|
+
"react": "^18.3.1",
|
|
66
|
+
"react-dom": "^18.3.1",
|
|
67
|
+
"react-router-dom": "^6.30.0",
|
|
68
|
+
"styled-components": "^6.4.3",
|
|
69
|
+
"typescript": "^5.9.3"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"@strapi/design-system": "^2.0.0",
|
|
73
|
+
"@strapi/icons": "^2.0.0",
|
|
74
|
+
"@strapi/strapi": ">=5.12.3 <6.0.0",
|
|
75
|
+
"@strapi/utils": ">=5.12.3 <6.0.0",
|
|
76
|
+
"react": "^18.3.1",
|
|
77
|
+
"react-dom": "^18.3.1",
|
|
78
|
+
"react-router-dom": "^6.30.0",
|
|
79
|
+
"styled-components": "^6.1.17"
|
|
80
|
+
},
|
|
81
|
+
"strapi": {
|
|
82
|
+
"kind": "plugin",
|
|
83
|
+
"name": "ai-translator",
|
|
84
|
+
"displayName": "AI Translator",
|
|
85
|
+
"description": "Translate localized content with any OpenAI-compatible model, with streaming review before apply"
|
|
86
|
+
}
|
|
87
|
+
}
|