super-agent-sdk 1.0.22 → 1.0.23
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/README.md +3 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +27 -24
- package/dist/widget.cjs +61 -61
- package/dist/widget.d.ts +18 -3
- package/dist/widget.mjs +4978 -4968
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1548,6 +1548,7 @@ export type MessagePart =
|
|
|
1548
1548
|
renderMode?: string;
|
|
1549
1549
|
html?: string;
|
|
1550
1550
|
markdown?: string;
|
|
1551
|
+
defaultExpanded?: boolean; // config.default_expanded=true 或 renderMode==="html":默认展开
|
|
1551
1552
|
}
|
|
1552
1553
|
| { type: "error"; content: string }
|
|
1553
1554
|
| { type: "attachment"; attachment: ChatAttachment } // 用户消息携带的附件 chip
|
|
@@ -1564,7 +1565,7 @@ export type MessagePart =
|
|
|
1564
1565
|
| `text` | `content` | 文本 / Markdown 内容 |
|
|
1565
1566
|
| `thinking` | `content` | 思考过程(reasoning) |
|
|
1566
1567
|
| `tool_call` | `toolName`, `toolCallId`, `args` | 工具调用,`args` 为 JSON 字符串 |
|
|
1567
|
-
| `tool_result` | `toolName`, `toolCallId`, `content`, `artifacts?`, `renderMode?`, `html?`, `markdown?` | 工具返回结果(文件产物已上移至消息级 `UIMessage.artifacts`,part 级 `artifacts` 仅供自定义 slot
|
|
1568
|
+
| `tool_result` | `toolName`, `toolCallId`, `content`, `artifacts?`, `renderMode?`, `html?`, `markdown?`, `defaultExpanded?` | 工具返回结果(文件产物已上移至消息级 `UIMessage.artifacts`,part 级 `artifacts` 仅供自定义 slot 取用);`defaultExpanded=true` 结果块默认展开(缺省收起),来源为工具配置 `config.default_expanded` 或 `renderMode==="html"` |
|
|
1568
1569
|
| `error` | `content` | 错误信息 |
|
|
1569
1570
|
| `attachment` | `attachment` | 用户消息附件 chip(发送时本地构造 / 历史加载由后端映射,有 `url` 时可下载) |
|
|
1570
1571
|
| `interrupt` | `interrupt`, `resolved?`, `response?` | 中断交互卡片(HITL) |
|
|
@@ -1594,6 +1595,7 @@ export interface ChatEvent {
|
|
|
1594
1595
|
renderMode?: string; // "html" 时工具结果为富文本
|
|
1595
1596
|
html?: string; // renderMode==="html" 时的 HTML 内容
|
|
1596
1597
|
markdown?: string; // renderMode==="markdown" 时的 markdown 内容
|
|
1598
|
+
defaultExpanded?: boolean; // tool_result 顶层 default_expanded:结果块默认展开(缺省收起)
|
|
1597
1599
|
roundId?: string; // session.start/done 携带,本轮对话 id
|
|
1598
1600
|
}
|
|
1599
1601
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./nosUploader-Dk2GyRpT.cjs");function g(r){if(Array.isArray(r))return r.map(e=>g(e));if(r&&typeof r=="object"&&r.constructor===Object){const e={};for(const[o,s]of Object.entries(r)){const d=o.replace(/_([a-z])/g,(t,n)=>n.toUpperCase());e[d]=g(s)}return e}return r}const S="/api/agent/runtime/v1";class C{constructor(e){this.refreshing=null,this.tokenPromise=null;const o=e.baseUrl??S;this.baseUrl=o.replace(/\/$/,""),this.tokenGateway=e.tokenGateway.replace(/\/$/,""),this.appId=e.appId??"",this.token=e.token??"",this.botCode=e.botCode,this.tenantId=e.tenantId,this.isAbsoluteUrl=/^https?:\/\//.test(this.baseUrl),this.isAbsoluteGateway=/^https?:\/\//.test(this.tokenGateway),this.loginUrl=e.loginUrl,this.onAuthExpired=e.onAuthExpired}getBotCode(){return this.botCode}getAppKey(){return this.appId}setToken(e){this.token=e}getOrigin(){return typeof window<"u"?window.location.origin:""}async fetchToken(){if(this.token)return this.token;if(this.tokenPromise)return this.tokenPromise;this.tokenPromise=(async()=>{const o=`${this.isAbsoluteGateway?this.tokenGateway:`${this.getOrigin()}${this.tokenGateway}`}/superagent/v2/token/generate`,s={"Content-Type":"application/json"};this.tenantId!=null&&(s["X-Tenant-Id"]=String(this.tenantId));const d=await fetch(o,{method:"POST",headers:s,body:JSON.stringify({botCode:this.botCode})});if(!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);const t=await d.json();if(t.code!=="200")throw new Error(t.message||`API error: ${t.code}`);const n=g(t.data);return this.token=n.token,n.appId&&!this.appId&&(this.appId=n.appId),n.token})();try{return await this.tokenPromise}finally{this.tokenPromise=null}}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.token="",this.refreshing=(async()=>{await this.fetchToken()})(),await this.refreshing,!0}catch{return!1}finally{this.refreshing=null}}async request(e,o,s){if(!this.token&&!await this.handleTokenRefresh())throw new Error("SDK token not available: POST /token failed");let d=this.isAbsoluteUrl?`${this.baseUrl}${o}`:`${this.getOrigin()}${this.baseUrl}${o}`;if(s!=null&&s.params){const a=new URLSearchParams;for(const[c,l]of Object.entries(s.params))l!=null&&a.set(c,String(l));const i=a.toString();i&&(d+=`?${i}`)}const t=await fetch(d,{method:e,headers:this.headers(),body:s!=null&&s.body?JSON.stringify(s.body):void 0});if(t.status===401&&!(s!=null&&s.retry)&&await this.handleTokenRefresh())return this.request(e,o,{...s,retry:!0});if(!t.ok){let a=`HTTP ${t.status}: ${t.statusText}`;try{const i=await t.json();i!=null&&i.message&&(a=i.message)}catch{}throw new Error(a)}const n=await t.json();if(n.code!=="200")throw new Error(n.message||`API error: ${n.code}`);return g(n.data)}get(e,o){return this.request("GET",e,{params:o})}post(e,o){return this.request("POST",e,{body:o})}patch(e,o){return this.request("PATCH",e,{body:o})}del(e){return this.request("DELETE",e)}async streamPost(e,o,s){if(!this.token&&!await this.handleTokenRefresh())throw new Error("SDK token not available: POST /token failed");const d=this.isAbsoluteUrl?`${this.baseUrl}${e}`:`${this.getOrigin()}${this.baseUrl}${e}`,t=await fetch(d,{method:"POST",headers:this.headers(),body:JSON.stringify(o),signal:s});if(t.status===401){const n=await m.peekCookieExpired(t.clone());if(n.isCookieExpired&&typeof(o==null?void 0:o.message)=="string"){m.stashPendingChat({botCode:this.botCode,message:o.message,sessionId:o.sessionId??""});const i=n.loginUrl??this.loginUrl;return this.onAuthExpired?this.onAuthExpired({loginUrl:i,sessionId:n.sessionId,botCode:this.botCode}):i&&window.location.replace(i),t}if(await this.handleTokenRefresh())return fetch(d,{method:"POST",headers:this.headers(),body:JSON.stringify(o),signal:s})}return t}}function h(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 k(r){const e=r.split(`
|
|
2
2
|
`).map(a=>a.trim()).filter(a=>a.length>0);let o,s,d;for(const a of e)if(a.startsWith("id:"))o=a.slice(3).trim();else if(a.startsWith("event:"))s=a.slice(6).trim();else if(a.startsWith("data:")){const i=a.slice(5).trim();d=d?`${d}
|
|
3
|
-
${i}`:i}if(d===void 0)return null;let t;try{t=JSON.parse(d)}catch{return null}const n=t.type==="tool_result"&&typeof t.content=="object"&&t.content?t.content:void 0;switch(t.type){case"session.start":return{type:"session.start",content:"",sessionId:t.sessionId??t.session_id??"",roundId:t.roundId??t.round_id,event:s,id:o};case"user":return{type:"user",content:h(t.content),event:s,id:o};case"thinking":return{type:"thinking",content:h(t.content),event:s,id:o};case"ai":return{type:"ai",content:h(t.content),event:s,id:o};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??{}),event:s,id:o};case"tool_delta":return{type:"tool_delta",content:typeof t.content=="string"?t.content:"",toolCallId:t.tool_call_id??t.toolCallId??"",event:s,id:o};case"tool_result":{const a=n==null?void 0:n.result;let i;return typeof a=="string"?i=a:a!=null&&typeof a=="object"?i=JSON.stringify(a):n&&typeof n=="object"&&Object.keys(n).length>0?i=JSON.stringify(n):i=h(t.output??""),{type:"tool_result",content:i,toolName:t.name,toolCallId:t.id,artifacts:Array.isArray(t.artifacts)?t.artifacts:void 0,renderMode:(n==null?void 0:n.render_mode)??t.render_mode??t.renderMode,html:(n==null?void 0:n.html)??t.html,markdown:(n==null?void 0:n.markdown)??t.markdown,event:s,id:o}}case"done":return{type:"done",content:h(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id,roundId:t.roundId??t.round_id,artifacts:Array.isArray(t.artifacts)?t.artifacts:void 0,event:s,id:o};case"stop":return{type:"stop",content:h(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id,roundId:t.roundId??t.round_id,event:s,id:o};case"error":return{type:"error",content:t.message??"Unknown error",event:s,id:o};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},event:s,id:o};default:return null}}async function b(r,e,o){if(!r.body){o(new Error("Response body is null"));return}const s=r.body.getReader(),d=new TextDecoder;let t="";try{for(;;){const{value:n,done:a}=await s.read();if(a)break;t+=d.decode(n,{stream:!0});let i;for(;(i=t.indexOf(`
|
|
3
|
+
${i}`:i}if(d===void 0)return null;let t;try{t=JSON.parse(d)}catch{return null}const n=t.type==="tool_result"&&typeof t.content=="object"&&t.content?t.content:void 0;switch(t.type){case"session.start":return{type:"session.start",content:"",sessionId:t.sessionId??t.session_id??"",roundId:t.roundId??t.round_id,event:s,id:o};case"user":return{type:"user",content:h(t.content),event:s,id:o};case"thinking":return{type:"thinking",content:h(t.content),event:s,id:o};case"ai":return{type:"ai",content:h(t.content),event:s,id:o};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??{}),event:s,id:o};case"tool_delta":return{type:"tool_delta",content:typeof t.content=="string"?t.content:"",toolCallId:t.tool_call_id??t.toolCallId??"",event:s,id:o};case"tool_result":{const a=n==null?void 0:n.result;let i;return typeof a=="string"?i=a:a!=null&&typeof a=="object"?i=JSON.stringify(a):n&&typeof n=="object"&&Object.keys(n).length>0?i=JSON.stringify(n):i=h(t.output??""),{type:"tool_result",content:i,toolName:t.name,toolCallId:t.id,artifacts:Array.isArray(t.artifacts)?t.artifacts:void 0,renderMode:(n==null?void 0:n.render_mode)??t.render_mode??t.renderMode,html:(n==null?void 0:n.html)??t.html,markdown:(n==null?void 0:n.markdown)??t.markdown,defaultExpanded:t.default_expanded??t.defaultExpanded,event:s,id:o}}case"done":return{type:"done",content:h(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id,roundId:t.roundId??t.round_id,artifacts:Array.isArray(t.artifacts)?t.artifacts:void 0,event:s,id:o};case"stop":return{type:"stop",content:h(t.content),sessionId:t.sessionId??t.session_id??"",messageId:t.messageId??t.message_id,roundId:t.roundId??t.round_id,event:s,id:o};case"error":return{type:"error",content:t.message??"Unknown error",event:s,id:o};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},event:s,id:o};default:return null}}async function b(r,e,o){if(!r.body){o(new Error("Response body is null"));return}const s=r.body.getReader(),d=new TextDecoder;let t="";try{for(;;){const{value:n,done:a}=await s.read();if(a)break;t+=d.decode(n,{stream:!0});let i;for(;(i=t.indexOf(`
|
|
4
4
|
|
|
5
|
-
`))!==-1;){const c=t.slice(0,i);t=t.slice(i+2);const l=k(c);l&&e(l)}}if(t.trim()){const n=k(t);n&&e(n)}}catch(n){(n==null?void 0:n.name)!=="AbortError"&&o(n instanceof Error?n:new Error(String(n)))}finally{try{s.releaseLock()}catch{}}}function A(r,e){var t;const o=new AbortController,s=e.signal?_(e.signal,o.signal):o.signal,d={botCode:r.getBotCode(),message:e.message,sessionId:e.sessionId,stream:e.stream!==!1,...(t=e.attachments)!=null&&t.length?{attachments:e.attachments.map(({url:n,...a})=>a)}:{}};return d.stream?r.streamPost("/chat",d,s).then(async n=>{var a;if(!n.ok){let i=`HTTP ${n.status}`;try{const c=await n.json();c!=null&&c.message&&(i=c.message)}catch{}(a=e.onError)==null||a.call(e,new Error(i));return}return b(n,i=>{var c,l,u,
|
|
5
|
+
`))!==-1;){const c=t.slice(0,i);t=t.slice(i+2);const l=k(c);l&&e(l)}}if(t.trim()){const n=k(t);n&&e(n)}}catch(n){(n==null?void 0:n.name)!=="AbortError"&&o(n instanceof Error?n:new Error(String(n)))}finally{try{s.releaseLock()}catch{}}}function A(r,e){var t;const o=new AbortController,s=e.signal?_(e.signal,o.signal):o.signal,d={botCode:r.getBotCode(),message:e.message,sessionId:e.sessionId,stream:e.stream!==!1,...(t=e.attachments)!=null&&t.length?{attachments:e.attachments.map(({url:n,...a})=>a)}:{}};return d.stream?r.streamPost("/chat",d,s).then(async n=>{var a;if(!n.ok){let i=`HTTP ${n.status}`;try{const c=await n.json();c!=null&&c.message&&(i=c.message)}catch{}(a=e.onError)==null||a.call(e,new Error(i));return}return b(n,i=>{var c,l,f,u,y,I,p,w;i.type==="done"&&i.sessionId?((c=e.onMessage)==null||c.call(e,i),(l=e.onDone)==null||l.call(e,{sessionId:i.sessionId,content:i.content,messageId:i.messageId,roundId:i.roundId,artifacts:i.artifacts})):i.type==="done"?((f=e.onMessage)==null||f.call(e,i),(u=e.onDone)==null||u.call(e,{sessionId:"",content:i.content,messageId:i.messageId,roundId:i.roundId,artifacts:i.artifacts})):i.type==="stop"?((y=e.onMessage)==null||y.call(e,i),(I=e.onDone)==null||I.call(e,{sessionId:i.sessionId??"",content:i.content,messageId:i.messageId,roundId:i.roundId})):i.type==="error"?(p=e.onError)==null||p.call(e,new Error(i.content)):(w=e.onMessage)==null||w.call(e,i)},i=>{var c;return(c=e.onError)==null?void 0:c.call(e,i)})}).catch(n=>{var a;(n==null?void 0:n.name)!=="AbortError"&&((a=e.onError)==null||a.call(e,n instanceof Error?n:new Error(String(n))))}):r.post("/chat",d).then(n=>{var a;(a=e.onDone)==null||a.call(e,{sessionId:n.sessionId,content:n.content??"",messageId:n.messageId})}).catch(n=>{var a;(a=e.onError)==null||a.call(e,n instanceof Error?n:new Error(String(n)))}),o}function _(r,e){const o=new AbortController,s=()=>o.abort();return r.addEventListener("abort",s,{once:!0}),e.addEventListener("abort",s,{once:!0}),(r.aborted||e.aborted)&&o.abort(),o.signal}async function $(r){return(await r.post("/chat/sessions",{botCode:r.getBotCode()})).sessionId}function x(r){return{sessionId:r.threadId??r.sessionId,title:r.title,createTime:r.createTime,updateTime:r.updateTime}}async function E(r,e){const o=await r.get("/chat/conversations",{botCode:r.getBotCode(),page:(e==null?void 0:e.page)??1,size:(e==null?void 0:e.size)??20});return{...o,items:o.items.map(x)}}async function P(r,e,o){await r.patch(`/chat/conversations/${e}`,{title:o})}async function v(r,e){await r.del(`/chat/conversations/${e}`)}async function O(r,e){const o=await r.get(`/chat/conversations/${e}/messages`);return U(o)}function T(){return`r_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}function U(r){var d;const e=r.length>0&&Array.isArray((d=r[0])==null?void 0:d.data),o=[];if(e)for(const t of r)o.push({roundId:t.roundId??T(),artifacts:Array.isArray(t.artifacts)&&t.artifacts.length?t.artifacts:void 0,items:Array.isArray(t.data)?t.data:[]});else o.push({roundId:T(),items:r});const s=[];for(const t of o){const n=M(t.items);for(const a of n)a.roundId=t.roundId;if(t.artifacts){const a=n.findLast(i=>i.role==="assistant");a&&(a.artifacts=t.artifacts)}s.push(...n)}return s}function M(r){var n;const e=[...r].sort((a,i)=>{const c=new Date(a.createTime??0).getTime()||0,l=new Date(i.createTime??0).getTime()||0;return c!==l?c-l:(a.seq??0)-(i.seq??0)}),o=new Map;for(const a of e)a.role==="tool"&&a.toolCallId&&o.set(a.toolCallId,a.content||"");const s=new Set,d=[],t=(a,i,c,l,f)=>{const u=d[d.length-1];(u==null?void 0:u.role)==="assistant"?(u.parts.push(...a),u.id=i,l&&(u.messageId=l,u.feedback=f??null)):d.push({id:i,role:"assistant",parts:[...a],timestamp:c,messageId:l,feedback:f??null})};for(const a of e){if(a.role==="system")continue;const i=String(a.id??a.messageId??`msg_${Date.now()}`),c=new Date(a.createTime??"").getTime()||Date.now();if(a.role==="human"){const l=(a.attachments??[]).map(u=>({type:"attachment",attachment:{nosKey:u.nosKey??u.attachmentId??"",filename:u.filename??"file",size:u.size??void 0,mime:u.mime??void 0,url:u.url??void 0}})),f=(n=a.metadata)==null?void 0:n.raw_message;d.push({id:i,role:"user",parts:[...l,{type:"text",content:h(a.content)}],timestamp:c,messageId:a.messageId,rawContent:typeof f=="string"&&f?f:void 0});continue}if(a.role==="ai"){const l=N(a,o,s);l.length>0&&t(l,i,c,a.messageId,a.feedback);continue}if(a.role==="tool"){if(a.toolCallId&&s.has(a.toolCallId))continue;t([j(a)],i,c)}}return d}function N(r,e,o){const s=[];r.reasoning&&s.push({type:"thinking",content:r.reasoning}),r.content&&s.push({type:"text",content:h(r.content)});for(const d of r.toolCalls??[])d.is_interrupt??d.isInterrupt?(o.add(d.id),s.push(D(d,e))):s.push(q(d));return s}function D(r,e){const o=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:o,response:o?{action:"submit",value:J(e.get(r.id))}:void 0}}function q(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 j(r){var o,s,d,t,n;const e=Array.isArray(r.artifacts)?r.artifacts:void 0;return{type:"tool_result",toolName:r.toolName??"",toolCallId:r.toolCallId??"",content:h(r.content),artifacts:e,renderMode:r.renderMode??((o=r.metadata)==null?void 0:o.renderMode)??((s=r.metadata)==null?void 0:s.render_mode),html:r.html??((d=r.metadata)==null?void 0:d.html),markdown:r.markdown??((t=r.metadata)==null?void 0:t.markdown),defaultExpanded:r.defaultExpanded??((n=r.metadata)==null?void 0:n.default_expanded)}}function J(r){if(r!=null)try{return JSON.parse(r)}catch{return r}}async function L(r,e,o,s,d,t,n){const a=await r.streamPost(`/chat/interrupt/${e}/respond`,{sessionId:o,action:s.action,value:s.value},n);if(!a.ok){const i=new Error(`HTTP ${a.status}`);throw t==null||t(i),i}d&&await b(a,i=>{i.type==="error"?t==null||t(new Error(i.content)):d(i)},i=>t==null?void 0:t(i))}async function G(r){return r.get(`/chat/bots/${r.getBotCode()}/skills`)}async function R(r,e){await r.post("/chat/stop",{sessionId:e})}function B(r){const e=new C(r);return{botCode:e.getBotCode(),getToken:()=>e.fetchToken(),createSession:()=>$(e),chat:s=>A(e,s),listConversations:s=>E(e,s),renameConversation:(s,d)=>P(e,s,d),deleteConversation:s=>v(e,s),getMessages:s=>O(e,s),respondInterrupt:(s,d,t,n,a,i)=>L(e,s,d,t,n,a,i),setToken:s=>e.setToken(s),feedback:async(s,d,t)=>{const n={type:d};d==="dislike"&&((t==null?void 0:t.reason)!=null&&(n.reason=t.reason),t!=null&&t.remark&&(n.remark=t.remark)),await e.post(`/chat/messages/${s}/feedback`,n)},cancelFeedback:async s=>{await e.del(`/chat/messages/${s}/feedback`)},listSkills:()=>G(e),stopGeneration:s=>R(e,s)}}exports.createNosUploader=m.createNosUploader;exports.createSuperAgent=B;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare interface ChatEvent {
|
|
|
36
36
|
renderMode?: string;
|
|
37
37
|
html?: string;
|
|
38
38
|
markdown?: string;
|
|
39
|
+
defaultExpanded?: boolean;
|
|
39
40
|
roundId?: string;
|
|
40
41
|
event?: string;
|
|
41
42
|
id?: string;
|
|
@@ -128,6 +129,14 @@ export declare interface ListConversationsResult {
|
|
|
128
129
|
total: number;
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
/** 消息反馈(赞/踩)。type 为 like/dislike;reason/remark 仅 dislike 有值。
|
|
133
|
+
* 历史加载时由消息列表的 feedback 字段还原,供赞/踩按钮回显已选态。 */
|
|
134
|
+
export declare interface MessageFeedback {
|
|
135
|
+
type: "like" | "dislike";
|
|
136
|
+
reason?: number | null;
|
|
137
|
+
remark?: string | null;
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
export declare type MessagePart = {
|
|
132
141
|
type: "text";
|
|
133
142
|
content: string;
|
|
@@ -149,6 +158,7 @@ export declare type MessagePart = {
|
|
|
149
158
|
renderMode?: string;
|
|
150
159
|
html?: string;
|
|
151
160
|
markdown?: string;
|
|
161
|
+
defaultExpanded?: boolean;
|
|
152
162
|
} | {
|
|
153
163
|
type: "error";
|
|
154
164
|
content: string;
|
|
@@ -251,6 +261,9 @@ export declare interface UIMessage {
|
|
|
251
261
|
* feedback / cancelFeedback 按它定位消息(不是表主键 id)。来源二选一:
|
|
252
262
|
* 历史加载取消息列表的 messageId;流式消息取 done/stop 帧的 messageId。 */
|
|
253
263
|
messageId?: string;
|
|
264
|
+
/** 该消息已有的反馈(历史加载还原,无则 null/undefined):赞/踩按钮据此显示已选态。
|
|
265
|
+
* 流式消息不携带(新回复尚无反馈)。 */
|
|
266
|
+
feedback?: MessageFeedback | null;
|
|
254
267
|
roundId?: string;
|
|
255
268
|
artifacts?: Artifact[];
|
|
256
269
|
/** 用户消息原文(含技能 "/code" 前缀;parts 文本展示 "/技能名" 版本时两者不同)。
|
package/dist/index.mjs
CHANGED
|
@@ -244,6 +244,7 @@ ${i}` : i;
|
|
|
244
244
|
renderMode: (n == null ? void 0 : n.render_mode) ?? t.render_mode ?? t.renderMode,
|
|
245
245
|
html: (n == null ? void 0 : n.html) ?? t.html,
|
|
246
246
|
markdown: (n == null ? void 0 : n.markdown) ?? t.markdown,
|
|
247
|
+
defaultExpanded: t.default_expanded ?? t.defaultExpanded,
|
|
247
248
|
event: s,
|
|
248
249
|
id: o
|
|
249
250
|
};
|
|
@@ -356,8 +357,8 @@ function _(r, e) {
|
|
|
356
357
|
return T(
|
|
357
358
|
n,
|
|
358
359
|
(i) => {
|
|
359
|
-
var c, l,
|
|
360
|
-
i.type === "done" && i.sessionId ? ((c = e.onMessage) == null || c.call(e, i), (l = e.onDone) == null || l.call(e, { sessionId: i.sessionId, content: i.content, messageId: i.messageId, roundId: i.roundId, artifacts: i.artifacts })) : i.type === "done" ? ((
|
|
360
|
+
var c, l, f, u, m, y, I, p;
|
|
361
|
+
i.type === "done" && i.sessionId ? ((c = e.onMessage) == null || c.call(e, i), (l = e.onDone) == null || l.call(e, { sessionId: i.sessionId, content: i.content, messageId: i.messageId, roundId: i.roundId, artifacts: i.artifacts })) : i.type === "done" ? ((f = e.onMessage) == null || f.call(e, i), (u = e.onDone) == null || u.call(e, { sessionId: "", content: i.content, messageId: i.messageId, roundId: i.roundId, artifacts: i.artifacts })) : i.type === "stop" ? ((m = e.onMessage) == null || m.call(e, i), (y = e.onDone) == null || y.call(e, { sessionId: i.sessionId ?? "", content: i.content, messageId: i.messageId, roundId: i.roundId })) : i.type === "error" ? (I = e.onError) == null || I.call(e, new Error(i.content)) : (p = e.onMessage) == null || p.call(e, i);
|
|
361
362
|
},
|
|
362
363
|
(i) => {
|
|
363
364
|
var c;
|
|
@@ -383,12 +384,12 @@ function $(r, e) {
|
|
|
383
384
|
const o = new AbortController(), s = () => o.abort();
|
|
384
385
|
return r.addEventListener("abort", s, { once: !0 }), e.addEventListener("abort", s, { once: !0 }), (r.aborted || e.aborted) && o.abort(), o.signal;
|
|
385
386
|
}
|
|
386
|
-
async function
|
|
387
|
+
async function x(r) {
|
|
387
388
|
return (await r.post("/chat/sessions", {
|
|
388
389
|
botCode: r.getBotCode()
|
|
389
390
|
})).sessionId;
|
|
390
391
|
}
|
|
391
|
-
function
|
|
392
|
+
function E(r) {
|
|
392
393
|
return {
|
|
393
394
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
394
395
|
sessionId: r.threadId ?? r.sessionId,
|
|
@@ -399,7 +400,7 @@ function v(r) {
|
|
|
399
400
|
updateTime: r.updateTime
|
|
400
401
|
};
|
|
401
402
|
}
|
|
402
|
-
async function
|
|
403
|
+
async function P(r, e) {
|
|
403
404
|
const o = await r.get("/chat/conversations", {
|
|
404
405
|
botCode: r.getBotCode(),
|
|
405
406
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
@@ -407,10 +408,10 @@ async function x(r, e) {
|
|
|
407
408
|
});
|
|
408
409
|
return {
|
|
409
410
|
...o,
|
|
410
|
-
items: o.items.map(
|
|
411
|
+
items: o.items.map(E)
|
|
411
412
|
};
|
|
412
413
|
}
|
|
413
|
-
async function
|
|
414
|
+
async function v(r, e, o) {
|
|
414
415
|
await r.patch(`/chat/conversations/${e}`, { title: o });
|
|
415
416
|
}
|
|
416
417
|
async function O(r, e) {
|
|
@@ -457,14 +458,15 @@ function N(r) {
|
|
|
457
458
|
}), o = /* @__PURE__ */ new Map();
|
|
458
459
|
for (const a of e)
|
|
459
460
|
a.role === "tool" && a.toolCallId && o.set(a.toolCallId, a.content || "");
|
|
460
|
-
const s = /* @__PURE__ */ new Set(), d = [], t = (a, i, c, l) => {
|
|
461
|
+
const s = /* @__PURE__ */ new Set(), d = [], t = (a, i, c, l, f) => {
|
|
461
462
|
const u = d[d.length - 1];
|
|
462
|
-
(u == null ? void 0 : u.role) === "assistant" ? (u.parts.push(...a), u.id = i, l && (u.messageId = l)) : d.push({
|
|
463
|
+
(u == null ? void 0 : u.role) === "assistant" ? (u.parts.push(...a), u.id = i, l && (u.messageId = l, u.feedback = f ?? null)) : d.push({
|
|
463
464
|
id: i,
|
|
464
465
|
role: "assistant",
|
|
465
466
|
parts: [...a],
|
|
466
467
|
timestamp: c,
|
|
467
|
-
messageId: l
|
|
468
|
+
messageId: l,
|
|
469
|
+
feedback: f ?? null
|
|
468
470
|
});
|
|
469
471
|
};
|
|
470
472
|
for (const a of e) {
|
|
@@ -472,32 +474,32 @@ function N(r) {
|
|
|
472
474
|
const i = String(a.id ?? a.messageId ?? `msg_${Date.now()}`), c = new Date(a.createTime ?? "").getTime() || Date.now();
|
|
473
475
|
if (a.role === "human") {
|
|
474
476
|
const l = (a.attachments ?? []).map(
|
|
475
|
-
(
|
|
477
|
+
(u) => ({
|
|
476
478
|
type: "attachment",
|
|
477
479
|
attachment: {
|
|
478
|
-
nosKey:
|
|
480
|
+
nosKey: u.nosKey ?? u.attachmentId ?? "",
|
|
479
481
|
// 历史回显后端不带 nosKey,占位空串
|
|
480
|
-
filename:
|
|
481
|
-
size:
|
|
482
|
-
mime:
|
|
483
|
-
url:
|
|
482
|
+
filename: u.filename ?? "file",
|
|
483
|
+
size: u.size ?? void 0,
|
|
484
|
+
mime: u.mime ?? void 0,
|
|
485
|
+
url: u.url ?? void 0
|
|
484
486
|
// 公开读桶下载链接(有则 chip 可点击下载)
|
|
485
487
|
}
|
|
486
488
|
})
|
|
487
|
-
),
|
|
489
|
+
), f = (n = a.metadata) == null ? void 0 : n.raw_message;
|
|
488
490
|
d.push({
|
|
489
491
|
id: i,
|
|
490
492
|
role: "user",
|
|
491
493
|
parts: [...l, { type: "text", content: h(a.content) }],
|
|
492
494
|
timestamp: c,
|
|
493
495
|
messageId: a.messageId,
|
|
494
|
-
rawContent: typeof
|
|
496
|
+
rawContent: typeof f == "string" && f ? f : void 0
|
|
495
497
|
});
|
|
496
498
|
continue;
|
|
497
499
|
}
|
|
498
500
|
if (a.role === "ai") {
|
|
499
501
|
const l = D(a, o, s);
|
|
500
|
-
l.length > 0 && t(l, i, c, a.messageId);
|
|
502
|
+
l.length > 0 && t(l, i, c, a.messageId, a.feedback);
|
|
501
503
|
continue;
|
|
502
504
|
}
|
|
503
505
|
if (a.role === "tool") {
|
|
@@ -549,7 +551,7 @@ function J(r) {
|
|
|
549
551
|
};
|
|
550
552
|
}
|
|
551
553
|
function L(r) {
|
|
552
|
-
var o, s, d, t;
|
|
554
|
+
var o, s, d, t, n;
|
|
553
555
|
const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
|
|
554
556
|
return {
|
|
555
557
|
type: "tool_result",
|
|
@@ -560,7 +562,8 @@ function L(r) {
|
|
|
560
562
|
artifacts: e,
|
|
561
563
|
renderMode: r.renderMode ?? ((o = r.metadata) == null ? void 0 : o.renderMode) ?? ((s = r.metadata) == null ? void 0 : s.render_mode),
|
|
562
564
|
html: r.html ?? ((d = r.metadata) == null ? void 0 : d.html),
|
|
563
|
-
markdown: r.markdown ?? ((t = r.metadata) == null ? void 0 : t.markdown)
|
|
565
|
+
markdown: r.markdown ?? ((t = r.metadata) == null ? void 0 : t.markdown),
|
|
566
|
+
defaultExpanded: r.defaultExpanded ?? ((n = r.metadata) == null ? void 0 : n.default_expanded)
|
|
564
567
|
};
|
|
565
568
|
}
|
|
566
569
|
function j(r) {
|
|
@@ -604,10 +607,10 @@ function z(r) {
|
|
|
604
607
|
return {
|
|
605
608
|
botCode: e.getBotCode(),
|
|
606
609
|
getToken: () => e.fetchToken(),
|
|
607
|
-
createSession: () =>
|
|
610
|
+
createSession: () => x(e),
|
|
608
611
|
chat: (s) => _(e, s),
|
|
609
|
-
listConversations: (s) =>
|
|
610
|
-
renameConversation: (s, d) =>
|
|
612
|
+
listConversations: (s) => P(e, s),
|
|
613
|
+
renameConversation: (s, d) => v(e, s, d),
|
|
611
614
|
deleteConversation: (s) => O(e, s),
|
|
612
615
|
getMessages: (s) => U(e, s),
|
|
613
616
|
respondInterrupt: (s, d, t, n, a, i) => G(e, s, d, t, n, a, i),
|