UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.35 kB
import{f as e,i as t,p as n,r}from"./transcript-chat-message-content-Cx-VPFHv.mjs";import{i,r as a}from"./transcript-record-coerce-eN4p5mcq.mjs";import{i as o}from"./transcript-number-coercion-Dr06QpMa.mjs";import{s}from"./transcript-transcript-only-openclaw-assistant-CxIarIin.mjs";function readPreferredUpstreamUserText(e){let t=a(e.__openclaw);return typeof t?.upstreamUserText==`string`?t.upstreamUserText.trim():t?.mirrorOrigin?null:void 0}function extractRecentConversationText(a,c={}){let l=i(a),u=i(l?.message);if(!u||u.role!==`user`&&u.role!==`assistant`||c.role&&u.role!==c.role)return;let d=u.openclawDeliveryMirror,f=c.includeCronDirectDeliveryContext===!0&&typeof d==`object`&&!!d&&!Array.isArray(d)&&`kind`in d&&d.kind===`cron-direct-delivery-context`,p=u.role===`assistant`&&s(u),m=p&&(f||!!(c.includeMessageToolSourceReplies&&e(u)));if(p&&!m)return;let h=c.preferUpstreamUserText&&u.role===`user`?readPreferredUpstreamUserText(u):void 0;if(h===null)return;let g=u.role===`assistant`?r(u):h??t(u)?.trim();if(!g)return;let _=i(u.provenance),v=o(u.timestamp),y={...typeof l?.id==`string`&&l.id?{id:l.id}:{},role:u.role,text:g,...v===void 0?{}:{timestamp:v},...typeof _?.sourceChannel==`string`&&_.sourceChannel.trim()?{sourceChannel:_.sourceChannel.trim()}:{}};if(c.includeTurnIdentity){let t=i(u.__openclaw),r=u.role===`user`?i(t?.transport)?.messageId:void 0;typeof r==`string`&&r&&(y.messageId=r),u.role===`assistant`&&(e(u)||u.stopReason===`stop`&&!u.errorMessage&&n(u)!==`commentary`&&u.openclawStreamFallback===void 0&&u.openclawAsyncDelivery===void 0&&(t?.mirrorOrigin===void 0||t.runTerminal===!0))&&(y.isCompletedAnswer=!0)}return{deliveryOnly:m,entry:y}}function readRecentTranscriptConversationText(e,t={}){let n=Math.max(1,Math.floor(t.limit??10)),r=[];for(let i=0;r.length<n;i+=250){let a=e({maxMessages:250,maxBytes:2**53-1,offset:i});for(let e of a.events.toReversed()){let i=extractRecentConversationText(e.event,t);if(i&&(t.beforeTimestampMs===void 0||i.entry.timestamp===void 0||i.entry.timestamp<t.beforeTimestampMs)&&(t.minTimestampMs===void 0||i.entry.timestamp===void 0||i.entry.timestamp>=t.minTimestampMs)&&(r.push(i),r.length>=n))break}if(i+a.scannedMessages>=a.totalMessages)break}return r.toReversed().flatMap(({deliveryOnly:e,entry:n})=>!t.deliveryOnly||e?[n]:[])}export{readRecentTranscriptConversationText as t};