import { execFile } from 'child_process' import { promisify } from 'util' import { POWERSHELL_EXE } from './lib/systemPaths' import type { SkillDefinition } from '../types' const execFileAsync = promisify(execFile) interface ConnectionInfo { Connected: boolean Ip: string | null } const PS_SCRIPT = ` $ping = Test-Connection -ComputerName 8.8.8.8 -Count 1 -Quiet -ErrorAction SilentlyContinue $ip = (Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object { $_.InterfaceAlias -notmatch 'Loopback' -and $_.IPAddress -notlike '169.254.*' } | Select-Object -First 1).IPAddress [PSCustomObject]@{ Connected = [bool]$ping; Ip = $ip } | ConvertTo-Json ` export const checkInternet: SkillDefinition = { name: 'check_internet_connection', description: "Teste si la connexion internet fonctionne et donne l'adresse IP locale.", parameters: { type: 'object', properties: {} }, execute: async () => { const { stdout } = await execFileAsync(POWERSHELL_EXE, ['-NoProfile', '-Command', PS_SCRIPT], { timeout: 10000 }) const data = JSON.parse(stdout) as ConnectionInfo return data.Connected ? `Internet fonctionne. Adresse IP locale : ${data.Ip ?? 'inconnue'}.` : 'Pas de connexion internet detectee.' } }