From 50d55090b9e44ea937a496042db89e5162a5aa58 Mon Sep 17 00:00:00 2001 From: xmanrui <841206367@qq.com> Date: Wed, 26 Aug 2026 18:04:31 +0800 Subject: [PATCH] chore: release v3.0.4 --- CHANGELOG.md | 10 +++++++++- lib/client.js | 2 +- lib/index.js | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 510fd4c..7c071da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ This file records the notable changes in each dsh-im release. Its format follows ## [Unreleased] +## [3.0.4] - 2026-08-26 + +### Changed / 变更 + +- 回退 3.0.3 中未计划进入 `main` 的 WhatsApp 群聊提及、回复识别与群成员调用白名单改动;WhatsApp 行为恢复到 3.0.2。 + Reverted the WhatsApp group mention/reply detection and group-caller allowlist changes from 3.0.3 that were not intended for `main`; WhatsApp behavior returns to 3.0.2. + ## [3.0.3] - 2026-08-26 ### Fixed / 修复 @@ -382,7 +389,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/v3.0.3...HEAD +[Unreleased]: https://github.com/xmanrui/dsh-im/compare/v3.0.4...HEAD +[3.0.4]: https://github.com/xmanrui/dsh-im/compare/v3.0.3...v3.0.4 [3.0.3]: https://github.com/xmanrui/dsh-im/compare/v3.0.2...v3.0.3 [3.0.2]: https://github.com/xmanrui/dsh-im/compare/v3.0.1...v3.0.2 [3.0.1]: https://github.com/xmanrui/dsh-im/compare/v3.0.0...v3.0.1 diff --git a/lib/client.js b/lib/client.js index d86bcd8..67ba271 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: "3.0.3", + version: "3.0.4", 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 4eb2ccd..3491b04 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 Tb(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 Nb(n,t){let o=Number(n);return Number.isFinite(o)&&o>0?o:t}function vH({fetchImpl:n=fetch,registrationBaseUrl:t=process.env.DINGTALK_REGISTRATION_BASE_URL||MH,registrationSource:o=process.env.DINGTALK_REGISTRATION_SOURCE||qge,now:i=()=>Date.now(),cardMinIntervalMs:e=50,cardBackoffMs:a=1e3,delay:A=rce}={}){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=Rb(t,{label:"\u9489\u9489\u6CE8\u518C\u670D\u52A1",requireSubdomain:!1}),s=new URL(Jge),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 ae=await bn(n,Q(s,"v1.0/oauth2/accessToken"),{body:{appKey:R,appSecret:V},signal:q,action:"\u9274\u6743"}),ge=WA(ae?.accessToken);if(!ge)throw new gt("invalid-access-token","\u9489\u9489\u670D\u52A1\u6CA1\u6709\u8FD4\u56DE\u8BBF\u95EE\u4EE4\u724C\u3002");let Se=Nb(ae?.expireIn??ae?.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 P=WA(H),W=WA(j),ae=WA(q)??P,ge=WA(U),Se=WA(R),de=WA(V);if(!P||!W)throw new TypeError("clientId and clientSecret are required");if(!ae)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:P,clientSecret:W,signal:L,requestKind:"reaction"}),Be=await bn(n,Q(s,`v1.0/robot/emotion/${T}`),{body:{robotCode:ae,openMsgId:ge,openConversationId:Se,emotionType:2,emotionName:de,textEmotion:{emotionId:Zge,emotionName:de,text:de,backgroundId:Xge}},headers:{"x-acs-dingtalk-access-token":De},signal:L,timeoutMs:Wge,action:T==="reply"?"\u6D88\u606F\u72B6\u6001\u6DFB\u52A0":"\u6D88\u606F\u72B6\u6001\u64A4\u56DE"}),ve=Be?.success===!1?qh(Be?.code??Be?.errcode)??"rejected":Mb(Be);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 P=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":P},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 ae=WA(W?.downloadUrl??W?.download_url);if(!ae)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 tce(ae)}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 P={"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:P,signal:R,action:"AI Card \u5931\u8D25\u6536\u53E3"}),G("v1.0/card/instances",{method:"PUT",body:{outTrackId:V,cardData:_b(L,"5"),cardUpdateOptions:{updateCardDataByKey:!0}},headers:P,signal:R,action:"AI Card \u5931\u8D25\u72B6\u6001"})],ae=await Promise.allSettled(W);if(ae.every(({status:ge})=>ge==="rejected"))throw ae[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 P=ice(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 ae=new URL("media/upload",MH);ae.searchParams.set("access_token",W),ae.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 ace(n,ae,{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=Mb(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 Be={robotCode:P.robotCode,msgKey:L,msgParam:JSON.stringify(T(De,U)),...P.type==="group"?{openConversationId:P.openConversationId}:{userIds:[P.userId]}},ve=P.type==="group"?"v1.0/robot/groupMessages/send":"v1.0/robot/oToMessages/batchSend",eA;try{eA=await bn(n,Q(s,ve),{body:Be,headers:{"x-acs-dingtalk-access-token":W},signal:R,action:"\u6587\u4EF6\u6D88\u606F\u53D1\u9001"})}catch(Re){throw Ace(Re,R)}let iA=Mb(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=Tb(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=Tb(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=Rb(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:Nb(U.expires_in,7200),intervalSeconds:Nb(U.interval,5)}},async pollRegistration({deviceCode:H,signal:j}={}){let q=WA(H);if(!q)throw new TypeError("deviceCode is required");let U=Tb(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||!$ge.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 P=nce(q),W=await y({clientId:V,clientSecret:L,signal:R}),ae=`dsh_${Yh()}`,ge={"x-acs-dingtalk-access-token":W},Se=!1;try{await G("v1.0/card/instances",{body:{cardTemplateId:zge,outTrackId:ae,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:sce(ae,P,V),headers:ge,signal:R,action:"AI Card \u6295\u653E"}),Se=!0,await G("v1.0/card/instances",{method:"PUT",body:{outTrackId:ae,cardData:_b(T,"2")},headers:ge,signal:R,action:"AI Card \u542F\u52A8"}),await G("v1.0/card/streaming",{method:"PUT",body:{outTrackId:ae,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:ae,text:D("\u5361\u7247\u5DF2\u7ED3\u675F\uFF0C\u8BF7\u67E5\u770B\u540E\u7EED\u6D88\u606F\u3002"),signal:De}).catch(()=>{})}throw de}return{cardInstanceId:ae}},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 P={"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:P,signal:R,action:"AI Card \u5B8C\u6210"});let ae=!0,ge={method:"PUT",body:{outTrackId:V,cardData:_b(L,"3"),cardUpdateOptions:{updateCardDataByKey:!0}},headers:P,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{ae=!1}}return{delivered:!0,completed:ae}},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}),P=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(P?.errcode!==void 0&&P.errcode!==0||P?.code!==void 0&&P.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:oce(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 gce=500,cce="\u5361\u7247\u5DF2\u7ED3\u675F\uFF0C\u8BF7\u67E5\u770B\u540E\u7EED\u6D88\u606F\u3002";function kb(n,t){if(typeof n!="string")throw new TypeError(`${t} must be a string`);return n}function PH(n,t){if(typeof n!="string"||!n.trim())throw new TypeError(`${t} is required`);return n.trim()}function GH({api:n,clientId:t,clientSecret:o,target:i,signal:e,logger:a=console,updateIntervalMs:A=gce,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=PH(t,"clientId"),c=PH(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(cce),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 P=f;f=null,y=(async()=>{try{await n.updateAiCard({...B,text:P,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(kb(T,"initialText"),d!=="idle")return!1;d="starting";try{let P=await n.createAiCard({clientId:g,clientSecret:c,target:i,initialText:T,signal:e}),W=typeof P?.cardInstanceId=="string"?P.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=>{kb(T,"progressText"),d==="active"&&(f=T,!Q&&!y&&U())},finish:T=>{if(kb(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 P=y;return m=(async()=>{if(P&&await P,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 pf(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})),pf(n.header)&&e.push("",n.header.trim()),e.push("",pf(n.question)??D("\u8BF7\u8F93\u5165\u4F60\u7684\u56DE\u7B54\u3002")),pf(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=pf(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 FH(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=FH(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=FH(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 Ice=new Map([["\u6279\u51C6","allowed-once"],["\u540C\u610F","allowed-once"],["yes","allowed-once"],["\u62D2\u7EDD","rejected"],["\u4E0D\u540C\u610F","rejected"],["no","rejected"]]),vb="\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",lce="\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",pce=5*6e4,dce=2048;function wa(n){return typeof n=="string"?n.trim():""}function Pb(n){return wa(n).replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g,"")}function hce(n){return Ice.get(wa(n).toLowerCase())??null}function UH(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 Ece(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=Pb(t);if(!o)return t===""?"{}":null;try{return JSON.stringify(JSON.parse(o),null,2)}catch{return o}}function Gb(n,{toolCall:t,requiresMention:o=!1,maxArgumentsLength:i=6e3}={}){if(!UH(n))return null;let e=wa(n.callId);if(!e||wa(t?.callId)!==e||wa(t?.name)!==wa(n.toolName))return null;let a=Ece(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:Pb(n.toolName)}),D("\u64CD\u4F5C\u53C2\u6570\uFF1A"),a],r=Pb(n.reason);return r&&A.push(D("\u539F\u56E0\uFF1A{reason}",{reason:r})),A.push("",D(vb)),o&&A.push("",D("\u7FA4\u804A\u4E2D\u8BF7 @\u673A\u5668\u4EBA \u540E\u53D1\u9001\u5BA1\u6279\u51B3\u5B9A\u3002")),A.join(` -`)}function LH(n,t){return{ok:!0,value:{sessionId:n.sessionId,approvalId:n.approvalId,outcome:t}}}function df(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=hce(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(lce));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(vb));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(vb));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||!UH(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=Gb(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(df(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(LH(e,"rejected"),{signal:AbortSignal.timeout(5e3)}),e.closedOutcome="rejected",(e.presented||e.deliveryCompleted)&&!e.resolutionNotified&&(e.resolutionNotified=!0,await e.send(df("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(df(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(LH(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(df(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+pce);this.#a.size>dce;)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 Fb=new WeakMap;function Cce(n){let t=Fb.get(n);return t||(t=new Map,Fb.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=Cce(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&&Fb.delete(n))}}var oi="workspace-session-stale";function HH(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 uce(n,t){return t===void 0?n.sessionExists():n.sessionExists(t)}async function Bce(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?HH(n,B):null;if(!f||!await uce(f,A)){if(B=await Bce(n,a),await t.setSession(o,B)===!1)return null;f=HH(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 fce=/^\/compact(?=$|\s)([\s\S]*)$/i,Qce="\u7528\u6CD5\uFF1A/compact\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",KH=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 yce(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]}):KH.has(t)?D(KH.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 mce(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=fce.exec(n.trim());if(!a)return null;if(a[1].trim())return Wc(D(Qce));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"):yce(r?.result))}catch(r){return Wc(mce(r))}}var xH={name:"@xmanrui/dsh-im",version:"3.0.3",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 run build && npm test && 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 Dce=/^\/(?:stop|steer|version)(?=$|\s)/iu,wce=/^\/stop(?=$|\s)/iu,Oce=/^\/version(?=$|\s)/iu,bce="\u7528\u6CD5\uFF1A/stop\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",Mce="\u7528\u6CD5\uFF1A/version\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",_ce="\u7528\u6CD5\uFF1A/steer <\u8865\u5145\u6307\u4EE4>",Tce="\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 YH(n){return n?{signal:n}:{}}function jH(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"&&Dce.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=wce.test(s),c=Oce.test(s);if(a)return co(D(Tce));if(c)return/^\/version$/iu.test(s)?co(`dsh-im v${xH.version}`):co(D(Mce));if(g){if(!/^\/stop$/iu.test(s))return co(D(bce));let Q=jH(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,YH(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(_ce));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 LH(n,t){return{ok:!0,value:{sessionId:n.sessionId,approvalId:n.approvalId,outcome:t}}}function df(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=hce(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(lce));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(vb));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(vb));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||!UH(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=Gb(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(df(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(LH(e,"rejected"),{signal:AbortSignal.timeout(5e3)}),e.closedOutcome="rejected",(e.presented||e.deliveryCompleted)&&!e.resolutionNotified&&(e.resolutionNotified=!0,await e.send(df("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(df(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(LH(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(df(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+pce);this.#a.size>dce;)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 Fb=new WeakMap;function Cce(n){let t=Fb.get(n);return t||(t=new Map,Fb.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=Cce(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&&Fb.delete(n))}}var oi="workspace-session-stale";function HH(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 uce(n,t){return t===void 0?n.sessionExists():n.sessionExists(t)}async function Bce(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?HH(n,B):null;if(!f||!await uce(f,A)){if(B=await Bce(n,a),await t.setSession(o,B)===!1)return null;f=HH(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 fce=/^\/compact(?=$|\s)([\s\S]*)$/i,Qce="\u7528\u6CD5\uFF1A/compact\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",KH=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 yce(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]}):KH.has(t)?D(KH.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 mce(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=fce.exec(n.trim());if(!a)return null;if(a[1].trim())return Wc(D(Qce));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"):yce(r?.result))}catch(r){return Wc(mce(r))}}var xH={name:"@xmanrui/dsh-im",version:"3.0.4",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 run build && npm test && 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 Dce=/^\/(?:stop|steer|version)(?=$|\s)/iu,wce=/^\/stop(?=$|\s)/iu,Oce=/^\/version(?=$|\s)/iu,bce="\u7528\u6CD5\uFF1A/stop\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",Mce="\u7528\u6CD5\uFF1A/version\uFF08\u4E0D\u5E26\u53C2\u6570\uFF09",_ce="\u7528\u6CD5\uFF1A/steer <\u8865\u5145\u6307\u4EE4>",Tce="\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 YH(n){return n?{signal:n}:{}}function jH(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"&&Dce.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=wce.test(s),c=Oce.test(s);if(a)return co(D(Tce));if(c)return/^\/version$/iu.test(s)?co(`dsh-im v${xH.version}`):co(D(Mce));if(g){if(!/^\/stop$/iu.test(s))return co(D(bce));let Q=jH(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,YH(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(_ce));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=jH(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,YH(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 zH,stat as VH}from"node:fs/promises";import{isAbsolute as WH,resolve as Nce}from"node:path";var Rce=/^\/workspace(?:\s+([\s\S]+))?$/i,kce=/^\/workspacelist(?:\s+([\s\S]+))?$/i,vce=/^\/sessionlist(?:\s+([\s\S]+))?$/i,Pce=/^\/session(?=$|\s)/i,Gce=/^\/session[ \t]+([^\s]+)$/i,Fce=4096,Lce=1800,Uce=256,ZH=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u,Hce=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu,XH="\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>Fce||!WH(n)||ZH.test(n)?null:Nce(n)}function hf(n){return typeof n!="string"?"":n.replace(Hce," ").replace(/\s+/gu," ").trim()}function JH(n){return typeof n=="string"&&n.length>0&&n.length<=Uce&&!new RegExp("\\p{White_Space}","u").test(n)&&!ZH.test(n)}async function Lb(n){let t=await Promise.all(n.map(async o=>{let i=Ll(o);if(!i)return null;try{return(await VH(i)).isDirectory()?Ll(await zH(i)):null}catch{return null}}));return[...new Set(t.filter(Boolean))]}async function Ub(n){if(typeof n!="string"||!WH(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 a467116..7799adf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@xmanrui/dsh-im", - "version": "3.0.3", + "version": "3.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@xmanrui/dsh-im", - "version": "3.0.3", + "version": "3.0.4", "license": "MIT", "dependencies": { "@tencent-connect/qqbot-connector": "1.2.0", diff --git a/package.json b/package.json index e2acde0..def85da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xmanrui/dsh-im", - "version": "3.0.3", + "version": "3.0.4", "description": "把九种 IM 机器人和公网 AI Office 接入本机 DeepSeek Harness。 Connect nine IM channels and a public AI Office to a local DeepSeek Harness.", "keywords": [ "deepseek-harness",