super-agent-sdk 1.0.0 → 1.0.1
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 +16 -16
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# super-agent-sdk
|
|
2
2
|
|
|
3
3
|
Super Agent Web SDK —— 为 `super-agent-service` 提供的一站式浏览器端集成方案:既包含纯 JS 的 API 调用层(鉴权、SSE 流式解析、会话与消息接口),也包含开箱即用的嵌入式 React 聊天组件。
|
|
4
4
|
|
|
@@ -21,12 +21,12 @@ Super Agent Web SDK —— 为 `super-agent-service` 提供的一站式浏览器
|
|
|
21
21
|
|
|
22
22
|
## 1. 概述
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
`super-agent-sdk` 提供两个入口:
|
|
25
25
|
|
|
26
26
|
| 入口 | 说明 | 依赖 |
|
|
27
27
|
| ------------------------- | ---------------------------------------------------------- | ---------- |
|
|
28
|
-
|
|
|
29
|
-
|
|
|
28
|
+
| `super-agent-sdk` | 纯 JS API 调用层,封装鉴权、SSE 流式解析、会话与消息接口 | 无 UI 依赖 |
|
|
29
|
+
| `super-agent-sdk/widget` | 可嵌入式 React 聊天组件 | React 18+ |
|
|
30
30
|
|
|
31
31
|
核心能力:
|
|
32
32
|
|
|
@@ -40,7 +40,7 @@ Super Agent Web SDK —— 为 `super-agent-service` 提供的一站式浏览器
|
|
|
40
40
|
## 2. 安装
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
-
pnpm add
|
|
43
|
+
pnpm add super-agent-sdk
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
纯 API 模式无需任何额外依赖。若使用聊天组件(widget),需同时安装 React:
|
|
@@ -58,8 +58,8 @@ pnpm add react react-dom
|
|
|
58
58
|
最简 5 行接入:
|
|
59
59
|
|
|
60
60
|
```typescript
|
|
61
|
-
import { createSuperAgent } from "
|
|
62
|
-
import { mount } from "
|
|
61
|
+
import { createSuperAgent } from "super-agent-sdk";
|
|
62
|
+
import { mount } from "super-agent-sdk/widget";
|
|
63
63
|
|
|
64
64
|
const sdk = createSuperAgent({ baseUrl: "/api/v1", botId: 1 });
|
|
65
65
|
// Token 自动获取,无需手动设置
|
|
@@ -332,7 +332,7 @@ SDK 方法 → 后端接口的完整映射:
|
|
|
332
332
|
|
|
333
333
|
## 6. 聊天组件
|
|
334
334
|
|
|
335
|
-
组件通过 `mount()` 从
|
|
335
|
+
组件通过 `mount()` 从 `super-agent-sdk/widget` 导入。
|
|
336
336
|
|
|
337
337
|
### 6.1 mount()
|
|
338
338
|
|
|
@@ -363,8 +363,8 @@ export interface WidgetInstance {
|
|
|
363
363
|
```
|
|
364
364
|
|
|
365
365
|
```ts
|
|
366
|
-
import { createSuperAgent } from "
|
|
367
|
-
import { mount } from "
|
|
366
|
+
import { createSuperAgent } from "super-agent-sdk";
|
|
367
|
+
import { mount } from "super-agent-sdk/widget";
|
|
368
368
|
|
|
369
369
|
const sdk = createSuperAgent({ baseUrl: "/api/v1", botId: 1 });
|
|
370
370
|
|
|
@@ -475,7 +475,7 @@ mount("#chat-root", {
|
|
|
475
475
|
|
|
476
476
|
### 8.3 组件插槽(Slots)
|
|
477
477
|
|
|
478
|
-
通过 `slots` 替换内置子组件。所有插槽 Props 均从
|
|
478
|
+
通过 `slots` 替换内置子组件。所有插槽 Props 均从 `super-agent-sdk/widget` 导出。
|
|
479
479
|
|
|
480
480
|
```ts
|
|
481
481
|
export interface Slots {
|
|
@@ -865,14 +865,14 @@ mount("#chat-root", {
|
|
|
865
865
|
|
|
866
866
|
```tsx
|
|
867
867
|
import React, { useState } from "react";
|
|
868
|
-
import { createSuperAgent } from "
|
|
869
|
-
import { mount, Icon } from "
|
|
868
|
+
import { createSuperAgent } from "super-agent-sdk";
|
|
869
|
+
import { mount, Icon } from "super-agent-sdk/widget";
|
|
870
870
|
import type {
|
|
871
871
|
HeaderProps,
|
|
872
872
|
MessageProps,
|
|
873
873
|
ActionBarProps,
|
|
874
874
|
WelcomeScreenProps,
|
|
875
|
-
} from "
|
|
875
|
+
} from "super-agent-sdk/widget";
|
|
876
876
|
|
|
877
877
|
const sdk = createSuperAgent({ baseUrl: "/api/v1", botId: 1 });
|
|
878
878
|
sdk.setToken("demo_app", "demo_token");
|
|
@@ -1199,7 +1199,7 @@ export interface ChatEvent {
|
|
|
1199
1199
|
不挂载组件,仅使用 API 层构建自己的 UI:
|
|
1200
1200
|
|
|
1201
1201
|
```ts
|
|
1202
|
-
import { createSuperAgent } from "
|
|
1202
|
+
import { createSuperAgent } from "super-agent-sdk";
|
|
1203
1203
|
|
|
1204
1204
|
const sdk = createSuperAgent({ baseUrl: "/api/v1", botId: 1 });
|
|
1205
1205
|
sdk.setToken("<APP_ID>", "<TOKEN>");
|
|
@@ -1220,7 +1220,7 @@ sdk.chat({
|
|
|
1220
1220
|
|
|
1221
1221
|
### 12.2 使用 Hooks
|
|
1222
1222
|
|
|
1223
|
-
从
|
|
1223
|
+
从 `super-agent-sdk/widget` 导出 `useChat`、`useConversations`,可在自己的 React 应用中复用:
|
|
1224
1224
|
|
|
1225
1225
|
```ts
|
|
1226
1226
|
export function useChat(options: UseChatOptions): UseChatReturn;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "super-agent-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Super Agent Web SDK — API + 嵌入式聊天组件",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"vite-plugin-dts": "^4.0.0"
|
|
48
48
|
},
|
|
49
49
|
"license": "MIT"
|
|
50
|
-
}
|
|
50
|
+
}
|