@l10nmonster/helpers-anthropic 3.0.0-alpha.9 → 3.1.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/CHANGELOG.md +35 -0
- package/anthropicAgent.js +17 -7
- package/package.json +21 -20
- package/tsconfig.json +18 -0
- package/.releaserc.json +0 -31
- package/example.js +0 -65
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
## @l10nmonster/helpers-anthropic [3.1.1](https://public-github/l10nmonster/l10nmonster/compare/@l10nmonster/helpers-anthropic@3.1.0...@l10nmonster/helpers-anthropic@3.1.1) (2025-12-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Improve type definitions and checks ([826b412](https://public-github/l10nmonster/l10nmonster/commit/826b412f0f7e761d404165a243b0c2b26c416ac1))
|
|
7
|
+
|
|
8
|
+
## @l10nmonster/helpers-anthropic [3.1.1](https://public-github/l10nmonster/l10nmonster/compare/@l10nmonster/helpers-anthropic@3.1.0...@l10nmonster/helpers-anthropic@3.1.1) (2025-12-23)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* Improve type definitions and checks ([826b412](https://public-github/l10nmonster/l10nmonster/commit/826b412f0f7e761d404165a243b0c2b26c416ac1))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Dependencies
|
|
20
|
+
|
|
21
|
+
* **@l10nmonster/core:** upgraded to 3.1.1
|
|
22
|
+
|
|
23
|
+
# @l10nmonster/helpers-anthropic [3.1.0](https://public-github/l10nmonster/l10nmonster/compare/@l10nmonster/helpers-anthropic@3.0.0...@l10nmonster/helpers-anthropic@3.1.0) (2025-12-20)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* Add support for async functions for secrets ([5d9d0a9](https://public-github/l10nmonster/l10nmonster/commit/5d9d0a99f45e1f4f16a30a634bea4259b106d74a))
|
|
29
|
+
* **server:** Fix cart cleanup ([9bbcab9](https://public-github/l10nmonster/l10nmonster/commit/9bbcab93e1fd20aeb09f59c828665159f091f37c))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* **providers:** Support promises for secrets ([3ac66dc](https://public-github/l10nmonster/l10nmonster/commit/3ac66dc13761f671a85f7f3b3df0539d021366dd))
|
|
35
|
+
|
|
1
36
|
# Changelog
|
|
2
37
|
|
|
3
38
|
All notable changes to this project will be documented in this file.
|
package/anthropicAgent.js
CHANGED
|
@@ -2,7 +2,7 @@ import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
|
|
|
2
2
|
import Anthropic from '@anthropic-ai/sdk';
|
|
3
3
|
import { GoogleAuth } from 'google-auth-library';
|
|
4
4
|
|
|
5
|
-
import { logInfo, logWarn, providers, styleString } from '
|
|
5
|
+
import { logInfo, logWarn, providers, styleString } from '@l10nmonster/core';
|
|
6
6
|
|
|
7
7
|
const TRANSLATION_TOOL = {
|
|
8
8
|
name: 'provide_translations',
|
|
@@ -29,11 +29,11 @@ const TRANSLATION_TOOL = {
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @typedef {object} AnthropicAgentOptions
|
|
32
|
-
* @extends LLMTranslationProviderOptions
|
|
33
32
|
* @property {Promise<string>|string} [apiKey] - The Anthropic API key (if using direct API).
|
|
34
33
|
* @property {string} [vertexProject] - The VertexAI project ID.
|
|
35
34
|
* @property {string} [vertexLocation] - The VertexAI datacenter location.
|
|
36
35
|
* @property {number} [maxTokens] - Maximum number of output tokens (32000 by default)
|
|
36
|
+
* @property {number} [maxRetries] - Maximum number of retries (2 by default)
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -52,6 +52,7 @@ export class AnthropicAgent extends providers.LLMTranslationProvider {
|
|
|
52
52
|
* @param {AnthropicAgentOptions} options - Configuration options for the provider.
|
|
53
53
|
*/
|
|
54
54
|
constructor({ apiKey, vertexProject, vertexLocation, maxTokens, maxRetries, ...options }) {
|
|
55
|
+
// @ts-ignore - spread loses type info but parent class handles validation
|
|
55
56
|
super({...options, maxRetries: 0}); // bypass our own retry logic since Anthropic SDK has built-in support
|
|
56
57
|
this.#apiKey = apiKey;
|
|
57
58
|
this.#vertexProject = vertexProject;
|
|
@@ -68,8 +69,10 @@ export class AnthropicAgent extends providers.LLMTranslationProvider {
|
|
|
68
69
|
}
|
|
69
70
|
if (this.#apiKey) {
|
|
70
71
|
// Direct Anthropic API
|
|
72
|
+
// @ts-ignore - apiKey can be a function or value, TypeScript doesn't narrow correctly
|
|
73
|
+
const resolvedKey = await (typeof this.#apiKey === 'function' ? this.#apiKey() : this.#apiKey);
|
|
71
74
|
this.#client = new Anthropic({
|
|
72
|
-
apiKey:
|
|
75
|
+
apiKey: resolvedKey,
|
|
73
76
|
maxRetries: this.#maxRetries,
|
|
74
77
|
timeout: 15 * 60000, // 15 minutes
|
|
75
78
|
});
|
|
@@ -93,7 +96,7 @@ export class AnthropicAgent extends providers.LLMTranslationProvider {
|
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
prepareTranslateChunkArgs({ sourceLang, targetLang, xmlTus, instructions }) {
|
|
99
|
+
prepareTranslateChunkArgs({ sourceLang, targetLang, xmlTus, jobGuid, chunkNumber, instructions }) {
|
|
97
100
|
const userPrompt = this.buildUserPrompt({ sourceLang, targetLang, xmlTus, instructions });
|
|
98
101
|
|
|
99
102
|
const messages = [
|
|
@@ -103,7 +106,8 @@ export class AnthropicAgent extends providers.LLMTranslationProvider {
|
|
|
103
106
|
}
|
|
104
107
|
];
|
|
105
108
|
|
|
106
|
-
const toolConfig = this.customSchema ?
|
|
109
|
+
const toolConfig = this.customSchema ?
|
|
110
|
+
{
|
|
107
111
|
tools: [{
|
|
108
112
|
name: 'provide_custom_translations',
|
|
109
113
|
description: 'Provide translations using custom schema',
|
|
@@ -119,7 +123,8 @@ export class AnthropicAgent extends providers.LLMTranslationProvider {
|
|
|
119
123
|
}
|
|
120
124
|
}],
|
|
121
125
|
tool_choice: { type: 'tool', name: 'provide_custom_translations' }
|
|
122
|
-
} :
|
|
126
|
+
} :
|
|
127
|
+
{
|
|
123
128
|
tools: [TRANSLATION_TOOL],
|
|
124
129
|
tool_choice: { type: 'tool', name: 'provide_translations' }
|
|
125
130
|
};
|
|
@@ -130,7 +135,12 @@ export class AnthropicAgent extends providers.LLMTranslationProvider {
|
|
|
130
135
|
temperature: this.temperature,
|
|
131
136
|
system: this.systemPrompt,
|
|
132
137
|
messages,
|
|
133
|
-
...toolConfig
|
|
138
|
+
...toolConfig,
|
|
139
|
+
sourceLang,
|
|
140
|
+
targetLang,
|
|
141
|
+
xmlTus,
|
|
142
|
+
jobGuid,
|
|
143
|
+
chunkNumber,
|
|
134
144
|
};
|
|
135
145
|
}
|
|
136
146
|
|
package/package.json
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
"name": "@l10nmonster/helpers-anthropic",
|
|
3
|
+
"version": "3.1.1",
|
|
4
|
+
"description": "Anthropic Claude LLM provider for l10nmonster using Vertex AI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "anthropicAgent.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node --test",
|
|
9
|
+
"typecheck": "tsc --noEmit"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@anthropic-ai/vertex-sdk": "latest",
|
|
13
|
+
"@anthropic-ai/sdk": "latest",
|
|
14
|
+
"google-auth-library": "^10"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@l10nmonster/core": "3.1.1"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.11.0"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT"
|
|
22
23
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig.base.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"*.js",
|
|
5
|
+
"**/*.js"
|
|
6
|
+
],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"node_modules",
|
|
9
|
+
"**/node_modules",
|
|
10
|
+
"test/**",
|
|
11
|
+
"tests/**",
|
|
12
|
+
"**/*.test.js",
|
|
13
|
+
"**/*.spec.js",
|
|
14
|
+
"dist/**",
|
|
15
|
+
"ui/**",
|
|
16
|
+
"types/**"
|
|
17
|
+
]
|
|
18
|
+
}
|
package/.releaserc.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"branches": [
|
|
3
|
-
"main",
|
|
4
|
-
{
|
|
5
|
-
"name": "next",
|
|
6
|
-
"prerelease": "alpha"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"name": "beta",
|
|
10
|
-
"prerelease": "beta"
|
|
11
|
-
}
|
|
12
|
-
],
|
|
13
|
-
"tagFormat": "@l10nmonster/helpers-anthropic@${version}",
|
|
14
|
-
"plugins": [
|
|
15
|
-
"@semantic-release/commit-analyzer",
|
|
16
|
-
"@semantic-release/release-notes-generator",
|
|
17
|
-
{
|
|
18
|
-
"path": "@semantic-release/changelog",
|
|
19
|
-
"changelogFile": "CHANGELOG.md"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"path": "@semantic-release/npm",
|
|
23
|
-
"npmPublish": true
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"path": "@semantic-release/git",
|
|
27
|
-
"assets": ["CHANGELOG.md", "package.json"],
|
|
28
|
-
"message": "chore(release): @l10nmonster/helpers-anthropic@${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
package/example.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { AnthropicAgent } from './index.js';
|
|
2
|
-
|
|
3
|
-
// Example L10nMonster configuration using AnthropicAgent
|
|
4
|
-
export const exampleConfig = {
|
|
5
|
-
translationProviders: [
|
|
6
|
-
// Direct API configuration
|
|
7
|
-
{
|
|
8
|
-
id: 'claude-direct-api',
|
|
9
|
-
provider: AnthropicAgent,
|
|
10
|
-
options: {
|
|
11
|
-
model: 'claude-3-5-sonnet-latest',
|
|
12
|
-
quality: 90,
|
|
13
|
-
temperature: 0.1,
|
|
14
|
-
maxTokens: 4096,
|
|
15
|
-
maxRetries: 3, // Passed to Anthropic SDK for native retry handling
|
|
16
|
-
apiKey: process.env.ANTHROPIC_API_KEY, // Set your API key
|
|
17
|
-
persona: 'You are a professional translator specializing in technical documentation and user interfaces.',
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
// Vertex AI configuration
|
|
21
|
-
{
|
|
22
|
-
id: 'claude-vertex-sonnet',
|
|
23
|
-
provider: AnthropicAgent,
|
|
24
|
-
options: {
|
|
25
|
-
model: 'claude-3-5-sonnet@20241022',
|
|
26
|
-
quality: 85,
|
|
27
|
-
temperature: 0.1,
|
|
28
|
-
maxTokens: 4096,
|
|
29
|
-
// vertexProject: 'your-gcp-project-id', // Optional, auto-detected
|
|
30
|
-
vertexLocation: 'us-central1',
|
|
31
|
-
persona: 'You are a professional translator specializing in technical documentation and user interfaces.',
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
id: 'claude-vertex-haiku',
|
|
36
|
-
provider: AnthropicAgent,
|
|
37
|
-
options: {
|
|
38
|
-
model: 'claude-3-5-haiku@20241022',
|
|
39
|
-
quality: 80,
|
|
40
|
-
temperature: 0.1,
|
|
41
|
-
maxTokens: 2048,
|
|
42
|
-
vertexLocation: 'us-central1',
|
|
43
|
-
persona: 'You are a fast and efficient translator focused on accuracy and consistency.',
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
|
|
48
|
-
// Example translation jobs configuration
|
|
49
|
-
jobs: [
|
|
50
|
-
{
|
|
51
|
-
id: 'ui-translation',
|
|
52
|
-
translationProvider: 'claude-direct-api',
|
|
53
|
-
instructions: 'Translate user interface strings. Keep labels concise and maintain consistent terminology.',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
id: 'content-translation',
|
|
57
|
-
translationProvider: 'claude-vertex-haiku',
|
|
58
|
-
instructions: 'Translate general content while maintaining the original tone and style.',
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// Example usage
|
|
64
|
-
console.log('AnthropicAgent configuration example loaded');
|
|
65
|
-
console.log('Available providers:', exampleConfig.translationProviders.map(p => p.id));
|