@blueking/chat-helper 0.0.1-beta.9 → 0.0.2
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 +631 -141
- package/dist/agent/type.d.ts +27 -2
- package/dist/agent/type.ts.js +1 -1
- package/dist/agent/use-agent.d.ts +464 -484
- package/dist/agent/use-agent.ts.js +191 -42
- package/dist/event/ag-ui.d.ts +37 -7
- package/dist/event/ag-ui.ts.js +225 -173
- package/dist/event/type.d.ts +99 -107
- package/dist/event/type.ts.js +34 -11
- package/dist/http/fetch/fetch.d.ts +2 -1
- package/dist/http/fetch/fetch.ts.js +38 -8
- package/dist/http/fetch/index.d.ts +1 -0
- package/dist/http/fetch/index.ts.js +17 -1
- package/dist/http/index.d.ts +14 -5
- package/dist/http/index.ts.js +59 -3
- package/dist/http/module/index.d.ts +13 -5
- package/dist/http/module/index.ts.js +2 -1
- package/dist/http/module/message.d.ts +22 -5
- package/dist/http/module/message.ts.js +51 -4
- package/dist/http/module/session.d.ts +4 -1
- package/dist/http/module/session.ts.js +66 -4
- package/dist/http/transform/agent.ts.js +11 -8
- package/dist/http/transform/message.d.ts +6 -6
- package/dist/http/transform/message.ts.js +566 -118
- package/dist/http/transform/session.ts.js +9 -1
- package/dist/index.d.ts +2983 -3314
- package/dist/index.ts.js +27 -5
- package/dist/mediator/index.d.ts +2 -0
- package/dist/mediator/index.ts.js +26 -0
- package/dist/mediator/type.d.ts +50 -0
- package/dist/mediator/type.ts.js +28 -0
- package/dist/mediator/use-mediator.d.ts +7 -0
- package/dist/mediator/use-mediator.ts.js +47 -0
- package/dist/message/type.d.ts +280 -146
- package/dist/message/type.ts.js +16 -15
- package/dist/message/use-message.d.ts +847 -963
- package/dist/message/use-message.ts.js +230 -37
- package/dist/session/type.d.ts +10 -0
- package/dist/session/use-session.d.ts +2006 -2214
- package/dist/session/use-session.ts.js +198 -33
- package/package.json +11 -6
package/dist/event/type.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare enum
|
|
3
|
-
|
|
1
|
+
import { type IMessageApi, type MessageRole, type MessageStatus } from '../message/type';
|
|
2
|
+
export declare enum CustomEventName {
|
|
3
|
+
FlowAgentEnd = "flow_agent_end",
|
|
4
|
+
FlowAgentResult = "flow_agent_result",
|
|
5
|
+
FlowAgentStart = "flow_agent_start",
|
|
6
|
+
KnowledgeRagEnd = "knowledge_rag_end",
|
|
7
|
+
KnowledgeRagResult = "knowledge_rag_result",
|
|
8
|
+
KnowledgeRagStart = "knowledge_rag_start",
|
|
9
|
+
KnowledgeRagTextContent = "knowledge_rag_text_content",
|
|
10
|
+
ReferenceDocument = "reference_document",
|
|
11
|
+
TempMessage = "temp_message"
|
|
4
12
|
}
|
|
5
13
|
export declare enum EventType {
|
|
6
14
|
ActivityDelta = "ACTIVITY_DELTA",
|
|
@@ -30,23 +38,49 @@ export declare enum EventType {
|
|
|
30
38
|
ToolCallResult = "TOOL_CALL_RESULT",
|
|
31
39
|
ToolCallStart = "TOOL_CALL_START"
|
|
32
40
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
/** BKFlow 收敛后的节点状态 - task.node 的状态枚举 */
|
|
42
|
+
export declare enum FlowNodeState {
|
|
43
|
+
/** 失败 */
|
|
44
|
+
Failed = "failed",
|
|
45
|
+
/** 执行中 */
|
|
46
|
+
Running = "running",
|
|
47
|
+
/** 成功 */
|
|
48
|
+
Success = "success",
|
|
49
|
+
/** 挂起 */
|
|
50
|
+
Suspended = "suspended"
|
|
51
|
+
}
|
|
52
|
+
/** BKFLOW 原始状态 - task 的状态枚举 */
|
|
53
|
+
export declare enum FlowTaskState {
|
|
54
|
+
/** 执行中 */
|
|
55
|
+
Blocked = "BLOCKED",
|
|
56
|
+
/** 执行中 */
|
|
57
|
+
Created = "CREATED",
|
|
58
|
+
/** 失败 */
|
|
59
|
+
Failed = "FAILED",
|
|
60
|
+
/** 成功 */
|
|
61
|
+
Finished = "FINISHED",
|
|
62
|
+
/** 执行中 */
|
|
63
|
+
LoopReady = "LOOP_READY",
|
|
64
|
+
/** 执行中 */
|
|
65
|
+
Ready = "READY",
|
|
66
|
+
/** 失败 */
|
|
67
|
+
Revoked = "REVOKED",
|
|
68
|
+
/** 失败 */
|
|
69
|
+
RollBackFailed = "ROLL_BACK_FAILED",
|
|
70
|
+
/** 执行中 */
|
|
71
|
+
RollBackSuccess = "ROLL_BACK_SUCCESS",
|
|
72
|
+
/** 执行中 */
|
|
73
|
+
RollingBack = "ROLLING_BACK",
|
|
74
|
+
/** 执行中 */
|
|
75
|
+
Running = "RUNNING",
|
|
76
|
+
/** 挂起 */
|
|
77
|
+
Suspended = "SUSPENDED"
|
|
38
78
|
}
|
|
39
79
|
/**
|
|
40
80
|
* Activity 代表 Agent 执行过程中的活动/动作/任务,可能包含结构化数据
|
|
41
81
|
* 活动状态的增量更新
|
|
42
82
|
* 记录活动类型 activityType
|
|
43
83
|
* 使用 JSON Patch (RFC 6902) 格式增量更新 Activity 数据
|
|
44
|
-
*
|
|
45
|
-
* @example ActivityDeltaEvent {
|
|
46
|
-
* activityType: "file_processing",
|
|
47
|
-
* messageId: "123",
|
|
48
|
-
* patch: [{ op: "add", path: "/title", value: "分析需求" }]
|
|
49
|
-
* }
|
|
50
84
|
*/
|
|
51
85
|
export interface IActivityDeltaEvent extends IBaseEvent {
|
|
52
86
|
activityType: string;
|
|
@@ -59,17 +93,6 @@ export interface IActivityDeltaEvent extends IBaseEvent {
|
|
|
59
93
|
* 活动状态的快照
|
|
60
94
|
* 记录活动类型 activityType
|
|
61
95
|
* 使用 JSON 格式存储 Activity 数据
|
|
62
|
-
*
|
|
63
|
-
* @example ActivitySnapshotEvent {
|
|
64
|
-
* activityType: "file_processing",
|
|
65
|
-
* messageId: "123",
|
|
66
|
-
* content: {
|
|
67
|
-
* title: "分析需求",
|
|
68
|
-
* status: "pending",
|
|
69
|
-
* progress: 0.5,
|
|
70
|
-
* },
|
|
71
|
-
* replace: true,
|
|
72
|
-
* }
|
|
73
96
|
*/
|
|
74
97
|
export interface IActivitySnapshotEvent extends IBaseEvent {
|
|
75
98
|
activityType: string;
|
|
@@ -78,10 +101,6 @@ export interface IActivitySnapshotEvent extends IBaseEvent {
|
|
|
78
101
|
replace?: boolean;
|
|
79
102
|
type: EventType.ActivitySnapshot;
|
|
80
103
|
}
|
|
81
|
-
export interface IBaseCustomEvent {
|
|
82
|
-
timestamp?: number;
|
|
83
|
-
type: CustomEventType;
|
|
84
|
-
}
|
|
85
104
|
export interface IBaseEvent {
|
|
86
105
|
timestamp?: number;
|
|
87
106
|
type: EventType;
|
|
@@ -89,26 +108,47 @@ export interface IBaseEvent {
|
|
|
89
108
|
/**
|
|
90
109
|
* 自定义事件
|
|
91
110
|
* 用于发送自定义事件到客户端
|
|
92
|
-
*
|
|
93
|
-
* @example CustomEvent {
|
|
94
|
-
* name: "custom_event",
|
|
95
|
-
* value: { type: CustomEventType.ReferenceDocument, data: { ... } }
|
|
96
|
-
* }
|
|
97
111
|
*/
|
|
98
112
|
export interface ICustomEvent extends IBaseEvent {
|
|
99
|
-
name:
|
|
113
|
+
name: CustomEventName;
|
|
100
114
|
type: EventType.Custom;
|
|
101
|
-
value:
|
|
115
|
+
value: IFlowAgentEndCustomValue | IFlowAgentResultCustomValue | IFlowAgentStartCustomValue | IKnowledgeRagResultCustomValue | IKnowledgeRagTextContentCustomValue | IReferenceDocumentCustomValue | ITempMessageCustomValue;
|
|
102
116
|
}
|
|
103
117
|
export type IEvent = IActivityDeltaEvent | IActivitySnapshotEvent | ICustomEvent | IMessagesSnapshotEvent | IRawEvent | IRunErrorEvent | IRunFinishedEvent | IRunStartedEvent | IStateDeltaEvent | IStateSnapshotEvent | IStepFinishedEvent | IStepStartedEvent | ITextMessageChunkEvent | ITextMessageContentEvent | ITextMessageEndEvent | ITextMessageStartEvent | IThinkingEndEvent | IThinkingStartEvent | IThinkingTextMessageContentEvent | IThinkingTextMessageEndEvent | IThinkingTextMessageStartEvent | IToolCallArgsEvent | IToolCallChunkEvent | IToolCallEndEvent | IToolCallResultEvent | IToolCallStartEvent;
|
|
118
|
+
export interface IFlowAgentEndCustomValue {
|
|
119
|
+
task_outputs: string[];
|
|
120
|
+
}
|
|
121
|
+
export interface IFlowAgentNode {
|
|
122
|
+
/** 耗时(s) */
|
|
123
|
+
elapsed_time: number;
|
|
124
|
+
/** 节点id */
|
|
125
|
+
id: string;
|
|
126
|
+
/** 节点名称 */
|
|
127
|
+
name: string;
|
|
128
|
+
/** 节点状态 */
|
|
129
|
+
state: FlowNodeState;
|
|
130
|
+
}
|
|
131
|
+
export interface IFlowAgentResultCustomValue {
|
|
132
|
+
nodes: Record<string, IFlowAgentNode>;
|
|
133
|
+
task_id: number;
|
|
134
|
+
task_name: string;
|
|
135
|
+
task_outputs: string[];
|
|
136
|
+
task_state: FlowTaskState;
|
|
137
|
+
}
|
|
138
|
+
export interface IFlowAgentStartCustomValue {
|
|
139
|
+
task_id: string;
|
|
140
|
+
}
|
|
141
|
+
export type IKnowledgeRagResultCustomValue = IReferenceDocumentCustomValue;
|
|
142
|
+
export interface IKnowledgeRagTextContentCustomValue {
|
|
143
|
+
cover: boolean;
|
|
144
|
+
chunk: {
|
|
145
|
+
content: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
104
148
|
/**
|
|
105
149
|
* 消息快照事件
|
|
106
150
|
* 用于记录当前时刻的完整消息状态
|
|
107
151
|
* 同步多端消息状态
|
|
108
|
-
*
|
|
109
|
-
* @example MessagesSnapshotEvent {
|
|
110
|
-
* messages: [{ ... }, { ... }]
|
|
111
|
-
* }
|
|
112
152
|
*/
|
|
113
153
|
export interface IMessagesSnapshotEvent extends IBaseEvent {
|
|
114
154
|
messages: IMessageApi[];
|
|
@@ -117,32 +157,17 @@ export interface IMessagesSnapshotEvent extends IBaseEvent {
|
|
|
117
157
|
/**
|
|
118
158
|
* 透传底层原始事件数据
|
|
119
159
|
* 保留完整的原始事件信息,不做解析
|
|
120
|
-
*
|
|
121
|
-
* // 同时对接多个 AI 服务
|
|
122
|
-
* @example RawEvent {
|
|
123
|
-
* event: { Claude 原始响应 },
|
|
124
|
-
* source: "anthropic"
|
|
125
|
-
* }
|
|
126
|
-
*
|
|
127
|
-
* @example RawEvent {
|
|
128
|
-
* event: { OpenAI 原始响应 },
|
|
129
|
-
* source: "openai"
|
|
130
|
-
* }
|
|
131
160
|
*/
|
|
132
161
|
export interface IRawEvent extends IBaseEvent {
|
|
133
162
|
event: unknown;
|
|
134
163
|
source?: string;
|
|
135
164
|
type: EventType.Raw;
|
|
136
165
|
}
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
title: string;
|
|
143
|
-
url: string;
|
|
144
|
-
}[];
|
|
145
|
-
}
|
|
166
|
+
export type IReferenceDocumentCustomValue = {
|
|
167
|
+
name: string;
|
|
168
|
+
originFileUrl?: string;
|
|
169
|
+
url: string;
|
|
170
|
+
}[];
|
|
146
171
|
export interface IRunErrorEvent extends IBaseEvent {
|
|
147
172
|
code?: string;
|
|
148
173
|
message: string;
|
|
@@ -164,13 +189,6 @@ export interface IRunFinishedEvent extends IBaseEvent {
|
|
|
164
189
|
* 关联会话线程 threadId
|
|
165
190
|
* 可以记录初始输入 input
|
|
166
191
|
* 支持嵌套运行(parentRunId 用于子 Agent 调用)
|
|
167
|
-
*
|
|
168
|
-
* @example RunStartedEvent {
|
|
169
|
-
* runId: 123,
|
|
170
|
-
* threadId: "thread_123",
|
|
171
|
-
* parentRunId: undefined,
|
|
172
|
-
* input: { messages: [...] },
|
|
173
|
-
* }
|
|
174
192
|
*/
|
|
175
193
|
export interface IRunStartedEvent extends IBaseEvent {
|
|
176
194
|
input?: unknown;
|
|
@@ -183,10 +201,6 @@ export interface IRunStartedEvent extends IBaseEvent {
|
|
|
183
201
|
* 状态增量更新事件
|
|
184
202
|
* 用于更新客户端状态
|
|
185
203
|
* 以 JSON Patch 格式增量更新状态
|
|
186
|
-
*
|
|
187
|
-
* @example StateDeltaEvent {
|
|
188
|
-
* delta: [{ op: "add", path: "/title", value: "分析需求" }]
|
|
189
|
-
* }
|
|
190
204
|
*/
|
|
191
205
|
export interface IStateDeltaEvent extends IBaseEvent {
|
|
192
206
|
delta: unknown;
|
|
@@ -196,10 +210,6 @@ export interface IStateDeltaEvent extends IBaseEvent {
|
|
|
196
210
|
* 状态快照事件
|
|
197
211
|
* 用于初始化或重置客户端状态
|
|
198
212
|
* 提供当前时刻的完整状态视图
|
|
199
|
-
*
|
|
200
|
-
* @example StateSnapshotEvent {
|
|
201
|
-
* snapshot: { ... }
|
|
202
|
-
* }
|
|
203
213
|
*/
|
|
204
214
|
export interface IStateSnapshotEvent extends IBaseEvent {
|
|
205
215
|
snapshot: unknown;
|
|
@@ -220,45 +230,40 @@ export interface IStepStartedEvent extends IBaseEvent {
|
|
|
220
230
|
stepName: string;
|
|
221
231
|
type: EventType.StepStarted;
|
|
222
232
|
}
|
|
233
|
+
export interface ITempMessageCustomValue {
|
|
234
|
+
message: string;
|
|
235
|
+
status: MessageStatus;
|
|
236
|
+
}
|
|
223
237
|
export interface ITextMessageChunkEvent extends IBaseEvent {
|
|
224
238
|
delta?: string;
|
|
225
|
-
messageId:
|
|
226
|
-
role?:
|
|
239
|
+
messageId: string;
|
|
240
|
+
role?: MessageRole;
|
|
227
241
|
type: EventType.TextMessageChunk;
|
|
228
242
|
}
|
|
229
243
|
export interface ITextMessageContentEvent extends IBaseEvent {
|
|
230
244
|
delta: string;
|
|
231
|
-
messageId:
|
|
245
|
+
messageId: string;
|
|
232
246
|
type: EventType.TextMessageContent;
|
|
233
247
|
}
|
|
234
248
|
export interface ITextMessageEndEvent extends IBaseEvent {
|
|
235
|
-
messageId:
|
|
249
|
+
messageId: string;
|
|
236
250
|
type: EventType.TextMessageEnd;
|
|
237
251
|
}
|
|
238
252
|
export interface ITextMessageStartEvent extends IBaseEvent {
|
|
239
|
-
messageId:
|
|
240
|
-
role:
|
|
253
|
+
messageId: string;
|
|
254
|
+
role: MessageRole;
|
|
241
255
|
type: EventType.TextMessageStart;
|
|
242
256
|
}
|
|
243
257
|
/**
|
|
244
258
|
* 思考结束事件
|
|
245
|
-
*
|
|
246
|
-
* @example ThinkingEndEvent {
|
|
247
|
-
* timestamp: 1734902400000,
|
|
248
|
-
* type: EventType.ThinkingEnd,
|
|
249
|
-
* }
|
|
250
259
|
*/
|
|
251
260
|
export interface IThinkingEndEvent extends IBaseEvent {
|
|
261
|
+
duration?: number;
|
|
252
262
|
type: EventType.ThinkingEnd;
|
|
253
263
|
}
|
|
254
264
|
/**
|
|
255
265
|
* 思考开始事件
|
|
256
266
|
* 记录思考的标题 title
|
|
257
|
-
*
|
|
258
|
-
* @example ThinkingStartEvent {
|
|
259
|
-
* title: "分析需求"
|
|
260
|
-
* type: EventType.ThinkingStart,
|
|
261
|
-
* }
|
|
262
267
|
*/
|
|
263
268
|
export interface IThinkingStartEvent extends IBaseEvent {
|
|
264
269
|
title?: string;
|
|
@@ -266,12 +271,6 @@ export interface IThinkingStartEvent extends IBaseEvent {
|
|
|
266
271
|
}
|
|
267
272
|
/**
|
|
268
273
|
* 思考文本消息内容事件
|
|
269
|
-
*
|
|
270
|
-
* @example ThinkingTextMessageContentEvent {
|
|
271
|
-
* timestamp: 1734902400000,
|
|
272
|
-
* type: EventType.ThinkingTextMessageContent,
|
|
273
|
-
* delta: "思考中..."
|
|
274
|
-
* }
|
|
275
274
|
*/
|
|
276
275
|
export interface IThinkingTextMessageContentEvent extends IBaseEvent {
|
|
277
276
|
delta: string;
|
|
@@ -279,22 +278,12 @@ export interface IThinkingTextMessageContentEvent extends IBaseEvent {
|
|
|
279
278
|
}
|
|
280
279
|
/**
|
|
281
280
|
* 思考文本消息结束事件
|
|
282
|
-
*
|
|
283
|
-
* @example ThinkingTextMessageEndEvent {
|
|
284
|
-
* timestamp: 1734902400000,
|
|
285
|
-
* type: EventType.ThinkingTextMessageEnd,
|
|
286
|
-
* }
|
|
287
281
|
*/
|
|
288
282
|
export interface IThinkingTextMessageEndEvent extends IBaseEvent {
|
|
289
283
|
type: EventType.ThinkingTextMessageEnd;
|
|
290
284
|
}
|
|
291
285
|
/**
|
|
292
286
|
* 思考文本消息开始事件
|
|
293
|
-
*
|
|
294
|
-
* @example ThinkingTextMessageStartEvent {
|
|
295
|
-
* timestamp: 1734902400000,
|
|
296
|
-
* type: EventType.ThinkingTextMessageStart,
|
|
297
|
-
* }
|
|
298
287
|
*/
|
|
299
288
|
export interface IThinkingTextMessageStartEvent extends IBaseEvent {
|
|
300
289
|
type: EventType.ThinkingTextMessageStart;
|
|
@@ -317,11 +306,14 @@ export interface IToolCallEndEvent extends IBaseEvent {
|
|
|
317
306
|
}
|
|
318
307
|
export interface IToolCallResultEvent extends IBaseEvent {
|
|
319
308
|
content: string;
|
|
309
|
+
duration?: number;
|
|
320
310
|
messageId: string;
|
|
321
311
|
toolCallId: string;
|
|
322
312
|
type: EventType.ToolCallResult;
|
|
323
313
|
}
|
|
324
314
|
export interface IToolCallStartEvent extends IBaseEvent {
|
|
315
|
+
description?: string;
|
|
316
|
+
mcpName?: string;
|
|
325
317
|
parentMessageId?: string;
|
|
326
318
|
toolCallId: string;
|
|
327
319
|
toolCallName: string;
|
package/dist/event/type.ts.js
CHANGED
|
@@ -22,10 +22,18 @@
|
|
|
22
22
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
23
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
24
|
* IN THE SOFTWARE.
|
|
25
|
-
*/ export var
|
|
26
|
-
(function(
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
*/ export var CustomEventName;
|
|
26
|
+
(function(CustomEventName) {
|
|
27
|
+
CustomEventName["FlowAgentEnd"] = "flow_agent_end";
|
|
28
|
+
CustomEventName["FlowAgentResult"] = "flow_agent_result";
|
|
29
|
+
CustomEventName["FlowAgentStart"] = "flow_agent_start";
|
|
30
|
+
CustomEventName["KnowledgeRagEnd"] = "knowledge_rag_end";
|
|
31
|
+
CustomEventName["KnowledgeRagResult"] = "knowledge_rag_result";
|
|
32
|
+
CustomEventName["KnowledgeRagStart"] = "knowledge_rag_start";
|
|
33
|
+
CustomEventName["KnowledgeRagTextContent"] = "knowledge_rag_text_content";
|
|
34
|
+
CustomEventName["ReferenceDocument"] = "reference_document";
|
|
35
|
+
CustomEventName["TempMessage"] = "temp_message";
|
|
36
|
+
})(CustomEventName || (CustomEventName = {}));
|
|
29
37
|
export var EventType;
|
|
30
38
|
(function(EventType) {
|
|
31
39
|
EventType["ActivityDelta"] = "ACTIVITY_DELTA";
|
|
@@ -55,10 +63,25 @@ export var EventType;
|
|
|
55
63
|
EventType["ToolCallResult"] = "TOOL_CALL_RESULT";
|
|
56
64
|
EventType["ToolCallStart"] = "TOOL_CALL_START";
|
|
57
65
|
})(EventType || (EventType = {}));
|
|
58
|
-
export var
|
|
59
|
-
(function(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})(
|
|
66
|
+
export var FlowNodeState;
|
|
67
|
+
(function(FlowNodeState) {
|
|
68
|
+
/** 失败 */ FlowNodeState["Failed"] = "failed";
|
|
69
|
+
/** 执行中 */ FlowNodeState["Running"] = "running";
|
|
70
|
+
/** 成功 */ FlowNodeState["Success"] = "success";
|
|
71
|
+
/** 挂起 */ FlowNodeState["Suspended"] = "suspended";
|
|
72
|
+
})(FlowNodeState || (FlowNodeState = {}));
|
|
73
|
+
export var FlowTaskState;
|
|
74
|
+
(function(FlowTaskState) {
|
|
75
|
+
/** 执行中 */ FlowTaskState["Blocked"] = "BLOCKED";
|
|
76
|
+
/** 执行中 */ FlowTaskState["Created"] = "CREATED";
|
|
77
|
+
/** 失败 */ FlowTaskState["Failed"] = "FAILED";
|
|
78
|
+
/** 成功 */ FlowTaskState["Finished"] = "FINISHED";
|
|
79
|
+
/** 执行中 */ FlowTaskState["LoopReady"] = "LOOP_READY";
|
|
80
|
+
/** 执行中 */ FlowTaskState["Ready"] = "READY";
|
|
81
|
+
/** 失败 */ FlowTaskState["Revoked"] = "REVOKED";
|
|
82
|
+
/** 失败 */ FlowTaskState["RollBackFailed"] = "ROLL_BACK_FAILED";
|
|
83
|
+
/** 执行中 */ FlowTaskState["RollBackSuccess"] = "ROLL_BACK_SUCCESS";
|
|
84
|
+
/** 执行中 */ FlowTaskState["RollingBack"] = "ROLLING_BACK";
|
|
85
|
+
/** 执行中 */ FlowTaskState["Running"] = "RUNNING";
|
|
86
|
+
/** 挂起 */ FlowTaskState["Suspended"] = "SUSPENDED";
|
|
87
|
+
})(FlowTaskState || (FlowTaskState = {}));
|
|
@@ -75,8 +75,9 @@ export declare class FetchClient {
|
|
|
75
75
|
mode: "same-origin" | "cors" | "no-cors";
|
|
76
76
|
headers: Headers;
|
|
77
77
|
body: BodyInit;
|
|
78
|
-
|
|
78
|
+
signal: AbortSignal;
|
|
79
79
|
};
|
|
80
|
+
controller: AbortController;
|
|
80
81
|
};
|
|
81
82
|
put<T = unknown>(url: string, data?: unknown, config?: IRequestConfig): Promise<T>;
|
|
82
83
|
request<T = unknown>(config: IRequestConfig): Promise<T>;
|
|
@@ -238,12 +238,13 @@ export class FetchClient {
|
|
|
238
238
|
mode: requestConfig.mode,
|
|
239
239
|
headers,
|
|
240
240
|
body,
|
|
241
|
-
controller
|
|
241
|
+
signal: controller.signal
|
|
242
242
|
};
|
|
243
243
|
return {
|
|
244
244
|
url,
|
|
245
245
|
requestConfig,
|
|
246
|
-
fetchConfig
|
|
246
|
+
fetchConfig,
|
|
247
|
+
controller
|
|
247
248
|
};
|
|
248
249
|
}
|
|
249
250
|
put(url, data, config) {
|
|
@@ -257,9 +258,9 @@ export class FetchClient {
|
|
|
257
258
|
var _this = this;
|
|
258
259
|
return _async_to_generator(function*() {
|
|
259
260
|
// 准备请求
|
|
260
|
-
const { url, fetchConfig, requestConfig } = _this.prepareRequest(config);
|
|
261
|
+
const { url, fetchConfig, requestConfig, controller } = _this.prepareRequest(config);
|
|
261
262
|
// 创建超时控制
|
|
262
|
-
const timeoutId = requestConfig.timeout && requestConfig.timeout > 0 ? setTimeout(()=>
|
|
263
|
+
const timeoutId = requestConfig.timeout && requestConfig.timeout > 0 ? setTimeout(()=>controller.abort(), requestConfig.timeout) : undefined;
|
|
263
264
|
try {
|
|
264
265
|
// 发送请求
|
|
265
266
|
const fetchResponse = yield fetch(url, fetchConfig);
|
|
@@ -308,7 +309,9 @@ export class FetchClient {
|
|
|
308
309
|
// 验证状态码
|
|
309
310
|
const validateStatus = requestConfig.validateStatus || _this.defaults.validateStatus;
|
|
310
311
|
if (!validateStatus(fetchResponse.status)) {
|
|
311
|
-
|
|
312
|
+
var _response_data_error, _response_data;
|
|
313
|
+
const message = ((_response_data = response.data) === null || _response_data === void 0 ? void 0 : (_response_data_error = _response_data.error) === null || _response_data_error === void 0 ? void 0 : _response_data_error.message) || `Request failed with status code ${fetchResponse.status}`;
|
|
314
|
+
throw createError(message, requestConfig, `ERR_BAD_RESPONSE`, response);
|
|
312
315
|
}
|
|
313
316
|
// 应用响应拦截器
|
|
314
317
|
let finalResponse = response;
|
|
@@ -374,7 +377,17 @@ export class FetchClient {
|
|
|
374
377
|
const validateStatus = requestConfig.validateStatus || _this.defaults.validateStatus;
|
|
375
378
|
if (!validateStatus(fetchResponse.status)) {
|
|
376
379
|
var _config_onError;
|
|
377
|
-
|
|
380
|
+
let message = `Request failed with status code ${fetchResponse.status}`;
|
|
381
|
+
try {
|
|
382
|
+
var _errorData_error;
|
|
383
|
+
const errorData = yield fetchResponse.json();
|
|
384
|
+
if (errorData === null || errorData === void 0 ? void 0 : (_errorData_error = errorData.error) === null || _errorData_error === void 0 ? void 0 : _errorData_error.message) {
|
|
385
|
+
message = errorData.error.message;
|
|
386
|
+
}
|
|
387
|
+
} catch (_error) {
|
|
388
|
+
message = `Request failed with status code ${fetchResponse.status}`;
|
|
389
|
+
}
|
|
390
|
+
const error = createError(message, requestConfig, `ERR_BAD_RESPONSE`, undefined);
|
|
378
391
|
(_config_onError = config.onError) === null || _config_onError === void 0 ? void 0 : _config_onError.call(config, error);
|
|
379
392
|
return;
|
|
380
393
|
}
|
|
@@ -389,6 +402,15 @@ export class FetchClient {
|
|
|
389
402
|
}
|
|
390
403
|
// 临时存储数据
|
|
391
404
|
let temp = '';
|
|
405
|
+
// 判断是否为 JSON 字符串
|
|
406
|
+
const isJson = (str)=>{
|
|
407
|
+
try {
|
|
408
|
+
JSON.parse(str);
|
|
409
|
+
return true;
|
|
410
|
+
} catch (_error) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
392
414
|
// eslint-disable-next-line no-constant-condition
|
|
393
415
|
while(true){
|
|
394
416
|
const { value, done } = yield reader.read();
|
|
@@ -401,10 +423,11 @@ export class FetchClient {
|
|
|
401
423
|
const values = (temp + value.toString()).split('\n');
|
|
402
424
|
values.forEach((value)=>{
|
|
403
425
|
const item = value.replace('data:', '').trim();
|
|
404
|
-
if (item
|
|
426
|
+
if (isJson(item)) {
|
|
405
427
|
var _config_onMessage;
|
|
406
428
|
const json = JSON.parse(item);
|
|
407
429
|
(_config_onMessage = config.onMessage) === null || _config_onMessage === void 0 ? void 0 : _config_onMessage.call(config, json);
|
|
430
|
+
temp = '';
|
|
408
431
|
} else if (item) {
|
|
409
432
|
temp = item;
|
|
410
433
|
}
|
|
@@ -478,12 +501,19 @@ function createError(message, config, code, response) {
|
|
|
478
501
|
function getValue(value) {
|
|
479
502
|
return typeof value === 'function' ? value() : value;
|
|
480
503
|
}
|
|
504
|
+
// 判断是否是普通对象(排除类实例如 AbortController、Headers 等)
|
|
505
|
+
function isPlainObject(value) {
|
|
506
|
+
if (!value || typeof value !== 'object') return false;
|
|
507
|
+
const proto = Object.getPrototypeOf(value);
|
|
508
|
+
return proto === Object.prototype || proto === null;
|
|
509
|
+
}
|
|
481
510
|
// 合并配置
|
|
482
511
|
function mergeConfig(config1, config2) {
|
|
483
512
|
const output = _object_spread({}, config1);
|
|
484
513
|
for(const key in config2){
|
|
485
514
|
const value2 = config2[key];
|
|
486
|
-
|
|
515
|
+
// 只对普通对象进行深度合并,类实例(如 AbortController)直接赋值
|
|
516
|
+
if (isPlainObject(value2)) {
|
|
487
517
|
const value1 = config1[key];
|
|
488
518
|
output[key] = mergeConfig(value1 || {}, value2);
|
|
489
519
|
} else {
|
|
@@ -35,7 +35,23 @@ export const useFetch = (options)=>{
|
|
|
35
35
|
if ((_options_interceptors1 = options.interceptors) === null || _options_interceptors1 === void 0 ? void 0 : _options_interceptors1.response) {
|
|
36
36
|
fetchClient.interceptors.response.use(options.interceptors.response);
|
|
37
37
|
}
|
|
38
|
+
// 重置 fetchClient 配置
|
|
39
|
+
const reset = (newOptions)=>{
|
|
40
|
+
var _newOptions_interceptors, _newOptions_interceptors1;
|
|
41
|
+
// 更新 baseURL
|
|
42
|
+
fetchClient.defaults.baseURL = newOptions.requestData.urlPrefix;
|
|
43
|
+
// 清空并重新注册拦截器
|
|
44
|
+
fetchClient.interceptors.request.clear();
|
|
45
|
+
fetchClient.interceptors.response.clear();
|
|
46
|
+
if ((_newOptions_interceptors = newOptions.interceptors) === null || _newOptions_interceptors === void 0 ? void 0 : _newOptions_interceptors.request) {
|
|
47
|
+
fetchClient.interceptors.request.use(newOptions.interceptors.request);
|
|
48
|
+
}
|
|
49
|
+
if ((_newOptions_interceptors1 = newOptions.interceptors) === null || _newOptions_interceptors1 === void 0 ? void 0 : _newOptions_interceptors1.response) {
|
|
50
|
+
fetchClient.interceptors.response.use(newOptions.interceptors.response);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
38
53
|
return {
|
|
39
|
-
fetchClient
|
|
54
|
+
fetchClient,
|
|
55
|
+
reset
|
|
40
56
|
};
|
|
41
57
|
};
|
package/dist/http/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './transform';
|
|
|
7
7
|
* @returns HTTP 模块
|
|
8
8
|
*/
|
|
9
9
|
export declare const useHttp: (options: IUseChatHelperOptions) => {
|
|
10
|
+
reset: (newOptions: IUseChatHelperOptions) => void;
|
|
10
11
|
agent: {
|
|
11
12
|
getAgentInfo: (config?: import("./fetch").IRequestConfig) => Promise<import("..").IAgentInfo>;
|
|
12
13
|
};
|
|
@@ -25,15 +26,23 @@ export declare const useHttp: (options: IUseChatHelperOptions) => {
|
|
|
25
26
|
comment: string;
|
|
26
27
|
labels: string[];
|
|
27
28
|
}>;
|
|
28
|
-
|
|
29
|
+
getSessionFeedbackReasons: (rate: number, config?: import("./fetch").IRequestConfig) => Promise<string[]>;
|
|
29
30
|
renameSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
|
|
31
|
+
uploadFile: (sessionCode: string, file: File, config?: import("./fetch").IRequestConfig) => Promise<{
|
|
32
|
+
download_url?: string;
|
|
33
|
+
}>;
|
|
30
34
|
};
|
|
31
35
|
message: {
|
|
32
36
|
getMessages: (sessionCode: string, limit?: number, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessage[]>;
|
|
33
|
-
plusMessage: (data: import("..").IMessage, config?: import("./fetch").IRequestConfig) => Promise<import("..").IAssistantMessage | import("..").IGuideMessage | import("..").IHiddenAssistantMessage | import("..").IHiddenGuideMessage | import("..").IHiddenMessage | import("..").IHiddenSystemMessage | import("..").IHiddenUserMessage | import("..").IInfoMessage | import("..").IPauseMessage | import("..").IPlaceholderMessage | import("..").ISystemMessage | import("..").ITemplateAssistantMessage | import("..").ITemplateGuideMessage | import("..").ITemplateHiddenMessage | import("..").ITemplateSystemMessage | import("..").ITemplateUserMessage | import("..").IUserMessage>;
|
|
34
|
-
modifyMessage: (data: import("..").IMessage, config?: import("./fetch").IRequestConfig) => Promise<import("..").IAssistantMessage | import("..").IGuideMessage | import("..").IHiddenAssistantMessage | import("..").IHiddenGuideMessage | import("..").IHiddenMessage | import("..").IHiddenSystemMessage | import("..").IHiddenUserMessage | import("..").IInfoMessage | import("..").IPauseMessage | import("..").IPlaceholderMessage | import("..").ISystemMessage | import("..").ITemplateAssistantMessage | import("..").ITemplateGuideMessage | import("..").ITemplateHiddenMessage | import("..").ITemplateSystemMessage | import("..").ITemplateUserMessage | import("..").IUserMessage>;
|
|
35
|
-
deleteMessage: (id:
|
|
36
|
-
batchDeleteMessages: (ids:
|
|
37
|
+
plusMessage: (data: import("..").IMessage, config?: import("./fetch").IRequestConfig) => Promise<import("..").IActivityMessage | import("..").IAssistantMessage | import("..").IDeveloperMessage | import("..").IGuideMessage | import("..").IHiddenAssistantMessage | import("..").IHiddenGuideMessage | import("..").IHiddenMessage | import("..").IHiddenSystemMessage | import("..").IHiddenUserMessage | import("..").IInfoMessage | import("..").IPauseMessage | import("..").IPlaceholderMessage | import("..").IReasoningMessage | import("..").ISystemMessage | import("..").ITemplateAssistantMessage | import("..").ITemplateGuideMessage | import("..").ITemplateHiddenMessage | import("..").ITemplateSystemMessage | import("..").ITemplateUserMessage | import("..").IToolMessage | import("..").IUserMessage>;
|
|
38
|
+
modifyMessage: (data: import("..").IMessage, config?: import("./fetch").IRequestConfig) => Promise<import("..").IActivityMessage | import("..").IAssistantMessage | import("..").IDeveloperMessage | import("..").IGuideMessage | import("..").IHiddenAssistantMessage | import("..").IHiddenGuideMessage | import("..").IHiddenMessage | import("..").IHiddenSystemMessage | import("..").IHiddenUserMessage | import("..").IInfoMessage | import("..").IPauseMessage | import("..").IPlaceholderMessage | import("..").IReasoningMessage | import("..").ISystemMessage | import("..").ITemplateAssistantMessage | import("..").ITemplateGuideMessage | import("..").ITemplateHiddenMessage | import("..").ITemplateSystemMessage | import("..").ITemplateUserMessage | import("..").IToolMessage | import("..").IUserMessage>;
|
|
39
|
+
deleteMessage: (id: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessage>;
|
|
40
|
+
batchDeleteMessages: (ids: string[], config?: import("./fetch").IRequestConfig) => Promise<number>;
|
|
41
|
+
shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: import("./fetch").IRequestConfig) => Promise<import("./module/message").IShareMessagesResponse>;
|
|
42
|
+
stopChat: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<void>;
|
|
43
|
+
getFlowAgentTaskInfo: (taskId: number, config?: import("./fetch").IRequestConfig) => Promise<unknown>;
|
|
44
|
+
getFlowAgentTaskNodeInfo: (taskId: number, nodeId: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").IFlowAgentTaskNodeInfo>;
|
|
37
45
|
};
|
|
46
|
+
fetchClient: import("./fetch").FetchClient;
|
|
38
47
|
};
|
|
39
48
|
export type IHttpModule = ReturnType<typeof useHttp>;
|
package/dist/http/index.ts.js
CHANGED
|
@@ -22,7 +22,59 @@
|
|
|
22
22
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
23
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
24
|
* IN THE SOFTWARE.
|
|
25
|
-
*/
|
|
25
|
+
*/ function _define_property(obj, key, value) {
|
|
26
|
+
if (key in obj) {
|
|
27
|
+
Object.defineProperty(obj, key, {
|
|
28
|
+
value: value,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
obj[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
function _object_spread(target) {
|
|
39
|
+
for(var i = 1; i < arguments.length; i++){
|
|
40
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
41
|
+
var ownKeys = Object.keys(source);
|
|
42
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
43
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
44
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
ownKeys.forEach(function(key) {
|
|
48
|
+
_define_property(target, key, source[key]);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
function ownKeys(object, enumerableOnly) {
|
|
54
|
+
var keys = Object.keys(object);
|
|
55
|
+
if (Object.getOwnPropertySymbols) {
|
|
56
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
57
|
+
if (enumerableOnly) {
|
|
58
|
+
symbols = symbols.filter(function(sym) {
|
|
59
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
keys.push.apply(keys, symbols);
|
|
63
|
+
}
|
|
64
|
+
return keys;
|
|
65
|
+
}
|
|
66
|
+
function _object_spread_props(target, source) {
|
|
67
|
+
source = source != null ? source : {};
|
|
68
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
69
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
70
|
+
} else {
|
|
71
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
72
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return target;
|
|
76
|
+
}
|
|
77
|
+
import { useFetch } from './fetch/index.ts.js';
|
|
26
78
|
import { useModule } from './module/index.ts.js';
|
|
27
79
|
export * from './fetch/index.ts.js';
|
|
28
80
|
export * from './transform/index.ts.js';
|
|
@@ -31,7 +83,11 @@ export * from './transform/index.ts.js';
|
|
|
31
83
|
* @param options - 选项
|
|
32
84
|
* @returns HTTP 模块
|
|
33
85
|
*/ export const useHttp = (options)=>{
|
|
34
|
-
|
|
86
|
+
// 创建 fetchClient
|
|
87
|
+
const { fetchClient, reset } = useFetch(options);
|
|
88
|
+
// 创建 http 模块
|
|
35
89
|
const http = useModule(fetchClient);
|
|
36
|
-
return http
|
|
90
|
+
return _object_spread_props(_object_spread({}, http), {
|
|
91
|
+
reset
|
|
92
|
+
});
|
|
37
93
|
};
|