diff options
Diffstat (limited to 'src/shared/constants.js')
| -rw-r--r-- | src/shared/constants.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/shared/constants.js b/src/shared/constants.js new file mode 100644 index 0000000..76a679c --- /dev/null +++ b/src/shared/constants.js @@ -0,0 +1,71 @@ +/** + * Shared constants for the extension. + * + * NOTE: This module is loaded by ES module contexts (background / popup / + * options / tests). The content script is a classic script and duplicates the + * small subset it needs (see src/content/content.js). The unit tests assert + * that the duplicated constants stay in sync. + */ + +export const PORT_NAME = 'translation-stream'; + +/** Maximum accepted selection length (characters). */ +export const MAX_SELECTION_LENGTH = 20000; + +/** Maximum length of the user-defined system prompt. */ +export const MAX_USER_SYSTEM_PROMPT_LENGTH = 2000; + +/** Context length presets (fixed values only). */ +export const CONTEXT_PRESETS = [4096, 8192, 16384, 32768, 131072, 262144]; + +/** Supported target languages. */ +export const LANGUAGES = [ + { code: 'ja', label: '日本語' }, + { code: 'en', label: 'English' }, + { code: 'zh-CN', label: '简体中文' }, + { code: 'zh-TW', label: '繁體中文' }, + { code: 'ko', label: '한국어' }, + { code: 'fr', label: 'Français' }, + { code: 'de', label: 'Deutsch' }, + { code: 'es', label: 'Español' }, + { code: 'pt', label: 'Português' }, + { code: 'ru', label: 'Русский' } +]; + +/** Thinking mode values accepted by the settings UI. */ +export const THINKING_MODES = ['off', 'on', 'low', 'medium', 'high']; + +/** Default Ollama endpoint. */ +export const DEFAULT_OLLAMA_HOST = 'http://localhost:11434'; + +/** Error codes exchanged between background and content script. */ +export const ERROR_CODES = { + INVALID_REQUEST: 'INVALID_REQUEST', + TEXT_EMPTY: 'TEXT_EMPTY', + TEXT_TOO_LONG: 'TEXT_TOO_LONG', + OLLAMA_UNAVAILABLE: 'OLLAMA_UNAVAILABLE', + MODEL_NOT_FOUND: 'MODEL_NOT_FOUND', + INVALID_SETTINGS: 'INVALID_SETTINGS', + REQUEST_ABORTED: 'REQUEST_ABORTED', + STREAM_ERROR: 'STREAM_ERROR', + UNKNOWN_ERROR: 'UNKNOWN_ERROR' +}; + +/** Message types: content -> background (via runtime.Port). */ +export const CONTENT_TO_BG = { + TRANSLATE: 'translate', + CANCEL: 'cancel' +}; + +/** Message types: background -> content (via runtime.Port). */ +export const BG_TO_CONTENT = { + STARTED: 'started', + CHUNK: 'chunk', + COMPLETED: 'completed', + ERROR: 'error' +}; + +/** Message types: one-shot runtime messages (popup/options -> background). */ +export const RUNTIME_MESSAGES = { + LIST_MODELS: 'listModels' +};
\ No newline at end of file |
