@molecule/api-ai-translation-deepl 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/README.md +173 -0
- package/package.json +11 -5
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T01:47:39.595Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/api-ai-translation-deepl
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
DeepL translation provider for molecule.dev.
|
|
16
|
+
|
|
17
|
+
Implements the full `@molecule/api-ai-translation` contract (`translate`,
|
|
18
|
+
`getSupportedLanguages`, `getUsage`) over the DeepL REST API, auto-batching
|
|
19
|
+
large inputs (50 texts per request, DeepL's limit).
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { setProvider, requireProvider } from '@molecule/api-ai-translation'
|
|
25
|
+
import { provider } from '@molecule/api-ai-translation-deepl'
|
|
26
|
+
|
|
27
|
+
setProvider(provider) // at startup — lazy; reads DEEPL_API_KEY on first use
|
|
28
|
+
|
|
29
|
+
const { translations } = await requireProvider().translate({
|
|
30
|
+
text: 'Hello, world!',
|
|
31
|
+
targetLang: 'DE',
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Type
|
|
36
|
+
|
|
37
|
+
`provider`
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @molecule/api-ai-translation-deepl @molecule/api-ai-translation @molecule/api-secrets
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### Interfaces
|
|
48
|
+
|
|
49
|
+
#### `DeeplConfig`
|
|
50
|
+
|
|
51
|
+
Configuration for the DeepL translation provider.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
interface DeeplConfig {
|
|
55
|
+
/** DeepL API key. Defaults to DEEPL_API_KEY env var. */
|
|
56
|
+
apiKey?: string
|
|
57
|
+
/**
|
|
58
|
+
* Base URL for the DeepL API.
|
|
59
|
+
* Defaults to 'https://api-free.deepl.com' for free keys (ending in ':fx'),
|
|
60
|
+
* or 'https://api.deepl.com' for pro keys.
|
|
61
|
+
*/
|
|
62
|
+
baseUrl?: string
|
|
63
|
+
/** Default formality preference. Defaults to 'default'. */
|
|
64
|
+
defaultFormality?: 'default' | 'more' | 'less' | 'prefer_more' | 'prefer_less'
|
|
65
|
+
/** Default model type preference. Defaults to 'latency_optimized'. */
|
|
66
|
+
defaultModelType?: 'quality_optimized' | 'prefer_quality_optimized' | 'latency_optimized'
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Functions
|
|
71
|
+
|
|
72
|
+
#### `createProvider(config)`
|
|
73
|
+
|
|
74
|
+
Creates a DeepL translation provider instance.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
function createProvider(config?: DeeplConfig): AITranslationProvider
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- `config` — DeepL-specific configuration (API key, base URL, defaults).
|
|
81
|
+
|
|
82
|
+
**Returns:** An `AITranslationProvider` backed by the DeepL REST API.
|
|
83
|
+
|
|
84
|
+
### Constants
|
|
85
|
+
|
|
86
|
+
#### `aiTranslationDeeplSecretDefinitions`
|
|
87
|
+
|
|
88
|
+
Secret definitions required by the DeepL translation bond.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
const aiTranslationDeeplSecretDefinitions: SecretDefinition[]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### `provider`
|
|
95
|
+
|
|
96
|
+
The provider implementation.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
const provider: AITranslationProvider
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Core Interface
|
|
103
|
+
|
|
104
|
+
Implements `@molecule/api-ai-translation` interface.
|
|
105
|
+
|
|
106
|
+
## Bond Wiring
|
|
107
|
+
|
|
108
|
+
Setup function to register this provider with the core interface:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { setProvider } from '@molecule/api-ai-translation'
|
|
112
|
+
import { provider } from '@molecule/api-ai-translation-deepl'
|
|
113
|
+
|
|
114
|
+
export function setupAiTranslationDeepl(): void {
|
|
115
|
+
setProvider(provider)
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Injection Notes
|
|
120
|
+
|
|
121
|
+
### Requirements
|
|
122
|
+
|
|
123
|
+
Peer dependencies:
|
|
124
|
+
|
|
125
|
+
- `@molecule/api-ai-translation` >=1.0.1
|
|
126
|
+
- `@molecule/api-secrets` ^1.0.1
|
|
127
|
+
|
|
128
|
+
### Environment Variables
|
|
129
|
+
|
|
130
|
+
- `DEEPL_API_KEY` _(required)_ — DeepL API key
|
|
131
|
+
- Setup: Copy the authentication key from your DeepL account (free keys end with ":fx").
|
|
132
|
+
- Get it here: [https://www.deepl.com/en/your-account/keys](https://www.deepl.com/en/your-account/keys)
|
|
133
|
+
- Example: `279a2e9d-...:fx`
|
|
134
|
+
|
|
135
|
+
### Runtime Dependencies
|
|
136
|
+
|
|
137
|
+
- `@molecule/api-ai-translation`
|
|
138
|
+
- `@molecule/api-secrets`
|
|
139
|
+
|
|
140
|
+
- **Wiring**: bond the lazy `provider` export once — `setProvider(provider)` — or
|
|
141
|
+
`setProvider(createProvider(config?))` to pass explicit config. Use the core's
|
|
142
|
+
`setProvider`, NOT `bond('ai-translation', …)`.
|
|
143
|
+
- Config: `DEEPL_API_KEY` (required; free keys end in `:fx` and auto-route to
|
|
144
|
+
`https://api-free.deepl.com`, pro keys to `https://api.deepl.com`); `DEEPL_BASE_URL`
|
|
145
|
+
(optional) overrides the endpoint outright — it deliberately wins over the key-shape
|
|
146
|
+
heuristic so credential brokers/gateways work with either key type.
|
|
147
|
+
|
|
148
|
+
## E2E Tests
|
|
149
|
+
|
|
150
|
+
Integration checklist — drive the real UI (live preview, no mocks), adapt
|
|
151
|
+
each item to this app's actual screens/flows, and check every box off one
|
|
152
|
+
by one. A box you can't check is an integration bug to fix — not a skip.
|
|
153
|
+
The sandbox has a live AI provider, so translations run for real; output is
|
|
154
|
+
non-deterministic, so assert on the resulting LANGUAGE/meaning, never an
|
|
155
|
+
exact string:
|
|
156
|
+
|
|
157
|
+
- [ ] Translating real text to a target language through the UI returns text
|
|
158
|
+
ACTUALLY in that language — English→Spanish produces recognizably Spanish,
|
|
159
|
+
not the original echoed back or left in English.
|
|
160
|
+
- [ ] Switching the target language (from the picker populated by
|
|
161
|
+
getSupportedLanguages('target')) changes the output language for the same
|
|
162
|
+
input — the same source re-translates into the newly chosen language.
|
|
163
|
+
- [ ] With sourceLang omitted the provider auto-detects: a known-language
|
|
164
|
+
input comes back with the correct detectedSourceLang, and if the UI shows
|
|
165
|
+
a detected-language label it names the right one.
|
|
166
|
+
- [ ] Text already in the target language is left sensible — unchanged or a
|
|
167
|
+
valid paraphrase, never mangled, doubled, or emptied.
|
|
168
|
+
- [ ] Empty or untranslatable input (whitespace, emoji, a bare code snippet)
|
|
169
|
+
is handled gracefully — a clear UI state, nothing crashes.
|
|
170
|
+
- [ ] A provider failure (bad key, quota exhausted, network drop) surfaces a
|
|
171
|
+
visible error in the UI, not an unhandled 500 or a silently blank result.
|
|
172
|
+
- [ ] The translate call runs server-side only — the provider key never
|
|
173
|
+
reaches the browser (check the network panel: no key in any request).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-ai-translation-deepl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "DeepL translation provider for molecule.dev — text translation via DeepL API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"keywords": [
|
|
23
24
|
"molecule",
|
|
@@ -26,12 +27,17 @@
|
|
|
26
27
|
"deepl"
|
|
27
28
|
],
|
|
28
29
|
"license": "Apache-2.0",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
33
|
+
"directory": "packages/api/bonds/ai-translation/deepl"
|
|
34
|
+
},
|
|
29
35
|
"peerDependencies": {
|
|
30
|
-
"@molecule/api-ai-translation": ">=1.0.
|
|
31
|
-
"@molecule/api-secrets": "^1.0.
|
|
36
|
+
"@molecule/api-ai-translation": ">=1.0.1",
|
|
37
|
+
"@molecule/api-secrets": "^1.0.1"
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|
|
34
|
-
"@molecule/api-ai-translation": "1.0.
|
|
40
|
+
"@molecule/api-ai-translation": "1.0.1",
|
|
35
41
|
"@types/node": "26.1.2",
|
|
36
42
|
"typescript": "6.0.3",
|
|
37
43
|
"vitest": "4.1.10"
|