forked from outsourc-e/hermes-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
736 lines (677 loc) · 24 KB
/
Copy pathvite.config.ts
File metadata and controls
736 lines (677 loc) · 24 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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
import { URL, fileURLToPath } from 'node:url'
import { execSync, spawn } from 'node:child_process'
import type { ChildProcess } from 'node:child_process'
import { copyFileSync, existsSync, mkdirSync } from 'node:fs'
import net from 'node:net'
import { resolve, dirname } from 'node:path'
import os from 'node:os'
// devtools removed
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import viteReact from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
// nitro plugin removed (tanstackStart handles server runtime)
import { defineConfig, loadEnv } from 'vite'
import viteTsConfigPaths from 'vite-tsconfig-paths'
// ---------------------------------------------------------------------------
// Hermes Agent auto-start helpers
// ---------------------------------------------------------------------------
/** Resolve the hermes-agent directory using a priority-ordered fallback chain:
* 1. HERMES_AGENT_PATH env var (explicit override)
* 2. CLAUDE_AGENT_PATH env var (legacy override)
* 3. ../hermes-agent — sibling clone (standard README setup)
* 4. ../../hermes-agent — one level up (monorepo / nested workspace)
* Returns null if none found.
*/
function resolveClaudeAgentDir(env: Record<string, string>): string | null {
const candidates: string[] = []
const explicitAgentPath = env.HERMES_AGENT_PATH?.trim() || env.CLAUDE_AGENT_PATH?.trim()
if (explicitAgentPath) {
candidates.push(explicitAgentPath)
}
// Resolve relative to the workspace root (parent of hermes-workspace/)
const workspaceRoot = dirname(resolve('.'))
candidates.push(
resolve(workspaceRoot, 'hermes-agent'), // sibling (old README)
resolve(workspaceRoot, '..', 'hermes-agent'), // one level up
resolve(os.homedir(), '.claude', 'hermes-agent'), // Nous installer default
resolve(os.homedir(), 'hermes-agent'), // ~/hermes-agent
)
for (const candidate of candidates) {
if (existsSync(resolve(candidate, 'webapi'))) return candidate
}
return null
}
/** Find the Hermes CLI binary used to start the local gateway. */
function resolveClaudeBinary(): string | null {
const candidates = [
process.env.HERMES_CLI_BIN || '',
resolve(os.homedir(), '.hermes', 'hermes-agent', 'venv', 'bin', 'hermes'),
resolve(os.homedir(), '.claude', 'bin', 'claude'),
resolve(os.homedir(), '.local', 'bin', 'claude'),
]
for (const c of candidates) {
if (existsSync(c)) return c
}
return null
}
/** Resolve the Python executable to use for Hermes backend startup.
* Prefers .venv/bin/python inside agentDir, falls back to system python3.
*/
function resolveClaudePython(agentDir: string): string {
const venvPython = resolve(agentDir, '.venv', 'bin', 'python')
if (existsSync(venvPython)) return venvPython
// uv creates 'venv' not '.venv' sometimes
const uvVenv = resolve(agentDir, 'venv', 'bin', 'python')
if (existsSync(uvVenv)) return uvVenv
return 'python3'
}
/** Check if hermes-agent health endpoint is responding */
async function isClaudeAgentHealthy(port = 8642): Promise<boolean> {
try {
const r = await fetch(`http://127.0.0.1:${port}/health`, {
signal: AbortSignal.timeout(2000),
})
return r.ok
} catch {
return false
}
}
const config = defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd(), '')
const claudeApiUrl = env.CLAUDE_API_URL?.trim() || 'http://127.0.0.1:8642'
// /api/connection-status is handled by the real route file at
// src/routes/api/connection-status.ts; the dev server no longer
// intercepts that path with a slim shortcut. See #285.
// Hermes Agent auto-start state
let claudeAgentChild: ChildProcess | null = null
let claudeAgentStarted = false
const startClaudeAgent = async () => {
if (claudeAgentStarted) return
// Skip auto-start when CLAUDE_API_URL is explicitly set to a non-local endpoint
const explicitUrl =
env.CLAUDE_API_URL || process.env.CLAUDE_API_URL || claudeApiUrl || ''
if (
explicitUrl &&
explicitUrl !== 'http://127.0.0.1:8642' &&
explicitUrl !== 'http://localhost:8642'
) {
console.log(
`[hermes-agent] Skipping auto-start — using external API: ${explicitUrl}`,
)
claudeAgentStarted = true
return
}
if (await isClaudeAgentHealthy()) {
console.log('[hermes-agent] Already running — reusing existing process')
claudeAgentStarted = true
return
}
const claudeBin = resolveClaudeBinary()
const agentDir = resolveClaudeAgentDir(env)
// Prefer the `hermes gateway run` binary path (Nous installer's canonical
// entrypoint). Fall back to launching uvicorn against the source tree if
// only a directory is present (dev / cloned-in-place setups).
let launchCmd: string
let commandArgs: string[]
let launchCwd: string | undefined
if (claudeBin) {
launchCmd = claudeBin
commandArgs = ['gateway', 'run']
launchCwd = agentDir ?? undefined
console.log(`[hermes-agent] Starting ${claudeBin} gateway run`)
} else if (agentDir) {
launchCmd = resolveClaudePython(agentDir)
const useGatewayRun = existsSync(resolve(agentDir, 'gateway', 'run.py'))
commandArgs = useGatewayRun
? ['-m', 'gateway.run']
: [
'-m',
'uvicorn',
'webapi.app:app',
'--host',
'0.0.0.0',
'--port',
'8642',
]
launchCwd = agentDir
console.log(
`[hermes-agent] Starting from ${agentDir} using ${launchCmd} (${useGatewayRun ? 'gateway.run' : 'uvicorn'})`,
)
} else {
console.warn(
'[hermes-agent] Could not find hermes-agent installation.\n' +
' Run the installer:\n' +
' curl -fsSL https://hermes-workspace.com/install.sh | bash\n' +
' Or set HERMES_AGENT_PATH (or legacy CLAUDE_AGENT_PATH) in .env to point at your hermes-agent clone.',
)
return
}
const child = spawn(launchCmd, commandArgs, {
cwd: launchCwd,
detached: false, // keep tied to vite process — stops when dev server stops
stdio: 'pipe',
env: {
...process.env,
PATH: [
resolve(os.homedir(), '.claude', 'bin'),
resolve(os.homedir(), '.local', 'bin'),
agentDir ? resolve(agentDir, '.venv', 'bin') : '',
agentDir ? resolve(agentDir, 'venv', 'bin') : '',
process.env.PATH || '',
]
.filter(Boolean)
.join(':'),
},
})
claudeAgentChild = child
claudeAgentStarted = true
child.stdout?.on('data', (d: Buffer) => {
const line = d.toString().trim()
if (line) console.log(`[hermes-agent] ${line}`)
})
child.stderr?.on('data', (d: Buffer) => {
const line = d.toString().trim()
if (line) console.log(`[hermes-agent] ${line}`)
})
child.on('exit', (code) => {
claudeAgentChild = null
claudeAgentStarted = false
if (code !== 0 && code !== null) {
console.warn(`[hermes-agent] Exited with code ${code}`)
}
})
// Wait for healthy
for (let i = 0; i < 15; i++) {
await new Promise((r) => setTimeout(r, 1000))
if (await isClaudeAgentHealthy()) {
console.log('[hermes-agent] ✓ Ready on http://127.0.0.1:8642')
return
}
}
console.warn(
'[hermes-agent] Started but health check timed out — may still be loading',
)
}
let workspaceDaemonStarted = false
let workspaceDaemonStarting = false
let workspaceDaemonShuttingDown = false
let workspaceDaemonRestarting = false
let workspaceDaemonChild: ChildProcess | null = null
let workspaceDaemonRetryCount = 0
const workspaceDaemonPort = '3099'
const daemonCwd = resolve('workspace-daemon')
const daemonSrcEntry = resolve('workspace-daemon/src/server.ts')
const daemonDistEntry = resolve('workspace-daemon/dist/server.js')
const workspaceDaemonDbPath = resolve(
'workspace-daemon/.workspaces/workspace.db',
)
const getWorkspaceDaemonDelayMs = (attempt: number) =>
Math.min(1000 * 2 ** Math.max(attempt - 1, 0), 30000)
const startWorkspaceDaemon = () => {
if (workspaceDaemonShuttingDown) return
if (workspaceDaemonStarted || workspaceDaemonStarting) return
const spawnCommand = existsSync(daemonSrcEntry)
? {
commandName: 'npx',
args: ['tsx', 'watch', 'src/server.ts'],
options: {
cwd: daemonCwd,
env: {
...process.env,
PORT: workspaceDaemonPort,
DB_PATH: workspaceDaemonDbPath,
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? '',
},
stdio: 'inherit' as const,
},
}
: existsSync(daemonDistEntry)
? {
commandName: 'node',
args: ['dist/server.js'],
options: {
cwd: daemonCwd,
env: {
...process.env,
PORT: workspaceDaemonPort,
DB_PATH: workspaceDaemonDbPath,
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? '',
},
stdio: 'inherit' as const,
},
}
: null
if (!spawnCommand) {
workspaceDaemonStarting = false
console.error('[workspace-daemon] no server entry found to spawn.')
return
}
workspaceDaemonStarted = true
workspaceDaemonStarting = false
const child = spawn(
spawnCommand.commandName,
spawnCommand.args,
spawnCommand.options,
)
workspaceDaemonChild = child
child.on('exit', (code) => {
if (workspaceDaemonChild === child) {
workspaceDaemonChild = null
}
if (workspaceDaemonShuttingDown || workspaceDaemonRestarting) {
workspaceDaemonStarted = false
workspaceDaemonStarting = false
return
}
if (code === 0) {
workspaceDaemonStarted = false
workspaceDaemonStarting = false
return
}
if (workspaceDaemonRetryCount >= 20) {
workspaceDaemonStarted = false
workspaceDaemonStarting = false
console.error(
`[workspace-daemon] crashed with code ${code ?? 'unknown'}; max restart attempts reached.`,
)
return
}
workspaceDaemonRetryCount += 1
const delayMs = getWorkspaceDaemonDelayMs(workspaceDaemonRetryCount)
console.error(
`[workspace-daemon] crashed with code ${code ?? 'unknown'}; restarting in ${Math.round(
delayMs / 1000,
)}s (${workspaceDaemonRetryCount}/20).`,
)
workspaceDaemonStarting = true
workspaceDaemonStarted = false
setTimeout(() => {
startWorkspaceDaemon()
}, delayMs)
})
child.on('error', (error) => {
console.error(`[workspace-daemon] failed to spawn: ${error.message}`)
})
}
const stopWorkspaceDaemon = async () => {
const child = workspaceDaemonChild
if (!child) {
workspaceDaemonStarted = false
workspaceDaemonStarting = false
return
}
workspaceDaemonRestarting = true
await new Promise<void>((resolve) => {
const exitTimer = setTimeout(() => {
if (!child.killed && child.pid) {
try {
process.kill(child.pid, 'SIGKILL')
} catch {
// ignore
}
}
}, 5000)
child.once('exit', () => {
clearTimeout(exitTimer)
resolve()
})
if (child.pid) {
try {
process.kill(child.pid, 'SIGTERM')
} catch {
clearTimeout(exitTimer)
resolve()
}
} else {
clearTimeout(exitTimer)
resolve()
}
})
workspaceDaemonStarted = false
workspaceDaemonStarting = false
workspaceDaemonRestarting = false
}
const restartWorkspaceDaemon = async () => {
workspaceDaemonRetryCount = 0
await stopWorkspaceDaemon()
workspaceDaemonStarted = false
workspaceDaemonStarting = false
startWorkspaceDaemon()
}
const isPortInUse = (port: number) =>
new Promise<boolean>((resolvePortCheck) => {
const socket = net.createConnection({ port, host: '127.0.0.1' })
socket.once('connect', () => {
socket.destroy()
resolvePortCheck(true)
})
socket.once('error', () => resolvePortCheck(false))
})
const hasHealthyWorkspaceDaemon = async () => {
try {
const response = await fetch(
`http://127.0.0.1:${workspaceDaemonPort}/api/workspace/version`,
{
signal: AbortSignal.timeout(2000),
},
)
return response.ok
} catch {
return false
}
}
// Allow access from Tailscale, LAN, or custom domains via env var
// e.g. CLAUDE_ALLOWED_HOSTS=my-server.tail1234.ts.net,192.168.1.50
const _allowedHosts: string[] | true = env.CLAUDE_ALLOWED_HOSTS?.trim()
? env
.CLAUDE_ALLOWED_HOSTS!.split(',')
.map((h) => h.trim())
.filter(Boolean)
: ['.ts.net'] // allow all Tailscale hostnames by default
let proxyTarget = 'http://127.0.0.1:18789'
try {
const parsed = new URL(claudeApiUrl)
parsed.protocol = parsed.protocol === 'wss:' ? 'https:' : 'http:'
parsed.pathname = ''
proxyTarget = parsed.toString().replace(/\/$/, '')
} catch {
// fallback
}
return {
test: {
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/skills-bundle/**',
'**/.{idea,git,cache,output,temp}/**',
],
// Force vitest to run React through its own transform pipeline so ESM
// `import` and CJS `require('react')` share a single module instance.
// Without this, react-dom sets the dispatcher on its CJS React copy while
// components call hooks on the ESM React copy → null dispatcher → crash.
deps: {
inline: [
'react',
'react-dom',
'@testing-library/react',
'@testing-library/dom',
],
},
},
define: {
// Note: Do NOT set 'process.env': {} here — TanStack Start uses environment-based
// builds where isSsrBuild is unreliable. Blanket process.env replacement breaks
// server-side code in Docker (kills runtime env var access).
// Client-side process.env is handled per-environment below.
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
ssr: {
external: [
'playwright',
'playwright-core',
'playwright-extra',
'puppeteer-extra-plugin-stealth',
],
},
optimizeDeps: {
exclude: [
'playwright',
'playwright-core',
'playwright-extra',
'puppeteer-extra-plugin-stealth',
],
},
server: {
// Force IPv4 — 'localhost' resolves to ::1 (IPv6) on Windows, breaking connectivity
host: '0.0.0.0',
// Port precedence:
// 1. --port CLI flag (wins, but we no longer hardcode it in package.json)
// 2. $PORT env var (for containers, reverse proxies, WhatsApp bridge collisions, etc. — see #96)
// 3. default 888 (3000 is often occupied locally)
port: process.env.PORT ? Number(process.env.PORT) : 888,
strictPort: false, // allow fallback if port is taken, but log clearly
allowedHosts: true,
watch: {
ignored: [
// NOTE: the generated TanStack route tree must NOT be added to this
// ignore list — doing so causes route changes to require a full
// dev-server restart. See src/router-route-resolution.test.ts.
// Real fix for HMR thrash on the generated tree is to ensure only
// ONE vite dev server runs against this source tree at a time.
// Local portable session store, rewritten on every chat send.
// Without this, the watcher fires on every message → spurious
// server-side reload events / test churn during development.
'**/.runtime/**',
// Internal TanStack Start state cache.
'**/.tanstack/**',
// Local plan/notes/scratch state used by OMC tooling — never
// imported by the module graph, but file events still spam logs.
'**/.omc/**',
'**/.omx/**',
// Build artifacts.
'**/dist/**',
'**/.output/**',
// Test/coverage outputs.
'**/coverage/**',
'**/playwright-report/**',
'**/test-results/**',
// Editor / agent metadata.
'**/.vscode/**',
'**/.claude/**',
'**/.cursor/**',
// Loose log files.
'**/*.log',
],
},
proxy: {
// WebSocket proxy: clients connect to /ws-claude on the Hermes Workspace
// server (any IP/port), which internally forwards to the local server.
// This means phone/LAN/Docker users never need to reach port 18789 directly.
'/ws-claude': {
target: proxyTarget,
changeOrigin: false,
ws: true,
rewrite: (path) => path.replace(/^\/ws-claude/, ''),
},
// REST API proxy: API proxy for Hermes backend
'/api/claude-proxy': {
target: proxyTarget,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api\/claude-proxy/, ''),
},
'/claude-ui': {
target: proxyTarget,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/claude-ui/, ''),
ws: true,
configure: (proxy) => {
proxy.on('proxyRes', (_proxyRes) => {
// Strip iframe-blocking headers so we can embed
delete _proxyRes.headers['x-frame-options']
delete _proxyRes.headers['content-security-policy']
})
},
},
'/workspace-api': {
target: 'http://127.0.0.1:3099',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/workspace-api/, ''),
},
},
},
plugins: [
// devtools(),
// this is the plugin that enables path aliases
viteTsConfigPaths({
projects: ['./tsconfig.json'],
}),
tailwindcss(),
tanstackStart(),
viteReact(),
{
name: 'workspace-daemon',
buildStart() {
if (command !== 'serve') return
},
configureServer(server) {
server.middlewares.use(async (req, res, next) => {
const requestPath = req.url?.split('?')[0]
if (req.method === 'GET' && requestPath === '/api/healthcheck') {
res.statusCode = 200
res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ ok: true }))
return
}
// /api/connection-status is handled by the real route file at
// src/routes/api/connection-status.ts — it returns the full
// ConnectionStatus payload including capabilities and chatMode
// that downstream feature gates depend on. Earlier versions
// had an inline shortcut handler here that returned a slim
// body ({ok, mode, backend}) which silently broke things like
// useFeatureCapability/useFeatureAvailable in dev mode. See #285.
if (
req.method !== 'POST' ||
requestPath !== '/api/workspace/daemon/restart'
) {
next()
return
}
try {
await restartWorkspaceDaemon()
res.statusCode = 200
res.setHeader('content-type', 'application/json')
res.end(JSON.stringify({ ok: true }))
} catch (error) {
res.statusCode = 500
res.setHeader('content-type', 'application/json')
res.end(
JSON.stringify({
error:
error instanceof Error ? error.message : 'Internal error',
}),
)
}
})
// Dev-only: disable Node's default 5-minute request timeout so
// long-running SSE streams (agent runs that go silent for minutes
// during heavy reasoning / tool calls) don't get killed mid-stream
// by the HTTP layer. Heartbeats handle keep-alive at the application
// layer. Production servers should keep their default timeouts to
// avoid slowloris exposure.
if (command === 'serve' && server.httpServer) {
const httpServer = server.httpServer as unknown as {
requestTimeout?: number
headersTimeout?: number
timeout?: number
}
httpServer.requestTimeout = 0
httpServer.headersTimeout = 0
httpServer.timeout = 0
}
server.httpServer?.on('close', () => {
workspaceDaemonShuttingDown = true
workspaceDaemonStarted = false
workspaceDaemonStarting = false
if (workspaceDaemonChild) {
workspaceDaemonChild.kill()
workspaceDaemonChild = null
}
})
// Auto-start hermes-agent when dev server launches
if (command === 'serve') {
void startClaudeAgent()
}
// Shutdown hermes-agent when dev server stops
server.httpServer?.on('close', () => {
if (claudeAgentChild) {
console.log('[hermes-agent] Stopping...')
claudeAgentChild.kill('SIGTERM')
claudeAgentChild = null
claudeAgentStarted = false
}
})
if (
command !== 'serve' ||
workspaceDaemonStarted ||
workspaceDaemonStarting
)
return
workspaceDaemonStarting = true
void (async () => {
const running = await isPortInUse(Number(workspaceDaemonPort))
if (workspaceDaemonStarted) {
workspaceDaemonStarting = false
return
}
if (running) {
const healthy = await hasHealthyWorkspaceDaemon()
if (healthy) {
workspaceDaemonStarting = false
console.log('[workspace-daemon] Reusing existing daemon')
return
}
try {
execSync(
`lsof -ti:${workspaceDaemonPort} | xargs kill -9 2>/dev/null || true`,
)
} catch {
// ignore stale cleanup failures and continue with a fresh spawn
}
}
startWorkspaceDaemon()
})()
},
},
// Client-only: replace process.env references in client bundles
// Server bundles must keep real process.env for Docker runtime env vars
{
name: 'client-process-env',
enforce: 'pre',
transform(code, _id) {
const envName = this.environment?.name
if (envName !== 'client') return null
if (
!code.includes('process.env') &&
!code.includes('process.platform')
)
return null
// Replace specific env vars first, then the generic fallback
let result = code
result = result.replace(
/process\.env\.CLAUDE_API_URL/g,
JSON.stringify(claudeApiUrl),
)
result = result.replace(
/process\.env\.CLAUDE_API_TOKEN/g,
JSON.stringify(env.CLAUDE_API_TOKEN || ''),
)
result = result.replace(
/process\.env\.NODE_ENV/g,
JSON.stringify(mode),
)
result = result.replace(/process\.env/g, '{}')
result = result.replace(/process\.platform/g, '"browser"')
return result
},
},
// Copy pty-helper.py into the server assets directory after build
{
name: 'copy-pty-helper',
closeBundle() {
const src = resolve('src/server/pty-helper.py')
const destDir = resolve('dist/server/assets')
const dest = resolve(destDir, 'pty-helper.py')
if (existsSync(src)) {
mkdirSync(destDir, { recursive: true })
copyFileSync(src, dest)
}
},
},
],
}
})
export default config