super-agent-sdk 1.0.21 → 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 +14 -10
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +24 -2
- package/dist/index.mjs +306 -285
- package/dist/{mammoth.browser-BWTaSUmQ.cjs → mammoth.browser-CKp13R4W.cjs} +63 -63
- package/dist/{mammoth.browser-DFPCY35d.js → mammoth.browser-_e1UoKEX.js} +3708 -3725
- package/dist/{nosUploader-DjJ7u2B1.js → nosUploader-2VXYPLap.js} +2 -1
- package/dist/{nosUploader-DLX7JsnR.cjs → nosUploader-Dk2GyRpT.cjs} +4 -4
- package/dist/{purify.es-CImoWRjX.js → purify.es-C-6FFqDW.js} +205 -214
- package/dist/purify.es-Dsdnkgrg.cjs +3 -0
- package/dist/widget.cjs +323 -29
- package/dist/widget.d.ts +56 -11
- package/dist/widget.mjs +27999 -5544
- package/package.json +3 -1
- package/dist/purify.es-BnmCBz16.cjs +0 -3
package/README.md
CHANGED
|
@@ -201,7 +201,7 @@ export interface ChatOptions {
|
|
|
201
201
|
messageId?: string;
|
|
202
202
|
roundId?: string; // 本轮对话 id(session.start/session.done 携带)
|
|
203
203
|
artifacts?: Artifact[]; // done 汇总的本轮文件产物(generate_file 等交付产物)
|
|
204
|
-
}) => void; // messageId
|
|
204
|
+
}) => void; // messageId:done/stop 事件带回的后端消息标识(= conversation_messages.message_id,feedback 按它定位;未带回时 SDK 回查历史兜底)
|
|
205
205
|
signal?: AbortSignal;
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -352,23 +352,23 @@ sdk.setToken("<TOKEN>");
|
|
|
352
352
|
|
|
353
353
|
消息反馈(赞/踩)。调用 `sdk.feedback()` 发送 `POST /chat/messages/{messageId}/feedback`;调用 `sdk.cancelFeedback()` 发送 `DELETE` 取消反馈。
|
|
354
354
|
|
|
355
|
-
> **messageId
|
|
355
|
+
> **messageId 说明**:即消息列表里的 `messageId`(后端 `conversation_messages.message_id`,langchain 原始消息 id,UUID 字符串),**不是** `UIMessage.id`(历史加载为表主键、流式为客户端临时 id,仅作渲染 key)。纯 API 模式从 `getMessages()` 结果取 `UIMessage.messageId`;流式消息由 `done`/`stop` 事件(`onDone` 的 `messageId`)带回,两者都有时以帧内为准。
|
|
356
356
|
|
|
357
357
|
```ts
|
|
358
358
|
const messages = await sdk.getMessages(sessionId);
|
|
359
359
|
const aiMsg = messages.findLast((m) => m.role === "assistant");
|
|
360
360
|
|
|
361
361
|
// 点赞
|
|
362
|
-
await sdk.feedback(aiMsg.
|
|
362
|
+
await sdk.feedback(aiMsg.messageId!, "like");
|
|
363
363
|
|
|
364
364
|
// 踩(可附原因 + 备注)
|
|
365
|
-
await sdk.feedback(aiMsg.
|
|
365
|
+
await sdk.feedback(aiMsg.messageId!, "dislike", {
|
|
366
366
|
reason: 1, // 1=事实错误 2=逻辑问题 3=不相关 4=信息过时 5=冗长啰嗦 6=难以理解
|
|
367
367
|
remark: "时间描述有误",
|
|
368
368
|
});
|
|
369
369
|
|
|
370
370
|
// 取消反馈
|
|
371
|
-
await sdk.cancelFeedback(aiMsg.
|
|
371
|
+
await sdk.cancelFeedback(aiMsg.messageId!);
|
|
372
372
|
```
|
|
373
373
|
|
|
374
374
|
组件内置的点赞/踩按钮已自动调用 `feedback()`/`cancelFeedback()`:
|
|
@@ -376,7 +376,7 @@ await sdk.cancelFeedback(aiMsg.id);
|
|
|
376
376
|
- 点击已选中的按钮 → 取消(DELETE)
|
|
377
377
|
- 点击另一个按钮 → 切换(POST)
|
|
378
378
|
- 点踩时弹出原因选择面板(可选填原因 + 备注后提交)
|
|
379
|
-
-
|
|
379
|
+
- 消息本身没带 `messageId` 时(如后端 done/stop 帧未回传),SDK 自动拉取一次历史消息,按该消息的 `roundId` 定位到它并取 `messageId` 再发送,业务方无感知
|
|
380
380
|
|
|
381
381
|
### 5.10 respondInterrupt()
|
|
382
382
|
|
|
@@ -928,8 +928,9 @@ export interface ActionBarProps {
|
|
|
928
928
|
message: UIMessage;
|
|
929
929
|
onCopy: () => void;
|
|
930
930
|
onRegenerate?: () => void;
|
|
931
|
+
// 传整条 message(内置 ActionBar 的做法)或 messageId / 本地 id 字符串均可
|
|
931
932
|
onFeedback?: (
|
|
932
|
-
|
|
933
|
+
message: UIMessage | string,
|
|
933
934
|
feedback: "like" | "dislike",
|
|
934
935
|
options?: { reason?: number; remark?: string },
|
|
935
936
|
) => void;
|
|
@@ -1517,10 +1518,11 @@ ac.abort();
|
|
|
1517
1518
|
|
|
1518
1519
|
```ts
|
|
1519
1520
|
export interface UIMessage {
|
|
1520
|
-
id: string;
|
|
1521
|
+
id: string; // 渲染 key:历史加载为表主键,流式为客户端临时 id(不用于 feedback)
|
|
1521
1522
|
role: "user" | "assistant";
|
|
1522
1523
|
parts: MessagePart[];
|
|
1523
1524
|
timestamp: number;
|
|
1525
|
+
messageId?: string; // 后端消息标识(= conversation_messages.message_id),feedback/cancelFeedback 按它定位
|
|
1524
1526
|
roundId?: string; // 本轮对话 id(历史分组 roundId;后端为 null 时 SDK 随机生成)
|
|
1525
1527
|
artifacts?: Artifact[]; // done 汇总的本轮文件产物(历史取分组 artifacts),消息末尾渲染文件卡片
|
|
1526
1528
|
}
|
|
@@ -1546,6 +1548,7 @@ export type MessagePart =
|
|
|
1546
1548
|
renderMode?: string;
|
|
1547
1549
|
html?: string;
|
|
1548
1550
|
markdown?: string;
|
|
1551
|
+
defaultExpanded?: boolean; // config.default_expanded=true 或 renderMode==="html":默认展开
|
|
1549
1552
|
}
|
|
1550
1553
|
| { type: "error"; content: string }
|
|
1551
1554
|
| { type: "attachment"; attachment: ChatAttachment } // 用户消息携带的附件 chip
|
|
@@ -1562,7 +1565,7 @@ export type MessagePart =
|
|
|
1562
1565
|
| `text` | `content` | 文本 / Markdown 内容 |
|
|
1563
1566
|
| `thinking` | `content` | 思考过程(reasoning) |
|
|
1564
1567
|
| `tool_call` | `toolName`, `toolCallId`, `args` | 工具调用,`args` 为 JSON 字符串 |
|
|
1565
|
-
| `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"` |
|
|
1566
1569
|
| `error` | `content` | 错误信息 |
|
|
1567
1570
|
| `attachment` | `attachment` | 用户消息附件 chip(发送时本地构造 / 历史加载由后端映射,有 `url` 时可下载) |
|
|
1568
1571
|
| `interrupt` | `interrupt`, `resolved?`, `response?` | 中断交互卡片(HITL) |
|
|
@@ -1586,12 +1589,13 @@ export interface ChatEvent {
|
|
|
1586
1589
|
toolCallId?: string;
|
|
1587
1590
|
args?: string; // JSON.stringify 后的字符串
|
|
1588
1591
|
sessionId?: string;
|
|
1589
|
-
messageId?: string; // done
|
|
1592
|
+
messageId?: string; // done/stop 事件携带的后端消息标识(= conversation_messages.message_id,feedback 按它定位消息)
|
|
1590
1593
|
interrupt?: InterruptEvent; // interrupt 事件携带中断详情
|
|
1591
1594
|
artifacts?: Artifact[]; // tool_result 顶层产物;done 事件汇总本轮产物(Widget 挂到消息级渲染文件卡片)
|
|
1592
1595
|
renderMode?: string; // "html" 时工具结果为富文本
|
|
1593
1596
|
html?: string; // renderMode==="html" 时的 HTML 内容
|
|
1594
1597
|
markdown?: string; // renderMode==="markdown" 时的 markdown 内容
|
|
1598
|
+
defaultExpanded?: boolean; // tool_result 顶层 default_expanded:结果块默认展开(缺省收起)
|
|
1595
1599
|
roundId?: string; // session.start/done 携带,本轮对话 id
|
|
1596
1600
|
}
|
|
1597
1601
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).map(
|
|
3
|
-
${
|
|
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
|
+
`).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,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,
|
|
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;
|
|
@@ -227,12 +237,14 @@ export declare interface SuperAgentSDK {
|
|
|
227
237
|
/** 响应中断事件(返回 SSE 流,后端继续推送后续事件);signal 供调用方中断续流 */
|
|
228
238
|
respondInterrupt(interruptId: string, sessionId: string, response: InterruptResponse, onMessage?: (event: ChatEvent) => void, onError?: (error: Error) => void, signal?: AbortSignal): Promise<void>;
|
|
229
239
|
setToken(token: string): void;
|
|
230
|
-
/** 消息反馈(赞/踩),POST /chat/messages/{messageId}/feedback
|
|
240
|
+
/** 消息反馈(赞/踩),POST /chat/messages/{messageId}/feedback。
|
|
241
|
+
* messageId = 消息列表的 UIMessage.messageId(后端 conversation_messages.message_id,
|
|
242
|
+
* langchain uuid),不是渲染 key id;流式消息取自 done/stop 事件的 messageId。 */
|
|
231
243
|
feedback(messageId: string, type: "like" | "dislike", options?: {
|
|
232
244
|
reason?: number;
|
|
233
245
|
remark?: string;
|
|
234
246
|
}): Promise<void>;
|
|
235
|
-
/** 取消消息反馈,DELETE /chat/messages/{messageId}/feedback */
|
|
247
|
+
/** 取消消息反馈,DELETE /chat/messages/{messageId}/feedback(messageId 同上) */
|
|
236
248
|
cancelFeedback(messageId: string): Promise<void>;
|
|
237
249
|
/** 获取当前 bot 绑定的 skill 列表,GET /chat/bots/{botCode}/skills(含归属与可选性) */
|
|
238
250
|
listSkills(): Promise<SkillInfo[]>;
|
|
@@ -245,8 +257,18 @@ export declare interface UIMessage {
|
|
|
245
257
|
role: "user" | "assistant";
|
|
246
258
|
parts: MessagePart[];
|
|
247
259
|
timestamp: number;
|
|
260
|
+
/** 后端消息标识(conversation_messages.message_id,langchain 原始 message id uuid):
|
|
261
|
+
* feedback / cancelFeedback 按它定位消息(不是表主键 id)。来源二选一:
|
|
262
|
+
* 历史加载取消息列表的 messageId;流式消息取 done/stop 帧的 messageId。 */
|
|
263
|
+
messageId?: string;
|
|
264
|
+
/** 该消息已有的反馈(历史加载还原,无则 null/undefined):赞/踩按钮据此显示已选态。
|
|
265
|
+
* 流式消息不携带(新回复尚无反馈)。 */
|
|
266
|
+
feedback?: MessageFeedback | null;
|
|
248
267
|
roundId?: string;
|
|
249
268
|
artifacts?: Artifact[];
|
|
269
|
+
/** 用户消息原文(含技能 "/code" 前缀;parts 文本展示 "/技能名" 版本时两者不同)。
|
|
270
|
+
* regenerate 原样重发用;历史加载从后端 metadata.raw_message 还原。 */
|
|
271
|
+
rawContent?: string;
|
|
250
272
|
}
|
|
251
273
|
|
|
252
274
|
export { }
|