diff --git a/CHANGELOG.md b/CHANGELOG.md index b5e05b0..5bdaac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,18 @@ This file records the notable changes in each dsh-im release. Its format follows ## [Unreleased] +## [2.6.0] - 2026-08-25 + +### Added / 新增 + +- 飞书、钉钉、Slack、Telegram、Discord 和 WhatsApp 现在会通过消息 Reaction 显示任务正在处理、成功或失败;Reaction 调用采用限时的尽力而为机制,不会阻塞正常回复。Slack App Manifest 同步加入 `reactions:write`,已有 App 需要重新授权或安装后再连接机器人。 + Feishu, DingTalk, Slack, Telegram, Discord, and WhatsApp now use message reactions to show processing, success, or failure. Reaction calls are time-bounded and best-effort, so they never block normal replies. The Slack App Manifest now includes `reactions:write`; existing Apps must be re-authorized or reinstalled before reconnecting the bot. + +### Fixed / 修复 + +- 当交互答案提交或后续交互问题发送失败时,消息会保留失败 Reaction,不再被外层处理流程覆盖为成功状态。 + When submitting an interaction answer or presenting a follow-up interaction question fails, the message now retains its failure reaction instead of being overwritten as successful by the outer processing flow. + ## [2.5.0] - 2026-08-25 ### Added / 新增 @@ -326,7 +338,8 @@ This file records the notable changes in each dsh-im release. Its format follows - 改进 npm 发布包结构,保留 CLI 入口并避免安装脚本拦截。 Improved npm package contents to preserve the CLI entry point and avoid install-script blocking. -[Unreleased]: https://github.com/xmanrui/dsh-im/compare/v2.5.0...HEAD +[Unreleased]: https://github.com/xmanrui/dsh-im/compare/v2.6.0...HEAD +[2.6.0]: https://github.com/xmanrui/dsh-im/compare/v2.5.0...v2.6.0 [2.5.0]: https://github.com/xmanrui/dsh-im/compare/v2.4.0...v2.5.0 [2.4.0]: https://github.com/xmanrui/dsh-im/compare/v2.3.0...v2.4.0 [2.3.0]: https://github.com/xmanrui/dsh-im/compare/v2.2.1...v2.3.0 diff --git a/lib/client.js b/lib/client.js index 83ccf23..4b1d779 100644 --- a/lib/client.js +++ b/lib/client.js @@ -47,7 +47,7 @@ var React20 = __toESM(require("react"), 1); // package.json var package_default = { name: "@xmanrui/dsh-im", - version: "2.5.0", + version: "2.6.0", description: "\u628A\u4E5D\u79CD IM \u673A\u5668\u4EBA\u548C\u516C\u7F51 AI Office \u63A5\u5165\u672C\u673A DeepSeek Harness\u3002 Connect nine IM channels and a public AI Office to a local DeepSeek Harness.", keywords: [ "deepseek-harness", diff --git a/lib/index.js b/lib/index.js index 31faf07..e507709 100644 --- a/lib/index.js +++ b/lib/index.js @@ -143,7 +143,7 @@ ${D("\u9519\u8BEF\u7801\uFF1A{code}\uFF1B\u53C2\u8003\u53F7\uFF1A{referenceId}", `:/^\s{0,3}(?:[-*+] |\d+[.)] |#{1,6} |\||> )/.test(o[a+1])?`${e} `:`${e}
`}).join("")}function _b(n,t){if(!n||typeof n!="object"||n.errcode!==0)throw new gt("registration-rejected",`\u9489\u9489\u626B\u7801${t}\u5931\u8D25\u3002`);return n}function Tb(n,t){let o=Number(n);return Number.isFinite(o)&&o>0?o:t}function _H({fetchImpl:n=fetch,registrationBaseUrl:t=process.env.DINGTALK_REGISTRATION_BASE_URL||SH,registrationSource:o=process.env.DINGTALK_REGISTRATION_SOURCE||Lge,now:i=()=>Date.now(),cardMinIntervalMs:e=50,cardBackoffMs:a=1e3,delay:A=Vge}={}){if(typeof n!="function")throw new TypeError("fetchImpl must be a function");if(typeof i!="function")throw new TypeError("now must be a function");if(!Number.isFinite(e)||e<0)throw new TypeError("cardMinIntervalMs must be a non-negative number");if(!Number.isFinite(a)||a<0)throw new TypeError("cardBackoffMs must be a non-negative number");if(typeof A!="function")throw new TypeError("delay must be a function");let r=Nb(t,{label:"\u9489\u9489\u6CE8\u518C\u670D\u52A1",requireSubdomain:!1}),s=new URL(Fge),g=WA(o);if(!g)throw new TypeError("registrationSource is required");let c=new Map,I=new Map,d=new Map,B=Promise.resolve(),f=0,Q=(H,J)=>new URL(J.replace(/^\//,""),H);async function y({clientId:H,clientSecret:J,signal:q,requestKind:U="normal"}){let R=WA(H),V=WA(J);if(!R||!V)throw new TypeError("clientId and clientSecret are required");let L=c.get(R);if(L&&L.expiresAt>i())return L.token;let T=U==="reaction"?d:I;if(T.has(R))return T.get(R);let W=(async()=>{let ie=await bn(n,Q(s,"v1.0/oauth2/accessToken"),{body:{appKey:R,appSecret:V},signal:q,action:"\u9274\u6743"}),ge=WA(ie?.accessToken);if(!ge)throw new gt("invalid-access-token","\u9489\u9489\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u8BBF\u95EE\u4EE4\u724C\u3002");let Se=Tb(ie?.expireIn??ie?.expiresIn,7200),de=Math.max(1e3,(Se-60)*1e3);return c.set(R,{token:ge,expiresAt:i()+de}),ge})().finally(()=>T.delete(R));return T.set(R,W),W}async function m({clientId:H,clientSecret:J,robotCode:q,messageId:U,conversationId:R,reactionName:V=zc,signal:L},T){let k=WA(H),W=WA(J),ie=WA(q)??k,ge=WA(U),Se=WA(R),de=WA(V);if(!k||!W)throw new TypeError("clientId and clientSecret are required");if(!ie)throw new TypeError("robotCode is required");if(!ge||!Se)throw new TypeError("messageId and conversationId are required");if(!de)throw new TypeError("reactionName is required");let De=await y({clientId:k,clientSecret:W,signal:L,requestKind:"reaction"}),fe=await bn(n,Q(s,`v1.0/robot/emotion/${T}`),{body:{robotCode:ie,openMsgId:ge,openConversationId:Se,emotionType:2,emotionName:de,textEmotion:{emotionId:xge,emotionName:de,text:de,backgroundId:Yge}},headers:{"x-acs-dingtalk-access-token":De},signal:L,timeoutMs:Kge,action:T==="reply"?"\u6D88\u606F\u72B6\u6001\u6DFB\u52A0":"\u6D88\u606F\u72B6\u6001\u64A4\u56DE"}),ve=fe?.success===!1?qh(fe?.code??fe?.errcode)??"rejected":bb(fe);if(ve)throw new gt("reaction-rejected","\u9489\u9489\u670D\u52A1\u62D2\u7EDD\u4E86\u6D88\u606F\u72B6\u6001\u8BF7\u6C42\u3002",{providerCode:ve});return!0}async function _({clientId:H,clientSecret:J,robotCode:q,downloadCode:U,signal:R,kind:V}){let L=WA(q),T=WA(U);if(!L||!T)throw new TypeError("robotCode and downloadCode are required");let k=await y({clientId:H,clientSecret:J,signal:R}),W;try{W=await bn(n,Q(s,"v1.0/robot/messageFiles/download"),{body:{downloadCode:T,robotCode:L},headers:{"x-acs-dingtalk-access-token":k},signal:R,action:`${V==="image"?"\u56FE\u7247":"\u6587\u4EF6"}\u4E0B\u8F7D\u5730\u5740`})}catch(ge){throw R?.aborted?ge:new gt(`${V}-download-address-failed`,`\u9489\u9489${V==="image"?"\u56FE\u7247":"\u6587\u4EF6"}\u4E0B\u8F7D\u5730\u5740\u83B7\u53D6\u5931\u8D25\u3002`,{cause:ge,status:ge?.status,providerCode:ge?.providerCode})}let ie=WA(W?.downloadUrl??W?.download_url);if(!ie)throw new gt(`invalid-${V}-download`,`\u9489\u9489\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE${V==="image"?"\u56FE\u7247":"\u6587\u4EF6"}\u4E0B\u8F7D\u5730\u5740\u3002`);return zge(ie)}function N(H){let J=async()=>{let U=Math.max(0,f-i());U>0&&await A(U,H),f=Math.max(f,i())+e},q=B.then(J,J);return B=q.catch(()=>{}),q}async function G(H,J){await N(J.signal);try{return await bn(n,Q(s,H),J)}catch(q){if(!(q instanceof gt)||q.status!==403)throw q;return await A(a,J.signal),await N(J.signal),bn(n,Q(s,H),J)}}async function Y({clientId:H,clientSecret:J,cardInstanceId:q,text:U,signal:R}){let V=WA(q),L=WA(U);if(!V)throw new TypeError("cardInstanceId is required");if(!L)throw new TypeError("text is required");let k={"x-acs-dingtalk-access-token":await y({clientId:H,clientSecret:J,signal:R})},W=[G("v1.0/card/streaming",{method:"PUT",body:{outTrackId:V,guid:Yh(),key:"msgContent",content:Jh(L),isFull:!0,isFinalize:!1,isError:!0},headers:k,signal:R,action:"AI Card \u5931\u8D25\u6536\u53E3"}),G("v1.0/card/instances",{method:"PUT",body:{outTrackId:V,cardData:Mb(L,"5"),cardUpdateOptions:{updateCardDataByKey:!0}},headers:k,signal:R,action:"AI Card \u5931\u8D25\u72B6\u6001"})],ie=await Promise.allSettled(W);if(ie.every(({status:ge})=>ge==="rejected"))throw ie[0].reason;return!0}async function j({clientId:H,clientSecret:J,target:q,file:U,signal:R},{uploadType:V,messageKey:L,createMessageParams:T}){if(!U||typeof U!="object"||typeof U.fileName!="string"||!U.fileName||!Buffer.isBuffer(U.bytes))throw new TypeError("A DingTalk file is required");let k=Zge(q),W;try{W=await y({clientId:H,clientSecret:J,signal:R})}catch(Re){if(R?.aborted)throw Mn(R);let AA=Number(Re?.status),ue=Re?.code==="http-error"&&AA>=400&&AA<500?"artifact-provider-rejected":"artifact-provider-failed";throw jh(Re,{fallback:ue})}let ie=new URL("media/upload",SH);ie.searchParams.set("access_token",W),ie.searchParams.set("type",V);let ge=new FormData;ge.append("media",new Blob([U.bytes],{type:U.mediaType??"application/octet-stream"}),U.fileName);let Se;try{Se=await Wge(n,ie,{body:ge,signal:R})}catch(Re){if(R?.aborted)throw Mn(R);let AA=Number(Re?.status),ue=Re?.code==="http-error"&&AA>=400&&AA<500?"artifact-provider-rejected":"artifact-provider-failed";throw jh(Re,{fallback:ue})}let de=bb(Se),De=WA(Se?.media_id);if(de||!De)throw jh(new gt("upload-rejected","\u9489\u9489\u670D\u52A1\u62D2\u7EDD\u4E86\u6587\u4EF6\u4E0A\u4F20\u3002",{providerCode:de??"missing-media-id"}));R?.throwIfAborted();let fe={robotCode:k.robotCode,msgKey:L,msgParam:JSON.stringify(T(De,U)),...k.type==="group"?{openConversationId:k.openConversationId}:{userIds:[k.userId]}},ve=k.type==="group"?"v1.0/robot/groupMessages/send":"v1.0/robot/oToMessages/batchSend",eA;try{eA=await bn(n,Q(s,ve),{body:fe,headers:{"x-acs-dingtalk-access-token":W},signal:R,action:"\u6587\u4EF6\u6D88\u606F\u53D1\u9001"})}catch(Re){throw qge(Re,R)}let iA=bb(eA);if(iA)throw jh(new gt("send-rejected","\u9489\u9489\u670D\u52A1\u62D2\u7EDD\u4E86\u6587\u4EF6\u6D88\u606F\u3002",{providerCode:iA}));return eA}return Object.freeze({async beginRegistration({signal:H}={}){let J=_b(await bn(n,Q(r,"app/registration/init"),{body:{source:g},signal:H,action:"\u521D\u59CB\u5316"}),"\u521D\u59CB\u5316"),q=WA(J.nonce);if(!q)throw new gt("invalid-registration","\u9489\u9489\u626B\u7801\u521D\u59CB\u5316\u7F3A\u5C11 nonce\u3002");let U=_b(await bn(n,Q(r,"app/registration/begin"),{body:{nonce:q},signal:H,action:"\u521B\u5EFA"}),"\u521B\u5EFA"),R=WA(U.device_code),V=WA(U.verification_uri_complete);if(!R||!V)throw new gt("invalid-registration","\u9489\u9489\u626B\u7801\u670D\u52A1\u8FD4\u56DE\u7684\u4FE1\u606F\u4E0D\u5B8C\u6574\u3002");let L=Nb(V,{label:"\u9489\u9489\u626B\u7801",requireSubdomain:!1}).toString();return{deviceCode:R,userCode:WA(U.user_code)??void 0,verificationUri:WA(U.verification_uri)??void 0,verificationUriComplete:L,expiresInSeconds:Tb(U.expires_in,7200),intervalSeconds:Tb(U.interval,5)}},async pollRegistration({deviceCode:H,signal:J}={}){let q=WA(H);if(!q)throw new TypeError("deviceCode is required");let U=_b(await bn(n,Q(r,"app/registration/poll"),{body:{device_code:q},signal:J,action:"\u72B6\u6001\u67E5\u8BE2"}),"\u72B6\u6001\u67E5\u8BE2"),R=WA(U.status)?.toUpperCase();if(!R||!jge.has(R))throw new gt("invalid-registration-status","\u9489\u9489\u626B\u7801\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6CD5\u8BC6\u522B\u7684\u72B6\u6001\u3002");let V={status:R,failReason:WA(U.fail_reason)??void 0};if(R==="SUCCESS"&&(V.clientId=WA(U.client_id)??void 0,V.clientSecret=WA(U.client_secret)??void 0,!V.clientId||!V.clientSecret))throw new gt("missing-credentials","\u9489\u9489\u626B\u7801\u5DF2\u786E\u8BA4\uFF0C\u4F46\u6CA1\u6709\u8FD4\u56DE\u673A\u5668\u4EBA\u51ED\u636E\u3002");return V},accessToken:y,async addReaction(H){return m(H,"reply")},async recallReaction(H){return m(H,"recall")},async addThinkingReaction(H){return m({...H,reactionName:zc},"reply")},async recallThinkingReaction(H){return m({...H,reactionName:zc},"recall")},async downloadImage({clientId:H,clientSecret:J,robotCode:q,downloadCode:U,signal:R,maxBytes:V}){let L=await _({clientId:H,clientSecret:J,robotCode:q,downloadCode:U,signal:R,kind:"image"});try{return await no(L,{fetchImpl:n,signal:R,maxBytes:V})}catch(T){throw R?.aborted||T instanceof ut?T:new gt("image-content-download-failed","\u9489\u9489\u56FE\u7247\u5185\u5BB9\u4E0B\u8F7D\u5931\u8D25\u3002",{cause:T})}},async downloadFile({clientId:H,clientSecret:J,robotCode:q,downloadCode:U,signal:R}){let V=await _({clientId:H,clientSecret:J,robotCode:q,downloadCode:U,signal:R,kind:"file"});if(V.protocol!=="https:")throw new gt("invalid-file-download","\u9489\u9489\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6548\u7684\u6587\u4EF6\u4E0B\u8F7D\u5730\u5740\u3002");try{let L=await n(V,{method:"GET",redirect:"follow",signal:R});if(!L?.ok)throw await L?.body?.cancel?.().catch?.(()=>{}),new gt("file-content-download-failed",`\u9489\u9489\u6587\u4EF6\u5185\u5BB9\u4E0B\u8F7D\u5931\u8D25\uFF08HTTP ${L?.status??"unknown"}\uFF09\u3002`,{status:L?.status});return Buffer.from(await L.arrayBuffer())}catch(L){throw R?.aborted?Mn(R):L instanceof gt?L:new gt("file-content-download-failed","\u9489\u9489\u6587\u4EF6\u5185\u5BB9\u4E0B\u8F7D\u5931\u8D25\u3002",{cause:L})}},async createAiCard({clientId:H,clientSecret:J,target:q,initialText:U,signal:R}){let V=WA(H),L=WA(J),T=WA(U);if(!V||!L)throw new TypeError("clientId and clientSecret are required");if(!T)throw new TypeError("initialText is required");let k=$ge(q),W=await y({clientId:V,clientSecret:L,signal:R}),ie=`dsh_${Yh()}`,ge={"x-acs-dingtalk-access-token":W},Se=!1;try{await G("v1.0/card/instances",{body:{cardTemplateId:Uge,outTrackId:ie,cardData:{cardParamMap:{config:JSON.stringify({autoLayout:!0})}},callbackType:"STREAM",imGroupOpenSpaceModel:{supportForward:!0},imRobotOpenSpaceModel:{supportForward:!0}},headers:ge,signal:R,action:"AI Card \u521B\u5EFA"}),await G("v1.0/card/instances/deliver",{body:ece(ie,k,V),headers:ge,signal:R,action:"AI Card \u6295\u653E"}),Se=!0,await G("v1.0/card/instances",{method:"PUT",body:{outTrackId:ie,cardData:Mb(T,"2")},headers:ge,signal:R,action:"AI Card \u542F\u52A8"}),await G("v1.0/card/streaming",{method:"PUT",body:{outTrackId:ie,guid:Yh(),key:"msgContent",content:Jh(T).replace(/\n+$/,""),isFull:!0,isFinalize:!1,isError:!1},headers:ge,signal:R,action:"AI Card \u542F\u52A8"})}catch(de){if(Se){let De=AbortSignal.timeout(5e3);await Y({clientId:V,clientSecret:L,cardInstanceId:ie,text:D("\u5361\u7247\u5DF2\u7ED3\u675F\uFF0C\u8BF7\u67E5\u770B\u540E\u7EED\u6D88\u606F\u3002"),signal:De}).catch(()=>{})}throw de}return{cardInstanceId:ie}},async updateAiCard({clientId:H,clientSecret:J,cardInstanceId:q,text:U,signal:R}){let V=WA(q),L=WA(U);if(!V)throw new TypeError("cardInstanceId is required");if(!L)throw new TypeError("text is required");let T=await y({clientId:H,clientSecret:J,signal:R});return await G("v1.0/card/streaming",{method:"PUT",body:{outTrackId:V,guid:Yh(),key:"msgContent",content:Jh(L).replace(/\n+$/,""),isFull:!0,isFinalize:!1,isError:!1},headers:{"x-acs-dingtalk-access-token":T},signal:R,action:"AI Card \u66F4\u65B0"}),!0},async finishAiCard({clientId:H,clientSecret:J,cardInstanceId:q,text:U,signal:R}){let V=WA(q),L=WA(U);if(!V)throw new TypeError("cardInstanceId is required");if(!L)throw new TypeError("text is required");let k={"x-acs-dingtalk-access-token":await y({clientId:H,clientSecret:J,signal:R})},W=Jh(L);await G("v1.0/card/streaming",{method:"PUT",body:{outTrackId:V,guid:Yh(),key:"msgContent",content:W,isFull:!0,isFinalize:!0,isError:!1},headers:k,signal:R,action:"AI Card \u5B8C\u6210"});let ie=!0,ge={method:"PUT",body:{outTrackId:V,cardData:Mb(L,"3"),cardUpdateOptions:{updateCardDataByKey:!0}},headers:k,signal:R,action:"AI Card \u6536\u53E3"};try{await G("v1.0/card/instances",ge)}catch{try{await G("v1.0/card/instances",ge)}catch{ie=!1}}return{delivered:!0,completed:ie}},failAiCard:Y,async sendText({clientId:H,clientSecret:J,sessionWebhook:q,text:U,signal:R}){let V=WA(U);if(!V)throw new TypeError("text is required");let L=Rg(q),T=await y({clientId:H,clientSecret:J,signal:R}),k=await bn(n,L,{body:{msgtype:"text",text:{content:V}},headers:{"x-acs-dingtalk-access-token":T},signal:R,action:"\u6D88\u606F\u56DE\u590D"});if(k?.errcode!==void 0&&k.errcode!==0||k?.code!==void 0&&k.code!==0)throw new gt("send-rejected","\u9489\u9489\u670D\u52A1\u62D2\u7EDD\u4E86\u56DE\u590D\u6D88\u606F\u3002");return!0},async sendFile(H){return j(H,{uploadType:"file",messageKey:"sampleFile",createMessageParams:(J,q)=>({mediaId:J,fileName:q.fileName,fileType:Xge(q.fileName)})})},async sendImage(H){return j(H,{uploadType:"image",messageKey:"sampleImageMsg",createMessageParams:J=>({photoURL:J})})},clearAccessToken(H){let J=WA(H);J&&c.delete(J)}})}var Ace=500,tce="\u5361\u7247\u5DF2\u7ED3\u675F\uFF0C\u8BF7\u67E5\u770B\u540E\u7EED\u6D88\u606F\u3002";function Rb(n,t){if(typeof n!="string")throw new TypeError(`${t} must be a string`);return n}function TH(n,t){if(typeof n!="string"||!n.trim())throw new TypeError(`${t} is required`);return n.trim()}function NH({api:n,clientId:t,clientSecret:o,target:i,signal:e,logger:a=console,updateIntervalMs:A=Ace,clock:r=()=>Date.now(),timer:s={setTimeout:(g,c)=>globalThis.setTimeout(g,c),clearTimeout:g=>globalThis.clearTimeout(g)}}={}){if(!n||typeof n.createAiCard!="function"||typeof n.updateAiCard!="function"||typeof n.finishAiCard!="function")throw new TypeError("DingTalk AI Card API is required");let g=TH(t,"clientId"),c=TH(o,"clientSecret");if(i==null)throw new TypeError("target is required");if(!Number.isFinite(A)||A<0)throw new TypeError("updateIntervalMs must be a non-negative number");if(typeof r!="function")throw new TypeError("clock must be a function");if(typeof s?.setTimeout!="function"||typeof s?.clearTimeout!="function")throw new TypeError("timer must provide setTimeout and clearTimeout");let I=()=>{let T=r();if(!Number.isFinite(T))throw new TypeError("clock must return a finite timestamp");return T};I();let d=e?.aborted?"aborted":"idle",B=null,f=null,Q=null,y=null,m=null,_=null,N=0,G=()=>{Q!==null&&(s.clearTimeout(Q),Q=null)},Y=()=>e?.removeEventListener("abort",q),j=T=>{d=T,f=null,G(),Y()},H=()=>!B||typeof n.failAiCard!="function"?Promise.resolve(!1):(_||(_=n.failAiCard({...B,text:D(tce),signal:AbortSignal.timeout(5e3)}).then(()=>!0,()=>!1)),_),J=T=>{d==="failed"||d==="finished"||d==="aborted"||(H(),j("failed"),a?.error?.(`[dsh-dingtalk] AI Card ${T} failed`))};function q(){d==="finished"||d==="failed"||d==="aborted"||(H(),j("aborted"))}d!=="aborted"&&e?.addEventListener("abort",q,{once:!0});let U=()=>{if(d!=="active"||y||f===null)return;let T=Math.max(0,N+A-I());if(T>0){Q=s.setTimeout(()=>{Q=null,U()},T);return}let k=f;f=null,y=(async()=>{try{await n.updateAiCard({...B,text:k,finished:!1}),N=I()}catch{if(e?.aborted||d==="aborted")return;J("update")}})().finally(()=>{y=null,d==="active"&&f!==null&&U()})};return Object.freeze({start:async T=>{if(Rb(T,"initialText"),d!=="idle")return!1;d="starting";try{let k=await n.createAiCard({clientId:g,clientSecret:c,target:i,initialText:T,signal:e}),W=typeof k?.cardInstanceId=="string"?k.cardInstanceId.trim():"";if(!W)throw new TypeError("DingTalk did not return a card instance id");return B=Object.freeze({clientId:g,clientSecret:c,target:i,cardInstanceId:W,signal:e}),d!=="starting"?(H(),!1):(N=I(),d="active",!0)}catch{return e?.aborted||d==="aborted"?(j("aborted"),!1):(J("creation"),!1)}},push:T=>{Rb(T,"progressText"),d==="active"&&(f=T,!Q&&!y&&U())},finish:T=>{if(Rb(T,"finalText"),d==="finished")return Promise.resolve(!0);if(d==="finishing")return m;if(d!=="active")return Promise.resolve(!1);d="finishing",f=null,G();let k=y;return m=(async()=>{if(k&&await k,d!=="finishing")return!1;try{return await n.finishAiCard({...B,text:T}),d!=="finishing"?!1:(j("finished"),!0)}catch{return e?.aborted||d==="aborted"?(j("aborted"),!1):(J("finish"),!1)}})(),m}})}function lf(n){return typeof n=="string"&&n.trim()?n.trim():null}function ti(n){return n&&typeof n.id=="string"&&typeof n.question=="string"&&(n.header===void 0||typeof n.header=="string")&&(n.detail===void 0||typeof n.detail=="string")&&(n.multiSelect===void 0||typeof n.multiSelect=="boolean")&&(n.options===void 0||Array.isArray(n.options)&&n.options.every(t=>t&&typeof t.label=="string"&&(t.description===void 0||typeof t.description=="string")))}function ri(n,t,o,{requiresMention:i=!1}={}){let e=[],a=o>1?`\uFF08${t+1}/${o}\uFF09`:"";e.push(D("DeepSeek Harness \u9700\u8981\u4F60\u8865\u5145\u4FE1\u606F{progress}\uFF1A",{progress:a})),lf(n.header)&&e.push("",n.header.trim()),e.push("",lf(n.question)??D("\u8BF7\u8F93\u5165\u4F60\u7684\u56DE\u7B54\u3002")),lf(n.detail)&&e.push("",n.detail.trim());let A=Array.isArray(n.options)?n.options:[];return A.length>0?(e.push(""),A.forEach((r,s)=>{let g=typeof r?.label=="string"?r.label:"",c=lf(r?.description);e.push(`${s+1}. ${g}${c?` \u2014 ${c}`:""}`)}),e.push("",n.multiSelect===!0?D("\u8BF7\u56DE\u590D\u9009\u9879\u5E8F\u53F7\u6216\u6587\u5B57\uFF1B\u591A\u9009\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4E5F\u53EF\u8865\u5145\u5176\u4ED6\u5185\u5BB9\u3002"):D("\u8BF7\u56DE\u590D\u4E00\u4E2A\u9009\u9879\u5E8F\u53F7\u6216\u6587\u5B57\uFF0C\u4E5F\u53EF\u76F4\u63A5\u8F93\u5165\u5176\u4ED6\u7B54\u6848\u3002"))):e.push("",D("\u8BF7\u76F4\u63A5\u56DE\u590D\u4F60\u7684\u7B54\u6848\u3002")),i&&e.push("",D("\u7FA4\u804A\u4E2D\u8BF7 @\u673A\u5668\u4EBA \u540E\u53D1\u9001\u7B54\u6848\u3002")),e.join(` `)}function RH(n,t){let o=n.trim();if(!o)return null;if(/^\d+$/.test(o)){let e=t[Number(o)-1];return typeof e?.label=="string"?e.label:null}let i=t.find(e=>e?.label===o);return typeof i?.label=="string"?i.label:null}function ai(n,t){let o=Array.isArray(n.options)?n.options:[];if(o.length===0)return{id:n.id,selected:[],custom:t};let i=RH(t,o);if(n.multiSelect!==!0)return i?{id:n.id,selected:[i]}:{id:n.id,selected:[],custom:t};if(i)return{id:n.id,selected:[i]};let e=[],a=[];for(let A of t.split(/[,,、;;\n]+/)){let r=A.trim();if(!r)continue;let s=RH(r,o);s?e.includes(s)||e.push(s):a.push(r)}return{id:n.id,selected:e,...a.length>0?{custom:a.join("\u3001")}:{}}}var rce=new Map([["\u6279\u51C6","allowed-once"],["\u540C\u610F","allowed-once"],["yes","allowed-once"],["\u62D2\u7EDD","rejected"],["\u4E0D\u540C\u610F","rejected"],["no","rejected"]]),kb="\u8BF7\u7CBE\u51C6\u56DE\u590D\u300C\u6279\u51C6\u300D\u6216\u300C\u62D2\u7EDD\u300D\uFF08\u4E5F\u652F\u6301\uFF1A\u540C\u610F / \u4E0D\u540C\u610F / yes / no\uFF09\u3002",ace="\u8BF7\u5148\u5B8C\u6210\u5F53\u524D\u95EE\u9898\uFF0C\u518D\u7CBE\u51C6\u56DE\u590D\u300C\u6279\u51C6\u300D\u6216\u300C\u62D2\u7EDD\u300D\u3002",Gl="\u8BE5\u5BA1\u6279\u5DF2\u5904\u7406\uFF0C\u65E0\u9700\u518D\u6B21\u56DE\u590D\u3002",ice=5*6e4,oce=2048;function wa(n){return typeof n=="string"?n.trim():""}function vb(n){return wa(n).replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g,"")}function nce(n){return rce.get(wa(n).toLowerCase())??null}function vH(n){return n?.type==="approval/requested"&&!!wa(n.sessionId)&&!!wa(n.approvalId)&&!!wa(n.toolName)&&(n.callId===void 0||!!wa(n.callId))&&(n.reason===void 0||typeof n.reason=="string")}function sce(n){let t=n?.arguments;if(t!==null&&typeof t=="object")try{return JSON.stringify(t,null,2)}catch{return null}if(typeof t!="string")return null;let o=vb(t);if(!o)return t===""?"{}":null;try{return JSON.stringify(JSON.parse(o),null,2)}catch{return o}}function Pb(n,{toolCall:t,requiresMention:o=!1,maxArgumentsLength:i=6e3}={}){if(!vH(n))return null;let e=wa(n.callId);if(!e||wa(t?.callId)!==e||wa(t?.name)!==wa(n.toolName))return null;let a=sce(t);if(!a||a.length>i)return null;let A=[D("DeepSeek Harness \u9700\u8981\u4F60\u7684\u5BA1\u6279\uFF1A"),"",D("\u5DE5\u5177\uFF1A{tool}",{tool:vb(n.toolName)}),D("\u64CD\u4F5C\u53C2\u6570\uFF1A"),a],r=vb(n.reason);return r&&A.push(D("\u539F\u56E0\uFF1A{reason}",{reason:r})),A.push("",D(kb)),o&&A.push("",D("\u7FA4\u804A\u4E2D\u8BF7 @\u673A\u5668\u4EBA \u540E\u53D1\u9001\u5BA1\u6279\u51B3\u5B9A\u3002")),A.join(` -`)}function kH(n,t){return{ok:!0,value:{sessionId:n.sessionId,approvalId:n.approvalId,outcome:t}}}function pf(n){return n==="allowed-once"?D("\u5DF2\u6279\u51C6\uFF0C\u4EC5\u5BF9\u672C\u6B21\u64CD\u4F5C\u6709\u6548\u3002"):n==="rejected"?D("\u5DF2\u62D2\u7EDD\u6B64\u6B21\u64CD\u4F5C\u3002"):D(Gl)}var ii=class{#e;#A;#t=new Map;#r=new Map;#a=new Map;constructor({label:t="IM",logger:o=console}={}){this.#e=t,this.#A=o}hasPending(t){return this.#r.get(t)?.items.some(o=>!o.inactive)===!0}claimReply({key:t,actor:o,text:i,addressed:e=!0,hasPendingQuestion:a=!1,questionCompletion:A,isQuestionPending:r,send:s}){let c=this.#r.get(t)?.items[0],I=nce(i),d=(f,Q=!1)=>({...Q?{resolved:!0}:{},process:async y=>{typeof y=="function"&&await y()===!1||await s(f)}}),B=a&&c&&A&&typeof A.then=="function";return a&&!B?null:!c||c.inactive?(this.#a.get(t)??0)<=Date.now()?(this.#a.delete(t),null):I?d(D(Gl),!0):null:c.actor!==o||c.requiresMention&&e!==!0?I?d(D("\u53EA\u6709\u53D1\u8D77\u5F53\u524D\u4EFB\u52A1\u7684\u7528\u6237\u53EF\u4EE5\u5904\u7406\u8FD9\u6761\u5BA1\u6279\u3002")):null:{process:async f=>{let Q=c.presented,m=(c.replyTail??Promise.resolve()).catch(()=>{}).then(async()=>{if(!(typeof f=="function"&&await f()===!1)){if(B){if(await A.catch(()=>{}),c.inactive||c.resolving)return;if(typeof r=="function"&&r()){await s(D(ace));return}}if(await c.activationTask?.catch(()=>{}),await c.presentationTask?.catch(()=>{}),c.inactive||c.resolving){await s(D(Gl));return}if(c.send=s,!Q||!c.presented){if(c.presented||await this.#i(c),c.inactive||c.resolving)return;await s(D(kb));return}if(c.submitting){await s(D("\u5BA1\u6279\u51B3\u5B9A\u6B63\u5728\u63D0\u4EA4\uFF0C\u8BF7\u7A0D\u5019\u3002"));return}if(!I){await s(D(kb));return}await this.#c(c,I)}});c.replyTail=m;try{await m}finally{c.replyTail===m&&(c.replyTail=null)}}}}async handleRequested(t,o){if(t?.kind!=="approval")return!1;let i=t.payload,e=wa(i?.approvalId);if(!wa(t.rpcId)||!wa(t.sessionId)||!e||!vH(i)||i.sessionId!==t.sessionId||typeof t.respond!="function")return this.#A.warn?.(`[dsh-im:${this.#e}] ignored an invalid Harness approval`),!0;if(t.recovered===!0)return await this.#g(t,i),!0;let a=this.#t.get(e);if(a)return a.interaction=t,a.toolCall=t.toolCall,a.presented||await this.#i(a),!0;let A=o?.send,r=wa(o?.key),s=wa(o?.actor);if(!r||!s||typeof A!="function")return this.#A.warn?.(`[dsh-im:${this.#e}] ignored an approval without a reply route`),await this.#g(t,i),!0;let g=Pb(i,{toolCall:t.toolCall,requiresMention:o.requiresMention===!0});if(!g){let d=await this.#g(t,i);return await A(d?D("\u65E0\u6CD5\u5B8C\u6574\u5C55\u793A\u8FD9\u6B21\u64CD\u4F5C\uFF0C\u5DF2\u5B89\u5168\u62D2\u7EDD\u6B64\u6B21\u5BA1\u6279\u3002"):D(Gl)),!0}let c={approvalId:e,sessionId:t.sessionId,interaction:t,toolCall:t.toolCall,key:r,actor:s,requiresMention:o.requiresMention===!0,send:A,text:g,presented:!1,presentationTask:null,deliveryCompleted:!1,replyTail:null,submitting:!1,inactive:!1,resolving:!1,closedOutcome:null,resolutionNotified:!1,activationTask:null};this.#t.set(e,c);let I=this.#r.get(r)??{items:[]};return I.items.push(c),this.#r.set(r,I),I.items[0]===c&&await this.#i(c),!0}async handleResolved(t){if(t?.kind!=="approval")return!1;let o=this.#t.get(wa(t.interactionId));if(!o||(o.resolving=!0,o.activationTask&&await o.activationTask.catch(()=>{}),o.inactive||this.#t.get(o.approvalId)!==o))return!0;let i=o.presentationTask,e=o.presented||i,a=o.send,A=this.#o(o);return await this.#s(A,async()=>{let r=o.presented;i&&(r=await i.then(()=>!0,()=>!1)),e&&r&&(o.resolutionNotified=!0,await a(pf(t.outcome)).catch(()=>{}))}),!0}async closeRoute(t){let o=this.#r.get(t);if(!o)return;let i=[...o.items];for(let e of i)this.#o(e);await Promise.all(i.map(async e=>{try{await e.interaction.respond(kH(e,"rejected"),{signal:AbortSignal.timeout(5e3)}),e.closedOutcome="rejected",(e.presented||e.deliveryCompleted)&&!e.resolutionNotified&&(e.resolutionNotified=!0,await e.send(pf("rejected")).catch(()=>{}))}catch(a){a?.code==="interaction-not-pending"?(e.closedOutcome="resolved",(e.presented||e.deliveryCompleted)&&!e.resolutionNotified&&(e.resolutionNotified=!0,await e.send(D(Gl)).catch(()=>{}))):this.#A.warn?.(`[dsh-im:${this.#e}] failed to reject a closing approval:`,a)}}))}async#i(t){if(this.#r.get(t.key)?.items[0]!==t||t.inactive||t.resolving||t.presented||(await t.activationTask?.catch(()=>{}),this.#r.get(t.key)?.items[0]!==t||t.inactive||t.resolving||t.presented))return;if(t.presentationTask)return t.presentationTask;let o=Promise.resolve().then(()=>t.send(t.text));t.presentationTask=o;try{await o,t.deliveryCompleted=!0,t.inactive?t.closedOutcome&&!t.resolutionNotified&&(t.resolutionNotified=!0,await t.send(pf(t.closedOutcome)).catch(()=>{})):t.presented=!0}finally{t.presentationTask===o&&(t.presentationTask=null)}}async#c(t,o){t.submitting=!0;try{await t.interaction.respond(kH(t,o))}catch(a){if(a?.code==="interaction-not-pending"){let A=t.send,r=this.#o(t);await this.#s(r,async()=>{t.resolutionNotified||await A(D(Gl)).catch(()=>{})});return}if(t.inactive)return;t.submitting=!1,this.#A.error?.(`[dsh-im:${this.#e}] failed to submit an approval:`,a),await t.send(D("\u5BA1\u6279\u63D0\u4EA4\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u56DE\u590D\u300C\u6279\u51C6\u300D\u6216\u300C\u62D2\u7EDD\u300D\u3002")).catch(()=>{});return}let i=t.send,e=this.#o(t);await this.#s(e,async()=>{t.resolutionNotified||await i(pf(o)).catch(()=>{})})}async#s(t,o){let i,e=new Promise(a=>{i=a});t&&(t.activationTask=e);try{await o()}finally{i(),t?.activationTask===e&&(t.activationTask=null)}await this.#I(t)}async#I(t){if(t)try{await this.#i(t)}catch(o){this.#A.error?.(`[dsh-im:${this.#e}] failed to present the next approval:`,o);try{t.interaction.reconnect?.()}catch{}}}#o(t){if(t.inactive)return null;t.inactive=!0,this.#n(t.key),this.#t.delete(t.approvalId);let o=this.#r.get(t.key);if(!o)return null;let i=o.items[0]===t,e=o.items.indexOf(t);return e!==-1&&o.items.splice(e,1),o.items.length===0?(this.#r.delete(t.key),null):i?o.items[0]:null}#n(t){let o=Date.now();for(let[i,e]of this.#a)e<=o&&this.#a.delete(i);for(this.#a.delete(t),this.#a.set(t,o+ice);this.#a.size>oce;)this.#a.delete(this.#a.keys().next().value)}async#g(t,o){try{return await t.respond({ok:!0,value:{sessionId:t.sessionId,approvalId:o.approvalId,outcome:"rejected"}},{signal:AbortSignal.timeout(5e3)}),!0}catch(i){if(i?.code==="interaction-not-pending")return!1;throw i}}};var Gb=new WeakMap;function gce(n){let t=Gb.get(n);return t||(t=new Map,Gb.set(n,t)),t}async function Vc(n,t,o){let i=typeof n;if(i!=="object"&&i!=="function"||n===null)throw new TypeError("state is required");if(typeof t!="string"||!t)throw new TypeError("conversation key is required");if(typeof o!="function")throw new TypeError("operation is required");let e=gce(n),a=e.get(t)??Promise.resolve(),A,r=new Promise(s=>{A=s});e.set(t,r),await a;try{return await o()}finally{A(),e.get(t)===r&&(e.delete(t),e.size===0&&Gb.delete(n))}}var oi="workspace-session-stale";function PH(n,t){return typeof n.workspaceSession=="function"?n.workspaceSession(t):Object.freeze({sessionId:t,sessionExists:(...o)=>n.sessionExists(t,...o),models:(...o)=>n.getSessionModels(t,...o),selectModel:(...o)=>n.selectSessionModel(t,...o),isRunning:(...o)=>n.isSessionRunning(t,...o),hasActiveTurn:(...o)=>n.hasActiveTurn(t,...o),stopActiveTurn:(...o)=>n.stopActiveTurn(t,...o),steerActiveTurn:(...o)=>n.steerActiveTurn(t,...o),ask:(...o)=>n.ask(t,...o)})}async function cce(n,t){return t===void 0?n.sessionExists():n.sessionExists(t)}async function Ice(n,t){return t===void 0?n.createSession():n.createSession(t)}async function ni({harness:n,state:t,key:o,text:i,content:e,createOptions:a,existsOptions:A,askOptions:r}){for(;;)try{let s=await Vc(t,o,async()=>{let B=t.sessionFor(o),f=B?PH(n,B):null;if(!f||!await cce(f,A)){if(B=await Ice(n,a),await t.setSession(o,B)===!1)return null;f=PH(n,B)}return{sessionId:B,session:f}});if(!s)continue;let g=[],c=typeof r=="object"&&typeof r?.onArtifact=="function"?r.onArtifact:null,I=typeof r=="number"?{timeoutMs:r}:{...r};I.onArtifact=async B=>{g.push(B),await c?.(B)};let d=await s.session.ask(e??i,I);return{sessionId:s.sessionId,answer:d,...g.length>0?{artifacts:g}:{}}}catch(s){if(s?.code!==oi)throw s}}var lce=/^\/compact(?=$|\s)([\s\S]*)$/i,pce="\u7528\u6CD5\uFF1A/compact\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",GH=new Map([["No compactable history yet.","\u6682\u65E0\u53EF\u538B\u7F29\u7684\u5386\u53F2\u8BB0\u5F55\u3002"],["Compaction is unavailable because this process has an active compaction, or the agent is not idle.","\u5F53\u524D\u4F1A\u8BDD\u6B63\u5728\u751F\u6210\u56DE\u590D\u6216\u6267\u884C\u538B\u7F29\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002"],["Compaction cancelled.","\u4E0A\u4E0B\u6587\u538B\u7F29\u5DF2\u53D6\u6D88\u3002"],["The history selected for compaction changed before it could be replaced. The conversation is unchanged; the attempt is recorded in the session log.","\u538B\u7F29\u671F\u95F4\u4F1A\u8BDD\u5386\u53F2\u53D1\u751F\u53D8\u5316\uFF0C\u672C\u6B21\u672A\u4FEE\u6539\u4F1A\u8BDD\uFF0C\u8BF7\u91CD\u8BD5\u3002"],["Compaction could not produce a useful summary. The conversation is unchanged; the attempt is recorded in the session log.","\u672A\u80FD\u751F\u6210\u6709\u6548\u7684\u538B\u7F29\u6458\u8981\uFF0C\u672C\u6B21\u672A\u4FEE\u6539\u4F1A\u8BDD\u3002"],["Compaction did not finish cleanly; some session history may have changed. Inspect the current session state before retrying.","\u4E0A\u4E0B\u6587\u538B\u7F29\u672A\u6B63\u5E38\u5B8C\u6210\uFF0C\u90E8\u5206\u4F1A\u8BDD\u5386\u53F2\u53EF\u80FD\u5DF2\u53D8\u5316\uFF0C\u8BF7\u68C0\u67E5\u4F1A\u8BDD\u540E\u518D\u91CD\u8BD5\u3002"],["Compaction finished, but the session could not be saved.","\u4E0A\u4E0B\u6587\u5DF2\u538B\u7F29\uFF0C\u4F46\u4F1A\u8BDD\u4FDD\u5B58\u5931\u8D25\u3002"]]);function Wc(n){return{handled:!0,message:n,messages:[n]}}function dce(n){if(!n||typeof n!="object"||!["success","error"].includes(n.kind)||n.text!==void 0&&typeof n.text!="string")throw new TypeError("Harness returned an invalid /compact result");let t=n.text?.trim()??"",o=/^Compacted (\d+) history items \(~(\d+) tokens\)\.$/u.exec(t);return o?D("\u5DF2\u538B\u7F29 {count} \u6761\u5386\u53F2\u8BB0\u5F55\uFF08\u7EA6 {tokens} \u4E2A token\uFF09\u3002",{count:o[1],tokens:o[2]}):GH.has(t)?D(GH.get(t)):t||(n.kind==="success"?D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5B8C\u6210\u3002"):D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25\u3002"))}function hce(n){let t=n?.code??n?.failure?.code;return t==="session-not-found"?D("\u5F53\u524D\u804A\u5929\u7ED1\u5B9A\u7684\u4F1A\u8BDD\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u53D1\u9001\u65B0\u6D88\u606F\u5F00\u542F\u4F1A\u8BDD\u3002"):t==="agent-busy"?D("\u5F53\u524D\u4F1A\u8BDD\u6B63\u5728\u751F\u6210\u56DE\u590D\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002"):t==="cancelled"||n?.name==="AbortError"?D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5DF2\u53D6\u6D88\u3002"):t===oi||t==="workspace-bot-not-found"?D("\u5DE5\u4F5C\u533A\u6216\u673A\u5668\u4EBA\u72B6\u6001\u5DF2\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u8BD5\u3002"):t==="commands-unavailable"?D("\u5F53\u524D Harness \u6682\u4E0D\u652F\u6301\u4ECE\u673A\u5668\u4EBA\u6267\u884C\u4E0A\u4E0B\u6587\u538B\u7F29\u3002"):D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002")}async function si(n,t,o,i,e={}){if(typeof n!="string")return null;let a=lce.exec(n.trim());if(!a)return null;if(a[1].trim())return Wc(D(pce));if(typeof o?.sessionFor!="function")return Wc(D("\u5F53\u524D\u673A\u5668\u4EBA\u6CA1\u6709\u53EF\u7528\u7684\u4F1A\u8BDD\u72B6\u6001\u3002"));let A=o.sessionFor(i);if(typeof A!="string"||!A)return Wc(D("\u5F53\u524D\u804A\u5929\u8FD8\u6CA1\u6709\u53EF\u538B\u7F29\u7684\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u53D1\u9001\u4E00\u6761\u6D88\u606F\u3002"));if(typeof t?.executeCommand!="function")return Wc(D("\u5F53\u524D\u673A\u5668\u4EBA\u6682\u4E0D\u652F\u6301\u4E0A\u4E0B\u6587\u538B\u7F29\u3002"));try{let r=await t.executeCommand(A,"/compact",e);return Wc(r===void 0?D("\u5F53\u524D Harness \u672A\u6CE8\u518C /compact \u547D\u4EE4\uFF0C\u8BF7\u786E\u8BA4\u4E0A\u4E0B\u6587\u538B\u7F29\u7EC4\u4EF6\u5DF2\u542F\u7528\u3002"):dce(r?.result))}catch(r){return Wc(hce(r))}}var FH={name:"@xmanrui/dsh-im",version:"2.5.0",description:"\u628A\u4E5D\u79CD IM \u673A\u5668\u4EBA\u548C\u516C\u7F51 AI Office \u63A5\u5165\u672C\u673A DeepSeek Harness\u3002 Connect nine IM channels and a public AI Office to a local DeepSeek Harness.",keywords:["deepseek-harness","dsh","dsh-plugin","ai-agent","im","instant-messaging","chatbot","feishu","lark","wechat","wecom","dingtalk","qq","slack","telegram","discord","whatsapp","ai-office"],author:{name:"xmanrui",url:"https://github.com/xmanrui"},contributors:[{name:"C3H3-AI",url:"https://github.com/C3H3-AI"}],license:"MIT",type:"module",repository:{type:"git",url:"git+https://github.com/xmanrui/dsh-im.git"},homepage:"https://github.com/xmanrui/dsh-im#readme",bugs:"https://github.com/xmanrui/dsh-im/issues",publishConfig:{access:"public"},bin:{"dsh-im":"bin/dsh-im.mjs"},main:"./lib/index.js",exports:{".":"./lib/index.js","./client":"./lib/client.js","./package.json":"./package.json"},files:["assets","bin","cordis.patch.yml","lib","plugin-src","scripts","src","LICENSE","README.md","README.en.md","THIRD_PARTY_NOTICES.md"],dsh:{bundle:{patch:"./cordis.patch.yml"},client:{inject:["@deepseek-ai/dsh-client-connection","@deepseek-ai/dsh-client-runtime","@deepseek-ai/dsh-client-ui-settings","@deepseek-ai/dsh-client-ui-slots","@deepseek-ai/dsh-client-locale"],platform:"web"}},scripts:{build:"node plugin-src/client/build.mjs && node plugin-src/host/build.mjs",test:"node --test test/*.test.mjs test/channels/*/*.test.mjs",check:"npm test && npm run build && node scripts/verify-package.mjs"},engines:{node:">=22.19"},dependencies:{"@tencent-connect/qqbot-connector":"1.2.0","@tencent-connect/qqbot-nodejs":"1.0.4","@wecom/aibot-node-sdk":"1.0.7","dingtalk-stream":"2.1.4",qrcode:"1.5.4"},devDependencies:{"@larksuiteoapi/node-sdk":"1.73.0","@whiskeysockets/baileys":"7.0.0-rc14",esbuild:"0.25.9","https-proxy-agent":"5.0.1",react:"18.3.1","react-dom":"18.3.1","react-test-renderer":"18.3.1"}};var Cce=/^\/(?:stop|steer|version)(?=$|\s)/iu,uce=/^\/stop(?=$|\s)/iu,Bce=/^\/version(?=$|\s)/iu,fce="\u7528\u6CD5\uFF1A/stop\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",Qce="\u7528\u6CD5\uFF1A/version\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",yce="\u7528\u6CD5\uFF1A/steer <\u8865\u5145\u6307\u4EE4>",mce="\u63A7\u5236\u547D\u4EE4\u4EC5\u652F\u6301\u7EAF\u6587\u5B57\uFF0C\u8BF7\u79FB\u9664\u56FE\u7247\u540E\u91CD\u8BD5\u3002";function co(n,t={}){return{message:n,...t}}function LH(n){return n?{signal:n}:{}}function UH(n,t,o){if(typeof t?.sessionFor!="function")return null;let i=t.sessionFor(o);if(typeof i!="string"||!i)return null;if(typeof n?.workspaceSession!="function")throw new TypeError("Harness does not support workspace sessions");let e=n.workspaceSession(i);if(!e||typeof e!="object")throw new TypeError("Harness returned an invalid workspace session");return e}function Pi(n){return typeof n=="string"&&Cce.test(n.trim())}async function gi(n,t,o,i,{signal:e,hasImages:a=!1,pendingInteraction:A=!1,control:r}={}){if(!Pi(n))return null;let s=n.trim(),g=uce.test(s),c=Bce.test(s);if(a)return co(D(mce));if(c)return/^\/version$/iu.test(s)?co(`dsh-im v${FH.version}`):co(D(Qce));if(g){if(!/^\/stop$/iu.test(s))return co(D(fce));let Q=UH(t,o,i);if(!Q)return co(D("\u5F53\u524D\u804A\u5929\u6CA1\u6709\u6B63\u5728\u8FD0\u884C\u7684\u4EFB\u52A1\u3002"));if(typeof Q.stopActiveTurn!="function")throw new TypeError("Harness session does not support stopping active turns");return await Q.stopActiveTurn(r,LH(e))?co(D("\u5DF2\u8BF7\u6C42\u505C\u6B62\u5F53\u524D\u4EFB\u52A1\u3002"),{stopped:!0}):co(D("\u5F53\u524D\u804A\u5929\u6CA1\u6709\u6B63\u5728\u8FD0\u884C\u7684\u4EFB\u52A1\u3002"))}let d=/^\/steer(?:\s+([\s\S]*))?$/iu.exec(s)?.[1]?.trim()??"";if(!d)return co(D(yce));if(A)return co([D("\u5F53\u524D\u4EFB\u52A1\u6B63\u5728\u7B49\u5F85\u4F60\u7684\u56DE\u7B54\u6216\u5BA1\u6279\u3002"),"",D("\u8BF7\u5148\u5904\u7406\u5F53\u524D\u8BF7\u6C42\uFF0C\u6216\u8005\u53D1\u9001 /stop \u505C\u6B62\u4EFB\u52A1\u3002")].join(` +`)}function kH(n,t){return{ok:!0,value:{sessionId:n.sessionId,approvalId:n.approvalId,outcome:t}}}function pf(n){return n==="allowed-once"?D("\u5DF2\u6279\u51C6\uFF0C\u4EC5\u5BF9\u672C\u6B21\u64CD\u4F5C\u6709\u6548\u3002"):n==="rejected"?D("\u5DF2\u62D2\u7EDD\u6B64\u6B21\u64CD\u4F5C\u3002"):D(Gl)}var ii=class{#e;#A;#t=new Map;#r=new Map;#a=new Map;constructor({label:t="IM",logger:o=console}={}){this.#e=t,this.#A=o}hasPending(t){return this.#r.get(t)?.items.some(o=>!o.inactive)===!0}claimReply({key:t,actor:o,text:i,addressed:e=!0,hasPendingQuestion:a=!1,questionCompletion:A,isQuestionPending:r,send:s}){let c=this.#r.get(t)?.items[0],I=nce(i),d=(f,Q=!1)=>({...Q?{resolved:!0}:{},process:async y=>{typeof y=="function"&&await y()===!1||await s(f)}}),B=a&&c&&A&&typeof A.then=="function";return a&&!B?null:!c||c.inactive?(this.#a.get(t)??0)<=Date.now()?(this.#a.delete(t),null):I?d(D(Gl),!0):null:c.actor!==o||c.requiresMention&&e!==!0?I?d(D("\u53EA\u6709\u53D1\u8D77\u5F53\u524D\u4EFB\u52A1\u7684\u7528\u6237\u53EF\u4EE5\u5904\u7406\u8FD9\u6761\u5BA1\u6279\u3002")):null:{process:async f=>{let Q=c.presented,m=(c.replyTail??Promise.resolve()).catch(()=>{}).then(async()=>{if(!(typeof f=="function"&&await f()===!1)){if(B){if(await A.catch(()=>{}),c.inactive||c.resolving)return;if(typeof r=="function"&&r()){await s(D(ace));return}}if(await c.activationTask?.catch(()=>{}),await c.presentationTask?.catch(()=>{}),c.inactive||c.resolving){await s(D(Gl));return}if(c.send=s,!Q||!c.presented){if(c.presented||await this.#i(c),c.inactive||c.resolving)return;await s(D(kb));return}if(c.submitting){await s(D("\u5BA1\u6279\u51B3\u5B9A\u6B63\u5728\u63D0\u4EA4\uFF0C\u8BF7\u7A0D\u5019\u3002"));return}if(!I){await s(D(kb));return}await this.#c(c,I)}});c.replyTail=m;try{await m}finally{c.replyTail===m&&(c.replyTail=null)}}}}async handleRequested(t,o){if(t?.kind!=="approval")return!1;let i=t.payload,e=wa(i?.approvalId);if(!wa(t.rpcId)||!wa(t.sessionId)||!e||!vH(i)||i.sessionId!==t.sessionId||typeof t.respond!="function")return this.#A.warn?.(`[dsh-im:${this.#e}] ignored an invalid Harness approval`),!0;if(t.recovered===!0)return await this.#g(t,i),!0;let a=this.#t.get(e);if(a)return a.interaction=t,a.toolCall=t.toolCall,a.presented||await this.#i(a),!0;let A=o?.send,r=wa(o?.key),s=wa(o?.actor);if(!r||!s||typeof A!="function")return this.#A.warn?.(`[dsh-im:${this.#e}] ignored an approval without a reply route`),await this.#g(t,i),!0;let g=Pb(i,{toolCall:t.toolCall,requiresMention:o.requiresMention===!0});if(!g){let d=await this.#g(t,i);return await A(d?D("\u65E0\u6CD5\u5B8C\u6574\u5C55\u793A\u8FD9\u6B21\u64CD\u4F5C\uFF0C\u5DF2\u5B89\u5168\u62D2\u7EDD\u6B64\u6B21\u5BA1\u6279\u3002"):D(Gl)),!0}let c={approvalId:e,sessionId:t.sessionId,interaction:t,toolCall:t.toolCall,key:r,actor:s,requiresMention:o.requiresMention===!0,send:A,text:g,presented:!1,presentationTask:null,deliveryCompleted:!1,replyTail:null,submitting:!1,inactive:!1,resolving:!1,closedOutcome:null,resolutionNotified:!1,activationTask:null};this.#t.set(e,c);let I=this.#r.get(r)??{items:[]};return I.items.push(c),this.#r.set(r,I),I.items[0]===c&&await this.#i(c),!0}async handleResolved(t){if(t?.kind!=="approval")return!1;let o=this.#t.get(wa(t.interactionId));if(!o||(o.resolving=!0,o.activationTask&&await o.activationTask.catch(()=>{}),o.inactive||this.#t.get(o.approvalId)!==o))return!0;let i=o.presentationTask,e=o.presented||i,a=o.send,A=this.#o(o);return await this.#s(A,async()=>{let r=o.presented;i&&(r=await i.then(()=>!0,()=>!1)),e&&r&&(o.resolutionNotified=!0,await a(pf(t.outcome)).catch(()=>{}))}),!0}async closeRoute(t){let o=this.#r.get(t);if(!o)return;let i=[...o.items];for(let e of i)this.#o(e);await Promise.all(i.map(async e=>{try{await e.interaction.respond(kH(e,"rejected"),{signal:AbortSignal.timeout(5e3)}),e.closedOutcome="rejected",(e.presented||e.deliveryCompleted)&&!e.resolutionNotified&&(e.resolutionNotified=!0,await e.send(pf("rejected")).catch(()=>{}))}catch(a){a?.code==="interaction-not-pending"?(e.closedOutcome="resolved",(e.presented||e.deliveryCompleted)&&!e.resolutionNotified&&(e.resolutionNotified=!0,await e.send(D(Gl)).catch(()=>{}))):this.#A.warn?.(`[dsh-im:${this.#e}] failed to reject a closing approval:`,a)}}))}async#i(t){if(this.#r.get(t.key)?.items[0]!==t||t.inactive||t.resolving||t.presented||(await t.activationTask?.catch(()=>{}),this.#r.get(t.key)?.items[0]!==t||t.inactive||t.resolving||t.presented))return;if(t.presentationTask)return t.presentationTask;let o=Promise.resolve().then(()=>t.send(t.text));t.presentationTask=o;try{await o,t.deliveryCompleted=!0,t.inactive?t.closedOutcome&&!t.resolutionNotified&&(t.resolutionNotified=!0,await t.send(pf(t.closedOutcome)).catch(()=>{})):t.presented=!0}finally{t.presentationTask===o&&(t.presentationTask=null)}}async#c(t,o){t.submitting=!0;try{await t.interaction.respond(kH(t,o))}catch(a){if(a?.code==="interaction-not-pending"){let A=t.send,r=this.#o(t);await this.#s(r,async()=>{t.resolutionNotified||await A(D(Gl)).catch(()=>{})});return}if(t.inactive)return;t.submitting=!1,this.#A.error?.(`[dsh-im:${this.#e}] failed to submit an approval:`,a),await t.send(D("\u5BA1\u6279\u63D0\u4EA4\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u56DE\u590D\u300C\u6279\u51C6\u300D\u6216\u300C\u62D2\u7EDD\u300D\u3002")).catch(()=>{});return}let i=t.send,e=this.#o(t);await this.#s(e,async()=>{t.resolutionNotified||await i(pf(o)).catch(()=>{})})}async#s(t,o){let i,e=new Promise(a=>{i=a});t&&(t.activationTask=e);try{await o()}finally{i(),t?.activationTask===e&&(t.activationTask=null)}await this.#I(t)}async#I(t){if(t)try{await this.#i(t)}catch(o){this.#A.error?.(`[dsh-im:${this.#e}] failed to present the next approval:`,o);try{t.interaction.reconnect?.()}catch{}}}#o(t){if(t.inactive)return null;t.inactive=!0,this.#n(t.key),this.#t.delete(t.approvalId);let o=this.#r.get(t.key);if(!o)return null;let i=o.items[0]===t,e=o.items.indexOf(t);return e!==-1&&o.items.splice(e,1),o.items.length===0?(this.#r.delete(t.key),null):i?o.items[0]:null}#n(t){let o=Date.now();for(let[i,e]of this.#a)e<=o&&this.#a.delete(i);for(this.#a.delete(t),this.#a.set(t,o+ice);this.#a.size>oce;)this.#a.delete(this.#a.keys().next().value)}async#g(t,o){try{return await t.respond({ok:!0,value:{sessionId:t.sessionId,approvalId:o.approvalId,outcome:"rejected"}},{signal:AbortSignal.timeout(5e3)}),!0}catch(i){if(i?.code==="interaction-not-pending")return!1;throw i}}};var Gb=new WeakMap;function gce(n){let t=Gb.get(n);return t||(t=new Map,Gb.set(n,t)),t}async function Vc(n,t,o){let i=typeof n;if(i!=="object"&&i!=="function"||n===null)throw new TypeError("state is required");if(typeof t!="string"||!t)throw new TypeError("conversation key is required");if(typeof o!="function")throw new TypeError("operation is required");let e=gce(n),a=e.get(t)??Promise.resolve(),A,r=new Promise(s=>{A=s});e.set(t,r),await a;try{return await o()}finally{A(),e.get(t)===r&&(e.delete(t),e.size===0&&Gb.delete(n))}}var oi="workspace-session-stale";function PH(n,t){return typeof n.workspaceSession=="function"?n.workspaceSession(t):Object.freeze({sessionId:t,sessionExists:(...o)=>n.sessionExists(t,...o),models:(...o)=>n.getSessionModels(t,...o),selectModel:(...o)=>n.selectSessionModel(t,...o),isRunning:(...o)=>n.isSessionRunning(t,...o),hasActiveTurn:(...o)=>n.hasActiveTurn(t,...o),stopActiveTurn:(...o)=>n.stopActiveTurn(t,...o),steerActiveTurn:(...o)=>n.steerActiveTurn(t,...o),ask:(...o)=>n.ask(t,...o)})}async function cce(n,t){return t===void 0?n.sessionExists():n.sessionExists(t)}async function Ice(n,t){return t===void 0?n.createSession():n.createSession(t)}async function ni({harness:n,state:t,key:o,text:i,content:e,createOptions:a,existsOptions:A,askOptions:r}){for(;;)try{let s=await Vc(t,o,async()=>{let B=t.sessionFor(o),f=B?PH(n,B):null;if(!f||!await cce(f,A)){if(B=await Ice(n,a),await t.setSession(o,B)===!1)return null;f=PH(n,B)}return{sessionId:B,session:f}});if(!s)continue;let g=[],c=typeof r=="object"&&typeof r?.onArtifact=="function"?r.onArtifact:null,I=typeof r=="number"?{timeoutMs:r}:{...r};I.onArtifact=async B=>{g.push(B),await c?.(B)};let d=await s.session.ask(e??i,I);return{sessionId:s.sessionId,answer:d,...g.length>0?{artifacts:g}:{}}}catch(s){if(s?.code!==oi)throw s}}var lce=/^\/compact(?=$|\s)([\s\S]*)$/i,pce="\u7528\u6CD5\uFF1A/compact\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",GH=new Map([["No compactable history yet.","\u6682\u65E0\u53EF\u538B\u7F29\u7684\u5386\u53F2\u8BB0\u5F55\u3002"],["Compaction is unavailable because this process has an active compaction, or the agent is not idle.","\u5F53\u524D\u4F1A\u8BDD\u6B63\u5728\u751F\u6210\u56DE\u590D\u6216\u6267\u884C\u538B\u7F29\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002"],["Compaction cancelled.","\u4E0A\u4E0B\u6587\u538B\u7F29\u5DF2\u53D6\u6D88\u3002"],["The history selected for compaction changed before it could be replaced. The conversation is unchanged; the attempt is recorded in the session log.","\u538B\u7F29\u671F\u95F4\u4F1A\u8BDD\u5386\u53F2\u53D1\u751F\u53D8\u5316\uFF0C\u672C\u6B21\u672A\u4FEE\u6539\u4F1A\u8BDD\uFF0C\u8BF7\u91CD\u8BD5\u3002"],["Compaction could not produce a useful summary. The conversation is unchanged; the attempt is recorded in the session log.","\u672A\u80FD\u751F\u6210\u6709\u6548\u7684\u538B\u7F29\u6458\u8981\uFF0C\u672C\u6B21\u672A\u4FEE\u6539\u4F1A\u8BDD\u3002"],["Compaction did not finish cleanly; some session history may have changed. Inspect the current session state before retrying.","\u4E0A\u4E0B\u6587\u538B\u7F29\u672A\u6B63\u5E38\u5B8C\u6210\uFF0C\u90E8\u5206\u4F1A\u8BDD\u5386\u53F2\u53EF\u80FD\u5DF2\u53D8\u5316\uFF0C\u8BF7\u68C0\u67E5\u4F1A\u8BDD\u540E\u518D\u91CD\u8BD5\u3002"],["Compaction finished, but the session could not be saved.","\u4E0A\u4E0B\u6587\u5DF2\u538B\u7F29\uFF0C\u4F46\u4F1A\u8BDD\u4FDD\u5B58\u5931\u8D25\u3002"]]);function Wc(n){return{handled:!0,message:n,messages:[n]}}function dce(n){if(!n||typeof n!="object"||!["success","error"].includes(n.kind)||n.text!==void 0&&typeof n.text!="string")throw new TypeError("Harness returned an invalid /compact result");let t=n.text?.trim()??"",o=/^Compacted (\d+) history items \(~(\d+) tokens\)\.$/u.exec(t);return o?D("\u5DF2\u538B\u7F29 {count} \u6761\u5386\u53F2\u8BB0\u5F55\uFF08\u7EA6 {tokens} \u4E2A token\uFF09\u3002",{count:o[1],tokens:o[2]}):GH.has(t)?D(GH.get(t)):t||(n.kind==="success"?D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5B8C\u6210\u3002"):D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25\u3002"))}function hce(n){let t=n?.code??n?.failure?.code;return t==="session-not-found"?D("\u5F53\u524D\u804A\u5929\u7ED1\u5B9A\u7684\u4F1A\u8BDD\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u53D1\u9001\u65B0\u6D88\u606F\u5F00\u542F\u4F1A\u8BDD\u3002"):t==="agent-busy"?D("\u5F53\u524D\u4F1A\u8BDD\u6B63\u5728\u751F\u6210\u56DE\u590D\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002"):t==="cancelled"||n?.name==="AbortError"?D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5DF2\u53D6\u6D88\u3002"):t===oi||t==="workspace-bot-not-found"?D("\u5DE5\u4F5C\u533A\u6216\u673A\u5668\u4EBA\u72B6\u6001\u5DF2\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u8BD5\u3002"):t==="commands-unavailable"?D("\u5F53\u524D Harness \u6682\u4E0D\u652F\u6301\u4ECE\u673A\u5668\u4EBA\u6267\u884C\u4E0A\u4E0B\u6587\u538B\u7F29\u3002"):D("\u4E0A\u4E0B\u6587\u538B\u7F29\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002")}async function si(n,t,o,i,e={}){if(typeof n!="string")return null;let a=lce.exec(n.trim());if(!a)return null;if(a[1].trim())return Wc(D(pce));if(typeof o?.sessionFor!="function")return Wc(D("\u5F53\u524D\u673A\u5668\u4EBA\u6CA1\u6709\u53EF\u7528\u7684\u4F1A\u8BDD\u72B6\u6001\u3002"));let A=o.sessionFor(i);if(typeof A!="string"||!A)return Wc(D("\u5F53\u524D\u804A\u5929\u8FD8\u6CA1\u6709\u53EF\u538B\u7F29\u7684\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u53D1\u9001\u4E00\u6761\u6D88\u606F\u3002"));if(typeof t?.executeCommand!="function")return Wc(D("\u5F53\u524D\u673A\u5668\u4EBA\u6682\u4E0D\u652F\u6301\u4E0A\u4E0B\u6587\u538B\u7F29\u3002"));try{let r=await t.executeCommand(A,"/compact",e);return Wc(r===void 0?D("\u5F53\u524D Harness \u672A\u6CE8\u518C /compact \u547D\u4EE4\uFF0C\u8BF7\u786E\u8BA4\u4E0A\u4E0B\u6587\u538B\u7F29\u7EC4\u4EF6\u5DF2\u542F\u7528\u3002"):dce(r?.result))}catch(r){return Wc(hce(r))}}var FH={name:"@xmanrui/dsh-im",version:"2.6.0",description:"\u628A\u4E5D\u79CD IM \u673A\u5668\u4EBA\u548C\u516C\u7F51 AI Office \u63A5\u5165\u672C\u673A DeepSeek Harness\u3002 Connect nine IM channels and a public AI Office to a local DeepSeek Harness.",keywords:["deepseek-harness","dsh","dsh-plugin","ai-agent","im","instant-messaging","chatbot","feishu","lark","wechat","wecom","dingtalk","qq","slack","telegram","discord","whatsapp","ai-office"],author:{name:"xmanrui",url:"https://github.com/xmanrui"},contributors:[{name:"C3H3-AI",url:"https://github.com/C3H3-AI"}],license:"MIT",type:"module",repository:{type:"git",url:"git+https://github.com/xmanrui/dsh-im.git"},homepage:"https://github.com/xmanrui/dsh-im#readme",bugs:"https://github.com/xmanrui/dsh-im/issues",publishConfig:{access:"public"},bin:{"dsh-im":"bin/dsh-im.mjs"},main:"./lib/index.js",exports:{".":"./lib/index.js","./client":"./lib/client.js","./package.json":"./package.json"},files:["assets","bin","cordis.patch.yml","lib","plugin-src","scripts","src","LICENSE","README.md","README.en.md","THIRD_PARTY_NOTICES.md"],dsh:{bundle:{patch:"./cordis.patch.yml"},client:{inject:["@deepseek-ai/dsh-client-connection","@deepseek-ai/dsh-client-runtime","@deepseek-ai/dsh-client-ui-settings","@deepseek-ai/dsh-client-ui-slots","@deepseek-ai/dsh-client-locale"],platform:"web"}},scripts:{build:"node plugin-src/client/build.mjs && node plugin-src/host/build.mjs",test:"node --test test/*.test.mjs test/channels/*/*.test.mjs",check:"npm test && npm run build && node scripts/verify-package.mjs"},engines:{node:">=22.19"},dependencies:{"@tencent-connect/qqbot-connector":"1.2.0","@tencent-connect/qqbot-nodejs":"1.0.4","@wecom/aibot-node-sdk":"1.0.7","dingtalk-stream":"2.1.4",qrcode:"1.5.4"},devDependencies:{"@larksuiteoapi/node-sdk":"1.73.0","@whiskeysockets/baileys":"7.0.0-rc14",esbuild:"0.25.9","https-proxy-agent":"5.0.1",react:"18.3.1","react-dom":"18.3.1","react-test-renderer":"18.3.1"}};var Cce=/^\/(?:stop|steer|version)(?=$|\s)/iu,uce=/^\/stop(?=$|\s)/iu,Bce=/^\/version(?=$|\s)/iu,fce="\u7528\u6CD5\uFF1A/stop\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",Qce="\u7528\u6CD5\uFF1A/version\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",yce="\u7528\u6CD5\uFF1A/steer <\u8865\u5145\u6307\u4EE4>",mce="\u63A7\u5236\u547D\u4EE4\u4EC5\u652F\u6301\u7EAF\u6587\u5B57\uFF0C\u8BF7\u79FB\u9664\u56FE\u7247\u540E\u91CD\u8BD5\u3002";function co(n,t={}){return{message:n,...t}}function LH(n){return n?{signal:n}:{}}function UH(n,t,o){if(typeof t?.sessionFor!="function")return null;let i=t.sessionFor(o);if(typeof i!="string"||!i)return null;if(typeof n?.workspaceSession!="function")throw new TypeError("Harness does not support workspace sessions");let e=n.workspaceSession(i);if(!e||typeof e!="object")throw new TypeError("Harness returned an invalid workspace session");return e}function Pi(n){return typeof n=="string"&&Cce.test(n.trim())}async function gi(n,t,o,i,{signal:e,hasImages:a=!1,pendingInteraction:A=!1,control:r}={}){if(!Pi(n))return null;let s=n.trim(),g=uce.test(s),c=Bce.test(s);if(a)return co(D(mce));if(c)return/^\/version$/iu.test(s)?co(`dsh-im v${FH.version}`):co(D(Qce));if(g){if(!/^\/stop$/iu.test(s))return co(D(fce));let Q=UH(t,o,i);if(!Q)return co(D("\u5F53\u524D\u804A\u5929\u6CA1\u6709\u6B63\u5728\u8FD0\u884C\u7684\u4EFB\u52A1\u3002"));if(typeof Q.stopActiveTurn!="function")throw new TypeError("Harness session does not support stopping active turns");return await Q.stopActiveTurn(r,LH(e))?co(D("\u5DF2\u8BF7\u6C42\u505C\u6B62\u5F53\u524D\u4EFB\u52A1\u3002"),{stopped:!0}):co(D("\u5F53\u524D\u804A\u5929\u6CA1\u6709\u6B63\u5728\u8FD0\u884C\u7684\u4EFB\u52A1\u3002"))}let d=/^\/steer(?:\s+([\s\S]*))?$/iu.exec(s)?.[1]?.trim()??"";if(!d)return co(D(yce));if(A)return co([D("\u5F53\u524D\u4EFB\u52A1\u6B63\u5728\u7B49\u5F85\u4F60\u7684\u56DE\u7B54\u6216\u5BA1\u6279\u3002"),"",D("\u8BF7\u5148\u5904\u7406\u5F53\u524D\u8BF7\u6C42\uFF0C\u6216\u8005\u53D1\u9001 /stop \u505C\u6B62\u4EFB\u52A1\u3002")].join(` `));let B=UH(t,o,i);if(!B)return co(D("\u5F53\u524D\u804A\u5929\u6CA1\u6709\u7ED1\u5B9A\u4F1A\u8BDD\uFF0C\u65E0\u6CD5\u8865\u5145\u6307\u4EE4\u3002\u8BF7\u5148\u7ED1\u5B9A\u4F1A\u8BDD\u3002"));if(typeof B.steerActiveTurn!="function")throw new TypeError("Harness session does not support steering active turns");let f=await B.steerActiveTurn(d,r,LH(e));return co(f?D("\u5DF2\u63D0\u4EA4\u8865\u5145\u6307\u4EE4\uFF0CAgent \u4F1A\u5728\u4E0B\u4E00\u6B65\u8BFB\u53D6\u3002"):D("\u4EFB\u52A1\u5DF2\u7ED3\u675F\uFF0C\u6CA1\u6709\u6B63\u5728\u8FD0\u884C\u7684\u4EFB\u52A1\uFF0C\u65E0\u6CD5\u8865\u5145\u6307\u4EE4\u3002\u8BF7\u76F4\u63A5\u53D1\u9001\u6D88\u606F\u5F00\u59CB\u65B0\u4EFB\u52A1\u3002"))}import{realpath as xH,stat as YH}from"node:fs/promises";import{isAbsolute as jH,resolve as Sce}from"node:path";var Dce=/^\/workspace(?:\s+([\s\S]+))?$/i,wce=/^\/workspacelist(?:\s+([\s\S]+))?$/i,Oce=/^\/sessionlist(?:\s+([\s\S]+))?$/i,bce=/^\/session(?=$|\s)/i,Mce=/^\/session[ \t]+([^\s]+)$/i,_ce=4096,Tce=1800,Nce=256,JH=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u,Rce=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu,qH="\u7528\u6CD5\uFF1A/session Session ID \u6216\u5F53\u524D\u5DE5\u4F5C\u533A\u5E8F\u53F7\uFF08/session N\uFF09",Fl=["\u7528\u6CD5\uFF1A","/sessionlist \u5217\u51FA\u5F53\u524D\u5DE5\u4F5C\u533A\u4F1A\u8BDD","/sessionlist \u5DE5\u4F5C\u533A\u5E8F\u53F7 \u6309 /workspacelist \u5E8F\u53F7\u5217\u51FA\u4F1A\u8BDD","/sessionlist \u5DE5\u4F5C\u533A\u7EDD\u5BF9\u8DEF\u5F84 \u5217\u51FA\u6307\u5B9A\u5DE5\u4F5C\u533A\u4F1A\u8BDD"].join(` `);function Pt(n,t=[n]){return{handled:!0,message:n,messages:t}}function Ll(n){return typeof n!="string"||n.length>_ce||!jH(n)||JH.test(n)?null:Sce(n)}function df(n){return typeof n!="string"?"":n.replace(Rce," ").replace(/\s+/gu," ").trim()}function HH(n){return typeof n=="string"&&n.length>0&&n.length<=Nce&&!new RegExp("\\p{White_Space}","u").test(n)&&!JH.test(n)}async function Fb(n){let t=await Promise.all(n.map(async o=>{let i=Ll(o);if(!i)return null;try{return(await YH(i)).isDirectory()?Ll(await xH(i)):null}catch{return null}}));return[...new Set(t.filter(Boolean))]}async function Lb(n){if(typeof n!="string"||!jH(n.trim()))return{error:D(`\u5DE5\u4F5C\u533A\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84\u3002 {usage}`,{usage:D(Fl)})};let t=Ll(n.trim());if(!t)return{error:D(`\u5DE5\u4F5C\u533A\u8DEF\u5F84\u5305\u542B\u4E0D\u652F\u6301\u7684\u5B57\u7B26\u6216\u957F\u5EA6\u8D85\u8FC7\u9650\u5236\u3002 diff --git a/package-lock.json b/package-lock.json index 366971e..0530eef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@xmanrui/dsh-im", - "version": "2.5.0", + "version": "2.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@xmanrui/dsh-im", - "version": "2.5.0", + "version": "2.6.0", "license": "MIT", "dependencies": { "@tencent-connect/qqbot-connector": "1.2.0", diff --git a/package.json b/package.json index 456e716..1144f55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xmanrui/dsh-im", - "version": "2.5.0", + "version": "2.6.0", "description": "把九种 IM 机器人和公网 AI Office 接入本机 DeepSeek Harness。 Connect nine IM channels and a public AI Office to a local DeepSeek Harness.", "keywords": [ "deepseek-harness",