@wps365/openclaw-wpsxiezuo 1.9.1-beta.2 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,7 @@ export declare const WebhookConfigSchema: z.ZodObject<{
59
59
  /**
60
60
  * 用户 OAuth `redirect_uri`(插件内置,**须**与 WPS 开放平台「安全设置 → 用户授权回调地址」登记**完全一致**)。
61
61
  */
62
- export declare const DEFAULT_USER_OAUTH_REDIRECT_URI = "https://o.wpsgo.com/app/41000207/El1ykTHO5aVv/";
62
+ export declare const DEFAULT_USER_OAUTH_REDIRECT_URI = "https://365.kdocs.cn/woa/openclaw/callback";
63
63
  export declare const WpsConfigSchema: z.ZodObject<{
64
64
  enabled: z.ZodDefault<z.ZodBoolean>;
65
65
  appId: z.ZodString;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var ro=Object.defineProperty;var we=(e,t)=>()=>(e&&(t=e(e=0)),t);var On=(e,t)=>{for(var r in t)ro(e,r,{get:t[r],enumerable:!0})};function _r(e){return e===401?{hint:"invalid/expired token or app credentials",retriable:!1}:e===403?{hint:"permission denied or scope not granted",retriable:!1}:e===404?{hint:"resource not found",retriable:!1}:e===409?{hint:"resource state conflict",retriable:!1}:e===429?{hint:"rate limited by WPS API",retriable:!0}:e>=500?{hint:"WPS API temporarily unavailable",retriable:!0}:{hint:"unexpected WPS API status",retriable:!1}}var Fe,se,St=we(()=>{"use strict";Fe=class extends Error{detail;name="WpsRequestError";constructor(t,r){super(t),this.detail=r}get retriable(){return this.detail.retriable===!0}get stage(){return this.detail.stage}},se=class extends Error{cause;name="WpsTokenError";constructor(t,r){super(t),this.cause=r}}});function oo(e){return e===401?"invalid app credentials (check client_id/client_secret)":e===403?"app not authorized for this enterprise or scope":e===429?"rate limited by WPS token endpoint":e>=500?"WPS OAuth service unavailable":"unexpected OAuth response"}function j(e){let t=`${e.clientId}@${e.baseUrl}`,r=An.get(t);return r||(r=new Wt(e),An.set(t,r)),r}var no,io,Wt,An,fr=we(()=>{"use strict";St();no=6e4,io=["/oauth2/token","/openapi/oauth2/token"];Wt=class{creds;token=null;inFlight=null;constructor(t){this.creds=t}async getToken(){if(this.token&&Date.now()<this.token.expiresAt-no)return this.token.accessToken;if(this.inFlight)return this.inFlight;this.inFlight=this.requestToken();try{return await this.inFlight}finally{this.inFlight=null}}invalidate(){this.token=null}async requestToken(){let t=this.creds.baseUrl.replace(/\/$/,""),r="unknown token error";for(let n of io){let o=`${t}${n}`,i;try{i=await fetch(o,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials",client_id:this.creds.clientId,client_secret:this.creds.clientSecret})})}catch(a){r=`Network error requesting token from ${o}: ${String(a)}`;continue}if(!i.ok){let a=await i.text();r=`Token request failed (${i.status}) at ${o}: ${oo(i.status)}; body=${a}`;continue}let s=await i.json();if(s.code!==void 0&&s.code!==0){r=`WPS OAuth error (code ${s.code}): ${s.msg??"unknown"}`;continue}if(!s.access_token||!s.expires_in){r=`Invalid token response from ${o}: missing access_token or expires_in`;continue}return this.token={accessToken:s.access_token,expiresAt:Date.now()+s.expires_in*1e3},this.token.accessToken}throw new se(r)}},An=new Map});import{z as x}from"zod";function Lt(e){return zt}function gr(e){let t=e?.defaultAccountId?.trim();if(t)return t;let r=e?.accounts?Object.keys(e.accounts)[0]:void 0;return r&&r.trim()?r:Ce}function yr(e){return e?e.accounts&&Object.keys(e.accounts).length>0?e.accounts:!(e.appId||e.appSecret||e.companyId||e.webhook||e.sdk||e.groups||e.dmPolicy||e.groupPolicy)?{}:!e.appId||!e.appSecret?{}:{[Ce]:{enabled:e.enabled??!0,appId:e.appId,appSecret:e.appSecret,companyId:e.companyId,baseUrl:e.baseUrl??"https://openapi.wps.cn",enableEncryption:e.enableEncryption??!0,webhook:e.webhook,sdk:e.sdk,dmPolicy:e.dmPolicy,allowFrom:e.allowFrom,groupPolicy:e.groupPolicy,groups:e.groups,instantAck:e.instantAck,robotJoinGroupMessage:e.robotJoinGroupMessage,mcp:e.mcp}}:{}}function _e(e){return!e?.appId||!e?.appSecret?null:{clientId:e.appId,clientSecret:e.appSecret,baseUrl:e.baseUrl??"https://openapi.wps.cn"}}var Rn,$n,qn,Cn,Dn,Nn,zt,mr,hr,E,be,Ce,rt=we(()=>{"use strict";Rn=x.enum(["disabled","open","allowlist","pairing"]).default("pairing"),$n=x.object({requireMention:x.boolean().optional(),toolPolicy:x.enum(["full","limited","none"]).optional()}).passthrough(),qn=x.object({enabled:x.boolean().default(!1),mode:x.literal("app").default("app"),clientId:x.string().optional(),clientSecret:x.string().optional(),baseUrl:x.string().optional(),toolAllowlist:x.array(x.string()).min(1,"mcp.toolAllowlist must contain at least one tool").default(["wps_user_search","wps_user_get","wps_message_send","wps_calendar_create","wps_calendar_list_events","wps_calendar_search_events","wps_calendar_update_event","wps_calendar_delete_event","wps_calendar_get_event","wps_calendar_list_event_attendees","wps_calendar_add_event_attendees","wps_calendar_list_event_meeting_rooms","wps_calendar_event_meeting_rooms_batch_create","wps_calendar_event_meeting_rooms_batch_delete","wps_calendar_delete_event_attendees","wps_calendar_list_calendar_event_instances","wps_calendar_list_event_instances","wps_calendar_respond_invitation","wps_todo_create_personal_task","wps_todo_list_personal_tasks","wps_todo_get_personal_task","wps_todo_update_personal_task","wps_todo_update_personal_task_status","wps_cloud_doc_list_drives","wps_cloud_doc_list_children_files","wps_cloud_doc_create_file","wps_cloud_doc_upload_file","wps_cloud_doc_extract_file_content","wps_cloud_doc_get_file_meta","wps_cloud_doc_search_files","wps_airpage_create_file","wps_airpage_create_block_content","wps_airpage_query_document_blocks","wps_airpage_batch_query_document_blocks","wps_airpage_delete_block_content","wps_airpage_batch_delete_block_content","wps_airpage_update_document_block","wps_airpage_batch_update_document_blocks","wps_meeting_rooms_list","wps_meeting_rooms_get","wps_meeting_rooms_search","wps_meeting_room_bookings_batch_get","wps_meeting_room_bookings_update_status"])}),Cn=x.object({enabled:x.boolean().default(!0),text:x.string().default("\u5185\u5BB9\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019...")}),Dn=x.object({enabled:x.boolean().default(!1),logLevel:x.enum(["debug","info","warn","error"]).default("info"),endpoint:x.string().optional(),connectTimeoutMs:x.number().min(3e3).max(12e4).default(2e4),pongTimeout:x.number().min(3e4).max(3e5).default(15e4),autoReconnect:x.boolean().default(!0),reconnectBaseInterval:x.number().min(500).max(1e4).default(1e3),reconnectMaxInterval:x.number().min(1e4).max(3e5).default(6e4),reconnectMultiplier:x.number().min(1.5).max(3).default(2),reconnectMaxRetry:x.number().min(-1).max(100).default(-1),reconnectJitter:x.number().min(0).max(.5).default(.2)}),Nn=x.object({path:x.string().default("/wps/webhook"),port:x.number().default(3e3)}),zt="https://o.wpsgo.com/app/41000207/El1ykTHO5aVv/",mr=x.object({enabled:x.boolean().default(!0),appId:x.string().describe("WPS App ID (client_id)"),appSecret:x.string().describe("WPS App Secret (client_secret)"),companyId:x.string().optional().describe("WPS Company ID"),baseUrl:x.string().default("https://openapi.wps.cn"),enableEncryption:x.boolean().default(!0),webhook:Nn.optional(),sdk:Dn.optional(),dmPolicy:Rn.optional(),allowFrom:x.array(x.string()).optional(),groupPolicy:x.enum(["open","allowlist"]).optional(),groups:x.record(x.string(),$n).optional(),instantAck:Cn.optional(),robotJoinGroupMessage:x.string().optional(),mcp:qn.optional()}),hr=mr.partial().extend({defaultAccountId:x.string().optional(),accounts:x.record(x.string(),mr).optional()});E="wps-xiezuo",be="wps-xiezuo",Ce="default"});function wr(e){xt=e}function br(e,t){nt.set(e,t),jn(e,t)}function vt(e){let t=nt.get(e);return t?Date.now()>=t.expiresAt?(nt.delete(e),Un(e),null):t.accessToken:null}function Un(e){let t=Bt.get(e);t&&(clearTimeout(t),Bt.delete(e))}function jn(e,t){if(Un(e),!t.refreshToken)return;let r=Math.max(t.expiresAt-Date.now()-so,1e4),n=setTimeout(()=>{ao(e).catch(()=>{nt.delete(e),Bt.delete(e)})},r);n.unref?.(),Bt.set(e,n)}async function ao(e){let t=nt.get(e);if(!t?.refreshToken||!xt)return;let r=xt.baseUrl.replace(/\/$/,""),n=new URLSearchParams({grant_type:"refresh_token",client_id:xt.appId,client_secret:xt.appSecret,refresh_token:t.refreshToken}),o=await fetch(`${r}/oauth2/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()}),i=await o.text(),s;try{s=JSON.parse(i)}catch{throw new se(`OAuth refresh: non-JSON response (${o.status}): ${i.slice(0,200)}`)}if(!o.ok||typeof s.code=="number"&&s.code!==0)throw new se(`OAuth refresh failed (${o.status}): ${JSON.stringify(s)}`);let a=typeof s.access_token=="string"?s.access_token:"";if(!a)throw new se(`OAuth refresh: missing access_token: ${JSON.stringify(s)}`);let d=typeof s.expires_in=="number"?s.expires_in:7200,l={accessToken:a,refreshToken:typeof s.refresh_token=="string"?s.refresh_token:t.refreshToken,expiresAt:Date.now()+d*1e3,openid:typeof s.openid=="string"?s.openid:t.openid};nt.set(e,l),jn(e,l)}async function Ir(e){let t=e.baseUrl.replace(/\/$/,""),r=new URLSearchParams({grant_type:"authorization_code",client_id:e.appId,client_secret:e.appSecret,code:e.code,redirect_uri:e.redirectUri??zt}),n=await fetch(`${t}/oauth2/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()}),o=await n.text(),i;try{i=JSON.parse(o)}catch{throw new se(`OAuth code exchange: non-JSON response (${n.status}): ${o.slice(0,200)}`)}if(!n.ok||typeof i.code=="number"&&i.code!==0)throw new se(`OAuth code exchange failed (${n.status}): ${JSON.stringify(i)}`);let s=typeof i.access_token=="string"?i.access_token:"";if(!s)throw new se(`OAuth code exchange: missing access_token in response: ${JSON.stringify(i)}`);let a=typeof i.expires_in=="number"?i.expires_in:7200;return{accessToken:s,refreshToken:typeof i.refresh_token=="string"?i.refresh_token:"",expiresAt:Date.now()+a*1e3,openid:typeof i.openid=="string"?i.openid:""}}var nt,Bt,so,xt,it=we(()=>{"use strict";St();rt();nt=new Map,Bt=new Map,so=5*6e4,xt=null});function W(e,t){return new Tt(e,new Ft(t))}function kr(e,t){return new Tt(e,new Gt(t))}var Ft,Gt,Tt,Kt=we(()=>{"use strict";St();Ft=class{tokenStore;constructor(t){this.tokenStore=t}async getHeaders(){return{Authorization:`Bearer ${await this.tokenStore.getToken()}`}}},Gt=class{accessToken;constructor(t){this.accessToken=t}async getHeaders(){return{Authorization:`Bearer ${this.accessToken}`}}},Tt=class{baseUrl;auth;constructor(t,r){this.baseUrl=t,this.auth=r}async request(t){let r=await this.auth.getHeaders(),n=this.buildUrl(t.path,t.query),o=t.method??"GET",i=await fetch(n,{method:o,headers:{"Content-Type":"application/json",...r,...t.headers??{}},body:t.body?JSON.stringify(t.body):void 0}),s=i.headers.get("X-Request-Id")??i.headers.get("x-request-id")??i.headers.get("X-Trace-Id")??i.headers.get("x-trace-id")??void 0;if(!i.ok){let a=await i.text(),d;try{let u=JSON.parse(a);d=u.code??u.result}catch{}let{hint:l,retriable:c}=_r(i.status),p=s?` request_id=${s}`:"";throw console.error(`[WPS-API-ERROR] ${i.status} ${o} ${t.path}${p} body=${a}`),new Fe(`WPS API error (${i.status} ${o} ${t.path}): ${a}`,{stage:"http",method:o,path:t.path,httpStatus:i.status,wpsCode:d,hint:l,retriable:c,requestId:s})}return this.parseResponse(i,o,t.path,s)}buildUrl(t,r){let n=new URL(t,this.baseUrl);if(r){for(let[o,i]of Object.entries(r))if(i!==void 0)if(Array.isArray(i))for(let s of i)n.searchParams.append(o,s);else n.searchParams.set(o,String(i))}return n.toString()}async parseResponse(t,r,n,o){let i=await t.text();if(!i||i.trim()==="")return{};let s;try{s=JSON.parse(i)}catch{throw new Fe(`Failed to parse JSON from ${r} ${n}: ${i.slice(0,200)}`,{stage:"parse",method:r,path:n,hint:"response is not valid JSON",retriable:!1})}let a=s.code??s.result;if(a!==void 0&&a!==0&&a!=="ok"){let d=String(a)==="40300001"?"permission denied by WPS business policy":"WPS business validation failed",l=s.request_id??o,c=l?` request_id=${String(l)}`:"";throw console.error(`[WPS-API-ERROR] biz_code=${String(a)} ${r} ${n}${c} msg=${s.msg??s.message??"unknown"}`),new Fe(`WPS business error code=${String(a)}: ${s.msg??s.message??"unknown"}`,{stage:"business",method:r,path:n,wpsCode:a,hint:d,retriable:!1,requestId:l?String(l):void 0})}return s}}});import{imageSize as co}from"image-size";function Et(e,t=0){if(!e||typeof e!="object"||t>2)return null;let r=e;for(let n of lo){let o=r[n];if(typeof o=="string"&&o.trim())return o.trim()}return r.data&&typeof r.data=="object"?Et(r.data,t+1):null}function Sr(e){let t=Et(e);if(!t)throw new Error("cannot resolve download URL from WPS API response");return t}function Ge(e){try{let t=co(Buffer.isBuffer(e)?e:Buffer.from(e));return t.width&&t.height?{width:t.width,height:t.height}:null}catch{return null}}var lo,Pt=we(()=>{"use strict";lo=["url","download_url","downloadUrl","file_url","fileUrl"]});async function vr(e,t,r){let n=j(e);await W(e.baseUrl,n).request({method:"POST",path:`/v7/chats/${encodeURIComponent(t)}/messages/${encodeURIComponent(r)}/reactions/create`,body:{reaction_type:xr}})}async function Tr(e,t,r,n){try{let o=j(e);await W(e.baseUrl,o).request({method:"POST",path:`/v7/chats/${encodeURIComponent(t)}/messages/${encodeURIComponent(r)}/reactions/delete`,body:{reaction_type:xr}})}catch(o){let i=String(o);i.includes("msgRecalled")||i.includes("message_not_found")||i.includes("404")?(n?.info??console.log)(`WPS thinking reaction cleanup skipped (message gone): ${i.substring(0,100)}`):(n?.error??console.error)(`WPS thinking reaction cleanup failed: ${i}`)}}var xr,Er=we(()=>{"use strict";fr();Kt();xr="emoji_busy"});var Ot=we(()=>{"use strict";St();fr();it();Kt();Pt();Er();rt()});var ci={};On(ci,{getDelegatedScopes:()=>qt,getLazyClient:()=>Kr,getLazyCreds:()=>Vt,getLazyLog:()=>dt,getLazyWpsCfg:()=>Hr,setDelegatedScopes:()=>Yt,setLazyClient:()=>Gr});function Gr(e,t,r,n){Lr=e,ai=t??null,Br=r??null,Fr=n??null}function Kr(){if(!Lr)throw new Error("WPS client not initialized yet (startAccount has not been called)");return Lr}function dt(){return ai}function Hr(){if(!Br)throw new Error("WPS config not set yet (startAccount has not been called)");return Br}function Vt(){if(!Fr)throw new Error("WPS credentials not set yet (startAccount has not been called)");return Fr}function Yt(e){di=e}function qt(){return di}var Lr,ai,Br,Fr,di,ct=we(()=>{"use strict";Lr=null,ai=null,Br=null,Fr=null;di=[]});var Vr={};On(Vr,{buildAuthCard:()=>_i,buildAuthSuccessCard:()=>fi,buildAuthorizeUrl:()=>ui,decodeState:()=>pi,encodeState:()=>li,handleAuthEvent:()=>Ko,sendAuthCard:()=>Xr});import{randomBytes as Bo}from"node:crypto";function li(e){let t=Bo(16).toString("hex");e.nonce=t;let r=t;return Ct.set(r,e),setTimeout(()=>Ct.delete(r),10*6e4).unref?.(),r}function pi(e){let t=Ct.get(e);return t&&Ct.delete(e),t??null}function ui(e){let t=new URL("/oauth2/auth",e.baseUrl);return t.searchParams.set("response_type","code"),t.searchParams.set("client_id",e.appId),t.searchParams.set("redirect_uri",e.redirectUri),t.searchParams.set("scope",e.scopes.join(",")),t.searchParams.set("state",e.state),t.toString()}function _i(e,t,r){let n=t.length>Zt,i=(n?t.slice(0,Zt):t).join(`
1
+ var ro=Object.defineProperty;var we=(e,t)=>()=>(e&&(t=e(e=0)),t);var On=(e,t)=>{for(var r in t)ro(e,r,{get:t[r],enumerable:!0})};function _r(e){return e===401?{hint:"invalid/expired token or app credentials",retriable:!1}:e===403?{hint:"permission denied or scope not granted",retriable:!1}:e===404?{hint:"resource not found",retriable:!1}:e===409?{hint:"resource state conflict",retriable:!1}:e===429?{hint:"rate limited by WPS API",retriable:!0}:e>=500?{hint:"WPS API temporarily unavailable",retriable:!0}:{hint:"unexpected WPS API status",retriable:!1}}var Fe,se,St=we(()=>{"use strict";Fe=class extends Error{detail;name="WpsRequestError";constructor(t,r){super(t),this.detail=r}get retriable(){return this.detail.retriable===!0}get stage(){return this.detail.stage}},se=class extends Error{cause;name="WpsTokenError";constructor(t,r){super(t),this.cause=r}}});function oo(e){return e===401?"invalid app credentials (check client_id/client_secret)":e===403?"app not authorized for this enterprise or scope":e===429?"rate limited by WPS token endpoint":e>=500?"WPS OAuth service unavailable":"unexpected OAuth response"}function j(e){let t=`${e.clientId}@${e.baseUrl}`,r=An.get(t);return r||(r=new Wt(e),An.set(t,r)),r}var no,io,Wt,An,fr=we(()=>{"use strict";St();no=6e4,io=["/oauth2/token","/openapi/oauth2/token"];Wt=class{creds;token=null;inFlight=null;constructor(t){this.creds=t}async getToken(){if(this.token&&Date.now()<this.token.expiresAt-no)return this.token.accessToken;if(this.inFlight)return this.inFlight;this.inFlight=this.requestToken();try{return await this.inFlight}finally{this.inFlight=null}}invalidate(){this.token=null}async requestToken(){let t=this.creds.baseUrl.replace(/\/$/,""),r="unknown token error";for(let n of io){let o=`${t}${n}`,i;try{i=await fetch(o,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials",client_id:this.creds.clientId,client_secret:this.creds.clientSecret})})}catch(a){r=`Network error requesting token from ${o}: ${String(a)}`;continue}if(!i.ok){let a=await i.text();r=`Token request failed (${i.status}) at ${o}: ${oo(i.status)}; body=${a}`;continue}let s=await i.json();if(s.code!==void 0&&s.code!==0){r=`WPS OAuth error (code ${s.code}): ${s.msg??"unknown"}`;continue}if(!s.access_token||!s.expires_in){r=`Invalid token response from ${o}: missing access_token or expires_in`;continue}return this.token={accessToken:s.access_token,expiresAt:Date.now()+s.expires_in*1e3},this.token.accessToken}throw new se(r)}},An=new Map});import{z as x}from"zod";function Lt(e){return zt}function gr(e){let t=e?.defaultAccountId?.trim();if(t)return t;let r=e?.accounts?Object.keys(e.accounts)[0]:void 0;return r&&r.trim()?r:Ce}function yr(e){return e?e.accounts&&Object.keys(e.accounts).length>0?e.accounts:!(e.appId||e.appSecret||e.companyId||e.webhook||e.sdk||e.groups||e.dmPolicy||e.groupPolicy)?{}:!e.appId||!e.appSecret?{}:{[Ce]:{enabled:e.enabled??!0,appId:e.appId,appSecret:e.appSecret,companyId:e.companyId,baseUrl:e.baseUrl??"https://openapi.wps.cn",enableEncryption:e.enableEncryption??!0,webhook:e.webhook,sdk:e.sdk,dmPolicy:e.dmPolicy,allowFrom:e.allowFrom,groupPolicy:e.groupPolicy,groups:e.groups,instantAck:e.instantAck,robotJoinGroupMessage:e.robotJoinGroupMessage,mcp:e.mcp}}:{}}function _e(e){return!e?.appId||!e?.appSecret?null:{clientId:e.appId,clientSecret:e.appSecret,baseUrl:e.baseUrl??"https://openapi.wps.cn"}}var Rn,$n,qn,Cn,Dn,Nn,zt,mr,hr,E,be,Ce,rt=we(()=>{"use strict";Rn=x.enum(["disabled","open","allowlist","pairing"]).default("pairing"),$n=x.object({requireMention:x.boolean().optional(),toolPolicy:x.enum(["full","limited","none"]).optional()}).passthrough(),qn=x.object({enabled:x.boolean().default(!1),mode:x.literal("app").default("app"),clientId:x.string().optional(),clientSecret:x.string().optional(),baseUrl:x.string().optional(),toolAllowlist:x.array(x.string()).min(1,"mcp.toolAllowlist must contain at least one tool").default(["wps_user_search","wps_user_get","wps_message_send","wps_calendar_create","wps_calendar_list_events","wps_calendar_search_events","wps_calendar_update_event","wps_calendar_delete_event","wps_calendar_get_event","wps_calendar_list_event_attendees","wps_calendar_add_event_attendees","wps_calendar_list_event_meeting_rooms","wps_calendar_event_meeting_rooms_batch_create","wps_calendar_event_meeting_rooms_batch_delete","wps_calendar_delete_event_attendees","wps_calendar_list_calendar_event_instances","wps_calendar_list_event_instances","wps_calendar_respond_invitation","wps_todo_create_personal_task","wps_todo_list_personal_tasks","wps_todo_get_personal_task","wps_todo_update_personal_task","wps_todo_update_personal_task_status","wps_cloud_doc_list_drives","wps_cloud_doc_list_children_files","wps_cloud_doc_create_file","wps_cloud_doc_upload_file","wps_cloud_doc_extract_file_content","wps_cloud_doc_get_file_meta","wps_cloud_doc_search_files","wps_airpage_create_file","wps_airpage_create_block_content","wps_airpage_query_document_blocks","wps_airpage_batch_query_document_blocks","wps_airpage_delete_block_content","wps_airpage_batch_delete_block_content","wps_airpage_update_document_block","wps_airpage_batch_update_document_blocks","wps_meeting_rooms_list","wps_meeting_rooms_get","wps_meeting_rooms_search","wps_meeting_room_bookings_batch_get","wps_meeting_room_bookings_update_status"])}),Cn=x.object({enabled:x.boolean().default(!0),text:x.string().default("\u5185\u5BB9\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019...")}),Dn=x.object({enabled:x.boolean().default(!1),logLevel:x.enum(["debug","info","warn","error"]).default("info"),endpoint:x.string().optional(),connectTimeoutMs:x.number().min(3e3).max(12e4).default(2e4),pongTimeout:x.number().min(3e4).max(3e5).default(15e4),autoReconnect:x.boolean().default(!0),reconnectBaseInterval:x.number().min(500).max(1e4).default(1e3),reconnectMaxInterval:x.number().min(1e4).max(3e5).default(6e4),reconnectMultiplier:x.number().min(1.5).max(3).default(2),reconnectMaxRetry:x.number().min(-1).max(100).default(-1),reconnectJitter:x.number().min(0).max(.5).default(.2)}),Nn=x.object({path:x.string().default("/wps/webhook"),port:x.number().default(3e3)}),zt="https://365.kdocs.cn/woa/openclaw/callback",mr=x.object({enabled:x.boolean().default(!0),appId:x.string().describe("WPS App ID (client_id)"),appSecret:x.string().describe("WPS App Secret (client_secret)"),companyId:x.string().optional().describe("WPS Company ID"),baseUrl:x.string().default("https://openapi.wps.cn"),enableEncryption:x.boolean().default(!0),webhook:Nn.optional(),sdk:Dn.optional(),dmPolicy:Rn.optional(),allowFrom:x.array(x.string()).optional(),groupPolicy:x.enum(["open","allowlist"]).optional(),groups:x.record(x.string(),$n).optional(),instantAck:Cn.optional(),robotJoinGroupMessage:x.string().optional(),mcp:qn.optional()}),hr=mr.partial().extend({defaultAccountId:x.string().optional(),accounts:x.record(x.string(),mr).optional()});E="wps-xiezuo",be="wps-xiezuo",Ce="default"});function wr(e){xt=e}function br(e,t){nt.set(e,t),jn(e,t)}function vt(e){let t=nt.get(e);return t?Date.now()>=t.expiresAt?(nt.delete(e),Un(e),null):t.accessToken:null}function Un(e){let t=Bt.get(e);t&&(clearTimeout(t),Bt.delete(e))}function jn(e,t){if(Un(e),!t.refreshToken)return;let r=Math.max(t.expiresAt-Date.now()-so,1e4),n=setTimeout(()=>{ao(e).catch(()=>{nt.delete(e),Bt.delete(e)})},r);n.unref?.(),Bt.set(e,n)}async function ao(e){let t=nt.get(e);if(!t?.refreshToken||!xt)return;let r=xt.baseUrl.replace(/\/$/,""),n=new URLSearchParams({grant_type:"refresh_token",client_id:xt.appId,client_secret:xt.appSecret,refresh_token:t.refreshToken}),o=await fetch(`${r}/oauth2/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()}),i=await o.text(),s;try{s=JSON.parse(i)}catch{throw new se(`OAuth refresh: non-JSON response (${o.status}): ${i.slice(0,200)}`)}if(!o.ok||typeof s.code=="number"&&s.code!==0)throw new se(`OAuth refresh failed (${o.status}): ${JSON.stringify(s)}`);let a=typeof s.access_token=="string"?s.access_token:"";if(!a)throw new se(`OAuth refresh: missing access_token: ${JSON.stringify(s)}`);let d=typeof s.expires_in=="number"?s.expires_in:7200,l={accessToken:a,refreshToken:typeof s.refresh_token=="string"?s.refresh_token:t.refreshToken,expiresAt:Date.now()+d*1e3,openid:typeof s.openid=="string"?s.openid:t.openid};nt.set(e,l),jn(e,l)}async function Ir(e){let t=e.baseUrl.replace(/\/$/,""),r=new URLSearchParams({grant_type:"authorization_code",client_id:e.appId,client_secret:e.appSecret,code:e.code,redirect_uri:e.redirectUri??zt}),n=await fetch(`${t}/oauth2/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()}),o=await n.text(),i;try{i=JSON.parse(o)}catch{throw new se(`OAuth code exchange: non-JSON response (${n.status}): ${o.slice(0,200)}`)}if(!n.ok||typeof i.code=="number"&&i.code!==0)throw new se(`OAuth code exchange failed (${n.status}): ${JSON.stringify(i)}`);let s=typeof i.access_token=="string"?i.access_token:"";if(!s)throw new se(`OAuth code exchange: missing access_token in response: ${JSON.stringify(i)}`);let a=typeof i.expires_in=="number"?i.expires_in:7200;return{accessToken:s,refreshToken:typeof i.refresh_token=="string"?i.refresh_token:"",expiresAt:Date.now()+a*1e3,openid:typeof i.openid=="string"?i.openid:""}}var nt,Bt,so,xt,it=we(()=>{"use strict";St();rt();nt=new Map,Bt=new Map,so=5*6e4,xt=null});function W(e,t){return new Tt(e,new Ft(t))}function kr(e,t){return new Tt(e,new Gt(t))}var Ft,Gt,Tt,Kt=we(()=>{"use strict";St();Ft=class{tokenStore;constructor(t){this.tokenStore=t}async getHeaders(){return{Authorization:`Bearer ${await this.tokenStore.getToken()}`}}},Gt=class{accessToken;constructor(t){this.accessToken=t}async getHeaders(){return{Authorization:`Bearer ${this.accessToken}`}}},Tt=class{baseUrl;auth;constructor(t,r){this.baseUrl=t,this.auth=r}async request(t){let r=await this.auth.getHeaders(),n=this.buildUrl(t.path,t.query),o=t.method??"GET",i=await fetch(n,{method:o,headers:{"Content-Type":"application/json",...r,...t.headers??{}},body:t.body?JSON.stringify(t.body):void 0}),s=i.headers.get("X-Request-Id")??i.headers.get("x-request-id")??i.headers.get("X-Trace-Id")??i.headers.get("x-trace-id")??void 0;if(!i.ok){let a=await i.text(),d;try{let u=JSON.parse(a);d=u.code??u.result}catch{}let{hint:l,retriable:c}=_r(i.status),p=s?` request_id=${s}`:"";throw console.error(`[WPS-API-ERROR] ${i.status} ${o} ${t.path}${p} body=${a}`),new Fe(`WPS API error (${i.status} ${o} ${t.path}): ${a}`,{stage:"http",method:o,path:t.path,httpStatus:i.status,wpsCode:d,hint:l,retriable:c,requestId:s})}return this.parseResponse(i,o,t.path,s)}buildUrl(t,r){let n=new URL(t,this.baseUrl);if(r){for(let[o,i]of Object.entries(r))if(i!==void 0)if(Array.isArray(i))for(let s of i)n.searchParams.append(o,s);else n.searchParams.set(o,String(i))}return n.toString()}async parseResponse(t,r,n,o){let i=await t.text();if(!i||i.trim()==="")return{};let s;try{s=JSON.parse(i)}catch{throw new Fe(`Failed to parse JSON from ${r} ${n}: ${i.slice(0,200)}`,{stage:"parse",method:r,path:n,hint:"response is not valid JSON",retriable:!1})}let a=s.code??s.result;if(a!==void 0&&a!==0&&a!=="ok"){let d=String(a)==="40300001"?"permission denied by WPS business policy":"WPS business validation failed",l=s.request_id??o,c=l?` request_id=${String(l)}`:"";throw console.error(`[WPS-API-ERROR] biz_code=${String(a)} ${r} ${n}${c} msg=${s.msg??s.message??"unknown"}`),new Fe(`WPS business error code=${String(a)}: ${s.msg??s.message??"unknown"}`,{stage:"business",method:r,path:n,wpsCode:a,hint:d,retriable:!1,requestId:l?String(l):void 0})}return s}}});import{imageSize as co}from"image-size";function Et(e,t=0){if(!e||typeof e!="object"||t>2)return null;let r=e;for(let n of lo){let o=r[n];if(typeof o=="string"&&o.trim())return o.trim()}return r.data&&typeof r.data=="object"?Et(r.data,t+1):null}function Sr(e){let t=Et(e);if(!t)throw new Error("cannot resolve download URL from WPS API response");return t}function Ge(e){try{let t=co(Buffer.isBuffer(e)?e:Buffer.from(e));return t.width&&t.height?{width:t.width,height:t.height}:null}catch{return null}}var lo,Pt=we(()=>{"use strict";lo=["url","download_url","downloadUrl","file_url","fileUrl"]});async function vr(e,t,r){let n=j(e);await W(e.baseUrl,n).request({method:"POST",path:`/v7/chats/${encodeURIComponent(t)}/messages/${encodeURIComponent(r)}/reactions/create`,body:{reaction_type:xr}})}async function Tr(e,t,r,n){try{let o=j(e);await W(e.baseUrl,o).request({method:"POST",path:`/v7/chats/${encodeURIComponent(t)}/messages/${encodeURIComponent(r)}/reactions/delete`,body:{reaction_type:xr}})}catch(o){let i=String(o);i.includes("msgRecalled")||i.includes("message_not_found")||i.includes("404")?(n?.info??console.log)(`WPS thinking reaction cleanup skipped (message gone): ${i.substring(0,100)}`):(n?.error??console.error)(`WPS thinking reaction cleanup failed: ${i}`)}}var xr,Er=we(()=>{"use strict";fr();Kt();xr="emoji_busy"});var Ot=we(()=>{"use strict";St();fr();it();Kt();Pt();Er();rt()});var ci={};On(ci,{getDelegatedScopes:()=>qt,getLazyClient:()=>Kr,getLazyCreds:()=>Vt,getLazyLog:()=>dt,getLazyWpsCfg:()=>Hr,setDelegatedScopes:()=>Yt,setLazyClient:()=>Gr});function Gr(e,t,r,n){Lr=e,ai=t??null,Br=r??null,Fr=n??null}function Kr(){if(!Lr)throw new Error("WPS client not initialized yet (startAccount has not been called)");return Lr}function dt(){return ai}function Hr(){if(!Br)throw new Error("WPS config not set yet (startAccount has not been called)");return Br}function Vt(){if(!Fr)throw new Error("WPS credentials not set yet (startAccount has not been called)");return Fr}function Yt(e){di=e}function qt(){return di}var Lr,ai,Br,Fr,di,ct=we(()=>{"use strict";Lr=null,ai=null,Br=null,Fr=null;di=[]});var Vr={};On(Vr,{buildAuthCard:()=>_i,buildAuthSuccessCard:()=>fi,buildAuthorizeUrl:()=>ui,decodeState:()=>pi,encodeState:()=>li,handleAuthEvent:()=>Ko,sendAuthCard:()=>Xr});import{randomBytes as Bo}from"node:crypto";function li(e){let t=Bo(16).toString("hex");e.nonce=t;let r=t;return Ct.set(r,e),setTimeout(()=>Ct.delete(r),10*6e4).unref?.(),r}function pi(e){let t=Ct.get(e);return t&&Ct.delete(e),t??null}function ui(e){let t=new URL("/oauth2/auth",e.baseUrl);return t.searchParams.set("response_type","code"),t.searchParams.set("client_id",e.appId),t.searchParams.set("redirect_uri",e.redirectUri),t.searchParams.set("scope",e.scopes.join(",")),t.searchParams.set("state",e.state),t.toString()}function _i(e,t,r){let n=t.length>Zt,i=(n?t.slice(0,Zt):t).join(`
2
2
  `)+(n?`
3
3
  ... \u7B49\u5171 ${t.length} \u9879\u6743\u9650`:""),s=r?.totalScopes??t.length,a=r&&r.totalParts>1?`\uFF08\u7B2C ${r.partIndex}/${r.totalParts} \u7EC4\uFF0C\u672C\u7EC4 ${t.length} \u9879\uFF09`:"",d=r&&r.totalParts>1?`\u8BF7\u6388\u6743\u4EE5\u65B9\u4FBF\u7EE7\u7EED\u64CD\u4F5C\uFF08${r.partIndex}/${r.totalParts}\uFF09`:"\u8BF7\u6388\u6743\u4EE5\u65B9\u4FBF\u7EE7\u7EED\u64CD\u4F5C";return{card:{i18n_items:[{key:"zh-CN",value:{elements:[{text:{tag:"text",text:{content:`\u5E94\u7528\u9700\u8981\u6388\u6743 ${s} \u4E2A\u7528\u6237\u6743\u9650${a}\u3002`,text_align:"left",text_size:"small",type:"markdown"}}},{text:{tag:"text",text:{content:`**\u5C06\u8981\u6388\u6743\u7684\u6743\u9650\uFF1A**
4
4
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "wps-xiezuo",
3
3
  "name": "WPS Xiezuo",
4
- "version": "1.8.1",
4
+ "version": "1.10.0",
5
5
  "description": "WPS Xiezuo OpenClaw Plugin - connect to WPS Open Platform enterprise robot",
6
6
  "main": "dist/index.js",
7
7
  "author": "WPS Xiezuo Team",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wps365/openclaw-wpsxiezuo",
3
- "version": "1.9.1-beta.2",
3
+ "version": "1.10.0",
4
4
  "description": "WPS Xiezuo OpenClaw plugin - connect OpenClaw Agent to the WPS Open Platform enterprise robot",
5
5
  "keywords": [
6
6
  "openclaw",