@@ -101,7 +101,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
101101 const { wrapBulkAction } = entities . bulkAction
102102 const { wrapAppAccessToken } = entities . appAccessToken
103103 const { wrapAgent, wrapAgentCollection } = entities . agent
104- const { wrapAgentRun, wrapAgentRunCollection } = entities . agentRun
104+ const { wrapAgentRun, wrapAgentRunCollection, wrapAgentGenerateResponse } = entities . agentRun
105105 const { wrapResourceTypesForEnvironmentCollection } = entities . resourceType
106106 const { wrapResourceCollection } = entities . resource
107107 const { wrapSemanticDuplicates } = entities . semanticDuplicates
@@ -2987,31 +2987,38 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
29872987 * Generates content using an AI Agent
29882988 * @param agentId - AI Agent ID
29892989 * @param payload - Generation payload
2990- * @return Promise for the generation response
2990+ * @return Promise for a simplified response containing `sys.id`, `sys.type`, and `sys.status`.
2991+ * Use `getAgentRun()` with the returned `sys.id` to poll for full results.
29912992 * @example ```javascript
29922993 * const contentful = require('contentful-management')
29932994 *
2994- * const client = contentful.createClient({
2995- * accessToken: '<content_management_api_key>'
2996- * })
2995+ * async function generateContent() {
2996+ * const client = contentful.createClient({
2997+ * accessToken: '<content_management_api_key>'
2998+ * })
29972999 *
2998- * client.getSpace('<space_id>')
2999- * .then((space) => space.getEnvironment('<environment_id>'))
3000- * .then((environment) => environment.generateWithAgent('<agent_id>', {
3000+ * const space = await client.getSpace('<space_id>')
3001+ * const environment = await space.getEnvironment('<environment_id>')
3002+ *
3003+ * // Start generation (returns 202 Accepted)
3004+ * const response = await environment.generateWithAgent('<agent_id>', {
30013005 * messages: [
30023006 * {
3003- * parts: [
3004- * {
3005- * type: 'text',
3006- * text: 'Write a short poem about Contentful'
3007- * }
3008- * ],
3007+ * parts: [{ type: 'text', text: 'Write a short poem about Contentful' }],
30093008 * role: 'user'
30103009 * }
30113010 * ]
3012- * }))
3013- * .then((result) => console.log(result))
3014- * .catch(console.error)
3011+ * })
3012+ *
3013+ * // Poll for full results
3014+ * let run = await environment.getAgentRun(response.sys.id)
3015+ * while (run.sys.status === 'IN_PROGRESS') {
3016+ * await new Promise((resolve) => setTimeout(resolve, 1000))
3017+ * run = await environment.getAgentRun(response.sys.id)
3018+ * }
3019+ *
3020+ * console.log(run)
3021+ * }
30153022 * ```
30163023 */
30173024 generateWithAgent ( agentId : string , payload : AgentGeneratePayload ) {
@@ -3025,7 +3032,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
30253032 agentId,
30263033 } ,
30273034 payload,
3028- } ) . then ( ( data ) => wrapAgentRun ( makeRequest , data ) )
3035+ } ) . then ( ( data ) => wrapAgentGenerateResponse ( makeRequest , data ) )
30293036 } ,
30303037
30313038 /**
0 commit comments