super-agent-sdk 1.0.14 → 1.0.16

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/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./nosUploader-KkzFK5EW.cjs");function h(r){if(Array.isArray(r))return r.map(e=>h(e));if(r&&typeof r=="object"&&r.constructor===Object){const e={};for(const[t,n]of Object.entries(r)){const o=t.replace(/_([a-z])/g,(a,s)=>s.toUpperCase());e[o]=h(n)}return e}return r}const T="/api/agent/runtime/v1";class k{constructor(e){this.refreshing=null;const t=e.baseUrl??T;this.baseUrl=t.replace(/\/$/,""),this.tokenGateway=e.tokenGateway.replace(/\/$/,""),this.appId=e.appId??"",this.token=e.token??"",this.botId=e.botId,this.isAbsoluteUrl=/^https?:\/\//.test(this.baseUrl),this.isAbsoluteGateway=/^https?:\/\//.test(this.tokenGateway)}getBotId(){return this.botId}getAppKey(){return this.appId}setToken(e){this.token=e}getOrigin(){return typeof window<"u"?window.location.origin:""}async fetchToken(){const t=`${this.isAbsoluteGateway?this.tokenGateway:`${this.getOrigin()}${this.tokenGateway}`}/v1/token`,n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:this.botId})});if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`);const o=await n.json();if(o.code!=="200")throw new Error(o.message||`API error: ${o.code}`);const a=h(o.data);return this.token=a.token,a.appId&&!this.appId&&(this.appId=a.appId),a.token}headers(e){return{"Content-Type":"application/json","X-App-Id":this.appId,"X-Token":this.token,...e}}async handleTokenRefresh(){if(this.refreshing)return await this.refreshing,!0;try{return this.refreshing=(async()=>{await this.fetchToken()})(),await this.refreshing,!0}catch{return!1}finally{this.refreshing=null}}async request(e,t,n){if(!this.token&&!await this.handleTokenRefresh())throw new Error("SDK token not available: POST /token failed");let o=this.isAbsoluteUrl?`${this.baseUrl}${t}`:`${this.getOrigin()}${this.baseUrl}${t}`;if(n!=null&&n.params){const c=new URLSearchParams;for(const[d,l]of Object.entries(n.params))l!=null&&c.set(d,String(l));const i=c.toString();i&&(o+=`?${i}`)}const a=await fetch(o,{method:e,headers:this.headers(),body:n!=null&&n.body?JSON.stringify(n.body):void 0});if(a.status===401&&!(n!=null&&n.retry)&&await this.handleTokenRefresh())return this.request(e,t,{...n,retry:!0});if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const s=await a.json();if(s.code!=="200")throw new Error(s.message||`API error: ${s.code}`);return h(s.data)}get(e,t){return this.request("GET",e,{params:t})}post(e,t){return this.request("POST",e,{body:t})}patch(e,t){return this.request("PATCH",e,{body:t})}del(e){return this.request("DELETE",e)}async streamPost(e,t,n){if(!this.token&&!await this.handleTokenRefresh())throw new Error("SDK token not available: POST /token failed");const o=this.isAbsoluteUrl?`${this.baseUrl}${e}`:`${this.getOrigin()}${this.baseUrl}${e}`,a=await fetch(o,{method:"POST",headers:this.headers(),body:JSON.stringify(t),signal:n});return a.status===401&&await this.handleTokenRefresh()?fetch(o,{method:"POST",headers:this.headers(),body:JSON.stringify(t),signal:n}):a}}function u(r){return typeof r=="string"?r:Array.isArray(r)?r.map(e=>{if(typeof e=="string")return e;if(e&&typeof e=="object"){if(typeof e.text=="string")return e.text;if(e.type)return`[${e.type}${e.mime_type?": "+e.mime_type:""}]`}return""}).join(""):r==null?"":String(r)}function I(r){const e=r.split(`
2
- `).map(n=>n.trim()).filter(n=>n.startsWith("data:")).map(n=>n.slice(5).trim());if(!e.length)return null;let t;try{t=JSON.parse(e.join(`
3
- `))}catch{return null}switch(t.type){case"user":return{type:"user",content:u(t.content)};case"thinking":return{type:"thinking",content:u(t.content)};case"ai":return{type:"ai",content:u(t.content)};case"tool_call":return{type:"tool_call",content:t.name??"",toolName:t.name,toolCallId:t.id,args:typeof t.args=="string"?t.args:JSON.stringify(t.args??{})};case"tool_result":return{type:"tool_result",content:u(t.output),toolName:t.name,toolCallId:t.id,artifacts:Array.isArray(t.artifacts)?t.artifacts:void 0,renderMode:t.render_mode??t.renderMode,html:t.html};case"done":return{type:"done",content:u(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id};case"stop":return{type:"stop",content:u(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id};case"error":return{type:"error",content:t.message??"Unknown error"};case"interrupt":return{type:"interrupt",content:t.content??"",interrupt:{interruptId:t.interruptId??t.interrupt_id??"",interruptType:t.interruptType??t.interrupt_type??"confirm",content:t.content??"",options:t.options,placeholder:t.placeholder,inputType:t.inputType??t.input_type,maxLength:t.maxLength??t.max_length,required:t.required,fields:t.fields,metadata:t.metadata}};default:return null}}async function p(r,e,t){if(!r.body){t(new Error("Response body is null"));return}const n=r.body.getReader(),o=new TextDecoder;let a="";try{for(;;){const{value:s,done:c}=await n.read();if(c)break;a+=o.decode(s,{stream:!0});let i;for(;(i=a.indexOf(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./nosUploader-CgVOa1Lz.cjs");function h(r){if(Array.isArray(r))return r.map(e=>h(e));if(r&&typeof r=="object"&&r.constructor===Object){const e={};for(const[t,s]of Object.entries(r)){const o=t.replace(/_([a-z])/g,(a,n)=>n.toUpperCase());e[o]=h(s)}return e}return r}const k="/api/agent/runtime/v1";class T{constructor(e){this.refreshing=null;const t=e.baseUrl??k;this.baseUrl=t.replace(/\/$/,""),this.tokenGateway=e.tokenGateway.replace(/\/$/,""),this.appId=e.appId??"",this.token=e.token??"",this.botId=e.botId,this.isAbsoluteUrl=/^https?:\/\//.test(this.baseUrl),this.isAbsoluteGateway=/^https?:\/\//.test(this.tokenGateway),this.loginUrl=e.loginUrl,this.onAuthExpired=e.onAuthExpired}getBotId(){return this.botId}getAppKey(){return this.appId}setToken(e){this.token=e}getOrigin(){return typeof window<"u"?window.location.origin:""}async fetchToken(){const t=`${this.isAbsoluteGateway?this.tokenGateway:`${this.getOrigin()}${this.tokenGateway}`}/v1/token`,s=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:this.botId})});if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);const o=await s.json();if(o.code!=="200")throw new Error(o.message||`API error: ${o.code}`);const a=h(o.data);return this.token=a.token,a.appId&&!this.appId&&(this.appId=a.appId),a.token}headers(e){return{"Content-Type":"application/json","X-App-Id":this.appId,"X-Token":this.token,...e}}async handleTokenRefresh(){if(this.refreshing)return await this.refreshing,!0;try{return this.refreshing=(async()=>{await this.fetchToken()})(),await this.refreshing,!0}catch{return!1}finally{this.refreshing=null}}async request(e,t,s){if(!this.token&&!await this.handleTokenRefresh())throw new Error("SDK token not available: POST /token failed");let o=this.isAbsoluteUrl?`${this.baseUrl}${t}`:`${this.getOrigin()}${this.baseUrl}${t}`;if(s!=null&&s.params){const c=new URLSearchParams;for(const[d,l]of Object.entries(s.params))l!=null&&c.set(d,String(l));const i=c.toString();i&&(o+=`?${i}`)}const a=await fetch(o,{method:e,headers:this.headers(),body:s!=null&&s.body?JSON.stringify(s.body):void 0});if(a.status===401&&!(s!=null&&s.retry)&&await this.handleTokenRefresh())return this.request(e,t,{...s,retry:!0});if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const n=await a.json();if(n.code!=="200")throw new Error(n.message||`API error: ${n.code}`);return h(n.data)}get(e,t){return this.request("GET",e,{params:t})}post(e,t){return this.request("POST",e,{body:t})}patch(e,t){return this.request("PATCH",e,{body:t})}del(e){return this.request("DELETE",e)}async streamPost(e,t,s){if(!this.token&&!await this.handleTokenRefresh())throw new Error("SDK token not available: POST /token failed");const o=this.isAbsoluteUrl?`${this.baseUrl}${e}`:`${this.getOrigin()}${this.baseUrl}${e}`,a=await fetch(o,{method:"POST",headers:this.headers(),body:JSON.stringify(t),signal:s});if(a.status===401){const n=await f.peekCookieExpired(a.clone());if(n.isCookieExpired&&typeof(t==null?void 0:t.message)=="string"){f.stashPendingChat({botId:this.botId,message:t.message,sessionId:t.sessionId??""});const i=n.loginUrl??this.loginUrl;return this.onAuthExpired?this.onAuthExpired({loginUrl:i,sessionId:n.sessionId,botId:this.botId}):i&&window.location.replace(i),a}if(await this.handleTokenRefresh())return fetch(o,{method:"POST",headers:this.headers(),body:JSON.stringify(t),signal:s})}return a}}function u(r){return typeof r=="string"?r:Array.isArray(r)?r.map(e=>{if(typeof e=="string")return e;if(e&&typeof e=="object"){if(typeof e.text=="string")return e.text;if(e.type)return`[${e.type}${e.mime_type?": "+e.mime_type:""}]`}return""}).join(""):r==null?"":String(r)}function p(r){const e=r.split(`
2
+ `).map(s=>s.trim()).filter(s=>s.startsWith("data:")).map(s=>s.slice(5).trim());if(!e.length)return null;let t;try{t=JSON.parse(e.join(`
3
+ `))}catch{return null}switch(t.type){case"user":return{type:"user",content:u(t.content)};case"thinking":return{type:"thinking",content:u(t.content)};case"ai":return{type:"ai",content:u(t.content)};case"tool_call":return{type:"tool_call",content:t.name??"",toolName:t.name,toolCallId:t.id,args:typeof t.args=="string"?t.args:JSON.stringify(t.args??{})};case"tool_result":return{type:"tool_result",content:u(t.output),toolName:t.name,toolCallId:t.id,artifacts:Array.isArray(t.artifacts)?t.artifacts:void 0,renderMode:t.render_mode??t.renderMode,html:t.html};case"done":return{type:"done",content:u(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id};case"stop":return{type:"stop",content:u(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id};case"error":return{type:"error",content:t.message??"Unknown error"};case"interrupt":return{type:"interrupt",content:t.content??"",interrupt:{interruptId:t.interruptId??t.interrupt_id??"",interruptType:t.interruptType??t.interrupt_type??"confirm",content:t.content??"",options:t.options,placeholder:t.placeholder,inputType:t.inputType??t.input_type,maxLength:t.maxLength??t.max_length,required:t.required,fields:t.fields,metadata:t.metadata}};default:return null}}async function w(r,e,t){if(!r.body){t(new Error("Response body is null"));return}const s=r.body.getReader(),o=new TextDecoder;let a="";try{for(;;){const{value:n,done:c}=await s.read();if(c)break;a+=o.decode(n,{stream:!0});let i;for(;(i=a.indexOf(`
4
4
 
