@difizen/magent-au
Version:
42 lines (34 loc) • 980 B
text/typescript
import { inject, prop, singleton } from '@difizen/mana-app';
import { AgentManager } from './agent-manager.js';
import type { AgentModel } from './agent-model.js';
import type { AgentModelOption } from './protocol.js';
export class AgentMarket {
agentManager: AgentManager;
list: AgentModel[] = [];
loading = false;
protected fetching?: Promise<AgentModelOption[]>;
constructor( agentManager: AgentManager) {
this.agentManager = agentManager;
this.update();
}
async update() {
this.loading = true;
if (this.fetching) {
return this.fetching;
} else {
this.fetching = this.agentManager.getAll();
}
this.fetching
.then(() => {
return (this.fetching = undefined);
})
.catch(console.error);
const options = await this.fetching;
this.list = options.map(this.agentManager.getOrCreate);
this.loading = false;
return options;
}
}