UNPKG

contentful-management

Version:
34 lines (31 loc) 1.18 kB
import { toPlainObject, freezeSys } from 'contentful-sdk-core'; import copy from 'fast-copy'; import { wrapCollection } from '../common-utils.js'; import enhanceWithMethods from '../enhance-with-methods.js'; import { wrapAgentGenerateResponse } from './agent-run.js'; function createAgentApi(makeRequest) { const getParams = (data) => ({ spaceId: data.sys.space.sys.id, environmentId: data.sys.environment.sys.id, agentId: data.sys.id, }); return { generate: function generate(payload) { const self = this; return makeRequest({ entityType: 'Agent', action: 'generate', params: getParams(self), payload, }).then((data) => wrapAgentGenerateResponse(makeRequest, data)); }, }; } function wrapAgent(makeRequest, data) { const agent = toPlainObject(copy(data)); const agentWithMethods = enhanceWithMethods(agent, createAgentApi(makeRequest)); return freezeSys(agentWithMethods); } const wrapAgentCollection = wrapCollection(wrapAgent); export { wrapAgent, wrapAgentCollection }; //# sourceMappingURL=agent.js.map