super-agent-sdk 1.0.9 → 1.0.10
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 +87 -3
- package/dist/widget.cjs +52 -28
- package/dist/widget.d.ts +73 -3
- package/dist/widget.mjs +1557 -1405
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -430,7 +430,8 @@ export interface QuickLinkItem {
|
|
|
430
430
|
icon?: string; // 图标 URL
|
|
431
431
|
label: string; // 入口名称
|
|
432
432
|
prompt?: string; // 点击后发送的消息
|
|
433
|
-
|
|
433
|
+
action?: PanelAction; // 点击行为:整屏容器 / 外链(优先于 prompt)
|
|
434
|
+
onClick?: () => void; // 自定义点击行为(优先于 action / prompt)
|
|
434
435
|
}
|
|
435
436
|
|
|
436
437
|
export interface WidgetInstance {
|
|
@@ -513,10 +514,10 @@ mount("#chat-root", { sdk, mode: "fullpage", sidebarDefaultOpen: false });
|
|
|
513
514
|
浮窗窗口对齐 hr-for-help 设计,开箱具备以下交互能力:
|
|
514
515
|
|
|
515
516
|
- **标题栏拖拽**:按住顶部导航栏移动窗口(视口内钳制,按钮区域不触发)
|
|
516
|
-
-
|
|
517
|
+
- **左侧拉伸调宽**:窗口左侧 6px 手柄拖拽(右缘稳定不动),宽度范围 360 ~ 800 px,拖超过 800 自动进入大窗
|
|
517
518
|
- **大窗/小窗切换**:header 右侧「大窗」按钮切换;大窗为底部弹出的近全屏 overlay(内容区 800px 居中),回小窗时宽度重置为默认值
|
|
518
519
|
- **内容自适应高度**:聊天内容增长时窗口自动变高(默认 648px,上限 95% 视口,超出后消息区滚动),回到首页恢复默认高度
|
|
519
|
-
- **内嵌会话侧边栏**:header
|
|
520
|
+
- **内嵌会话侧边栏**:header「历史记录」按钮开合;小窗下侧边栏紧贴窗口左缘向外展开(无缝拼接为一个连续圆角窗口,主区位置不动);大窗模式自动展开(220px),大窗/小窗各自记住用户偏好
|
|
520
521
|
- **关闭即还原**:关闭窗口后几何状态(位置/宽度/大窗态/高度)全部重置
|
|
521
522
|
|
|
522
523
|
浮窗消息展示对齐 hr-for-help:AI 头像独占一行(无背景色,生成中切换动效头像)、气泡白底描边、用户气泡浅蓝右对齐;`fullpage` 模式保持横排头像 + 经典气泡,两者互不影响。
|
|
@@ -610,6 +611,8 @@ export interface Slots {
|
|
|
610
611
|
ErrorPart?: ComponentType<ErrorPartProps>;
|
|
611
612
|
InterruptCard?: ComponentType<InterruptCardProps>;
|
|
612
613
|
WelcomeScreen?: ComponentType<WelcomeScreenProps>;
|
|
614
|
+
/** 首屏底部业务定制容器 */
|
|
615
|
+
AppendContainer?: ComponentType<AppendContainerProps>;
|
|
613
616
|
}
|
|
614
617
|
```
|
|
615
618
|
|
|
@@ -627,6 +630,7 @@ export interface Slots {
|
|
|
627
630
|
| `ToolResultPart` | `ToolResultPartProps` | 工具返回卡片(pre 滚动 + 复制;`renderMode==="html"` 时 DOMPurify 清洗后直接渲染,最高 60vh 滚动) |
|
|
628
631
|
| `ErrorPart` | `ErrorPartProps` | 错误提示块 |
|
|
629
632
|
| `WelcomeScreen` | `WelcomeScreenProps` | 空会话欢迎页 |
|
|
633
|
+
| `AppendContainer`| `AppendContainerProps`| 首屏底部业务定制区,`openPanel(action)` 开整屏容器或外链(见下) |
|
|
630
634
|
|
|
631
635
|
#### Trigger
|
|
632
636
|
|
|
@@ -965,6 +969,86 @@ function MyErrorPart({ content, onRetry }: ErrorPartProps) {
|
|
|
965
969
|
}
|
|
966
970
|
```
|
|
967
971
|
|
|
972
|
+
#### AppendContainer(首屏业务定制 + 整屏容器)
|
|
973
|
+
|
|
974
|
+
首屏(无消息时)在 `WelcomeScreen` 之下预留一块业务定制区,浮窗与全屏模式共用;未配置则不产生任何 DOM。
|
|
975
|
+
用法就一句话:**点一下,`openPanel(action)`**——可视区始终在 chatPanel 内(`link` 除外)。
|
|
976
|
+
|
|
977
|
+
```ts
|
|
978
|
+
export type PanelContent = ComponentType<PageProps> | ReactElement; // 组件类型,或带参数的元素
|
|
979
|
+
export type PanelAction =
|
|
980
|
+
| { type: 'page'; component: PanelContent; title?: string } // 整屏容器
|
|
981
|
+
| { type: 'link'; url: string; target?: '_blank' | '_self' }; // 外链
|
|
982
|
+
|
|
983
|
+
export interface AppendContainerProps { openPanel: (action: PanelAction) => void }
|
|
984
|
+
export interface PageProps { close: () => void }
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
```tsx
|
|
988
|
+
function ReportPage({ close }: PageProps) {
|
|
989
|
+
return (
|
|
990
|
+
<div style={{ padding: 16 }}>
|
|
991
|
+
报告内容……
|
|
992
|
+
<button onClick={close}>返回</button>
|
|
993
|
+
</div>
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function MyHomeBlock({ openPanel }: AppendContainerProps) {
|
|
998
|
+
return (
|
|
999
|
+
<>
|
|
1000
|
+
<button onClick={() => openPanel({ type: "page", component: ReportPage, title: "全景报告" })}>
|
|
1001
|
+
整屏容器
|
|
1002
|
+
</button>
|
|
1003
|
+
<button onClick={() => openPanel({ type: "link", url: "https://example.com" })}>
|
|
1004
|
+
新窗口外链
|
|
1005
|
+
</button>
|
|
1006
|
+
</>
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
mount("#app", { sdk, slots: { AppendContainer: MyHomeBlock } });
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
要开「第 3 条记录」这类带参数的页面,直接给**元素**,SDK 用 `cloneElement` 补上 `close`:
|
|
1014
|
+
|
|
1015
|
+
```tsx
|
|
1016
|
+
// 元素形态下 close 声明为可选,才能写 <DetailPage id={3} />(运行时 SDK 必然注入)
|
|
1017
|
+
function DetailPage({ id, close }: { id: number; close?: () => void }) {
|
|
1018
|
+
return <button onClick={close}>详情 #{id} 返回</button>;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
openPanel({ type: "page", component: <DetailPage id={3} />, title: "详情 #3" });
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
给组件类型(`component: DetailPage`)时 `close` 是必填 prop,同样由 SDK 注入。
|
|
1025
|
+
|
|
1026
|
+
连定制区都不想写?首屏「快速入口」吃同一个 `action`,纯配置即可接入(`title` 缺省用 `label`):
|
|
1027
|
+
|
|
1028
|
+
```tsx
|
|
1029
|
+
mount("#app", {
|
|
1030
|
+
sdk,
|
|
1031
|
+
quickLinks: [
|
|
1032
|
+
{ label: "全景报告", action: { type: "page", component: ReportPage } },
|
|
1033
|
+
{ label: "帮助文档", action: { type: "link", url: "https://example.com/help" } },
|
|
1034
|
+
],
|
|
1035
|
+
});
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
点击优先级:`onClick > action > prompt`。
|
|
1039
|
+
|
|
1040
|
+
整屏容器行为:
|
|
1041
|
+
|
|
1042
|
+
| 项 | 表现 |
|
|
1043
|
+
| --- | --- |
|
|
1044
|
+
| 呈现 | 替换「内容区 + 输入区」,Header 保留(小窗仍可拖拽);`link` 走 `window.open`,不占状态 |
|
|
1045
|
+
| 标题栏 | 返回箭头 + `title`(可选);`Esc` 等价返回 |
|
|
1046
|
+
| 窗口几何 | 保持打开前窗态,小窗不自动升大窗;内容在容器内滚动(业务页不写滚动容器) |
|
|
1047
|
+
| 关闭 | 返回 / `close()` / `Esc`;关闭聊天面板时一并清掉 |
|
|
1048
|
+
| 栈 | 单层不叠栈,容器内部导航由业务组件自己管 |
|
|
1049
|
+
|
|
1050
|
+
注意:浮层组件渲染在 SDK 自己的 `createRoot` 树内,拿不到宿主的 React Context / Router。组件引用直接给,不需要注册表——类型即校验。
|
|
1051
|
+
|
|
968
1052
|
### 8.4 事件钩子(EventHooks)
|
|
969
1053
|
|
|
970
1054
|
通过 `hooks` 监听组件生命周期与交互事件:
|