-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.ts
More file actions
172 lines (140 loc) · 5.07 KB
/
Copy pathconstants.ts
File metadata and controls
172 lines (140 loc) · 5.07 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Centralized constants for the Prompsit CLI (TypeScript port).
// Single source of truth for magic strings, numbers, and enum-like objects.
// --- Job lifecycle statuses ---
export const JobStatus = {
PENDING: "pending",
RUNNING: "running",
PROCESSING: "processing",
COMPLETED: "completed",
FAILED: "failed",
CANCELLED: "cancelled",
DLQ: "dlq",
} as const;
export type JobStatus = (typeof JobStatus)[keyof typeof JobStatus];
// --- Health check statuses ---
export const HealthStatus = {
OK: "ok",
HEALTHY: "healthy",
ERROR: "error",
UNREACHABLE: "unreachable",
DEGRADED: "degraded",
} as const;
export type HealthStatus = (typeof HealthStatus)[keyof typeof HealthStatus];
// --- SSE event type discriminators ---
export const SSEEventType = {
CONNECTED: "connected",
PROGRESS: "progress",
COMPLETE: "complete",
ERROR: "error",
CANCELLED: "cancelled",
PING: "ping",
} as const;
export type SSEEventType = (typeof SSEEventType)[keyof typeof SSEEventType];
// --- OAuth2 grant types ---
export const GrantType = {
PASSWORD: "password",
REFRESH_TOKEN: "refresh_token",
DEVICE_CODE: "urn:ietf:params:oauth:grant-type:device_code",
} as const;
export type GrantType = (typeof GrantType)[keyof typeof GrantType];
// --- HTTP status codes used in error classification ---
export const HttpStatus = {
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
UNPROCESSABLE: 422,
RATE_LIMITED: 429,
INTERNAL_ERROR: 500,
BAD_GATEWAY: 502,
SERVICE_UNAVAILABLE: 503,
GATEWAY_TIMEOUT: 504,
} as const;
export type HttpStatus = (typeof HttpStatus)[keyof typeof HttpStatus];
/** HTTP status codes that trigger automatic retry in got. */
export const RETRYABLE_STATUS_CODES = [
HttpStatus.RATE_LIMITED,
HttpStatus.INTERNAL_ERROR,
HttpStatus.BAD_GATEWAY,
HttpStatus.SERVICE_UNAVAILABLE,
HttpStatus.GATEWAY_TIMEOUT,
] as const;
// --- API endpoint paths ---
export const Endpoint = {
AUTH_TOKEN: "/v1/auth/token",
AUTH_DEVICE: "/v1/auth/device",
AUTH_DEVICE_TOKEN: "/v1/auth/device/token",
AUTH_SECRET: "/v1/auth/secret",
HEALTH: "/health",
LANGUAGES: "/v1/translation/languages",
TRANSLATE: "/v1/translation",
EVALUATE: "/v1/quality/score",
DOCUMENT_TRANSLATE: "/v1/translation/document",
JOB: "/v1/jobs/{job_id}",
JOB_SSE_EVENTS: "/v1/jobs/{job_id}/events",
DOCUMENT_FORMATS: "/v1/translation/document/formats",
QE_FORMATS: "/v1/quality/score/formats",
EVALUATE_FILE: "/v1/quality/score/file",
EVALUATE_TAGS: "/v1/quality/tags",
DATA_SCORE_FORMATS: "/v1/data/score/formats",
DATA_SCORE_LANGUAGES: "/v1/data/score/languages",
DATA_ANNOTATE_FORMATS: "/v1/data/annotate/formats",
DATA_ANNOTATE: "/v1/data/annotate",
DATA_SCORE: "/v1/data/score",
USER_USAGE: "/v1/user/usage",
// Translation Memory
TM: "/v1/translation/memory",
TM_IMPORT: "/v1/translation/memory/import",
TM_SEGMENTS: "/v1/translation/memory/segments",
TM_SEARCH: "/v1/translation/memory/search",
} as const;
export type Endpoint = (typeof Endpoint)[keyof typeof Endpoint];
// --- Auth / HTTP headers ---
export const HEADER_AUTHORIZATION = "Authorization";
export const BEARER_PREFIX = "Bearer";
export const HEADER_ACCEPT = "Accept";
export const CONTENT_TYPE_SSE = "text/event-stream";
// --- Numeric constants ---
// GIT_INSTALL_URL intentionally excluded — contains embedded deploy token (OWASP)
export const SSE_RETRY_ATTEMPTS = 3;
export const DEFAULT_POLL_INTERVAL = 5; // seconds
export const MAX_POLL_INTERVAL = 30; // seconds
// --- Device Flow (RFC 8628) ---
export const DEVICE_FLOW_DEFAULT_INTERVAL = 5; // seconds (RFC 8628 §3.2 default)
export const SSE_HEARTBEAT_TIMEOUT = 30; // seconds (2x server heartbeat interval)
// --- Data processing validation ---
/** Valid annotation pipeline stages (POST /v1/data/annotate). */
export const VALID_PIPELINE_STAGES = new Set([
"lid",
"pii",
"monofixer",
"docscorer",
"adult_filter",
"dedup",
]);
/** Valid LID model identifiers. */
export const VALID_LID_MODELS = new Set(["openlid-v2", "nllb", "openlid-v3"]);
/** Default LID model when --lid-model is not specified. */
export const DEFAULT_LID_MODEL = "openlid-v3";
/** Valid source languages for Bicleaner scoring (POST /v1/data/score). */
export const VALID_SCORING_LANGUAGES = new Set(["en", "de", "es"]);
// --- Quality score thresholds ---
export const QE_THRESHOLD_GOOD = 0.8;
export const QE_THRESHOLD_FAIR = 0.5;
export const BLEU_THRESHOLD_EXCELLENT = 40;
export const BLEU_THRESHOLD_GOOD = 25;
export const METRICX_THRESHOLD_EXCELLENT = 5; // lower = better
export const METRICX_THRESHOLD_GOOD = 10;
export const CHRF_THRESHOLD_EXCELLENT = 60;
export const CHRF_THRESHOLD_GOOD = 40;
// --- Translation Memory thresholds ---
export const TM_SEARCH_THRESHOLD = 0.7;
export const TM_DEFAULT_SEARCH_LIMIT = 10;
export const TM_DEFAULT_PAGE_SIZE = 50;
export const TM_SIMILARITY_GOOD = 0.9;
// --- File permissions ---
/** Owner read/write only (0o600). Used for credentials, config, logs. */
export const FILE_MODE_OWNER_RW = 0o600;
// --- SSE backoff ---
export const SSE_BACKOFF_MAX_MS = 4000;
export const SSE_BACKOFF_JITTER_MS = 500;
// --- Defaults ---