@coze/cli 0.1.3-alpha.3ae441 → 0.1.3-alpha.83c02a
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.
- package/bin/main +1 -7
- package/lib/cli.js +2 -2
- package/lib/http-utils-Ci82xaGo.js +1 -0
- package/lib/index-zg3ZlYH2.js +1 -0
- package/lib/send-message.worker.js +1 -1
- package/lib/session-task-refresh.worker.js +1 -0
- package/lib/task-worker-1kO99GjJ.js +1 -0
- package/package.json +12 -7
- package/lib/index-DWNGLR7D.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("mitt"),t=require("crypto"),s=require("./http-utils-Ci82xaGo.js"),i=require("path"),r=require("fs"),n=require("form-data"),a=require("fs/promises"),o=require("lodash");var c;!function(e){e.SendMessage="sendMessage";e.ResumeMessage="resumeMessage";e.GetMessage="getMessage";e.ClearHistory="clearHistory";e.ClearMessageContext="clearMessageContext";e.DeleteMessage="deleteMessage";e.BreakMessage="breakMessage";e.ReportMessage="reportMessage";e.ChatASR="chatASR";e.ChatReconnect="chatReconnect";e.ChatRetrieve="chatRetrieve"}(c||(c={}));let _,l,h=(e=21)=>{var s;s=e-=0,!_||_.length<s?(_=Buffer.allocUnsafe(128*s),t.randomFillSync(_),l=0):l+s>_.length&&(t.randomFillSync(_),l=0),l+=s;let i="";for(let t=l-e;t<l;t++)i+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&_[t]];return i};function u(e){return e}function p(){}var d=Date.now;var g,T,E,m=s.defineProperty?function(e,t){return s.defineProperty(e,"toString",{configurable:!0,enumerable:!1,value:(i=t,function(){return i}),writable:!0});var i}:u,f=(g=m,T=0,E=0,function(){var e=d(),t=16-(e-E);if(E=e,t>0){if(++T>=800)return arguments[0]}else T=0;return g.apply(void 0,arguments)});var L=Math.max;function A(e,t){return f(function(e,t,s){return t=L(void 0===t?e.length-1:t,0),function(){for(var i=arguments,r=-1,n=L(i.length-t,0),a=Array(n);++r<n;)a[r]=i[t+r];r=-1;for(var o=Array(t+1);++r<t;)o[r]=i[r];return o[t]=s(a),function(e,t,s){switch(s.length){case 0:return e.call(t);case 1:return e.call(t,s[0]);case 2:return e.call(t,s[0],s[1]);case 3:return e.call(t,s[0],s[1],s[2])}return e.apply(t,s)}(e,this,o)}}(e,t,u),e+"")}function S(e){return A((function(t,i){var r=-1,n=i.length,a=n>1?i[n-1]:void 0,o=n>2?i[2]:void 0;for(a=e.length>3&&"function"==typeof a?(n--,a):void 0,o&&function(e,t,i){if(!s.isObject(i))return!1;var r=typeof t;return!!("number"==r?s.isArrayLike(i)&&s.isIndex(t,i.length):"string"==r&&t in i)&&s.eq(i[t],e)}(i[0],i[1],o)&&(a=n<3?void 0:a,n=1),t=Object(t);++r<n;){var c=i[r];c&&e(t,c,r,a)}return t}))}var R=Object.prototype.hasOwnProperty;function C(e){if(!s.isObject(e))return function(e){var t=[];if(null!=e)for(var s in Object(e))t.push(s);return t}(e);var t=s.isPrototype(e),i=[];for(var r in e)("constructor"!=r||!t&&R.call(e,r))&&i.push(r);return i}function v(e){return s.isArrayLike(e)?s.arrayLikeKeys(e,!0):C(e)}var I=Function.prototype,y=Object.prototype,b=I.toString,M=y.hasOwnProperty,N=b.call(Object);var U=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)s.arrayPush(t,s.getSymbols(e)),e=s.getPrototype(e);return t}:s.stubArray;function O(e){var t=-1,i=null==e?0:e.length;for(this.__data__=new s.MapCache;++t<i;)this.add(e[t])}function P(e,t){for(var s=-1,i=null==e?0:e.length;++s<i;)if(t(e[s],s,e))return!0;return!1}O.prototype.add=O.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},O.prototype.has=function(e){return this.__data__.has(e)};function B(e,t,s,i,r,n){var a=1&s,o=e.length,c=t.length;if(o!=c&&!(a&&c>o))return!1;var _=n.get(e),l=n.get(t);if(_&&l)return _==t&&l==e;var h=-1,u=!0,p=2&s?new O:void 0;for(n.set(e,t),n.set(t,e);++h<o;){var d=e[h],g=t[h];if(i)var T=a?i(g,d,h,t,e,n):i(d,g,h,e,t,n);if(void 0!==T){if(T)continue;u=!1;break}if(p){if(!P(t,(function(e,t){if(a=t,!p.has(a)&&(d===e||r(d,e,s,i,n)))return p.push(t);var a}))){u=!1;break}}else if(d!==g&&!r(d,g,s,i,n)){u=!1;break}}return n.delete(e),n.delete(t),u}function k(e){var t=-1,s=Array(e.size);return e.forEach((function(e,i){s[++t]=[i,e]})),s}function j(e){var t=-1,s=Array(e.size);return e.forEach((function(e){s[++t]=e})),s}var D=s.Symbol?s.Symbol.prototype:void 0,G=D?D.valueOf:void 0;var q=Object.prototype.hasOwnProperty;var w="[object Arguments]",F="[object Array]",x="[object Object]",W=Object.prototype.hasOwnProperty;function H(e,t,i,r,n,a){var o=s.isArray(e),c=s.isArray(t),_=o?F:s.getTag(e),l=c?F:s.getTag(t),h=(_=_==w?x:_)==x,u=(l=l==w?x:l)==x,p=_==l;if(p&&s.isBuffer(e)){if(!s.isBuffer(t))return!1;o=!0,h=!1}if(p&&!h)return a||(a=new s.Stack),o||s.isTypedArray(e)?B(e,t,i,r,n,a):function(e,t,i,r,n,a,o){switch(i){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!a(new s.Uint8Array(e),new s.Uint8Array(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return s.eq(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var c=k;case"[object Set]":var _=1&r;if(c||(c=j),e.size!=t.size&&!_)return!1;var l=o.get(e);if(l)return l==t;r|=2,o.set(e,t);var h=B(c(e),c(t),r,n,a,o);return o.delete(e),h;case"[object Symbol]":if(G)return G.call(e)==G.call(t)}return!1}(e,t,_,i,r,n,a);if(!(1&i)){var d=h&&W.call(e,"__wrapped__"),g=u&&W.call(t,"__wrapped__");if(d||g){var T=d?e.value():e,E=g?t.value():t;return a||(a=new s.Stack),n(T,E,i,r,a)}}return!!p&&(a||(a=new s.Stack),function(e,t,i,r,n,a){var o=1&i,c=s.getAllKeys(e),_=c.length;if(_!=s.getAllKeys(t).length&&!o)return!1;for(var l=_;l--;){var h=c[l];if(!(o?h in t:q.call(t,h)))return!1}var u=a.get(e),p=a.get(t);if(u&&p)return u==t&&p==e;var d=!0;a.set(e,t),a.set(t,e);for(var g=o;++l<_;){var T=e[h=c[l]],E=t[h];if(r)var m=o?r(E,T,h,t,e,a):r(T,E,h,e,t,a);if(!(void 0===m?T===E||n(T,E,i,r,a):m)){d=!1;break}g||(g="constructor"==h)}if(d&&!g){var f=e.constructor,L=t.constructor;f==L||!("constructor"in e)||!("constructor"in t)||"function"==typeof f&&f instanceof f&&"function"==typeof L&&L instanceof L||(d=!1)}return a.delete(e),a.delete(t),d}(e,t,i,r,n,a))}function K(e,t,i,r,n){return e===t||(null==e||null==t||!s.isObjectLike(e)&&!s.isObjectLike(t)?e!=e&&t!=t:H(e,t,i,r,K,n))}function V(e){return e==e&&!s.isObject(e)}function $(e,t){return function(s){return null!=s&&(s[e]===t&&(void 0!==t||e in Object(s)))}}function z(e){var t=function(e){for(var t=s.keys(e),i=t.length;i--;){var r=t[i],n=e[r];t[i]=[r,n,V(n)]}return t}(e);return 1==t.length&&t[0][2]?$(t[0][0],t[0][1]):function(i){return i===e||function(e,t,i,r){var n=i.length,a=n;if(null==e)return!a;for(e=Object(e);n--;){var o=i[n];if(o[2]?o[1]!==e[o[0]]:!(o[0]in e))return!1}for(;++n<a;){var c=(o=i[n])[0],_=e[c],l=o[1];if(o[2]){if(void 0===_&&!(c in e))return!1}else if(!K(l,_,3,r,new s.Stack))return!1}return!0}(i,0,t)}}function Q(e,t){return null!=e&&t in Object(e)}function J(e,t){return null!=e&&function(e,t,i){for(var r=-1,n=(t=s.castPath(t,e)).length,a=!1;++r<n;){var o=s.toKey(t[r]);if(!(a=null!=e&&i(e,o)))break;e=e[o]}return a||++r!=n?a:!!(n=null==e?0:e.length)&&s.isLength(n)&&s.isIndex(o,n)&&(s.isArray(e)||s.isArguments(e))}(e,t,Q)}function Y(e){return s.isKey(e)?(t=s.toKey(e),function(e){return null==e?void 0:e[t]}):function(e){return function(t){return s.baseGet(t,e)}}(e);var t}function Z(e){return"function"==typeof e?e:null==e?u:"object"==typeof e?s.isArray(e)?function(e,t){return s.isKey(e)&&V(t)?$(s.toKey(e),t):function(i){var r=s.get(i,e);return void 0===r&&r===t?J(i,e):K(t,r,3)}}(e[0],e[1]):z(e):Y(e)}var X=function(e,t,s){for(var i=-1,r=Object(e),n=s(e),a=n.length;a--;){var o=n[++i];if(!1===t(r[o],o,r))break}return e};function ee(e,t,i){(void 0!==i&&!s.eq(e[t],i)||void 0===i&&!(t in e))&&s.baseAssignValue(e,t,i)}function te(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}function se(e){return function(e,t,i){var r=!i;i||(i={});for(var n=-1,a=t.length;++n<a;){var o=t[n],c=void 0;void 0===c&&(c=e[o]),r?s.baseAssignValue(i,o,c):s.assignValue(i,o,c)}return i}(e,v(e))}function ie(e,t,i,r,n,a,o){var c=te(e,i),_=te(t,i),l=o.get(_);if(l)ee(e,i,l);else{var h,u=a?a(c,_,i+"",e,t,o):void 0,p=void 0===u;if(p){var d=s.isArray(_),g=!d&&s.isBuffer(_),T=!d&&!g&&s.isTypedArray(_);u=_,d||g||T?s.isArray(c)?u=c:(h=c,s.isObjectLike(h)&&s.isArrayLike(h)?u=function(e,t){var s=-1,i=e.length;for(t||(t=Array(i));++s<i;)t[s]=e[s];return t}(c):g?(p=!1,u=s.cloneBuffer(_,!0)):T?(p=!1,u=s.cloneTypedArray(_,!0)):u=[]):function(e){if(!s.isObjectLike(e)||"[object Object]"!=s.baseGetTag(e))return!1;var t=s.getPrototype(e);if(null===t)return!0;var i=M.call(t,"constructor")&&t.constructor;return"function"==typeof i&&i instanceof i&&b.call(i)==N}(_)||s.isArguments(_)?(u=c,s.isArguments(c)?u=se(c):s.isObject(c)&&!s.isFunction(c)||(u=s.initCloneObject(_))):p=!1}p&&(o.set(_,u),n(u,_,r,a,o),o.delete(_)),ee(e,i,u)}}function re(e,t,i,r,n){e!==t&&X(t,(function(a,o){if(n||(n=new s.Stack),s.isObject(a))ie(e,t,o,i,re,r,n);else{var c=r?r(te(e,o),a,o+"",e,t,n):void 0;void 0===c&&(c=a),ee(e,o,c)}}),v)}var ne=S((function(e,t,s,i){re(e,t,s,i)}));function ae(e){return void 0===e}var oe=S((function(e,t,s){re(e,t,s)}));function ce(e,t){if(null==e)return{};var i=s.arrayMap(function(e){return s.baseGetAllKeys(e,v,U)}(e),(function(e){return[e]}));return t=Z(t),function(e,t,i){for(var r=-1,n=t.length,a={};++r<n;){var o=t[r],c=s.baseGet(e,o);i(c,o)&&s.baseSet(a,s.castPath(o,e),c)}return a}(e,i,(function(e,s){return t(e,s[0])}))}function _e(e,t,i){return null==e?e:function(e,t,i){return s.baseSet(e,t,i(s.baseGet(e,t)))}(e,t,"function"==typeof(r=i)?r:u);var r}class le{createQueryMessage(e,t){return{content:e,session_id:t.session_id,type:"query",project_id:t.project_id,conversation_id:t.conversation_id,context:t.context,local_msg_id:h()}}createRetryMessage(e,t){return{content:e,session_id:t.session_id,type:"retry",project_id:t.project_id,conversation_id:t.conversation_id,context:t.context,local_msg_id:h()}}createEditMessage(e,t){const s=h();return{content:oe(e,{edit:{local_msg_id:s}}),session_id:t.session_id,type:"edit",project_id:t.project_id,conversation_id:t.conversation_id,context:t.context,local_msg_id:s}}createInputMessage(e,t){return{content:e,session_id:t.session_id,type:"input",project_id:t.project_id,conversation_id:t.conversation_id,context:t.context,local_msg_id:h()}}createCancelMessage(e,t){return{content:e,session_id:t.session_id,type:"cancel",project_id:t.project_id,conversation_id:t.conversation_id,context:t.context,local_msg_id:h()}}}const he=(...e)=>ne(...e,((e,t)=>{if(s.isArray(e))return e.concat(t)}));var ue,pe,de,ge,Te,Ee,me,fe,Le,Ae,Se,Re,Ce,ve,Ie,ye,be,Me,Ne;function Ue(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}!function(e){e[e.OpenClawChannelTypeLark=1]="OpenClawChannelTypeLark";e[e.OpenClawChannelTypeWeixin=2]="OpenClawChannelTypeWeixin";e[e.OpenClawChannelTypeWeCom=3]="OpenClawChannelTypeWeCom"}(ue||(ue={})),function(e){e[e.OpenClawLarkAuthStatusAuthorized=1]="OpenClawLarkAuthStatusAuthorized";e[e.OpenClawLarkAuthStatusUnauthorized=2]="OpenClawLarkAuthStatusUnauthorized"}(pe||(pe={})),function(e){e[e.OpenClawLarkConfigStatusNotCreated=1]="OpenClawLarkConfigStatusNotCreated";e[e.OpenClawLarkConfigStatusCreated=2]="OpenClawLarkConfigStatusCreated";e[e.OpenClawLarkConfigStatusConfigured=3]="OpenClawLarkConfigStatusConfigured"}(de||(de={})),function(e){e[e.OpenClawUpdateStatusNoUpdate=1]="OpenClawUpdateStatusNoUpdate";e[e.OpenClawUpdateStatusPending=2]="OpenClawUpdateStatusPending";e[e.OpenClawUpdateStatusUpdating=3]="OpenClawUpdateStatusUpdating"}(ge||(ge={})),function(e){e[e.OpenClawVersionTypeFull=1]="OpenClawVersionTypeFull";e[e.OpenClawVersionTypeLite=2]="OpenClawVersionTypeLite"}(Te||(Te={})),function(e){e[e.RequirementsNotMet=1]="RequirementsNotMet";e[e.FunctionDefect=2]="FunctionDefect";e[e.PoorDesign=3]="PoorDesign";e[e.InteractionIssue=4]="InteractionIssue";e[e.LongTimeWait=5]="LongTimeWait";e[e.RequirementsMisunderstood=6]="RequirementsMisunderstood";e[e.BadPlanning=7]="BadPlanning";e[e.ExecutionFailed=8]="ExecutionFailed";e[e.UnstableExecution=9]="UnstableExecution"}(Ee||(Ee={})),function(e){e[e.Unknown=0]="Unknown";e[e.Like=1]="Like";e[e.Dislike=2]="Dislike"}(me||(me={})),function(e){e[e.Wait=0]="Wait";e[e.Done=1]="Done"}(fe||(fe={})),function(e){e[e.RoleTypeUnknown=0]="RoleTypeUnknown";e[e.RoleTypeUser=1]="RoleTypeUser";e[e.RoleTypeAssistant=2]="RoleTypeAssistant"}(Le||(Le={})),function(e){e[e.Agent=0]="Agent";e[e.Ask=1]="Ask";e[e.DangerousConfirm=2]="DangerousConfirm";e[e.Plan=4]="Plan"}(Ae||(Ae={})),function(e){e[e.Idle=0]="Idle";e[e.Running=1]="Running";e[e.Interrupted=2]="Interrupted"}(Se||(Se={})),function(e){e[e.AddAttributes=1]="AddAttributes";e[e.RemoveAttributes=2]="RemoveAttributes"}(Re||(Re={})),function(e){e[e.CloseConnection=1]="CloseConnection"}(Ce||(Ce={})),function(e){e[e.ON_LINE=0]="ON_LINE";e[e.OFF_LINE=1]="OFF_LINE";e[e.TOUCH=2]="TOUCH"}(ve||(ve={})),function(e){e[e.AddGroups=1]="AddGroups";e[e.RemoveGroups=2]="RemoveGroups";e[e.ReplaceWithGroups=3]="ReplaceWithGroups"}(Ie||(Ie={})),function(e){e[e.App=0]="App";e[e.Service=1]="Service";e[e.Method=2]="Method"}(ye||(ye={})),function(e){e[e.ApiKey=1]="ApiKey";e[e.WechatOfficialAccount=2]="WechatOfficialAccount";e[e.OAuth=3]="OAuth"}(be||(be={})),function(e){e[e.PROJECT_COPY=1]="PROJECT_COPY";e[e.SKILL_STORE=2]="SKILL_STORE"}(Me||(Me={})),function(e){e[e.PENDING=1]="PENDING";e[e.SUCCESS=2]="SUCCESS";e[e.FAILED=3]="FAILED"}(Ne||(Ne={}));class Oe{__init(){this.request=s.request}__init2(){this.baseURL=""}constructor(e){Oe.prototype.__init.call(this),Oe.prototype.__init2.call(this),this.request=Ue([e,"optionalAccess",e=>e.request])||this.request,this.baseURL=Ue([e,"optionalAccess",e=>e.baseURL])||this.baseURL}genBaseURL(e){return"string"==typeof this.baseURL?this.baseURL+e:this.baseURL(e)}GetHistory(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/chat/history`),r={before:s.before,limit:s.limit,after:s.after,conversation_id:s.conversation_id};return this.request({url:i,method:"GET",params:r},t)}ReplyFeedback(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/chat/feedback`),r={reply_id:s.reply_id,type:s.type,session_id:s.session_id,feedback_detail:s.feedback_detail};return this.request({url:i,method:"POST",data:r},t)}TestChat(e,t){const s=e,i=this.genBaseURL("/v1/api/project/:project_id/chat/mock"),r={msg:s.msg};return this.request({url:i,method:"POST",data:r},t)}GetCanvasInfo(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/agent/canvas`),r={space_id:s.space_id,commit_id:s.commit_id};return this.request({url:i,method:"POST",data:r},t)}ExplainNode(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/agent/explain_node`),r={node_ids:s.node_ids,schema:s.schema};return this.request({url:i,method:"POST",data:r},t)}GetInOutSchema(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/agent/inout_schema`),r={space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}GetSkillMeta(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/skill/meta`);return this.request({url:i,method:"POST"},t)}ListSpans(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/list_spans`),r={workspace_id:s.workspace_id,start_time:s.start_time,end_time:s.end_time,filters:s.filters,page_size:s.page_size,order_bys:s.order_bys,page_token:s.page_token,platform_type:s.platform_type,span_list_type:s.span_list_type};return this.request({url:i,method:"POST",data:r},t)}GetModelList(e,t){const s=e||{},i=this.genBaseURL("/v1/api/project/model_list"),r={project_id:s.project_id,project_type:s.project_type,space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}GetCommercialInfo(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/chat/commercial_info`),r={reply_id_list:s.reply_id_list};return this.request({url:i,method:"POST",data:r},t)}PackSkill(e,t){const s=e,i=this.genBaseURL("/v1/api/project/:project_id/skill/pack"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}GetSkillOAuthUrl(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/skill/oauth_url`),r={checkpoint_id:s.checkpoint_id,credential_name:s.credential_name,platform_oauth_info:s.platform_oauth_info,custom_oauth_info:s.custom_oauth_info,credential_tips:s.credential_tips};return this.request({url:i,method:"POST",data:r},t)}GetTools(e,t){const s=this.genBaseURL("/v1/api/project/tools");return this.request({url:s,method:"GET"},t)}CanvasSubmit(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/agent/canvas_submit`),r={after_canvas:s.after_canvas};return this.request({url:i,method:"POST",data:r},t)}UpdateOpenClawSettings(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/update_setting`),r={selected_model_id:s.selected_model_id,version:s.version,channels:s.channels};return this.request({url:i,method:"POST",data:r},t)}CreateOpenClawLarkApp(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/create_lark_app`),r={app_name:s.app_name,recreate:s.recreate};return this.request({url:i,method:"POST",data:r},t)}GetOpenClawSettings(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/settings`);return this.request({url:i,method:"GET"},t)}CancelChatCLIMessage(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/chat/message/cancel`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}GetChatCLIMessageStatus(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/chat/message/status`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"GET",params:r},t)}ChatCLISendMessage(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/chat/message/send`),r={message:s.message,device_id:s.device_id};return this.request({url:i,method:"POST",data:r},t)}GetChatCLIMessageResultContent(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/chat/message/result`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"GET",params:r},t)}CreateOpenClawWeixinQRCode(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/create_weixin_qrcode`);return this.request({url:i,method:"POST"},t)}GetOpenClawUpdateStatus(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/update_status`);return this.request({url:i,method:"GET"},t)}TriggerOpenClawUpdate(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/trigger_update`);return this.request({url:i,method:"POST"},t)}ConnectOpenClawFeishu(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/connect_feishu`),r={app_name:s.app_name,recreate:s.recreate,avatar_url:s.avatar_url};return this.request({url:i,method:"POST",data:r},t)}ConnectOpenClawWeChat(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/connect_wechat`);return this.request({url:i,method:"POST"},t)}GetProjectQueue(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"GET",params:r},t)}ReorderProjectQueue(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue/reorder`),r={ordered_message_ids:s.ordered_message_ids,conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}EnqueueMessage(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue/enqueue`),r={message:s.message,device_id:s.device_id,conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}PauseProjectQueue(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue/pause`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}EditQueueMessage(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue/edit`),r={message_id:s.message_id,message:s.message,conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}ResumeProjectQueue(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue/resume`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}DeleteQueueMessage(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue/delete`),r={message_id:s.message_id,conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}ClearProjectQueue(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue/clear`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:r},t)}GetConversation(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/conversation/${s.conversation_id}`);return this.request({url:i,method:"GET"},t)}CreateConversation(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/conversation/create`),r={title:s.title,new_worktree:s.new_worktree,source_conversation_id:s.source_conversation_id,source_message_id:s.source_message_id};return this.request({url:i,method:"POST",data:r},t)}UpdateConversationSetting(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/conversation/${s.conversation_id}/update_setting`),r={model_setting:s.model_setting,skill_setting:s.skill_setting,mode:s.mode,wizards:s.wizards,agent_tools:s.agent_tools};return this.request({url:i,method:"POST",data:r},t)}DeleteConversation(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/conversation/${s.conversation_id}/delete`);return this.request({url:i,method:"POST"},t)}UpdateConversation(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/conversation/${s.conversation_id}/update`),r={title:s.title,is_pinned:s.is_pinned,ack_sequence_id:s.ack_sequence_id};return this.request({url:i,method:"POST",data:r},t)}ListConversations(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/conversation/list`),r={before:s.before,after:s.after,limit:s.limit};return this.request({url:i,method:"GET",params:r},t)}ConnectOpenClawWeCom(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/assistant/openclaw/connect_wecom`),r={bot_id:s.bot_id,secret:s.secret};return this.request({url:i,method:"POST",data:r},t)}ExtractStyle(e,t){const s=e,i=this.genBaseURL("/v1/api/project/style/extract"),r={url:s.url};return this.request({url:i,method:"POST",data:r},t)}BatchGetStyleDetail(e,t){const s=e,i=this.genBaseURL("/v1/api/project/style/detail"),r={style_ids:s.style_ids};return this.request({url:i,method:"POST",data:r},t)}ListRecommendStyles(e,t){const s=this.genBaseURL("/v1/api/project/style/list");return this.request({url:s,method:"GET"},t)}GetFrontierConnectionParams(e,t){const s=e||{},i=this.genBaseURL("/v1/api/project/frontier/connection-params"),r={device_id:s.device_id},n={Host:s.Host};return this.request({url:i,method:"GET",params:r,headers:n},t)}GetProjectDefaultConversation(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/conversation/default`);return this.request({url:i,method:"GET"},t)}}Oe.prototype.GetProjectQueue=function(e,t){const s=e,i=this.genBaseURL(`/v1/api/project/${s.project_id}/queue`),r={conversation_id:s.conversation_id};return this.request({url:i,method:"GET",params:r},t)};const Pe=new Oe({});class Be{constructor({options:e,reportLog:t}){this.mergedBaseOptions=he({scenes:{[c.GetMessage]:async(...e)=>await Pe.GetHistory(...e)}},e),this.reportLog=t,this.reportLogWithScope=this.reportLog.createLoggerWith({scope:"RequestManager"}),this.reportLogWithScope.info({message:"RequestManager is initialized",meta:{...this.mergedBaseOptions}})}appendRequestOptions(e){this.mergedBaseOptions=he(this.mergedBaseOptions,e)}getSceneConfig(e){const{scenes:t}=this.mergedBaseOptions;return t[e]}}class ke{constructor(){ke.prototype.__init.call(this)}__init(){this.preSendLocalMessageEvents=e()}on(e,t){this.preSendLocalMessageEvents.on(e,t)}off(e,t){this.preSendLocalMessageEvents.off(e,t)}once(e,t){const s=i=>{t(i),this.preSendLocalMessageEvents.off(e,s)};this.preSendLocalMessageEvents.on(e,s)}emit(e,t){this.preSendLocalMessageEvents.emit(e,t)}destroy(){this.preSendLocalMessageEvents.all.clear()}}class je{getSendChatMessageStructure(e,t){const s=oe(e,function(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}([t,"optionalAccess",e=>e.extendFields]));return ce(s,(e=>null!=e&&""!==e))}}function De(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}const Ge=["console","file","text"],qe="generate_image";function we(e,t){return null!=e?e:t()}function Fe(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}const xe=(e,t)=>{const i=t.at(0);if(!i)return e;if("message_start"===i.type||"message_end"===i.type)return s.cloneDeep(i);const r=e?s.cloneDeep(e):s.cloneDeep(i),n=e?t:t.slice(1);if(0===n.length)return r;const a=n.filter((e=>e.type===r.type));if("answer"===r.type){const e=a.map((e=>we(e.content.answer,(()=>""))));r.content.answer=we(r.content.answer,(()=>""))+e.join("")}else if("thinking"===r.type){const e=a.map((e=>we(e.content.thinking,(()=>""))));r.content.thinking=we(r.content.thinking,(()=>""))+e.join("")}else if("tool_request"===r.type&&r.content.tool_request){const e=a.map((e=>we(Fe([e,"access",e=>e.content,"access",e=>e.tool_request,"optionalAccess",e=>e.stream_parameters]),(()=>""))));r.content.tool_request.stream_parameters=we(r.content.tool_request.stream_parameters,(()=>""))+e.join("")}else if("tool_process"===r.type){const e=a.map((e=>Fe([e,"access",e=>e.content,"access",e=>e.tool_process,"optionalAccess",e=>e.data,"access",e=>e.content]))),t=function(e,t){const s={};let i=!1;const r=t.map((e=>De([e,"optionalAccess",e=>e[qe],"optionalAccess",e=>e.images])||[])).flat();return(r.length>0||!ae(De([e,"optionalAccess",e=>e[qe]])))&&(s[qe]={images:(De([e,"optionalAccess",e=>e[qe],"optionalAccess",e=>e.images])||[]).concat(r)},i=!0),Ge.forEach((r=>{const n=t.filter((e=>!ae(De([e,"optionalAccess",e=>e[r]])))).map((e=>De([e,"optionalAccess",e=>e[r]])||""));(n.length>0||!ae(De([e,"optionalAccess",e=>e[r]])))&&(s[r]=(De([e,"optionalAccess",e=>e[r]])||"")+n.join(""),i=!0)})),i?s:e||{}}(Fe([r,"access",e=>e.content,"access",e=>e.tool_process,"optionalAccess",e=>e.data,"access",e=>e.content]),e);r.content.tool_process&&(r.content.tool_process.data.content=t)}const o=t.at(-1);return o&&(r.sequence_id=o.sequence_id,r.finish=o.finish),r};function We(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}class He{__init(){this.streamBufferSnapshot=null}constructor(e){He.prototype.__init.call(this),He.prototype.__init2.call(this),He.prototype.__init3.call(this),this.key=e.key}__init2(){this.getBufferMeta=e=>{return{query_msg_id:(t=We([e,"access",e=>e.at,"call",e=>e(0),"optionalAccess",e=>e.query_msg_id]),s=()=>"",null!=t?t:s()),timestamp:Date.now(),key:this.key};var t,s}}__init3(){this.recordStreamBuffer=e=>{const{streamMessageBuffer:t,streamChunkBuffer:s}=e;this.streamBufferSnapshot={streamMessageBuffer:[...t],streamChunkBuffer:[...s],...this.getBufferMeta(t)}}}getStreamBufferSnapshot(){return this.streamBufferSnapshot}clear(){this.streamBufferSnapshot=null}}class Ke{__init(){this.timeoutMs=3e4}__init2(){this.debugLogTimer=null}__init3(){this.debugTimeoutTimer=null}__init4(){this.currentQueryMsgId=""}__init5(){this.logInterval=3e3}get isDebugging(){return null!==this.debugLogTimer||null!==this.debugTimeoutTimer}constructor(e){Ke.prototype.__init.call(this),Ke.prototype.__init2.call(this),Ke.prototype.__init3.call(this),Ke.prototype.__init4.call(this),Ke.prototype.__init5.call(this),this.reportLogWithScope=e.reportLogWithScope,this.getEnableDebug=e.getEnableDebug,this.getLogPayload=e.getLogPayload,this.mark=e.mark}startDebugLog(e){this.getEnableDebug()&&this.currentQueryMsgId!==e&&(this.clearAllTimers(),this.currentQueryMsgId=e,this.debugLogTimer=setInterval((()=>{this.clearTimeoutTimer(),this.reportLogWithScope.info({message:`${this.mark} Debug - Pulling`,meta:{query_msg_id:this.currentQueryMsgId,payload:this.getLogPayload()}}),this.startTimeout(e)}),this.logInterval))}stopDebugLog(){this.getEnableDebug()&&(this.debugLogTimer||this.debugTimeoutTimer)&&(this.clearAllTimers(),this.reportLogWithScope.info({message:`${this.mark} Debug - Final`,meta:{query_msg_id:this.currentQueryMsgId,payload:this.getLogPayload()}}))}destroy(){this.clearAllTimers(),this.currentQueryMsgId=""}clearAllTimers(){this.debugLogTimer&&(clearInterval(this.debugLogTimer),this.debugLogTimer=null),this.clearTimeoutTimer()}startTimeout(e){this.debugTimeoutTimer=setTimeout((()=>{this.reportLogWithScope.info({message:`${this.mark} Debug - Timeout兜底触发`,meta:{query_msg_id:e,payload:this.getLogPayload(),timeoutMs:this.timeoutMs}}),this.clearAllTimers(),this.currentQueryMsgId=""}),this.timeoutMs)}clearTimeoutTimer(){this.debugTimeoutTimer&&(clearTimeout(this.debugTimeoutTimer),this.debugTimeoutTimer=null)}}var Ve;!function(e){e[e.BACKSPACE=8]="BACKSPACE",e[e.FORM_FEED=12]="FORM_FEED",e[e.NEWLINE=10]="NEWLINE",e[e.CARRIAGE_RETURN=13]="CARRIAGE_RETURN",e[e.TAB=9]="TAB",e[e.SPACE=32]="SPACE",e[e.EXCLAMATION_MARK=33]="EXCLAMATION_MARK",e[e.QUOTATION_MARK=34]="QUOTATION_MARK",e[e.NUMBER_SIGN=35]="NUMBER_SIGN",e[e.DOLLAR_SIGN=36]="DOLLAR_SIGN",e[e.PERCENT_SIGN=37]="PERCENT_SIGN",e[e.AMPERSAND=38]="AMPERSAND",e[e.APOSTROPHE=39]="APOSTROPHE",e[e.LEFT_PARENTHESIS=40]="LEFT_PARENTHESIS",e[e.RIGHT_PARENTHESIS=41]="RIGHT_PARENTHESIS",e[e.ASTERISK=42]="ASTERISK",e[e.PLUS_SIGN=43]="PLUS_SIGN",e[e.COMMA=44]="COMMA",e[e.HYPHEN_MINUS=45]="HYPHEN_MINUS",e[e.FULL_STOP=46]="FULL_STOP",e[e.SOLIDUS=47]="SOLIDUS",e[e.DIGIT_ZERO=48]="DIGIT_ZERO",e[e.DIGIT_ONE=49]="DIGIT_ONE",e[e.DIGIT_TWO=50]="DIGIT_TWO",e[e.DIGIT_THREE=51]="DIGIT_THREE",e[e.DIGIT_FOUR=52]="DIGIT_FOUR",e[e.DIGIT_FIVE=53]="DIGIT_FIVE",e[e.DIGIT_SIX=54]="DIGIT_SIX",e[e.DIGIT_SEVEN=55]="DIGIT_SEVEN",e[e.DIGIT_EIGHT=56]="DIGIT_EIGHT",e[e.DIGIT_NINE=57]="DIGIT_NINE",e[e.COLON=58]="COLON",e[e.SEMICOLON=59]="SEMICOLON",e[e.LESS_THAN_SIGN=60]="LESS_THAN_SIGN",e[e.EQUALS_SIGN=61]="EQUALS_SIGN",e[e.GREATER_THAN_SIGN=62]="GREATER_THAN_SIGN",e[e.QUESTION_MARK=63]="QUESTION_MARK",e[e.COMMERCIAL_AT=64]="COMMERCIAL_AT",e[e.LATIN_CAPITAL_LETTER_A=65]="LATIN_CAPITAL_LETTER_A",e[e.LATIN_CAPITAL_LETTER_B=66]="LATIN_CAPITAL_LETTER_B",e[e.LATIN_CAPITAL_LETTER_C=67]="LATIN_CAPITAL_LETTER_C",e[e.LATIN_CAPITAL_LETTER_D=68]="LATIN_CAPITAL_LETTER_D",e[e.LATIN_CAPITAL_LETTER_E=69]="LATIN_CAPITAL_LETTER_E",e[e.LATIN_CAPITAL_LETTER_F=70]="LATIN_CAPITAL_LETTER_F",e[e.LATIN_CAPITAL_LETTER_G=71]="LATIN_CAPITAL_LETTER_G",e[e.LATIN_CAPITAL_LETTER_H=72]="LATIN_CAPITAL_LETTER_H",e[e.LATIN_CAPITAL_LETTER_I=73]="LATIN_CAPITAL_LETTER_I",e[e.LATIN_CAPITAL_LETTER_J=74]="LATIN_CAPITAL_LETTER_J",e[e.LATIN_CAPITAL_LETTER_K=75]="LATIN_CAPITAL_LETTER_K",e[e.LATIN_CAPITAL_LETTER_L=76]="LATIN_CAPITAL_LETTER_L",e[e.LATIN_CAPITAL_LETTER_M=77]="LATIN_CAPITAL_LETTER_M",e[e.LATIN_CAPITAL_LETTER_N=78]="LATIN_CAPITAL_LETTER_N",e[e.LATIN_CAPITAL_LETTER_O=79]="LATIN_CAPITAL_LETTER_O",e[e.LATIN_CAPITAL_LETTER_P=80]="LATIN_CAPITAL_LETTER_P",e[e.LATIN_CAPITAL_LETTER_Q=81]="LATIN_CAPITAL_LETTER_Q",e[e.LATIN_CAPITAL_LETTER_R=82]="LATIN_CAPITAL_LETTER_R",e[e.LATIN_CAPITAL_LETTER_S=83]="LATIN_CAPITAL_LETTER_S",e[e.LATIN_CAPITAL_LETTER_T=84]="LATIN_CAPITAL_LETTER_T",e[e.LATIN_CAPITAL_LETTER_U=85]="LATIN_CAPITAL_LETTER_U",e[e.LATIN_CAPITAL_LETTER_V=86]="LATIN_CAPITAL_LETTER_V",e[e.LATIN_CAPITAL_LETTER_W=87]="LATIN_CAPITAL_LETTER_W",e[e.LATIN_CAPITAL_LETTER_X=88]="LATIN_CAPITAL_LETTER_X",e[e.LATIN_CAPITAL_LETTER_Y=89]="LATIN_CAPITAL_LETTER_Y",e[e.LATIN_CAPITAL_LETTER_Z=90]="LATIN_CAPITAL_LETTER_Z",e[e.LEFT_SQUARE_BRACKET=91]="LEFT_SQUARE_BRACKET",e[e.REVERSE_SOLIDUS=92]="REVERSE_SOLIDUS",e[e.RIGHT_SQUARE_BRACKET=93]="RIGHT_SQUARE_BRACKET",e[e.CIRCUMFLEX_ACCENT=94]="CIRCUMFLEX_ACCENT",e[e.LOW_LINE=95]="LOW_LINE",e[e.GRAVE_ACCENT=96]="GRAVE_ACCENT",e[e.LATIN_SMALL_LETTER_A=97]="LATIN_SMALL_LETTER_A",e[e.LATIN_SMALL_LETTER_B=98]="LATIN_SMALL_LETTER_B",e[e.LATIN_SMALL_LETTER_C=99]="LATIN_SMALL_LETTER_C",e[e.LATIN_SMALL_LETTER_D=100]="LATIN_SMALL_LETTER_D",e[e.LATIN_SMALL_LETTER_E=101]="LATIN_SMALL_LETTER_E",e[e.LATIN_SMALL_LETTER_F=102]="LATIN_SMALL_LETTER_F",e[e.LATIN_SMALL_LETTER_G=103]="LATIN_SMALL_LETTER_G",e[e.LATIN_SMALL_LETTER_H=104]="LATIN_SMALL_LETTER_H",e[e.LATIN_SMALL_LETTER_I=105]="LATIN_SMALL_LETTER_I",e[e.LATIN_SMALL_LETTER_J=106]="LATIN_SMALL_LETTER_J",e[e.LATIN_SMALL_LETTER_K=107]="LATIN_SMALL_LETTER_K",e[e.LATIN_SMALL_LETTER_L=108]="LATIN_SMALL_LETTER_L",e[e.LATIN_SMALL_LETTER_M=109]="LATIN_SMALL_LETTER_M",e[e.LATIN_SMALL_LETTER_N=110]="LATIN_SMALL_LETTER_N",e[e.LATIN_SMALL_LETTER_O=111]="LATIN_SMALL_LETTER_O",e[e.LATIN_SMALL_LETTER_P=112]="LATIN_SMALL_LETTER_P",e[e.LATIN_SMALL_LETTER_Q=113]="LATIN_SMALL_LETTER_Q",e[e.LATIN_SMALL_LETTER_R=114]="LATIN_SMALL_LETTER_R",e[e.LATIN_SMALL_LETTER_S=115]="LATIN_SMALL_LETTER_S",e[e.LATIN_SMALL_LETTER_T=116]="LATIN_SMALL_LETTER_T",e[e.LATIN_SMALL_LETTER_U=117]="LATIN_SMALL_LETTER_U",e[e.LATIN_SMALL_LETTER_V=118]="LATIN_SMALL_LETTER_V",e[e.LATIN_SMALL_LETTER_W=119]="LATIN_SMALL_LETTER_W",e[e.LATIN_SMALL_LETTER_X=120]="LATIN_SMALL_LETTER_X",e[e.LATIN_SMALL_LETTER_Y=121]="LATIN_SMALL_LETTER_Y",e[e.LATIN_SMALL_LETTER_Z=122]="LATIN_SMALL_LETTER_Z",e[e.LEFT_CURLY_BRACKET=123]="LEFT_CURLY_BRACKET",e[e.VERTICAL_LINE=124]="VERTICAL_LINE",e[e.RIGHT_CURLY_BRACKET=125]="RIGHT_CURLY_BRACKET",e[e.TILDE=126]="TILDE"}(Ve||(Ve={}));const $e={[Ve.QUOTATION_MARK]:Ve.QUOTATION_MARK,[Ve.REVERSE_SOLIDUS]:Ve.REVERSE_SOLIDUS,[Ve.SOLIDUS]:Ve.SOLIDUS,[Ve.LATIN_SMALL_LETTER_B]:Ve.BACKSPACE,[Ve.LATIN_SMALL_LETTER_F]:Ve.FORM_FEED,[Ve.LATIN_SMALL_LETTER_N]:Ve.NEWLINE,[Ve.LATIN_SMALL_LETTER_R]:Ve.CARRIAGE_RETURN,[Ve.LATIN_SMALL_LETTER_T]:Ve.TAB};class ze{constructor(){this.decoder=new TextDecoder("utf-8"),this.strings=[],this.byteLength=0}appendChar(e){this.strings.push(String.fromCharCode(e)),this.byteLength+=1}appendBuf(e,t=0,s=e.length){this.strings.push(this.decoder.decode(e.subarray(t,s))),this.byteLength+=s-t}reset(){this.strings=[],this.byteLength=0}toString(){return this.strings.join("")}}class Qe{constructor(e){this.decoder=new TextDecoder("utf-8"),this.bufferOffset=0,this.string="",this.byteLength=0,this.buffer=new Uint8Array(e)}appendChar(e){this.bufferOffset>=this.buffer.length&&this.flushStringBuffer(),this.buffer[this.bufferOffset++]=e,this.byteLength+=1}appendBuf(e,t=0,s=e.length){const i=s-t;this.bufferOffset+i>this.buffer.length&&this.flushStringBuffer(),this.buffer.set(e.subarray(t,s),this.bufferOffset),this.bufferOffset+=i,this.byteLength+=i}flushStringBuffer(){this.string+=this.decoder.decode(this.buffer.subarray(0,this.bufferOffset)),this.bufferOffset=0}reset(){this.string="",this.bufferOffset=0,this.byteLength=0}toString(){return this.flushStringBuffer(),this.string}}var Je,Ye;function Ze(e){return["START","ENDED","ERROR","TRUE1","TRUE2","TRUE3","FALSE1","FALSE2","FALSE3","FALSE4","NULL1","NULL2","NULL3","STRING_DEFAULT","STRING_AFTER_BACKSLASH","STRING_UNICODE_DIGIT_1","STRING_UNICODE_DIGIT_2","STRING_UNICODE_DIGIT_3","STRING_UNICODE_DIGIT_4","STRING_INCOMPLETE_CHAR","NUMBER_AFTER_INITIAL_MINUS","NUMBER_AFTER_INITIAL_ZERO","NUMBER_AFTER_INITIAL_NON_ZERO","NUMBER_AFTER_FULL_STOP","NUMBER_AFTER_DECIMAL","NUMBER_AFTER_E","NUMBER_AFTER_E_AND_SIGN","NUMBER_AFTER_E_AND_DIGIT","SEPARATOR","BOM_OR_START","BOM"][e]}!function(e){e[e.LEFT_BRACE=0]="LEFT_BRACE",e[e.RIGHT_BRACE=1]="RIGHT_BRACE",e[e.LEFT_BRACKET=2]="LEFT_BRACKET",e[e.RIGHT_BRACKET=3]="RIGHT_BRACKET",e[e.COLON=4]="COLON",e[e.COMMA=5]="COMMA",e[e.TRUE=6]="TRUE",e[e.FALSE=7]="FALSE",e[e.NULL=8]="NULL",e[e.STRING=9]="STRING",e[e.NUMBER=10]="NUMBER",e[e.SEPARATOR=11]="SEPARATOR"}(Je||(Je={})),function(e){e[e.START=0]="START",e[e.ENDED=1]="ENDED",e[e.ERROR=2]="ERROR",e[e.TRUE1=3]="TRUE1",e[e.TRUE2=4]="TRUE2",e[e.TRUE3=5]="TRUE3",e[e.FALSE1=6]="FALSE1",e[e.FALSE2=7]="FALSE2",e[e.FALSE3=8]="FALSE3",e[e.FALSE4=9]="FALSE4",e[e.NULL1=10]="NULL1",e[e.NULL2=11]="NULL2",e[e.NULL3=12]="NULL3",e[e.STRING_DEFAULT=13]="STRING_DEFAULT",e[e.STRING_AFTER_BACKSLASH=14]="STRING_AFTER_BACKSLASH",e[e.STRING_UNICODE_DIGIT_1=15]="STRING_UNICODE_DIGIT_1",e[e.STRING_UNICODE_DIGIT_2=16]="STRING_UNICODE_DIGIT_2",e[e.STRING_UNICODE_DIGIT_3=17]="STRING_UNICODE_DIGIT_3",e[e.STRING_UNICODE_DIGIT_4=18]="STRING_UNICODE_DIGIT_4",e[e.STRING_INCOMPLETE_CHAR=19]="STRING_INCOMPLETE_CHAR",e[e.NUMBER_AFTER_INITIAL_MINUS=20]="NUMBER_AFTER_INITIAL_MINUS",e[e.NUMBER_AFTER_INITIAL_ZERO=21]="NUMBER_AFTER_INITIAL_ZERO",e[e.NUMBER_AFTER_INITIAL_NON_ZERO=22]="NUMBER_AFTER_INITIAL_NON_ZERO",e[e.NUMBER_AFTER_FULL_STOP=23]="NUMBER_AFTER_FULL_STOP",e[e.NUMBER_AFTER_DECIMAL=24]="NUMBER_AFTER_DECIMAL",e[e.NUMBER_AFTER_E=25]="NUMBER_AFTER_E",e[e.NUMBER_AFTER_E_AND_SIGN=26]="NUMBER_AFTER_E_AND_SIGN",e[e.NUMBER_AFTER_E_AND_DIGIT=27]="NUMBER_AFTER_E_AND_DIGIT",e[e.SEPARATOR=28]="SEPARATOR",e[e.BOM_OR_START=29]="BOM_OR_START",e[e.BOM=30]="BOM"}(Ye||(Ye={}));const Xe={stringBufferSize:0,numberBufferSize:0,separator:void 0,emitPartialTokens:!1};class et extends Error{constructor(e){super(e),Object.setPrototypeOf(this,et.prototype)}}class tt{constructor(e){this.state=Ye.BOM_OR_START,this.bomIndex=0,this.separatorIndex=0,this.escapedCharsByteLength=0,this.bytes_remaining=0,this.bytes_in_sequence=0,this.char_split_buffer=new Uint8Array(4),this.encoder=new TextEncoder,this.offset=-1,e=Object.assign(Object.assign({},Xe),e),this.emitPartialTokens=!0===e.emitPartialTokens,this.bufferedString=e.stringBufferSize&&e.stringBufferSize>4?new Qe(e.stringBufferSize):new ze,this.bufferedNumber=e.numberBufferSize&&e.numberBufferSize>0?new Qe(e.numberBufferSize):new ze,this.separator=e.separator,this.separatorBytes=e.separator?this.encoder.encode(e.separator):void 0}get isEnded(){return this.state===Ye.ENDED}write(e){try{let t;if(e instanceof Uint8Array)t=e;else if("string"==typeof e)t=this.encoder.encode(e);else if(Array.isArray(e))t=Uint8Array.from(e);else{if(!ArrayBuffer.isView(e))throw new TypeError("Unexpected type. The `write` function only accepts Arrays, TypedArrays and Strings.");t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}for(let s=0;s<t.length;s+=1){const i=t[s];switch(this.state){case Ye.BOM_OR_START:if(e instanceof Uint8Array&&239===i){this.bom=[239,187,191],this.bomIndex+=1,this.state=Ye.BOM;continue}if(e instanceof Uint16Array){if(254===i){this.bom=[254,255],this.bomIndex+=1,this.state=Ye.BOM;continue}if(255===i){this.bom=[255,254],this.bomIndex+=1,this.state=Ye.BOM;continue}}if(e instanceof Uint32Array){if(0===i){this.bom=[0,0,254,255],this.bomIndex+=1,this.state=Ye.BOM;continue}if(255===i){this.bom=[255,254,0,0],this.bomIndex+=1,this.state=Ye.BOM;continue}}case Ye.START:if(this.offset+=1,this.separatorBytes&&i===this.separatorBytes[0]){if(1===this.separatorBytes.length){this.state=Ye.START,this.onToken({token:Je.SEPARATOR,value:this.separator,offset:this.offset+this.separatorBytes.length-1});continue}this.state=Ye.SEPARATOR;continue}if(i===Ve.SPACE||i===Ve.NEWLINE||i===Ve.CARRIAGE_RETURN||i===Ve.TAB)continue;if(i===Ve.LEFT_CURLY_BRACKET){this.onToken({token:Je.LEFT_BRACE,value:"{",offset:this.offset});continue}if(i===Ve.RIGHT_CURLY_BRACKET){this.onToken({token:Je.RIGHT_BRACE,value:"}",offset:this.offset});continue}if(i===Ve.LEFT_SQUARE_BRACKET){this.onToken({token:Je.LEFT_BRACKET,value:"[",offset:this.offset});continue}if(i===Ve.RIGHT_SQUARE_BRACKET){this.onToken({token:Je.RIGHT_BRACKET,value:"]",offset:this.offset});continue}if(i===Ve.COLON){this.onToken({token:Je.COLON,value:":",offset:this.offset});continue}if(i===Ve.COMMA){this.onToken({token:Je.COMMA,value:",",offset:this.offset});continue}if(i===Ve.LATIN_SMALL_LETTER_T){this.state=Ye.TRUE1;continue}if(i===Ve.LATIN_SMALL_LETTER_F){this.state=Ye.FALSE1;continue}if(i===Ve.LATIN_SMALL_LETTER_N){this.state=Ye.NULL1;continue}if(i===Ve.QUOTATION_MARK){this.bufferedString.reset(),this.escapedCharsByteLength=0,this.state=Ye.STRING_DEFAULT;continue}if(i>=Ve.DIGIT_ONE&&i<=Ve.DIGIT_NINE){this.bufferedNumber.reset(),this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_INITIAL_NON_ZERO;continue}if(i===Ve.DIGIT_ZERO){this.bufferedNumber.reset(),this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_INITIAL_ZERO;continue}if(i===Ve.HYPHEN_MINUS){this.bufferedNumber.reset(),this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_INITIAL_MINUS;continue}break;case Ye.STRING_DEFAULT:if(i===Ve.QUOTATION_MARK){const e=this.bufferedString.toString();this.state=Ye.START,this.onToken({token:Je.STRING,value:e,offset:this.offset}),this.offset+=this.escapedCharsByteLength+this.bufferedString.byteLength+1;continue}if(i===Ve.REVERSE_SOLIDUS){this.state=Ye.STRING_AFTER_BACKSLASH;continue}if(i>=128){if(this.bytes_in_sequence=i>=194&&i<=223?2:i<=239?3:4,this.bytes_in_sequence<=t.length-s){this.bufferedString.appendBuf(t,s,s+this.bytes_in_sequence),s+=this.bytes_in_sequence-1;continue}this.bytes_remaining=s+this.bytes_in_sequence-t.length,this.char_split_buffer.set(t.subarray(s)),s=t.length-1,this.state=Ye.STRING_INCOMPLETE_CHAR;continue}if(i>=Ve.SPACE){this.bufferedString.appendChar(i);continue}break;case Ye.STRING_INCOMPLETE_CHAR:this.char_split_buffer.set(t.subarray(s,s+this.bytes_remaining),this.bytes_in_sequence-this.bytes_remaining),this.bufferedString.appendBuf(this.char_split_buffer,0,this.bytes_in_sequence),s=this.bytes_remaining-1,this.state=Ye.STRING_DEFAULT;continue;case Ye.STRING_AFTER_BACKSLASH:const r=$e[i];if(r){this.bufferedString.appendChar(r),this.escapedCharsByteLength+=1,this.state=Ye.STRING_DEFAULT;continue}if(i===Ve.LATIN_SMALL_LETTER_U){this.unicode="",this.state=Ye.STRING_UNICODE_DIGIT_1;continue}break;case Ye.STRING_UNICODE_DIGIT_1:case Ye.STRING_UNICODE_DIGIT_2:case Ye.STRING_UNICODE_DIGIT_3:if(i>=Ve.DIGIT_ZERO&&i<=Ve.DIGIT_NINE||i>=Ve.LATIN_CAPITAL_LETTER_A&&i<=Ve.LATIN_CAPITAL_LETTER_F||i>=Ve.LATIN_SMALL_LETTER_A&&i<=Ve.LATIN_SMALL_LETTER_F){this.unicode+=String.fromCharCode(i),this.state+=1;continue}break;case Ye.STRING_UNICODE_DIGIT_4:if(i>=Ve.DIGIT_ZERO&&i<=Ve.DIGIT_NINE||i>=Ve.LATIN_CAPITAL_LETTER_A&&i<=Ve.LATIN_CAPITAL_LETTER_F||i>=Ve.LATIN_SMALL_LETTER_A&&i<=Ve.LATIN_SMALL_LETTER_F){const e=parseInt(this.unicode+String.fromCharCode(i),16);let t;if(void 0===this.highSurrogate){if(e>=55296&&e<=56319){this.highSurrogate=e,this.state=Ye.STRING_DEFAULT;continue}t=String.fromCharCode(e)}else t=e>=56320&&e<=57343?String.fromCharCode(this.highSurrogate,e):String.fromCharCode(this.highSurrogate),this.highSurrogate=void 0;const s=this.encoder.encode(t);this.bufferedString.appendBuf(s),this.escapedCharsByteLength+=6-s.byteLength,this.state=Ye.STRING_DEFAULT;continue}break;case Ye.NUMBER_AFTER_INITIAL_MINUS:if(i===Ve.DIGIT_ZERO){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_INITIAL_ZERO;continue}if(i>=Ve.DIGIT_ONE&&i<=Ve.DIGIT_NINE){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_INITIAL_NON_ZERO;continue}break;case Ye.NUMBER_AFTER_INITIAL_ZERO:if(i===Ve.FULL_STOP){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_FULL_STOP;continue}if(i===Ve.LATIN_SMALL_LETTER_E||i===Ve.LATIN_CAPITAL_LETTER_E){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_E;continue}s-=1,this.state=Ye.START,this.emitNumber();continue;case Ye.NUMBER_AFTER_INITIAL_NON_ZERO:if(i>=Ve.DIGIT_ZERO&&i<=Ve.DIGIT_NINE){this.bufferedNumber.appendChar(i);continue}if(i===Ve.FULL_STOP){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_FULL_STOP;continue}if(i===Ve.LATIN_SMALL_LETTER_E||i===Ve.LATIN_CAPITAL_LETTER_E){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_E;continue}s-=1,this.state=Ye.START,this.emitNumber();continue;case Ye.NUMBER_AFTER_FULL_STOP:if(i>=Ve.DIGIT_ZERO&&i<=Ve.DIGIT_NINE){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_DECIMAL;continue}break;case Ye.NUMBER_AFTER_DECIMAL:if(i>=Ve.DIGIT_ZERO&&i<=Ve.DIGIT_NINE){this.bufferedNumber.appendChar(i);continue}if(i===Ve.LATIN_SMALL_LETTER_E||i===Ve.LATIN_CAPITAL_LETTER_E){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_E;continue}s-=1,this.state=Ye.START,this.emitNumber();continue;case Ye.NUMBER_AFTER_E:if(i===Ve.PLUS_SIGN||i===Ve.HYPHEN_MINUS){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_E_AND_SIGN;continue}case Ye.NUMBER_AFTER_E_AND_SIGN:if(i>=Ve.DIGIT_ZERO&&i<=Ve.DIGIT_NINE){this.bufferedNumber.appendChar(i),this.state=Ye.NUMBER_AFTER_E_AND_DIGIT;continue}break;case Ye.NUMBER_AFTER_E_AND_DIGIT:if(i>=Ve.DIGIT_ZERO&&i<=Ve.DIGIT_NINE){this.bufferedNumber.appendChar(i);continue}s-=1,this.state=Ye.START,this.emitNumber();continue;case Ye.TRUE1:if(i===Ve.LATIN_SMALL_LETTER_R){this.state=Ye.TRUE2;continue}break;case Ye.TRUE2:if(i===Ve.LATIN_SMALL_LETTER_U){this.state=Ye.TRUE3;continue}break;case Ye.TRUE3:if(i===Ve.LATIN_SMALL_LETTER_E){this.state=Ye.START,this.onToken({token:Je.TRUE,value:!0,offset:this.offset}),this.offset+=3;continue}break;case Ye.FALSE1:if(i===Ve.LATIN_SMALL_LETTER_A){this.state=Ye.FALSE2;continue}break;case Ye.FALSE2:if(i===Ve.LATIN_SMALL_LETTER_L){this.state=Ye.FALSE3;continue}break;case Ye.FALSE3:if(i===Ve.LATIN_SMALL_LETTER_S){this.state=Ye.FALSE4;continue}break;case Ye.FALSE4:if(i===Ve.LATIN_SMALL_LETTER_E){this.state=Ye.START,this.onToken({token:Je.FALSE,value:!1,offset:this.offset}),this.offset+=4;continue}break;case Ye.NULL1:if(i===Ve.LATIN_SMALL_LETTER_U){this.state=Ye.NULL2;continue}break;case Ye.NULL2:if(i===Ve.LATIN_SMALL_LETTER_L){this.state=Ye.NULL3;continue}break;case Ye.NULL3:if(i===Ve.LATIN_SMALL_LETTER_L){this.state=Ye.START,this.onToken({token:Je.NULL,value:null,offset:this.offset}),this.offset+=3;continue}break;case Ye.SEPARATOR:if(this.separatorIndex+=1,!this.separatorBytes||i!==this.separatorBytes[this.separatorIndex])break;this.separatorIndex===this.separatorBytes.length-1&&(this.state=Ye.START,this.onToken({token:Je.SEPARATOR,value:this.separator,offset:this.offset+this.separatorIndex}),this.separatorIndex=0);continue;case Ye.BOM:if(i===this.bom[this.bomIndex]){if(this.bomIndex===this.bom.length-1){this.state=Ye.START,this.bom=void 0,this.bomIndex=0;continue}this.bomIndex+=1;continue}break;case Ye.ENDED:if(i===Ve.SPACE||i===Ve.NEWLINE||i===Ve.CARRIAGE_RETURN||i===Ve.TAB)continue}throw new et(`Unexpected "${String.fromCharCode(i)}" at position "${s}" in state ${Ze(this.state)}`)}if(this.emitPartialTokens)switch(this.state){case Ye.TRUE1:case Ye.TRUE2:case Ye.TRUE3:this.onToken({token:Je.TRUE,value:!0,offset:this.offset,partial:!0});break;case Ye.FALSE1:case Ye.FALSE2:case Ye.FALSE3:case Ye.FALSE4:this.onToken({token:Je.FALSE,value:!1,offset:this.offset,partial:!0});break;case Ye.NULL1:case Ye.NULL2:case Ye.NULL3:this.onToken({token:Je.NULL,value:null,offset:this.offset,partial:!0});break;case Ye.STRING_DEFAULT:{const e=this.bufferedString.toString();this.onToken({token:Je.STRING,value:e,offset:this.offset,partial:!0});break}case Ye.NUMBER_AFTER_INITIAL_ZERO:case Ye.NUMBER_AFTER_INITIAL_NON_ZERO:case Ye.NUMBER_AFTER_DECIMAL:case Ye.NUMBER_AFTER_E_AND_DIGIT:try{this.onToken({token:Je.NUMBER,value:this.parseNumber(this.bufferedNumber.toString()),offset:this.offset,partial:!0})}catch(e){}}}catch(e){this.error(e)}}emitNumber(){this.onToken({token:Je.NUMBER,value:this.parseNumber(this.bufferedNumber.toString()),offset:this.offset}),this.offset+=this.bufferedNumber.byteLength-1}parseNumber(e){return Number(e)}error(e){this.state!==Ye.ENDED&&(this.state=Ye.ERROR),this.onError(e)}end(){switch(this.state){case Ye.NUMBER_AFTER_INITIAL_ZERO:case Ye.NUMBER_AFTER_INITIAL_NON_ZERO:case Ye.NUMBER_AFTER_DECIMAL:case Ye.NUMBER_AFTER_E_AND_DIGIT:this.state=Ye.ENDED,this.emitNumber(),this.onEnd();break;case Ye.BOM_OR_START:case Ye.START:case Ye.ERROR:case Ye.SEPARATOR:this.state=Ye.ENDED,this.onEnd();break;default:this.error(new et(`Tokenizer ended in the middle of a token (state: ${Ze(this.state)}). Either not all the data was received or the data was invalid.`))}}onToken(e){throw new et('Can\'t emit tokens before the "onToken" callback has been set up.')}onError(e){throw e}onEnd(){}}var st,it;function rt(e){return["VALUE","KEY","COLON","COMMA","ENDED","ERROR","SEPARATOR"][e]}!function(e){e[e.OBJECT=0]="OBJECT",e[e.ARRAY=1]="ARRAY"}(st||(st={})),function(e){e[e.VALUE=0]="VALUE",e[e.KEY=1]="KEY",e[e.COLON=2]="COLON",e[e.COMMA=3]="COMMA",e[e.ENDED=4]="ENDED",e[e.ERROR=5]="ERROR",e[e.SEPARATOR=6]="SEPARATOR"}(it||(it={}));const nt={paths:void 0,keepStack:!0,separator:void 0,emitPartialValues:!1};class at extends Error{constructor(e){super(e),Object.setPrototypeOf(this,at.prototype)}}class ot{constructor(e){this.state=it.VALUE,this.mode=void 0,this.key=void 0,this.value=void 0,this.stack=[],(e=Object.assign(Object.assign({},nt),e)).paths&&(this.paths=e.paths.map((e=>{if(void 0===e||"$*"===e)return;if(!e.startsWith("$"))throw new at(`Invalid selector "${e}". Should start with "$".`);const t=e.split(".").slice(1);if(t.includes(""))throw new at(`Invalid selector "${e}". ".." syntax not supported.`);return t}))),this.keepStack=e.keepStack||!1,this.separator=e.separator,e.emitPartialValues||(this.emitPartial=()=>{})}shouldEmit(){return!this.paths||this.paths.some((e=>{var t;if(void 0===e)return!0;if(e.length!==this.stack.length)return!1;for(let t=0;t<e.length-1;t++){const s=e[t],i=this.stack[t+1].key;if("*"!==s&&s!==(null==i?void 0:i.toString()))return!1}const s=e[e.length-1];return"*"===s||s===(null===(t=this.key)||void 0===t?void 0:t.toString())}))}push(){this.stack.push({key:this.key,value:this.value,mode:this.mode,emit:this.shouldEmit()})}pop(){const e=this.value;let t;({key:this.key,value:this.value,mode:this.mode,emit:t}=this.stack.pop()),this.state=void 0!==this.mode?it.COMMA:it.VALUE,this.emit(e,t)}emit(e,t){!this.keepStack&&this.value&&this.stack.every((e=>!e.emit))&&delete this.value[this.key],t&&this.onValue({value:e,key:this.key,parent:this.value,stack:this.stack}),0===this.stack.length&&(this.separator?this.state=it.SEPARATOR:void 0===this.separator&&this.end())}emitPartial(e){this.shouldEmit()&&(this.state!==it.KEY?this.onValue({value:e,key:this.key,parent:this.value,stack:this.stack,partial:!0}):this.onValue({value:void 0,key:e,parent:this.value,stack:this.stack,partial:!0}))}get isEnded(){return this.state===it.ENDED}write({token:e,value:t,partial:s}){try{if(s)return void this.emitPartial(t);if(this.state===it.VALUE){if(e===Je.STRING||e===Je.NUMBER||e===Je.TRUE||e===Je.FALSE||e===Je.NULL)return this.mode===st.OBJECT?(this.value[this.key]=t,this.state=it.COMMA):this.mode===st.ARRAY&&(this.value.push(t),this.state=it.COMMA),void this.emit(t,this.shouldEmit());if(e===Je.LEFT_BRACE){if(this.push(),this.mode===st.OBJECT)this.value=this.value[this.key]={};else if(this.mode===st.ARRAY){const e={};this.value.push(e),this.value=e}else this.value={};return this.mode=st.OBJECT,this.state=it.KEY,this.key=void 0,void this.emitPartial()}if(e===Je.LEFT_BRACKET){if(this.push(),this.mode===st.OBJECT)this.value=this.value[this.key]=[];else if(this.mode===st.ARRAY){const e=[];this.value.push(e),this.value=e}else this.value=[];return this.mode=st.ARRAY,this.state=it.VALUE,this.key=0,void this.emitPartial()}if(this.mode===st.ARRAY&&e===Je.RIGHT_BRACKET&&0===this.value.length)return void this.pop()}if(this.state===it.KEY){if(e===Je.STRING)return this.key=t,this.state=it.COLON,void this.emitPartial();if(e===Je.RIGHT_BRACE&&0===Object.keys(this.value).length)return void this.pop()}if(this.state===it.COLON&&e===Je.COLON)return void(this.state=it.VALUE);if(this.state===it.COMMA){if(e===Je.COMMA){if(this.mode===st.ARRAY)return this.state=it.VALUE,void(this.key+=1);if(this.mode===st.OBJECT)return void(this.state=it.KEY)}if(e===Je.RIGHT_BRACE&&this.mode===st.OBJECT||e===Je.RIGHT_BRACKET&&this.mode===st.ARRAY)return void this.pop()}if(this.state===it.SEPARATOR&&e===Je.SEPARATOR&&t===this.separator)return void(this.state=it.VALUE);if(e===Je.SEPARATOR&&this.state!==it.SEPARATOR&&Array.from(t).map((e=>e.charCodeAt(0))).every((e=>e===Ve.SPACE||e===Ve.NEWLINE||e===Ve.CARRIAGE_RETURN||e===Ve.TAB)))return;throw new at(`Unexpected ${Je[e]} (${JSON.stringify(t)}) in state ${rt(this.state)}`)}catch(e){this.error(e)}}error(e){this.state!==it.ENDED&&(this.state=it.ERROR),this.onError(e)}end(){this.state!==it.VALUE&&this.state!==it.SEPARATOR||this.stack.length>0?this.error(new Error(`Parser ended in mid-parsing (state: ${rt(this.state)}). Either not all the data was received or the data was invalid.`)):(this.state=it.ENDED,this.onEnd())}onValue(e){throw new at('Can\'t emit data before the "onValue" callback has been set up.')}onError(e){throw e}onEnd(){}}class ct{constructor(e={}){this.tokenizer=new tt(e),this.tokenParser=new ot(e),this.tokenizer.onToken=this.tokenParser.write.bind(this.tokenParser),this.tokenizer.onEnd=()=>{this.tokenParser.isEnded||this.tokenParser.end()},this.tokenParser.onError=this.tokenizer.error.bind(this.tokenizer),this.tokenParser.onEnd=()=>{this.tokenizer.isEnded||this.tokenizer.end()}}get isEnded(){return this.tokenizer.isEnded&&this.tokenParser.isEnded}write(e){this.tokenizer.write(e)}end(){this.tokenizer.end()}set onToken(e){this.tokenizer.onToken=t=>{e(t),this.tokenParser.write(t)}}set onValue(e){this.tokenParser.onValue=e}set onError(e){this.tokenizer.onError=e}set onEnd(e){this.tokenParser.onEnd=()=>{this.tokenizer.isEnded||this.tokenizer.end(),e.call(this.tokenParser)}}}var _t;function lt(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}(_t||(_t={})).STREAM_PARSER_JSON_ERROR="chat_sdk_pull_stream_parser_error";class ht{__init(){this.parserOptions={emitPartialValues:!0,emitPartialTokens:!0,keepStack:!0}}__init2(){this.jsonParserMap={}}__init3(){this.jsonParserMetaMap={}}constructor(e){ht.prototype.__init.call(this),ht.prototype.__init2.call(this),ht.prototype.__init3.call(this),ht.prototype.__init4.call(this),ht.prototype.__init5.call(this),ht.prototype.__init6.call(this),ht.prototype.__init7.call(this),ht.prototype.__init8.call(this);const{reportLogWithScope:t}=e;this.reportLogWithScope=t}__init4(){this.getJsonParser=e=>{if(this.jsonParserMap[e])return this.jsonParserMap[e];const t=new ct(this.parserOptions);return this.jsonParserMap[e]=t,this.jsonParserMetaMap[e]={isError:!1},this.jsonParserMap[e]}}__init5(){this.updateJsonParserMeta=(e,t)=>{_e(this.jsonParserMetaMap,e,t)}}__init6(){this.write=(e,t,{onValue:s,onError:i,onEnd:r,onToken:n})=>{const a=this.getJsonParser(e);lt([this,"access",e=>e.jsonParserMetaMap,"access",t=>t[e],"optionalAccess",e=>e.isError])||a.isEnded||(a.onValue=s,a.onError=t=>{this.updateJsonParserMeta(e,(e=>({...e,isError:!0}))),lt([i,"optionalCall",e=>e(t)]),this.reportLogWithScope.slardarErrorEvent({error:t,eventName:_t.STREAM_PARSER_JSON_ERROR,meta:{msgId:e}})},a.onEnd=()=>{this.clearByMsgId(e),lt([r,"optionalCall",e=>e()])},n&&(a.onToken=n),a.write(t))}}__init7(){this.clearParserCallback=e=>{e.onValue=p,e.onError=p,e.onEnd=p,e.onToken=p}}__init8(){this.clearByMsgId=e=>{const t=this.jsonParserMap[e];t&&this.clearParserCallback(t),delete this.jsonParserMap[e],delete this.jsonParserMetaMap[e]}}destroy(){Object.values(this.jsonParserMap).forEach(this.clearParserCallback),this.jsonParserMap={},this.jsonParserMetaMap={}}}const ut={toolRequestStreamingParameters:!1},pt={v1:{toolRequestStreamingParameters:!0}},dt=e=>{return"tool_request"===e.type&&(t=e.version,t&&pt[t]||ut).toolRequestStreamingParameters;var t};function gt(e,t){return null!=e?e:t()}function Tt(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}class Et{constructor(e){const{initMessageBuffer:t=[],reportLogWithScope:i}=e;this.streamMessageBuffer=s.cloneDeep(t),this.streamChunkBuffer=s.cloneDeep(t),this.streamParserJson=new ht({reportLogWithScope:i}),this.streamMessageBuffer.forEach((e=>{dt(e)&&this.streamParserJson.write(e.msg_id,Tt([e,"access",e=>e.content,"access",e=>e.tool_request,"optionalAccess",e=>e.stream_parameters])||"",{onValue:p})}))}pushChunk(e){this.streamChunkBuffer.push(e)}clearMessageBuffer(){this.streamMessageBuffer=[],this.streamChunkBuffer=[],this.streamParserJson.destroy()}getChunkByMessageId(e){return this.streamChunkBuffer.filter((t=>t.msg_id===e))}concatBatchAndUpdateMessage(e){const{msgId:t,chunks:i}=e;if(0===i.length)return;i.forEach((e=>{this.streamChunkBuffer.push(e)}));const r=i.at(0),n=this.streamMessageBuffer.findIndex((e=>r?""!==t?e.msg_id===t:""===e.msg_id&&e.type===r.type&&e.query_msg_id===r.query_msg_id:e.msg_id===t)),a=-1!==n?this.streamMessageBuffer[n]:void 0,o=xe(a,i);if(!o)return;const c=dt(o);return c&&i.forEach((e=>{this.streamParserJson.write(e.msg_id,Tt([e,"access",e=>e.content,"access",e=>e.tool_request,"optionalAccess",e=>e.stream_parameters])||"",{onValue:(...e)=>{const t=(e=>{const{key:t,value:i,stack:r,partial:n,parent:a}=e,o=r.slice(1),c=o.at(0);if(ae(t)||ae(i))return;const _=s.cloneDeep(a),l=s.cloneDeep(i);if(!c){if(!n)return _||l;if(!_)return;return _[t]=l,_}const h=s.cloneDeep(c.value);return n?(_e(h,o.map((e=>e.key)).filter((e=>!ae(e))).concat(t),(()=>l)),h):h})(...e);t&&(o.streamParametersContent=t)}})})),!o.streamParametersContent&&c&&a&&(o.streamParametersContent=a.streamParametersContent),-1===n?this.streamMessageBuffer.push(o):this.streamMessageBuffer.splice(n,1,o),o}}const mt=1073741823;class ft{__init(){this.shallowCloneStreamBuffer=()=>({streamMessageBuffer:[...this.streamBuffer.streamMessageBuffer],streamChunkBuffer:[...this.streamBuffer.streamChunkBuffer]})}__init2(){this.getStreamBuffer=()=>this.shallowCloneStreamBuffer()}__init3(){this.getStreamBufferWithMeta=()=>{const e=this.shallowCloneStreamBuffer();return{...e,...this.simpleMessageDump.getBufferMeta(e.streamMessageBuffer)}}}__init4(){this.getStreamBufferSnapshot=()=>this.simpleMessageDump.getStreamBufferSnapshot()}constructor(e){ft.prototype.__init.call(this),ft.prototype.__init2.call(this),ft.prototype.__init3.call(this),ft.prototype.__init4.call(this),ft.prototype.__init5.call(this),ft.prototype.__init6.call(this),ft.prototype.__init7.call(this),ft.prototype.__init8.call(this);const{getEnableDebug:t,key:s,reportLogWithScope:i,initMaxSequenceId:r}=e;this.getEnableDebug=t,this.maxSequenceId=gt(r,(()=>0)),this.enableChunkProcessedCheck=gt(e.enableChunkProcessedCheck,(()=>!1)),this.streamBuffer=new Et(e),this.debugLogger=new Ke({reportLogWithScope:i,getEnableDebug:t,getLogPayload:()=>this.getStreamBuffer(),mark:"ChunkProcessor"}),this.simpleMessageDump=new He({key:s})}__init5(){this.startDebugLog=e=>{this.debugLogger.isDebugging||this.debugLogger.startDebugLog(e)}}__init6(){this.stopDebugLog=()=>{this.debugLogger.stopDebugLog()}}isStreamBufferEmpty(){return 0===this.streamBuffer.streamChunkBuffer.length&&0===this.streamBuffer.streamMessageBuffer.length}__init7(){this.clearMessageBuffer=()=>{this.stopDebugLog(),this.simpleMessageDump.recordStreamBuffer(this.shallowCloneStreamBuffer()),this.streamBuffer.clearMessageBuffer()}}addBatchAndProcess(e){const t=e.chunks.at(0);if(t)return this.startDebugLog(t.query_msg_id),this.streamBuffer.concatBatchAndUpdateMessage(e)}checkInBufferProcessed(e){return""===e.msg_id?this.streamBuffer.streamMessageBuffer.some((t=>""===t.msg_id&&t.type===e.type&&t.query_msg_id===e.query_msg_id&&t.sequence_id>=e.sequence_id)):this.streamBuffer.streamMessageBuffer.some((t=>t.msg_id===e.msg_id&&t.sequence_id>=e.sequence_id))}checkMessageHasProcessed(e){if(this.checkInBufferProcessed(e))return!0;if(!this.enableChunkProcessedCheck)return!1;if(0===this.maxSequenceId)return this.maxSequenceId=e.sequence_id,!1;const t=this.maxSequenceId,s=e.sequence_id,i=t>mt,r=s>mt;return i&&!r?(this.maxSequenceId=s,!1):!(i||!r)||(!(s>=t)||(this.maxSequenceId=s,!1))}getProcessedMessageByChunk(e){return this.streamBuffer.streamMessageBuffer.find((t=>t.msg_id===e.msg_id))}getProcessedMessageByMessageId(e){return this.streamBuffer.streamMessageBuffer.find((t=>t.msg_id===e))}getAckMessageByLocalMessageId(e){return this.streamBuffer.streamMessageBuffer.find((t=>Tt([t,"access",e=>e.content,"access",e=>e.message_start,"optionalAccess",e=>e.local_msg_id])===e&&"message_start"===t.type))}getFirstReplyMessageByChunk(e){if(this.streamBuffer.streamMessageBuffer.some((t=>"message_start"===t.type&&t.query_msg_id===e.query_msg_id)))return this.streamBuffer.streamMessageBuffer.find((t=>"message_start"!==t.type&&t.query_msg_id===e.query_msg_id))}getAckMessage(){return this.streamBuffer.streamMessageBuffer.find((e=>"message_start"===e.type))}isFirstReplyMessage(e){return!!this.getAckMessage()&&!this.getFirstReplyMessageByChunk(e)}getReplyMessagesByQueryMsgId(e){return this.streamBuffer.streamMessageBuffer.filter((t=>"message_start"!==t.type&&t.query_msg_id===e))}__init8(){this.destroy=()=>{this.debugLogger.destroy(),this.clearMessageBuffer(),this.simpleMessageDump.clear()}}}var Lt,At,St;!function(e){e.MESSAGE_RECEIVED_AND_UPDATE="message_received_and_update";e.MESSAGE_PULLING_STATUS="message_pulling_status";e.SEND_MESSAGE_ERROR="send_message_error";e.CHANNEL_STATUS="channel_status";e.CONTEXT_CHANGE="context_change";e.SESSION_CHANGED="session_changed"}(Lt||(Lt={})),function(e){e[e.Unknown=0]="Unknown";e[e.Prev=1]="Prev";e[e.Next=2]="Next"}(At||(At={}));class Rt{__init(){this.timer=null}__init2(){this.timeoutMs=12e4}constructor(e){Rt.prototype.__init.call(this),Rt.prototype.__init2.call(this),this.reportLogWithScope=e.reportLogWithScope,e.timeoutMs&&(this.timeoutMs=e.timeoutMs),this.getChannelOptions=e.getChannelOptions}flushMessage(e){this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.reportLogWithScope.slardarErrorEvent({eventName:`${this.getChannelOptions().channelName}_OnMessageTimeout`,error:new Error("OnMessageTimeout - 超时未收到消息"),meta:{...this.getChannelOptions(),log_id:e.log_id,query_msg_id:e.query_msg_id,lastMessage:e}}),this.timer=null}),this.timeoutMs)}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null)}}!function(e){e.MESSAGE_END="message_end";e.MESSAGE_SEND_SUCCESS="message_send_success";e.MESSAGE_SEND_AND_RECEIVE_ERROR="message_send_and_receive_error";e.MESSAGE_SEND_TIMEOUT="message_send_timeout"}(St||(St={}));class Ct{__init(){this.state="pending"}constructor(){Ct.prototype.__init.call(this),this.promise=new Promise(((e,t)=>{this.resolve=(...t)=>{this.state="fulfilled",e(...t)},this.reject=(...e)=>{this.state="rejected",t(...e)}})),this.then=this.promise.then.bind(this.promise)}}function vt(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}const It={message_start:!0,answer:!0,thinking:!0,tool_request:!0,tool_process:!0,tool_response:!0,message_end:!0,deploy:!0,version:!0,context:!0,session_changed:!0,error:!0,message_enqueued:!0,ack:!0,conversation_changed:!0,setting_changed:!0,queue_changed:!0,collaborator_changed:!0,conversation_settings_update:!0,conversation_delete:!0,project_invitation:!0,project_change:!0},yt=e=>{const{type:t}=e;return(e=>e in It)(t)?dt({type:t,version:e.version})?{...e,role:"assistant",type:t,streamParametersContent:(n=vt([e,"access",e=>e.content,"access",e=>e.tool_request,"optionalAccess",e=>e.stream_parameters]),a=()=>"",i=null!=n?n:a(),s.safeJsonParse(i,void 0,{onError:r}))}:{...e,role:"assistant",type:t}:((e=>{throw new Error(`[chat-area] ${e}`)})(`invalid server message type: ${t}`),{...e,role:"assistant"});var i,r,n,a};class bt extends Error{constructor(e,t){super(e),bt.prototype.__init.call(this),this.name="chatCoreError",this.ext=t||{}}__init(){this.flatten=()=>{const{message:e,ext:t}=this;return{message:e,...t}}}}function Mt(e,t){return null!=e?e:t()}function Nt(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}const Ut=e=>{const{content:t,type:s}=e;switch(s){case"answer":return Mt(Nt([t,"access",e=>e.answer,"optionalAccess",e=>e.length]),(()=>0));case"thinking":return Mt(Nt([t,"access",e=>e.thinking,"optionalAccess",e=>e.length]),(()=>0));case"tool_request":return Mt(Nt([t,"access",e=>e.tool_request,"optionalAccess",e=>e.stream_parameters,"optionalAccess",e=>e.length]),(()=>0));case"tool_process":return(e=>{const t=Nt([e,"access",e=>e.content,"access",e=>e.tool_process,"optionalAccess",e=>e.data,"access",e=>e.content]);return Ge.reduce(((e,s)=>{const i=Nt([t,"optionalAccess",e=>e[s]]);return"string"!=typeof i?e:e+i.length}),0)})(e);case"tool_response":return Mt(Nt([t,"access",e=>e.tool_response,"optionalAccess",e=>e.result,"access",e=>e.length]),(()=>0));default:return 0}};class Ot{__init(){this.bufferMap=new Map}constructor(e,t){Ot.prototype.__init.call(this),Ot.prototype.__init2.call(this),Ot.prototype.__init3.call(this),Ot.prototype.__init4.call(this),Ot.prototype.__init5.call(this),Ot.prototype.__init6.call(this),Ot.prototype.__init7.call(this),Ot.prototype.__init8.call(this),Ot.prototype.__init9.call(this),Ot.prototype.__init10.call(this),this.onFlush=e,this.config={lengthThreshold:Mt(Nt([t,"optionalAccess",e=>e.lengthThreshold]),(()=>4096)),maxWaitMs:Mt(Nt([t,"optionalAccess",e=>e.maxWaitMs]),(()=>500))}}__init2(){this.createEntry=(e,t)=>({msgId:e,chunks:[],totalLength:0,startSeq:t.sequence_id,maxWaitTimerId:null,hasFirstFlushed:!1})}__init3(){this.enqueue=e=>{const{msg_id:t}=e;let s=this.bufferMap.get(t);if(!s)return s=this.createEntry(t,e),this.bufferMap.set(t,s),this.onFlush({msgId:t,chunks:[e],startSeq:e.sequence_id,reason:"firstChunk"}),void(s.hasFirstFlushed=!0);0===s.chunks.length&&(s.startSeq=e.sequence_id),s.chunks.push(e),s.totalLength+=Ut(e),s.totalLength>=this.config.lengthThreshold?this.flush(t,"length"):e.finish?this.flush(t,"finish"):this.armMaxWaitTimer(t)}}__init4(){this.flush=(e,t)=>{const s=this.bufferMap.get(e);if(!s||0===s.chunks.length)return;this.cancelMaxWaitTimer(e);const i=this.buildBatch(s,t);this.onFlush(i),s.chunks=[],s.totalLength=0}}__init5(){this.buildBatch=(e,t)=>({msgId:e.msgId,chunks:[...e.chunks],startSeq:e.startSeq,reason:t})}__init6(){this.armMaxWaitTimer=e=>{const t=this.bufferMap.get(e);t&&(t.maxWaitTimerId||(t.maxWaitTimerId=setTimeout((()=>{this.flush(e,"maxWait")}),this.config.maxWaitMs)))}}__init7(){this.cancelMaxWaitTimer=e=>{const t=this.bufferMap.get(e);Nt([t,"optionalAccess",e=>e.maxWaitTimerId])&&(clearTimeout(t.maxWaitTimerId),t.maxWaitTimerId=null)}}__init8(){this.forceFlush=e=>{this.flush(e,"force"),this.bufferMap.delete(e)}}__init9(){this.forceFlushAll=()=>{Array.from(this.bufferMap.keys()).forEach((e=>this.forceFlush(e)))}}__init10(){this.destroy=()=>{this.bufferMap.forEach(((e,t)=>{this.cancelMaxWaitTimer(t)})),this.bufferMap.clear()}}}function Pt(e,t){return null!=e?e:t()}function Bt(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}class kt{__init(){this.bufferManager=null}constructor({channel:e,reportLogWithScope:t,chunkProcessor:s,preSendLocalMessageEventsManager:i,chatSdkEventEmit:r,chatSdkEventBus:n,reportEventsTracer:a,manualInitChannel:o,enableBuffer:c=!1}){kt.prototype.__init.call(this),kt.prototype.__init2.call(this),kt.prototype.__init3.call(this),kt.prototype.__init4.call(this),kt.prototype.__init5.call(this),kt.prototype.__init6.call(this),kt.prototype.__init7.call(this),kt.prototype.__init8.call(this),kt.prototype.__init9.call(this),kt.prototype.__init10.call(this),kt.prototype.__init11.call(this),kt.prototype.__init12.call(this),kt.prototype.__init13.call(this),kt.prototype.__init14.call(this),kt.prototype.__init15.call(this),this.channel=e,this.reportLogWithScope=t,this.chunkProcessor=s,this.preSendLocalMessageEventsManager=i,this.chatSdkEventEmit=r,this.reportEventsTracer=a,this.chatSdkEventBus=n,this.enableBuffer=c,this.onMessageMonitor=new Rt({reportLogWithScope:t,getChannelOptions:()=>({...Pt(Bt([this,"access",e=>e.channel,"access",e=>e.getChannelOptions,"optionalCall",e=>e()]),(()=>({}))),channelName:this.channel.channelName}),timeoutMs:12e4}),c&&(this.bufferManager=new Ot(this.processChunkBatchAndEmit,void 0)),o||this.initChannel()}onChannelEvents(){this.channel.addEventListener("onmessage",this.handleChannelMessage),this.channel.addEventListener("onerror",this.handleWebSocketChannelError),this.channel.addEventListener("onopen",this.handleChannelOpen),this.channel.addEventListener("onclose",this.handleChannelClose)}offChannelEvents(){this.channel.removeEventListener("onmessage",this.handleChannelMessage),this.channel.removeEventListener("onerror",this.handleWebSocketChannelError),this.channel.removeEventListener("onopen",this.handleChannelOpen),this.channel.removeEventListener("onclose",this.handleChannelClose)}__init2(){this.handleChannelMessage=e=>{const t=yt(e);this.onMessageMonitor.flushMessage(t);const{type:s}=t;return"context"===s&&t.content.context?this.handleContextChange(t.content.context):"session_changed"===s&&t.content.session_changed?this.handleSessionChange(t.content.session_changed):this.handleChatMessage(t)}}__init3(){this.handleContextChange=e=>{this.reportLogWithScope.info({message:"context 更新",meta:{context:e}}),this.chatSdkEventEmit(Lt.CONTEXT_CHANGE,{name:Lt.CONTEXT_CHANGE,data:e})}}__init4(){this.handleSessionChange=e=>{this.reportLogWithScope.info({message:"session 更新",meta:{session:e}}),this.chatSdkEventEmit(Lt.SESSION_CHANGED,{name:Lt.SESSION_CHANGED,data:e})}}__init5(){this.handleChatFinish=()=>{Bt([this,"access",e=>e.bufferManager,"optionalAccess",e=>e.forceFlushAll,"call",e=>e()]),this.chunkProcessor.clearMessageBuffer(),this.onMessageMonitor.destroy()}}__init6(){this.createSingleChunkBatch=e=>({msgId:e.msg_id,chunks:[e],startSeq:e.sequence_id,reason:"force"})}__init7(){this.processChunkBatchAndEmit=e=>{const{chunks:t}=e;if(0===t.length)return;const s=t.at(0);if(!s)return;const{query_msg_id:i,log_id:r,content:n}=s,a=Pt(Bt([n,"access",e=>e.message_start,"optionalAccess",e=>e.local_msg_id]),(()=>""));this.chunkProcessor.isFirstReplyMessage(s)&&Bt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.pullStreamTracer,"optionalAccess",e=>e.receiveFirstAnsChunk,"call",e=>e(a,{log_id:r})]);const o=this.chunkProcessor.addBatchAndProcess(e);if(!o)throw new bt("processedMessage is undefined",{local_msg_id:a});this.chatSdkEventEmit(Lt.MESSAGE_PULLING_STATUS,{name:Lt.MESSAGE_PULLING_STATUS,data:{pullingStatus:"pulling",local_msg_id:a,query_msg_id:i,conversation_id:s.conversation_id,project_id:s.project_id}}),this.chatSdkEventEmit(Lt.MESSAGE_RECEIVED_AND_UPDATE,{name:Lt.MESSAGE_RECEIVED_AND_UPDATE,data:[o]})}}__init8(){this.handleChatMessage=e=>{const{content:t,type:s}=e,i=Pt(Bt([t,"access",e=>e.message_start,"optionalAccess",e=>e.local_msg_id]),(()=>""));if(!this.chunkProcessor.checkMessageHasProcessed(e))if("message_end"!==s)if("message_start"!==s)if("error"!==s)this.enableBuffer&&this.bufferManager?this.bufferManager.enqueue(e):this.processChunkBatchAndEmit(this.createSingleChunkBatch(e));else{Bt([this,"access",e=>e.bufferManager,"optionalAccess",e=>e.forceFlushAll,"call",e=>e()]);const t=this.chunkProcessor.addBatchAndProcess(this.createSingleChunkBatch(e));if(!t)throw new bt("processedMessage is undefined",{local_msg_id:i});this.handleMessageError(t)}else{const t=this.chunkProcessor.addBatchAndProcess(this.createSingleChunkBatch(e));if(!t)throw new bt("processedMessage is undefined",{local_msg_id:i});this.handleMessageStart(t)}else{Bt([this,"access",e=>e.bufferManager,"optionalAccess",e=>e.forceFlushAll,"call",e=>e()]);const t=this.chunkProcessor.addBatchAndProcess(this.createSingleChunkBatch(e));if(!t)throw new bt("processedMessage is undefined",{local_msg_id:i});this.handleMessageEnd(t)}}}__init9(){this.handleWebSocketChannelError=e=>{!e.ext.willClose&&e.ext.isQosError||(this.onMessageMonitor.destroy(),this.reportLogWithScope.error({message:"信道异常",error:e}),this.chatSdkEventEmit(Lt.MESSAGE_PULLING_STATUS,{name:Lt.MESSAGE_PULLING_STATUS,data:{pullingStatus:"channel_error",wsError:e}}),this.chatSdkEventEmit(Lt.CHANNEL_STATUS,{name:Lt.CHANNEL_STATUS,data:{channelStatus:"disconnected",message:e.message}}),this.handleChatFinish())}}__init10(){this.handleMessageEnd=e=>{const{query_msg_id:t,reply_id:s,content:i}=e,r=this.chunkProcessor.getReplyMessagesByQueryMsgId(t);Bt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.pullStreamTracer,"optionalAccess",e=>e.success,"call",e=>e(t,{replyMessageCount:r})]),this.reportLogWithScope.info({message:"拉取回复完成",meta:{query_msg_id:t,message:e}});const n=i.message_end;switch(Bt([n,"optionalAccess",e=>e.code])){case"0":this.chatSdkEventEmit(Lt.MESSAGE_PULLING_STATUS,{name:Lt.MESSAGE_PULLING_STATUS,data:{pullingStatus:"success",query_msg_id:t,reply_id:s,messageEndDetail:i.message_end,conversation_id:e.conversation_id,project_id:e.project_id}});break;case"1":this.chatSdkEventEmit(Lt.MESSAGE_PULLING_STATUS,{name:Lt.MESSAGE_PULLING_STATUS,data:{pullingStatus:"cancel",query_msg_id:t,messageEndDetail:i.message_end,reply_id:s,conversation_id:e.conversation_id,project_id:e.project_id}});break;default:this.chatSdkEventEmit(Lt.MESSAGE_PULLING_STATUS,{name:Lt.MESSAGE_PULLING_STATUS,data:{pullingStatus:"error",query_msg_id:t,messageEndDetail:i.message_end,reply_id:s,code:Bt([n,"optionalAccess",e=>e.code]),message:Bt([n,"optionalAccess",e=>e.message]),conversation_id:e.conversation_id,project_id:e.project_id}})}this.preSendLocalMessageEventsManager.emit(St.MESSAGE_END,e),this.handleChatFinish()}}__init11(){this.handleMessageError=e=>{const{query_msg_id:t,content:s}=e,i=Bt([s,"access",e=>e.error,"optionalAccess",e=>e.local_msg_id]),r=Pt(Bt([s,"access",e=>e.error,"optionalAccess",e=>e.error_msg]),(()=>"")),n=new bt(r,{query_msg_id:t,local_msg_id:i,code:Bt([s,"access",e=>e.error,"optionalAccess",e=>e.code])});Bt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.pullStreamTracer,"optionalAccess",e=>e.error,"call",e=>e(n)]),this.reportLogWithScope.error({error:n,message:"收到错误消息",meta:{query_msg_id:t,local_msg_id:i,errorMessage:r}}),this.preSendLocalMessageEventsManager.emit(St.MESSAGE_SEND_AND_RECEIVE_ERROR,n),this.chatSdkEventEmit(Lt.SEND_MESSAGE_ERROR,{name:Lt.SEND_MESSAGE_ERROR,data:{error:n}}),this.handleChatFinish()}}__init12(){this.handleMessageStart=e=>{const{content:t,query_msg_id:s,log_id:i}=e,r=t.message_start,n=Bt([r,"optionalAccess",e=>e.local_msg_id]);Bt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.pullStreamTracer,"optionalAccess",e=>e.start,"call",e=>e(s,{logId:i})]),this.reportLogWithScope.info({message:"开始拉取回复",meta:{local_msg_id:n,query_msg_id:s,log_id:i}}),this.preSendLocalMessageEventsManager.emit(St.MESSAGE_SEND_SUCCESS,e),this.chatSdkEventEmit(Lt.MESSAGE_PULLING_STATUS,{name:Lt.MESSAGE_PULLING_STATUS,data:{pullingStatus:"start",local_msg_id:n,query_msg_id:s,startDetail:r,conversation_id:e.conversation_id,project_id:e.project_id}})}}__init13(){this.handleChannelOpen=()=>{this.reportLogWithScope.info({message:"信道连接成功"}),this.chatSdkEventEmit(Lt.CHANNEL_STATUS,{name:Lt.CHANNEL_STATUS,data:{channelStatus:"connected"}})}}__init14(){this.handleChannelClose=({code:e,reason:t})=>{this.onMessageMonitor.destroy(),this.reportLogWithScope.info({message:"信道关闭",meta:{code:e,reason:t}}),this.chatSdkEventEmit(Lt.CHANNEL_STATUS,{name:Lt.CHANNEL_STATUS,data:{channelStatus:"disconnected",message:t}})}}__init15(){this.initChannel=async()=>{this.channel.isChannelOpen()||await this.channel.connect()}}destroy(){Bt([this,"access",e=>e.bufferManager,"optionalAccess",e=>e.destroy,"call",e=>e()]),this.offChannelEvents(),this.chatSdkEventBus.all.clear()}}function jt(e,t){return null!=e?e:t()}function Dt(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}class Gt{constructor({preSendLocalMessageFactory:e,channel:t,preSendLocalMessageEventsManager:s,reportLogWithScope:i,reportEventsTracer:r,chatSdkEventEmit:n}){Gt.prototype.__init.call(this),this.preSendLocalMessageFactory=e,this.channel=t,this.preSendLocalMessageEventsManager=s,this.reportLogWithScope=i,this.reportEventsTracer=r,this.chatSdkEventEmit=n}createChannelErrorHandler(e){return()=>{const t=new bt("Error: during send message channel onerror",{local_msg_id:e});throw Dt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.sendMessageTracer,"access",e=>e.error,"call",e=>e(t)]),t}}__init(){this.createAckErrorHandler=e=>t=>{if("0"===t.code)return;const s=new bt(t.msg,{local_msg_id:e});throw this.chatSdkEventEmit(Lt.SEND_MESSAGE_ERROR,{name:Lt.SEND_MESSAGE_ERROR,data:{error:s}}),Dt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.sendMessageTracer,"access",e=>e.error,"call",e=>e(s)]),s}}startMessageTracing(e,t){Dt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.sendMessageTracer,"access",e=>e.start,"call",s=>s(e,{local_msg_id:e,...t})])}completeMessageTracing(e,t){Dt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.sendMessageTracer,"access",e=>e.success,"call",s=>s(e,t)])}traceMessageError(e,t){Dt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.sendMessageTracer,"access",e=>e.error,"call",e=>e(t)])}async sendCommandMessage(e){this.reportLogWithScope.info({message:"开始发送命令消息",meta:{message:e}}),await this.executeCommandMessage(e)}async executeCommandMessage(e){const{local_msg_id:t,type:s}=e;return this.startMessageTracing(t),new Promise(((i,r)=>{const n=this.createCommandContext(e,i,r);this.setupCommandEventListeners(n),this.sendMessageWithChannel(e,t).then((()=>this.handleCommandSendSuccess(s,t,n.promiseHandlers.resolve))).catch((e=>this.handleCommandSendError(e,t,n.promiseHandlers.reject)))}))}createCommandContext(e,t,s){const i={resolve:()=>{o(),t()},reject:e=>{o(),s(e)}},{local_msg_id:r,type:n}=e,a=[],o=()=>{a.forEach((e=>e()))};return{localMsgId:r,type:n,eventCleanup:a,cleanup:o,handleMessageEnd:e=>{"cancel"===n&&(this.completeMessageTracing(r,{logId:e.log_id}),i.resolve())},promiseHandlers:i}}setupCommandEventListeners(e){const{localMsgId:t,type:s,eventCleanup:i,handleMessageEnd:r}=e,n=this.createChannelErrorHandler(t),a=this.createAckErrorHandler(t),o=()=>{try{n()}catch(t){e.promiseHandlers.reject(t)}},c=t=>{try{a(t)}catch(t){e.promiseHandlers.reject(t)}};this.channel.addEventListener("onerror",o),this.channel.addEventListener("onack",c),i.push((()=>this.channel.removeEventListener("onerror",o))),i.push((()=>this.channel.removeEventListener("onack",c))),"cancel"===s&&(this.preSendLocalMessageEventsManager.on(St.MESSAGE_END,r),i.push((()=>this.preSendLocalMessageEventsManager.off(St.MESSAGE_END,r))))}handleCommandSendSuccess(e,t,s){"input"===e&&(this.completeMessageTracing(t),s())}handleCommandSendError(e,t,s){const i=new bt(`Error: channel send command message error: ${String(e)}`,{local_msg_id:t});this.traceMessageError(t,i),s(i)}async sendChatMessage(e,t){this.reportLogWithScope.info({message:"开始发送聊天消息",meta:{message:e}});const s=this.preSendLocalMessageFactory.getSendChatMessageStructure(e,t);return await this.executeChatMessage(s,t)}executeChatMessage(e,t){const{local_msg_id:s}=e,i=jt(Dt([t,"optionalAccess",e=>e.sendTimeout]),(()=>6e4));return new Promise(((t,r)=>{const n=this.createChatContext(e,t,r);this.setupChatEventListeners(n,i),this.startMessageTracing(s),this.sendMessageWithChannel(e,s).catch((e=>this.handleChatSendError(e,s,n.promiseHandlers.reject)))}))}createChatContext(e,t,s){const i={resolve:e=>{a(),t(e)},reject:e=>{a(),s(e)}},{local_msg_id:r}=e,n=[],a=()=>{n.forEach((e=>e()))};return{localMsgId:r,message:e,eventCleanup:n,cleanup:a,promiseHandlers:i}}setupChatEventListeners(e,t){const{localMsgId:s,eventCleanup:i,promiseHandlers:r}=e,n=this.setupTimeoutHandler(s,t,r.reject);i.push((()=>clearTimeout(n)));const a=this.createChannelErrorHandler(s),o=this.createAckErrorHandler(s),c=()=>{try{a()}catch(e){r.reject(e)}},_=e=>{try{o(e)}catch(e){r.reject(e)}};this.channel.addEventListener("onerror",c),this.channel.addEventListener("onack",_),i.push((()=>this.channel.removeEventListener("onerror",c))),i.push((()=>this.channel.removeEventListener("onack",_)));const l=this.createMessageSuccessHandler(e);this.preSendLocalMessageEventsManager.on(St.MESSAGE_SEND_SUCCESS,l),i.push((()=>this.preSendLocalMessageEventsManager.off(St.MESSAGE_SEND_SUCCESS,l)));const h=this.createMessageFailedHandler(s,r.reject);this.preSendLocalMessageEventsManager.on(St.MESSAGE_SEND_AND_RECEIVE_ERROR,h),i.push((()=>this.preSendLocalMessageEventsManager.off(St.MESSAGE_SEND_AND_RECEIVE_ERROR,h)))}setupTimeoutHandler(e,t,s){return setTimeout((()=>{Dt([this,"access",e=>e.reportEventsTracer,"optionalAccess",e=>e.sendMessageTracer,"access",e=>e.timeout,"call",t=>t(e)]);const t=new bt("send chat message timeout",{local_msg_id:e});this.preSendLocalMessageEventsManager.emit(St.MESSAGE_SEND_TIMEOUT,t),s(t)}),t)}createMessageSuccessHandler(e){const{localMsgId:t,message:s,promiseHandlers:i}=e;return e=>{const r=Dt([e,"access",e=>e.content,"access",e=>e.message_start,"optionalAccess",e=>e.local_msg_id]),n=Dt([e,"access",e=>e.content,"access",e=>e.message_start,"optionalAccess",e=>e.msg_id]);if(r!==t)return;this.completeMessageTracing(t,{logId:e.log_id});const a={...s,msg_id:jt(n,(()=>"")),role:"user"};i.resolve({message:a,status:"message_start"})}}createMessageFailedHandler(e,t){return s=>{s.ext.local_msg_id===e&&(this.traceMessageError(e,s),t(s))}}handleChatSendError(e,t,s){const i=new bt(`Error: channel send chat message error: ${String(e)}`,{local_msg_id:t});this.traceMessageError(t,i),s(e)}async sendMessageWithChannel(e,t){try{await this.ensureChannelReadyAndSend(e)}catch(e){const s=new bt((e=>e instanceof Error?e.message:"object"==typeof e?JSON.stringify(e):String(e))(e),{local_msg_id:t});throw this.traceMessageError(t,s),s}}async ensureChannelReadyAndSend(e){return this.channel.isChannelOpenPromise?await this.channel.isChannelOpenPromise:this.channel.isChannelOpen()||await this.channel.connect(),await this.channel.send(e)}}function qt(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}var wt,Ft,xt,Wt,Ht,Kt,Vt,$t,zt,Qt,Jt,Yt,Zt,Xt,es,ts,ss,is,rs,ns,as,os,cs,_s,ls,hs,us,ps,ds,gs,Ts,Es,ms,fs,Ls,As,Ss,Rs;!function(e){e.SDK_INIT="chat_sdk_init";e.SDK_MESSAGE_UPLOAD_FAIL="chat_sdk_message_upload_fail";e.SDK_BREAK_MESSAGE="chat_sdk_break_message";e.SDK_MESSAGE_SEND_TRACER="chat_sdk_message_send_tracer";e.SDK_PULL_STREAM_TRACER="chat_sdk_pull_stream_tracer"}(wt||(wt={}));class Cs{__init(){this.eventTracers=new Map}constructor(e){Cs.prototype.__init.call(this),Cs.prototype.__init2.call(this),Cs.prototype.__init3.call(this),this.reporter=e}__init2(){this.sendMessageTracer={start:(e,t)=>{const{trace:s}=this.createTracer(wt.SDK_MESSAGE_SEND_TRACER);this.setTracer(e,wt.SDK_MESSAGE_SEND_TRACER,{trace:s}),qt([s,"optionalCall",e=>e("start",{meta:t})])},success:(e,t)=>{const{trace:s}=this.getTracer(e,wt.SDK_MESSAGE_SEND_TRACER);qt([s,"optionalCall",e=>e("success",{meta:t})]),this.deleteTracer(e,wt.SDK_MESSAGE_SEND_TRACER),this.pullStreamTracer.start(e,t)},inqueue:(e,t)=>{const{trace:s}=this.getTracer(e,wt.SDK_MESSAGE_SEND_TRACER);qt([s,"optionalCall",e=>e("inqueue",{meta:t})]),this.deleteTracer(e,wt.SDK_MESSAGE_SEND_TRACER)},error:e=>{const{local_msg_id:t}=e.ext;if(!t)return;const{trace:s}=this.getTracer(t,wt.SDK_MESSAGE_SEND_TRACER);qt([s,"optionalCall",t=>t("error",{meta:e.flatten(),error:e})]),this.deleteTracer(t,wt.SDK_MESSAGE_SEND_TRACER)},timeout:e=>{const{trace:t}=this.getTracer(e,wt.SDK_MESSAGE_SEND_TRACER);qt([t,"optionalCall",e=>e("timeout")]),this.deleteTracer(e,wt.SDK_MESSAGE_SEND_TRACER)}}}__init3(){this.pullStreamTracer={start:(e,t)=>{const{trace:s}=this.createTracer(wt.SDK_PULL_STREAM_TRACER);this.setTracer(e,wt.SDK_PULL_STREAM_TRACER,{trace:s,meta:t}),qt([s,"optionalCall",e=>e("start",{meta:t})])},success:(e,t)=>{const{trace:s}=this.getTracer(e,wt.SDK_PULL_STREAM_TRACER);qt([s,"optionalCall",e=>e("success",{meta:t})]),this.deleteTracer(e,wt.SDK_PULL_STREAM_TRACER)},break:(e,t)=>{const{trace:s}=this.getTracer(e,wt.SDK_PULL_STREAM_TRACER);qt([s,"optionalCall",e=>e("success",{meta:t})]),this.deleteTracer(e,wt.SDK_PULL_STREAM_TRACER)},error:(e,t)=>{const{query_msg_id:s}=e.ext;if(!s)return;const{trace:i}=this.getTracer(s,wt.SDK_PULL_STREAM_TRACER);qt([i,"optionalCall",s=>s("error",{meta:{...e.flatten(),...t},error:e})]),this.deleteTracer(s,wt.SDK_PULL_STREAM_TRACER)},timeout:e=>{const{query_msg_id:t}=e.ext;if(!t)return;const{trace:s}=this.getTracer(t,wt.SDK_PULL_STREAM_TRACER);qt([s,"optionalCall",t=>t("timeout",{meta:e.flatten(),error:e})]),this.deleteTracer(t,wt.SDK_PULL_STREAM_TRACER)},receiveFirstAnsChunk:(e,t)=>{const{trace:s}=this.getTracer(e,wt.SDK_PULL_STREAM_TRACER);qt([s,"optionalCall",e=>e("first_ans_chunk",{meta:t})])}}}static getUniqueKey(e,t){return`${e}_${t}`}getTracer(e,t){return this.eventTracers.get(Cs.getUniqueKey(e,t))||{trace:void 0}}setTracer(e,t,s){const{trace:i,meta:r}=s;this.eventTracers.set(Cs.getUniqueKey(e,t),{trace:i,meta:r})}deleteTracer(e,t){this.eventTracers.delete(Cs.getUniqueKey(e,t))}createTracer(e){return this.reporter.slardarTracer({eventName:e})}}class vs{static __initStatic(){this.instances=new Map}static __initStatic2(){this.EVENTS=Lt}__init(){this.enableDebug=!1}__init2(){this.eventBus=e()}constructor(e){vs.prototype.__init.call(this),vs.prototype.__init2.call(this),vs.prototype.__init3.call(this),vs.prototype.__init4.call(this),vs.prototype.__init5.call(this),vs.prototype.__init6.call(this),vs.prototype.__init7.call(this),vs.prototype.__init8.call(this),vs.prototype.__init9.call(this),vs.prototype.__init10.call(this);const{enableDebug:t,logLevel:s,env:i,key:r}=e;this.key=r,this.enableDebug=Boolean(t),this.logLevel=s||"error",this.env=i,this.reportLog=e.reportLog,this.reportLog.init(),this.reportLogWithScope=this.reportLog.createLoggerWith({scope:"chat-sdk",meta:{key:r}}),this.reportEventsTracer=new Cs(this.reportLogWithScope),this.requestManager=new Be({options:e.requestManagerOptions,reportLog:this.reportLog}),this.preSendLocalMessageEventsManager=new ke,this.preSendLocalMessageFactory=new je,this.chunkProcessor=new ft({getEnableDebug:()=>this.enableDebug,initMessageBuffer:e.initMessageBuffer,initMaxSequenceId:e.initMaxSequenceId,enableChunkProcessedCheck:e.enableChunkProcessedCheck,reportLogWithScope:this.reportLogWithScope,key:r}),this.channel=e.channel,this.createMessageService=new le,this.sendMessageService=new Gt({preSendLocalMessageFactory:this.preSendLocalMessageFactory,channel:this.channel,preSendLocalMessageEventsManager:this.preSendLocalMessageEventsManager,reportLogWithScope:this.reportLogWithScope,reportEventsTracer:this.reportEventsTracer,chatSdkEventEmit:this.emit}),this.websocketService=new kt({channel:this.channel,reportLogWithScope:this.reportLogWithScope,chunkProcessor:this.chunkProcessor,preSendLocalMessageEventsManager:this.preSendLocalMessageEventsManager,chatSdkEventEmit:this.emit,chatSdkEventBus:this.eventBus,reportEventsTracer:this.reportEventsTracer,manualInitChannel:Boolean(e.manualInitChannel),enableBuffer:Boolean(e.enableBuffer)}),this.onEvents(),this.reportLogWithScope.slardarEvent({eventName:wt.SDK_INIT,meta:{...e}}),this.reportLogWithScope.info({message:"SDK 初始化完成"})}static create(e){const{key:t}=e;if(vs.instances.has(t))return console.error("duplicate chat core instance error"),vs.instances.get(t);const s=new vs(e);return vs.instances.set(t,s),s}onEvents(){this.websocketService.onChannelEvents()}destroy(){this.websocketService.destroy(),this.eventBus.all.clear(),this.chunkProcessor.destroy(),vs.instances.delete(this.key),this.preSendLocalMessageEventsManager.destroy(),this.reportLogWithScope.info({message:"SDK销毁"})}__init3(){this.on=(e,t,s)=>(this.eventBus.all.has(e)&&!s&&this.reportLogWithScope.slardarError({message:"重复监听事件",error:new Error("重复监听"),meta:{event:e}}),this.eventBus.on(e,t),()=>{this.eventBus.off(e,t)})}__init4(){this.off=(e,t)=>{this.eventBus.off(e,t)}}__init5(){this.emit=(e,t)=>{this.eventBus.emit(e,t)}}createQueryMessage(...e){return this.createMessageService.createQueryMessage(...e)}createRetryMessage(...e){return this.createMessageService.createRetryMessage(...e)}createEditMessage(...e){return this.createMessageService.createEditMessage(...e)}createInterruptMessage(...e){return this.createMessageService.createInputMessage(...e)}createCancelMessage(...e){return this.createMessageService.createCancelMessage(...e)}sendChatMessage(e,t){return this.sendMessageService.sendChatMessage(e,t)}sendCommandMessage(e){return this.sendMessageService.sendCommandMessage(e)}__init6(){this.getHistoryMessage=(...e)=>this.requestManager.getSceneConfig(c.GetMessage)(...e)}__init7(){this.isChannelOpen=()=>this.channel.isChannelOpenPromise?"connecting":this.channel.isChannelOpen()?"connected":"disconnected"}__init8(){this.initChannel=()=>this.websocketService.initChannel()}__init9(){this.captureStreamBuffer=()=>this.chunkProcessor.getStreamBufferWithMeta()}__init10(){this.captureStreamBufferSnapshot=()=>this.chunkProcessor.getStreamBufferSnapshot()}}function Is(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}vs.__initStatic(),vs.__initStatic2(),function(e){e.ASRMessageTypeAudio="audio";e.ASRMessageTypeConfig="config";e.ASRMessageTypeStop="stop"}(Ft||(Ft={})),function(e){e[e.Unknown=0]="Unknown";e[e.Organization=1]="Organization";e[e.Personal=2]="Personal"}(xt||(xt={})),function(e){e.ASRServerMessageTypeError="asr_error";e.ASRServerMessageTypeResult="asr_result"}(Wt||(Wt={})),function(e){e[e.develop=0]="develop";e[e.product=1]="product"}(Ht||(Ht={})),function(e){e[e.Agent=1]="Agent";e[e.Automation=2]="Automation";e[e.WebApp=3]="WebApp";e[e.App=4]="App";e[e.Skill=5]="Skill";e[e.GeneralWeb=6]="GeneralWeb";e[e.WechatMiniProgram=7]="WechatMiniProgram";e[e.AssistantAgent=8]="AssistantAgent"}(Kt||(Kt={})),function(e){e[e.restoring=0]="restoring";e[e.success=1]="success";e[e.failed=2]="failed"}(Vt||(Vt={})),function(e){e[e.active=0]="active";e[e.creating=1]="creating"}($t||($t={})),function(e){e[e.postgre=0]="postgre";e[e.supabase=1]="supabase"}(zt||(zt={})),function(e){e[e.SQL=1]="SQL";e[e.REPORT=2]="REPORT";e[e.LOG_SQL=3]="LOG_SQL"}(Qt||(Qt={})),function(e){e[e.NAME=1]="NAME";e[e.INSERTED_AT=2]="INSERTED_AT"}(Jt||(Jt={})),function(e){e[e.ASC=1]="ASC";e[e.DESC=2]="DESC"}(Yt||(Yt={})),function(e){e[e.USER=1]="USER";e[e.PROJECT=2]="PROJECT";e[e.ORG=3]="ORG";e[e.PUBLIC=4]="PUBLIC"}(Zt||(Zt={})),function(e){e[e.AddAttributes=1]="AddAttributes";e[e.RemoveAttributes=2]="RemoveAttributes"}(Xt||(Xt={})),function(e){e[e.CloseConnection=1]="CloseConnection"}(es||(es={})),function(e){e[e.ON_LINE=0]="ON_LINE";e[e.OFF_LINE=1]="OFF_LINE";e[e.TOUCH=2]="TOUCH"}(ts||(ts={})),function(e){e[e.AddGroups=1]="AddGroups";e[e.RemoveGroups=2]="RemoveGroups";e[e.ReplaceWithGroups=3]="ReplaceWithGroups"}(ss||(ss={})),function(e){e[e.App=0]="App";e[e.Service=1]="Service";e[e.Method=2]="Method"}(is||(is={})),function(e){e.FileBatchDelete="file.batch_delete";e.FileBatchMove="file.batch_move";e.FileChanged="file.changed";e.FileCreate="file.create";e.FileDelete="file.delete";e.FileExist="file.exist";e.FileGrep="file.grep";e.FileList="file.list";e.FileMove="file.move";e.FilePack="file.pack";e.FilePatch="file.patch";e.FileRead="file.read";e.FileReplace="file.replace";e.FileSearch="file.search";e.FileStat="file.stat";e.FileWrite="file.write";e.GetAppLog="log.get_app_log";e.GetCurrentCanvas="canvas.get_current";e.GetExecuteLog="test.get_execute_log";e.GetInOutSchema="canvas.get_inout_schema";e.GetSourceCode="canvas.get_source_code";e.LspCompletion="lsp.completion";e.LspCompletionItemResolve="lsp.completionItemResolve";e.LspDefinition="lsp.definition";e.LspDidChange="lsp.didChange";e.LspDidClose="lsp.didClose";e.LspDidOpen="lsp.didOpen";e.LspGetDiagnosticsCli="lsp.getDiagnosticsCli";e.LspHover="lsp.hover";e.LspOnNotification="lsp.onNotification";e.LspReferences="lsp.references";e.LspRestart="lsp.restart";e.LspSignatureHelp="lsp.signatureHelp";e.NodeDebug="node.debug";e.PageRouterGetPage="page_router.get_routes";e.PreviewReload="preview.reload";e.RepoCommitCreate="repo_version.commit.create";e.RepoCommitFileDiff="repo_version.commit.file.diff";e.RepoCommitFileRead="repo_version.commit.file.read";e.RepoCommitList="repo_version.commit.list";e.RepoCommitRetrieve="repo_version.commit.retrieve";e.RepoCommitSearch="repo_version.commit.search";e.RepoCommitStatus="repo_version.commit.status";e.RepoCommitVersionDiff="repo_version.commit.diff";e.RepoCommitVersions="repo_version.commit.versions";e.RepoVersionCodeStage="repo_version.commit.stage";e.RepoVersionCodeUnstage="repo_version.commit.restore";e.RepoVersionConflictResolve="repo_version.conflict.resolve";e.RepoVersionEvent="repo_version.event";e.RepoVersionFileRead="repo_version.file.read";e.RepoVersionLatest="repo_version.commit.version.latest";e.RepoVersionNotify="repo_version.notify";e.RepoVersionRemoteAdd="repo_version.remote.add";e.RepoVersionRemoteFetch="repo_version.remote.fetch";e.RepoVersionRemoteOutgoingCommits="repo_version.remote.outgoing_commits";e.RepoVersionRemotePull="repo_version.remote.pull";e.RepoVersionRemotePush="repo_version.remote.push";e.RepoVersionRemoteRemove="repo_version.remote.remove";e.SandboxBroadcast="sandbox.broadcast";e.SandboxPing="sandbox.ping";e.SandboxProjectStatus="sandbox.project_status";e.SandboxProjectStatusNotify="sandbox.project_status_notify";e.SandboxVersion="sandbox.version";e.ShellClose="shell.close";e.ShellCreate="shell.create";e.ShellExecute="shell.execute";e.ShellExited="shell.exited";e.ShellInput="shell.input";e.ShellOutput="shell.output";e.ShellResize="shell.resize";e.TestRun="test.run";e.TestValidate="test.validate";e.WebIsServerStart="web.is_server_start";e.WebStartServer="web.start_server"}(rs||(rs={})),function(e){e[e.text=0]="text";e[e.url=1]="url";e[e.uri=2]="uri"}(ns||(ns={})),(as||(as={})).PdfTargetFileType="pdf",function(e){e.TabAuthentication="Authentication"}(os||(os={})),function(e){e.FeatureApp="app";e.FeatureAssistantAgent="assistantagent";e.FeatureGeneral="general";e.FeatureSkill="skill";e.FeatureWechatMiniProgram="wechatminiprogram"}(cs||(cs={})),function(e){e.ScenePredefinedQuery="PredefinedQuery";e.SceneRecommendProjectCases="RecommendProjectCases";e.SceneSubmitWorkPoint="SubmitWorkPoint"}(_s||(_s={})),function(e){e[e.CozeSpace=1]="CozeSpace";e[e.Ark=2]="Ark"}(ls||(ls={})),function(e){e[e.LocalFile=1]="LocalFile";e[e.GithubRepo=2]="GithubRepo"}(hs||(hs={})),function(e){e.ProjectTypeAgent="Agent";e.ProjectTypeApp="App";e.ProjectTypeAssistantAgent="AssistantAgent";e.ProjectTypeAutomation="Automation";e.ProjectTypeGeneral="General";e.ProjectTypeGeneralWeb="GeneralWeb";e.ProjectTypeSkill="Skill";e.ProjectTypeWechatMiniProgram="WechatMiniProgram"}(us||(us={})),function(e){e[e.Confirming=1]="Confirming";e[e.Joined=2]="Joined";e[e.Rejected=3]="Rejected";e[e.Expired=4]="Expired"}(ps||(ps={})),function(e){e[e.Agent=0]="Agent";e[e.Ask=1]="Ask";e[e.DangerousConfirm=2]="DangerousConfirm";e[e.Plan=4]="Plan"}(ds||(ds={})),function(e){e.ProjectSymbolVersion3="v3"}(gs||(gs={})),function(e){e[e.Web=1]="Web";e[e.Mobile=2]="Mobile"}(Ts||(Ts={})),function(e){e[e.Default=0]="Default";e[e.Collaborator=1]="Collaborator"}(Es||(Es={})),exports.VibeProjectType=void 0,function(e){e[e.Agent=1]="Agent";e[e.Automation=2]="Automation";e[e.WebApp=3]="WebApp";e[e.App=4]="App";e[e.Skill=5]="Skill";e[e.GeneralWeb=6]="GeneralWeb";e[e.WechatMiniProgram=7]="WechatMiniProgram";e[e.AssistantAgent=8]="AssistantAgent";e[e.General=9]="General";e[e.CLIBilling=101]="CLIBilling"}(exports.VibeProjectType||(exports.VibeProjectType={})),function(e){e[e.UnAuth=1]="UnAuth";e[e.AuthButNoBind=2]="AuthButNoBind";e[e.AuthAndBind=3]="AuthAndBind"}(ms||(ms={})),function(e){e[e.Inactive=1]="Inactive";e[e.Active=2]="Active"}(fs||(fs={})),function(e){e[e.Unknown=0]="Unknown";e[e.String=1]="String";e[e.Boolean=2]="Boolean";e[e.StringList=11]="StringList";e[e.BooleanList=12]="BooleanList"}(Ls||(Ls={})),function(e){e[e.Account=1]="Account";e[e.Workspace=2]="Workspace";e[e.VibeProject=38]="VibeProject";e[e.PostgresDatabase=39]="PostgresDatabase";e[e.Storage=40]="Storage"}(As||(As={})),function(e){e.PdfTargetFileType="pdf";e.XlsxTargetFileType="xlsx"}(Ss||(Ss={})),function(e){e[e.move=0]="move";e[e.copy=1]="copy"}(Rs||(Rs={}));class ys{__init(){this.request=s.request}__init2(){this.baseURL=""}constructor(e){ys.prototype.__init.call(this),ys.prototype.__init2.call(this),this.request=Is([e,"optionalAccess",e=>e.request])||this.request,this.baseURL=Is([e,"optionalAccess",e=>e.baseURL])||this.baseURL}genBaseURL(e){return"string"==typeof this.baseURL?this.baseURL+e:this.baseURL(e)}GetVibeGlobalSettings(e,t){const s=this.genBaseURL("/api/ideserver_api/project/get_vibe_global_settings");return this.request({url:s,method:"POST"},t)}UpdateVibeGlobalSettings(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/update_vibe_global_settings"),r={global_settings:s.global_settings};return this.request({url:i,method:"POST",data:r},t)}GetVibeProjectCases(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_vibe_project_cases"),r={project_type:s.project_type};return this.request({url:i,method:"POST",data:r},t)}UpdateVibeProject(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/update_vibe_project"),r={project_id:s.project_id,name:s.name,description:s.description,icon_uri:s.icon_uri,project_settings:s.project_settings};return this.request({url:i,method:"POST",data:r},t)}CopyVibeProject(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/copy_vibe_project"),r={project_id:s.project_id,name:s.name,description:s.description,icon_uri:s.icon_uri,icon_url:s.icon_url,target_space_id:s.target_space_id};return this.request({url:i,method:"POST",data:r},t)}ChatCreateVibeProject(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/create_vibe_project"),r={space_id:s.space_id,user_query:s.user_query,project_type:s.project_type,agent_tools:s.agent_tools,project_settings:s.project_settings};return this.request({url:i,method:"POST",data:r},t)}UploadFile(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/upload_file"),r={data:s.data},n={"Content-Type":s["Content-Type"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetVibeProject(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/get_vibe_project"),r={project_id:s.project_id,project_symbol:s.project_symbol};return this.request({url:i,method:"POST",data:r},t)}CreatePostgresqlDatabase(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/postgresql"),r={project_id:s.project_id,user_id:s.user_id,space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}CreateStorageBucket(e,t){const s=e,i=this.genBaseURL("/api/memory/storage/create"),r={project_id:s.project_id,user_id:s.user_id,bucket_name:s.bucket_name,space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}ListStorageBucket(e,t){const s=e||{},i=this.genBaseURL("/api/memory/storage/list"),r={project_id:s.project_id,bucket_ids:s.bucket_ids,env:s.env};return this.request({url:i,method:"POST",data:r},t)}ListPostgresqlDatabase(e,t){const s=e||{},i=this.genBaseURL("/api/memory/databases/postgresql/list"),r={project_id:s.project_id,database_ids:s.database_ids,env:s.env};return this.request({url:i,method:"POST",data:r},t)}RestorePostgresqlDatabase(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/postgresql/restore"),r={project_id:s.project_id,database_ids:s.database_ids,env:s.env,timestamp:s.timestamp};return this.request({url:i,method:"POST",data:r},t)}DeleteStorageBucket(e,t){const s=e||{},i=this.genBaseURL("/api/memory/storage/delete"),r={project_id:s.project_id,bucket_ids:s.bucket_ids};return this.request({url:i,method:"POST",data:r},t)}DeletePostgresqlDatabase(e,t){const s=e||{},i=this.genBaseURL("/api/memory/databases/postgresql/delete"),r={project_id:s.project_id,database_ids:s.database_ids};return this.request({url:i,method:"POST",data:r},t)}CheckRestorePossibility(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/postgresql/restore/check"),r={project_id:s.project_id,database_ids:s.database_ids,env:s.env,timestamp:s.timestamp};return this.request({url:i,method:"POST",data:r},t)}CreateStorageFolder(e,t){const s=e,i=this.genBaseURL(`/api/memory/storage/${s.bucket_id}/folder/create`),r={folder_name:s.folder_name};return this.request({url:i,method:"POST",data:r},t)}GetFileURL(e,t){const s=e,i=this.genBaseURL(`/api/memory/storage/${s.bucket_id}/file/get_url`),r={uri_list:s.uri_list,expired_time:s.expired_time};return this.request({url:i,method:"POST",data:r},t)}StorageFileMigrate(e,t){const s=e,i=this.genBaseURL(`/api/memory/storage/${s.bucket_id}/file/migrate`),r={folder_name_list:s.folder_name_list,obj_name_list:s.obj_name_list,target_folder:s.target_folder,action:s.action};return this.request({url:i,method:"POST",data:r},t)}UploadStorageFile(e,t){const s=e,i=this.genBaseURL(`/api/memory/storage/${s.bucket_id}/file/upload`),r={body:s.body},n={"Content-Type":s["Content-Type"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}StorageFileRename(e,t){const s=e,i=this.genBaseURL(`/api/memory/storage/${s.bucket_id}/file/rename`),r={rename_list:s.rename_list};return this.request({url:i,method:"POST",data:r},t)}DeleteStorageFile(e,t){const s=e,i=this.genBaseURL(`/api/memory/storage/${s.bucket_id}/file/delete`),r={folder_name_list:s.folder_name_list,obj_name_list:s.obj_name_list};return this.request({url:i,method:"POST",data:r},t)}ListStorageObjects(e,t){const s=e,i=this.genBaseURL(`/api/memory/storage/${s.bucket_id}/file/list`),r={prefix:s.prefix,page_size:s.page_size,page_token:s.page_token,search_key:s.search_key};return this.request({url:i,method:"POST",data:r},t)}CreateContent(e,t){const s=e||{},i=this.genBaseURL(`/api/memory/databases/${s.database_id}/content`),r={id:s.id,name:s.name,type:s.type,visibility:s.visibility,description:s.description,favorite:s.favorite,folder_id:s.folder_id,owner_id:s.owner_id,content_json:s.content_json};return this.request({url:i,method:"POST",data:r},t)}UpdateWholeContent(e,t){const s=e||{},i=this.genBaseURL(`/api/memory/databases/${s.database_id}/content`),r={id:s.id,name:s.name,type:s.type,visibility:s.visibility,description:s.description,favorite:s.favorite,folder_id:s.folder_id,owner_id:s.owner_id,content_json:s.content_json};return this.request({url:i,method:"PUT",data:r},t)}DeleteContents(e,t){const s=e||{},i=this.genBaseURL(`/api/memory/databases/${s.database_id}/content`),r={ids:s.ids};return this.request({url:i,method:"DELETE",data:r},t)}GetContentById(e,t){const s=e||{},i=this.genBaseURL(`/api/memory/databases/${s.database_id}/content/${s.item_id}`);return this.request({url:i,method:"GET"},t)}GetContent(e,t){const s=e||{},i=this.genBaseURL(`/api/memory/databases/${s.database_id}/content`),r={cursor:s.cursor,favorite:s.favorite,limit:s.limit,name:s.name,sort_by:s.sort_by,sort_order:s.sort_order,type:s.type,visibility:s.visibility};return this.request({url:i,method:"GET",params:r},t)}UploadProjectFile(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/sandbox/file/upload"),r={body:s.body},n={"Content-Type":s["Content-Type"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}InitSandbox(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/sandbox/init_sandbox"),r={project_id:s.project_id,source:s.source},n={"x-devbox-cli-env":s["x-devbox-cli-env"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetProjectFileUrl(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/sandbox/file/get_url"),r={file_path:s.file_path,project_id:s.project_id};return this.request({url:i,method:"GET",params:r},t)}UpdateRestoreRetention(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/postgresql/restore/retention"),r={database_id:s.database_id,retention_hours:s.retention_hours};return this.request({url:i,method:"POST",data:r},t)}RestoreRepoVersion(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/repository/restore"),r={ProjectID:s.ProjectID,CommitID:s.CommitID,NoConfirm:s.NoConfirm,ConfirmInfos:s.ConfirmInfos,ConversationID:s.ConversationID};return this.request({url:i,method:"POST",data:r},t)}RefreshVibeProjectCases(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/refresh_vibe_project_cases"),r={refresh_token:s.refresh_token};return this.request({url:i,method:"POST",data:r},t)}GetUserQueryForCreate(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_user_query_for_create"),r={query_id:s.query_id,scene:s.scene},n={Cookie:s.Cookie};return this.request({url:i,method:"POST",data:r,headers:n},t)}DeleteVibeProject(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/delete_vibe_project"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}CheckUserFeature(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/check_user_feature"),r={feature_keys:s.feature_keys};return this.request({url:i,method:"POST",data:r},t)}UpsertVibeProjectShare(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/upsert_share_info"),r={project_id:s.project_id,is_public_share:s.is_public_share,relative_expired_time:s.relative_expired_time};return this.request({url:i,method:"POST",data:r},t)}GetVibeProjectShare(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_share_info"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}GetProtectSchemaList(e,t){const s=this.genBaseURL("/api/memory/databases/postgresql/get_protect_schema");return this.request({url:s,method:"POST"},t)}BatchImportData(e,t){const s=e,i=this.genBaseURL("/v1/knowledge_base/batch_import"),r={dataset:s.dataset,data:s.data,chunk_config:s.chunk_config},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetSchemaTables(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/postgresql/get_schema_tables"),r={project_id:s.project_id,database_env:s.database_env,schema:s.schema};return this.request({url:i,method:"POST",data:r},t)}ConvertFile(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/sandbox/file/convert"),r={file_path:s.file_path,project_id:s.project_id,target_file_type:s.target_file_type};return this.request({url:i,method:"GET",params:r},t)}GetDatabaseSupportVector(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/postgresql/get_support_vector"),r={database_id:s.database_id};return this.request({url:i,method:"POST",data:r},t)}RecallData(e,t){const s=e,i=this.genBaseURL("/v1/knowledge_base/recall"),r={dataset:s.dataset,query:s.query,top_k:s.top_k,min_score:s.min_score},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetFileInterfaceConfig(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/sandbox/file/get_interface_config"),r={project_id:s.project_id};return this.request({url:i,method:"GET",params:r},t)}UpsertProjectCopyType(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/upsert_copy_type"),r={project_id:s.project_id,enable_cross_space_copy:s.enable_cross_space_copy};return this.request({url:i,method:"POST",data:r},t)}OpenGetVibeProjectInfo(e,t){const s=e||{},i=this.genBaseURL(`/v1/vibe_projects/${s.project_id}`);return this.request({url:i,method:"GET"},t)}ImportSpaceDevAgent(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/import_space_dev_agent"),r={task_id:s.task_id,space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}CreateCommit(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/repository/create_commit"),r={ProjectID:s.ProjectID,message:s.message};return this.request({url:i,method:"POST",data:r},t)}ListBuckets(e,t){const s=e,i=this.genBaseURL("/v1/supabase/buckets/list"),r={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",headers:r},t)}DeleteBucket(e,t){const s=e,i=this.genBaseURL("/v1/supabase/buckets/delete"),r={bucket_id:s.bucket_id},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetEdgeFunction(e,t){const s=e,i=this.genBaseURL("/v1/supabase/functions/get"),r={slug:s.slug},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}DeleteEdgeFunction(e,t){const s=e,i=this.genBaseURL("/v1/supabase/functions/delete"),r={slug:s.slug},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}ListEdgeFunctions(e,t){const s=e,i=this.genBaseURL("/v1/supabase/functions/list"),r={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",headers:r},t)}UpdateAuthConfig(e,t){const s=e,i=this.genBaseURL("/v1/supabase/auth/config/update"),r={config:s.config},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetBucket(e,t){const s=e,i=this.genBaseURL("/v1/supabase/buckets/get"),r={bucket_id:s.bucket_id},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetAuthConfig(e,t){const s=e,i=this.genBaseURL("/v1/supabase/auth/config/get"),r={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",headers:r},t)}UpdateBucket(e,t){const s=e,i=this.genBaseURL("/v1/supabase/buckets/update"),r={bucket_id:s.bucket_id,public:s.public,file_size_limit:s.file_size_limit,allowed_mime_types:s.allowed_mime_types},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}DeployEdgeFunction(e,t){const s=e,i=this.genBaseURL("/v1/supabase/functions/deploy"),r={slug:s.slug,code:s.code,files:s.files,name:s.name,entrypoint:s.entrypoint,verify_jwt:s.verify_jwt},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}CreateBucket(e,t){const s=e,i=this.genBaseURL("/v1/supabase/buckets/create"),r={bucket_id:s.bucket_id,name:s.name,public:s.public,file_size_limit:s.file_size_limit,allowed_mime_types:s.allowed_mime_types},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}OpenConvertFile(e,t){const s=e||{},i=this.genBaseURL("/v1/vibe_projects/files/convert"),r={project_id:s.project_id,file_url:s.file_url,target_file_type:s.target_file_type};return this.request({url:i,method:"POST",data:r},t)}OpenUploadFile(e,t){const s=e||{},i=this.genBaseURL("/v1/vibe_projects/files/upload"),r={body:s.body},n={"Content-Type":s["Content-Type"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetUserAssistantAttrs(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_user_assistant_attrs"),r={space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}GetProjectArtifactShare(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_artifact_share"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}UpsertProjectArtifactShare(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/upsert_artifact_share"),r={project_id:s.project_id,is_artifact_share:s.is_artifact_share,relative_expired_time:s.relative_expired_time};return this.request({url:i,method:"POST",data:r},t)}GetUserProjectNum(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_user_project_num"),r={enterprise_id:s.enterprise_id,organization_id:s.organization_id};return this.request({url:i,method:"POST",data:r},t)}GetLarkTableContent(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_content"),r={scene:s.scene};return this.request({url:i,method:"POST",data:r},t)}GetProjectStatus(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/sandbox/project_status"),r={project_id:s.project_id};return this.request({url:i,method:"GET",params:r},t)}UpdateProjectSkillSetting(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/update_project_skill_setting"),r={project_id:s.project_id,add_skills:s.add_skills,remove_skills:s.remove_skills};return this.request({url:i,method:"POST",data:r},t)}ProxySandboxMessage(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/repository/proxy_sandbox_message"),r={ProjectID:s.ProjectID,Method:s.Method,Params:s.Params};return this.request({url:i,method:"POST",data:r},t)}GetOauthStatus(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/oauth/status"),r={integration_id:s.integration_id,space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}SearchRepo(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/search_repo"),r={space_id:s.space_id,name_search:s.name_search,per_page:s.per_page,page:s.page};return this.request({url:i,method:"POST",data:r},t)}AddRemote(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/add_remote"),r={project_id:s.project_id,integration_id:s.integration_id,repo_full_name:s.repo_full_name,has_add_in_devbox:s.has_add_in_devbox};return this.request({url:i,method:"POST",data:r},t)}RemoveRemote(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/remove_remote"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}ListIntegration(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/list"),r={space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}CreateRepo(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/create_repo"),r={space_id:s.space_id,name:s.name,private:s.private};return this.request({url:i,method:"POST",data:r},t)}CancelOauth(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/oauth/cancel"),r={integration_id:s.integration_id,space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}GetOauthConfig(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/oauth/oauth_config"),r={integration_id:s.integration_id,space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}ListDatabaseRestoreHistory(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/postgresql/restore/history"),r={project_id:s.project_id,commit_id:s.commit_id,env:s.env,limit:s.limit,cursor:s.cursor};return this.request({url:i,method:"POST",data:r},t)}ImportProject(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/import_project"),r={space_id:s.space_id,import_source:s.import_source,data:s.data,git_url:s.git_url,git_repo_name:s.git_repo_name,project_symbol:s.project_symbol},n={"Content-Type":s["Content-Type"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetUser(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/user"),r={space_id:s.space_id,integration_id:s.integration_id};return this.request({url:i,method:"POST",data:r},t)}GetRemote(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/repository/integration/get_remote"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}DiagnoseDatabaseHTTP(e,t){const s=e,i=this.genBaseURL("/v1/supabase/database/diagnose"),r={env:s.env},n={"x-coze-token":s["x-coze-token"]};return this.request({url:i,method:"POST",data:r,headers:n},t)}GetProjectDisplayTabInfo(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_display_tab_info"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}GetOrCreateBillingProject(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/get_or_create_billing_project"),r={space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}UpdatePermissionSetting(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/update_permission_setting"),r={project_id:s.project_id,add_commands:s.add_commands,remove_commands:s.remove_commands};return this.request({url:i,method:"POST",data:r},t)}OptimizeQuery(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/optimize_query"),r={query:s.query,project_type:s.project_type};return this.request({url:i,method:"POST",data:r},t)}CreateSpaceDatabase(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/space/create"),r={space_id:s.space_id};return this.request({url:i,method:"POST",data:r},t)}GetSpaceDatabase(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/space/get"),r={space_id:s.space_id,database_id:s.database_id};return this.request({url:i,method:"POST",data:r},t)}ListSpaceDatabase(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/space/list"),r={space_id:s.space_id,cursor_id:s.cursor_id,limit:s.limit};return this.request({url:i,method:"POST",data:r},t)}GetSpaceDatabaseStatus(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/space/status"),r={space_id:s.space_id,database_id:s.database_id};return this.request({url:i,method:"POST",data:r},t)}DeleteSpaceDatabase(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/space/delete"),r={space_id:s.space_id,database_id:s.database_id};return this.request({url:i,method:"POST",data:r},t)}RollbackSpaceDatabase(e,t){const s=e,i=this.genBaseURL("/api/memory/databases/space/rollback"),r={space_id:s.space_id,database_id:s.database_id,timestamp:s.timestamp};return this.request({url:i,method:"POST",data:r},t)}GetVibeProjectMembers(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/get_members"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}SendNotice(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/send_notice"),r={project_id:s.project_id,notice_type:s.notice_type,uids:s.uids,variables:s.variables};return this.request({url:i,method:"POST",data:r},t)}UpdateProjectPinStatus(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/update_project_pin_status"),r={project_id:s.project_id,is_pin:s.is_pin};return this.request({url:i,method:"POST",data:r},t)}ImportProjectToSpace(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/import_project_to_space"),r={project_id:s.project_id};return this.request({url:i,method:"POST",data:r},t)}GetProjectListForSpace(e,t){const s=e,i=this.genBaseURL("/api/ideserver_api/project/get_project_list_for_space"),r={user_client:s.user_client,enterprise_id:s.enterprise_id,organization_id:s.organization_id,page_size:s.page_size,cursor:s.cursor,is_pinned:s.is_pinned,name:s.name,is_trigger_onboarding:s.is_trigger_onboarding};return this.request({url:i,method:"POST",data:r},t)}}ys.prototype.UploadProjectFile=function(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/sandbox/file/upload"),r=s.body;return this.request({url:i,method:"POST",data:r},t)},ys.prototype.UploadFile=function(e,t){const s=e||{},i=this.genBaseURL("/api/ideserver_api/project/upload_file"),r=s.data;return this.request({url:i,method:"POST",data:r},t)};const bs=new ys({});function Ms(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}const Ns=/(?<![\w`])@(\.?[^\s`,.]*(?:\.[^\s`,.]+)*)/g;class Us{constructor(){Us.prototype.__init.call(this),Us.prototype.__init2.call(this),Us.prototype.__init3.call(this),Us.prototype.__init4.call(this),Us.prototype.__init5.call(this),Us.prototype.__init6.call(this),Us.prototype.__init7.call(this),Us.prototype.__init8.call(this),Us.prototype.__init9.call(this),Us.prototype.__init10.call(this),Us.prototype.__init11.call(this),Us.prototype.__init12.call(this)}__init(){this.ctx={options:{},get:()=>({})}}__init2(){this.init=o.noop}__init3(){this.createLoggerWith=()=>new Us}__init4(){this.info=o.noop}__init5(){this.error=o.noop}__init6(){this.slardarInfo=o.noop}__init7(){this.slardarSuccess=o.noop}__init8(){this.slardarError=o.noop}__init9(){this.slardarEvent=o.noop}__init10(){this.slardarSuccessEvent=o.noop}__init11(){this.slardarErrorEvent=o.noop}__init12(){this.slardarTracer=()=>({trace:o.noop})}}function Os(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}const Ps=e=>{const{onData:t}=e,s=e.buffered.split(/\n\n/),i=(r=s.pop(),n=()=>"",null!=r?r:n());var r,n;for(const e of s){const s=e.split(/\r?\n/),i=[];for(const e of s)e.startsWith("data:")&&i.push(e.slice(5).trimStart());if(0===i.length)continue;const r=i.join("\n").trim();r&&"[DONE]"!==r&&t(r)}return{buffered:i}},Bs=async e=>{const{apiBaseUrl:t,request:i,onStart:r,onMessage:n,signal:a,totalTimeoutMs:o,onTotalTimeout:c,betweenChunkTimeoutMs:_,onBetweenChunkTimeout:l}=e,h=new AbortController;((e,t)=>{t&&(t.aborted?e.abort():t.addEventListener("abort",(()=>e.abort()),{once:!0}))})(h,a);const u=(e=>{const{controller:t,timeoutMs:s,onTimeout:i}=e;if(!s||s<=0)return()=>{};const r=setTimeout((()=>{Os([i,"optionalCall",e=>e()]),t.abort()}),s);return()=>clearTimeout(r)})({controller:h,timeoutMs:o,onTimeout:c}),p=(e=>{const{controller:t,timeoutMs:s,onTimeout:i}=e;if(!s||s<=0)return{refresh:()=>{},clear:()=>{}};let r=null;const n=()=>{r&&(clearTimeout(r),r=null)};return{refresh:()=>{n(),r=setTimeout((()=>{Os([i,"optionalCall",e=>e()]),t.abort()}),s)},clear:n}})({controller:h,timeoutMs:_,onTimeout:l});try{const e=new URL(`/v1/api/project/${i.project_id}/chat/message/send`,t),a=await s.customFetch.fetch(e.toString(),{method:"POST",signal:h.signal,body:JSON.stringify({message:i.message,device_id:i.device_id,project_id:i.project_id})});if(!a.ok)throw new Error(`ChatCLISendMessage failed: ${a.status} ${a.statusText}`);if(!a.body)throw new Error("ChatCLISendMessage response body is empty");await Os([r,"optionalCall",e=>e(a)]);const o=new TextDecoder("utf-8"),c=a.body.getReader();let _="";for(p.refresh();;){const{done:e,value:t}=await c.read();if(e)break;p.refresh(),_+=o.decode(t,{stream:!0});_=Ps({buffered:_,onData:e=>{const t=JSON.parse(e);n(t)}}).buffered}_+=o.decode(),Ps({buffered:_,onData:e=>{const t=JSON.parse(e);n(t)}})}catch(e){if((e=>!(!e||"object"!=typeof e)&&"AbortError"===e.name)(e))return;throw e}finally{u(),p.clear()}};function ks(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}class js extends Error{constructor(e,t){super(e),js.prototype.__init.call(this),this.name="ChatCLIChannelError",this.ext=t}__init(){this.flatten=()=>{const{message:e,ext:t}=this;return{message:e,...t}}}}const Ds=e=>!(!e||"object"!=typeof e)&&"AbortError"===e.name;class Gs{__init2(){this.channelName="ChatCLI"}__init3(){this.isChannelOpenPromise=null}__init4(){this.opened=!1}__init5(){this.destroyed=!1}__init6(){this.abortController=null}__init7(){this.eventBus=e()}constructor(e){Gs.prototype.__init2.call(this),Gs.prototype.__init3.call(this),Gs.prototype.__init4.call(this),Gs.prototype.__init5.call(this),Gs.prototype.__init6.call(this),Gs.prototype.__init7.call(this),Gs.prototype.__init8.call(this),Gs.prototype.__init9.call(this),Gs.prototype.__init10.call(this),Gs.prototype.__init11.call(this),Gs.prototype.__init12.call(this),Gs.prototype.__init13.call(this),Gs.prototype.__init14.call(this),Gs.prototype.__init15.call(this),Gs.prototype.__init16.call(this),this.apiBaseUrl=e.apiBaseUrl,this.deviceId=e.deviceId,this.totalTimeoutMs=e.totalTimeoutMs,this.betweenChunkTimeoutMs=e.betweenChunkTimeoutMs}__init8(){this.getChannelOptions=()=>({apiBaseUrl:this.apiBaseUrl})}__init9(){this.connect=async()=>{this.destroyed||(this.opened=!0,this.isChannelOpenPromise=Promise.resolve(),this.eventBus.emit("onopen",void 0))}}__init10(){this.reconnect=async()=>{await this.connect()}}__init11(){this.isChannelOpen=()=>this.opened}__init12(){this.addEventListener=(e,t)=>{this.eventBus.on(e,t)}}__init13(){this.removeEventListener=(e,t)=>{this.eventBus.off(e,t)}}__init14(){this.send=async e=>{if(this.destroyed)throw new Error("ChatCLIChannel is destroyed");this.opened||await this.connect(),ks([this,"access",e=>e.abortController,"optionalAccess",e=>e.abort,"call",e=>e()]);const t=new AbortController;this.abortController=t;const s=e,i={project_id:s.project_id,message:s,device_id:(r=this.deviceId,n=()=>{},null!=r?r:n())};var r,n;let a=!1,o=null;const c=new Promise((e=>{Bs({apiBaseUrl:this.apiBaseUrl,request:i,signal:t.signal,totalTimeoutMs:this.totalTimeoutMs,betweenChunkTimeoutMs:this.betweenChunkTimeoutMs,onTotalTimeout:()=>{this.eventBus.emit("onerror",new js("ChatCLISendMessage total timeout",{willClose:!0}))},onBetweenChunkTimeout:()=>{this.eventBus.emit("onerror",new js("ChatCLISendMessage between-chunk timeout",{willClose:!0}))},onStart:()=>{a=!0,this.eventBus.emit("onack",{code:"0",msg:""}),e()},onMessage:e=>{this.eventBus.emit("onmessage",e)}}).then((()=>{this.eventBus.emit("onclose",{code:0,reason:"eof"})})).catch((t=>{if(!a)return o=t,void e();Ds(t)?this.eventBus.emit("onclose",{code:1e3,reason:"aborted"}):(this.eventBus.emit("onerror",new js(`ChatCLISendMessage stream error: ${String(t)}`,{willClose:!0,rawError:t})),this.eventBus.emit("onclose",{code:1,reason:String(t)}))})).finally((()=>{this.abortController===t&&(this.abortController=null)}))}));if(await c,o){if(Ds(o))return;throw this.eventBus.emit("onerror",new js(`ChatCLISendMessage request error: ${String(o)}`,{willClose:!0,rawError:o})),o}}}__init15(){this.close=()=>{ks([this,"access",e=>e.abortController,"optionalAccess",e=>e.abort,"call",e=>e()]),this.abortController=null,this.opened=!1}}__init16(){this.destroy=()=>{this.destroyed||(this.destroyed=!0,this.close(),this.eventBus.all.clear())}}}function qs(e){let t,s=e[0],i=1;for(;i<e.length;){const r=e[i],n=e[i+1];if(i+=2,("optionalAccess"===r||"optionalCall"===r)&&null==s)return;"access"===r||"optionalAccess"===r?(t=s,s=n(s)):"call"!==r&&"optionalCall"!==r||(s=n(((...e)=>s.call(t,...e))),t=void 0)}return s}const ws=e=>{const{key:t,apiBaseUrl:s,totalTimeoutMs:i,betweenChunkTimeoutMs:r}=e,n=new Gs({apiBaseUrl:s,totalTimeoutMs:i,betweenChunkTimeoutMs:r});return new vs({key:t,env:"production",logLevel:"error",channel:n,reportLog:new Us})};exports.BuildAgentApi=Pe,exports.ChatCoreError=bt,exports.IdeApi=bs,exports.createChatCore=ws,exports.sendProjectChatMessage=async e=>{const{projectId:t,prompt:o,apiBaseUrl:c,sessionId:_="",key:l=`coze-coding-cli:chat:${t}`,totalTimeoutMs:h,betweenChunkTimeoutMs:u,onMessageItem:p,onWarn:d,waitForResponse:g=!0}=e,T=ws({key:l,apiBaseUrl:c,totalTimeoutMs:h,betweenChunkTimeoutMs:u}),E=new Ct;let m=!1;const f=e=>{m||(m=!0,e())};let L;const A=T.on(Lt.MESSAGE_RECEIVED_AND_UPDATE,(({data:e})=>{for(const t of e)if(qs([p,"optionalCall",e=>e(t)]),"answer"===t.type&&t.content.answer&&(L=t),"message_end"===t.type&&t.finish){const e=qs([t,"access",e=>e.content,"access",e=>e.message_end,"optionalAccess",e=>e.code]);if(e&&"0"!==e){f((()=>{E.reject(new s.CozeError(s.ErrorCode.E5002,`Conversation ended with error code: ${e}`,{message_end:t.content.message_end}))}));continue}f((()=>{E.resolve()}))}}),!0),S=T.on(Lt.SEND_MESSAGE_ERROR,(e=>{f((()=>{E.reject(e.data.error)}))}),!0),R=T.on(Lt.MESSAGE_PULLING_STATUS,(({data:e,error:t})=>{const s=e.pullingStatus;"error"!==s&&"channel_error"!==s||f((()=>{E.reject(t)})),("success"===s||"cancel"===s||!g&&"start"===s)&&f((()=>{E.resolve()}))}),!0);try{const e=await(async(e,t,s,r)=>{const n=[],o=[...e.matchAll(Ns)];if(0===o.length)return[{type:"text",content:{text:e}}];let c=0;for(const _ of o){const o=_.index,l=_[0],h=_[1];o>c&&n.push({type:"text",content:{text:e.slice(c,o)}});const u=i.resolve(t,h);let p=!1;if(u.startsWith(i.resolve(t)))try{(await a.stat(u)).isFile()?p=!0:Ms([r,"optionalCall",e=>e(`Uploading directories is not supported: ${h}`)])}catch(e){Ms([r,"optionalCall",e=>e(`File not found: ${h}`)])}if(p)try{const e=await s(u);n.push({type:"upload_file",content:{upload_file:e}})}catch(e){Ms([r,"optionalCall",t=>t(`Failed to upload file: ${h}, ${String(e)}`)]),n.push({type:"text",content:{text:l}})}else n.push({type:"text",content:{text:l}});c=o+l.length}return c<e.length&&n.push({type:"text",content:{text:e.slice(c)}}),n})(o,process.cwd(),(e=>async t=>{const s=i.basename(t),a=new n;a.append("project_id",e),a.append("file_name",s),a.append("file_content",r.createReadStream(t));const o=await bs.UploadProjectFile({body:a},{headers:{...a.getHeaders()}});if(!o.file)throw new Error(`Upload failed for file: ${t}`);return{file_name:o.file.name,file_path:o.file.file_path,url:o.file.url}})(t),d),s=T.createQueryMessage({query:{prompt:e}},{session_id:_,project_id:t,conversation_id:void 0});return await T.sendChatMessage(s),await E.promise,{lastAnswerMessage:L}}finally{A(),S(),R(),T.destroy()}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("process"),r=require("undici"),t=require("./
|
|
1
|
+
"use strict";const e=require("process"),r=require("undici"),t=require("./http-utils-Ci82xaGo.js"),i=require("./index-zg3ZlYH2.js");require("form-data"),require("crypto"),require("url"),require("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("os"),require("zlib"),require("events"),require("lodash"),require("mitt"),require("path"),require("fs"),require("fs/promises"),async function(){try{const s=e.argv[2];if(!s)throw new Error("No payload provided");const o=t.safeJsonParse(s,void 0);if(!o)throw new Error("Invalid payload");const u=new r.EnvHttpProxyAgent;t.customFetch.setDispatcher(u),t.customFetch.setHeaders({Authorization:`Bearer ${o.accessToken}`}),t.installScopedCozeAccountFetchHeader({organizationId:o.organizationId}),o.xTTEnv&&t.customFetch.setHeaders({"x-use-ppe":"1","x-tt-env":o.xTTEnv||""}),await i.sendProjectChatMessage(o),e.exit(0)}catch(r){console.error("❌ Worker error:",r),e.exit(1)}}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("process"),r=require("./task-worker-1kO99GjJ.js");require("path"),require("child_process"),require("undici"),require("./http-utils-Ci82xaGo.js"),require("form-data"),require("crypto"),require("url"),require("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("os"),require("zlib"),require("events"),require("lodash"),require("node:path"),require("node:os"),require("node:fs/promises"),require("node:fs"),async function(){try{await r.runSessionTaskRefreshWorkerCli(),e.exit(0)}catch(r){console.error("❌ Session task refresh worker error:",r),e.exit(1)}}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("process"),t=require("path"),s=require("child_process"),i=require("undici"),a=require("./http-utils-Ci82xaGo.js"),r=require("node:path"),n=require("node:os"),o=require("node:fs/promises");function c(e){const t=Object.create(null);if(e)for(const s in e)if("default"!==s){const i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}return t.default=e,Object.freeze(t)}require("node:fs");const l=c(r),d=c(n),_=c(o);const u=l.join(d.homedir(),".coze"),p=l.join(u,"config.json"),h=l.join(process.cwd(),".cozerc.json"),m={apiBaseUrl:"https://code.coze.cn/",sessionApiBaseUrl:"https://www.coze.cn/",openApiBaseUrl:"https://api.coze.cn",integrationApiBaseUrl:"https://integration.coze.cn",clientId:"95438868623436343239609434490626.app.coze",defaultOutputFormat:"json"};async function g(e){try{const t=await _.readFile(e,"utf8");return JSON.parse(t)}catch(e){return}}function E(){const e={};return process.env.COZE_API_TOKEN&&(e.accessToken=process.env.COZE_API_TOKEN),process.env.COZE_ORG_ID&&(e.organizationId=process.env.COZE_ORG_ID),process.env.COZE_ENTERPRISE_ID&&(e.enterpriseId=process.env.COZE_ENTERPRISE_ID),process.env.COZE_SPACE_ID&&(e.spaceId=process.env.COZE_SPACE_ID),process.env.COZE_SESSION_SPACE_WEB_ID&&(e.sessionSpaceWebId=process.env.COZE_SESSION_SPACE_WEB_ID),"global"!==process.env.COZE_CONFIG_SCOPE&&"local"!==process.env.COZE_CONFIG_SCOPE||(e.configScope=process.env.COZE_CONFIG_SCOPE),process.env.COZE_AUTO_CHECK_UPDATE&&(e.autoCheckUpdate="true"===process.env.COZE_AUTO_CHECK_UPDATE),process.env.COZE_DISABLE_TELEMETRY&&(e.disableTelemetry="true"===process.env.COZE_DISABLE_TELEMETRY),e}async function w(e){const t=process.env.COZE_CONFIG_FILE,[s,i,a,r]=await Promise.all([g(p),g(h),t?g(t):void 0,e?g(e):void 0]),n=E();return{...m,...s,...i,...a,...r,...n}}async function T(e,t=function(e,t){return null!=e?e:t()}(E().configScope,(()=>"global"))){const s=process.env.COZE_CONFIG_FILE,i=s||("global"===t?p:h),a=l.dirname(i);try{await _.mkdir(a,{recursive:!0});const t={...await g(i)||{},...e};await _.writeFile(i,JSON.stringify(t,null,2),"utf8")}catch(e){throw new Error(`Failed to save config to ${i}: ${e}`)}}const S=async({url:e,api:t})=>{if(!e||!t.getWebUrl)return e;try{return function(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}([await t.getWebUrl({original_url:e,exchange_for_short_url:!0}),"access",e=>e.data,"optionalAccess",e=>e.short_url])||e}catch(t){return e}},f=({api:e})=>async({url:t})=>await S({url:t,api:e})||t;const R=({accountId:e,authConfigured:t})=>({authConfigured:t,authValid:!1,clawId:void 0,accountId:e,updatedAt:void 0});function P(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}const A=({api:e,resolveClawId:t})=>async(s={})=>{const i=s.clawId||await t();return(P([await e.listProcess({claw_id:i,size:s.size||100}),"access",e=>e.data,"optionalAccess",e=>e.processes])||[]).map((e=>(e=>{const t=String(e.id||"");if(!t)return null;const s=e;return{progressId:t,name:"string"==typeof e.name?e.name:void 0,type:"string"==typeof s.type?s.type:void 0,progressStatus:"running",raw:e}})(e))).filter((e=>null!==e))},U=e=>async({progressId:t,clawId:s})=>(await e({clawId:s})).find((e=>e.progressId===t))||null,I=({listProgresses:e,runtimeStatusStore:t})=>async({sessionId:s,clawId:i})=>{const a=await e({clawId:i}),r=t.getLive(s),n=P([r,"optionalAccess",e=>e.status])||"idle",o=a.length;return{sessionId:s,displayStatus:"working"===n?"working":"idle",clawBusy:o>0,clawProgressCount:o,runtimeStatus:n,updatedAt:P([r,"optionalAccess",e=>e.updatedAt])}};class C extends Error{constructor(e,t){super(e),this.code=t,this.name="SessionServiceError"}}const L=()=>new C("Session token is missing or invalid","SESSION_AUTH_INVALID");function O(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}const v=({api:e,resolveClawId:t})=>async()=>{const s=await t(),i=await e.createSession({claw_id:s}),a=O([i,"access",e=>e.data,"optionalAccess",e=>e.session,"optionalAccess",e=>e.id]);if(!a)throw new C(i.msg||"Failed to create session","SESSION_CREATE_FAILED");return{clawId:s,sessionId:String(a)}},y=({api:e,resolveClawId:t})=>async(s={})=>{const i=await t(),a=await e.listSession({claw_id:i,offset:s.offset,limit:s.limit});if(0!==a.code&&void 0!==a.code)throw new C(a.msg||"Failed to list sessions","SESSION_LIST_FAILED");const r=O([a,"access",e=>e.data,"optionalAccess",e=>e.session_list])||[],n=O([a,"access",e=>e.data,"optionalAccess",e=>e.next_offset]);return{items:r,nextOffset:n,hasMore:Boolean(n)}},B=({api:e,updateSessionRuntimeStatus:t})=>async({sessionId:s,content:i,files:a})=>{const r=await e.chat({session_id:s,content:i,files:a}),n=O([r,"access",e=>e.data,"optionalAccess",e=>e.message_id]);if(!n)throw new C(r.msg||"Failed to send session message","SESSION_MESSAGE_FAILED");return await t({sessionId:s,status:"working"}),{sessionId:s,messageId:n,status:"accepted"}};var b,z,N,D,q,k,F,G,j,x,M,H,W,V,Y,$,Z,K,J,X,Q,ee,te,se,ie,ae,re,ne,oe,ce,le,de,_e,ue,pe,he,me,ge,Ee,we,Te,Se,fe,Re,Pe,Ae,Ue,Ie,Ce,Le,Oe,ve,ye,Be,be,ze;function Ne(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}!function(e){e[e.Free=0]="Free";e[e.PremiumLite=10]="PremiumLite";e[e.Premium=15]="Premium";e[e.PremiumPlus=20]="PremiumPlus";e[e.V1ProInstance=100]="V1ProInstance";e[e.ProPersonal=110]="ProPersonal";e[e.CozePersonalPlus=112]="CozePersonalPlus";e[e.CozePersonalAdvanced=114]="CozePersonalAdvanced";e[e.CozePersonalPro=116]="CozePersonalPro";e[e.CozePersonalUltra=118]="CozePersonalUltra";e[e.Team=120]="Team";e[e.EnterpriseBasic=125]="EnterpriseBasic";e[e.Enterprise=130]="Enterprise";e[e.EnterprisePro=135]="EnterprisePro"}(b||(b={})),function(e){e[e.Resume=1]="Resume";e[e.Terminate=2]="Terminate"}(z||(z={})),function(e){e[e.CAL_TYPE_UNSPECIFIED=0]="CAL_TYPE_UNSPECIFIED";e[e.CAL_TYPE_CRON=1]="CAL_TYPE_CRON";e[e.CAL_TYPE_HEARTBEAT=2]="CAL_TYPE_HEARTBEAT";e[e.CAL_TYPE_ONCE=3]="CAL_TYPE_ONCE";e[e.CAL_TYPE_DEFAULT=4]="CAL_TYPE_DEFAULT"}(N||(N={})),function(e){e[e.EVENT_STATUS_UNSPECIFIED=0]="EVENT_STATUS_UNSPECIFIED";e[e.EVENT_STATUS_PENDING=1]="EVENT_STATUS_PENDING";e[e.EVENT_STATUS_RUNNING=2]="EVENT_STATUS_RUNNING";e[e.EVENT_STATUS_COMPLETED=3]="EVENT_STATUS_COMPLETED";e[e.EVENT_STATUS_PAUSED=4]="EVENT_STATUS_PAUSED";e[e.EVENT_STATUS_FAILED=5]="EVENT_STATUS_FAILED"}(D||(D={})),function(e){e[e.UnknownTask=0]="UnknownTask";e[e.SubagentTask=1]="SubagentTask";e[e.CronTask=2]="CronTask";e[e.MobileUseTask=3]="MobileUseTask";e[e.BrowserUseTask=4]="BrowserUseTask";e[e.ComputerUseTask=5]="ComputerUseTask"}(q||(q={})),function(e){e[e.Owner=1]="Owner";e[e.Member=10]="Member"}(k||(k={})),function(e){e[e.User=1]="User";e[e.Agent=2]="Agent"}(F||(F={})),function(e){e[e.Unread=1]="Unread";e[e.Read=2]="Read";e[e.Overdue=3]="Overdue"}(G||(G={})),function(e){e[e.All=0]="All";e[e.Private=1]="Private";e[e.NormalProject=2]="NormalProject";e[e.VideoProject=3]="VideoProject"}(j||(j={})),function(e){e[e.Common=1]="Common";e[e.Video=2]="Video"}(x||(x={})),function(e){e[e.History=0]="History";e[e.Private=1]="Private";e[e.Project=2]="Project"}(M||(M={})),function(e){e[e.Asset=1]="Asset";e[e.Material=2]="Material"}(H||(H={})),function(e){e[e.Running=1]="Running";e[e.Waiting=2]="Waiting";e[e.Terminated=3]="Terminated";e[e.Finish=4]="Finish"}(W||(W={})),function(e){e[e.PENDING=0]="PENDING";e[e.RUNNING=1]="RUNNING";e[e.COMPLETED=2]="COMPLETED";e[e.FAILED=3]="FAILED";e[e.INTERRUPTED=4]="INTERRUPTED";e[e.CANCELLED=5]="CANCELLED";e[e.TIMEOUT=6]="TIMEOUT";e[e.RESUMED=7]="RESUMED"}(V||(V={})),function(e){e[e.PENDING=0]="PENDING";e[e.RUNNING=1]="RUNNING";e[e.COMPLETED=2]="COMPLETED";e[e.FAILED=3]="FAILED";e[e.INTERRUPTED=4]="INTERRUPTED";e[e.RESUMED=5]="RESUMED";e[e.CANCELLED=6]="CANCELLED"}(Y||(Y={})),function(e){e[e.Managed=1]="Managed";e[e.Cloud=2]="Cloud";e[e.Local=3]="Local"}($||($={})),function(e){e[e.AgentFrameworkCozeClaw=0]="AgentFrameworkCozeClaw";e[e.AgentFrameworkClaudeCode=1]="AgentFrameworkClaudeCode";e[e.AgentFrameworkCodex=2]="AgentFrameworkCodex";e[e.AgentFrameworkOpenClaw=3]="AgentFrameworkOpenClaw"}(Z||(Z={})),function(e){e[e.Offline=0]="Offline";e[e.Online=1]="Online";e[e.Busy=2]="Busy";e[e.Starting=3]="Starting";e[e.Error=4]="Error"}(K||(K={})),function(e){e[e.CreateModeTemplate=1]="CreateModeTemplate";e[e.CreateModeCloudThirdParty=2]="CreateModeCloudThirdParty";e[e.CreateModeLocalThirdParty=3]="CreateModeLocalThirdParty"}(J||(J={})),function(e){e[e.ACCOUNT_QUOTA_ZERO=1]="ACCOUNT_QUOTA_ZERO";e[e.MOBILE_LIMIT_EXCEEDED=2]="MOBILE_LIMIT_EXCEEDED"}(X||(X={})),function(e){e[e.Terminate=1]="Terminate"}(Q||(Q={})),function(e){e[e.CANCEL=1]="CANCEL"}(ee||(ee={})),function(e){e[e.Success=1]="Success";e[e.Failed=2]="Failed";e[e.Timeout=3]="Timeout"}(te||(te={})),function(e){e[e.Init=1]="Init";e[e.Online=2]="Online";e[e.Busy=3]="Busy";e[e.Offline=4]="Offline";e[e.Error=5]="Error"}(se||(se={})),function(e){e[e.Unset=0]="Unset";e[e.Disabled=1]="Disabled";e[e.Enabled=2]="Enabled"}(ie||(ie={})),function(e){e[e.PENDING=0]="PENDING";e[e.APPROVED=1]="APPROVED";e[e.REJECTED=2]="REJECTED"}(ae||(ae={})),function(e){e[e.IDLE=1]="IDLE";e[e.INTERRUPTED=2]="INTERRUPTED";e[e.REBOOTING=3]="REBOOTING";e[e.INITIALIZING=4]="INITIALIZING";e[e.ARREARS=5]="ARREARS";e[e.RUNNING=6]="RUNNING";e[e.RESERVED=7]="RESERVED";e[e.SCALING=8]="SCALING";e[e.ASSIGN_FAILED=9]="ASSIGN_FAILED"}(re||(re={})),function(e){e[e.PHONE_8C24G=1]="PHONE_8C24G";e[e.PHONE_4C12G=2]="PHONE_4C12G";e[e.PHONE_2C6G=3]="PHONE_2C6G";e[e.PC_2C4G=101]="PC_2C4G";e[e.PC_4C8G=102]="PC_4C8G";e[e.PC_8C16G=103]="PC_8C16G";e[e.PC_16C32G=104]="PC_16C32G";e[e.PC_32C64G=105]="PC_32C64G"}(ne||(ne={})),function(e){e[e.MOBILE=1]="MOBILE";e[e.COMPUTER=2]="COMPUTER"}(oe||(oe={})),function(e){e[e.SUBSCRIBING=0]="SUBSCRIBING";e[e.BOOTING=1]="BOOTING";e[e.REBOOTING=2]="REBOOTING";e[e.IDLE=3]="IDLE";e[e.BUSY=4]="BUSY";e[e.INTERRUPTED=5]="INTERRUPTED";e[e.RELEASING=6]="RELEASING";e[e.RELEASED=7]="RELEASED";e[e.OFFLINE=8]="OFFLINE";e[e.ARREARS=9]="ARREARS";e[e.RESERVED=10]="RESERVED";e[e.SCALING=11]="SCALING";e[e.ASSIGN_FAILED=12]="ASSIGN_FAILED"}(ce||(ce={})),function(e){e[e.HEALTHY=1]="HEALTHY";e[e.WARNING=2]="WARNING";e[e.CRITICAL=3]="CRITICAL"}(le||(le={})),function(e){e[e.AVAILABLE=1]="AVAILABLE";e[e.NEED_UPGRADE_PLAN=2]="NEED_UPGRADE_PLAN";e[e.NOT_ALLOWED_DOWNGRADE=3]="NOT_ALLOWED_DOWNGRADE";e[e.CURRENT_SPEC=4]="CURRENT_SPEC"}(de||(de={})),function(e){e[e.Send=1]="Send";e[e.Received=2]="Received";e[e.Spam=3]="Spam"}(_e||(_e={})),function(e){e[e.Normal=0]="Normal";e[e.Spoof=1]="Spoof";e[e.Phishing=2]="Phishing";e[e.Spam=3]="Spam";e[e.Malicious=4]="Malicious"}(ue||(ue={})),function(e){e[e.Normal=0]="Normal";e[e.Sending=1]="Sending";e[e.Failed=2]="Failed"}(pe||(pe={})),function(e){e[e.FILE_PARTITION_UNSPECIFIED=0]="FILE_PARTITION_UNSPECIFIED";e[e.FILE_PARTITION_USER_MEMORY=1]="FILE_PARTITION_USER_MEMORY";e[e.FILE_PARTITION_AGENT_ALL=2]="FILE_PARTITION_AGENT_ALL";e[e.FILE_PARTITION_USER_ALL=3]="FILE_PARTITION_USER_ALL";e[e.FILE_PARTITION_TRASH=9]="FILE_PARTITION_TRASH"}(he||(he={})),function(e){e[e.FILE_TAG_UNSPECIFIED=0]="FILE_TAG_UNSPECIFIED";e[e.FILE_TAG_FAVORITE=1]="FILE_TAG_FAVORITE";e[e.FILE_TAG_MEMORY=2]="FILE_TAG_MEMORY";e[e.FILE_TAG_TRASH=3]="FILE_TAG_TRASH"}(me||(me={})),function(e){e[e.FILE_TYPE_UNSPECIFIED=0]="FILE_TYPE_UNSPECIFIED";e[e.FILE_TYPE_FAVORITE=1]="FILE_TYPE_FAVORITE";e[e.FILE_TYPE_TEMPLATE=2]="FILE_TYPE_TEMPLATE";e[e.FILE_TYPE_TEMPLATE_COVER=3]="FILE_TYPE_TEMPLATE_COVER";e[e.FILE_TYPE_PLAN_TEMPLATE=4]="FILE_TYPE_PLAN_TEMPLATE";e[e.FILE_TYPE_ARTICLE=5]="FILE_TYPE_ARTICLE"}(ge||(ge={})),function(e){e[e.FOLDER_ARCHIVE_STATUS_UNSPECIFIED=0]="FOLDER_ARCHIVE_STATUS_UNSPECIFIED";e[e.FOLDER_ARCHIVE_STATUS_PENDING=1]="FOLDER_ARCHIVE_STATUS_PENDING";e[e.FOLDER_ARCHIVE_STATUS_RUNNING=2]="FOLDER_ARCHIVE_STATUS_RUNNING";e[e.FOLDER_ARCHIVE_STATUS_SUCCEEDED=3]="FOLDER_ARCHIVE_STATUS_SUCCEEDED";e[e.FOLDER_ARCHIVE_STATUS_FAILED=4]="FOLDER_ARCHIVE_STATUS_FAILED";e[e.FOLDER_ARCHIVE_STATUS_REJECTED=5]="FOLDER_ARCHIVE_STATUS_REJECTED";e[e.FOLDER_ARCHIVE_STATUS_EXPIRED=6]="FOLDER_ARCHIVE_STATUS_EXPIRED"}(Ee||(Ee={})),function(e){e[e.WORKSPACE_SEARCH_TAB_UNSPECIFIED=0]="WORKSPACE_SEARCH_TAB_UNSPECIFIED";e[e.WORKSPACE_SEARCH_TAB_ALL=1]="WORKSPACE_SEARCH_TAB_ALL";e[e.WORKSPACE_SEARCH_TAB_DOC=2]="WORKSPACE_SEARCH_TAB_DOC";e[e.WORKSPACE_SEARCH_TAB_SHEET=3]="WORKSPACE_SEARCH_TAB_SHEET";e[e.WORKSPACE_SEARCH_TAB_PPT=4]="WORKSPACE_SEARCH_TAB_PPT";e[e.WORKSPACE_SEARCH_TAB_IMAGE=5]="WORKSPACE_SEARCH_TAB_IMAGE";e[e.WORKSPACE_SEARCH_TAB_WEB=6]="WORKSPACE_SEARCH_TAB_WEB";e[e.WORKSPACE_SEARCH_TAB_VIDEO=7]="WORKSPACE_SEARCH_TAB_VIDEO";e[e.WORKSPACE_SEARCH_TAB_PODCAST=8]="WORKSPACE_SEARCH_TAB_PODCAST"}(we||(we={})),function(e){e[e.Chat=1]="Chat";e[e.ApiTemplate=2]="ApiTemplate"}(Te||(Te={})),function(e){e[e.User=1]="User";e[e.Agent=2]="Agent";e[e.Project=3]="Project"}(Se||(Se={})),function(e){e[e.Grant=1]="Grant";e[e.Revoke=2]="Revoke";e[e.UpdateScope=3]="UpdateScope"}(fe||(fe={})),function(e){e[e.Single=1]="Single";e[e.Desktop=2]="Desktop";e[e.All=3]="All"}(Re||(Re={})),function(e){e[e.Session=1]="Session";e[e.Agent=2]="Agent"}(Pe||(Pe={})),function(e){e[e.PDF=1]="PDF";e[e.PPT=2]="PPT";e[e.ImageEditablePpt=3]="ImageEditablePpt"}(Ae||(Ae={})),function(e){e[e.PDF=1]="PDF";e[e.DOCX=2]="DOCX"}(Ue||(Ue={})),function(e){e[e.POSITION=0]="POSITION";e[e.ELEMENT=1]="ELEMENT"}(Ie||(Ie={})),function(e){e[e.STORAGE_RESOURCE_TYPE_UNSPECIFIED=0]="STORAGE_RESOURCE_TYPE_UNSPECIFIED";e[e.STORAGE_RESOURCE_TYPE_AGENT=1]="STORAGE_RESOURCE_TYPE_AGENT";e[e.STORAGE_RESOURCE_TYPE_PROJECT=2]="STORAGE_RESOURCE_TYPE_PROJECT";e[e.STORAGE_RESOURCE_TYPE_VIDEO_PROJECT=3]="STORAGE_RESOURCE_TYPE_VIDEO_PROJECT";e[e.STORAGE_RESOURCE_TYPE_CODING_PROJECT=4]="STORAGE_RESOURCE_TYPE_CODING_PROJECT"}(Ce||(Ce={})),function(e){e[e.ACCOUNT_QUOTA_ZERO=1]="ACCOUNT_QUOTA_ZERO";e[e.RESOURCE_LIMIT_EXCEEDED=2]="RESOURCE_LIMIT_EXCEEDED"}(Le||(Le={})),function(e){e[e.MOBILE=1]="MOBILE";e[e.COMPUTER=2]="COMPUTER"}(Oe||(Oe={})),function(e){e[e.Delete=1]="Delete";e[e.Read=2]="Read";e[e.ClearAt=3]="ClearAt"}(ve||(ve={})),function(e){e[e.Delete=0]="Delete";e[e.Running=1]="Running";e[e.Idle=2]="Idle"}(ye||(ye={})),function(e){e[e.Pin=1]="Pin";e[e.Unpin=2]="Unpin";e[e.Delete=3]="Delete"}(Be||(Be={})),function(e){e[e.Running=1]="Running";e[e.Idle=2]="Idle"}(be||(be={})),function(e){e[e.Valid=1]="Valid";e[e.Delete=2]="Delete"}(ze||(ze={}));class De{__init(){this.request=a.request}__init2(){this.baseURL=""}constructor(e){De.prototype.__init.call(this),De.prototype.__init2.call(this),this.request=Ne([e,"optionalAccess",e=>e.request])||this.request,this.baseURL=Ne([e,"optionalAccess",e=>e.baseURL])||this.baseURL}genBaseURL(e){return"string"==typeof this.baseURL?this.baseURL+e:this.baseURL(e)}ListMessage(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message/list"),a={session_id:s.session_id,cursor:s.cursor,size:s.size,asc_mode:s.asc_mode,need_reference:s.need_reference,conversation_id:s.conversation_id};return this.request({url:i,method:"POST",data:a},t)}ListSession(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session/list"),a={claw_id:s.claw_id,limit:s.limit,offset:s.offset,is_pin:s.is_pin,order_by:s.order_by};return this.request({url:i,method:"POST",data:a},t)}ListProcess(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/process/list"),a={claw_id:s.claw_id,size:s.size,cursor:s.cursor};return this.request({url:i,method:"POST",data:a},t)}OperateSession(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session/operate"),a={session_id:s.session_id,operate_type:s.operate_type};return this.request({url:i,method:"POST",data:a},t)}UpdateSession(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session/update"),a={session_id:s.session_id,name:s.name,is_pin:s.is_pin};return this.request({url:i,method:"POST",data:a},t)}Chat(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message/chat"),a={session_id:s.session_id,content:s.content,files:s.files,skill_ids:s.skill_ids,reference_message_id:s.reference_message_id,at_members:s.at_members,conversation_id:s.conversation_id,video_option:s.video_option};return this.request({url:i,method:"POST",data:a},t)}CreateMessageShare(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message/create_share"),a={session_id:s.session_id,message_ids:s.message_ids,share_file:s.share_file};return this.request({url:i,method:"POST",data:a},t)}CreateSession(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session/create"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}GetMainSession(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session/get_main"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}EmailList(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/email/list"),a={claw_id:s.claw_id,email_type:s.email_type,contact_address:s.contact_address,size:s.size,cursor:s.cursor};return this.request({url:i,method:"POST",data:a},t)}CreateMailAddress(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/email/create_address"),a={claw_id:s.claw_id,address:s.address};return this.request({url:i,method:"POST",data:a},t)}BatchGetEmails(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/email/batch"),a={claw_id:s.claw_id,email_ids:s.email_ids};return this.request({url:i,method:"POST",data:a},t)}GetMailAddressInfo(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/email/get_address"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}UpdateUserClawInfo(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/claw/update_info"),a={claw_id:s.claw_id,file_name:s.file_name,file_content:s.file_content,model_name:s.model_name};return this.request({url:i,method:"POST",data:a},t)}ReceivedCallback(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/email/received_callback"),a={app_id:s.app_id,app_email:s.app_email,mail_id:s.mail_id,ouid:s.ouid,mail_message:s.mail_message,create_time:s.create_time};return this.request({url:i,method:"POST",data:a},t)}ListChannel(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/list"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}GetUrl(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/get_url"),a={uris:s.uris,share_id:s.share_id};return this.request({url:i,method:"POST",data:a},t)}GetUserClawInfo(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/claw/info"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}CalendarQueryRange(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/calendar/query_range"),a={start_date:s.start_date,end_date:s.end_date,timezone:s.timezone,claw_id:s.claw_id};return this.request({url:i,method:"GET",params:a},t)}GetRecentFiles(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/recent"),a={limit:s.limit,claw_id:s.claw_id,project_id:s.project_id};return this.request({url:i,method:"GET",params:a},t)}FileUpload(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/upload"),a={file_name:s.file_name,file_content:s.file_content,file_type:s.file_type,tags:s.tags,claw_id:s.claw_id,session_id:s.session_id,project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}GetFileTree(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/tree"),a={partition:s.partition,depth:s.depth,claw_id:s.claw_id};return this.request({url:i,method:"GET",params:a},t)}ListFiles(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/list"),a={tag:s.tag,limit:s.limit,offset:s.offset,sort_by:s.sort_by,sort_order:s.sort_order,claw_id:s.claw_id,project_id:s.project_id};return this.request({url:i,method:"GET",params:a},t)}GetFrontierKey(e,t){const s=this.genBaseURL("/api/coze_claw/resource/get_frontier_key");return this.request({url:s,method:"GET"},t)}GetContacts(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/email/get_contacts"),a={claw_id:s.claw_id,size:s.size,cursor:s.cursor};return this.request({url:i,method:"POST",data:a},t)}CalendarBatchGetEvents(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/calendar/batch_get_events"),a={uids:s.uids,claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}UpdateFile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/update"),a={file_path:s.file_path,file_content:s.file_content,claw_id:s.claw_id,file_uri:s.file_uri,project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}GetFileVersions(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/versions"),a={file_path:s.file_path,claw_id:s.claw_id,file_uri:s.file_uri};return this.request({url:i,method:"GET",params:a},t)}GetSessionInfo(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session/get_info"),a={session_id:s.session_id};return this.request({url:i,method:"POST",data:a},t)}GetMobileSTSCredentials(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/mobile/sts_credentials"),a={pod_id:s.pod_id};return this.request({url:i,method:"GET",params:a},t)}ListMobileTask(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/mobile/list_task"),a={size:s.size,cursor:s.cursor};return this.request({url:i,method:"POST",data:a},t)}FileSearch(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/search"),a={keyword:s.keyword,file_type:s.file_type,tags:s.tags,trash_only:s.trash_only,partition:s.partition,sort_by:s.sort_by,sort_order:s.sort_order,page_size:s.page_size,page_token:s.page_token,claw_id:s.claw_id,project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}OperateMobileTask(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/mobile/operate_task"),a={mobile_task_id:s.mobile_task_id,action:s.action,reason:s.reason};return this.request({url:i,method:"POST",data:a},t)}Reset(e,t){const s=this.genBaseURL("/api/coze_claw/resource/reset");return this.request({url:s,method:"POST"},t)}ListMobile(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/mobile/list"),a={mobile_ids:s.mobile_ids};return this.request({url:i,method:"GET",params:a},t)}EmailSendCallback(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/email/send_callback"),a={otid:s.otid,ouid:s.ouid,mail_id:s.mail_id,message_id:s.message_id,time_stamp:s.time_stamp,from_address:s.from_address,recipient_address:s.recipient_address,event:s.event,src_ip:s.src_ip,return_code:s.return_code,return_msg:s.return_msg,last_update_time_stamp:s.last_update_time_stamp,delivery_error_classify:s.delivery_error_classify};return this.request({url:i,method:"POST",data:a},t)}UnsubscribeMobile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/mobile/unsubscribe"),a={mobile_id:s.mobile_id};return this.request({url:i,method:"POST",data:a},t)}SubscribeMobile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/mobile/subscribe"),a={name:s.name};return this.request({url:i,method:"POST",data:a},t)}OperateMobile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/mobile/operate"),a={mobile_id:s.mobile_id,action:s.action,reason:s.reason,new_name:s.new_name};return this.request({url:i,method:"POST",data:a},t)}CalendarListRecurringEvents(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/calendar/list_recurring_events"),a={claw_id:s.claw_id};return this.request({url:i,method:"GET",params:a},t)}CalendarGetEventDebugURL(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/calendar/get_event_debug_url"),a={calendar_event_uid:s.calendar_event_uid,instance_start:s.instance_start};return this.request({url:i,method:"GET",params:a},t)}GetFeishuAuthInfo(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/feishu/auth_info"),a={claw_id:s.claw_id,bot_name:s.bot_name,redirect_url:s.redirect_url};return this.request({url:i,method:"POST",data:a},t)}ExchangeFeishuAuthCode(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/feishu/exchange_code"),a={code:s.code,verify_state:s.verify_state};return this.request({url:i,method:"POST",data:a},t)}FeishuAuthCallback(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/feishu/auth_callback"),a={code:s.code,verify_state:s.verify_state};return this.request({url:i,method:"POST",data:a},t)}CancelFeishuAuth(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/feishu/cancel_auth"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}ApiTemplate(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/image/api_template"),a={session_id:s.session_id,prompt:s.prompt,files:s.files,type:s.type};return this.request({url:i,method:"POST",data:a},t)}CreateFeishuApp(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/feishu/create_app"),a={claw_id:s.claw_id,bot_name:s.bot_name,recreate:s.recreate};return this.request({url:i,method:"POST",data:a},t)}GetWebUrl(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/get_web_url"),a={original_url:s.original_url,exchange_for_short_url:s.exchange_for_short_url,exchange_for_qr_code:s.exchange_for_qr_code,exchange_for_long_url:s.exchange_for_long_url};return this.request({url:i,method:"GET",params:a},t)}CalendarDelete(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/calendar/delete"),a={uid:s.uid,instance_start:s.instance_start,claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}CalendarResume(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/calendar/resume"),a={uid:s.uid,instance_start:s.instance_start,claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}CalendarPause(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/calendar/pause"),a={uid:s.uid,instance_start:s.instance_start,claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}DetailMobile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/mobile/detail"),a={mobile_id:s.mobile_id};return this.request({url:i,method:"GET",params:a},t)}MGetMessage(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message/mget"),a={session_id:s.session_id,message_ids:s.message_ids};return this.request({url:i,method:"POST",data:a},t)}GenCover(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/resource/gen_cover"),a={original_file_uri:s.original_file_uri,resolution:s.resolution,mode:s.mode,selector_str:s.selector_str,claw_id:s.claw_id,project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}GenDoc(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/resource/gen_doc"),a={target_file_type:s.target_file_type,original_file_uri:s.original_file_uri,resource_map:s.resource_map,claw_id:s.claw_id,project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}ShareDocs(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message/share_docs"),a={uris:s.uris};return this.request({url:i,method:"POST",data:a},t)}TerminateProcess(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/process/terminate"),a={claw_id:s.claw_id,process_id:s.process_id};return this.request({url:i,method:"POST",data:a},t)}SearchMessage(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message/search_message"),a={session_id:s.session_id,query:s.query,limit:s.limit};return this.request({url:i,method:"POST",data:a},t)}WorkspaceSearch(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/workspace_search"),a={keyword:s.keyword,tab:s.tab,page_size:s.page_size,page_token:s.page_token,session_id:s.session_id,claw_id:s.claw_id,project_id:s.project_id};return this.request({url:i,method:"GET",params:a},t)}ExportPPT(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/export_ppt"),a={source_uri:s.source_uri,export_type:s.export_type};return this.request({url:i,method:"POST",data:a},t)}CreateFolderArchive(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/archive/create"),a={claw_id:s.claw_id,file_path:s.file_path,partition:s.partition,project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}GetFolderArchiveStatus(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/archive/status"),a={claw_id:s.claw_id,job_id:s.job_id,project_id:s.project_id};return this.request({url:i,method:"GET",params:a},t)}GetSandboxToken(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/browser_use/get_sandbox_token"),a={session_id:s.session_id,claw_id:s.claw_id,session_key:s.session_key,computer_id:s.computer_id};return this.request({url:i,method:"POST",data:a},t)}OperateBrowserUse(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/browser_use/operate"),a={session_id:s.session_id,claw_id:s.claw_id,action:s.action};return this.request({url:i,method:"POST",data:a},t)}ListBrowserUseMessage(e,t){const s=this.genBaseURL("/api/coze_claw/browser_use/list_message");return this.request({url:s,method:"GET"},t)}IntentRecognition(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/image/intent_recognition"),a={session_id:s.session_id,files:s.files,query:s.query};return this.request({url:i,method:"POST",data:a},t)}RestoreFileVersion(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/versions/restore"),a={file_path:s.file_path,claw_id:s.claw_id,file_uri:s.file_uri,version_id:s.version_id};return this.request({url:i,method:"POST",data:a},t)}GetFileVersionURL(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/versions/url"),a={file_path:s.file_path,claw_id:s.claw_id,file_uri:s.file_uri,version_id:s.version_id};return this.request({url:i,method:"GET",params:a},t)}ExportPPTSandbox(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/export_ppt_sandbox"),a={sandbox_identity_ticket:s.sandbox_identity_ticket,html_content:s.html_content,title:s.title,export_type:s.export_type};return this.request({url:i,method:"POST",data:a},t)}CheckSubscribe(e,t){const s=this.genBaseURL("/api/coze_claw/mobile/check_subscribe");return this.request({url:s,method:"GET"},t)}GetMessageShare(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message/get_share"),a={share_id:s.share_id,need_reference:s.need_reference};return this.request({url:i,method:"POST",data:a},t)}GetModelConfig(e,t){const s=this.genBaseURL("/api/coze_claw/resource/get_model_config");return this.request({url:s,method:"POST"},t)}CheckResourceSubscribe(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/check_subscribe"),a={resource_types:s.resource_types};return this.request({url:i,method:"GET",params:a},t)}UnsubscribeComputer(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/computer/unsubscribe"),a={computer_id:s.computer_id};return this.request({url:i,method:"POST",data:a},t)}ListComputer(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/computer/list"),a={computer_ids:s.computer_ids};return this.request({url:i,method:"GET",params:a},t)}SubscribeComputer(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/computer/subscribe"),a={name:s.name};return this.request({url:i,method:"POST",data:a},t)}OperateComputer(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/computer/operate"),a={computer_id:s.computer_id,action:s.action,new_name:s.new_name};return this.request({url:i,method:"POST",data:a},t)}WechatBindWait(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/wechat/bind_wait"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}WechatWebhook(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/wechat/webhook"),a={app_id:s.app_id,wechat_messages:s.wechat_messages};return this.request({url:i,method:"POST",data:a},t)}WechatBindStart(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/wechat/bind_start"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}WechatUnbind(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/wechat/unbind"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}OperateVideoTask(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/video/operate_task"),a={video_task_id:s.video_task_id,action:s.action,claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}ListVideoTask(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/video/list_task"),a={size:s.size,cursor:s.cursor,claw_id:s.claw_id};return this.request({url:i,method:"GET",params:a},t)}WechatUnbindInternal(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/channel/wechat/unbind_internal"),a={app_id:s.app_id};return this.request({url:i,method:"POST",data:a},t)}GetEmailSettings(e,t){const s=this.genBaseURL("/api/coze_claw/email/get_settings");return this.request({url:s,method:"POST"},t)}GetFileTreeV2(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/tree_v2"),a={partition:s.partition,depth:s.depth,claw_id:s.claw_id,file_path:s.file_path,project_id:s.project_id};return this.request({url:i,method:"GET",params:a},t)}SandboxSkillHubAdd(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/skill/skill_hub_add"),a={sandbox_identity_ticket:s.sandbox_identity_ticket,skill_id:s.skill_id};return this.request({url:i,method:"POST",data:a},t)}SandboxSkillHubShopSearch(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/skill/skill_hub_shop_search"),a={sandbox_identity_ticket:s.sandbox_identity_ticket,keyword:s.keyword};return this.request({url:i,method:"POST",data:a},t)}GetStorageUsage(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/storage_usage"),a={claw_id:s.claw_id,project_id:s.project_id};return this.request({url:i,method:"GET",params:a},t)}MobileScreenShot(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/mobile/screenshot"),a={mobile_id:s.mobile_id};return this.request({url:i,method:"GET",params:a},t)}OperateComputerTask(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/computer/operate_task"),a={run_id:s.run_id,action:s.action};return this.request({url:i,method:"POST",data:a},t)}ListComputerTask(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/computer/list_task"),a={size:s.size,cursor:s.cursor};return this.request({url:i,method:"POST",data:a},t)}ListClaw(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/list_claw"),a={project_id:s.project_id,limit:s.limit,cursor:s.cursor};return this.request({url:i,method:"POST",data:a},t)}ListProject(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/list"),a={type:s.type,limit:s.limit,offset:s.offset,is_pin:s.is_pin};return this.request({url:i,method:"POST",data:a},t)}RemoveProjectMember(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_member/remove"),a={project_id:s.project_id,project_member:s.project_member};return this.request({url:i,method:"POST",data:a},t)}UpdateInviteProjectUser(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_invite/update"),a={project_id:s.project_id,is_accept:s.is_accept};return this.request({url:i,method:"POST",data:a},t)}CreateProject(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/create"),a={claw_ids:s.claw_ids,name:s.name,source_message_ids:s.source_message_ids,source_msg_id:s.source_msg_id,sub_type:s.sub_type};return this.request({url:i,method:"POST",data:a},t)}InviteProjectUser(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_invite/invite"),a={project_id:s.project_id,invite_member:s.invite_member,invite_agent:s.invite_agent};return this.request({url:i,method:"POST",data:a},t)}DeleteProject(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/delete"),a={project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}AddProjectMember(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_member/add"),a={project_id:s.project_id,members:s.members};return this.request({url:i,method:"POST",data:a},t)}CreateClaw(e,t){const s=this.genBaseURL("/api/coze_claw/project/create_claw");return this.request({url:s,method:"POST"},t)}UpdateProject(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/update"),a={project_id:s.project_id,name:s.name,description:s.description,is_pin:s.is_pin};return this.request({url:i,method:"POST",data:a},t)}LeaveProject(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_member/leave"),a={project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}GetDeviceCreatePreflight(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/device/create/preflight"),a={cloud_device_type:s.cloud_device_type,cloud_device_id:s.cloud_device_id,enterprise_id:s.enterprise_id};return this.request({url:i,method:"GET",params:a},t)}ListInvitedProject(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_invite/list_project"),a={limit:s.limit,offset:s.offset};return this.request({url:i,method:"POST",data:a},t)}ListProjectInvitee(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_invite/list_invitee"),a={project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}GetGlobalFileTree(e,t){const s=this.genBaseURL("/api/coze_claw/file/global_tree");return this.request({url:s,method:"GET"},t)}EnterpriseGetDeviceStats(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/stats"),a={enterprise_id:s.enterprise_id};return this.request({url:i,method:"GET",params:a},t)}ListBackgroundSession(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/session/list_background"),a={session_id:s.session_id,filter_running:s.filter_running,cursor:s.cursor,size:s.size};return this.request({url:i,method:"POST",data:a},t)}EnterpriseListMyDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/my"),a={cursor:s.cursor,page_size:s.page_size,enterprise_id:s.enterprise_id};return this.request({url:i,method:"GET",params:a},t)}EnterpriseGetAutoApprove(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/auto_approve"),a={enterprise_id:s.enterprise_id};return this.request({url:i,method:"GET",params:a},t)}EnterpriseAssignDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/assign"),a={cloud_device_id:s.cloud_device_id,target_user_uid:s.target_user_uid,organization_id:s.organization_id,cloud_device_type:s.cloud_device_type,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}GetPairResult(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/get_pair_result"),a={pair_code:s.pair_code};return this.request({url:i,method:"POST",data:a},t)}GetAgentStatus(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/get_status"),a={agent_ids:s.agent_ids};return this.request({url:i,method:"POST",data:a},t)}GetGlobalStorageUsage(e,t){const s=this.genBaseURL("/api/coze_claw/resource/global_storage_usage");return this.request({url:s,method:"GET"},t)}EnterpriseClaimDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/claim"),a={devices:s.devices,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}EnterpriseEditDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/edit"),a={cloud_device_id:s.cloud_device_id,device_name:s.device_name,spec:s.spec,confirm_price_change:s.confirm_price_change,cloud_device_type:s.cloud_device_type,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}SubscribeDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/device/subscribe"),a={cloud_device_type:s.cloud_device_type,spec:s.spec,name:s.name};return this.request({url:i,method:"POST",data:a},t)}ChangeDeviceSpec(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/device/change_spec"),a={cloud_device_type:s.cloud_device_type,cloud_device_id:s.cloud_device_id,target_spec:s.target_spec,name:s.name};return this.request({url:i,method:"POST",data:a},t)}EnterpriseListDeviceClaimRecord(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/claim/list"),a={cursor:s.cursor,page_size:s.page_size,status:s.status,keyword:s.keyword,enterprise_id:s.enterprise_id};return this.request({url:i,method:"GET",params:a},t)}GeneratePairCode(e,t){const s=this.genBaseURL("/api/coze_claw/agent/generate_pair_code");return this.request({url:s,method:"POST"},t)}EnterpriseRejectDeviceClaim(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/claim/reject"),a={claim_record_id:s.claim_record_id,reason:s.reason,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}EnterpriseDeleteDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/delete"),a={cloud_device_id:s.cloud_device_id,cloud_device_type:s.cloud_device_type,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}EnterpriseApproveDeviceClaim(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/claim/approve"),a={claim_record_id:s.claim_record_id,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}EnterpriseListDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/list"),a={cursor:s.cursor,page_size:s.page_size,keyword:s.keyword,cloud_device_type:s.cloud_device_type,status:s.status,enterprise_id:s.enterprise_id};return this.request({url:i,method:"GET",params:a},t)}EnterpriseListAvailableDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/available"),a={cursor:s.cursor,page_size:s.page_size,enterprise_id:s.enterprise_id};return this.request({url:i,method:"GET",params:a},t)}CreateAgent(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/create"),a={agent_name:s.agent_name,create_mode:s.create_mode,template_id:s.template_id,target_device_id:s.target_device_id,framework:s.framework,pair_code:s.pair_code,local_agents:s.local_agents,description:s.description,icon:s.icon};return this.request({url:i,method:"POST",data:a},t)}ListDeviceAgents(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/agent/device/binding/list_by_device"),a={cloud_device_id:s.cloud_device_id,cloud_device_type:s.cloud_device_type,cursor:s.cursor,page_size:s.page_size};return this.request({url:i,method:"GET",params:a},t)}EnterpriseReassignDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/reassign"),a={cloud_device_id:s.cloud_device_id,new_user_uid:s.new_user_uid,new_organization_id:s.new_organization_id,cloud_device_type:s.cloud_device_type,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}EnterpriseSetAutoApprove(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/auto_approve"),a={enabled:s.enabled,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}GetHotWords(e,t){const s=this.genBaseURL("/api/coze_claw/asr/get_hot_words");return this.request({url:s,method:"GET"},t)}GetModelList(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/get_model_list"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}SelectModel(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/resource/select_model"),a={claw_id:s.claw_id,name:s.name};return this.request({url:i,method:"POST",data:a},t)}CreateSessionConversation(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session_conversation/create"),a={session_id:s.session_id,name:s.name,description:s.description};return this.request({url:i,method:"POST",data:a},t)}OperateSessionConversation(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session_conversation/operate"),a={session_conversation_id:s.session_conversation_id,operate_type:s.operate_type};return this.request({url:i,method:"POST",data:a},t)}MessageCardAction(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/message_card/action"),a={name:s.name,surface_id:s.surface_id,source_component_id:s.source_component_id,timestamp:s.timestamp,context:s.context,message_id:s.message_id,claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}UpdateSessionConversation(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session_conversation/update"),a={session_conversation_id:s.session_conversation_id,name:s.name,description:s.description};return this.request({url:i,method:"POST",data:a},t)}ListConversation(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/conversation/list"),a={type:s.type,is_pin:s.is_pin,limit:s.limit,offset:s.offset,top_claw_id:s.top_claw_id};return this.request({url:i,method:"POST",data:a},t)}EnterpriseBatchCreateDevice(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/enterprise/device/batch_create"),a={cloud_device_type:s.cloud_device_type,device_name:s.device_name,spec:s.spec,quantity:s.quantity,enterprise_id:s.enterprise_id};return this.request({url:i,method:"POST",data:a},t)}ListSessionConversation(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/session_conversation/list"),a={session_id:s.session_id,limit:s.limit,offset:s.offset};return this.request({url:i,method:"POST",data:a},t)}GetAgentFileContent(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/file/content"),a={agent_id:s.agent_id,file_path:s.file_path};return this.request({url:i,method:"GET",params:a},t)}GetProjectInfo(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/info"),a={project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}OperateDesktop(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/desktop/operate"),a={device_id:s.device_id,action:s.action,new_name:s.new_name};return this.request({url:i,method:"POST",data:a},t)}DesktopHeartbeat(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/desktop/heartbeat"),a={device_id:s.device_id,version:s.version,status:s.status,os:s.os,desktop_name:s.desktop_name};return this.request({url:i,method:"POST",data:a},t)}ReportDesktopCommandResult(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/desktop/report_command_result"),a={command_id:s.command_id,status:s.status,data:s.data,upload_file:s.upload_file};return this.request({url:i,method:"POST",data:a},t)}ListDesktop(e,t){const s=this.genBaseURL("/api/coze_claw/desktop/list");return this.request({url:s,method:"GET"},t)}SearchProject(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/search"),a={type:s.type,keyword:s.keyword,limit:s.limit,cursor:s.cursor};return this.request({url:i,method:"GET",params:a},t)}GetProjectMembers(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_member/list"),a={project_id:s.project_id};return this.request({url:i,method:"POST",data:a},t)}UpdateAgent(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/update"),a={agent_id:s.agent_id,agent_name:s.agent_name,description:s.description,file_name:s.file_name,file_content:s.file_content};return this.request({url:i,method:"POST",data:a},t)}ListAgents(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/agent/list"),a={page_size:s.page_size,cursor:s.cursor,deploy_types:s.deploy_types,order_by:s.order_by};return this.request({url:i,method:"POST",data:a},t)}GetAgentDetail(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/detail"),a={agent_id:s.agent_id};return this.request({url:i,method:"POST",data:a},t)}ReconnectAgent(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/reconnect"),a={agent_id:s.agent_id,reason:s.reason};return this.request({url:i,method:"POST",data:a},t)}DisconnectAgent(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/disconnect"),a={agent_id:s.agent_id,reason:s.reason,force:s.force};return this.request({url:i,method:"POST",data:a},t)}GetCozeClawUserInfo(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/user/info"),a={need_onboarding_status:s.need_onboarding_status};return this.request({url:i,method:"POST",data:a},t)}SetCozeClawUserOnboardingStatus(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/user/set_onboarding_status"),a={onboarding_status:s.onboarding_status};return this.request({url:i,method:"POST",data:a},t)}GetGlobalUnread(e,t){const s=this.genBaseURL("/api/coze_claw/unread/get_total");return this.request({url:s,method:"POST"},t)}GenerateAgentName(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/agent/generate_name"),a={create_mode:s.create_mode,template_id:s.template_id,framework:s.framework};return this.request({url:i,method:"POST",data:a},t)}ListProjectFiles(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/project/file/list"),a={project_id:s.project_id,file_path:s.file_path,depth:s.depth};return this.request({url:i,method:"POST",data:a},t)}WriteProjectFile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/project/file/write"),a={project_id:s.project_id,file_path:s.file_path,content:s.content};return this.request({url:i,method:"POST",data:a},t)}ReadProjectFile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/project/file/read"),a={project_id:s.project_id,file_path:s.file_path,offset:s.offset,limit:s.limit};return this.request({url:i,method:"POST",data:a},t)}EditProjectFile(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/project/file/edit"),a={project_id:s.project_id,file_path:s.file_path,mode:s.mode,old_string:s.old_string,new_string:s.new_string,append_content:s.append_content};return this.request({url:i,method:"POST",data:a},t)}ComputerScreenShot(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/computer/screenshot"),a={computer_id:s.computer_id};return this.request({url:i,method:"GET",params:a},t)}CancelProjectInvite(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project_invite/cancel"),a={project_id:s.project_id,invite_member:s.invite_member};return this.request({url:i,method:"POST",data:a},t)}GenerateAgentIcon(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/generate_icon"),a={agent_name:s.agent_name,description:s.description};return this.request({url:i,method:"POST",data:a},t)}ListPermission(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/permission/list"),a={session_id:s.session_id};return this.request({url:i,method:"GET",params:a},t)}OperatePermission(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/permission/operate"),a={session_id:s.session_id,action:s.action,target:s.target,permission_id:s.permission_id,desktop_id:s.desktop_id,scope:s.scope,claw_id:s.claw_id,file_path:s.file_path};return this.request({url:i,method:"POST",data:a},t)}RepairAgent(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/repair"),a={agent_id:s.agent_id,reason:s.reason};return this.request({url:i,method:"POST",data:a},t)}ResetAgent(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/reset"),a={agent_id:s.agent_id,reason:s.reason};return this.request({url:i,method:"POST",data:a},t)}MGetConversation(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/conversation/mget"),a={session_ids:s.session_ids,option:s.option};return this.request({url:i,method:"POST",data:a},t)}GetProjectByClawID(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/project/get_by_claw_id"),a={claw_id:s.claw_id};return this.request({url:i,method:"POST",data:a},t)}GetDesktopCommand(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/desktop/get_command"),a={command_id:s.command_id};return this.request({url:i,method:"GET",params:a},t)}OperateVideoConversation(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/video/operate_conversation"),a={session_id:s.session_id,conversation_id:s.conversation_id,action:s.action};return this.request({url:i,method:"POST",data:a},t)}ValidateAgentName(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/agent/validate_name"),a={agent_name:s.agent_name};return this.request({url:i,method:"POST",data:a},t)}GetLocalFileAccess(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/desktop/local_file_access"),a={device_id:s.device_id};return this.request({url:i,method:"GET",params:a},t)}UpdateLocalFileAccess(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/desktop/update_local_file_access"),a={device_id:s.device_id,status:s.status};return this.request({url:i,method:"POST",data:a},t)}AgentFileUpload(e,t){const s=e,i=this.genBaseURL("/api/coze_claw/file/agent_upload"),a={file_name:s.file_name,file_content:s.file_content,file_type:s.file_type,tags:s.tags,agent_id:s.agent_id,session_id:s.session_id};return this.request({url:i,method:"POST",data:a},t)}SetNewFeaturePopupStatus(e,t){const s=e||{},i=this.genBaseURL("/api/coze_claw/user/set_new_feature_popup_status"),a={new_feature_popup_status:s.new_feature_popup_status};return this.request({url:i,method:"POST",data:a},t)}}const qe=new De({});function ke(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}const Fe=Ae.PPT,Ge=Ae.ImageEditablePpt,je=e=>e.replace(/\s+/g," ").trim(),xe=e=>je(e.replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/ /g," ").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'")),Me=e=>{const t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i),s=ke([t,"optionalAccess",e=>e[1]])?xe(t[1]):"";if(s)return s;const i=xe(e);return i?i.split(" ")[0]:void 0},He=e=>{const t=(e=>{if(e.includes("\x3c!--SPLIT_HTML--\x3e"))return e.split("\x3c!--SPLIT_HTML--\x3e").map((e=>e.trim())).filter(Boolean);const t=e.match(/<html[\s\S]*?<\/html>/gi);return ke([t,"optionalAccess",e=>e.length])?t.map((e=>e.trim())).filter(Boolean):[e.trim()].filter(Boolean)})(e).map(((e,t)=>({page:t+1,title:Me(e),previewText:xe(e)})));return{type:"html",pageCount:t.length,pages:t}},We=(e,t)=>{if(!(t.length>=80||void 0===e))if("string"!=typeof e)Array.isArray(e)?e.forEach((e=>We(e,t))):e&&"object"==typeof e&&Object.entries(e).forEach((([e,s])=>{(["title","text","content","description","name"].includes(e)||Array.isArray(s)||s&&"object"==typeof s)&&We(s,t)}));else{const s=je(e);s&&t.push(s)}},Ve=({api:e})=>async({fileUri:t,exportType:s="ppt"})=>{const i=await e.exportPPT({source_uri:t,export_type:"editable"===s?Ge:Fe});if(void 0!==i.code&&0!==i.code&&"0"!==i.code)throw new C(i.msg||"Failed to export PPT","SESSION_PPT_EXPORT_FAILED");const a=ke([i,"access",e=>e.data,"optionalAccess",e=>e.url]);if(!a)throw new C(i.msg||"PPT export response missing download URL","SESSION_PPT_EXPORT_FAILED");return{uri:ke([i,"access",e=>e.data,"optionalAccess",e=>e.uri]),url:a,exportType:s}};function Ye(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}const $e=e=>{const t=String(e.id||"");if(!t)return null;const s="string"==typeof e.content?e.content:"",i=(r=s,a.safeJsonParse(r,void 0));var r;const n=Ye([i,"optionalAccess",e=>e.message_data,"optionalAccess",e=>e.reply]),o=void 0===Ye([i,"optionalAccess",e=>e.create_time_ms])?void 0:String(i.create_time_ms);return{messageId:t,sessionId:"string"==typeof Ye([i,"optionalAccess",e=>e.session_id])?i.session_id:void 0,source:(c=e.source,1===Number(c)?"user":2===Number(c)?"agent":"unknown"),content:"string"==typeof Ye([n,"optionalAccess",e=>e.content])&&n.content?n.content:s,files:Array.isArray(e.files)?e.files:void 0,createTime:"string"==typeof e.create_time?e.create_time:o,messageType:"string"==typeof Ye([i,"optionalAccess",e=>e.message_type])?i.message_type:void 0,replyToMessageId:"string"==typeof Ye([n,"optionalAccess",e=>e.reply_to_message_id])?n.reply_to_message_id:void 0,raw:e};var c};const Ze=({api:e})=>async({fileUri:t})=>{const s=await e.getUrl({uris:[t]}),i=function(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}([s,"access",e=>e.data,"optionalAccess",e=>e.urls,"optionalAccess",e=>e[0]]);if(!i)throw new C(s.msg||"Failed to resolve session file URL","SESSION_FILE_URL_FAILED");return i};const Ke=async({formData:e,request:t})=>{e.append("file_name",t.fileName);const s=await(async e=>{if(e instanceof Blob)return e;if(Buffer.isBuffer(e))return new Blob([e]);if(e instanceof Uint8Array)return new Blob([e]);if(e instanceof ArrayBuffer)return new Blob([e]);if("string"==typeof e)return new Blob([e]);throw new TypeError("Unsupported session upload file content type")})(t.fileContent),i=(a=t.fileContent)instanceof Blob&&a.type?a.type:void 0;var a;const r=i&&s.type!==i?new Blob([s],{type:i}):s;e.append("file_content",r,t.fileName),e.append("claw_id",t.clawId),t.sessionId&&e.append("session_id",t.sessionId)},Je=({options:e,requestOptions:t})=>{const s={...(i=t.headers,r=()=>({}),null!=i?i:r())};var i,r;const n=(({baseUrl:e,webOrigin:t})=>{if(t)return t;try{return new URL(a.normalizeBaseUrl(e)).origin}catch(e){return}})({baseUrl:e.baseUrl,webOrigin:e.webOrigin});return n&&(s.Origin=n),s.Referer=(({baseUrl:e,webOrigin:t})=>t?t.endsWith("/")?t:`${t}/`:a.normalizeBaseUrl(e))({baseUrl:e.baseUrl,webOrigin:e.webOrigin}),e.xSpaceWebId&&(s["x-space-webid"]=e.xSpaceWebId),Object.assign(s,a.getPpeHeaders(e.xTTEnv)),s};const Xe=async({baseUrl:e,params:t,requestOptions:s={},responseFallback:i,xTTEnv:r})=>{const n=new URL(t.url,a.normalizeBaseUrl(e));a.appendSearchParams(n,t.params);const o={"Content-Type":"application/json",...(c=s.headers,l=()=>({}),null!=c?c:l()),...a.getPpeHeaders(r)};var c,l;const d=t.method.toUpperCase(),_="GET"===d?void 0:JSON.stringify(void 0===t.data?{}:t.data),u=await a.customFetch.fetch(n.toString(),{method:d,headers:o,body:_});!function(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}}([s,"access",e=>e.onGetLogId,"optionalCall",e=>e(a.getServiceResponseLogId(u)||"")]);const p=await a.parseServiceResponseBody(u,i);return a.assertServiceResponseOk(u,p,{serviceName:"Session"}),p},Qe=e=>{const t=async(t,s={})=>await Xe({baseUrl:e.baseUrl,params:t,requestOptions:s,responseFallback:{},xTTEnv:e.xTTEnv}),s=new De({baseURL:a.normalizeBaseUrl(e.baseUrl),request:(e,s={})=>t(e,s)}),i=new De({baseURL:a.normalizeBaseUrl(e.baseUrl),request:(e,s={})=>t(e,s)}),r=(e=>async(t,s={})=>{const i=new URL("/api/coze_claw/file/upload",a.normalizeBaseUrl(e.baseUrl)),r=new FormData;await Ke({formData:r,request:t});const n=Je({options:e,requestOptions:s}),o={...a.customFetch.getHeaders(),...n},c=await globalThis.fetch(i.toString(),{method:"POST",headers:o,body:r});!function(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}}([s,"access",e=>e.onGetLogId,"optionalCall",e=>e(c.headers.get("x-tt-logid")||"")]);const l=await a.parseServiceResponseBody(c,{});return a.assertServiceResponseOk(c,l,{serviceName:"Session"}),l})(e);return{getUserClawInfo:(t,s)=>Xe({baseUrl:e.baseUrl,params:{url:"/api/coze_claw/claw/info",method:"POST",data:t},requestOptions:s,responseFallback:{},xTTEnv:e.xTTEnv}),createSession:(e,t)=>s.CreateSession(e,t),listSession:(e,t)=>s.ListSession(e,t),listMessage:(e,t)=>s.ListMessage(e,t),uploadFile:r,getWebUrl:(e,t)=>i.GetWebUrl(e,t),getUrl:(e,t)=>i.GetUrl(e,t),exportPPT:(e,t)=>i.ExportPPT(e,t),chat:(e,t)=>s.Chat(e,t),listProcess:(e,t)=>s.ListProcess(e,t)}},et=e=>{const t=Qe({baseUrl:e.sessionApiBaseUrl||e.apiBaseUrl,webOrigin:e.sessionApiBaseUrl||e.apiBaseUrl,xSpaceWebId:e.sessionSpaceWebId,xTTEnv:e.xTTEnv});return{getUserClawInfo:(e,s)=>t.getUserClawInfo(e,s),createSession:(e,s)=>t.createSession(e,s),listSession:(e,s)=>t.listSession(e,s),listMessage:(e,s)=>t.listMessage(e,s),uploadFile:(e,s)=>t.uploadFile(e,s),getWebUrl:(e,s)=>t.getWebUrl(e,s),getUrl:(e,s)=>t.getUrl(e,s),exportPPT:(e,s)=>t.exportPPT(e,s),chat:(e,s)=>t.chat(e,s),listProcess:(e,s)=>t.listProcess(e,s)}},tt=()=>({async get(){const e=await w();return{sessionId:e.sessionId,sessionClawId:e.sessionClawId}},async save(e){await T(e)}});function st(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}const it=[".report.html",".podcast.html",".webdoc.html",".socmed.html",".pptx.html",".poster.html",".resume.html",".chart.html"],at=({file:e,fileIndex:t,clawId:s,webOrigin:i})=>{const a=e.file_uri;if(!a||!s)return;const r=new URL(i).origin;const n=e.file_name||a.split("/").pop()||"";return(e=>e.endsWith(".html")&&!it.some((t=>e.endsWith(t))))(n||a)?`${r}/web?is_shared=1&uri=${encodeURIComponent(a)}&is_claw=1`:`${r}/share-product/${s}?index=${t}&uri=${encodeURIComponent(a)}&filename=${encodeURIComponent(n)}&only_content=1&is_claw=1`},rt=async({files:e,clawId:t,webOrigin:s,api:i})=>e&&0!==e.length?await Promise.all(e.map((async(e,a)=>{const r=at({file:e,fileIndex:a,clawId:t,webOrigin:s});return{...e,preview_url:await S({url:r,api:i})}}))):[],nt=async({files:e,clawId:t,apiBaseUrl:s,sessionApiBaseUrl:i,xTTEnv:a,service:r,deps:n})=>{if(!e||0===e.length)return e;const o=st([n,"optionalAccess",e=>e.store])||tt(),{sessionClawId:c}=await o.get(),l=t||c||(await r.getStatus()).clawId,d=(st([n,"optionalAccess",e=>e.createApi])||Qe)({baseUrl:i||s,xTTEnv:a}),_=st([n,"optionalAccess",e=>e.resolveFiles])||rt;return await _({files:e,clawId:l,webOrigin:i||s,api:{getWebUrl:e=>d.getWebUrl(e)}})},ot=e=>"running"!==e,ct=e=>{if(e&&0!==e.length)return e.map((e=>({fileName:e.file_name,fileUrl:e.file_url,previewUrl:e.preview_url,fileUri:e.file_uri})))};const lt=r.join(n.homedir(),".coze","tasks","session-progress-tasks.json");class dt extends Error{constructor(e){super(e),this.name="SessionTaskStoreError"}}class _t extends Error{constructor(e){super(`Session task expired: ${e}`),this.taskId=e,this.name="SessionTaskExpiredError"}}class ut extends Error{constructor(e){super(`Session task not found: ${e}`),this.taskId=e,this.name="SessionTaskNotFoundError"}}const pt=(e,t)=>Object.entries(t).reduce(((e,[t,s])=>void 0===s?e:{...e,[t]:s}),{...e}),ht=e=>{const t=a.safeJsonParse(e,void 0);if(void 0===t)throw new dt("Failed to parse session task store");if(s=t,!Boolean(s)||"object"!=typeof s||Array.isArray(s)||!Array.isArray(t.items))throw new dt("Failed to parse session task store");var s;return{version:1,items:t.items}},mt=({filePath:e=lt,now:t=Date.now,retentionMs:s=6048e5,writeDocument:i=async(e,t)=>{await(async({content:e,filePath:t})=>{await o.mkdir(r.dirname(t),{recursive:!0});const s=`${t}.tmp.${Date.now()}.${process.pid}`,i=await o.open(s,"w");try{await i.writeFile(e,"utf8"),await i.sync()}finally{await i.close()}try{await o.rename(s,t)}catch(e){throw await o.rm(s,{force:!0}).catch((()=>{})),e}})({content:t,filePath:e})}}={})=>{const a=(e=>async()=>{try{const t=await o.readFile(e,"utf8");return ht(t)}catch(e){if("ENOENT"===function(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}([e,"optionalAccess",e=>e.code]))return{version:1,items:[]};if(e instanceof dt)throw e;throw new dt(`Failed to read session task store: ${String(e)}`)}})(e),n=(({filePath:e,writeDocument:t})=>async s=>{await t(e,JSON.stringify(s,null,2))})({filePath:e,writeDocument:i}),c=e=>{if(!ot(e.status))return!1;const i=(a=e.finishedAt,r=()=>e.updatedAt,null!=a?a:r());var a,r;return t()-i>s},l=(({isExpired:e,readDocument:t})=>async({includeExpired:s,taskId:i})=>{const a=(await t()).items.find((e=>e.taskId===i));if(!a)throw new ut(i);if(!s&&e(a))throw new _t(i);return a})({isExpired:c,readDocument:a});return{list:async(e={})=>(await a()).items.filter((t=>!(!e.includeExpired&&c(t))&&((!e.sessionId||t.sessionId===e.sessionId)&&(!e.status||t.status===e.status)))).sort(((e,t)=>t.updatedAt-e.updatedAt)),get:async(e,t={})=>await l({includeExpired:t.includeExpired,taskId:e}),async upsert(e){const t=await a(),s=t.items.findIndex((t=>t.taskId===e.taskId));if(s>=0){const[i]=t.items.slice(s,s+1),a=pt(i,e);t.items.splice(s,1,a)}else t.items.push(e);return await n(t),await l({includeExpired:!0,taskId:e.taskId})},async patch(e,t){const s=await a(),i=s.items.findIndex((t=>t.taskId===e));if(i<0)throw new ut(e);const[r]=s.items.slice(i,i+1),o=pt(r,t);return s.items.splice(i,1,o),await n(s),await l({includeExpired:!0,taskId:e})},async remove(e){const t=await a();t.items=t.items.filter((t=>t.taskId!==e)),await n(t)},async gc(){const e=await a(),t=e.items.filter(c);return e.items=e.items.filter((e=>!c(e))),await n(e),t},isExpired:c}},gt=({api:e,store:t,authConfigured:s=()=>!0,fallbackAccountId:i})=>{const a=(({now:e=Date.now,workingTtlMs:t=3e4}={})=>{const s=new Map;return{clear(){s.clear()},getLive(i){const a=s.get(i);if(a){if(!(e()-a.updatedAt>t))return a;s.delete(i)}},markIdle(e){s.delete(e)},markWorking(t){s.set(t,{status:"working",updatedAt:e()})}}})(),r=(e=>async({sessionId:t,status:s})=>{"idle"!==s?e.markWorking(t):e.markIdle(t)})(a),n=(({api:e,authConfigured:t,fallbackAccountId:s,store:i})=>async()=>{const a=s;if(!t())return R({accountId:a,authConfigured:!1});try{const t=a?{account_id:a}:{},s=function(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}([await e.getUserClawInfo(t),"access",e=>e.data,"optionalAccess",e=>e.user_claw_info,"optionalAccess",e=>e.claw_id]);return s?(await i.save({sessionClawId:s}),{authConfigured:!0,authValid:!0,clawId:s,accountId:a,updatedAt:void 0}):R({accountId:a,authConfigured:!0})}catch(e){return R({accountId:a,authConfigured:!0})}})({api:e,authConfigured:s,fallbackAccountId:i,store:t}),o=(({createAuthInvalidError:e,getStatus:t,getStoredConfig:s})=>async()=>{const i=await s();if(i.sessionClawId)return i.sessionClawId;const a=await t();if(!a.authValid||!a.clawId)throw e();return a.clawId})({createAuthInvalidError:L,getStatus:n,getStoredConfig:async()=>t.get()}),c=A({api:e,resolveClawId:o}),{listMessages:l,listRepliesByMessage:d}=(({api:e,createListError:t})=>{const s=async({sessionId:s,cursor:i,size:a=10,ascMode:r})=>{const n=await e.listMessage({session_id:s,cursor:i,size:a,asc_mode:r});if(0!==n.code&&void 0!==n.code)throw t(n.msg||"Failed to list session messages");const o=(Ye([n,"access",e=>e.data,"optionalAccess",e=>e.messages])||[]).map((e=>$e(e))).filter((e=>null!==e)),c=Ye([n,"access",e=>e.data,"optionalAccess",e=>e.next_cursor]);return{items:o,nextCursor:c,hasMore:Boolean(c)}};return{listMessages:s,listRepliesByMessage:async({sessionId:e,messageId:t,size:i=10,maxPages:a=100})=>{let r,n=!1;const o=[];for(let c=0;c<a;c+=1){const a=await s({sessionId:e,cursor:r,size:i});if(a.items.forEach((e=>{e.messageId===t&&(n=!0),e.replyToMessageId===t&&o.push(e)})),n||!a.hasMore||!a.nextCursor)break;r=a.nextCursor}return{sessionId:e,requestMessageId:t,requestMessageFound:n,items:o.reverse()}}}})({api:e,createListError:e=>new C(e,"SESSION_MESSAGE_LIST_FAILED")});return{getStatus:n,createSession:v({api:e,resolveClawId:o}),listSessions:y({api:e,resolveClawId:o}),listMessages:l,listRepliesByMessage:d,sendMessage:B({api:e,updateSessionRuntimeStatus:r}),listProgresses:c,getProgress:U(c),getSessionDisplayStatus:I({listProgresses:c,runtimeStatusStore:a}),resolveFileUrl:Ze({api:e}),exportPpt:Ve({api:e}),shortenWebUrl:f({api:e}),updateSessionRuntimeStatus:r}},Et=e=>{const t=tt();return gt({api:et(e),store:t,authConfigured:()=>Boolean(e.accessToken),fallbackAccountId:e.organizationId})};function wt(e){let t,s=e[0],i=1;for(;i<e.length;){const a=e[i],r=e[i+1];if(i+=2,("optionalAccess"===a||"optionalCall"===a)&&null==s)return;"access"===a||"optionalAccess"===a?(t=s,s=r(s)):"call"!==a&&"optionalCall"!==a||(s=r(((...e)=>s.call(t,...e))),t=void 0)}return s}const Tt=e=>{if(!e)return;const t=(e=>e.replace(/\s+/g," ").trim())(e);return t?t.length>120?`${t.slice(0,117)}...`:t:void 0},St=e=>{if(!e)return;const t=e.trim();return t?t.length>200?`${t.slice(0,197)}...`:t:void 0},ft=({apiBaseUrl:e,now:t=Date.now,resolveReplyFiles:s,service:i,sessionApiBaseUrl:a,store:r=mt(),xTTEnv:n})=>({async createOrUpdateTaskFromMessageWait({answerMessageId:e,content:s,files:i,messageId:a,progress:n,sessionId:o}){const c=t(),l=s,d=Tt(l),_="running"!==n.progressStatus,u=_?St(l):void 0;return await r.upsert({taskId:(p=n.progressId,`stp_${p}`),kind:"session_progress",sessionId:o,messageId:a,progressId:n.progressId,status:_?"finished":"running",contentPreview:d,answerMessageId:e,replyContent:l,resultSummary:u,artifacts:ct(i),lastProgressStatus:n.progressStatus,createdAt:c,updatedAt:c,finishedAt:_?c:void 0});var p},getTask:async(e,t)=>await r.get(e,t),patchTask:async(e,t)=>await r.patch(e,t),listTasks:async e=>await r.list(e),async refreshTask(o,c){const l=await r.get(o,c);if(ot(l.status))return l;try{const c=await i.getProgress({progressId:l.progressId}),d=t();if(c)return await r.patch(o,{contentPreview:Tt(l.replyContent),lastProgressStatus:c.progressStatus,lastRefreshError:void 0,resultSummary:void 0,status:"running"===c.progressStatus?"running":"finished",updatedAt:d});const _=await(async({apiBaseUrl:e,resolveReplyFiles:t=nt,service:s,sessionApiBaseUrl:i,task:a,xTTEnv:r})=>{const n=await s.listRepliesByMessage({sessionId:a.sessionId,messageId:a.messageId}),o=n.items[n.items.length-1];if(!o)return null;const c=o.files&&o.files.length>0?await t({files:o.files,apiBaseUrl:e,sessionApiBaseUrl:i,service:s,xTTEnv:r}):o.files;return{answerMessageId:o.messageId,files:c,replyContent:o.content,resultSummary:St(o.content)}})({apiBaseUrl:e,resolveReplyFiles:s,service:i,sessionApiBaseUrl:a,task:l,xTTEnv:n});return await r.patch(o,{answerMessageId:wt([_,"optionalAccess",e=>e.answerMessageId]),artifacts:wt([_,"optionalAccess",e=>e.files])?ct(_.files):void 0,contentPreview:Tt(wt([_,"optionalAccess",e=>e.replyContent])),finishedAt:d,lastProgressStatus:"finished",lastRefreshError:void 0,replyContent:wt([_,"optionalAccess",e=>e.replyContent]),resultSummary:wt([_,"optionalAccess",e=>e.resultSummary]),status:"finished",updatedAt:d})}catch(e){return await r.patch(o,{lastRefreshError:e instanceof Error?e.message:String(e),updatedAt:t()})}},gcTasks:async()=>await r.gc()});function Rt(e,t){return null!=e?e:t()}const Pt=({elapsedMs:e})=>e>=3e5?3e4:1e4;exports.Claw=qe,exports.DEFAULT_CONFIG=m,exports.SessionServiceError=C,exports.SessionTaskExpiredError=_t,exports.SessionTaskNotFoundError=ut,exports.SessionTaskStoreError=dt,exports.buildSessionPptSlideUrl=({origin:e,fileUri:t,taskId:s,baseHeight:i=720,baseWidth:a=1280})=>{const r=s||(e=>e.split("/").filter(Boolean)[0])(t);if(!r)throw new C("Missing PPT task id for share URL","SESSION_PPT_SHARE_FAILED");const n=new URL(`/slide/${encodeURIComponent(r)}`,(e=>e.endsWith("/")?e.slice(0,-1):e)(e));return n.searchParams.set("uri",t),n.searchParams.set("baseHeight",String(i)),n.searchParams.set("baseWidth",String(a)),n.searchParams.set("is_claw","1"),n.toString()},exports.createDefaultSessionService=Et,exports.createSessionApiClient=Qe,exports.createSessionConfigStore=tt,exports.createSessionTaskService=ft,exports.deleteConfig=async function(e){const t=process.env.COZE_CONFIG_FILE;if(t){const s=await g(t);if(s&&e in s){try{delete s[e],await _.writeFile(t,JSON.stringify(s,null,2),"utf8")}catch(e){throw new Error(`Failed to delete config from ${t}: ${e}`)}return}}let s=h,i=await g(s);if(i&&e in i||(s=p,i=await g(s)),i&&e in i)try{delete i[e],await _.writeFile(s,JSON.stringify(i,null,2),"utf8")}catch(e){throw new Error(`Failed to delete config from ${s}: ${e}`)}},exports.fetchSessionPptContent=async({url:e,fetchImpl:t=e=>a.customFetch.fetch(e),maxBytes:s=10485760})=>{const i=await t(e);if(!i.ok)throw new C(`Failed to fetch PPT content: ${i.status} ${i.statusText}`,"SESSION_PPT_FETCH_FAILED");const r=i.headers.get("content-length");if(r){const e=Number.parseInt(r,10);if(Number.isFinite(e)&&e>s)throw new C(`PPT content is too large: ${e} bytes exceeds ${s} bytes`,"SESSION_PPT_FETCH_FAILED")}const n=await i.text(),o=Buffer.byteLength(n,"utf8");if(o>s)throw new C(`PPT content is too large: ${o} bytes exceeds ${s} bytes`,"SESSION_PPT_FETCH_FAILED");return n},exports.formatSessionPptEditQuery=({pages:e,query:t})=>{const s=[...new Set(e)].sort(((e,t)=>e-t));return 1===s.length?`对第${s[0]}页进行变更:<${t}>`:`对第${s.join("、")}页进行变更:<${t}>`},exports.isSessionTaskTerminal=ot,exports.listConfigs=async function(){const e=process.env.COZE_CONFIG_FILE,[t,s,i]=await Promise.all([g(p),g(h),e?g(e):void 0]),a=E(),r=new Set([...Object.keys(m),...Object.keys(t||{}),...Object.keys(s||{}),...Object.keys(i||{}),...Object.keys(a)]),n=[];for(const e of Array.from(r)){const r=e;let o,c="default";r in a&&void 0!==a[r]?(o=a[r],c="env"):i&&r in i&&void 0!==i[r]?(o=String(i[r]),c="env-file"):s&&r in s&&void 0!==s[r]?(o=String(s[r]),c="local"):t&&r in t&&void 0!==t[r]?(o=String(t[r]),c="global"):r in m&&(o=String(m[r]),c="default"),n.push({key:e,value:o,source:c})}return n},exports.loadConfig=w,exports.parseSessionPptContent=e=>{const t=e.trim(),s=(e=>{const t=a.safeJsonParse(e,null),s=Array.isArray(ke([t,"optionalAccess",e=>e.pages]))?t.pages:Array.isArray(ke([t,"optionalAccess",e=>e.data,"optionalAccess",e=>e.pages]))?t.data.pages:null;return s?{type:"json",pageCount:s.length,pages:s.map(((e,t)=>{const s=[];We(e,s);const i=((e,t)=>{if(!e||"object"!=typeof e)return;const s=e;for(const e of t){const t=s[e];if("string"==typeof t&&t.trim())return t}})(e,["image_url","export_image_url","preview_url","thumbnail_url"]);return{page:t+1,title:s[0]||`第${t+1}页`,previewUrl:i,previewText:je(s.join(" "))||(i?`preview_url: ${i}`:"")}}))}:null})(t);return s||(/<html[\s>]/i.test(t)||t.includes("\x3c!--SPLIT_HTML--\x3e")?He(t):{type:"unknown",pageCount:0,pages:[]})},exports.resolveStoredSessionReplyFiles=nt,exports.runSessionTaskRefreshWorkerCli=async()=>{const t=e.argv[2];if(!t)throw new Error("No payload provided");const s=a.safeJsonParse(t,void 0);if(!s)throw new Error("Invalid payload");await(async({now:e=Date.now,payload:t,sleep:s=async e=>await new Promise((t=>setTimeout(t,e))),taskService:r=ft({apiBaseUrl:t.apiBaseUrl,service:Et({accessToken:t.accessToken,apiBaseUrl:t.apiBaseUrl,organizationId:t.organizationId,sessionApiBaseUrl:Rt(t.sessionApiBaseUrl,(()=>"")),xTTEnv:t.xTTEnv}),sessionApiBaseUrl:t.sessionApiBaseUrl,store:mt(),xTTEnv:t.xTTEnv})})=>{const n=new i.EnvHttpProxyAgent;a.customFetch.setDispatcher(n),a.customFetch.setHeaders({Authorization:`Bearer ${t.accessToken}`}),a.installScopedCozeAccountFetchHeader({organizationId:t.organizationId}),t.xTTEnv&&a.customFetch.setHeaders({"x-use-ppe":"1","x-tt-env":t.xTTEnv});const o=e();let c=3e3;try{for(;;){await s(c);const i=await r.refreshTask(t.taskId,{includeExpired:!0});if(ot(i.status))return;c=Pt({elapsedMs:e()-o})}}finally{await r.patchTask(t.taskId,{workerPid:void 0})}})({payload:s})},exports.saveConfig=T,exports.startDetachedSessionTaskRefreshWorker=async({payload:i,spawnImpl:a=s.spawn})=>{const r=a(e.execPath,[t.resolve(__dirname,"./session-task-refresh.worker.js"),JSON.stringify(i)],{detached:!0,stdio:"ignore"});return r.unref(),r.pid};
|