openpencil/vite/automation.ts
Danila Poyarkov 0f981ff2af fix(mcp): isolate Portless development routes
- Register the Vite-owned MCP child as a worktree-prefixed Portless sibling service\n- Inject HTTPS and WebSocket automation URLs into the browser instead of assuming port 7600\n- Isolate development socket and discovery files while preserving fixed-port non-Portless flows
2026-08-21 08:14:04 +03:00

27 lines
1 KiB
TypeScript

import { randomUUID } from 'node:crypto'
import process from 'node:process'
import { AUTOMATION_HTTP_PORT } from '@open-pencil/core/constants'
import { devAutomationRoute } from '../src/app/automation/bridge/portless-route'
import { automationPlugin } from '../src/app/automation/bridge/vite-plugin'
const devAutomationAuthToken = process.env.OPENPENCIL_DEV_TOKEN ?? randomUUID()
export function localAutomationToken(command: string): string | null {
return command === 'serve' ? devAutomationAuthToken : null
}
export function automationCORSOrigin(host: string | undefined): string {
return host ? `http://${host}:1420` : 'http://localhost:1420'
}
export function openPencilAutomationPlugin(command: string, host: string | undefined) {
const route = devAutomationRoute(process.env.PORTLESS_URL, AUTOMATION_HTTP_PORT)
return automationPlugin(localAutomationToken(command), {
...route,
corsOrigin: process.env.PORTLESS_URL ? route.corsOrigin : automationCORSOrigin(host),
httpPort: AUTOMATION_HTTP_PORT
})
}