@auipage/core 0.1.0 → 0.2.0-alpha.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/AUTHORS.txt +6 -6
- package/CHANGELOG +29 -4
- package/README.md +128 -54
- package/dist/index.js +1013 -584
- package/package.json +2 -2
- package/src/AuiPage.js +736 -429
- package/src/ChatContentRuntime.js +21 -18
- package/src/ChatTransportAdapter.js +22 -17
- package/src/MessageHistoryAdapter.js +17 -17
- package/src/MessageStream.js +9 -7
- package/src/ThreadListAdapter.js +22 -20
- package/src/ThreadListRuntime.js +22 -22
- package/src/defineTool.js +15 -13
- package/src/generator.js +78 -64
- package/src/index.js +16 -12
- package/src/tools/toHistoryMessages.js +19 -16
- package/src/tools/toModelMessages.js +89 -0
- package/types/adapters/chat-transport.d.ts +62 -57
- package/types/adapters/index.d.ts +26 -26
- package/types/adapters/message-history.d.ts +35 -35
- package/types/adapters/thread-list.d.ts +45 -45
- package/types/auipage.d.ts +169 -116
- package/types/define-tool.d.ts +18 -18
- package/types/generator.d.ts +27 -27
- package/types/index.d.ts +98 -96
- package/types/message-stream.d.ts +22 -22
- package/types/message.d.ts +66 -60
- package/types/runtimes/chat-content.d.ts +65 -65
- package/types/runtimes/index.d.ts +22 -22
- package/types/runtimes/thread-list.d.ts +40 -40
- package/types/thread.d.ts +14 -14
- package/types/to-model-messages.d.ts +15 -0
- package/types/tool.d.ts +57 -51
|
@@ -1,57 +1,62 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChatTransportAdapter:对接模型对话接口
|
|
3
|
-
*/
|
|
4
|
-
import type { ToolDescription } from "@auipage/types";
|
|
5
|
-
import type {
|
|
6
|
-
ChatContentMessage,
|
|
7
|
-
ContentPart,
|
|
8
|
-
HistoryMessageGroup
|
|
9
|
-
} from "../message.js";
|
|
10
|
-
import type { AuiPage } from "../auipage.js";
|
|
11
|
-
|
|
12
|
-
/** run 的入参 */
|
|
13
|
-
export interface ChatTransportRunParams {
|
|
14
|
-
/** 本轮新发送的消息(当前实现中只有一条) */
|
|
15
|
-
messages: ChatContentMessage[];
|
|
16
|
-
context: {
|
|
17
|
-
/** 当前会话已入库的历史消息组 */
|
|
18
|
-
history: HistoryMessageGroup[];
|
|
19
|
-
/** AuiPage 构造时注册的工具描述 */
|
|
20
|
-
tools: Array<{ description: ToolDescription }>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ChatTransportAdapter:对接模型对话接口
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDescription } from "@auipage/types";
|
|
5
|
+
import type {
|
|
6
|
+
ChatContentMessage,
|
|
7
|
+
ContentPart,
|
|
8
|
+
HistoryMessageGroup
|
|
9
|
+
} from "../message.js";
|
|
10
|
+
import type { AuiPage } from "../auipage.js";
|
|
11
|
+
|
|
12
|
+
/** run 的入参 */
|
|
13
|
+
export interface ChatTransportRunParams {
|
|
14
|
+
/** 本轮新发送的消息(当前实现中只有一条) */
|
|
15
|
+
messages: ChatContentMessage[];
|
|
16
|
+
context: {
|
|
17
|
+
/** 当前会话已入库的历史消息组 */
|
|
18
|
+
history: HistoryMessageGroup[];
|
|
19
|
+
/** AuiPage 构造时注册的工具描述 */
|
|
20
|
+
tools: Array<{ description: ToolDescription }>;
|
|
21
|
+
/**
|
|
22
|
+
* 取消信号(0.2.0 起提供):透传给底层 HTTP / 模型请求,
|
|
23
|
+
* AuiPage.stop() 时 abort。不接则取消只在页面侧生效,底层请求仍会跑完。
|
|
24
|
+
*/
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 发起一轮对话并返回异步生成器,逐个 yield 消息片段;
|
|
31
|
+
* 返回假值时 AuiPage 会直接终止本轮处理。
|
|
32
|
+
*/
|
|
33
|
+
export type ChatTransportRun = (
|
|
34
|
+
params: ChatTransportRunParams
|
|
35
|
+
) => AsyncGenerator<ContentPart, void, void> | void | null | undefined;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 页面 → 服务端的反向回传通道。
|
|
39
|
+
* 目前仅用于前端工具结果回传:response("tool-result", { id, status, result })。
|
|
40
|
+
*/
|
|
41
|
+
export type ChatTransportResponse = (
|
|
42
|
+
name: string,
|
|
43
|
+
data: Record<string, unknown>
|
|
44
|
+
) => unknown;
|
|
45
|
+
|
|
46
|
+
export interface ChatTransportAdapterOptions {
|
|
47
|
+
run?: ChatTransportRun;
|
|
48
|
+
response?: ChatTransportResponse;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare class ChatTransportAdapter {
|
|
52
|
+
constructor(options?: ChatTransportAdapterOptions);
|
|
53
|
+
|
|
54
|
+
/** 实例名,AuiPage 按它去掉 Adapter 后缀后挂载;子类可覆盖 */
|
|
55
|
+
name: string;
|
|
56
|
+
|
|
57
|
+
run: ChatTransportRun;
|
|
58
|
+
response: ChatTransportResponse;
|
|
59
|
+
|
|
60
|
+
/** 被 AuiPage 挂载后写入的反向引用 */
|
|
61
|
+
aui?: AuiPage;
|
|
62
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 适配器(Adapter)类型入口:负责对接模型 / 存储等外部世界
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
ChatTransportAdapter,
|
|
7
|
-
type ChatTransportAdapterOptions,
|
|
8
|
-
type ChatTransportRun,
|
|
9
|
-
type ChatTransportRunParams,
|
|
10
|
-
type ChatTransportResponse
|
|
11
|
-
} from "./chat-transport.js";
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
MessageHistoryAdapter,
|
|
15
|
-
type MessageHistoryAdapterOptions,
|
|
16
|
-
type MessageHistoryLoad,
|
|
17
|
-
type MessageHistoryAppend
|
|
18
|
-
} from "./message-history.js";
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
ThreadListAdapter,
|
|
22
|
-
type ThreadListAdapterOptions,
|
|
23
|
-
type ThreadListList,
|
|
24
|
-
type ThreadListNew,
|
|
25
|
-
type ThreadIdHandler
|
|
26
|
-
} from "./thread-list.js";
|
|
1
|
+
/**
|
|
2
|
+
* 适配器(Adapter)类型入口:负责对接模型 / 存储等外部世界
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
ChatTransportAdapter,
|
|
7
|
+
type ChatTransportAdapterOptions,
|
|
8
|
+
type ChatTransportRun,
|
|
9
|
+
type ChatTransportRunParams,
|
|
10
|
+
type ChatTransportResponse
|
|
11
|
+
} from "./chat-transport.js";
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
MessageHistoryAdapter,
|
|
15
|
+
type MessageHistoryAdapterOptions,
|
|
16
|
+
type MessageHistoryLoad,
|
|
17
|
+
type MessageHistoryAppend
|
|
18
|
+
} from "./message-history.js";
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
ThreadListAdapter,
|
|
22
|
+
type ThreadListAdapterOptions,
|
|
23
|
+
type ThreadListList,
|
|
24
|
+
type ThreadListNew,
|
|
25
|
+
type ThreadIdHandler
|
|
26
|
+
} from "./thread-list.js";
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessageHistoryAdapter:历史消息的加载与追加
|
|
3
|
-
*/
|
|
4
|
-
import type { MaybePromise } from "@auipage/types";
|
|
5
|
-
import type { HistoryMessageGroup } from "../message.js";
|
|
6
|
-
import type { AuiPage } from "../auipage.js";
|
|
7
|
-
|
|
8
|
-
/** 加载指定会话的历史消息组;返回假值时 AuiPage 跳过历史加载 */
|
|
9
|
-
export type MessageHistoryLoad = (
|
|
10
|
-
threadId: string
|
|
11
|
-
) => MaybePromise<HistoryMessageGroup[] | void | null | undefined>;
|
|
12
|
-
|
|
13
|
-
/** 把一轮消息组追加到指定会话 */
|
|
14
|
-
export type MessageHistoryAppend = (
|
|
15
|
-
threadId: string,
|
|
16
|
-
message: HistoryMessageGroup
|
|
17
|
-
) => MaybePromise<void>;
|
|
18
|
-
|
|
19
|
-
export interface MessageHistoryAdapterOptions {
|
|
20
|
-
load?: MessageHistoryLoad;
|
|
21
|
-
append?: MessageHistoryAppend;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export declare class MessageHistoryAdapter {
|
|
25
|
-
constructor(options?: MessageHistoryAdapterOptions);
|
|
26
|
-
|
|
27
|
-
/** 实例名,AuiPage 按它去掉 Adapter 后缀后挂载;子类可覆盖 */
|
|
28
|
-
name: string;
|
|
29
|
-
|
|
30
|
-
load: MessageHistoryLoad;
|
|
31
|
-
append: MessageHistoryAppend;
|
|
32
|
-
|
|
33
|
-
/** 被 AuiPage 挂载后写入的反向引用 */
|
|
34
|
-
aui?: AuiPage;
|
|
35
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* MessageHistoryAdapter:历史消息的加载与追加
|
|
3
|
+
*/
|
|
4
|
+
import type { MaybePromise } from "@auipage/types";
|
|
5
|
+
import type { HistoryMessageGroup } from "../message.js";
|
|
6
|
+
import type { AuiPage } from "../auipage.js";
|
|
7
|
+
|
|
8
|
+
/** 加载指定会话的历史消息组;返回假值时 AuiPage 跳过历史加载 */
|
|
9
|
+
export type MessageHistoryLoad = (
|
|
10
|
+
threadId: string
|
|
11
|
+
) => MaybePromise<HistoryMessageGroup[] | void | null | undefined>;
|
|
12
|
+
|
|
13
|
+
/** 把一轮消息组追加到指定会话 */
|
|
14
|
+
export type MessageHistoryAppend = (
|
|
15
|
+
threadId: string,
|
|
16
|
+
message: HistoryMessageGroup
|
|
17
|
+
) => MaybePromise<void>;
|
|
18
|
+
|
|
19
|
+
export interface MessageHistoryAdapterOptions {
|
|
20
|
+
load?: MessageHistoryLoad;
|
|
21
|
+
append?: MessageHistoryAppend;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare class MessageHistoryAdapter {
|
|
25
|
+
constructor(options?: MessageHistoryAdapterOptions);
|
|
26
|
+
|
|
27
|
+
/** 实例名,AuiPage 按它去掉 Adapter 后缀后挂载;子类可覆盖 */
|
|
28
|
+
name: string;
|
|
29
|
+
|
|
30
|
+
load: MessageHistoryLoad;
|
|
31
|
+
append: MessageHistoryAppend;
|
|
32
|
+
|
|
33
|
+
/** 被 AuiPage 挂载后写入的反向引用 */
|
|
34
|
+
aui?: AuiPage;
|
|
35
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ThreadListAdapter:会话列表的增删改查
|
|
3
|
-
*/
|
|
4
|
-
import type { MaybePromise } from "@auipage/types";
|
|
5
|
-
import type { HistoryMessageGroup } from "../message.js";
|
|
6
|
-
import type { Thread } from "../thread.js";
|
|
7
|
-
import type { AuiPage } from "../auipage.js";
|
|
8
|
-
|
|
9
|
-
/** 获取会话列表 */
|
|
10
|
-
export type ThreadListList = () => MaybePromise<Thread[]>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 创建新会话,入参为首轮消息组;
|
|
14
|
-
* 返回假值时 AuiPage 中止本轮后续处理(不渲染会话、不写历史)。
|
|
15
|
-
*/
|
|
16
|
-
export type ThreadListNew = (
|
|
17
|
-
firstMessage: HistoryMessageGroup
|
|
18
|
-
) => MaybePromise<Thread | void | null | undefined>;
|
|
19
|
-
|
|
20
|
-
/** 以会话 ID 为入参的操作:删除 / 归档 / 取消归档 */
|
|
21
|
-
export type ThreadIdHandler = (threadId: string) => MaybePromise<void>;
|
|
22
|
-
|
|
23
|
-
export interface ThreadListAdapterOptions {
|
|
24
|
-
list?: ThreadListList;
|
|
25
|
-
new?: ThreadListNew;
|
|
26
|
-
delete?: ThreadIdHandler;
|
|
27
|
-
archive?: ThreadIdHandler;
|
|
28
|
-
unarchive?: ThreadIdHandler;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export declare class ThreadListAdapter {
|
|
32
|
-
constructor(options?: ThreadListAdapterOptions);
|
|
33
|
-
|
|
34
|
-
/** 实例名,AuiPage 按它去掉 Adapter 后缀后挂载;子类可覆盖 */
|
|
35
|
-
name: string;
|
|
36
|
-
|
|
37
|
-
list: ThreadListList;
|
|
38
|
-
new: ThreadListNew;
|
|
39
|
-
delete: ThreadIdHandler;
|
|
40
|
-
archive: ThreadIdHandler;
|
|
41
|
-
unarchive: ThreadIdHandler;
|
|
42
|
-
|
|
43
|
-
/** 被 AuiPage 挂载后写入的反向引用 */
|
|
44
|
-
aui?: AuiPage;
|
|
45
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* ThreadListAdapter:会话列表的增删改查
|
|
3
|
+
*/
|
|
4
|
+
import type { MaybePromise } from "@auipage/types";
|
|
5
|
+
import type { HistoryMessageGroup } from "../message.js";
|
|
6
|
+
import type { Thread } from "../thread.js";
|
|
7
|
+
import type { AuiPage } from "../auipage.js";
|
|
8
|
+
|
|
9
|
+
/** 获取会话列表 */
|
|
10
|
+
export type ThreadListList = () => MaybePromise<Thread[]>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 创建新会话,入参为首轮消息组;
|
|
14
|
+
* 返回假值时 AuiPage 中止本轮后续处理(不渲染会话、不写历史)。
|
|
15
|
+
*/
|
|
16
|
+
export type ThreadListNew = (
|
|
17
|
+
firstMessage: HistoryMessageGroup
|
|
18
|
+
) => MaybePromise<Thread | void | null | undefined>;
|
|
19
|
+
|
|
20
|
+
/** 以会话 ID 为入参的操作:删除 / 归档 / 取消归档 */
|
|
21
|
+
export type ThreadIdHandler = (threadId: string) => MaybePromise<void>;
|
|
22
|
+
|
|
23
|
+
export interface ThreadListAdapterOptions {
|
|
24
|
+
list?: ThreadListList;
|
|
25
|
+
new?: ThreadListNew;
|
|
26
|
+
delete?: ThreadIdHandler;
|
|
27
|
+
archive?: ThreadIdHandler;
|
|
28
|
+
unarchive?: ThreadIdHandler;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare class ThreadListAdapter {
|
|
32
|
+
constructor(options?: ThreadListAdapterOptions);
|
|
33
|
+
|
|
34
|
+
/** 实例名,AuiPage 按它去掉 Adapter 后缀后挂载;子类可覆盖 */
|
|
35
|
+
name: string;
|
|
36
|
+
|
|
37
|
+
list: ThreadListList;
|
|
38
|
+
new: ThreadListNew;
|
|
39
|
+
delete: ThreadIdHandler;
|
|
40
|
+
archive: ThreadIdHandler;
|
|
41
|
+
unarchive: ThreadIdHandler;
|
|
42
|
+
|
|
43
|
+
/** 被 AuiPage 挂载后写入的反向引用 */
|
|
44
|
+
aui?: AuiPage;
|
|
45
|
+
}
|
package/types/auipage.d.ts
CHANGED
|
@@ -1,116 +1,169 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AuiPage:框架核心,串联 Adapter(业务侧)与 Runtime(UI 侧),
|
|
3
|
-
* 维护会话、消息历史、流式对话与工具调用状态。
|
|
4
|
-
*/
|
|
5
|
-
import type { ToolDescription, ToolExecutor } from "@auipage/types";
|
|
6
|
-
import type {
|
|
7
|
-
ChatContentMessage,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
15
|
-
import type {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1
|
+
/**
|
|
2
|
+
* AuiPage:框架核心,串联 Adapter(业务侧)与 Runtime(UI 侧),
|
|
3
|
+
* 维护会话、消息历史、流式对话与工具调用状态。
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolDescription, ToolExecutor } from "@auipage/types";
|
|
6
|
+
import type {
|
|
7
|
+
ChatContentMessage,
|
|
8
|
+
ContentPart,
|
|
9
|
+
HistoryMessageGroup
|
|
10
|
+
} from "./message.js";
|
|
11
|
+
import type { Tool, ToolRender } from "./tool.js";
|
|
12
|
+
import type { ChatTransportAdapter } from "./adapters/chat-transport.js";
|
|
13
|
+
import type { MessageHistoryAdapter } from "./adapters/message-history.js";
|
|
14
|
+
import type { ThreadListAdapter } from "./adapters/thread-list.js";
|
|
15
|
+
import type { ThreadListRuntime } from "./runtimes/thread-list.js";
|
|
16
|
+
import type { ChatContentRuntime } from "./runtimes/chat-content.js";
|
|
17
|
+
|
|
18
|
+
/** 三个适配器的挂载集合(key 与实例 name 去掉 Adapter 后缀一致) */
|
|
19
|
+
export interface AuiPageAdapterSet {
|
|
20
|
+
ChatTransport: ChatTransportAdapter;
|
|
21
|
+
MessageHistory: MessageHistoryAdapter;
|
|
22
|
+
ThreadList: ThreadListAdapter;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 两个运行时的挂载集合(key 与实例 name 去掉 Runtime 后缀一致) */
|
|
26
|
+
export interface AuiPageRuntimeSet {
|
|
27
|
+
ThreadList: ThreadListRuntime;
|
|
28
|
+
ChatContent: ChatContentRuntime;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AuiPageOptions {
|
|
32
|
+
adapter: AuiPageAdapterSet;
|
|
33
|
+
runtime: AuiPageRuntimeSet;
|
|
34
|
+
/** 页面侧工具列表;可选,不使用工具时省略 */
|
|
35
|
+
tools?: Tool[];
|
|
36
|
+
/**
|
|
37
|
+
* 主动结束 / 取消时等待当前分片落定的兜底时长(毫秒),默认 5000(0.2.0 起提供)。
|
|
38
|
+
* 适配器忽略 signal 而不返回时,到点强制收尾,避免页面停在“执行中”。
|
|
39
|
+
*/
|
|
40
|
+
stopTimeout?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 任务生命周期事件名 */
|
|
44
|
+
export type AuiLifecycleEvent = "task:start" | "task:end";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 任务结束状态(0.2.0 起提供完整四态):
|
|
48
|
+
* - complete:模型流自然结束
|
|
49
|
+
* - stopped:主动结束(stop(),含工具里调用),当成功收尾
|
|
50
|
+
* - cancelled:取消(cancel(),含工具里调用),当失败收尾
|
|
51
|
+
* - error:流式过程抛错或入库失败
|
|
52
|
+
*/
|
|
53
|
+
export type AuiTaskStatus = "complete" | "stopped" | "cancelled" | "error";
|
|
54
|
+
|
|
55
|
+
/** 主动结束 / 取消的发起方(0.2.0 起提供) */
|
|
56
|
+
export type AuiEndBy = "user" | "tool";
|
|
57
|
+
|
|
58
|
+
/** task:start 回调载荷 */
|
|
59
|
+
export interface TaskLifecyclePayload {
|
|
60
|
+
/** 本次 sendMessage 自增生成的唯一任务 id */
|
|
61
|
+
taskId: string;
|
|
62
|
+
/** 任务发起时所处的会话 ID;新建会话场景下为 undefined */
|
|
63
|
+
threadId: string | undefined;
|
|
64
|
+
/** 本次发送的原始页面消息 */
|
|
65
|
+
message: ChatContentMessage;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 本次任务已交给界面渲染的条目(0.2.0 起提供)。
|
|
70
|
+
* part 是交给 ChatContentRuntime.append 的原始片段引用,可用它找回自己渲染的节点。
|
|
71
|
+
*/
|
|
72
|
+
export interface DisplayedPart {
|
|
73
|
+
/** 任务内的显示序号,从 0 开始 */
|
|
74
|
+
index: number;
|
|
75
|
+
/** 渲染时使用的角色 */
|
|
76
|
+
role: string;
|
|
77
|
+
/** 渲染时交给 append 的原始片段 */
|
|
78
|
+
part: ContentPart;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** task:end 回调载荷;在 TaskLifecyclePayload 基础上附带 status */
|
|
82
|
+
export interface TaskEndPayload extends TaskLifecyclePayload {
|
|
83
|
+
status: AuiTaskStatus;
|
|
84
|
+
/** 仅在 status 为 stopped / cancelled 时提供:谁发起的结束 */
|
|
85
|
+
by?: AuiEndBy;
|
|
86
|
+
/** 仅在 status 为 cancelled 时提供:本轮涉及的已显示条目 */
|
|
87
|
+
displayed?: DisplayedPart[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 生命周期事件 handler 签名 */
|
|
91
|
+
export type TaskStartHandler = (payload: TaskLifecyclePayload) => void;
|
|
92
|
+
export type TaskEndHandler = (payload: TaskEndPayload) => void;
|
|
93
|
+
|
|
94
|
+
export declare class AuiPage {
|
|
95
|
+
constructor(options: AuiPageOptions);
|
|
96
|
+
|
|
97
|
+
/** 按 name 映射后的适配器集合 */
|
|
98
|
+
adapter: AuiPageAdapterSet;
|
|
99
|
+
/** 按 name 映射后的运行时集合 */
|
|
100
|
+
runtime: AuiPageRuntimeSet;
|
|
101
|
+
|
|
102
|
+
/** 工具名 → 页面执行函数 */
|
|
103
|
+
tools_execute: Record<string, ToolExecutor>;
|
|
104
|
+
/** 工具名 → UI 交互函数(可能为 undefined) */
|
|
105
|
+
tools_render: Record<string, ToolRender | undefined>;
|
|
106
|
+
/** 透传给 ChatTransport.run 的 context.tools */
|
|
107
|
+
tools_description: Array<{ description: ToolDescription }>;
|
|
108
|
+
|
|
109
|
+
/** 当前是否处于对话执行中;执行中拒绝重复发送、忽略会话切换 */
|
|
110
|
+
isExecuting: boolean;
|
|
111
|
+
/** 当前激活的会话 ID;undefined 表示“新建会话”状态 */
|
|
112
|
+
currentThreadId: string | undefined;
|
|
113
|
+
/** 当前会话已加载的历史消息组 */
|
|
114
|
+
currentMessages: HistoryMessageGroup[];
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 发送一条消息并驱动完整的流式对话流程;
|
|
118
|
+
* 上一轮执行中时以 "当前正在执行中" reject,被 cancel() 取消时以 "已取消" reject;
|
|
119
|
+
* 全部完成(含落库)后 resolve;被 stop() 主动结束时同样 resolve;
|
|
120
|
+
* 流式过程出错时以原始 error reject(同时触发 task:end { status: "error" })。
|
|
121
|
+
*/
|
|
122
|
+
sendMessage(message: ChatContentMessage): Promise<void>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 主动结束当前任务(0.2.0 起提供):中断底层请求(context.signal 被 abort),
|
|
126
|
+
* 已产出的内容保留,消息组以 status: "stopped" 入库,
|
|
127
|
+
* 触发 task:end { status: "stopped", by } 后让 sendMessage 正常 resolve。
|
|
128
|
+
*
|
|
129
|
+
* 工具里调用时优先用 execute / render 拿到的 control.stop(),那会带上 by: "tool"。
|
|
130
|
+
*
|
|
131
|
+
* @returns 当时是否有正在执行的任务;没有则返回 false
|
|
132
|
+
*/
|
|
133
|
+
stop(): boolean;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 取消当前任务(0.2.0 起提供):与 stop() 相同的打断方式,但按失败收尾——
|
|
137
|
+
* 消息组以 status: "cancelled" 入库,task:end 附带 displayed(本轮已显示条目),
|
|
138
|
+
* sendMessage 以 "已取消" reject,界面可据此撤销已渲染的内容。
|
|
139
|
+
*
|
|
140
|
+
* @returns 当时是否有正在执行的任务;没有则返回 false
|
|
141
|
+
*/
|
|
142
|
+
cancel(): boolean;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 订阅任务生命周期事件。同名事件可注册多个 handler,触发时按注册顺序串行调用,
|
|
146
|
+
* handler 内部抛错被吞掉,不会影响 sendMessage 主流程。链式返回 AuiPage。
|
|
147
|
+
*/
|
|
148
|
+
on(event: "task:start", handler: TaskStartHandler): this;
|
|
149
|
+
on(event: "task:end", handler: TaskEndHandler): this;
|
|
150
|
+
|
|
151
|
+
/** 取消事件订阅;handler 未注册过则 no-op。链式返回 AuiPage */
|
|
152
|
+
off(event: AuiLifecycleEvent, handler: Function): this;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 切换到指定会话;threadId 为 undefined 表示进入新建会话状态。
|
|
156
|
+
* 对话执行中调用会被忽略(noLoad 内部调用除外)。
|
|
157
|
+
* @param noLoad 内部参数:true 时跳过历史重载(新建会话后使用)
|
|
158
|
+
*/
|
|
159
|
+
activeThread(threadId: string | undefined, noLoad?: boolean): void;
|
|
160
|
+
|
|
161
|
+
/** 删除会话;删除的是当前会话时自动进入新建会话状态 */
|
|
162
|
+
deleteThread(threadId: string): void;
|
|
163
|
+
/** 归档会话;归档的是当前会话时自动进入新建会话状态 */
|
|
164
|
+
archiveThread(threadId: string): void;
|
|
165
|
+
/** 取消归档(不自动切换会话) */
|
|
166
|
+
unarchiveThread(threadId: string): void;
|
|
167
|
+
/** 进入新建会话状态,等价于 activeThread(undefined) */
|
|
168
|
+
newThread(): void;
|
|
169
|
+
}
|