MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / readPortsFile

Function readPortsFile

scripts/guardian/shared.ts:86–109  ·  view source on GitHub ↗
(userDataHome: string)

Source from the content-addressed store, hash-verified

84 * explicit config should abort the boot, not silently fall back to defaults.
85 */
86export async function readPortsFile(userDataHome: string): Promise<Partial<Record<PortName, number>>> {
87 const filePath = resolve(userDataHome, 'data', 'config', 'ports.json')
88 let raw: string
89 try {
90 raw = await readFile(filePath, 'utf8')
91 } catch {
92 return {}
93 }
94 let parsed: unknown
95 try {
96 parsed = JSON.parse(raw)
97 } catch (err) {
98 throw new Error(`[guardian] ${filePath} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`)
99 }
100 if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
101 throw new Error(`[guardian] ${filePath} must be a JSON object like {"web":47331,"mcp":47332,"uta":47333,"ui":5173}`)
102 }
103 const out: Partial<Record<PortName, number>> = {}
104 for (const name of Object.keys(PORT_DEFAULTS) as PortName[]) {
105 const v = (parsed as Record<string, unknown>)[name]
106 if (v !== undefined) out[name] = parsePort(v, `${filePath} ("${name}")`)
107 }
108 return out
109}
110
111/** Resolve each port's value + source: env > ports.json > default. */
112export function resolvePortConfig(

Callers

nothing calls this directly

Calls 2

parseMethod · 0.80
parsePortFunction · 0.70

Tested by

no test coverage detected