import { kody } from 'kody:runtime'
type LoginMetadata = { description: string; updatedAt: string; disconnected: boolean }
export async function loginMetadata(): Promise<LoginMetadata | null> {
let listed: unknown
try { listed = await kody.secretList({ scope: 'user' }) }
catch { throw new Error('Audible login metadata unavailable. Check secretList capability and Kody access.') }
const rows = listed && typeof listed === 'object' && 'secrets' in listed ? listed.secrets : listed
if (!Array.isArray(rows)) return null
const row = rows.find(row => row?.name === 'audible-login' && row.scope === 'user')
if (!row) return null
return { description: typeof row.description === 'string' ? row.description : '', updatedAt: typeof row.updated_at === 'string' ? row.updated_at : '', disconnected: row.disconnected === true }
}