5
- `))!==-1;){const d=a.slice(0,i);a=a.slice(i+2);const l=I(d);l&&e(l)}}if(a.trim()){const s=I(a);s&&e(s)}}catch(s){(s==null?void 0:s.name)!=="AbortError"&&t(s instanceof Error?s:new Error(String(s)))}finally{try{n.releaseLock()}catch{}}}function b(r,e){var a;const t=new AbortController,n=e.signal?S(e.signal,t.signal):t.signal,o={botId:r.getBotId(),message:e.message,sessionId:e.sessionId,stream:e.stream!==!1,...(a=e.attachments)!=null&&a.length?{attachments:e.attachments.map(({url:s,...c})=>c)}:{}};return o.stream?r.streamPost("/chat",o,n).then(s=>{var c;if(!s.ok){(c=e.onError)==null||c.call(e,new Error(`HTTP ${s.status}`));return}return p(s,i=>{var d,l,f,g,y,m;i.type==="done"&&i.sessionId?(d=e.onDone)==null||d.call(e,{sessionId:i.sessionId,content:i.content,messageId:i.messageId}):i.type==="done"?(l=e.onDone)==null||l.call(e,{sessionId:"",content:i.content,messageId:i.messageId}):i.type==="stop"?((f=e.onMessage)==null||f.call(e,i),(g=e.onDone)==null||g.call(e,{sessionId:i.sessionId??"",content:i.content,messageId:i.messageId})):i.type==="error"?(y=e.onError)==null||y.call(e,new Error(i.content)):(m=e.onMessage)==null||m.call(e,i)},i=>{var d;return(d=e.onError)==null?void 0:d.call(e,i)})}).catch(s=>{var c;(s==null?void 0:s.name)!=="AbortError"&&((c=e.onError)==null||c.call(e,s instanceof Error?s:new Error(String(s))))}):r.post("/chat",o).then(s=>{var c;(c=e.onDone)==null||c.call(e,{sessionId:s.sessionId,content:s.content??"",messageId:s.messageId})}).catch(s=>{var c;(c=e.onError)==null||c.call(e,s instanceof Error?s:new Error(String(s)))}),t}function S(r,e){const t=new AbortController,n=()=>t.abort();return r.addEventListener("abort",n,{once:!0}),e.addEventListener("abort",n,{once:!0}),(r.aborted||e.aborted)&&t.abort(),t.signal}async function $(r){return(await r.post("/chat/sessions",{botId:r.getBotId()})).sessionId}function A(r){return{sessionId:r.threadId??r.sessionId,botId:r.botId,title:r.title,createTime:r.createTime,updateTime:r.updateTime}}async function C(r,e){const t=await r.get("/chat/conversations",{botId:r.getBotId(),page:(e==null?void 0:e.page)??1,size:(e==null?void 0:e.size)??20});return{...t,items:t.items.map(A)}}async function _(r,e,t){await r.patch(`/chat/conversations/${e}`,{title:t})}async function O(r,e){await r.del(`/chat/conversations/${e}`)}async function P(r,e){const t=await r.get(`/chat/conversations/${e}/messages`);return E(t)}function E(r){const e=[...r].sort((s,c)=>{const i=new Date(s.createTime??0).getTime()||0,d=new Date(c.createTime??0).getTime()||0;return i!==d?i-d:(s.seq??0)-(c.seq??0)}),t=new Map;for(const s of e)s.role==="tool"&&s.toolCallId&&t.set(s.toolCallId,s.content||"");const n=new Set,o=[],a=(s,c,i)=>{const d=o[o.length-1];(d==null?void 0:d.role)==="assistant"?(d.parts.push(...s),d.id=c):o.push({id:c,role:"assistant",parts:[...s],timestamp:i})};for(const s of e){if(s.role==="system")continue;const c=String(s.id??s.messageId??`msg_${Date.now()}`),i=new Date(s.createTime??"").getTime()||Date.now();if(s.role==="human"){const d=(s.attachments??[]).map(l=>({type:"attachment",attachment:{nosKey:l.nosKey??l.attachmentId??"",filename:l.filename??"file",size:l.size??void 0,mime:l.mime??void 0,url:l.url??void 0}}));o.push({id:c,role:"user",parts:[...d,{type:"text",content:u(s.content)}],timestamp:i});continue}if(s.role==="ai"){const d=U(s,t,n);d.length>0&&a(d,c,i);continue}if(s.role==="tool"){if(s.toolCallId&&n.has(s.toolCallId))continue;a([N(s)],c,i)}}return o}function U(r,e,t){const n=[];r.reasoning&&n.push({type:"thinking",content:r.reasoning}),r.content&&n.push({type:"text",content:u(r.content)});for(const o of r.toolCalls??[])o.is_interrupt?(t.add(o.id),n.push(x(o,e))):n.push(v(o));return n}function x(r,e){const t=e.has(r.id),n=typeof r.args=="object"?r.args:{};return{type:"interrupt",interrupt:{interruptId:r.id??"",interruptType:n.interruptType??"input",content:n.content??"",options:n.options,placeholder:n.placeholder,inputType:n.inputType,maxLength:n.maxLength,required:n.required,fields:n.fields,metadata:n.metadata},resolved:t,response:t?{action:"submit",value:q(e.get(r.id))}:void 0}}function v(r){let e;try{e=typeof r.args=="string"?r.args:JSON.stringify(r.args??{})}catch{e=String(r.args??"{}")}return{type:"tool_call",toolName:r.name??"",toolCallId:r.id??"",args:e}}function N(r){var t,n,o;const e=Array.isArray(r.artifacts)?r.artifacts:void 0;return{type:"tool_result",toolName:r.toolName??"",toolCallId:r.toolCallId??"",content:u(r.content),artifacts:e,renderMode:((t=r.metadata)==null?void 0:t.renderMode)??((n=r.metadata)==null?void 0:n.render_mode),html:(o=r.metadata)==null?void 0:o.html}}function q(r){if(r!=null)try{return JSON.parse(r)}catch{return r}}async function D(r,e,t,n,o,a,s){const c=await r.streamPost(`/chat/interrupt/${e}/respond`,{sessionId:t,action:n.action,value:n.value},s);if(!c.ok){const i=new Error(`HTTP ${c.status}`);throw a==null||a(i),i}o&&await p(c,i=>{i.type==="error"?a==null||a(new Error(i.content)):o(i)},i=>a==null?void 0:a(i))}async function L(r){return r.get(`/chat/bots/${r.getBotId()}/skills`)}async function G(r,e){await r.post("/chat/stop",{sessionId:e})}function M(r){const e=new k(r);return{botId:e.getBotId(),getToken:()=>e.fetchToken(),createSession:()=>$(e),chat:n=>b(e,n),listConversations:n=>C(e,n),renameConversation:(n,o)=>_(e,n,o),deleteConversation:n=>O(e,n),getMessages:n=>P(e,n),respondInterrupt:(n,o,a,s,c,i)=>D(e,n,o,a,s,c,i),setToken:n=>e.setToken(n),feedback:async(n,o,a)=>{const s={type:o};o==="dislike"&&((a==null?void 0:a.reason)!=null&&(s.reason=a.reason),a!=null&&a.remark&&(s.remark=a.remark)),await e.post(`/chat/messages/${n}/feedback`,s)},cancelFeedback:async n=>{await e.del(`/chat/messages/${n}/feedback`)},listSkills:()=>L(e),stopGeneration:n=>G(e,n)}}exports.createNosUploader=w.createNosUploader;exports.createSuperAgent=M;
5
+ `))!==-1;){const d=a.slice(0,i);a=a.slice(i+2);const l=p(d);l&&e(l)}}if(a.trim()){const n=p(a);n&&e(n)}}catch(n){(n==null?void 0:n.name)!=="AbortError"&&t(n instanceof Error?n:new Error(String(n)))}finally{try{s.releaseLock()}catch{}}}function b(r,e){var a;const t=new AbortController,s=e.signal?S(e.signal,t.signal):t.signal,o={botId:r.getBotId(),message:e.message,sessionId:e.sessionId,stream:e.stream!==!1,...(a=e.attachments)!=null&&a.length?{attachments:e.attachments.map(({url:n,...c})=>c)}:{}};return o.stream?r.streamPost("/chat",o,s).then(n=>{var c;if(!n.ok){(c=e.onError)==null||c.call(e,new Error(`HTTP ${n.status}`));return}return w(n,i=>{var d,l,g,m,y,I;i.type==="done"&&i.sessionId?(d=e.onDone)==null||d.call(e,{sessionId:i.sessionId,content:i.content,messageId:i.messageId}):i.type==="done"?(l=e.onDone)==null||l.call(e,{sessionId:"",content:i.content,messageId:i.messageId}):i.type==="stop"?((g=e.onMessage)==null||g.call(e,i),(m=e.onDone)==null||m.call(e,{sessionId:i.sessionId??"",content:i.content,messageId:i.messageId})):i.type==="error"?(y=e.onError)==null||y.call(e,new Error(i.content)):(I=e.onMessage)==null||I.call(e,i)},i=>{var d;return(d=e.onError)==null?void 0:d.call(e,i)})}).catch(n=>{var c;(n==null?void 0:n.name)!=="AbortError"&&((c=e.onError)==null||c.call(e,n instanceof Error?n:new Error(String(n))))}):r.post("/chat",o).then(n=>{var c;(c=e.onDone)==null||c.call(e,{sessionId:n.sessionId,content:n.content??"",messageId:n.messageId})}).catch(n=>{var c;(c=e.onError)==null||c.call(e,n instanceof Error?n:new Error(String(n)))}),t}function S(r,e){const t=new AbortController,s=()=>t.abort();return r.addEventListener("abort",s,{once:!0}),e.addEventListener("abort",s,{once:!0}),(r.aborted||e.aborted)&&t.abort(),t.signal}async function $(r){return(await r.post("/chat/sessions",{botId:r.getBotId()})).sessionId}function A(r){return{sessionId:r.threadId??r.sessionId,botId:r.botId,title:r.title,createTime:r.createTime,updateTime:r.updateTime}}async function C(r,e){const t=await r.get("/chat/conversations",{botId:r.getBotId(),page:(e==null?void 0:e.page)??1,size:(e==null?void 0:e.size)??20});return{...t,items:t.items.map(A)}}async function _(r,e,t){await r.patch(`/chat/conversations/${e}`,{title:t})}async function x(r,e){await r.del(`/chat/conversations/${e}`)}async function E(r,e){const t=await r.get(`/chat/conversations/${e}/messages`);return P(t)}function P(r){const e=[...r].sort((n,c)=>{const i=new Date(n.createTime??0).getTime()||0,d=new Date(c.createTime??0).getTime()||0;return i!==d?i-d:(n.seq??0)-(c.seq??0)}),t=new Map;for(const n of e)n.role==="tool"&&n.toolCallId&&t.set(n.toolCallId,n.content||"");const s=new Set,o=[],a=(n,c,i)=>{const d=o[o.length-1];(d==null?void 0:d.role)==="assistant"?(d.parts.push(...n),d.id=c):o.push({id:c,role:"assistant",parts:[...n],timestamp:i})};for(const n of e){if(n.role==="system")continue;const c=String(n.id??n.messageId??`msg_${Date.now()}`),i=new Date(n.createTime??"").getTime()||Date.now();if(n.role==="human"){const d=(n.attachments??[]).map(l=>({type:"attachment",attachment:{nosKey:l.nosKey??l.attachmentId??"",filename:l.filename??"file",size:l.size??void 0,mime:l.mime??void 0,url:l.url??void 0}}));o.push({id:c,role:"user",parts:[...d,{type:"text",content:u(n.content)}],timestamp:i});continue}if(n.role==="ai"){const d=O(n,t,s);d.length>0&&a(d,c,i);continue}if(n.role==="tool"){if(n.toolCallId&&s.has(n.toolCallId))continue;a([N(n)],c,i)}}return o}function O(r,e,t){const s=[];r.reasoning&&s.push({type:"thinking",content:r.reasoning}),r.content&&s.push({type:"text",content:u(r.content)});for(const o of r.toolCalls??[])o.is_interrupt?(t.add(o.id),s.push(U(o,e))):s.push(v(o));return s}function U(r,e){const t=e.has(r.id),s=typeof r.args=="object"?r.args:{};return{type:"interrupt",interrupt:{interruptId:r.id??"",interruptType:s.interruptType??"input",content:s.content??"",options:s.options,placeholder:s.placeholder,inputType:s.inputType,maxLength:s.maxLength,required:s.required,fields:s.fields,metadata:s.metadata},resolved:t,response:t?{action:"submit",value:q(e.get(r.id))}:void 0}}function v(r){let e;try{e=typeof r.args=="string"?r.args:JSON.stringify(r.args??{})}catch{e=String(r.args??"{}")}return{type:"tool_call",toolName:r.name??"",toolCallId:r.id??"",args:e}}function N(r){var t,s,o;const e=Array.isArray(r.artifacts)?r.artifacts:void 0;return{type:"tool_result",toolName:r.toolName??"",toolCallId:r.toolCallId??"",content:u(r.content),artifacts:e,renderMode:((t=r.metadata)==null?void 0:t.renderMode)??((s=r.metadata)==null?void 0:s.render_mode),html:(o=r.metadata)==null?void 0:o.html}}function q(r){if(r!=null)try{return JSON.parse(r)}catch{return r}}async function D(r,e,t,s,o,a,n){const c=await r.streamPost(`/chat/interrupt/${e}/respond`,{sessionId:t,action:s.action,value:s.value},n);if(!c.ok){const i=new Error(`HTTP ${c.status}`);throw a==null||a(i),i}o&&await w(c,i=>{i.type==="error"?a==null||a(new Error(i.content)):o(i)},i=>a==null?void 0:a(i))}async function L(r){return r.get(`/chat/bots/${r.getBotId()}/skills`)}async function G(r,e){await r.post("/chat/stop",{sessionId:e})}function M(r){const e=new T(r);return{botId:e.getBotId(),getToken:()=>e.fetchToken(),createSession:()=>$(e),chat:s=>b(e,s),listConversations:s=>C(e,s),renameConversation:(s,o)=>_(e,s,o),deleteConversation:s=>x(e,s),getMessages:s=>E(e,s),respondInterrupt:(s,o,a,n,c,i)=>D(e,s,o,a,n,c,i),setToken:s=>e.setToken(s),feedback:async(s,o,a)=>{const n={type:o};o==="dislike"&&((a==null?void 0:a.reason)!=null&&(n.reason=a.reason),a!=null&&a.remark&&(n.remark=a.remark)),await e.post(`/chat/messages/${s}/feedback`,n)},cancelFeedback:async s=>{await e.del(`/chat/messages/${s}/feedback`)},listSkills:()=>L(e),stopGeneration:s=>G(e,s)}}exports.createNosUploader=f.createNosUploader;exports.createSuperAgent=M;
package/dist/index.d.ts CHANGED
@@ -178,6 +178,12 @@ export declare interface SDKConfig {
178
178
  baseUrl?: string;
179
179
  appId?: string;
180
180
  token?: string;
181
+ loginUrl?: string;
182
+ onAuthExpired?: (ctx: {
183
+ loginUrl?: string;
184
+ sessionId?: string;
185
+ botId: number;
186
+ }) => void;
181
187
  }
