Something went wrong. Try again.
Open source agent hosting on the AT Protocol
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738// Optional Tailscale integration via the `tailscale` CLI: `languid serve --tailnet`// listens on this node's tailnet address and advertises its MagicDNS name.// Runners don't need it: they dial out to the service over HTTPS.
import { execFile } from 'node:child_process'import { promisify } from 'node:util'
const run = promisify(execFile)
export interface TailnetSelf { stableId: string hostName: string /** MagicDNS name without the trailing dot, e.g. desk.tailnet.ts.net */ dnsName: string ipv4: string userId: number}
async function tailscaleJson(args: string[]): Promise<any> { try { const [sub, ...rest] = args const { stdout } = await run('tailscale', [sub, '--json', ...rest], { timeout: 5000 }) return JSON.parse(stdout) } catch (e: any) { if (e.code === 'ENOENT') throw new Error('tailscale is not installed (https://tailscale.com/download)') throw new Error(`tailscale ${args.join(' ')} failed: ${(e.stderr || e.message).trim()}`) }}
export async function tailnetSelf(): Promise<TailnetSelf> { const st = await tailscaleJson(['status']) if (st.BackendState !== 'Running') throw new Error(`tailscale is ${st.BackendState}; run: sudo tailscale up`) const s = st.Self const ipv4 = (s.TailscaleIPs as string[]).find((ip) => ip.includes('.')) if (!ipv4) throw new Error('this node has no tailnet IPv4 address') return { stableId: s.ID, hostName: s.HostName, dnsName: String(s.DNSName).replace(/\.$/, ''), ipv4, userId: s.UserID }}