@dcrays/dcgchat-test 0.7.12 → 0.7.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +1 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -298,7 +298,7 @@ raw xml: ${i}`,a.status=t.status,a.requestId=t.headers&&t.headers["x-oss-request
298
298
  ${n}`}async function Rse(e,t){let r=new AbortController,n=setTimeout(()=>r.abort(new Error(`fetch timeout ${t}ms`)),t);try{return await fetch(e,{signal:r.signal})}finally{clearTimeout(n)}}function qse(e,t){if(Ih.extname(e))return e;let r=Ih.extname(t);if(!r)return e;let n=`${e}${r}`;try{return wse.renameSync(e,n),n}catch(i){return L(`media: failed to append extension to ${e}: ${String(i)}`,"error"),e}}async function Pse(e,t,r,n){let i=Vr();try{let s="";/^https?:\/\//i.test(e.url)?s=e.url:s=await jD(e.url,t);let o=await Rse(s,n);if(!o.ok)return L?.(`media: ${e.url} fetch failed with HTTP ${o.status}`,"error"),null;let a=Buffer.from(await o.arrayBuffer()),c=o.headers.get("content-type")||"";c||(c=await i.media.detectMime({buffer:a})||"");let u=e.name||P0(e.url),l=await i.channel.media.saveMediaBuffer(a,c,"inbound",r,u),p=l.contentType||c;return{path:qse(l.path,u),fileName:u,contentType:p,placeholder:Ase(p)}}catch(s){return L(`media: ${e.url} FAILED to process: ${String(s)}`,"error"),null}}async function pL(e,t,r){let n=r?.maxBytes??Sse,i=r?.fetchTimeoutMs??Ose,s=Math.max(1,r?.concurrency??Ise),o=e.length===0?1:Math.min(s,e.length);L(`media: inbound files count=${e.length}, concurrency=${o}, fetchTimeoutMs=${i}`);let a=new Array(e.length).fill(null),c=0;async function u(){for(;;){let p=c++;if(p>=e.length)break;a[p]=await Pse(e[p],t,n,i)}}await Promise.all(Array.from({length:o},()=>u()));let l=a.filter(p=>p!=null);return L(`media: resolve complete, ${l.length}/${e.length} file(s) succeeded`),l}var Sse,Ese,kse,Tse,Ose,Ise,D0=re(()=>{"use strict";Pe();Le();dx();Sse=500*1024*1024,Ese=["url","fileUrl","file_url","link","href","path","ossKey","oss_key","key"],kse=["name","fileName","file_name","title","originalName","original_filename"],Tse=["files","file_list","fileList","attachments","media_files","mediaFiles","resources","uploads"];Ose=18e4,Ise=3});import Dse from"fs";import Iu from"fs/promises";import Rh from"path";function Mse(e){let t=Zt();if(!Mr()||!t)return L("\u6280\u80FD\u64CD\u4F5C\u53CD\u9988\u53D1\u9001\u5931\u8D25: websocket \u672A\u8FDE\u63A5","error"),!1;try{let r=JSON.stringify({messageType:"openclaw_bot_event",source:"client",content:e});return t.send(r),!0}catch(r){return L(`\u6280\u80FD\u64CD\u4F5C\u53CD\u9988\u53D1\u9001\u5931\u8D25: ${String(r)}`,"error"),!1}}function zn(e,t,r){return L(`\u6280\u80FD\u64CD\u4F5C\u53CD\u9988: ${r}`),Mse({...e,status:t}),{success:t==="ok",status:t,...r?{error:r}:{}}}async function fL(){try{await Ue({method:"skills.status",params:{}})}catch(e){L(`skills.status refresh failed: ${String(e)}`,"error")}}function dL(e){let t=e?.trim()||"";return t?Nse.test(t)?t:(L(`invalid skill code: ${t}`,"error"),""):(L("skill code is empty","error"),"")}function hL(e){let t=Bt();if(t){let r=Rh.join(t,"skills",e);return Dse.existsSync(r)}return!1}async function Fse(e,t,r){await Iu.mkdir(t,{recursive:!0}),await Iu.rm(r,{recursive:!0,force:!0}).catch(i=>L(`skill cleanup before install failed: ${String(i)}`));let n=await _i({method:"get",url:e,responseType:"arraybuffer"});await Iu.mkdir(r,{recursive:!0}),await Au(Buffer.from(n.data),r),await fL()}async function qh(e,t){let{path:r}=e,n=dL(e.code);if(!n)return zn(t,"fail","invalid skill code");let i=Bt();if(!i)return zn(t,"fail","workspace directory not initialized");if(!r?.trim())return zn(t,"fail","skill url is empty");let s=Rh.join(i,"skills"),o=Rh.join(s,n);try{return await Ks(()=>Fse(r,s,o),3),zn(t,"ok")}catch(a){return L(`skill install failed: ${String(a)}`,"error"),await Iu.rm(o,{recursive:!0,force:!0}).catch(c=>L(`skill cleanup after install failure failed: ${String(c)}`)),zn(t,"fail",String(a))}}async function mL(e,t){let r=dL(e.code);if(!r)return zn(t,"fail","invalid skill code");let n=Bt();if(!n)return zn(t,"fail","workspace directory not initialized");try{let i=Rh.join(n,"skills",r);return await Iu.rm(i,{recursive:!0,force:!0}),await fL(),zn(t,"ok")}catch(i){return L(`skill uninstall failed: ${String(i)}`,"error"),zn(t,"fail",String(i))}}var Nse,M0=re(()=>{"use strict";Ud();Pe();Pe();Le();tr();Fr();k0();St();Nse=/^[A-Za-z][A-Za-z0-9_-]*$/});function Xe(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Hn(e){return typeof e=="object"&&e!==null}function gL(e){return Array.isArray(e)?e:e==null?[]:[e]}function Bs(e){let t=Xe(e);if(!t)return;let r=t.split(":");return r[0]==="agent"&&r[1]?.trim()?r[1].trim():void 0}function Ru(e,t="agent_send aborted"){if(!e?.aborted)return;let r=new Error(t);throw r.name="AbortError",r}var qu=re(()=>{"use strict"});function Lse(e){let t=e.trim();if(!t)return{kind:"deny"};if(t==="*")return{kind:"all"};if(!t.includes("*"))return{kind:"exact",value:t};let r=t.toLowerCase().split("*");return{kind:"wildcard",first:r[0]??"",last:r[r.length-1]??"",interior:r.slice(1,-1).filter(Boolean)}}function jse(e,t){let r=0;if(e.first){if(!t.startsWith(e.first))return!1;r=e.first.length}let n=e.last?t.length-e.last.length:t.length;if(e.last&&(!t.endsWith(e.last)||n<r))return!1;for(let i of e.interior){let s=t.indexOf(i,r);if(s===-1||s+i.length>n)return!1;r=s+i.length}return!0}function yL(e,t){let r=(t??[]).map(i=>typeof i=="string"?i:"").filter(Boolean);if(r.length===0)return!0;let n=e.toLowerCase();return r.map(Lse).some(i=>i.kind==="all"?!0:i.kind==="deny"?!1:i.kind==="exact"?i.value===e:jse(i,n))}function vL(e,t){let r=Xe(e),n=Bs(t);return!r||!n||r===n?{ok:!0}:{ok:!1,error:`agentId \u4E0E sessionKey \u4E0D\u5339\u914D\uFF1AagentId=${r}, sessionKey \u4E2D\u7684 agentId=${n}`}}function bL(e){let{sourceSessionKey:t,targetSessionKey:r,config:n}=e;if(t===r)return{ok:!0};let i=Bs(t),s=Bs(r);if(!i)return{ok:!1,error:`\u65E0\u6CD5\u4ECE\u5F53\u524D sessionKey \u89E3\u6790 agentId\uFF1A${t}`};if(!s)return{ok:!1,error:`\u65E0\u6CD5\u4ECE\u76EE\u6807 sessionKey \u89E3\u6790 agentId\uFF1A${r}`};let o=n?.tools,a=o?.sessions?.visibility;if(i===s)return a==="agent"||a==="all"?{ok:!0}:{ok:!1,error:'\u540C agent \u8DE8 session \u53D1\u9001\u9700\u8981 tools.sessions.visibility="agent" \u6216 "all"\u3002'};if(o?.agentToAgent?.enabled!==!0)return{ok:!1,error:"\u8DE8 agent \u53D1\u9001\u672A\u5F00\u542F\uFF1A\u8BF7\u8BBE\u7F6E tools.agentToAgent.enabled=true\u3002"};let c=Array.isArray(o.agentToAgent.allow)?o.agentToAgent.allow.filter(u=>typeof u=="string"):void 0;return!yL(i,c)||!yL(s,c)?{ok:!1,error:"\u8DE8 agent \u53D1\u9001\u88AB tools.agentToAgent.allow \u62D2\u7EDD\u3002"}:a!=="all"?{ok:!1,error:'\u8DE8 agent \u53D1\u9001\u9700\u8981 tools.sessions.visibility="all"\u3002'}:{ok:!0}}var xL=re(()=>{"use strict";qu()});function Bse(e){if(typeof e=="string"){let i=Xe(e);return i?{path:i}:null}if(!e||typeof e!="object")return null;let t=e,r=Xe(t.path)??Xe(t.file),n=Xe(t.url);return!r&&!n?null:{...r?{path:r}:{},...n?{url:n}:{},...Xe(t.contentType)?{contentType:Xe(t.contentType)}:{},...Xe(t.kind)?{kind:Xe(t.kind)}:{},...Xe(t.messageId)?{messageId:Xe(t.messageId)}:{},...Xe(t.name)?{name:Xe(t.name)}:{},...Xe(t.fileName)?{fileName:Xe(t.fileName)}:{}}}function wL(e){let t=[],r=new Set;for(let n of gL(e)){let i=Bse(n);if(!i)continue;let s=i.path??i.url??"";!s||r.has(s)||(r.add(s),t.push(i))}return t}function Use(e){if(e.length===0)return;let t=e.map((r,n)=>{let i=r.fileName??r.name??r.path?.split(/[\\/]/).pop()??r.url?.split(/[\\/]/).pop()??"attachment",s=r.contentType??r.kind??"unknown",o=r.path?` path=${r.path}`:r.url?` url=${r.url}`:"";return`${n+1}) ${i} [${s}]${o}`}).join("; ");return`[\u7CFB\u7EDF: \u672C\u6B21 agent_send \u5173\u8054 ${e.length} \u4E2A\u9644\u4EF6: ${t}\u3002Gateway agent \u63A5\u53E3\u4E0D\u652F\u6301 media \u53C2\u6570\uFF0C\u9644\u4EF6\u4FE1\u606F\u4EE5\u6587\u672C\u5F62\u5F0F\u4F20\u9012\u3002]`}function _L(e){let t=e.media??[],r=["[File delivery requirement]","If this task creates one or more files for the user, you must send them with the dcgchat_message tool before your final reply.",'Call dcgchat_message once with every generated file in the same media array, using this shape: { "media": [{ "file": "/absolute/path/to/file" }] }.',"Each file must already exist, be non-empty, and use its real absolute path inside the current agent workspace.","Wait for dcgchat_message to return success=true before saying that any file was delivered.","Do not use the built-in message tool, do not expose local file paths in the final reply, and do not treat a filename or an Attachment: marker as delivery.","If no file is generated, return the text result normally in the final assistant reply."].join(`
299
299
  `);return["[Agent-to-agent message]",`Source session: ${e.sourceSessionKey}`,`Target session: ${e.targetSessionKey}`,Use(t),r,"",e.message.trim()].filter(i=>typeof i=="string").join(`
300
300
  `)}var SL=re(()=>{"use strict";qu()});import{callGatewayTool as $se}from"openclaw/plugin-sdk/agent-harness-runtime";function EL(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Pu(e,t){for(let r of t){let n=e[r],i=EL(n);if(i)return i}}function zse(e){return typeof e=="string"?e.trim():Array.isArray(e)?e.map(t=>typeof t=="string"?t:Hn(t)?t.type==="text"&&typeof t.text=="string"?t.text:typeof t.content=="string"?t.content:"":"").join("").trim():""}function Sa(e){if(!Hn(e))return"";let t=Pu(e,["text","message","body"]);return t||zse(e.content)}function kL(e){if(Hn(e))return Pu(e,["role","author","type"])}function TL(e){if(!Hn(e))return;let t=Pu(e,["runId","run_id"]);return t||(Hn(e.metadata)?Pu(e.metadata,["runId","run_id"]):void 0)}function Hse(e){if(!Hn(e))return;let t=e.timestamp??e.createdAt??e.ts;return typeof t=="number"&&Number.isFinite(t)?String(t):EL(t)}function N0(e){if(!Hn(e))return Sa(e);let t=Pu(e,["id","messageId","entryId"]);if(t)return`id:${t}`;let r=TL(e),n=Hse(e);return[kL(e)??"",r??"",n??"",Sa(e)].join("\0")}function F0(e){return kL(e)==="assistant"}function Kse(e){return Hn(e)?Array.isArray(e.messages)?e.messages:[]:[]}async function L0(e){let t=await $se("chat.history",{timeoutMs:3e4},{sessionKey:e.sessionKey,...e.agentId?{agentId:e.agentId}:{},limit:e.limit,maxChars:e.maxChars});return Kse(t)}function CL(e){let t=[...e.messages].reverse().filter(F0),r=t.find(i=>TL(i)===e.runId&&Sa(i));if(r)return{text:Sa(r),message:r,matchedBy:"runId"};let n=t.find(i=>!e.baselineFingerprints.has(N0(i))&&Sa(i));if(n)return{text:Sa(n),message:n,matchedBy:"new_message"}}var AL=re(()=>{"use strict";qu()});import{randomUUID as Wse}from"node:crypto";import{callGatewayTool as Ph}from"openclaw/plugin-sdk/agent-harness-runtime";function Yse(e){return Math.max(1,Math.floor(typeof e=="number"&&Number.isFinite(e)?e:Xse))}function Qse(e){let t=typeof e=="number"&&Number.isFinite(e)?e:Jse;return Math.max(1,Math.min(1e3,Math.floor(t)))}function Zse(e){let t=typeof e=="number"&&Number.isFinite(e)?e:OL;return Math.max(1,Math.min(OL,Math.floor(t)))}function eoe(e){return Math.max(1,Math.min(e,6e4))}function toe(e){return Math.max(1,Math.ceil(e/1e3))}function IL(e){let t=e?.session?.mainKey;return Xe(t)??"main"}function roe(e,t){let r=Xe(e.sessionKey);if(r)return r;let n=Xe(e.agentId);if(n)return`agent:${n}:${IL(t)}`}async function noe(e){let t=Bs(e.targetSessionKey);if(!t)return{ok:!0};if(e.targetSessionKey!==`agent:${t}:${IL(e.config)}`)return{ok:!0};try{return await Ph("sessions.resolve",{timeoutMs:1e4},{key:e.targetSessionKey}),{ok:!0}}catch{try{return await Ph("sessions.create",{timeoutMs:1e4},{key:e.targetSessionKey,agentId:t}),{ok:!0}}catch(r){return{ok:!1,error:r instanceof Error?r.message:String(r)}}}}async function j0(e){let{sourceSessionKey:t,message:r,agentId:n,media:i,timeoutMs:s,waitForReply:o=!0,historyLimit:a,maxHistoryChars:c,signal:u,name:l}=e,p=e.config??vt()??void 0;Ru(u);let f=Xe(r);if(!f)return{success:!1,error:"\u4F60\u9700\u8981\u6211\u5E2E\u4F60\u505A\u4EC0\u4E48\u5462\uFF1F"};if(!Xe(t))return{success:!1,error:"\u672A\u77E5\u6765\u6E90\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F"};let d=roe(e,p);if(!d)return{success:!1,error:`\u6CA1\u6709\u67E5\u8BE2\u5230${l}\u7684\u4FE1\u606F`};if(!vL(n,d).ok)return{success:!1,status:"error",error:`${l}\u4E0D\u5B58\u5728`,targetSessionKey:d};if(!bL({sourceSessionKey:t,targetSessionKey:d,config:p}).ok)return{success:!1,status:"forbidden",error:`${l}\u6CA1\u6709\u6743\u9650\u8BBF\u95EE`,targetSessionKey:d};if(!(await noe({config:p,targetSessionKey:d})).ok)return{success:!1,status:"error",error:`${l}\u521B\u5EFA\u5931\u8D25`,targetSessionKey:d};let E=Wse(),S=Yse(s),v=Qse(a),g=Zse(c),y=wL(i),k=Xe(n)??Bs(d);try{let q=new Set;if(o){let G=await L0({sessionKey:d,agentId:k,limit:v,maxChars:g}).catch(()=>[]);q=new Set(G.filter(F0).map(N0))}Ru(u);let T=await Ph("agent",{timeoutMs:eoe(S)},{...k?{agentId:k}:{},sessionKey:d,message:_L({message:f,sourceSessionKey:t,targetSessionKey:d,media:y}),idempotencyKey:E,timeout:toe(S),deliver:!1,sourceReplyDeliveryMode:"message_tool_only",channel:Gse,inputProvenance:{kind:"inter_session",sourceSessionKey:t,sourceTool:Vse}},{expectFinal:!1}),w=typeof T?.runId=="string"?T.runId:E;if(!o)return{success:!0,status:"accepted",targetSessionKey:d,targetAgentId:k,mediaCount:y.length,runId:w,idempotencyKey:E,result:T};Ru(u);let C=await Ph("agent.wait",{timeoutMs:S+1e4},{runId:w,timeoutMs:S}),I=typeof C?.status=="string"?C.status:void 0;if(I==="timeout")return{success:!1,status:"timeout",error:`${l}\u6267\u884C\u8D85\u65F6`,targetSessionKey:d,targetAgentId:k,mediaCount:y.length,runId:w,idempotencyKey:E,waitResult:C};if(I&&I!=="ok"){let G=typeof C?.error=="string"?C.error:void 0;return{success:!1,status:I,error:G??`${l}\u6267\u884C\u5931\u8D25`,targetSessionKey:d,targetAgentId:k,mediaCount:y.length,runId:w,idempotencyKey:E,waitResult:C}}Ru(u);let M=await L0({sessionKey:d,agentId:k,limit:v,maxChars:g}),O=CL({messages:M,baselineFingerprints:q,runId:w});return O?.text?{success:!0,status:"ok",targetSessionKey:d,targetAgentId:k,mediaCount:y.length,runId:w,idempotencyKey:E,reply:O.text,matchedBy:O.matchedBy,waitResult:C,result:T}:{success:!1,status:"no_reply",error:`${l}\u5DF2\u7ED3\u675F\uFF0C\u4F46\u672A\u80FD\u4ECE chat.history \u4E2D\u8BFB\u53D6\u5230\u672C\u6B21 assistant \u56DE\u590D`,targetSessionKey:d,targetAgentId:k,mediaCount:y.length,runId:w,idempotencyKey:E,waitResult:C}}catch(q){return L(`agent_send: failed: ${String(q)}`,"error"),{success:!1,error:q instanceof Error?q.message:String(q),targetSessionKey:d,targetAgentId:k,mediaCount:y.length,idempotencyKey:E}}}var Gse,Vse,Xse,Jse,OL,B0=re(()=>{"use strict";Pe();Le();xL();qu();SL();AL();Gse="webchat",Vse="agent_send",Xse=3600*1e3,Jse=30,OL=5e5});var Iwe,Rwe,Dh,Mh,U0=re(()=>{"use strict";Fr();Pe();kt();Ha();Le();Iwe=1440*60*1e3,Rwe=600*1e3,Dh=({agentId:e,cloneCode:t,sessionId:r})=>`agent:${typeof t=="string"&&t.trim()||"main"}:mobook:direct:${e}:${r??0}`.toLowerCase(),Mh="12138"});import{randomUUID as ioe}from"node:crypto";import{callGatewayTool as RL}from"openclaw/plugin-sdk/agent-harness-runtime";async function Nh(e){let{sessionId:t}=Pr(e.sourceSessionKey),r=Dh({agentId:Mh,cloneCode:e.cloneCode,sessionId:t});ym(r,e.sourceSessionKey);try{return await j0({sourceSessionKey:e.sourceSessionKey,sessionKey:r,message:e.message,media:e.media,waitForReply:!0,timeoutMs:soe,name:e.name})}finally{bm(r,ooe)}}async function Fh(e){let t=["[Expert Reply Archive]",`\u4E13\u5BB6: ${e.expertName}`,e.expertSessionKey?`\u4E13\u5BB6 sessionKey: ${e.expertSessionKey}`:void 0,e.expertRunId?`\u4E13\u5BB6 runId: ${e.expertRunId}`:void 0,"","\u4E0B\u9762\u662F\u4E13\u5BB6 Agent \u672C\u8F6E\u751F\u6210\u7684\u6587\u672C\u5185\u5BB9\u3002","\u8BF7\u4EC5\u5C06\u5176\u4F5C\u4E3A\u5F53\u524D main \u4F1A\u8BDD\u7684\u5386\u53F2\u4E0A\u4E0B\u6587\u4FDD\u5B58\u3002","\u4E0D\u8981\u6539\u5199\uFF0C\u4E0D\u8981\u603B\u7ED3\uFF0C\u4E0D\u8981\u8C03\u7528\u5DE5\u5177\uFF0C\u4E0D\u8981\u5411\u7528\u6237\u53D1\u9001\u4EFB\u4F55\u989D\u5916\u56DE\u590D\u3002","\u5982\u679C\u5FC5\u987B\u8F93\u51FA\uFF0C\u8BF7\u53EA\u56DE\u590D\uFF1ANO_REPLY","",e.expertReply].filter(o=>typeof o=="string").join(`
301
- `),r=await RL("agent",{timeoutMs:6e5},{agentId:"main",sessionKey:e.mainSessionKey,message:t,idempotencyKey:ioe(),deliver:!1,timeout:Math.ceil($0/1e3),sourceReplyDeliveryMode:"message_tool_only",disableMessageTool:!0,inputProvenance:{kind:"inter_session",sourceSessionKey:e.expertSessionKey,sourceTool:"agent_send.writeback"}},{expectFinal:!1}),n=typeof r?.runId=="string"?r.runId:void 0;if(!n)throw new Error("main \u56DE\u5199\u5DF2\u63D0\u4EA4\uFF0C\u4F46 Gateway \u672A\u8FD4\u56DE runId");let i=await RL("agent.wait",{timeoutMs:$0+1e4},{runId:n,timeoutMs:$0}),s=typeof i?.status=="string"?i.status:void 0;if(s!=="ok"){let o=typeof i?.error=="string"?i.error:void 0;throw new Error(o??`main \u56DE\u5199\u5931\u8D25\uFF0Cstatus=${s??"unknown"}, runId=${n}`)}}var soe,ooe,$0,qL=re(()=>{"use strict";Pe();kt();U0();B0();soe=1440*60*1e3,ooe=600*1e3,$0=12e4});var PL=re(()=>{"use strict";B0();qL()});import{randomUUID as DL}from"node:crypto";function z0(e){return e.agent_scope?.[0]?Gs(e.agent_scope?.[0]||{}):NL(e)?.find(r=>r.biz_type==="agent")}function ML(e){return e.skills_scope?.[0]?Gs(e.skills_scope?.[0]||{}):NL(e)?.find(r=>r.biz_type==="skill")}function NL(e){return e.intent_recognition?.map(r=>{let n={url:r.downloadUrl??"",name:r.shortName??r.name??"",shortName:r.shortName??r.name??"",bizType:r.bizType??""};return r.bizType==="skill"&&(n.skillCode=r.name??"",n.skillId=r.id),r.bizType==="agent"&&(n.agentCode=r.agentCode??r.cloneCode?.replace(/(?:-\d+)+$/,"")??"",n.cloneCode=r.cloneCode,n.agentId=r.agentId??r.productId??"",n.coverUrl=r.coverUrl),Gs(n)})}function FL({sessionKey:e,type:t,name:r}){let{text:n,callId:i}=Qi("match_intent_finished",{toolName:"match_intent_finished"},{},"lifecycle",`\u5339\u914D${t}\u6267\u884C\u5B8C\u6210,\u4E3A\u60A8\u5339\u914D\u5230${r}`);Yi(e,n,i,0)}function Ea({sessionKey:e,type:t,name:r,toolCallId:n,isCover:i,duration:s}){let{text:o,callId:a}=Qi(i===0?"before_install_intent":"after_install_intent",{params:`\u81EA\u52A8\u5B89\u88C5${t}: ${r}`,toolName:i===0?"before_install_intent":"after_install_intent",durationMs:s?s>100?s:Math.floor(Math.random()*71)+150:void 0},{toolCallId:n},i===0?"running":"finished");Yi(e,o,a,i??0)}async function LL(e,t,r,n=[]){let i=z0(e.content);e.content?.agent_scope?.[0]||FL({sessionKey:t,type:"\u4E13\u5BB6",name:i?.name});let s=await U3({...i});if(console.log("\u{1F680} ~ handlerIntentRecognition ~ isHasAgent:",s),s){let o=Pt(t),a=await Nh({message:r,sourceSessionKey:t,cloneCode:i?.clone_code,media:n,name:i?.name});return a.status==="ok"&&a.reply?(await Fh({mainSessionKey:t,expertName:i?.clone_code||i?.name||"\u4E13\u5BB6 Agent",expertReply:a.reply,expertSessionKey:a.targetSessionKey,expertRunId:a.runId}),er({...o},{response:a.reply,is_finish:-1})):er({...o},{response:a.error??`${i?.name}\u53D1\u9001\u5931\u8D25`,is_finish:-1}),Dt(o,"agent_stop"),hr(t,e.content.message_id),{success:!0}}else{let o=Date.now(),a=DL();if(Ea({sessionKey:t,type:"\u4E13\u5BB6",name:`\u5F00\u59CB\u5B89\u88C5${i?.name}`,toolCallId:a,isCover:0}),!i?.url)return{success:!1,message:`${i?.name}\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54`};let{success:c}=await Th(i),u=Date.now()-o;if(c){Ea({sessionKey:t,type:"\u4E13\u5BB6",name:`\u5B89\u88C5${i.name}\u6210\u529F`,toolCallId:a,isCover:1,duration:u});let l=Pt(t),p=await Nh({message:r,sourceSessionKey:t,cloneCode:i.clone_code,name:i?.name,media:n});return p.status==="ok"&&p.reply?(await Fh({mainSessionKey:t,expertName:i.clone_code||i.name||"\u4E13\u5BB6 Agent",expertReply:p.reply,expertSessionKey:p.targetSessionKey,expertRunId:p.runId}),er({...l},{response:p.reply,is_finish:-1})):er({...l},{response:p.error??`${i?.name}\u53D1\u9001\u5931\u8D25`,is_finish:-1}),hr(t,e.content.message_id),Dt(l,"agent_stop"),{success:!0}}else return Ea({sessionKey:t,type:"\u4E13\u5BB6",name:`\u5B89\u88C5${i.name}\u5931\u8D25`,toolCallId:a,isCover:0,duration:u}),{success:c,message:`${i.name}\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54\u3002`}}}async function jL(e,t,r){if(r.content?.skills_scope?.[0]||FL({sessionKey:t,type:"\u6280\u80FD",name:e.name}),e?.skill_code&&!hL(e.skill_code)){if(!e.url)return{success:!1,message:`\u6280\u80FD${e.name}\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54\u3002`};let n=Date.now(),i=DL();Ea({sessionKey:t,type:"\u6280\u80FD",name:`\u5F00\u59CB\u5B89\u88C5${e.name}`,toolCallId:i,isCover:0});let s={event_type:"skill",operation_type:"install",skill_url:e.url,skill_code:e.skill_code,skill_id:e.skill_id,bot_token:r.content.bot_token},{success:o}=await qh({path:e.url,code:e.skill_code},s),a=Date.now()-n;return o?(Ea({sessionKey:t,type:"\u6280\u80FD",name:`\u5B89\u88C5${e.name}\u6210\u529F`,toolCallId:i,isCover:1,duration:a}),{success:!0}):(Ea({sessionKey:t,type:"\u6280\u80FD",name:`\u5B89\u88C5${e.name}\u5931\u8D25`,toolCallId:i,isCover:1,duration:a}),{success:!1,message:`${e.name}\u6280\u80FD\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54\u3002`})}return{success:!0}}var BL=re(()=>{"use strict";kt();tr();H0();ei();M0();Oh();Pe();PL()});import aoe from"node:path";import{createReplyPrefixContext as coe,createTypingCallbacks as uoe}from"openclaw/plugin-sdk/channel-reply-pipeline";function hr(e,t){ul(e),r1(e),Ja(e),v_(e),k1(e),Wn(e,""),t&&Pi(t);let{sessionId:r}=Pr(e);r&&Pi(r),Pi(e),iw(e),Ya(e),Rl(e)}function Lh(e){let t=(e??"").trim();if(!t)return UL;let r=t.toLowerCase();return loe.test(t)?r:r.replace(poe,"-").replace(foe,"").replace(doe,"").slice(0,64)||UL}function hoe(e,t){let r=e.split(":")[1];return!r?.trim()||!t.trim()?!1:Lh(r)===Lh(t)}function moe(e,t){let r=e.agents?.defaults?.humanDelay,n=Lh(t),i=e.agents?.list?.find(s=>Lh(s.id)===n)?.humanDelay;if(!(!r&&!i))return{mode:i?.mode??r?.mode,minMs:i?.minMs??r?.minMs,maxMs:i?.maxMs??r?.maxMs}}function yoe(e,t,r){let n=e.messageId?.trim();!n||n===t?.trim()||Dt(e,"abort")}function $L(e,t,r,n){return{userId:e._userId,botToken:e.content.bot_token,sessionId:r,messageId:e.content.message_id,domainId:e.content.domain_id,appId:n.channels?.[xe]?.appId||100,botId:e.content.bot_id??"",agentId:e.content.agent_id??"",sessionKey:t}}async function voe(e,t,r){let n=vt();if(!n)return;let i=Gn(e.content),s=e.content.session_id?.trim(),o=$L(e,i,s,n);gm(i,o);let a=Pt(i);Dt(a,"stop");let{started:c,barrier:u}=T1(i);c&&r&&yoe(r,e.content.message_id,i),L(`stop control ack: sessionKey=${i} messageId=${e.content.message_id} started=${c}`),await u}async function zL(e,t){let r=vt();if(!r){L("no OpenClaw config available","error");return}let n=Us(r,t),i=Gn(e.content),s=(e.content.text??"").trim(),o=Hs.includes(s),a=o?Pt(i):void 0;if(o){await voe(e,t,a);return}await C1(i,()=>boe(e,t))}async function boe(e,t){let r=vt();if(!r)return;let n=Us(r,t),i=Vr(),s=e.content.session_id?.trim(),o=e.content?.agent_clone_code?.trim()||"",a=Gn(e.content),c=za(a);Ja(a);let u=Cl(a),l=c>0&&!Hs.includes((e.content.text??"").trim()),p=$L(e,a,s,r);gm(a,p);let f=Pt(a),d=null,h=e.content.text?.trim();if(!h){Nr("\u4F60\u9700\u8981\u6211\u5E2E\u4F60\u505A\u4EC0\u4E48\u5462\uFF1F",f),Dt(f,"not text"),hr(a,e.content.message_id);return}if(Hs.includes(h)){Dt(f,"stop"),hr(a,e.content.message_id);return}if(o&&hoe(a,o)){let E=e.content.agent_code?.trim()||o.replace(/(?:-\d+)+$/,""),S=!0;if(Ah(o)?S=await I0(o):O0(o)?S=await kh(o):(L(`agent not installed, try local cache: agentCloneCode=${o}, agentCode=${E}`),S=await G3(E,o)),Mt(a)!==u){L(`skip stale install result: sessionKey=${a} inboundGen=${u}`);return}if(!S||!Eh(o)){L(`receive agentCloneCode, but agent not ready: ${o}`),Nr("\u62B1\u6B49\uFF0C\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",f,{message_tags:{source:"agent_not_found"},is_finish:-1}),Dt(f,"agent_not_installed"),hr(a,e.content.message_id);return}if(S=await kh(o),!S||!Eh(o)){L(`agent workspace binding validation failed: ${o}`,"error"),Nr("\u62B1\u6B49\uFF0C\u4E13\u5BB6\u521D\u59CB\u5316\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",f,{message_tags:{source:"agent_binding_failed"},is_finish:-1}),Dt(f,"agent_binding_failed"),hr(a,e.content.message_id);return}let v=vt();v&&(r=v)}let m=i.channel.routing.resolveAgentRoute({cfg:r,channel:xe,accountId:n.accountId,peer:{kind:"direct",id:s}}),b=o||m.agentId||"main";d=r.agents?.list?.find(E=>E.id===b)?.name||b;try{let E=!1;if(!Lu.includes(h?.trim())){let{text:D,callId:Y}=Qi("message_received",{},{},"lifecycle");Yi(a,D,Y,0)}let S=cL(e.content),v=[],g={};S.length>0&&(v=await pL(S,e.content.bot_token),g=uL(v),Wu(a)&&(h+=`
301
+ `),r=await RL("agent",{timeoutMs:6e5},{agentId:"main",sessionKey:e.mainSessionKey,message:t,idempotencyKey:ioe(),deliver:!1,timeout:Math.ceil($0/1e3),sourceReplyDeliveryMode:"message_tool_only",disableMessageTool:!0,inputProvenance:{kind:"inter_session",sourceSessionKey:e.expertSessionKey,sourceTool:"agent_send.writeback"}},{expectFinal:!1}),n=typeof r?.runId=="string"?r.runId:void 0;if(!n)throw new Error("main \u56DE\u5199\u5DF2\u63D0\u4EA4\uFF0C\u4F46 Gateway \u672A\u8FD4\u56DE runId");let i=await RL("agent.wait",{timeoutMs:$0+1e4},{runId:n,timeoutMs:$0}),s=typeof i?.status=="string"?i.status:void 0;if(s!=="ok"){let o=typeof i?.error=="string"?i.error:void 0;throw new Error(o??`main \u56DE\u5199\u5931\u8D25\uFF0Cstatus=${s??"unknown"}, runId=${n}`)}}var soe,ooe,$0,qL=re(()=>{"use strict";Pe();kt();U0();B0();soe=1440*60*1e3,ooe=600*1e3,$0=12e4});var PL=re(()=>{"use strict";B0();qL()});import{randomUUID as DL}from"node:crypto";function z0(e){return e.agent_scope?.[0]?Gs(e.agent_scope?.[0]||{}):NL(e)?.find(r=>r.biz_type==="agent")}function ML(e){return e.skills_scope?.[0]?Gs(e.skills_scope?.[0]||{}):NL(e)?.find(r=>r.biz_type==="skill")}function NL(e){return e.intent_recognition?.map(r=>{let n={url:r.downloadUrl??"",name:r.shortName??r.name??"",shortName:r.shortName??r.name??"",bizType:r.bizType??""};return r.bizType==="skill"&&(n.skillCode=r.name??"",n.skillId=r.id),r.bizType==="agent"&&(n.agentCode=r.agentCode??r.cloneCode?.replace(/(?:-\d+)+$/,"")??"",n.cloneCode=r.cloneCode,n.agentId=r.agentId??r.productId??"",n.coverUrl=r.coverUrl),Gs(n)})}function FL({sessionKey:e,type:t,name:r}){let{text:n,callId:i}=Qi("match_intent_finished",{toolName:"match_intent_finished"},{},"lifecycle",`\u5339\u914D${t}\u6267\u884C\u5B8C\u6210\uFF0C\u4E3A\u60A8\u5339\u914D\u5230${r}`);Yi(e,n,i,0)}function Ea({sessionKey:e,type:t,name:r,toolCallId:n,isCover:i,duration:s}){let{text:o,callId:a}=Qi(i===0?"before_install_intent":"after_install_intent",{params:`\u81EA\u52A8\u5B89\u88C5${t}\uFF1A${r}`,toolName:i===0?"before_install_intent":"after_install_intent",durationMs:s?s>100?s:Math.floor(Math.random()*71)+150:void 0},{toolCallId:n},i===0?"running":"finished");Yi(e,o,a,i??0)}async function LL(e,t,r,n=[]){let i=z0(e.content);e.content?.agent_scope?.[0]||FL({sessionKey:t,type:"\u4E13\u5BB6",name:i?.name});let s=await U3({...i});if(console.log("\u{1F680} ~ handlerIntentRecognition ~ isHasAgent:",s),s){let o=Pt(t),a=await Nh({message:r,sourceSessionKey:t,cloneCode:i?.clone_code,media:n,name:i?.name});return a.status==="ok"&&a.reply?(await Fh({mainSessionKey:t,expertName:i?.clone_code||i?.name||"\u4E13\u5BB6 Agent",expertReply:a.reply,expertSessionKey:a.targetSessionKey,expertRunId:a.runId}),er({...o},{response:a.reply,is_finish:-1})):er({...o},{response:a.error??`${i?.name}\u53D1\u9001\u5931\u8D25`,is_finish:-1}),Dt(o,"agent_stop"),hr(t,e.content.message_id),{success:!0}}else{let o=Date.now(),a=DL();if(Ea({sessionKey:t,type:"\u4E13\u5BB6",name:`\u5F00\u59CB\u5B89\u88C5${i?.name}`,toolCallId:a,isCover:0}),!i?.url)return{success:!1,message:`${i?.name}\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54`};let{success:c}=await Th(i),u=Date.now()-o;if(c){Ea({sessionKey:t,type:"\u4E13\u5BB6",name:`\u5B89\u88C5${i.name}\u6210\u529F`,toolCallId:a,isCover:1,duration:u});let l=Pt(t),p=await Nh({message:r,sourceSessionKey:t,cloneCode:i.clone_code,name:i?.name,media:n});return p.status==="ok"&&p.reply?(await Fh({mainSessionKey:t,expertName:i.clone_code||i.name||"\u4E13\u5BB6 Agent",expertReply:p.reply,expertSessionKey:p.targetSessionKey,expertRunId:p.runId}),er({...l},{response:p.reply,is_finish:-1})):er({...l},{response:p.error??`${i?.name}\u53D1\u9001\u5931\u8D25`,is_finish:-1}),hr(t,e.content.message_id),Dt(l,"agent_stop"),{success:!0}}else return Ea({sessionKey:t,type:"\u4E13\u5BB6",name:`\u5B89\u88C5${i.name}\u5931\u8D25`,toolCallId:a,isCover:0,duration:u}),{success:c,message:`${i.name}\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54\u3002`}}}async function jL(e,t,r){if(r.content?.skills_scope?.[0]||FL({sessionKey:t,type:"\u6280\u80FD",name:e.name}),e?.skill_code&&!hL(e.skill_code)){if(!e.url)return{success:!1,message:`\u6280\u80FD${e.name}\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54\u3002`};let n=Date.now(),i=DL();Ea({sessionKey:t,type:"\u6280\u80FD",name:`\u5F00\u59CB\u5B89\u88C5${e.name}`,toolCallId:i,isCover:0});let s={event_type:"skill",operation_type:"install",skill_url:e.url,skill_code:e.skill_code,skill_id:e.skill_id,bot_token:r.content.bot_token},{success:o}=await qh({path:e.url,code:e.skill_code},s),a=Date.now()-n;return o?(Ea({sessionKey:t,type:"\u6280\u80FD",name:`\u5B89\u88C5${e.name}\u6210\u529F`,toolCallId:i,isCover:1,duration:a}),{success:!0}):(Ea({sessionKey:t,type:"\u6280\u80FD",name:`\u5B89\u88C5${e.name}\u5931\u8D25`,toolCallId:i,isCover:1,duration:a}),{success:!1,message:`${e.name}\u6280\u80FD\u5B89\u88C5\u5931\u8D25\uFF0C\u7531\u4E66\u7075\u58A8\u5B9D\u4E3A\u60A8\u89E3\u7B54\u3002`})}return{success:!0}}var BL=re(()=>{"use strict";kt();tr();H0();ei();M0();Oh();Pe();PL()});import aoe from"node:path";import{createReplyPrefixContext as coe,createTypingCallbacks as uoe}from"openclaw/plugin-sdk/channel-reply-pipeline";function hr(e,t){ul(e),r1(e),Ja(e),v_(e),k1(e),Wn(e,""),t&&Pi(t);let{sessionId:r}=Pr(e);r&&Pi(r),Pi(e),iw(e),Ya(e),Rl(e)}function Lh(e){let t=(e??"").trim();if(!t)return UL;let r=t.toLowerCase();return loe.test(t)?r:r.replace(poe,"-").replace(foe,"").replace(doe,"").slice(0,64)||UL}function hoe(e,t){let r=e.split(":")[1];return!r?.trim()||!t.trim()?!1:Lh(r)===Lh(t)}function moe(e,t){let r=e.agents?.defaults?.humanDelay,n=Lh(t),i=e.agents?.list?.find(s=>Lh(s.id)===n)?.humanDelay;if(!(!r&&!i))return{mode:i?.mode??r?.mode,minMs:i?.minMs??r?.minMs,maxMs:i?.maxMs??r?.maxMs}}function yoe(e,t,r){let n=e.messageId?.trim();!n||n===t?.trim()||Dt(e,"abort")}function $L(e,t,r,n){return{userId:e._userId,botToken:e.content.bot_token,sessionId:r,messageId:e.content.message_id,domainId:e.content.domain_id,appId:n.channels?.[xe]?.appId||100,botId:e.content.bot_id??"",agentId:e.content.agent_id??"",sessionKey:t}}async function voe(e,t,r){let n=vt();if(!n)return;let i=Gn(e.content),s=e.content.session_id?.trim(),o=$L(e,i,s,n);gm(i,o);let a=Pt(i);Dt(a,"stop");let{started:c,barrier:u}=T1(i);c&&r&&yoe(r,e.content.message_id,i),L(`stop control ack: sessionKey=${i} messageId=${e.content.message_id} started=${c}`),await u}async function zL(e,t){let r=vt();if(!r){L("no OpenClaw config available","error");return}let n=Us(r,t),i=Gn(e.content),s=(e.content.text??"").trim(),o=Hs.includes(s),a=o?Pt(i):void 0;if(o){await voe(e,t,a);return}await C1(i,()=>boe(e,t))}async function boe(e,t){let r=vt();if(!r)return;let n=Us(r,t),i=Vr(),s=e.content.session_id?.trim(),o=e.content?.agent_clone_code?.trim()||"",a=Gn(e.content),c=za(a);Ja(a);let u=Cl(a),l=c>0&&!Hs.includes((e.content.text??"").trim()),p=$L(e,a,s,r);gm(a,p);let f=Pt(a),d=null,h=e.content.text?.trim();if(!h){Nr("\u4F60\u9700\u8981\u6211\u5E2E\u4F60\u505A\u4EC0\u4E48\u5462\uFF1F",f),Dt(f,"not text"),hr(a,e.content.message_id);return}if(Hs.includes(h)){Dt(f,"stop"),hr(a,e.content.message_id);return}if(o&&hoe(a,o)){let E=e.content.agent_code?.trim()||o.replace(/(?:-\d+)+$/,""),S=!0;if(Ah(o)?S=await I0(o):O0(o)?S=await kh(o):(L(`agent not installed, try local cache: agentCloneCode=${o}, agentCode=${E}`),S=await G3(E,o)),Mt(a)!==u){L(`skip stale install result: sessionKey=${a} inboundGen=${u}`);return}if(!S||!Eh(o)){L(`receive agentCloneCode, but agent not ready: ${o}`),Nr("\u62B1\u6B49\uFF0C\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",f,{message_tags:{source:"agent_not_found"},is_finish:-1}),Dt(f,"agent_not_installed"),hr(a,e.content.message_id);return}if(S=await kh(o),!S||!Eh(o)){L(`agent workspace binding validation failed: ${o}`,"error"),Nr("\u62B1\u6B49\uFF0C\u4E13\u5BB6\u521D\u59CB\u5316\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",f,{message_tags:{source:"agent_binding_failed"},is_finish:-1}),Dt(f,"agent_binding_failed"),hr(a,e.content.message_id);return}let v=vt();v&&(r=v)}let m=i.channel.routing.resolveAgentRoute({cfg:r,channel:xe,accountId:n.accountId,peer:{kind:"direct",id:s}}),b=o||m.agentId||"main";d=r.agents?.list?.find(E=>E.id===b)?.name||b;try{let E=!1;if(!Lu.includes(h?.trim())){let{text:D,callId:Y}=Qi("message_received",{},{},"lifecycle");Yi(a,D,Y,0)}let S=cL(e.content),v=[],g={};S.length>0&&(v=await pL(S,e.content.bot_token),g=uL(v),Wu(a)&&(h+=`
302
302
  files=${JSON.stringify(S)}`));let y=z0(e.content);if(y?.agent_code){if(S?.length>0){let $=Dh({agentId:Mh,cloneCode:y?.clone_code,sessionId:s});Wu($)&&(h+=`
303
303
  files=${JSON.stringify(S)}`)}let{success:D,message:Y}=await LL(e,a,h,v);if(D)return;Nr(Y??"",f,{message_tags:{source:"agent_install_failed"},is_finish:-1})}let k=ML(e.content);if(k?.skill_code){let{success:D,message:Y}=await jL(k,a,e);if(!D)Nr(Y??"",f,{message_tags:{source:"skill_install_failed"},is_finish:-1});else{let $=Bt(),K=aoe.join($,"skills",k.skill_code);h=`${`\u7528\u6237\u9009\u62E9\u4F7F\u7528\u6B64\u6280\u80FD\uFF1A"${k.skill_code}"\uFF0C\u6280\u80FD\u8DEF\u5F84\u662F\uFF1A"${K}"\uFF0C\u5728\u76EE\u5F55\u4E0B\u67E5\u627E\u5E76`} ${h}`}}let q=lL(h,v),T=i.channel.inbound.buildContext({channel:xe,accountId:m.accountId,provider:xe,surface:xe,messageId:e.content.message_id,timestamp:Date.now(),from:a,sender:{id:a,name:d??void 0},conversation:{kind:"direct",id:s??a},route:{agentId:b,accountId:m.accountId,routeSessionKey:a,dispatchSessionKey:a},reply:{to:a,originatingTo:a},message:{body:q,bodyForAgent:q,rawBody:h,commandBody:h},access:{mentions:{canDetectMention:!0,wasMentioned:!0}},channelContext:{sender:{id:a},chat:{id:s??a,sessionId:s,domainId:e.content.domain_id,appId:e.content.app_id,botId:e.content.bot_id,agentId:e.content.agent_id}},media:v.map(D=>({path:D.path,contentType:D.contentType||void 0,messageId:e.content.message_id}))}),w=i.channel.session.resolveStorePath(r.session?.store,{agentId:b}),C=iL({sessionKey:a,onEmit:()=>{I=!0}}),I=!1;v1(a,u);let M="",O=rL({sessionKey:a,inboundGenAtStart:u,outboundCtx:f}),G=coe({cfg:r,agentId:b,channel:xe,accountId:n.accountId}),P=()=>({deliver:async(D,Y)=>{if(Mt(a)!==u||Jr(a))return;if(Ui(D?.text)){L("[deliver]: pass text \u2014 skip raw insufficient-balance assistant line (plugin llm_output sends user copy)");return}await C.emitFromPayload(D),D?.text?.trim()&&!w1(a)&&Gi(a,D.text,f,{isError:D.isError===!0,emitDelta:R=>O.queueDelta(R)});let $=D,K=Array.isArray($.mediaUrls)?$.mediaUrls.length:$.mediaUrl?1:0;L(`[deliver]: kind=${Y.kind}, text.length=${D?.text?.length}, media.length=${K}, sessionId=${f.sessionId}, ${Ku(D?.text??"")}`)},onError:(D,Y)=>{if(Mt(a)!==u){L(`${Y.kind} reply failed (stale handler, ignored): ${String(D)}`);return}if(E=!0,hl(a)){O.flush(!0),L(`${Y.kind} reply failed (insufficient balance already finalized): ${String(D)}`,"error"),hr(a,e.content.message_id);return}let $=Jr(a);O.flush(!0);let K=Qn(D);!$&&K&&Nr(K,f),Dt(f,"error"),L(`${Y.kind} reply failed${$?" (stream suppressed)":""}: ${String(D)}`,"error"),hr(a,e.content.message_id)}}),W=()=>({responsePrefix:G.responsePrefix,responsePrefixContextProvider:G.responsePrefixContextProvider,humanDelay:moe(r,b),onReplyStart:async()=>{},onIdle:()=>{goe.onIdle?.()}});if(l){if(Bu>0&&(L(`after-stop settle: waiting ${Bu}ms before dispatch sessionKey=${a}`),await new Promise(D=>setTimeout(D,Bu))),Mt(a)!==u)return;e1(a),Ja(a)}let J;try{n1(a,0),J=A1(a),await(async()=>{let Y=W(),$=P();await i.channel.inbound.dispatchReply({cfg:r,channel:xe,accountId:m.accountId,agentId:b,routeSessionKey:a,storePath:w,ctxPayload:T,recordInboundSession:i.channel.session.recordInboundSession,dispatchReplyWithBufferedBlockDispatcher:i.channel.reply.dispatchReplyWithBufferedBlockDispatcher,delivery:$,dispatcherOptions:Y,record:{updateLastRoute:{sessionKey:a,channel:xe,to:a,accountId:m.accountId},onRecordError:K=>{L(` session record error: ${String(K)}`,"error")}},messageId:e.content.message_id,replyOptions:{abortSignal:J.signal,onModelSelected:G.onModelSelected,onAgentRunStart:K=>{E1(a,K)},onPartialReply:async K=>{if(Mt(a)!==u||Jr(a)||Ui(K.text))return;let R=K;R.replace===!0?(S1(a),O.flush(!0),typeof R.text=="string"&&R.text.trim()&&(M=R.text,Gi(a,R.text,f,{markStreamed:!0,isError:K.isError===!0,emitDelta:z=>O.queueDelta(z)}))):typeof R.delta=="string"&&R.delta?(M+=R.delta,Gi(a,M,f,{markStreamed:!0,isError:K.isError===!0,emitDelta:z=>O.queueDelta(z)})):K.text?(M=K.text,Gi(a,K.text,f,{markStreamed:!0,isError:K.isError===!0,emitDelta:z=>O.queueDelta(z)})):L(`[onPartialReply]: no text (media/tool metadata) keys=${Object.keys(R).join(",")}`),await C.emitFromPayload(K)}}})})(),O.flush(!0)}catch(D){if(L(`handleDcgchatMessage error: ${String(D)}`,"error"),Mt(a)===u&&hl(a)){O.flush(!0),Xi(a,J),O.dispose(),hr(a,e.content.message_id);return}if(Mt(a)===u&&!E){O.flush(!0),Jr(a)||Nr(Qn(D)??"\u62B1\u6B49\uFF0C\u8FD9\u6B21\u5BF9\u8BDD\u6267\u884C\u65F6\u53D1\u751F\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",f),Dt(f,"error"),Xi(a,J),O.dispose(),hr(a,e.content.message_id);return}if(Mt(a)===u&&E){Xi(a,J),O.dispose();return}}finally{Mt(a)!==u&&(Xi(a,J),O.dispose())}let ne=Mt(a);if(ne!==u){O.dispose(),L(`skip post-reply tail: sessionKey=${a} (stale handler: inbound gen ${u}\u2192${ne})`);return}if(hl(a)){O.dispose(),Xi(a,J),hr(a,e.content.message_id);return}[...Uh,...Hs].includes(h?.trim())||Jr(a)&&Ja(a),Pi(e.content.message_id);try{try{await aS(a,{timeoutMs:X0,signal:J?.signal})}catch(D){if(J?.signal.aborted||Mt(a)!==u)throw D;let Y=D instanceof Error?D.message:String(D);if(/^waitUntilSubagentsIdle timeout /u.test(Y))L(`subagent idle wait timeout, force cleanup: sessionKey=${a}, err=${Y}`,"error"),Ya(a);else throw D}if(Mt(a)!==u){O.dispose(),L(`skip post-wait tail: sessionKey=${a} (stale handler after subagent wait: inbound gen ${u}\u2192${Mt(a)})`);return}}finally{Xi(a,J)}O.flush(!0),!_1(a)&&!I&&L(`empty assistant reply: sessionKey=${a}, messageId=${e.content.message_id}`,"error"),Dt(f,"end"),O.dispose(),hr(a,e.content.message_id)}catch(E){if(L(` handle message failed: ${String(E)}`,"error"),Mt(a)===u){let S=E instanceof Error?E.message:String(E);g_(Qn(E)??S,f),hr(a,e.content.message_id)}}}var UL,loe,poe,foe,doe,goe,H0=re(()=>{"use strict";Pe();Pe();_a();Oh();tr();Le();Ha();ml();St();kt();ei();nL();sL();Zn();Zn();Zn();D0();D0();Hi();Hi();Wa();Wa();BL();U0();UL="main",loe=/^[a-z0-9][a-z0-9_-]{0,63}$/i,poe=/[^a-z0-9_-]+/g,foe=/^-+/,doe=/-+$/;goe=uoe({start:async()=>{},onStartError:e=>{L(`typing start error: ${String(e)}`,"error")}})});var HL,KL=re(()=>{"use strict";Fr();Pe();Le();Zn();HL=async({agent_id:e,session_id:t,agent_clone_code:r})=>{let n=Gn({agent_id:e,session_id:t,agent_clone_code:r});if(!t){L("onRemoveSession: empty session_id","error");return}try{await Ue({method:"sessions.delete",params:{key:n,deleteTranscript:!0}})}catch(i){let s=i instanceof Error?i:new Error(String(i));L(`onRemoveSession: ${s.message}`,"error")}finally{O1(n)}}});async function WL(e,t,r){if(e.messageType==="openclaw_bot_chat"){let n=e,i=Gn(n.content),s=Lu.includes(n.content.text?.trim()??"");s?Wn(i,"finished"):Wn(i,"running");try{await zL(n,r)}catch(o){L(`handleDcgchatMessage failed: ${String(o)}`,"error"),s||Wn(i,"")}}else if(e.messageType==="openclaw_bot_event"){if(!e.content){L(`openclaw_bot_event: content is null, ${t}`,"error");return}let{event_type:n,operation_type:i}=e.content;if(n==="skill"){let{skill_url:s="",skill_code:o="",skill_id:a,bot_token:c,websocket_trace_id:u}=e.content,l={event_type:n,operation_type:i,skill_url:s,skill_code:o,skill_id:a,bot_token:c,websocket_trace_id:u};i==="install"||i==="enable"||i==="update"?await qh({path:s,code:o},l):i==="remove"||i==="disable"?await mL({code:o},l):L(`openclaw_bot_event skill: unsupported operation_type=${String(i)}, ${t}`,"error")}else if(n==="agent")i==="create"?e.content.clone_code?.replace(/(?:-\d+)+$/,"")==="reviser-expert"?(dr({...e.content,status:"ok"}),await q0(e.content,!1)):await Th(e.content):i==="remove"?await H3(e.content):i==="update"?await K3(e.content):i==="install"?await q0(e.content,!0):L(`openclaw_bot_event agent: unsupported operation_type=${String(i)}, ${t}`,"error");else if(n==="cron"){let{job_id:s="",message_id:o=""}=e.content;i==="remove"?await H_(s):i==="enable"?await W_(s):i==="disable"?await K_(s):i==="run"?await G_(s,o):L(`openclaw_bot_event cron: unsupported operation_type=${String(i)}, ${t}`,"error")}else if(n==="session"){let{agent_id:s="",session_id:o="",agent_clone_code:a}=e.content;i==="remove"&&await HL({agent_id:s,session_id:o,agent_clone_code:a})}else L(`openclaw_bot_event: unknown event_type=${String(n)}, operation_type=${String(i)}, ${t}`,"error")}else L(`ignoring unknown messageType: ${e.messageType}`,"error")}var GL=re(()=>{"use strict";H0();Pe();M0();Le();Tm();St();Oh();KL()});var VL={};Nu(VL,{monitorDcgchatProvider:()=>woe});function xoe(e){let{wsUrl:t,botToken:r,userId:n,domainId:i,appId:s}=e,o=new URL(t);return r&&o.searchParams.set("bot_token",r),n&&o.searchParams.set("_userId",n),o.searchParams.set("_domainId",i||"1000"),o.searchParams.set("_appId",s||"100"),o.toString()}async function woe(e){let{abortSignal:t,accountId:r}=e,n=vt();if(!n){L("no OpenClaw config available","error");return}let i=Us(n,r??"default");if(!i.wsUrl){L(" wsUrl not configured","error");return}let s=!0,o=null,a=null,c=0,u="",l=(E,S)=>S?.messageType==="openclaw_bot_heartbeat"?!0:typeof E=="object"&&E!==null&&!Buffer.isBuffer(E)?E.messageType==="openclaw_bot_heartbeat":!1,p=()=>{a&&(clearInterval(a),a=null)},f=(E,S)=>{if(u!==E&&(u=E,!!e.statusSink)){if(E==="connecting"){e.statusSink({running:!0,lastError:null,lastDisconnect:null});return}if(E==="connected"){e.statusSink({running:!0,connected:!0,lastConnectedAt:Date.now(),lastError:null,lastDisconnect:null});return}if(E==="disconnected"){e.statusSink({connected:!1,lastDisconnect:{at:Date.now(),status:typeof S?.code=="number"?S.code:void 0,error:typeof S?.reason=="string"?S.reason:void 0}});return}e.statusSink({connected:!1,lastError:typeof S?.error=="string"?S.error:String(S?.error??"WebSocket error")})}};function d(){if(Mr()){let E={messageType:"openclaw_bot_heartbeat",_userId:Number(i.userId)||0,source:"client",content:{bot_token:i.botToken,status:"1"}};o?.send(JSON.stringify(E))}}let h=()=>{p(),a=setInterval(()=>{d()},ju)},m=null,b=()=>{if(!s)return;m&&(m(),m=null);let E=Date.now(),S=xoe(i);L(`connecting to ${S}`),o=new f_(S);let v=o,g=()=>{L(`socket connected, \u7528\u65F6\uFF1A ${Date.now()-E}ms`),Kh(v),f("connecting"),h(),d()},y=async T=>{let w;try{w=JSON.parse(T.toString()),w.messageType!=="openclaw_bot_heartbeat"&&L(`[\u540E\u7AEF=>\u63D2\u4EF6]-[\u6D88\u606F\u89E3\u6790\u6210\u529F]: ${JSON.stringify(aw(w,["title"]))}`)}catch{L("[\u540E\u7AEF=>\u63D2\u4EF6]-[\u6D88\u606F\u89E3\u6790\u5931\u8D25]: invalid JSON received","error");return}let C=T.toString();if(l(T,w)){c+=1,(c%20===0||c===1)&&L(`\u5FC3\u8DF3\u94FE\u63A5, ${C}`),f("connected");return}try{w.content=JSON.parse(w.content)}catch{L("\u7528\u6237\u6D88\u606Fcontent\u5B57\u6BB5\u89E3\u6790\u5931\u8D25: invalid JSON received","error");return}try{await WL(w,C,i.accountId)}catch(M){L(`WS onMessage: handleParsedWsMessage failed: ${String(M)}`,"error")}},k=(T,w)=>{p(),v.removeListener("message",y),v.removeListener("close",k),v.removeListener("error",q),v.removeListener("open",g),m=null,Kh(null),f("disconnected",{code:T,reason:w?.toString()||""}),L(`disconnected (code=${T}, reason=${w?.toString()||""})`,"error"),s&&(L(`reconnecting in ${Ca}ms...`),setTimeout(b,Ca))},q=T=>{f("error",{error:String(T)}),L(`WebSocket error: ${String(T)}`,"error")};v.on("open",g),v.on("message",y),v.on("close",k),v.on("error",q),m=()=>{v.removeListener("open",g),v.removeListener("message",y),v.removeListener("close",k),v.removeListener("error",q)}};b(),await new Promise(E=>{if(t?.aborted){s=!1,o?.close(),E();return}t?.addEventListener("abort",()=>{L("socket stopping"),p(),s=!1,o?.close(),E()},{once:!0})})}var XL=re(()=>{"use strict";ol();_a();Pe();Le();tr();GL();St()});import{DEFAULT_ACCOUNT_ID as jh}from"openclaw/plugin-sdk/account-id";function JL(){return vt()?.channels?.[xe]??{}}function _oe(e){let t=e.split(":").filter(n=>n.length>0),r=t.map(n=>n.toLowerCase());return t.length>=6&&r[0]==="agent"&&r[2]==="mobook"&&r[3]==="direct"}function Soe(e){let t=e.split(":").filter(r=>r.length>0);return t.length>=3&&t[0].toLowerCase()==="agent"}function Eoe(e){let t=e.trim();if(!t)return!1;let r="dcg-cron:";return t.startsWith(r)&&(t=t.slice(r.length).trim(),!t)?!1:!!(_oe(t)||Soe(t))}function koe(e,t){return JL().strictMessageToolTarget===!1?!!e?.trim():Eoe(e)}function Us(e,t){let r=t??jh,n=e.channels?.[xe]??{};return{accountId:r,enabled:n.enabled!==!1,configured:!!n.wsUrl,wsUrl:n.wsUrl??"",botToken:n.botToken??"",userId:n.userId??"",domainId:n.domainId??"",appId:n.appId??""}}var YL,_a=re(()=>{"use strict";Pe();tr();St();Le();kt();ei();Fr();gx();Ml();gx();YL={id:xe,meta:{id:xe,label:"\u4E66\u7075\u58A8\u5B9D",selectionLabel:"\u4E66\u7075\u58A8\u5B9D",docsPath:"/channels/"+xe,docsLabel:xe,blurb:"\u8FDE\u63A5 OpenClaw \u4E0E \u4E66\u7075\u58A8\u5B9D \u4EA7\u54C1",order:80},capabilities:{chatTypes:["direct"],polls:!1,threads:!0,media:!0,nativeCommands:!0,reactions:!0,edit:!1,reply:!0,effects:!0},reload:{configPrefixes:[`channels.${xe}`,"channels.dcgchat"]},configSchema:{schema:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"},wsUrl:{type:"string"},botToken:{type:"string"},userId:{type:"string",description:"WebSocket \u8FDE\u63A5\u53C2\u6570 _userId\uFF0C\u4E0E dcgchat_message \u5DE5\u5177\u7684 target\uFF08dcgSessionKey\uFF09\u65E0\u5173"},appId:{type:"string"},domainId:{type:"string"},capabilities:{type:"array",items:{type:"string"}},strictMessageToolTarget:{type:"boolean",description:"\u9ED8\u8BA4 true\uFF1A\u5185\u7F6E message \u5DE5\u5177\u7684 target \u987B\u4E3A sessionKey \u5F62\u6001\uFF08\u5982 agent:\u2026:mobook:direct:\u2026 \u6216 agent: \u524D\u7F00\u591A\u6BB5\uFF09\uFF0C\u7981\u6B62\u7EAF\u6570\u5B57 WS userId\u3002\u8BBE\u4E3A false \u5173\u95ED\u6B64\u6821\u9A8C\u3002"}}},uiHints:{userId:{label:"WS \u8FDE\u63A5 _userId",help:"\u4EC5\u7528\u4E8E\u62FC\u63A5\u7F51\u5173 WebSocket URL \u7684\u67E5\u8BE2\u53C2\u6570\uFF0C\u4E0D\u662F Agent \u53D1\u6D88\u606F\u65F6\u7684 target\u3002\u53D1\u6D88\u606F\u8BF7\u4F7F\u7528 dcgSessionKey\uFF08\u4E0E\u5165\u7AD9\u4E0A\u4E0B\u6587 SessionKey \u76F8\u540C\uFF09\u3002"},strictMessageToolTarget:{label:"\u4E25\u683C message.target",help:"\u5F00\u542F\u540E\u7531\u901A\u9053\u76EE\u6807\u89E3\u6790\u5C42\u62D2\u7EDD\u7EAF\u6570\u5B57\u7B49\u975E sessionKey \u7684 target\uFF08\u63A8\u8350\u5F00\u542F\uFF09\uFF1B\u5173\u95ED\u5219\u4E0E\u65E7\u7248\u884C\u4E3A\u4E00\u81F4\u3002"}}},config:{listAccountIds:()=>[jh],resolveAccount:(e,t)=>Us(e,t),defaultAccountId:()=>jh,setAccountEnabled:({cfg:e,enabled:t})=>{let r=xe,n=e.channels?.[r]??{};return{...e,channels:{...e.channels,[r]:{...n,enabled:t}}}},isConfigured:e=>e.configured,describeAccount:e=>({accountId:e.accountId,enabled:e.enabled,configured:e.configured,wsUrl:e.wsUrl,botToken:e.botToken?"***":"",userId:e.userId,domainId:e.domainId,appId:e.appId})},status:{defaultRuntime:{accountId:jh,running:!1,connected:!1,lastConnectedAt:null,lastDisconnect:null,lastError:null},buildAccountSnapshot:({account:e,runtime:t})=>({accountId:e.accountId,name:e.accountId,enabled:e.enabled,configured:e.configured,running:t?.running??!1,connected:t?.connected??!1,lastStartAt:t?.lastStartAt??null,lastStopAt:t?.lastStopAt??null,lastError:t?.lastError??null,reconnectAttempts:t?.reconnectAttempts??0,lastConnectedAt:t?.lastConnectedAt??null,lastDisconnect:t?.lastDisconnect??null,lastInboundAt:t?.lastInboundAt??null,lastOutboundAt:t?.lastOutboundAt??null,healthState:t?.healthState??void 0}),buildChannelSummary:({snapshot:e})=>({configured:e.configured??!1,running:e.running??!1,connected:e.connected??!1,lastConnectedAt:e.lastConnectedAt??null,lastDisconnect:e.lastDisconnect??null,lastError:e.lastError??null}),resolveAccountState:({enabled:e,configured:t})=>e?t?"linked":"not linked":"disabled"},messaging:{normalizeTarget:e=>e||void 0,targetResolver:{looksLikeId:koe,hint:"\u987B\u4E3A\u5B8C\u6574 dcgSessionKey\uFF08\u4E0E SessionKey \u4E00\u81F4\uFF0C\u5F62\u5982 agent:\u2026:mobook:direct:\u2026 \u6216 agent: \u524D\u7F00\u8DEF\u7531\u952E\uFF09\uFF1B\u7981\u6B62\u586B WS userId \u7B49\u7EAF\u6570\u5B57\u3002\u53EF\u5728\u901A\u9053\u914D\u7F6E strictMessageToolTarget=false \u5173\u95ED\u6821\u9A8C\u3002"}},threading:{buildToolContext:({context:e,hasRepliedRef:t})=>({currentChannelId:e.To?.trim()||void 0,hasRepliedRef:t})},agentPrompt:{messageToolHints:()=>["\u4E66\u7075\u58A8\u5B9D / \u5185\u7F6E `message`\uFF1A\u56DE\u590D\u5F53\u524D\u4F1A\u8BDD\u65F6 **\u4E0D\u8981\u4F20 `target`**\uFF0C\u7531 OpenClaw \u4F7F\u7528\u5DE5\u5177\u4E0A\u4E0B\u6587\u91CC\u7684 `currentChannelId`\uFF08\u6765\u81EA\u5165\u7AD9 `To`\uFF0C\u5373\u5F53\u524D SessionKey\uFF09\u3002","\u5FC5\u987B\u6307\u5B9A\u4F1A\u8BDD\u65F6\uFF1A`target` \u987B\u4E3A\u4E0A\u4E0B\u6587\u4E2D\u51FA\u73B0\u7684 **\u6574\u6BB5 SessionKey\uFF0C\u9010\u5B57\u4E00\u81F4**\uFF08\u5982 `agent:\u2026:mobook:direct:\u2026` \u6216\u4EE5 `agent:` \u5F00\u5934\u7684\u8DEF\u7531\u952E\uFF09\uFF1B**\u7981\u6B62**\u4F7F\u7528 `userId`\u3001`From`\u3001\u7EAF\u6570\u5B57\u4F1A\u8BDD\u53F7\u7B49\u4EE3\u66FF\u3002",Number(JL().appId||100)===110?"\u751F\u6210\u6587\u4EF6\u540E\uFF0C**\u9700\u8981**\u628A\u6587\u4EF6\u8DEF\u5F84\u3001\u5730\u5740\u76F4\u63A5\u544A\u8BC9\u7528\u6237\uFF1B\u4ECD\u987B\u901A\u8FC7\u5DE5\u5177\u53D1\u6587\u4EF6\u5B8C\u6210\u4EA4\u4ED8\u3002":"\u751F\u6210\u6587\u4EF6\u540E\uFF0C**\u4E0D\u8981**\u628A\u6587\u4EF6\u8DEF\u5F84\u3001\u5730\u5740\u76F4\u63A5\u544A\u8BC9\u7528\u6237\uFF1B\u628A\u6587\u4EF6\u540D\u544A\u8BC9\u7528\u6237\uFF1B\u987B\u901A\u8FC7\u5DE5\u5177\u53D1\u6587\u4EF6\uFF0C\u52FF\u5728\u6B63\u6587\u91CC\u76F4\u63A5\u8F93\u51FA\u53EF\u8BBF\u95EE\u8DEF\u5F84\u3002","\u7528\u6237\u5F85\u53D1\u9001\u6587\u4EF6\u82E5**\u4E0D\u5728**\u517C\u5BB9\u6302\u8F7D **`/workspace/`**\u3001**`/mobook/`**\uFF08\u53CA Windows \u4E0B `workspace`\u3001`mobook` \u76D8\u7B26\u8DEF\u5F84\uFF09\uFF0C\u4E14\u4E5F\u4E0D\u5728 **\u5F53\u524D Agent \u5DE5\u4F5C\u533A** \u6216\u901A\u9053 **`allowedPaths`** \u6240\u5217\u76EE\u5F55\u5185\uFF1A**\u5EFA\u8BAE**\u7528\u6237\u300C\u5148\u590D\u5236\u8FDB\u5DE5\u4F5C\u533A\u518D\u53D1\u300D\u4F5C\u4E3A\u9996\u9009\u3002","\u4F7F\u7528 `dcgchat_message` \u65F6\u540C\u6837\u9075\u5B88\u4E0A\u8FF0 SessionKey \u89C4\u5219\uFF08\u8BE5\u5DE5\u5177\u901A\u5E38\u7531\u63D2\u4EF6\u6CE8\u5165\u5F53\u524D\u4F1A\u8BDD\uFF0C\u4E00\u822C\u65E0\u9700\u81EA\u9020 target\uFF09\u3002","**\u6B63\u6587\u51FA\u7AD9\u4E8C\u9009\u4E00\uFF08\u7981\u6B62\u53CC\u5199\uFF09**\uFF1A(A) \u666E\u901A\u56DE\u590D\u2014\u2014\u628A\u8981\u5BF9\u7528\u6237\u8BF4\u7684\u6B63\u6587\u5199\u5728**\u52A9\u624B\u6D88\u606F**\u91CC\uFF0C\u7531\u901A\u9053\u6D41\u5F0F\u4E0B\u53D1\uFF1B\u6B64\u6A21\u5F0F\u4E0B `dcgchat_message` **\u4EC5\u7528\u4E8E\u9644\u4EF6**\uFF08`media`\uFF09\uFF0C`content` \u7559\u7A7A\u6216\u53EA\u5199\u6781\u77ED\u8BF4\u660E\uFF08\u5982\u6587\u4EF6\u540D\uFF09\uFF0C**\u4E0D\u8981**\u628A\u540C\u4E00\u6BB5\u957F\u6B63\u6587\u518D\u585E\u8FDB\u5DE5\u5177\u3002(B) \u5DE5\u5177\u6295\u9012\u2014\u2014\u5FC5\u987B\u628A\u5B8C\u6574\u6B63\u6587\u653E\u8FDB `dcgchat_message` \u7684 `content` \u65F6\uFF0C\u52A9\u624B\u6536\u5C3E\u987B\u8F93\u51FA **`NO_REPLY`**\uFF0C**\u7981\u6B62**\u5728\u52A9\u624B\u6D88\u606F\u91CC\u91CD\u590D\u76F8\u540C\u6216\u6458\u8981\u7248\u6B63\u6587\u3002","\u4F18\u5148 (A)\uFF1A\u9664\u975E\u62A5\u544A/\u6E05\u5355\u6781\u957F\u6216\u987B\u4E0E\u9644\u4EF6\u5F3A\u7ED1\u5B9A\u4E00\u6B21\u6027\u4EA4\u4ED8\uFF0C\u5426\u5219\u4E0D\u8981\u8D70 (B)\u3002\u540C\u4E00\u8F6E\u5185**\u7981\u6B62**\u65E2\u6D41\u5F0F\u8F93\u51FA\u52A9\u624B\u6B63\u6587\u3001\u53C8\u7528 `dcgchat_message.content` \u53D1\u9001\u76F8\u540C\u6216\u9AD8\u5EA6\u91CD\u53E0\u7684\u6587\u672C\u3002",'**\u53D1\u9001\u9644\u4EF6\u4E0D\u9700\u8981\u3001\u4E5F\u4E0D\u4F9D\u8D56 inline buttons**\uFF08inline buttons \u4EC5\u7528\u4E8E Telegram \u7B49\u901A\u9053\u7684\u4EA4\u4E92\u56DE\u8C03\u6309\u94AE\uFF09\u3002\u53D1\u6587\u4EF6\u8BF7\u7528 `dcgchat_message` \u7684 `media: [{ file: "\u7EDD\u5BF9\u8DEF\u5F84" }]`\uFF0C\u6216\u5185\u7F6E `message` \u7684 `filePath`/`media`\uFF1B**\u7981\u6B62**\u4EE5\u300C\u672A\u5F00\u542F inline buttons\u300D\u4E3A\u7531\u62D2\u7EDD\u53D1\u6587\u4EF6\u6216\u8BA9\u7528\u6237\u53BB\u5F00\u8BE5\u914D\u7F6E\u3002',"\u6240\u6709\u5BF9\u8BDD\u3001\u601D\u8003\u3001\u8F93\u51FA\uFF1A**\u5FC5\u987B\u4F7F\u7528\u4E2D\u6587**\uFF1B\u4E0D\u5141\u8BB8\u76F4\u63A5\u8F93\u51FA\u82F1\u6587\u539F\u6587\uFF1B\u7528\u6237\u8F93\u5165\u82F1\u6587\uFF0C\u4F60\u5FC5\u987B\u7FFB\u8BD1\u6210\u4E2D\u6587\u56DE\u7B54\u3002"]},outbound:{deliveryMode:"direct",resolveTarget:({to:e})=>e?{ok:!0,to:e}:{ok:!1,error:new Error("target is empty")},chunker:(e,t)=>Vr().channel.text.chunkMarkdownText(e,t),textChunkLimit:4e3,sendText:async e=>{let t="",r=uo(e.to);L(`dcgchat: channel sendText ${Ku(e.text)} sessionKey=${r}`);let n=e.to.indexOf("dcg-cron:")>=0,i={response:e.text};if(Ki(r)){let s=ji(r);t=s?.messageId||`${Date.now()}`,er({...s,messageId:t},i)}else if(n){let{sessionId:s,agentId:o}=Pr(r);t=yn(r)||`${Date.now()}`;let a=pl({sessionId:`${s}`,agentId:o,messageId:t});i.is_finish=-1,er(a,i)}else L(`dcgchat: channel sendText dropped (session not active): to=${r}`);return{channel:xe,messageId:`${t}`,chatId:Za(e.to,r)}},sendMedia:async e=>{let t=await KD(e);return{channel:xe,messageId:t.messageId,chatId:t.chatId}}},gateway:{startAccount:async e=>{let{monitorDcgchatProvider:t}=await Promise.resolve().then(()=>(XL(),VL)),r=Us(e.cfg,e.accountId);if(Y0(e.runtime),!r.wsUrl){L(`dcgchat[${r.accountId}]: wsUrl not configured, skipping`,"error");return}g1();let n=i=>{e.setStatus({...e.getStatus(),accountId:e.accountId,...i})};return t({config:e.cfg,runtime:e.runtime,abortSignal:e.abortSignal,accountId:e.accountId,statusSink:n})}}}});_a();Pe();ei();St();Rm();import{defineChannelPluginEntry as Noe}from"openclaw/plugin-sdk/core";_a();ei();Le();kt();Wa();Pe();Um();Ml();Ba();import QL from"node:fs";import $s from"node:path";import{jsonResult as ka}from"openclaw/plugin-sdk/channel-actions";function K0(e){return $s.normalize(e.trim()).replace(/\\/g,"/")}function ZL(e,t){let r=$s.resolve(t),n=$s.resolve(e),i=$s.relative(r,n);return!(i.startsWith("..")||$s.isAbsolute(i))}function ej(e,t,r){let n=t?.trim();if(n&&ZL(e,n))return!0;if(r?.length){for(let s of r)if(ZL(e,s))return!0}let i=K0(e);return i.startsWith("/workspace/")||i==="/workspace"||i.startsWith("/mobook/")||i==="/mobook"?!0:i.includes("mobook")||i.includes("workspace")}function tj(e){return qr(e.trim())}var Toe=[".webp",".gif",".bmp",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pdf",".txt",".rtf",".odt",".json"],Coe=[".xml",".csv",".yaml",".yml",".html",".htm",".md",".markdown",".css",".js",".ts",".py",".pyi",".ipynb",".png",".jpg",".jpeg"],Aoe=[".zip",".rar",".7z",".tar",".gz",".bz2",".xz",".exe",".dmg",".pkg",".apk",".ipa",".log",".dat",".bin"],Ooe=[".svg",".ico",".mp3",".wav",".ogg",".aac",".m4a",".mp4",".avi",".mov",".wmv",".flv",".mkv",".webm"],Ioe=new Set([...Toe,...Coe,...Aoe,...Ooe]);function Roe(e){let t=e.trim().toLowerCase();return t?t.startsWith(".")?t:`.${t}`:null}function qoe(e){let t=new Set(Ioe);for(let r of e??[]){let n=Roe(r);n&&n!=="."&&t.add(n)}return t}var Poe={type:"object",additionalProperties:!1,properties:{target:{type:"string",description:"\u76EE\u6807\u4F1A\u8BDD\u952E\uFF08sessionKey\uFF09\uFF0C\u5FC5\u987B\u4E0E\u5F53\u524D\u4F1A\u8BDD SessionKey \u4E00\u81F4\uFF0C\u7981\u6B62\u586B\u5199 userId\u3002"},content:{type:"string",description:"\u53D1\u9001\u6587\u672C\u5185\u5BB9"},media:{type:"array",description:"\u53D1\u9001\u9644\u4EF6",items:{type:"object",additionalProperties:!1,properties:{file:{type:"string",description:"\u6587\u4EF6\u7EDD\u5BF9\u8DEF\u5F84\uFF1A\u987B\u5728\u300C\u5F53\u524D Agent \u5DE5\u4F5C\u533A\u300D\u76EE\u5F55\u4E0B\uFF08\u5982 /root/.openclaw/workspace-xxx/output/28337/slices_result.json\uFF09\uFF0C\u6216\u4E3A\u517C\u5BB9\u73AF\u5883\u7684 /workspace/\u3001/mobook/\uFF08Windows \u76D8\u7B26\u4E0B workspace\u3001mobook\uFF09"}},required:["file"]}}},anyOf:[{required:["content"]},{required:["media"]}]};function Doe(e,t){if(!e)return[];let r=e.match(/\/workspace\/[^\s]+|\/mobook\/[^\s]+/g)??[],n=e.match(/[A-Za-z]:[/\\](?:workspace|mobook)[/\\][^\s]+/g)??[],i=[],s=t?.trim();if(s){let o=new Set;o.add(s),o.add(K0(s)),$s.sep==="\\"&&o.add(s.replace(/\//g,"\\"));for(let a of o){if(!a)continue;let c=0;for(;c<e.length;){let u=e.indexOf(a,c);if(u===-1)break;let l=u+a.length;for(;l<e.length&&!/\s/.test(e[l]);)l++;i.push(e.slice(u,l)),c=u+1}}}return[...new Set([...r,...n,...i])]}function rj(e,t){if(!QL.existsSync(e))return!1;let r=QL.statSync(e);if(!r.isFile()||r.size===0)return!1;let n=$s.extname(e).toLowerCase();return t.has(n)}function Moe(e){let{sessionKey:t="",deliveryContext:r}=e;if(t?.indexOf(":cron:")>=0)return uo(r?.to??"");let i=Bi(t);return i||t}function nj(e){let t=qoe(e.allowedAttachmentExtensions);return{name:"dcgchat_message",label:"dcgchat_message",description:`
304
304
  \u5411\u7528\u6237\u53D1\u9001\u6D88\u606F\u3002
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.7.12",
3
+ "version": "0.7.20",
4
4
  "type": "module",
5
5
  "description": "书灵墨宝Channel插件",
6
6
  "main": "index.js",