summaryrefslogtreecommitdiff
path: root/src/shared/constants.js
blob: adae26d6b82fb2a27435d349ab629f246d6feda9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * 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',
  GET_POPUP_STATE: 'getPopupState',
  START_CONTEXT_MENU_TRANSLATION: 'startContextMenuTranslation',
  REGENERATE_LAST: 'regenerateLast'
};

/** Context menu item id (menus API). */
export const MENU_ID_TRANSLATE_SELECTION = 'translate-selection';

/** Popup translation result statuses (Design.md §7.4). */
export const POPUP_STATUSES = {
  IDLE: 'idle',
  STARTING: 'starting',
  STREAMING: 'streaming',
  COMPLETED: 'completed',
  ERROR: 'error',
  CANCELLED: 'cancelled'
};