| 53 | } |
| 54 | |
| 55 | export function agentHost(agent: AgentV2.Interface): PluginContext["agent"] { |
| 56 | return { |
| 57 | reload: agent.reload, |
| 58 | transform: (callback) => |
| 59 | agent.transform((draft) => |
| 60 | callback({ |
| 61 | list: () => draft.list().map(agentInfo), |
| 62 | get: (id) => { |
| 63 | const value = draft.get(AgentV2.ID.make(id)) |
| 64 | return value && agentInfo(value) |
| 65 | }, |
| 66 | default: (id) => draft.default(id === undefined ? undefined : AgentV2.ID.make(id)), |
| 67 | update: (id, update) => |
| 68 | draft.update(AgentV2.ID.make(id), (value) => { |
| 69 | const current = agentInfo(value) |
| 70 | update(current) |
| 71 | Object.assign(value, current, { id: AgentV2.ID.make(current.id) }) |
| 72 | }), |
| 73 | remove: (id) => draft.remove(AgentV2.ID.make(id)), |
| 74 | }), |
| 75 | ), |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | export function catalogHost(catalog: Catalog.Interface): PluginContext["catalog"] { |
| 80 | return { |