182
188
 
183
189
  declare interface SkillInfo {
package/dist/index.mjs CHANGED
@@ -1,22 +1,23 @@
1
- import { c as J } from "./nosUploader-BkBtdrMs.js";
1
+ import { p as w, s as k } from "./nosUploader-CnYDALPr.js";
2
+ import { c as K } from "./nosUploader-CnYDALPr.js";
2
3
  function h(r) {
3
4
  if (Array.isArray(r)) return r.map((e) => h(e));
4
5
  if (r && typeof r == "object" && r.constructor === Object) {
5
6
  const e = {};
6
- for (const [t, n] of Object.entries(r)) {
7
- const o = t.replace(/_([a-z])/g, (a, s) => s.toUpperCase());
8
- e[o] = h(n);
7
+ for (const [t, s] of Object.entries(r)) {
8
+ const o = t.replace(/_([a-z])/g, (a, n) => n.toUpperCase());
9
+ e[o] = h(s);
9
10
  }
10
11
  return e;
11
12
  }
12
13
  return r;
13
14
  }
14
- const w = "/api/agent/runtime/v1";
15
- class T {
15
+ const T = "/api/agent/runtime/v1";
16
+ class b {
16
17
  constructor(e) {
17
18
  this.refreshing = null;
18
- const t = e.baseUrl ?? w;
19
- this.baseUrl = t.replace(/\/$/, ""), this.tokenGateway = e.tokenGateway.replace(/\/$/, ""), this.appId = e.appId ?? "", this.token = e.token ?? "", this.botId = e.botId, this.isAbsoluteUrl = /^https?:\/\//.test(this.baseUrl), this.isAbsoluteGateway = /^https?:\/\//.test(this.tokenGateway);
19
+ const t = e.baseUrl ?? T;
20
+ this.baseUrl = t.replace(/\/$/, ""), this.tokenGateway = e.tokenGateway.replace(/\/$/, ""), this.appId = e.appId ?? "", this.token = e.token ?? "", this.botId = e.botId, this.isAbsoluteUrl = /^https?:\/\//.test(this.baseUrl), this.isAbsoluteGateway = /^https?:\/\//.test(this.tokenGateway), this.loginUrl = e.loginUrl, this.onAuthExpired = e.onAuthExpired;
20
21
  }
21
22
  getBotId() {
22
23
  return this.botId;
@@ -33,14 +34,14 @@ class T {
33
34
  }
34
35
  /** POST {origin}{tokenGateway}/v1/token — 获取 token + appId */
35
36
  async fetchToken() {
36
- const t = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`, n = await fetch(t, {
37
+ const t = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`, s = await fetch(t, {
37
38
  method: "POST",
38
39
  headers: { "Content-Type": "application/json" },
39
40
  body: JSON.stringify({ botId: this.botId })
40
41
  });
41
- if (!n.ok)
42
- throw new Error(`HTTP ${n.status}: ${n.statusText}`);
43
- const o = await n.json();
42
+ if (!s.ok)
43
+ throw new Error(`HTTP ${s.status}: ${s.statusText}`);
44
+ const o = await s.json();
44
45
  if (o.code !== "200")
45
46
  throw new Error(o.message || `API error: ${o.code}`);
46
47
  const a = h(o.data);
@@ -67,13 +68,13 @@ class T {
67
68
  this.refreshing = null;
68
69
  }
69
70
  }
70
- async request(e, t, n) {
71
+ async request(e, t, s) {
71
72
  if (!this.token && !await this.handleTokenRefresh())
72
73
  throw new Error("SDK token not available: POST /token failed");
73
74
  let o = this.isAbsoluteUrl ? `${this.baseUrl}${t}` : `${this.getOrigin()}${this.baseUrl}${t}`;
74
- if (n != null && n.params) {
75
+ if (s != null && s.params) {
75
76
  const c = new URLSearchParams();
76
- for (const [d, l] of Object.entries(n.params))
77
+ for (const [d, l] of Object.entries(s.params))
77
78
  l != null && c.set(d, String(l));
78
79
  const i = c.toString();
79
80
  i && (o += `?${i}`);
@@ -81,16 +82,16 @@ class T {
81
82
  const a = await fetch(o, {
82
83
  method: e,
83
84
  headers: this.headers(),
84
- body: n != null && n.body ? JSON.stringify(n.body) : void 0
85
+ body: s != null && s.body ? JSON.stringify(s.body) : void 0
85
86
  });
86
- if (a.status === 401 && !(n != null && n.retry) && await this.handleTokenRefresh())
87
- return this.request(e, t, { ...n, retry: !0 });
87
+ if (a.status === 401 && !(s != null && s.retry) && await this.handleTokenRefresh())
88
+ return this.request(e, t, { ...s, retry: !0 });
88
89
  if (!a.ok)
89
90
  throw new Error(`HTTP ${a.status}: ${a.statusText}`);
90
- const s = await a.json();
91
- if (s.code !== "200")
92
- throw new Error(s.message || `API error: ${s.code}`);
93
- return h(s.data);
91
+ const n = await a.json();
92
+ if (n.code !== "200")
93
+ throw new Error(n.message || `API error: ${n.code}`);
94
+ return h(n.data);
94
95
  }
95
96
  get(e, t) {
96
97
  return this.request("GET", e, { params: t });
@@ -105,21 +106,39 @@ class T {
105
106
  return this.request("DELETE", e);
106
107
  }
107
108
  /** For SSE streaming — returns raw Response (no envelope unwrap) */
108
- async streamPost(e, t, n) {
109
+ async streamPost(e, t, s) {
109
110
  if (!this.token && !await this.handleTokenRefresh())
110
111
  throw new Error("SDK token not available: POST /token failed");
111
112
  const o = this.isAbsoluteUrl ? `${this.baseUrl}${e}` : `${this.getOrigin()}${this.baseUrl}${e}`, a = await fetch(o, {
112
113
  method: "POST",
113
114
  headers: this.headers(),
114
115
  body: JSON.stringify(t),
115
- signal: n
116
+ signal: s
116
117
  });
117
- return a.status === 401 && await this.handleTokenRefresh() ? fetch(o, {
118
- method: "POST",
119
- headers: this.headers(),
120
- body: JSON.stringify(t),
121
- signal: n
122
- }) : a;
118
+ if (a.status === 401) {
119
+ const n = await w(a.clone());
120
+ if (n.isCookieExpired && typeof (t == null ? void 0 : t.message) == "string") {
121
+ k({
122
+ botId: this.botId,
123
+ message: t.message,
124
+ sessionId: t.sessionId ?? ""
125
+ });
126
+ const i = n.loginUrl ?? this.loginUrl;
127
+ return this.onAuthExpired ? this.onAuthExpired({
128
+ loginUrl: i,
129
+ sessionId: n.sessionId,
130
+ botId: this.botId
131
+ }) : i && window.location.replace(i), a;
132
+ }
133
+ if (await this.handleTokenRefresh())
134
+ return fetch(o, {
135
+ method: "POST",
136
+ headers: this.headers(),
137
+ body: JSON.stringify(t),
138
+ signal: s
139
+ });
140
+ }
141
+ return a;
123
142
  }
124
143
  }
125
144
  function u(r) {
@@ -134,7 +153,7 @@ function u(r) {
134
153
  }
135
154
  function I(r) {
136
155
  const e = r.split(`
137
- `).map((n) => n.trim()).filter((n) => n.startsWith("data:")).map((n) => n.slice(5).trim());
156
+ `).map((s) => s.trim()).filter((s) => s.startsWith("data:")).map((s) => s.slice(5).trim());
138
157
  if (!e.length) return null;
139
158
  let t;
140
159
  try {
@@ -212,13 +231,13 @@ async function p(r, e, t) {
212
231
  t(new Error("Response body is null"));
213
232
  return;
214
233
  }
215
- const n = r.body.getReader(), o = new TextDecoder();
234
+ const s = r.body.getReader(), o = new TextDecoder();
216
235
  let a = "";
217
236
  try {
218
237
  for (; ; ) {
219
- const { value: s, done: c } = await n.read();
238
+ const { value: n, done: c } = await s.read();
220
239
  if (c) break;
221
- a += o.decode(s, { stream: !0 });
240
+ a += o.decode(n, { stream: !0 });
222
241
  let i;
223
242
  for (; (i = a.indexOf(`
224
243
 
@@ -230,72 +249,72 @@ async function p(r, e, t) {
230
249
  }
231
250
  }
232
251
  if (a.trim()) {
233
- const s = I(a);
234
- s && e(s);
252
+ const n = I(a);
253
+ n && e(n);
235
254
  }
236
- } catch (s) {
237
- (s == null ? void 0 : s.name) !== "AbortError" && t(s instanceof Error ? s : new Error(String(s)));
255
+ } catch (n) {
256
+ (n == null ? void 0 : n.name) !== "AbortError" && t(n instanceof Error ? n : new Error(String(n)));
238
257
  } finally {
239
258
  try {
240
- n.releaseLock();
259
+ s.releaseLock();
241
260
  } catch {
242
261
  }
243
262
  }
244
263
  }
245
- function k(r, e) {
264
+ function S(r, e) {
246
265
  var a;
247
- const t = new AbortController(), n = e.signal ? b(e.signal, t.signal) : t.signal, o = {
266
+ const t = new AbortController(), s = e.signal ? $(e.signal, t.signal) : t.signal, o = {
248
267
  botId: r.getBotId(),
249
268
  message: e.message,
250
269
  sessionId: e.sessionId,
251
270
  stream: e.stream !== !1,
252
271
  // url 仅前端回显(下载/预览),剥离后发送——签名 URL 不进后端
253
272
  ...(a = e.attachments) != null && a.length ? {
254
- attachments: e.attachments.map(({ url: s, ...c }) => c)
273
+ attachments: e.attachments.map(({ url: n, ...c }) => c)
255
274
  } : {}
256
275
  };
257
- return o.stream ? r.streamPost("/chat", o, n).then((s) => {
276
+ return o.stream ? r.streamPost("/chat", o, s).then((n) => {
258
277
  var c;
259
- if (!s.ok) {
260
- (c = e.onError) == null || c.call(e, new Error(`HTTP ${s.status}`));
278
+ if (!n.ok) {
279
+ (c = e.onError) == null || c.call(e, new Error(`HTTP ${n.status}`));
261
280
  return;
262
281
  }
263
282
  return p(
264
- s,
283
+ n,
265
284
  (i) => {
266
- var d, l, f, g, y, m;
267
- i.type === "done" && i.sessionId ? (d = e.onDone) == null || d.call(e, { sessionId: i.sessionId, content: i.content, messageId: i.messageId }) : i.type === "done" ? (l = e.onDone) == null || l.call(e, { sessionId: "", content: i.content, messageId: i.messageId }) : i.type === "stop" ? ((f = e.onMessage) == null || f.call(e, i), (g = e.onDone) == null || g.call(e, { sessionId: i.sessionId ?? "", content: i.content, messageId: i.messageId })) : i.type === "error" ? (y = e.onError) == null || y.call(e, new Error(i.content)) : (m = e.onMessage) == null || m.call(e, i);
285
+ var d, l, f, g, m, y;
286
+ i.type === "done" && i.sessionId ? (d = e.onDone) == null || d.call(e, { sessionId: i.sessionId, content: i.content, messageId: i.messageId }) : i.type === "done" ? (l = e.onDone) == null || l.call(e, { sessionId: "", content: i.content, messageId: i.messageId }) : i.type === "stop" ? ((f = e.onMessage) == null || f.call(e, i), (g = e.onDone) == null || g.call(e, { sessionId: i.sessionId ?? "", content: i.content, messageId: i.messageId })) : i.type === "error" ? (m = e.onError) == null || m.call(e, new Error(i.content)) : (y = e.onMessage) == null || y.call(e, i);
268
287
  },
269
288
  (i) => {
270
289
  var d;
271
290
  return (d = e.onError) == null ? void 0 : d.call(e, i);
272
291
  }
273
292
  );
274
- }).catch((s) => {
293
+ }).catch((n) => {
275
294
  var c;
276
- (s == null ? void 0 : s.name) !== "AbortError" && ((c = e.onError) == null || c.call(e, s instanceof Error ? s : new Error(String(s))));
277
- }) : r.post("/chat", o).then((s) => {
295
+ (n == null ? void 0 : n.name) !== "AbortError" && ((c = e.onError) == null || c.call(e, n instanceof Error ? n : new Error(String(n))));
296
+ }) : r.post("/chat", o).then((n) => {
278
297
  var c;
279
298
  (c = e.onDone) == null || c.call(e, {
280
- sessionId: s.sessionId,
281
- content: s.content ?? "",
282
- messageId: s.messageId
299
+ sessionId: n.sessionId,
300
+ content: n.content ?? "",
301
+ messageId: n.messageId
283
302
  });
284
- }).catch((s) => {
303
+ }).catch((n) => {
285
304
  var c;
286
- (c = e.onError) == null || c.call(e, s instanceof Error ? s : new Error(String(s)));
305
+ (c = e.onError) == null || c.call(e, n instanceof Error ? n : new Error(String(n)));
287
306
  }), t;
288
307
  }
289
- function b(r, e) {
290
- const t = new AbortController(), n = () => t.abort();
291
- return r.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), (r.aborted || e.aborted) && t.abort(), t.signal;
308
+ function $(r, e) {
309
+ const t = new AbortController(), s = () => t.abort();
310
+ return r.addEventListener("abort", s, { once: !0 }), e.addEventListener("abort", s, { once: !0 }), (r.aborted || e.aborted) && t.abort(), t.signal;
292
311
  }
293
- async function S(r) {
312
+ async function A(r) {
294
313
  return (await r.post("/chat/sessions", {
295
314
  botId: r.getBotId()
296
315
  })).sessionId;
297
316
  }
298
- function $(r) {
317
+ function C(r) {
299
318
  return {
300
319
  // 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
301
320
  sessionId: r.threadId ?? r.sessionId,
@@ -305,7 +324,7 @@ function $(r) {
305
324
  updateTime: r.updateTime
306
325
  };
307
326
  }
308
- async function A(r, e) {
327
+ async function x(r, e) {
309
328
  const t = await r.get("/chat/conversations", {
310
329
  botId: r.getBotId(),
311
330
  page: (e == null ? void 0 : e.page) ?? 1,
@@ -313,35 +332,35 @@ async function A(r, e) {
313
332
  });
314
333
  return {
315
334
  ...t,
316
- items: t.items.map($)
335
+ items: t.items.map(C)
317
336
  };
318
337
  }
319
- async function C(r, e, t) {
338
+ async function _(r, e, t) {
320
339
  await r.patch(`/chat/conversations/${e}`, { title: t });
321
340
  }
322
- async function _(r, e) {
341
+ async function E(r, e) {
323
342
  await r.del(`/chat/conversations/${e}`);
324
343
  }
325
- async function O(r, e) {
344
+ async function P(r, e) {
326
345
  const t = await r.get(`/chat/conversations/${e}/messages`);
327
- return P(t);
346
+ return O(t);
328
347
  }
329
- function P(r) {
330
- const e = [...r].sort((s, c) => {
331
- const i = new Date(s.createTime ?? 0).getTime() || 0, d = new Date(c.createTime ?? 0).getTime() || 0;
332
- return i !== d ? i - d : (s.seq ?? 0) - (c.seq ?? 0);
348
+ function O(r) {
349
+ const e = [...r].sort((n, c) => {
350
+ const i = new Date(n.createTime ?? 0).getTime() || 0, d = new Date(c.createTime ?? 0).getTime() || 0;
351
+ return i !== d ? i - d : (n.seq ?? 0) - (c.seq ?? 0);
333
352
  }), t = /* @__PURE__ */ new Map();
334
- for (const s of e)
335
- s.role === "tool" && s.toolCallId && t.set(s.toolCallId, s.content || "");
336
- const n = /* @__PURE__ */ new Set(), o = [], a = (s, c, i) => {
353
+ for (const n of e)
354
+ n.role === "tool" && n.toolCallId && t.set(n.toolCallId, n.content || "");
355
+ const s = /* @__PURE__ */ new Set(), o = [], a = (n, c, i) => {
337
356
  const d = o[o.length - 1];
338
- (d == null ? void 0 : d.role) === "assistant" ? (d.parts.push(...s), d.id = c) : o.push({ id: c, role: "assistant", parts: [...s], timestamp: i });
357
+ (d == null ? void 0 : d.role) === "assistant" ? (d.parts.push(...n), d.id = c) : o.push({ id: c, role: "assistant", parts: [...n], timestamp: i });
339
358
  };
340
- for (const s of e) {
341
- if (s.role === "system") continue;
342
- const c = String(s.id ?? s.messageId ?? `msg_${Date.now()}`), i = new Date(s.createTime ?? "").getTime() || Date.now();
343
- if (s.role === "human") {
344
- const d = (s.attachments ?? []).map((l) => ({
359
+ for (const n of e) {
360
+ if (n.role === "system") continue;
361
+ const c = String(n.id ?? n.messageId ?? `msg_${Date.now()}`), i = new Date(n.createTime ?? "").getTime() || Date.now();
362
+ if (n.role === "human") {
363
+ const d = (n.attachments ?? []).map((l) => ({
345
364
  type: "attachment",
346
365
  attachment: {
347
366
  nosKey: l.nosKey ?? l.attachmentId ?? "",
@@ -356,51 +375,51 @@ function P(r) {
356
375
  o.push({
357
376
  id: c,
358
377
  role: "user",
359
- parts: [...d, { type: "text", content: u(s.content) }],
378
+ parts: [...d, { type: "text", content: u(n.content) }],
360
379
  timestamp: i
361
380
  });
362
381
  continue;
363
382
  }
364
- if (s.role === "ai") {
365
- const d = x(s, t, n);
383
+ if (n.role === "ai") {
384
+ const d = U(n, t, s);
366
385
  d.length > 0 && a(d, c, i);
367
386
  continue;
368
387
  }
369
- if (s.role === "tool") {
370
- if (s.toolCallId && n.has(s.toolCallId)) continue;
371
- a([v(s)], c, i);
388
+ if (n.role === "tool") {
389
+ if (n.toolCallId && s.has(n.toolCallId)) continue;
390
+ a([N(n)], c, i);
372
391
  }
373
392
  }
374
393
  return o;
375
394
  }
376
- function x(r, e, t) {
377
- const n = [];
378
- r.reasoning && n.push({ type: "thinking", content: r.reasoning }), r.content && n.push({ type: "text", content: u(r.content) });
395
+ function U(r, e, t) {
396
+ const s = [];
397
+ r.reasoning && s.push({ type: "thinking", content: r.reasoning }), r.content && s.push({ type: "text", content: u(r.content) });
379
398
  for (const o of r.toolCalls ?? [])
380
- o.is_interrupt ? (t.add(o.id), n.push(E(o, e))) : n.push(U(o));
381
- return n;
399
+ o.is_interrupt ? (t.add(o.id), s.push(v(o, e))) : s.push(D(o));
400
+ return s;
382
401
  }
383
- function E(r, e) {
384
- const t = e.has(r.id), n = typeof r.args == "object" ? r.args : {};
402
+ function v(r, e) {
403
+ const t = e.has(r.id), s = typeof r.args == "object" ? r.args : {};
385
404
  return {
386
405
  type: "interrupt",
387
406
  interrupt: {
388
407
  interruptId: r.id ?? "",
389
- interruptType: n.interruptType ?? "input",
390
- content: n.content ?? "",
391
- options: n.options,
392
- placeholder: n.placeholder,
393
- inputType: n.inputType,
394
- maxLength: n.maxLength,
395
- required: n.required,
396
- fields: n.fields,
397
- metadata: n.metadata
408
+ interruptType: s.interruptType ?? "input",
409
+ content: s.content ?? "",
410
+ options: s.options,
411
+ placeholder: s.placeholder,
412
+ inputType: s.inputType,
413
+ maxLength: s.maxLength,
414
+ required: s.required,
415
+ fields: s.fields,
416
+ metadata: s.metadata
398
417
  },
399
418
  resolved: t,
400
- response: t ? { action: "submit", value: D(e.get(r.id)) } : void 0
419
+ response: t ? { action: "submit", value: q(e.get(r.id)) } : void 0
401
420
  };
402
421
  }
403
- function U(r) {
422
+ function D(r) {
404
423
  let e;
405
424
  try {
406
425
  e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
@@ -409,8 +428,8 @@ function U(r) {
409
428
  }
410
429
  return { type: "tool_call", toolName: r.name ?? "", toolCallId: r.id ?? "", args: e };
411
430
  }
412
- function v(r) {
413
- var t, n, o;
431
+ function N(r) {
432
+ var t, s, o;
414
433
  const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
415
434
  return {
416
435
  type: "tool_result",
@@ -418,11 +437,11 @@ function v(r) {
418
437
  toolCallId: r.toolCallId ?? "",
419
438
  content: u(r.content),
420
439
  artifacts: e,
421
- renderMode: ((t = r.metadata) == null ? void 0 : t.renderMode) ?? ((n = r.metadata) == null ? void 0 : n.render_mode),
440
+ renderMode: ((t = r.metadata) == null ? void 0 : t.renderMode) ?? ((s = r.metadata) == null ? void 0 : s.render_mode),
422
441
  html: (o = r.metadata) == null ? void 0 : o.html
423
442
  };
424
443
  }
425
- function D(r) {
444
+ function q(r) {
426
445
  if (r != null)
427
446
  try {
428
447
  return JSON.parse(r);
@@ -430,15 +449,15 @@ function D(r) {
430
449
  return r;
431
450
  }
432
451
  }
433
- async function N(r, e, t, n, o, a, s) {
452
+ async function L(r, e, t, s, o, a, n) {
434
453
  const c = await r.streamPost(
435
454
  `/chat/interrupt/${e}/respond`,
436
455
  {
437
456
  sessionId: t,
438
- action: n.action,
439
- value: n.value
457
+ action: s.action,
458
+ value: s.value
440
459
  },
441
- s
460
+ n
442
461
  );
443
462
  if (!c.ok) {
444
463
  const i = new Error(`HTTP ${c.status}`);
@@ -452,37 +471,37 @@ async function N(r, e, t, n, o, a, s) {
452
471
  (i) => a == null ? void 0 : a(i)
453
472
  );
454
473
  }
455
- async function q(r) {
474
+ async function G(r) {
456
475
  return r.get(`/chat/bots/${r.getBotId()}/skills`);
457
476
  }
458
- async function L(r, e) {
477
+ async function R(r, e) {
459
478
  await r.post("/chat/stop", { sessionId: e });
460
479
  }
461
- function G(r) {
462
- const e = new T(r);
480
+ function J(r) {
481
+ const e = new b(r);
463
482
  return {
464
483
  botId: e.getBotId(),
465
484
  getToken: () => e.fetchToken(),
466
- createSession: () => S(e),
467
- chat: (n) => k(e, n),
468
- listConversations: (n) => A(e, n),
469
- renameConversation: (n, o) => C(e, n, o),
470
- deleteConversation: (n) => _(e, n),
471
- getMessages: (n) => O(e, n),
472
- respondInterrupt: (n, o, a, s, c, i) => N(e, n, o, a, s, c, i),
473
- setToken: (n) => e.setToken(n),
474
- feedback: async (n, o, a) => {
475
- const s = { type: o };
476
- o === "dislike" && ((a == null ? void 0 : a.reason) != null && (s.reason = a.reason), a != null && a.remark && (s.remark = a.remark)), await e.post(`/chat/messages/${n}/feedback`, s);
485
+ createSession: () => A(e),
486
+ chat: (s) => S(e, s),
487
+ listConversations: (s) => x(e, s),
488
+ renameConversation: (s, o) => _(e, s, o),
489
+ deleteConversation: (s) => E(e, s),
490
+ getMessages: (s) => P(e, s),
491
+ respondInterrupt: (s, o, a, n, c, i) => L(e, s, o, a, n, c, i),
492
+ setToken: (s) => e.setToken(s),
493
+ feedback: async (s, o, a) => {
494
+ const n = { type: o };
495
+ o === "dislike" && ((a == null ? void 0 : a.reason) != null && (n.reason = a.reason), a != null && a.remark && (n.remark = a.remark)), await e.post(`/chat/messages/${s}/feedback`, n);
477
496
  },
478
- cancelFeedback: async (n) => {
479
- await e.del(`/chat/messages/${n}/feedback`);
497
+ cancelFeedback: async (s) => {
498
+ await e.del(`/chat/messages/${s}/feedback`);
480
499
  },
481
- listSkills: () => q(e),
482
- stopGeneration: (n) => L(e, n)
500
+ listSkills: () => G(e),
501
+ stopGeneration: (s) => R(e, s)
483
502
  };
484
503
  }
485
504
  export {
486
- J as createNosUploader,
487
- G as createSuperAgent
505
+ K as createNosUploader,
506
+ J as createSuperAgent
488
507
  };
@@ -1,4 +1,4 @@
1
- import { g as pi, b as Dn, a as rn } from "./nosUploader-BkBtdrMs.js";
1
+ import { g as pi, d as Dn, b as rn } from "./nosUploader-CnYDALPr.js";
2
2
  function gi(pn, _n) {
3
3
  for (var C = 0; C < _n.length; C++) {
4
4
  const ie = _n[C];