@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
package/types/define-tool.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* defineTool:工具工厂,把平铺参数组装为标准工具对象
|
|
3
|
-
*/
|
|
4
|
-
import type { DefineToolOptions, Tool } from "./tool.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @example
|
|
8
|
-
* defineTool({
|
|
9
|
-
* name: "showPlain",
|
|
10
|
-
* description: "显示文本文件中的内容",
|
|
11
|
-
* parameters: { type: "object", properties: { ... }, required: ["content"] },
|
|
12
|
-
* execute: async (args) => args.content,
|
|
13
|
-
* render: async ({ result }) => { alert(result); return "显示成功"; }
|
|
14
|
-
* });
|
|
15
|
-
*/
|
|
16
|
-
declare function defineTool(options: DefineToolOptions): Tool;
|
|
17
|
-
|
|
18
|
-
export default defineTool;
|
|
1
|
+
/**
|
|
2
|
+
* defineTool:工具工厂,把平铺参数组装为标准工具对象
|
|
3
|
+
*/
|
|
4
|
+
import type { DefineToolOptions, Tool } from "./tool.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @example
|
|
8
|
+
* defineTool({
|
|
9
|
+
* name: "showPlain",
|
|
10
|
+
* description: "显示文本文件中的内容",
|
|
11
|
+
* parameters: { type: "object", properties: { ... }, required: ["content"] },
|
|
12
|
+
* execute: async (args) => args.content,
|
|
13
|
+
* render: async ({ result }) => { alert(result); return "显示成功"; }
|
|
14
|
+
* });
|
|
15
|
+
*/
|
|
16
|
+
declare function defineTool(options: DefineToolOptions): Tool;
|
|
17
|
+
|
|
18
|
+
export default defineTool;
|
package/types/generator.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* generator:把 next / done / error 回调式异步流程转换为 AsyncGenerator
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/** 推送下一个值 */
|
|
6
|
-
export type StreamNext<T> = (value: T) => void;
|
|
7
|
-
/** 标记生产者结束 */
|
|
8
|
-
export type StreamDone = () => void;
|
|
9
|
-
/** 标记生产者异常 */
|
|
10
|
-
export type StreamError = (err: unknown) => void;
|
|
11
|
-
|
|
12
|
-
/** 生产者函数:立即执行,通过三个回调驱动数据流 */
|
|
13
|
-
export type StreamProducer<T> = (
|
|
14
|
-
next: StreamNext<T>,
|
|
15
|
-
done: StreamDone,
|
|
16
|
-
error: StreamError
|
|
17
|
-
) => void;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @param rawFun 生产者函数,接收 next / done / error 三个回调
|
|
21
|
-
* @returns 按推送顺序产出值的异步生成器
|
|
22
|
-
*/
|
|
23
|
-
declare function generator<T>(
|
|
24
|
-
rawFun: StreamProducer<T>
|
|
25
|
-
): AsyncGenerator<T, void, void>;
|
|
26
|
-
|
|
27
|
-
export default generator;
|
|
1
|
+
/**
|
|
2
|
+
* generator:把 next / done / error 回调式异步流程转换为 AsyncGenerator
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** 推送下一个值 */
|
|
6
|
+
export type StreamNext<T> = (value: T) => void;
|
|
7
|
+
/** 标记生产者结束 */
|
|
8
|
+
export type StreamDone = () => void;
|
|
9
|
+
/** 标记生产者异常 */
|
|
10
|
+
export type StreamError = (err: unknown) => void;
|
|
11
|
+
|
|
12
|
+
/** 生产者函数:立即执行,通过三个回调驱动数据流 */
|
|
13
|
+
export type StreamProducer<T> = (
|
|
14
|
+
next: StreamNext<T>,
|
|
15
|
+
done: StreamDone,
|
|
16
|
+
error: StreamError
|
|
17
|
+
) => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param rawFun 生产者函数,接收 next / done / error 三个回调
|
|
21
|
+
* @returns 按推送顺序产出值的异步生成器
|
|
22
|
+
*/
|
|
23
|
+
declare function generator<T>(
|
|
24
|
+
rawFun: StreamProducer<T>
|
|
25
|
+
): AsyncGenerator<T, void, void>;
|
|
26
|
+
|
|
27
|
+
export default generator;
|
package/types/index.d.ts
CHANGED
|
@@ -1,96 +1,98 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @auipage/core 类型入口
|
|
3
|
-
*
|
|
4
|
-
* “适配器 + 运行时”机制的核心抽象层:
|
|
5
|
-
* 业务侧实现 Adapter 对接模型/存储,UI 侧实现 Runtime 负责渲染,
|
|
6
|
-
* AuiPage 串联两者,统一处理会话、历史、流式对话与前后端工具调用。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/* ---------- 核心类 ---------- */
|
|
10
|
-
export {
|
|
11
|
-
AuiPage,
|
|
12
|
-
type AuiPageOptions,
|
|
13
|
-
type AuiPageAdapterSet,
|
|
14
|
-
type AuiPageRuntimeSet,
|
|
15
|
-
type AuiLifecycleEvent,
|
|
16
|
-
type AuiTaskStatus,
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
type
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
type
|
|
35
|
-
type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
type
|
|
41
|
-
type
|
|
42
|
-
type
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
type
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
type
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
type
|
|
58
|
-
type
|
|
59
|
-
type
|
|
60
|
-
type
|
|
61
|
-
type
|
|
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
|
-
type
|
|
90
|
-
type
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @auipage/core 类型入口
|
|
3
|
+
*
|
|
4
|
+
* “适配器 + 运行时”机制的核心抽象层:
|
|
5
|
+
* 业务侧实现 Adapter 对接模型/存储,UI 侧实现 Runtime 负责渲染,
|
|
6
|
+
* AuiPage 串联两者,统一处理会话、历史、流式对话与前后端工具调用。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* ---------- 核心类 ---------- */
|
|
10
|
+
export {
|
|
11
|
+
AuiPage,
|
|
12
|
+
type AuiPageOptions,
|
|
13
|
+
type AuiPageAdapterSet,
|
|
14
|
+
type AuiPageRuntimeSet,
|
|
15
|
+
type AuiLifecycleEvent,
|
|
16
|
+
type AuiTaskStatus,
|
|
17
|
+
type AuiEndBy,
|
|
18
|
+
type TaskLifecyclePayload,
|
|
19
|
+
type TaskEndPayload,
|
|
20
|
+
type TaskStartHandler,
|
|
21
|
+
type TaskEndHandler
|
|
22
|
+
} from "./auipage.js";
|
|
23
|
+
|
|
24
|
+
/* ---------- 适配器 ---------- */
|
|
25
|
+
export {
|
|
26
|
+
ChatTransportAdapter,
|
|
27
|
+
type ChatTransportAdapterOptions,
|
|
28
|
+
type ChatTransportRun,
|
|
29
|
+
type ChatTransportRunParams,
|
|
30
|
+
type ChatTransportResponse
|
|
31
|
+
} from "./adapters/chat-transport.js";
|
|
32
|
+
export {
|
|
33
|
+
MessageHistoryAdapter,
|
|
34
|
+
type MessageHistoryAdapterOptions,
|
|
35
|
+
type MessageHistoryLoad,
|
|
36
|
+
type MessageHistoryAppend
|
|
37
|
+
} from "./adapters/message-history.js";
|
|
38
|
+
export {
|
|
39
|
+
ThreadListAdapter,
|
|
40
|
+
type ThreadListAdapterOptions,
|
|
41
|
+
type ThreadListList,
|
|
42
|
+
type ThreadListNew,
|
|
43
|
+
type ThreadIdHandler
|
|
44
|
+
} from "./adapters/thread-list.js";
|
|
45
|
+
|
|
46
|
+
/* ---------- 运行时 ---------- */
|
|
47
|
+
export {
|
|
48
|
+
ThreadListRuntime,
|
|
49
|
+
type ThreadListRuntimeOptions,
|
|
50
|
+
type ThreadInitHandler,
|
|
51
|
+
type ThreadActiveHandler,
|
|
52
|
+
type ThreadAppendHandler,
|
|
53
|
+
type ThreadIdUIHandler
|
|
54
|
+
} from "./runtimes/thread-list.js";
|
|
55
|
+
export {
|
|
56
|
+
ChatContentRuntime,
|
|
57
|
+
type ChatContentRuntimeOptions,
|
|
58
|
+
type ChatInitHandler,
|
|
59
|
+
type ChatAppendHandler,
|
|
60
|
+
type ChatAppendReturn,
|
|
61
|
+
type TextStreamUpdater,
|
|
62
|
+
type ToolEndCallback
|
|
63
|
+
} from "./runtimes/chat-content.js";
|
|
64
|
+
|
|
65
|
+
/* ---------- 工具 ---------- */
|
|
66
|
+
export type {
|
|
67
|
+
Tool,
|
|
68
|
+
ToolRender,
|
|
69
|
+
ToolRenderData,
|
|
70
|
+
DefineToolOptions
|
|
71
|
+
} from "./tool.js";
|
|
72
|
+
export { default as defineTool } from "./define-tool.js";
|
|
73
|
+
|
|
74
|
+
/* ---------- 消息与会话 ---------- */
|
|
75
|
+
export { default as toModelMessages } from "./to-model-messages.js";
|
|
76
|
+
export type {
|
|
77
|
+
TextContentType,
|
|
78
|
+
TextContentPart,
|
|
79
|
+
ToolCallContentPart,
|
|
80
|
+
ContentPart,
|
|
81
|
+
ChatContentMessage,
|
|
82
|
+
HistoryMessageGroup
|
|
83
|
+
} from "./message.js";
|
|
84
|
+
export type { Thread } from "./thread.js";
|
|
85
|
+
|
|
86
|
+
/* ---------- 流工具 ---------- */
|
|
87
|
+
export {
|
|
88
|
+
default as generator,
|
|
89
|
+
type StreamProducer,
|
|
90
|
+
type StreamNext,
|
|
91
|
+
type StreamDone,
|
|
92
|
+
type StreamError
|
|
93
|
+
} from "./generator.js";
|
|
94
|
+
export {
|
|
95
|
+
MessageStream,
|
|
96
|
+
type MessageSendHandler,
|
|
97
|
+
type MessageEndHandler
|
|
98
|
+
} from "./message-stream.js";
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessageStream:消息流的简单封装
|
|
3
|
-
*
|
|
4
|
-
* 常用于服务端(配合 @auipage/agent 的 CreateTool)向页面推送 SSE 事件。
|
|
5
|
-
*/
|
|
6
|
-
import type { StreamEvent } from "@auipage/types";
|
|
7
|
-
|
|
8
|
-
/** 发送一条流式事件 */
|
|
9
|
-
export type MessageSendHandler = (data: StreamEvent) => void;
|
|
10
|
-
/** 结束本次消息流 */
|
|
11
|
-
export type MessageEndHandler = () => void;
|
|
12
|
-
|
|
13
|
-
export declare class MessageStream {
|
|
14
|
-
/**
|
|
15
|
-
* @param send 发送回调,缺省为空函数
|
|
16
|
-
* @param end 结束回调,缺省为空函数
|
|
17
|
-
*/
|
|
18
|
-
constructor(send?: MessageSendHandler, end?: MessageEndHandler);
|
|
19
|
-
|
|
20
|
-
send: MessageSendHandler;
|
|
21
|
-
end: MessageEndHandler;
|
|
22
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* MessageStream:消息流的简单封装
|
|
3
|
+
*
|
|
4
|
+
* 常用于服务端(配合 @auipage/agent 的 CreateTool)向页面推送 SSE 事件。
|
|
5
|
+
*/
|
|
6
|
+
import type { StreamEvent } from "@auipage/types";
|
|
7
|
+
|
|
8
|
+
/** 发送一条流式事件 */
|
|
9
|
+
export type MessageSendHandler = (data: StreamEvent) => void;
|
|
10
|
+
/** 结束本次消息流 */
|
|
11
|
+
export type MessageEndHandler = () => void;
|
|
12
|
+
|
|
13
|
+
export declare class MessageStream {
|
|
14
|
+
/**
|
|
15
|
+
* @param send 发送回调,缺省为空函数
|
|
16
|
+
* @param end 结束回调,缺省为空函数
|
|
17
|
+
*/
|
|
18
|
+
constructor(send?: MessageSendHandler, end?: MessageEndHandler);
|
|
19
|
+
|
|
20
|
+
send: MessageSendHandler;
|
|
21
|
+
end: MessageEndHandler;
|
|
22
|
+
}
|
package/types/message.d.ts
CHANGED
|
@@ -1,60 +1,66 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 页面侧的消息 / 内容片段类型(UI 渲染与历史入库使用)
|
|
3
|
-
*/
|
|
4
|
-
import type { ToolCallSide, ToolCallStatus } from "@auipage/types";
|
|
5
|
-
import type { ToolRender } from "./tool.js";
|
|
6
|
-
|
|
7
|
-
/** 文本类片段类型:正文 / 思维链 / 加载提示 */
|
|
8
|
-
export type TextContentType = "text" | "thinking" | "loading";
|
|
9
|
-
|
|
10
|
-
/** 文本类内容片段,同类型连续片段按增量拼接 */
|
|
11
|
-
export interface TextContentPart {
|
|
12
|
-
type: TextContentType;
|
|
13
|
-
/** 本次增量文本 */
|
|
14
|
-
text: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 工具调用内容片段。
|
|
19
|
-
*
|
|
20
|
-
* - 流中 pending 时携带 id / name / caller / args;
|
|
21
|
-
* - success / error 时补齐 result / status;
|
|
22
|
-
* - 带 render 的前端工具,运行时回调中还会带 render,落库时另存 ui 字段。
|
|
23
|
-
*/
|
|
24
|
-
export interface ToolCallContentPart {
|
|
25
|
-
type: "tool-call";
|
|
26
|
-
/** 单次工具调用唯一标识(落库片段可能缺省) */
|
|
27
|
-
id?: string;
|
|
28
|
-
name: string;
|
|
29
|
-
caller?: ToolCallSide;
|
|
30
|
-
args?: Record<string, unknown>;
|
|
31
|
-
status?: ToolCallStatus;
|
|
32
|
-
result?: unknown;
|
|
33
|
-
/** 仅在带 render 的前端工具、通知运行时做 UI 交互时存在 */
|
|
34
|
-
render?: ToolRender;
|
|
35
|
-
/** 带 render 的前端工具落库时,记录 UI 交互环节的状态与结果 */
|
|
36
|
-
ui?: {
|
|
37
|
-
status: ToolCallStatus;
|
|
38
|
-
result: unknown;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** 页面消费的全部内容片段;允许业务侧扩展自定义片段 */
|
|
43
|
-
export type ContentPart =
|
|
44
|
-
| TextContentPart
|
|
45
|
-
| ToolCallContentPart
|
|
46
|
-
| { type: string; [key: string]: unknown };
|
|
47
|
-
|
|
48
|
-
/** 一条页面消息(与发给模型的线上消息区分:content 是富片段数组) */
|
|
49
|
-
export interface ChatContentMessage {
|
|
50
|
-
role: string;
|
|
51
|
-
content: ContentPart[];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 历史消息组:一轮入站/出站消息的集合,
|
|
56
|
-
* MessageHistory.load 返回其数组,append 每次写入一组。
|
|
57
|
-
*/
|
|
58
|
-
export interface HistoryMessageGroup {
|
|
59
|
-
messages: ChatContentMessage[];
|
|
60
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 页面侧的消息 / 内容片段类型(UI 渲染与历史入库使用)
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolCallSide, ToolCallStatus } from "@auipage/types";
|
|
5
|
+
import type { ToolRender } from "./tool.js";
|
|
6
|
+
|
|
7
|
+
/** 文本类片段类型:正文 / 思维链 / 加载提示 */
|
|
8
|
+
export type TextContentType = "text" | "thinking" | "loading";
|
|
9
|
+
|
|
10
|
+
/** 文本类内容片段,同类型连续片段按增量拼接 */
|
|
11
|
+
export interface TextContentPart {
|
|
12
|
+
type: TextContentType;
|
|
13
|
+
/** 本次增量文本 */
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 工具调用内容片段。
|
|
19
|
+
*
|
|
20
|
+
* - 流中 pending 时携带 id / name / caller / args;
|
|
21
|
+
* - success / error 时补齐 result / status;
|
|
22
|
+
* - 带 render 的前端工具,运行时回调中还会带 render,落库时另存 ui 字段。
|
|
23
|
+
*/
|
|
24
|
+
export interface ToolCallContentPart {
|
|
25
|
+
type: "tool-call";
|
|
26
|
+
/** 单次工具调用唯一标识(落库片段可能缺省) */
|
|
27
|
+
id?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
caller?: ToolCallSide;
|
|
30
|
+
args?: Record<string, unknown>;
|
|
31
|
+
status?: ToolCallStatus;
|
|
32
|
+
result?: unknown;
|
|
33
|
+
/** 仅在带 render 的前端工具、通知运行时做 UI 交互时存在 */
|
|
34
|
+
render?: ToolRender;
|
|
35
|
+
/** 带 render 的前端工具落库时,记录 UI 交互环节的状态与结果 */
|
|
36
|
+
ui?: {
|
|
37
|
+
status: ToolCallStatus;
|
|
38
|
+
result: unknown;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 页面消费的全部内容片段;允许业务侧扩展自定义片段 */
|
|
43
|
+
export type ContentPart =
|
|
44
|
+
| TextContentPart
|
|
45
|
+
| ToolCallContentPart
|
|
46
|
+
| { type: string; [key: string]: unknown };
|
|
47
|
+
|
|
48
|
+
/** 一条页面消息(与发给模型的线上消息区分:content 是富片段数组) */
|
|
49
|
+
export interface ChatContentMessage {
|
|
50
|
+
role: string;
|
|
51
|
+
content: ContentPart[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 历史消息组:一轮入站/出站消息的集合,
|
|
56
|
+
* MessageHistory.load 返回其数组,append 每次写入一组。
|
|
57
|
+
*/
|
|
58
|
+
export interface HistoryMessageGroup {
|
|
59
|
+
messages: ChatContentMessage[];
|
|
60
|
+
/**
|
|
61
|
+
* 该轮的状态,0.2.0 起提供:
|
|
62
|
+
* complete(正常完成,通常省略)、cancelled(被 AuiPage.stop() 取消)。
|
|
63
|
+
* append 时据此决定入库、丢弃还是另做标记。
|
|
64
|
+
*/
|
|
65
|
+
status?: "complete" | "stopped" | "cancelled";
|
|
66
|
+
}
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChatContentRuntime:对话内容的渲染钩子
|
|
3
|
-
*/
|
|
4
|
-
import type {
|
|
5
|
-
ChatContentMessage,
|
|
6
|
-
ContentPart,
|
|
7
|
-
ToolCallContentPart
|
|
8
|
-
} from "../message.js";
|
|
9
|
-
import type { AuiPage } from "../auipage.js";
|
|
10
|
-
|
|
11
|
-
/** 初始化 / 重建整个对话区域 */
|
|
12
|
-
export type ChatInitHandler = (messages: ChatContentMessage[]) => void;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 文本分段的流式更新函数:
|
|
16
|
-
* append 创建文本节点时返回它,后续增量分片不再调用 append,而是调用它。
|
|
17
|
-
*/
|
|
18
|
-
export type TextStreamUpdater = (deltaText: string) => void;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 工具节点的“结束回调”:
|
|
22
|
-
* tool-call 的 pending 片段调用 append 时返回它并按 id 缓存,
|
|
23
|
-
* 在工具 success / error(或前端工具 render 交互)时被调用。
|
|
24
|
-
*
|
|
25
|
-
* 带 render 的前端工具会调用两次:
|
|
26
|
-
* 1. 入参携带 render,其返回值(可 Promise)作为 UI 交互结果;
|
|
27
|
-
* 2. 入参携带 UI 交互结果,用于最终渲染。
|
|
28
|
-
*/
|
|
29
|
-
export type ToolEndCallback = (data: ToolCallContentPart) => unknown;
|
|
30
|
-
|
|
31
|
-
/** append 的合法返回值:文本更新函数 / 工具结束回调 / 不返回 */
|
|
32
|
-
export type ChatAppendReturn =
|
|
33
|
-
| TextStreamUpdater
|
|
34
|
-
| ToolEndCallback
|
|
35
|
-
| void
|
|
36
|
-
| undefined;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 渲染一个消息片段:
|
|
40
|
-
* - 用户消息:每个片段调用一次,返回值被忽略;
|
|
41
|
-
* - 文本类流式片段:分段开始时调用,返回更新函数接收后续增量;
|
|
42
|
-
* - tool-call 的 pending:调用一次创建工具节点,返回结束回调。
|
|
43
|
-
*/
|
|
44
|
-
export type ChatAppendHandler = (
|
|
45
|
-
role: string,
|
|
46
|
-
part: ContentPart
|
|
47
|
-
) => ChatAppendReturn;
|
|
48
|
-
|
|
49
|
-
export interface ChatContentRuntimeOptions {
|
|
50
|
-
init?: ChatInitHandler;
|
|
51
|
-
append?: ChatAppendHandler;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export declare class ChatContentRuntime {
|
|
55
|
-
constructor(options?: ChatContentRuntimeOptions);
|
|
56
|
-
|
|
57
|
-
/** 实例名,AuiPage 按它去掉 Runtime 后缀后挂载;子类可覆盖 */
|
|
58
|
-
name: string;
|
|
59
|
-
|
|
60
|
-
init: ChatInitHandler;
|
|
61
|
-
append: ChatAppendHandler;
|
|
62
|
-
|
|
63
|
-
/** 被 AuiPage 挂载后写入的反向引用 */
|
|
64
|
-
aui?: AuiPage;
|
|
65
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* ChatContentRuntime:对话内容的渲染钩子
|
|
3
|
+
*/
|
|
4
|
+
import type {
|
|
5
|
+
ChatContentMessage,
|
|
6
|
+
ContentPart,
|
|
7
|
+
ToolCallContentPart
|
|
8
|
+
} from "../message.js";
|
|
9
|
+
import type { AuiPage } from "../auipage.js";
|
|
10
|
+
|
|
11
|
+
/** 初始化 / 重建整个对话区域 */
|
|
12
|
+
export type ChatInitHandler = (messages: ChatContentMessage[]) => void;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 文本分段的流式更新函数:
|
|
16
|
+
* append 创建文本节点时返回它,后续增量分片不再调用 append,而是调用它。
|
|
17
|
+
*/
|
|
18
|
+
export type TextStreamUpdater = (deltaText: string) => void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 工具节点的“结束回调”:
|
|
22
|
+
* tool-call 的 pending 片段调用 append 时返回它并按 id 缓存,
|
|
23
|
+
* 在工具 success / error(或前端工具 render 交互)时被调用。
|
|
24
|
+
*
|
|
25
|
+
* 带 render 的前端工具会调用两次:
|
|
26
|
+
* 1. 入参携带 render,其返回值(可 Promise)作为 UI 交互结果;
|
|
27
|
+
* 2. 入参携带 UI 交互结果,用于最终渲染。
|
|
28
|
+
*/
|
|
29
|
+
export type ToolEndCallback = (data: ToolCallContentPart) => unknown;
|
|
30
|
+
|
|
31
|
+
/** append 的合法返回值:文本更新函数 / 工具结束回调 / 不返回 */
|
|
32
|
+
export type ChatAppendReturn =
|
|
33
|
+
| TextStreamUpdater
|
|
34
|
+
| ToolEndCallback
|
|
35
|
+
| void
|
|
36
|
+
| undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 渲染一个消息片段:
|
|
40
|
+
* - 用户消息:每个片段调用一次,返回值被忽略;
|
|
41
|
+
* - 文本类流式片段:分段开始时调用,返回更新函数接收后续增量;
|
|
42
|
+
* - tool-call 的 pending:调用一次创建工具节点,返回结束回调。
|
|
43
|
+
*/
|
|
44
|
+
export type ChatAppendHandler = (
|
|
45
|
+
role: string,
|
|
46
|
+
part: ContentPart
|
|
47
|
+
) => ChatAppendReturn;
|
|
48
|
+
|
|
49
|
+
export interface ChatContentRuntimeOptions {
|
|
50
|
+
init?: ChatInitHandler;
|
|
51
|
+
append?: ChatAppendHandler;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare class ChatContentRuntime {
|
|
55
|
+
constructor(options?: ChatContentRuntimeOptions);
|
|
56
|
+
|
|
57
|
+
/** 实例名,AuiPage 按它去掉 Runtime 后缀后挂载;子类可覆盖 */
|
|
58
|
+
name: string;
|
|
59
|
+
|
|
60
|
+
init: ChatInitHandler;
|
|
61
|
+
append: ChatAppendHandler;
|
|
62
|
+
|
|
63
|
+
/** 被 AuiPage 挂载后写入的反向引用 */
|
|
64
|
+
aui?: AuiPage;
|
|
65
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 运行时(Runtime)类型入口:负责把数据画到 UI 上
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
ThreadListRuntime,
|
|
7
|
-
type ThreadListRuntimeOptions,
|
|
8
|
-
type ThreadInitHandler,
|
|
9
|
-
type ThreadActiveHandler,
|
|
10
|
-
type ThreadAppendHandler,
|
|
11
|
-
type ThreadIdUIHandler
|
|
12
|
-
} from "./thread-list.js";
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
ChatContentRuntime,
|
|
16
|
-
type ChatContentRuntimeOptions,
|
|
17
|
-
type ChatInitHandler,
|
|
18
|
-
type ChatAppendHandler,
|
|
19
|
-
type ChatAppendReturn,
|
|
20
|
-
type TextStreamUpdater,
|
|
21
|
-
type ToolEndCallback
|
|
22
|
-
} from "./chat-content.js";
|
|
1
|
+
/**
|
|
2
|
+
* 运行时(Runtime)类型入口:负责把数据画到 UI 上
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
ThreadListRuntime,
|
|
7
|
+
type ThreadListRuntimeOptions,
|
|
8
|
+
type ThreadInitHandler,
|
|
9
|
+
type ThreadActiveHandler,
|
|
10
|
+
type ThreadAppendHandler,
|
|
11
|
+
type ThreadIdUIHandler
|
|
12
|
+
} from "./thread-list.js";
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
ChatContentRuntime,
|
|
16
|
+
type ChatContentRuntimeOptions,
|
|
17
|
+
type ChatInitHandler,
|
|
18
|
+
type ChatAppendHandler,
|
|
19
|
+
type ChatAppendReturn,
|
|
20
|
+
type TextStreamUpdater,
|
|
21
|
+
type ToolEndCallback
|
|
22
|
+
} from "./chat-content.js";
|