import { useCallback, useEffect, useState } from 'react'; import { api } from '../api'; import { capRef } from '../util'; import { CapabilitySearch } from './CapabilitySearch'; import type { LibraryAsset, CapabilityResult } from '../types'; import type { SessionApi } from '../useSession'; // The user's OWN asset library — copy/clone/import. AIWG install files are never // written. Deploying/using an asset is an agent action (Use → inject into a session). export function Library({ session, setComposer, goSessions }: { session: SessionApi; setComposer: (v: string) => void; goSessions: () => void }) { const [items, setItems] = useState(null); const [cloning, setCloning] = useState(false); const [err, setErr] = useState(''); const load = useCallback(() => { api<{ library: LibraryAsset[] }>('/api/library').then((d) => { setItems(d.library); setErr(''); }).catch((e) => setErr((e as Error).message)); }, []); useEffect(() => { load(); }, [load]); const clone = async (r: CapabilityResult) => { try { await api(`/api/library/clone?type=${encodeURIComponent(r.type)}&name=${encodeURIComponent(r.name)}&path=${encodeURIComponent(r.path)}`, { method: 'POST' }); setCloning(false); load(); } catch (e) { setErr((e as Error).message); } }; const remove = (a: LibraryAsset) => { if (!confirm(`Remove "${a.name}" from your library? (Your copy only — AIWG is untouched.)`)) return; api(`/api/library/${encodeURIComponent(a.name)}`, { method: 'DELETE' }).then(load).catch((e) => alert((e as Error).message)); }; const use = (a: LibraryAsset) => { const cmd = capRef(a.type, a.name.replace(/\.(md|markdown|ya?ml|json)$/i, '')); if (!(session.isController && session.state.target && session.sendInput(cmd, session.state.target))) setComposer(cmd); goSessions(); }; return ( <>

Your own assets — copied, cloned, or imported. Edit them freely; AIWG install files are never touched. Stored on disk under ~/.aiwg/cockpit/library. Deploying one into a project is an agent action (Use → inject into a session).

{err &&

{err}

}
{cloning && (

Search the AIWG catalog and clone a copy into your library.

)} {!items ?

Loading…

: !items.length ?

Your library is empty. Clone a capability from the catalog to get a copy you can modify.

: ( {items.map((a) => ( ))}
{items.length} asset(s) in your library
NameTypeOriginActions
{a.name} {a.type} {a.origin} {' '}
)} ); }