coaches
Version:
Coaches - Open infrastructure for AI agents
5 lines (4 loc) • 754 B
JavaScript
;
class Component{constructor(o={}){this.name=o.name||"component";this._reg=new Map();this._hooks=[]}register(k,v,m={}){this._reg.set(k,{value:v,metadata:m,createdAt:new Date().toISOString()});return this}get(k){const e=this._reg.get(k);if(!e)throw new Error(`"${k}" not found`);return e.value}has(k){return this._reg.has(k)}list(){return Array.from(this._reg.entries()).map(([k,v])=>({key:k,...v}))}remove(k){return this._reg.delete(k)}use(fn){this._hooks.push(fn);return this}async process(i){let r=i;for(const h of this._hooks){r=await h(r,this)||r}return r}get size(){return this._reg.size}toJSON(){return{name:this.name,entries:this.list()}}}
function create(o){return new Component(o)}
module.exports={Component,create,default:create};