sse-stream-plugin-react 0.0.0-stage → 1.1.0
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/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +200 -3
- package/dist/index.cjs +138 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.mjs +136 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +40 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
本文件记录 sse-stream-plugin-react 的版本变更。
|
|
4
|
+
|
|
5
|
+
格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
6
|
+
|
|
7
|
+
## [1.1.0] - 2026-11-19
|
|
8
|
+
|
|
9
|
+
### 新增
|
|
10
|
+
|
|
11
|
+
- 新增 `resume()`:复用当前实例从断点续传;实例不存在或上次流已正常结束时自动退化为重新开始。
|
|
12
|
+
- 新增 `restart()`:销毁旧实例并清空输出,从头重新请求(与原 `start()` 行为一致)。
|
|
13
|
+
- 新增 `close()`:销毁实例与订阅并复位状态,用于「直接停止」;已输出内容保留。
|
|
14
|
+
- 新增 `closed` 事件监听:无论通过 `close()` 还是直接调用 `instance.destroy()`,`status` / `loading` / `instance` 都会同步复位。
|
|
15
|
+
- 订阅 `connecting` 事件:自动重连或续传期间 `loading` 能正确恢复为 `true`。
|
|
16
|
+
|
|
17
|
+
### 变更
|
|
18
|
+
|
|
19
|
+
- `stop()` 由调用 `destroy()` 改为调用核心 SDK 新增的 `abort()`:只中断当前流,实例与已输出内容保留,可通过 `resume()` 继续。
|
|
20
|
+
- peerDependencies 中 `sse-stream-plugin-sdk` 升级为 `^1.1.0`(`stop()` 依赖新增的 `abort()`)。
|
|
21
|
+
- `start()` 行为保持不变,等价于 `restart()`。
|
|
22
|
+
|
|
23
|
+
## [1.0.0] - 2026-10-04
|
|
24
|
+
|
|
25
|
+
### 新增
|
|
26
|
+
|
|
27
|
+
- 首次发布。sse-stream-plugin-sdk 的 React Hooks 封装。
|
|
28
|
+
- 提供 `useSSEStream` Hook:以声明式方式管理 SSE 连接,返回流式文本 `text`、加载状态 `loading`、连接状态 `status` 以及 `start` / `stop` 控制方法。
|
|
29
|
+
- 支持 `getBody`(每次发起连接时动态读取请求体)、`onMessage` / `onError` 等回调,并可透传核心 SDK 的 plugins、headers 等全部配置。
|
|
30
|
+
- 自动管理实例生命周期与事件订阅,组件卸载时自动销毁连接。
|
|
31
|
+
- peerDependencies:`react >= 16.8.0`、`sse-stream-plugin-sdk ^1.0.0`。
|
|
32
|
+
- 产物格式:ESM(`dist/index.mjs`)、CJS(`dist/index.cjs`)及 TypeScript 类型声明(`dist/index.d.ts`)。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ryan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,200 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# sse-stream-plugin-react
|
|
2
|
+
|
|
3
|
+
[sse-stream-plugin-sdk](../core) 的 React Hooks 封装。将插件化 SSE SDK 封装为声明式响应式 API,自动管理实例生命周期与事件订阅。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
需要同时安装核心 SDK:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install sse-stream-plugin-react sse-stream-plugin-sdk
|
|
11
|
+
# 或
|
|
12
|
+
pnpm add sse-stream-plugin-react sse-stream-plugin-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> `react` 为 peerDependency,要求 `>=16.8.0`。
|
|
16
|
+
|
|
17
|
+
## 快速开始
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { useSSEStream } from 'sse-stream-plugin-react'
|
|
21
|
+
import { recommendedPlugins } from 'sse-stream-plugin-sdk'
|
|
22
|
+
|
|
23
|
+
function Chat() {
|
|
24
|
+
const { text, loading, status, start, stop } = useSSEStream({
|
|
25
|
+
url: 'https://api.example.com/stream',
|
|
26
|
+
method: 'POST',
|
|
27
|
+
getBody: () => JSON.stringify({ prompt: '你好' }),
|
|
28
|
+
headers: { 'Content-Type': 'application/json' },
|
|
29
|
+
plugins: recommendedPlugins(),
|
|
30
|
+
onMessage: (data) => console.log(data),
|
|
31
|
+
onError: (err) => console.error(err),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div>
|
|
36
|
+
<button onClick={start} disabled={loading}>发送</button>
|
|
37
|
+
<button onClick={stop}>暂停</button>
|
|
38
|
+
<p>{status}</p>
|
|
39
|
+
<pre>{text}</pre>
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### `useSSEStream(options)`
|
|
48
|
+
|
|
49
|
+
#### 入参 `UseSSEStreamOptions`
|
|
50
|
+
|
|
51
|
+
继承 `PluginSSEOptions` 的核心字段,并追加事件回调与动态 body:
|
|
52
|
+
|
|
53
|
+
| 字段 | 类型 | 说明 |
|
|
54
|
+
|------|------|------|
|
|
55
|
+
| `url` | `string` | 请求地址(必填) |
|
|
56
|
+
| `method` | `'GET' \| 'POST'` | 请求方法,默认 `GET` |
|
|
57
|
+
| `body` | `string` | 请求体字符串 |
|
|
58
|
+
| `getBody` | `() => string` | 每次 `start` 时动态生成请求体,优先级高于 `body` |
|
|
59
|
+
| `headers` | `Record<string, string>` | 自定义请求头 |
|
|
60
|
+
| `transport` | `string \| TransportFactory` | 传输层,省略则自动探测 `fetch` |
|
|
61
|
+
| `parser` | `ParserFactory` | 自定义解析器 |
|
|
62
|
+
| `plugins` | `SSEPlugin[]` | 插件列表 |
|
|
63
|
+
| `onMessage` | `(data, event) => void` | 收到 message 事件回调 |
|
|
64
|
+
| `onOpen` | `(info: { transport }) => void` | 连接打开回调 |
|
|
65
|
+
| `onEnd` | `() => void` | 流结束回调 |
|
|
66
|
+
| `onError` | `(err) => void` | 错误回调 |
|
|
67
|
+
|
|
68
|
+
> 事件回调通过 `ref` 始终取最新值,不会出现闭包过期问题。
|
|
69
|
+
|
|
70
|
+
#### 返回值 `UseSSEStreamReturn`
|
|
71
|
+
|
|
72
|
+
| 字段 | 类型 | 说明 |
|
|
73
|
+
|------|------|------|
|
|
74
|
+
| `text` | `string` | 已拼接的消息文本(`message` 事件 `data` 累加) |
|
|
75
|
+
| `status` | `string` | 连接状态描述 |
|
|
76
|
+
| `loading` | `boolean` | 是否处于连接中/流式接收中 |
|
|
77
|
+
| `msgCount` | `number` | 已接收 message 事件条数 |
|
|
78
|
+
| `charCount` | `number` | 已接收字符总数 |
|
|
79
|
+
| `start` | `() => void` | 发起连接(销毁旧实例、清空已输出内容,等价 `restart`) |
|
|
80
|
+
| `restart` | `() => void` | 重新开始:丢弃已输出内容并新建实例 |
|
|
81
|
+
| `stop` | `() => void` | 暂停:中断当前流,保留实例与已输出内容 |
|
|
82
|
+
| `resume` | `() => void` | 继续:复用实例从断点续传 |
|
|
83
|
+
| `close` | `() => void` | 彻底停止:销毁实例与订阅(永久断开) |
|
|
84
|
+
| `instance` | `PluginSSE \| null` | 当前实例(便于 `use()` 追加插件等高级操作) |
|
|
85
|
+
|
|
86
|
+
## 生命周期
|
|
87
|
+
|
|
88
|
+
- 组件卸载时自动 `destroy()` 实例并清空订阅,无需手动清理
|
|
89
|
+
- `start()` / `restart()` 会先销毁旧连接再创建新连接,可重复调用
|
|
90
|
+
- `stop()` 只中断连接(内部调用 `abort()`),实例与已输出内容保留,可用 `resume()` 继续
|
|
91
|
+
- `close()` 彻底停止:内部调用 `destroy()`,释放插件资源并清空订阅,之后需重新 `start()`
|
|
92
|
+
- 流已正常结束或实例尚未创建时,`resume()` 自动退化为 `restart()`
|
|
93
|
+
|
|
94
|
+
## 暂停、继续与重新开始
|
|
95
|
+
|
|
96
|
+
`stop()` / `resume()` / `restart()` 组合可实现「流式输出到一半暂停,稍后从断点继续」:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import { useSSEStream } from 'sse-stream-plugin-react'
|
|
100
|
+
import { recommendedPlugins } from 'sse-stream-plugin-sdk'
|
|
101
|
+
|
|
102
|
+
function Chat() {
|
|
103
|
+
const { text, status, loading, start, stop, resume, restart } = useSSEStream({
|
|
104
|
+
url: 'https://api.example.com/stream',
|
|
105
|
+
method: 'POST',
|
|
106
|
+
getBody: () => JSON.stringify({ prompt: '你好' }),
|
|
107
|
+
headers: { 'Content-Type': 'application/json' },
|
|
108
|
+
plugins: recommendedPlugins(),
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div>
|
|
113
|
+
<button onClick={start}>发送</button>
|
|
114
|
+
{/* 中断连接,已输出内容保留,status 变为「已暂停」 */}
|
|
115
|
+
<button onClick={stop} disabled={!loading}>暂停</button>
|
|
116
|
+
{/* 复用实例继续,text 在原有内容基础上追加 */}
|
|
117
|
+
<button onClick={resume}>继续</button>
|
|
118
|
+
{/* 丢弃已输出内容,重新发送请求 */}
|
|
119
|
+
<button onClick={restart}>重新生成</button>
|
|
120
|
+
<p>{status}</p>
|
|
121
|
+
<pre>{text}</pre>
|
|
122
|
+
</div>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
| 方法 | 行为 | `text` | 连接位点 |
|
|
128
|
+
|------|------|--------|----------|
|
|
129
|
+
| `stop()` | 中断当前流,实例保留 | 保留 | 保留 |
|
|
130
|
+
| `resume()` | 复用实例重新连接 | 保留并追加 | 携带 `Last-Event-ID` 续传 |
|
|
131
|
+
| `restart()` | 销毁旧实例,重新发送 | 清空 | 从头开始 |
|
|
132
|
+
| `close()` | 销毁实例与订阅,彻底停止 | 保留 | 清空 |
|
|
133
|
+
|
|
134
|
+
> `resume()` 的断点续传依赖服务端支持 `Last-Event-ID`。若服务端不支持,续传会变成全量重发,请改用 `restart()` 或额外加去重插件。
|
|
135
|
+
|
|
136
|
+
### 彻底停止(close)
|
|
137
|
+
|
|
138
|
+
`stop()` 只是暂停,实例仍然驻留;若用户要真正结束本次会话,用 `close()`:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import { useSSEStream } from 'sse-stream-plugin-react'
|
|
142
|
+
|
|
143
|
+
function Chat() {
|
|
144
|
+
const { text, status, loading, start, stop, close } = useSSEStream({
|
|
145
|
+
url: 'https://api.example.com/stream',
|
|
146
|
+
method: 'POST',
|
|
147
|
+
getBody: () => JSON.stringify({ prompt: '你好' }),
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div>
|
|
152
|
+
<button onClick={start}>发送</button>
|
|
153
|
+
<button onClick={stop} disabled={!loading}>暂停</button>
|
|
154
|
+
{/* 销毁实例、释放插件资源并清空事件订阅,不可恢复 */}
|
|
155
|
+
<button onClick={close}>停止</button>
|
|
156
|
+
<p>{status}</p>{/* close 后为「已停止」 */}
|
|
157
|
+
<pre>{text}</pre>
|
|
158
|
+
</div>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
要点:
|
|
164
|
+
|
|
165
|
+
- `close()` 等价于对实例执行 `destroy()`:中止请求、执行插件销毁回调、清空事件订阅
|
|
166
|
+
- 之后 `status` 变为「已停止」、`loading` 变为 `false`、`instance` 变为 `null`
|
|
167
|
+
- 已输出的 `text` 保留;再次点击「发送」(`start()`)会创建全新实例,从头开始
|
|
168
|
+
- 组件卸载时会自动 `destroy()`,通常无需手动调用;`close()` 适用于「用户明确结束会话、希望立即释放资源」的场景
|
|
169
|
+
- 直接调用 `instance?.destroy()` 效果相同,Hook 会通过 `closed` 事件同步复位状态
|
|
170
|
+
|
|
171
|
+
## 高级用法
|
|
172
|
+
|
|
173
|
+
### 通过 `instance` 追加插件
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
const { instance, start } = useSSEStream({ url, method: 'POST' })
|
|
177
|
+
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (instance) {
|
|
180
|
+
instance.use(loggerPlugin())
|
|
181
|
+
}
|
|
182
|
+
}, [instance])
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 小程序环境
|
|
186
|
+
|
|
187
|
+
通过 `transport` 传入小程序传输层工厂:
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { createMpTransport } from 'sse-stream-plugin-sdk'
|
|
191
|
+
|
|
192
|
+
useSSEStream({
|
|
193
|
+
url,
|
|
194
|
+
transport: createMpTransport(() => wx),
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var sseStreamPluginSdk = require('sse-stream-plugin-sdk');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @file React Hook:将插件化 SSE SDK 封装为声明式响应式 API
|
|
8
|
+
* @description
|
|
9
|
+
* - 实例用 useRef 持有,不进入 React 状态;
|
|
10
|
+
* - start() 内按需创建 PluginSSE,组件卸载时自动 destroy();
|
|
11
|
+
* - 事件回调通过 optionsRef 始终取最新值,避免闭包过期;
|
|
12
|
+
* - 暴露 text/status/loading 等响应式状态与 start/stop 方法。
|
|
13
|
+
*/
|
|
14
|
+
function useSSEStream(options) {
|
|
15
|
+
// 始终保存最新入参,start 内读取,保证回调与配置不过期
|
|
16
|
+
const optionsRef = react.useRef(options);
|
|
17
|
+
optionsRef.current = options;
|
|
18
|
+
const sseRef = react.useRef(null);
|
|
19
|
+
/** 上一次连接是否正常结束(正常结束后续传位点已归零,resume 需从头开始) */
|
|
20
|
+
const endedRef = react.useRef(false);
|
|
21
|
+
/** 是否仍挂载,避免卸载时 destroy 触发的 closed 回调再更新状态 */
|
|
22
|
+
const mountedRef = react.useRef(true);
|
|
23
|
+
const [text, setText] = react.useState('');
|
|
24
|
+
const [status, setStatus] = react.useState('未连接');
|
|
25
|
+
const [loading, setLoading] = react.useState(false);
|
|
26
|
+
const [msgCount, setMsgCount] = react.useState(0);
|
|
27
|
+
const [charCount, setCharCount] = react.useState(0);
|
|
28
|
+
// 组件卸载:释放连接、清空订阅
|
|
29
|
+
react.useEffect(() => {
|
|
30
|
+
mountedRef.current = true;
|
|
31
|
+
return () => {
|
|
32
|
+
mountedRef.current = false;
|
|
33
|
+
sseRef.current?.destroy();
|
|
34
|
+
sseRef.current = null;
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
// 暂停:中断当前流但保留实例与已输出内容,状态由 abort 事件更新
|
|
38
|
+
const stop = react.useCallback(() => {
|
|
39
|
+
sseRef.current?.abort();
|
|
40
|
+
}, []);
|
|
41
|
+
// 彻底停止:销毁实例与订阅,状态由 closed 事件统一复位
|
|
42
|
+
const close = react.useCallback(() => {
|
|
43
|
+
if (sseRef.current) {
|
|
44
|
+
sseRef.current.destroy();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setStatus('已停止');
|
|
48
|
+
setLoading(false);
|
|
49
|
+
}, []);
|
|
50
|
+
const start = react.useCallback(() => {
|
|
51
|
+
const { url, method, body, headers, transport, parser, plugins, getBody, onMessage, onOpen, onEnd, onError, } = optionsRef.current;
|
|
52
|
+
// 销毁旧连接(含旧实例的全部事件订阅)
|
|
53
|
+
sseRef.current?.destroy();
|
|
54
|
+
setText('');
|
|
55
|
+
setMsgCount(0);
|
|
56
|
+
setCharCount(0);
|
|
57
|
+
setStatus('连接中…');
|
|
58
|
+
setLoading(true);
|
|
59
|
+
endedRef.current = false;
|
|
60
|
+
const sse = new sseStreamPluginSdk.PluginSSE({
|
|
61
|
+
url,
|
|
62
|
+
method: method ?? 'GET',
|
|
63
|
+
body: getBody ? getBody() : body,
|
|
64
|
+
headers,
|
|
65
|
+
transport,
|
|
66
|
+
parser,
|
|
67
|
+
plugins,
|
|
68
|
+
});
|
|
69
|
+
// 每次(含自动重连、resume)发起连接都会触发,保证 loading 状态不丢失
|
|
70
|
+
sse.on('connecting', () => {
|
|
71
|
+
setStatus('连接中…');
|
|
72
|
+
setLoading(true);
|
|
73
|
+
});
|
|
74
|
+
sse.on('open', ({ transport: name }) => {
|
|
75
|
+
setStatus(`已连接(${name})`);
|
|
76
|
+
onOpen?.({ transport: name });
|
|
77
|
+
});
|
|
78
|
+
sse.on('message', (data, event) => {
|
|
79
|
+
setText((prev) => prev + data);
|
|
80
|
+
setMsgCount((n) => n + 1);
|
|
81
|
+
setCharCount((n) => n + data.length);
|
|
82
|
+
onMessage?.(data, event);
|
|
83
|
+
});
|
|
84
|
+
sse.on('end', () => {
|
|
85
|
+
endedRef.current = true;
|
|
86
|
+
setStatus('流正常结束');
|
|
87
|
+
setLoading(false);
|
|
88
|
+
onEnd?.();
|
|
89
|
+
});
|
|
90
|
+
sse.on('error', (err) => {
|
|
91
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
92
|
+
setStatus(`错误:${msg}`);
|
|
93
|
+
setLoading(false);
|
|
94
|
+
onError?.(err);
|
|
95
|
+
});
|
|
96
|
+
sse.on('abort', () => {
|
|
97
|
+
setStatus('已暂停');
|
|
98
|
+
setLoading(false);
|
|
99
|
+
});
|
|
100
|
+
sse.on('closed', () => {
|
|
101
|
+
if (!mountedRef.current)
|
|
102
|
+
return;
|
|
103
|
+
endedRef.current = false;
|
|
104
|
+
sseRef.current = null;
|
|
105
|
+
setStatus('已停止');
|
|
106
|
+
setLoading(false);
|
|
107
|
+
});
|
|
108
|
+
sseRef.current = sse;
|
|
109
|
+
sse.connect();
|
|
110
|
+
}, []);
|
|
111
|
+
// 继续:复用实例从断点续传;无实例或上次已正常结束时退化为重新开始
|
|
112
|
+
const resume = react.useCallback(() => {
|
|
113
|
+
const sse = sseRef.current;
|
|
114
|
+
if (!sse || endedRef.current) {
|
|
115
|
+
start();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
setStatus('连接中…');
|
|
119
|
+
setLoading(true);
|
|
120
|
+
void sse.start();
|
|
121
|
+
}, [start]);
|
|
122
|
+
return {
|
|
123
|
+
text,
|
|
124
|
+
status,
|
|
125
|
+
loading,
|
|
126
|
+
msgCount,
|
|
127
|
+
charCount,
|
|
128
|
+
start,
|
|
129
|
+
restart: start,
|
|
130
|
+
stop,
|
|
131
|
+
resume,
|
|
132
|
+
close,
|
|
133
|
+
instance: sseRef.current,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exports.useSSEStream = useSSEStream;
|
|
138
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/useSSEStream.ts"],"sourcesContent":[null],"names":["useRef","useState","useEffect","useCallback","PluginSSE"],"mappings":";;;;;AAAA;;;;;;;AAOG;AA6CG,SAAU,YAAY,CAAC,OAA4B,EAAA;;AAEvD,IAAA,MAAM,UAAU,GAAGA,YAAM,CAAC,OAAO,CAAC;AAClC,IAAA,UAAU,CAAC,OAAO,GAAG,OAAO;AAE5B,IAAA,MAAM,MAAM,GAAGA,YAAM,CAAmB,IAAI,CAAC;;AAE7C,IAAA,MAAM,QAAQ,GAAGA,YAAM,CAAC,KAAK,CAAC;;AAE9B,IAAA,MAAM,UAAU,GAAGA,YAAM,CAAC,IAAI,CAAC;IAC/B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGC,cAAQ,CAAC,EAAE,CAAC;IACpC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;IAC3C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;IAC7C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAGA,cAAQ,CAAC,CAAC,CAAC;IAC3C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAGA,cAAQ,CAAC,CAAC,CAAC;;IAG7CC,eAAS,CAAC,MAAK;AACb,QAAA,UAAU,CAAC,OAAO,GAAG,IAAI;AACzB,QAAA,OAAO,MAAK;AACV,YAAA,UAAU,CAAC,OAAO,GAAG,KAAK;AAC1B,YAAA,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE;AACzB,YAAA,MAAM,CAAC,OAAO,GAAG,IAAI;AACvB,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;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,EAAE,CAAC,QAAQ,EAAE,MAAK;YACpB,IAAI,CAAC,UAAU,CAAC,OAAO;gBAAE;AACzB,YAAA,QAAQ,CAAC,OAAO,GAAG,KAAK;AACxB,YAAA,MAAM,CAAC,OAAO,GAAG,IAAI;YACrB,SAAS,CAAC,KAAK,CAAC;YAChB,UAAU,CAAC,KAAK,CAAC;AACnB,QAAA,CAAC,CAAC;AAEF,QAAA,MAAM,CAAC,OAAO,GAAG,GAAG;QACpB,GAAG,CAAC,OAAO,EAAE;IACf,CAAC,EAAE,EAAE,CAAC;;AAGN,IAAA,MAAM,MAAM,GAAGD,iBAAW,CAAC,MAAK;AAC9B,QAAA,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO;AAC1B,QAAA,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE;AAC5B,YAAA,KAAK,EAAE;YACP;QACF;QACA,SAAS,CAAC,MAAM,CAAC;QACjB,UAAU,CAAC,IAAI,CAAC;AAChB,QAAA,KAAK,GAAG,CAAC,KAAK,EAAE;AAClB,IAAA,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAEX,OAAO;QACL,IAAI;QACJ,MAAM;QACN,OAAO;QACP,QAAQ;QACR,SAAS;QACT,KAAK;AACL,QAAA,OAAO,EAAE,KAAK;QACd,IAAI;QACJ,MAAM;QACN,KAAK;QACL,QAAQ,EAAE,MAAM,CAAC,OAAO;KACzB;AACH;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PluginSSEOptions, ParsedEvent, PluginSSE } from 'sse-stream-plugin-sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook 入参:在核心 PluginSSEOptions 基础上追加动态 body 与事件回调
|
|
5
|
+
*/
|
|
6
|
+
interface UseSSEStreamOptions extends Pick<PluginSSEOptions, 'url' | 'method' | 'body' | 'headers' | 'transport' | 'parser' | 'plugins'> {
|
|
7
|
+
/** 每次 start 时动态生成请求体(如带当前 prompt),优先级高于 body */
|
|
8
|
+
getBody?: () => string;
|
|
9
|
+
onMessage?: (data: string, event: ParsedEvent) => void;
|
|
10
|
+
onOpen?: (info: {
|
|
11
|
+
transport: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
onEnd?: () => void;
|
|
14
|
+
onError?: (err: unknown) => void;
|
|
15
|
+
}
|
|
16
|
+
interface UseSSEStreamReturn {
|
|
17
|
+
/** 已拼接的消息文本(message 事件 data 累加) */
|
|
18
|
+
text: string;
|
|
19
|
+
/** 连接状态描述 */
|
|
20
|
+
status: string;
|
|
21
|
+
/** 是否处于连接中/流式接收中 */
|
|
22
|
+
loading: boolean;
|
|
23
|
+
/** 已接收 message 事件条数 */
|
|
24
|
+
msgCount: number;
|
|
25
|
+
/** 已接收字符总数 */
|
|
26
|
+
charCount: number;
|
|
27
|
+
/** 发起一次连接:销毁旧实例并清空已输出内容,从头开始(等价 restart) */
|
|
28
|
+
start: () => void;
|
|
29
|
+
/** 重新开始:丢弃已输出内容并新建实例(等价 start) */
|
|
30
|
+
restart: () => void;
|
|
31
|
+
/** 暂停:中断当前流,保留实例与已输出内容,可用 resume 继续 */
|
|
32
|
+
stop: () => void;
|
|
33
|
+
/** 继续:复用实例从断点续传(无实例或上次已正常结束时退化为重新开始) */
|
|
34
|
+
resume: () => void;
|
|
35
|
+
/** 彻底停止:销毁实例与订阅并复位状态,已输出内容保留 */
|
|
36
|
+
close: () => void;
|
|
37
|
+
/** 当前 PluginSSE 实例(便于 use() 追加插件等高级操作) */
|
|
38
|
+
instance: PluginSSE | null;
|
|
39
|
+
}
|
|
40
|
+
declare function useSSEStream(options: UseSSEStreamOptions): UseSSEStreamReturn;
|
|
41
|
+
|
|
42
|
+
export { useSSEStream };
|
|
43
|
+
export type { UseSSEStreamOptions, UseSSEStreamReturn };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { PluginSSE } from 'sse-stream-plugin-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file React Hook:将插件化 SSE SDK 封装为声明式响应式 API
|
|
6
|
+
* @description
|
|
7
|
+
* - 实例用 useRef 持有,不进入 React 状态;
|
|
8
|
+
* - start() 内按需创建 PluginSSE,组件卸载时自动 destroy();
|
|
9
|
+
* - 事件回调通过 optionsRef 始终取最新值,避免闭包过期;
|
|
10
|
+
* - 暴露 text/status/loading 等响应式状态与 start/stop 方法。
|
|
11
|
+
*/
|
|
12
|
+
function useSSEStream(options) {
|
|
13
|
+
// 始终保存最新入参,start 内读取,保证回调与配置不过期
|
|
14
|
+
const optionsRef = useRef(options);
|
|
15
|
+
optionsRef.current = options;
|
|
16
|
+
const sseRef = useRef(null);
|
|
17
|
+
/** 上一次连接是否正常结束(正常结束后续传位点已归零,resume 需从头开始) */
|
|
18
|
+
const endedRef = useRef(false);
|
|
19
|
+
/** 是否仍挂载,避免卸载时 destroy 触发的 closed 回调再更新状态 */
|
|
20
|
+
const mountedRef = useRef(true);
|
|
21
|
+
const [text, setText] = useState('');
|
|
22
|
+
const [status, setStatus] = useState('未连接');
|
|
23
|
+
const [loading, setLoading] = useState(false);
|
|
24
|
+
const [msgCount, setMsgCount] = useState(0);
|
|
25
|
+
const [charCount, setCharCount] = useState(0);
|
|
26
|
+
// 组件卸载:释放连接、清空订阅
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
mountedRef.current = true;
|
|
29
|
+
return () => {
|
|
30
|
+
mountedRef.current = false;
|
|
31
|
+
sseRef.current?.destroy();
|
|
32
|
+
sseRef.current = null;
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
// 暂停:中断当前流但保留实例与已输出内容,状态由 abort 事件更新
|
|
36
|
+
const stop = useCallback(() => {
|
|
37
|
+
sseRef.current?.abort();
|
|
38
|
+
}, []);
|
|
39
|
+
// 彻底停止:销毁实例与订阅,状态由 closed 事件统一复位
|
|
40
|
+
const close = useCallback(() => {
|
|
41
|
+
if (sseRef.current) {
|
|
42
|
+
sseRef.current.destroy();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
setStatus('已停止');
|
|
46
|
+
setLoading(false);
|
|
47
|
+
}, []);
|
|
48
|
+
const start = useCallback(() => {
|
|
49
|
+
const { url, method, body, headers, transport, parser, plugins, getBody, onMessage, onOpen, onEnd, onError, } = optionsRef.current;
|
|
50
|
+
// 销毁旧连接(含旧实例的全部事件订阅)
|
|
51
|
+
sseRef.current?.destroy();
|
|
52
|
+
setText('');
|
|
53
|
+
setMsgCount(0);
|
|
54
|
+
setCharCount(0);
|
|
55
|
+
setStatus('连接中…');
|
|
56
|
+
setLoading(true);
|
|
57
|
+
endedRef.current = false;
|
|
58
|
+
const sse = new PluginSSE({
|
|
59
|
+
url,
|
|
60
|
+
method: method ?? 'GET',
|
|
61
|
+
body: getBody ? getBody() : body,
|
|
62
|
+
headers,
|
|
63
|
+
transport,
|
|
64
|
+
parser,
|
|
65
|
+
plugins,
|
|
66
|
+
});
|
|
67
|
+
// 每次(含自动重连、resume)发起连接都会触发,保证 loading 状态不丢失
|
|
68
|
+
sse.on('connecting', () => {
|
|
69
|
+
setStatus('连接中…');
|
|
70
|
+
setLoading(true);
|
|
71
|
+
});
|
|
72
|
+
sse.on('open', ({ transport: name }) => {
|
|
73
|
+
setStatus(`已连接(${name})`);
|
|
74
|
+
onOpen?.({ transport: name });
|
|
75
|
+
});
|
|
76
|
+
sse.on('message', (data, event) => {
|
|
77
|
+
setText((prev) => prev + data);
|
|
78
|
+
setMsgCount((n) => n + 1);
|
|
79
|
+
setCharCount((n) => n + data.length);
|
|
80
|
+
onMessage?.(data, event);
|
|
81
|
+
});
|
|
82
|
+
sse.on('end', () => {
|
|
83
|
+
endedRef.current = true;
|
|
84
|
+
setStatus('流正常结束');
|
|
85
|
+
setLoading(false);
|
|
86
|
+
onEnd?.();
|
|
87
|
+
});
|
|
88
|
+
sse.on('error', (err) => {
|
|
89
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
90
|
+
setStatus(`错误:${msg}`);
|
|
91
|
+
setLoading(false);
|
|
92
|
+
onError?.(err);
|
|
93
|
+
});
|
|
94
|
+
sse.on('abort', () => {
|
|
95
|
+
setStatus('已暂停');
|
|
96
|
+
setLoading(false);
|
|
97
|
+
});
|
|
98
|
+
sse.on('closed', () => {
|
|
99
|
+
if (!mountedRef.current)
|
|
100
|
+
return;
|
|
101
|
+
endedRef.current = false;
|
|
102
|
+
sseRef.current = null;
|
|
103
|
+
setStatus('已停止');
|
|
104
|
+
setLoading(false);
|
|
105
|
+
});
|
|
106
|
+
sseRef.current = sse;
|
|
107
|
+
sse.connect();
|
|
108
|
+
}, []);
|
|
109
|
+
// 继续:复用实例从断点续传;无实例或上次已正常结束时退化为重新开始
|
|
110
|
+
const resume = useCallback(() => {
|
|
111
|
+
const sse = sseRef.current;
|
|
112
|
+
if (!sse || endedRef.current) {
|
|
113
|
+
start();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setStatus('连接中…');
|
|
117
|
+
setLoading(true);
|
|
118
|
+
void sse.start();
|
|
119
|
+
}, [start]);
|
|
120
|
+
return {
|
|
121
|
+
text,
|
|
122
|
+
status,
|
|
123
|
+
loading,
|
|
124
|
+
msgCount,
|
|
125
|
+
charCount,
|
|
126
|
+
start,
|
|
127
|
+
restart: start,
|
|
128
|
+
stop,
|
|
129
|
+
resume,
|
|
130
|
+
close,
|
|
131
|
+
instance: sseRef.current,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { useSSEStream };
|
|
136
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/useSSEStream.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;;;;;;;AAOG;AA6CG,SAAU,YAAY,CAAC,OAA4B,EAAA;;AAEvD,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,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AAG,WAAW,CAAC,MAAK;AAC9B,QAAA,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO;AAC1B,QAAA,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE;AAC5B,YAAA,KAAK,EAAE;YACP;QACF;QACA,SAAS,CAAC,MAAM,CAAC;QACjB,UAAU,CAAC,IAAI,CAAC;AAChB,QAAA,KAAK,GAAG,CAAC,KAAK,EAAE;AAClB,IAAA,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAEX,OAAO;QACL,IAAI;QACJ,MAAM;QACN,OAAO;QACP,QAAQ;QACR,SAAS;QACT,KAAK;AACL,QAAA,OAAO,EAAE,KAAK;QACd,IAAI;QACJ,MAAM;QACN,KAAK;QACL,QAAQ,EAAE,MAAM,CAAC,OAAO;KACzB;AACH;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sse-stream-plugin-react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "React Hooks for sse-stream-plugin-sdk",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"sse",
|
|
9
|
+
"server-sent-events",
|
|
10
|
+
"stream",
|
|
11
|
+
"react",
|
|
12
|
+
"hooks"
|
|
13
|
+
],
|
|
14
|
+
"main": "dist/index.cjs",
|
|
15
|
+
"module": "dist/index.mjs",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"README.md",
|
|
28
|
+
"CHANGELOG.md"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": ">=16.8.0",
|
|
32
|
+
"sse-stream-plugin-sdk": "^1.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "^19.2.18",
|
|
36
|
+
"react": "^19.2.8",
|
|
37
|
+
"sse-stream-plugin-sdk": "1.1.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "rollup -c",
|
|
41
|
+
"build:prod": "rollup -c --environment NODE_ENV:production"
|
|
42
|
+
}
|
|
6
43
|
}
|