openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 1.27 kB
JavaScript
//!src/gateway/agent-turn/agent-image-understanding.ts
const GENERATED_IMAGE_UNINSPECTED_NOTE=`[Generated image not inspected: no vision model produced a description. Do not claim to have inspected its content; refer to it only by what was requested.]`;function isGeneratedImageCompletion(e){return e?.kind===`inter_session`&&e.sourceTool?.trim().toLowerCase()===`image_generate`}async function prepareAgentImageUnderstanding(e){const{message:t,media:n,sessionKey:r,channel:i,chatType:a,inputProvenance:o,...s}=e;const c={Body:t,media:n,SessionKey:r,AgentId:e.agentId,Provider:i,ChatType:a};const{applyMediaUnderstanding:l}=await import(`./media-understanding/apply.runtime.js`);await l({...s,ctx:c});e.execution?.signal.throwIfAborted();if(!c.MediaUnderstanding?.some(e=>e.kind===`image.description`&&e.text.trim())){if(isGeneratedImageCompletion(o))return{message:`${t}\n\n${GENERATED_IMAGE_UNINSPECTED_NOTE}`,media:n.map(e=>Object.assign({},e,{hydrationSuppressed:true}))};throw new Error(`Image attachments could not be analyzed. Configure agents.defaults.imageModel or tools.media.models with an available vision model, then retry.`)}return{message:c.agentText??t,media:n.map(e=>Object.assign({},e,{hydrationSuppressed:true}))}}export{prepareAgentImageUnderstanding};