forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
473 lines (461 loc) Β· 18.5 KB
/
Copy pathvite.config.ts
File metadata and controls
473 lines (461 loc) Β· 18.5 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/// <reference types="vitest" />
/// <reference types="vite-plugin-svgr/client" />
import { fileURLToPath } from "node:url";
import { createRequire } from "node:module";
import { readFile } from "node:fs/promises";
import { resolve, dirname, relative, isAbsolute } from "node:path";
import { defineConfig, loadEnv } from "vite";
import svgr from "vite-plugin-svgr";
import { reactRouter } from "@react-router/dev/vite";
import { configDefaults } from "vitest/config";
import tailwindcss from "@tailwindcss/vite";
import prefixer from "postcss-prefix-selector";
import {
AGENT_SERVER_UI_SCOPE_SELECTOR,
transformAgentServerUISelector,
} from "./src/styles/agent-server-ui-style-scope";
const LIB_ENTRY = fileURLToPath(new URL("./src/index.ts", import.meta.url));
const LIB_EXTERNALS = [
"react",
"react-dom",
"react/jsx-runtime",
"react/jsx-dev-runtime",
"react-router",
];
const APP_CHUNK_MAX_BYTES = 450 * 1024;
const normalizeBasePath = (value?: string) => {
const raw = value?.trim();
if (!raw || raw === "/") return "/";
const withLeadingSlash = raw.startsWith("/") ? raw : `/${raw}`;
return `${withLeadingSlash.replace(/\/+$/, "")}/`;
};
// Absolute path to the bundled extensions skills directory in node_modules.
// Injected as __EXTENSIONS_SKILLS_DIR__ so agent-server-adapter.ts can pass
// real filesystem paths to the Python agent-server (which uses them to
// resolve bundled skill resources like scripts/ and references/).
const _require = createRequire(import.meta.url);
const EXTENSIONS_SKILLS_DIR = resolve(
dirname(_require.resolve("@openhands/extensions/package.json")),
"skills",
);
const PUBLIC_LOCALES_DIR = resolve(process.cwd(), "public", "locales");
const appBuildConfig = {
rolldownOptions: {
output: {
codeSplitting: {
groups: [
{
// Keep the styling core (HeroUI + tailwind-variants + its
// tailwind-merge/clsx deps) in one un-size-split chunk. When the
// generic size-split vendor group slices these apart, a HeroUI
// component's top-level `tv()` recipe can evaluate before
// tailwind-variants' core is initialized, throwing
// "TypeError: s is not a function" at module load and blanking the
// whole app (root-layout module fails to load β reload loop).
name: "vendor-styling",
test: /node_modules[\\/](@heroui[\\/]|tailwind-variants[\\/]|tailwind-merge[\\/]|clsx[\\/])/,
},
{
// Keep the markdown / syntax-highlight ecosystem
// (react-syntax-highlighter + refractor/lowlight/highlight.js and
// the unified/hast/mdast/micromark/vfile module tree it pulls in)
// in one un-size-split chunk. Same failure mode as vendor-styling
// above: once the file-viewer (HighlightedSourceView) is imported
// from a second route, the generic size-split vendor group slices
// this tree across chunk boundaries, so a vfile/unified module's
// interop `require` shim can evaluate before the chunk that defines
// it, throwing "TypeError: i is not a function" at module load and
// blanking the whole app (the shared home/conversation/files-tab
// chunk fails to load β route-module reload loop).
name: "vendor-markdown",
test: /node_modules[\\/](react-syntax-highlighter[\\/]|refractor[\\/]|lowlight[\\/]|highlight\.js[\\/]|hastscript[\\/]|(hast|mdast|unist|micromark|remark|rehype)[^\\/]*[\\/]|unified[\\/]|vfile[^\\/]*[\\/]|property-information[\\/]|(comma|space)-separated-tokens[\\/]|character-entities[^\\/]*[\\/]|(parse|stringify)-entities[\\/]|decode-named-character-reference[\\/]|bail[\\/]|trough[\\/]|is-plain-obj[\\/]|zwitch[\\/]|longest-streak[\\/]|ccount[\\/]|escape-string-regexp[\\/]|markdown-table[\\/]|devlop[\\/])/,
},
{
name: "vendor",
test: /node_modules[\\/]/,
maxSize: APP_CHUNK_MAX_BYTES,
minSize: 20 * 1024,
entriesAware: true,
},
],
},
},
},
};
export default defineConfig(({ mode }) => {
const {
VITE_BACKEND_HOST = "127.0.0.1:8000",
VITE_USE_TLS = "false",
VITE_FRONTEND_PORT = "3001",
VITE_INSECURE_SKIP_VERIFY = "false",
VITE_BASE_PATH,
// Runtime-services metadata for the dev server, passed by launchers that
// run the Vite dev server directly (e.g. dev:minimal). Unlike
// ingress/static-server, the Vite proxy cannot post-process the upstream
// /server_info response, so the launcher serializes the info here and the
// middleware below merges it into the proxied response.
VITE_RUNTIME_SERVICES_INFO,
} = loadEnv(mode, process.cwd());
const isLibraryBuild = process.env.BUILD_LIB === "true";
const USE_TLS = VITE_USE_TLS === "true";
const INSECURE_SKIP_VERIFY = VITE_INSECURE_SKIP_VERIFY === "true";
const PROTOCOL = USE_TLS ? "https" : "http";
const WS_PROTOCOL = USE_TLS ? "wss" : "ws";
const API_URL = `${PROTOCOL}://${VITE_BACKEND_HOST}/`;
const WS_URL = `${WS_PROTOCOL}://${VITE_BACKEND_HOST}/`;
const FE_PORT = Number.parseInt(VITE_FRONTEND_PORT, 10);
const base = normalizeBasePath(VITE_BASE_PATH);
return {
base,
define: {
// Empty string for library builds so consumers aren't bound to this
// machine's node_modules path; agent-server-adapter falls back to
// "public" when the value is falsy.
__EXTENSIONS_SKILLS_DIR__: JSON.stringify(
isLibraryBuild ? "" : EXTENSIONS_SKILLS_DIR,
),
},
plugins: [
{
name: "suppress-chrome-devtools-well-known",
apply: "serve",
configureServer(server) {
server.middlewares.use(
"/.well-known/appspecific/com.chrome.devtools.json",
(_req, res) => {
res.writeHead(204);
res.end();
},
);
},
},
{
name: "serve-generated-i18n-locales",
apply: "serve",
configureServer(server) {
server.middlewares.use(async (req, res, next) => {
const method = req.method ?? "GET";
if (method !== "GET" && method !== "HEAD") {
next();
return;
}
const pathname = new URL(req.url ?? "", "http://localhost")
.pathname;
if (
!pathname.startsWith("/locales/") ||
!pathname.endsWith(".json")
) {
next();
return;
}
const requestedPath = decodeURIComponent(
pathname.slice("/locales/".length),
);
const filePath = resolve(PUBLIC_LOCALES_DIR, requestedPath);
const relativePath = relative(PUBLIC_LOCALES_DIR, filePath);
if (relativePath.startsWith("..") || isAbsolute(relativePath)) {
res.writeHead(403);
res.end();
return;
}
try {
const content = await readFile(filePath);
res.writeHead(200, {
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "no-cache",
});
res.end(method === "HEAD" ? "" : content);
} catch {
next();
}
});
},
},
!process.env.VITEST && !isLibraryBuild && reactRouter(),
svgr(),
tailwindcss(),
],
resolve: {
tsconfigPaths: true,
},
css: {
postcss: {
plugins: [
prefixer({
prefix: AGENT_SERVER_UI_SCOPE_SELECTOR,
transform(
prefix: string,
selector: string,
prefixedSelector: string,
) {
return transformAgentServerUISelector(
prefix,
selector,
prefixedSelector,
);
},
}),
],
},
},
build: isLibraryBuild
? {
outDir: "dist",
emptyOutDir: true,
sourcemap: true,
lib: {
entry: LIB_ENTRY,
formats: ["es"],
},
rollupOptions: {
external: LIB_EXTERNALS,
output: [
{
format: "es",
preserveModules: true,
preserveModulesRoot: "src",
entryFileNames: "[name].js",
chunkFileNames: "chunks/[name]-[hash].js",
assetFileNames: "assets/[name]-[hash][extname]",
},
{
format: "cjs",
preserveModules: true,
preserveModulesRoot: "src",
entryFileNames: "[name].cjs",
chunkFileNames: "chunks/[name]-[hash].cjs",
assetFileNames: "assets/[name]-[hash][extname]",
exports: "named",
},
],
},
}
: appBuildConfig,
copyPublicDir: !isLibraryBuild,
optimizeDeps: {
// Disable discovery of new deps at runtime. All deps must be listed in
// `include`. This prevents Vite from returning 504s while optimizing
// newly-discovered deps - Safari doesn't retry like Chrome does.
noDiscovery: true,
include: [
// Pre-bundle client entry dependencies so the first page load does not 504
// with Vite's "Outdated Optimize Dep" before hydration finishes.
// Safari is particularly sensitive to runtime dep optimization - it gets
// stuck in 504 errors when Vite triggers "optimized dependencies changed. reloading"
"react",
"react/jsx-runtime",
"react-dom/client",
"react-router/dom",
// Pre-bundle ALL dependencies to prevent runtime optimization and page reloads
// These are discovered during initial app load:
"posthog-js",
"@tanstack/react-query",
"react-hot-toast",
"i18next",
"i18next-http-backend",
"i18next-browser-languagedetector",
"react-i18next",
"axios",
"@uidotdev/usehooks",
"react-icons/fa6",
"react-icons/fa",
"clsx",
"tailwind-merge",
// CJS dependencies used by react-transition-group. Without pre-bundling,
// Vite can serve them directly to the browser before route hydration.
"prop-types",
"react-is",
"@heroui/react",
"lucide-react",
"@microlink/react-json-view",
"socket.io-client",
// These are discovered when launching conversations:
"react-icons/vsc",
"react-icons/lu",
"react-icons/di",
"react-icons/io5",
"react-icons/io",
"@monaco-editor/react",
"react-textarea-autosize",
"react-markdown",
"remark-gfm",
"remark-breaks",
"react-syntax-highlighter",
"react-syntax-highlighter/dist/esm/styles/prism",
"react-syntax-highlighter/dist/esm/styles/hljs",
// Terminal dependencies - added to prevent runtime optimization
"@xterm/addon-fit",
"@xterm/xterm",
"@xterm/xterm/css/xterm.css",
// OpenHands typescript client
"@openhands/typescript-client",
"@openhands/typescript-client/client/http-client",
"@openhands/typescript-client/client/device-flow-client",
"@openhands/typescript-client/clients",
"@openhands/typescript-client/events/remote-events-list",
"@openhands/typescript-client/workspace/remote-workspace",
// Additional dependencies discovered at runtime
"class-variance-authority",
"downshift",
"framer-motion",
"rehype-raw",
"rehype-sanitize",
// ``shell-quote`` is a CJS module used by ``src/utils/acp-command.ts``
// for the Settings β Agent textarea. With ``noDiscovery: true`` above,
// omitting it from this list means Vite serves the raw CJS file to
// the browser and dev crashes with ``ReferenceError: exports is not
// defined`` on the first import of agent-settings.tsx.
"shell-quote",
"unist-util-visit",
"uuid",
"zustand",
"zustand/middleware",
// Syntax highlighter language definitions - Safari fails if these are
// optimized at runtime. Include all commonly used languages.
"react-syntax-highlighter/dist/esm/languages/prism/bash",
"react-syntax-highlighter/dist/esm/languages/prism/batch",
"react-syntax-highlighter/dist/esm/languages/prism/c",
"react-syntax-highlighter/dist/esm/languages/prism/clike",
"react-syntax-highlighter/dist/esm/languages/prism/clojure",
"react-syntax-highlighter/dist/esm/languages/prism/cpp",
"react-syntax-highlighter/dist/esm/languages/prism/csharp",
"react-syntax-highlighter/dist/esm/languages/prism/css",
"react-syntax-highlighter/dist/esm/languages/prism/dart",
"react-syntax-highlighter/dist/esm/languages/prism/diff",
"react-syntax-highlighter/dist/esm/languages/prism/docker",
"react-syntax-highlighter/dist/esm/languages/prism/elixir",
"react-syntax-highlighter/dist/esm/languages/prism/erlang",
"react-syntax-highlighter/dist/esm/languages/prism/fsharp",
"react-syntax-highlighter/dist/esm/languages/prism/go",
"react-syntax-highlighter/dist/esm/languages/prism/graphql",
"react-syntax-highlighter/dist/esm/languages/prism/groovy",
"react-syntax-highlighter/dist/esm/languages/prism/haskell",
"react-syntax-highlighter/dist/esm/languages/prism/hcl",
"react-syntax-highlighter/dist/esm/languages/prism/http",
"react-syntax-highlighter/dist/esm/languages/prism/ini",
"react-syntax-highlighter/dist/esm/languages/prism/java",
"react-syntax-highlighter/dist/esm/languages/prism/javascript",
"react-syntax-highlighter/dist/esm/languages/prism/json",
"react-syntax-highlighter/dist/esm/languages/prism/json5",
"react-syntax-highlighter/dist/esm/languages/prism/jsx",
"react-syntax-highlighter/dist/esm/languages/prism/julia",
"react-syntax-highlighter/dist/esm/languages/prism/kotlin",
"react-syntax-highlighter/dist/esm/languages/prism/less",
"react-syntax-highlighter/dist/esm/languages/prism/lua",
"react-syntax-highlighter/dist/esm/languages/prism/makefile",
"react-syntax-highlighter/dist/esm/languages/prism/markdown",
"react-syntax-highlighter/dist/esm/languages/prism/markup",
"react-syntax-highlighter/dist/esm/languages/prism/matlab",
"react-syntax-highlighter/dist/esm/languages/prism/nginx",
"react-syntax-highlighter/dist/esm/languages/prism/nix",
"react-syntax-highlighter/dist/esm/languages/prism/objectivec",
"react-syntax-highlighter/dist/esm/languages/prism/ocaml",
"react-syntax-highlighter/dist/esm/languages/prism/perl",
"react-syntax-highlighter/dist/esm/languages/prism/php",
"react-syntax-highlighter/dist/esm/languages/prism/powershell",
"react-syntax-highlighter/dist/esm/languages/prism/properties",
"react-syntax-highlighter/dist/esm/languages/prism/protobuf",
"react-syntax-highlighter/dist/esm/languages/prism/python",
"react-syntax-highlighter/dist/esm/languages/prism/r",
"react-syntax-highlighter/dist/esm/languages/prism/regex",
"react-syntax-highlighter/dist/esm/languages/prism/ruby",
"react-syntax-highlighter/dist/esm/languages/prism/rust",
"react-syntax-highlighter/dist/esm/languages/prism/sass",
"react-syntax-highlighter/dist/esm/languages/prism/scala",
"react-syntax-highlighter/dist/esm/languages/prism/scss",
"react-syntax-highlighter/dist/esm/languages/prism/shell-session",
"react-syntax-highlighter/dist/esm/languages/prism/solidity",
"react-syntax-highlighter/dist/esm/languages/prism/sql",
"react-syntax-highlighter/dist/esm/languages/prism/swift",
"react-syntax-highlighter/dist/esm/languages/prism/toml",
"react-syntax-highlighter/dist/esm/languages/prism/tsx",
"react-syntax-highlighter/dist/esm/languages/prism/typescript",
"react-syntax-highlighter/dist/esm/languages/prism/yaml",
],
},
server: {
port: FE_PORT,
strictPort: true, // Fail if port is busy (dynamic allocation handles fallback)
host: true,
allowedHosts: true,
proxy: {
"/api": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/server_info": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/alive": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/health": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/ready": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/docs": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/redoc": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/openapi.json": {
target: API_URL,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
"/sockets": {
target: WS_URL,
ws: true,
changeOrigin: true,
secure: !INSECURE_SKIP_VERIFY,
},
},
watch: {
ignored: ["**/node_modules/**", "**/.git/**"],
},
},
ssr: {
noExternal: ["react-syntax-highlighter"],
},
clearScreen: false,
test: {
environment: "jsdom",
setupFiles: ["vitest.setup.ts"],
exclude: [...configDefaults.exclude, "tests"],
// The full suite runs many DOM-heavy tests in parallel, which can
// push individual `userEvent`-driven tests past Vitest's 5000ms
// default on busy machines (the skills-settings and i18n
// namespace tests are the typical victims). Bumping the global
// timeout keeps these tests deterministic without changing any
// production behavior.
testTimeout: 30000,
hookTimeout: 30000,
server: {
deps: {
inline: ["@openhands/typescript-client"],
},
},
coverage: {
reporter: ["text", "json", "html", "lcov", "text-summary"],
reportsDirectory: "coverage",
include: ["src/**/*.{ts,tsx}"],
},
},
};
});