@auipage/core 0.1.0-alpha.0 → 0.1.0-alpha.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.
@@ -0,0 +1,16 @@
1
+ export default function (value) {
2
+
3
+ let messages = [], index = -1;
4
+ for (let message of value.messages) {
5
+
6
+ if (index != -1 && messages[index].role === message.role) {
7
+ messages[index].content.push(...message.content);
8
+ } else {
9
+ messages.push(message);
10
+ index = messages.length - 1;
11
+ }
12
+ }
13
+
14
+ value.messages = messages;
15
+ return value;
16
+ }
@@ -0,0 +1,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
+ }
23
+
24
+ /**
25
+ * 发起一轮对话并返回异步生成器,逐个 yield 消息片段;
26
+ * 返回假值时 AuiPage 会直接终止本轮处理。
27
+ */
28
+ export type ChatTransportRun = (
29
+ params: ChatTransportRunParams
30
+ ) => AsyncGenerator<ContentPart, void, void> | void | null | undefined;
31
+
32
+ /**
33
+ * 页面 → 服务端的反向回传通道。
34
+ * 目前仅用于前端工具结果回传:response("tool-result", { id, status, result })。
35
+ */
36
+ export type ChatTransportResponse = (
37
+ name: string,
38
+ data: Record<string, unknown>
39
+ ) => unknown;
40
+
41
+ export interface ChatTransportAdapterOptions {
42
+ run?: ChatTransportRun;
43
+ response?: ChatTransportResponse;
44
+ }
45
+
46
+ export declare class ChatTransportAdapter {
47
+ constructor(options?: ChatTransportAdapterOptions);
48
+
49
+ /** 实例名,AuiPage 按它去掉 Adapter 后缀后挂载;子类可覆盖 */
50
+ name: string;
51
+
52
+ run: ChatTransportRun;
53
+ response: ChatTransportResponse;
54
+
55
+ /** 被 AuiPage 挂载后写入的反向引用 */
56
+ aui?: AuiPage;
57
+ }
@@ -0,0 +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";
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * AuiPage:框架核心,串联 Adapter(业务侧)与 Runtime(UI 侧),
3
+ * 维护会话、消息历史、流式对话与工具调用状态。
4
+ */
5
+ import type { ToolDescription, ToolExecutor } from "@auipage/types";
6
+ import type {
7
+ ChatContentMessage,
8
+ HistoryMessageGroup
9
+ } from "./message.js";
10
+ import type { Tool, ToolRender } from "./tool.js";
11
+ import type { ChatTransportAdapter } from "./adapters/chat-transport.js";
12
+ import type { MessageHistoryAdapter } from "./adapters/message-history.js";
13
+ import type { ThreadListAdapter } from "./adapters/thread-list.js";
14
+ import type { ThreadListRuntime } from "./runtimes/thread-list.js";
15
+ import type { ChatContentRuntime } from "./runtimes/chat-content.js";
16
+
17
+ /** 三个适配器的挂载集合(key 与实例 name 去掉 Adapter 后缀一致) */
18
+ export interface AuiPageAdapterSet {
19
+ ChatTransport: ChatTransportAdapter;
20
+ MessageHistory: MessageHistoryAdapter;
21
+ ThreadList: ThreadListAdapter;
22
+ }
23
+
24
+ /** 两个运行时的挂载集合(key 与实例 name 去掉 Runtime 后缀一致) */
25
+ export interface AuiPageRuntimeSet {
26
+ ThreadList: ThreadListRuntime;
27
+ ChatContent: ChatContentRuntime;
28
+ }
29
+
30
+ export interface AuiPageOptions {
31
+ adapter: AuiPageAdapterSet;
32
+ runtime: AuiPageRuntimeSet;
33
+ /** 页面侧工具列表;可选,不使用工具时省略 */
34
+ tools?: Tool[];
35
+ }
36
+
37
+ /** 任务生命周期事件名 */
38
+ export type AuiLifecycleEvent = "task:start" | "task:end";
39
+
40
+ /** 任务结束状态 */
41
+ export type AuiTaskStatus = "complete" | "error";
42
+
43
+ /** task:start 回调载荷 */
44
+ export interface TaskLifecyclePayload {
45
+ /** 本次 sendMessage 自增生成的唯一任务 id */
46
+ taskId: string;
47
+ /** 任务发起时所处的会话 ID;新建会话场景下为 undefined */
48
+ threadId: string | undefined;
49
+ /** 本次发送的原始页面消息 */
50
+ message: ChatContentMessage;
51
+ }
52
+
53
+ /** task:end 回调载荷;在 TaskLifecyclePayload 基础上附带 status */
54
+ export interface TaskEndPayload extends TaskLifecyclePayload {
55
+ status: AuiTaskStatus;
56
+ }
57
+
58
+ /** 生命周期事件 handler 签名 */
59
+ export type TaskStartHandler = (payload: TaskLifecyclePayload) => void;
60
+ export type TaskEndHandler = (payload: TaskEndPayload) => void;
61
+
62
+ export declare class AuiPage {
63
+ constructor(options: AuiPageOptions);
64
+
65
+ /** 按 name 映射后的适配器集合 */
66
+ adapter: AuiPageAdapterSet;
67
+ /** 按 name 映射后的运行时集合 */
68
+ runtime: AuiPageRuntimeSet;
69
+
70
+ /** 工具名 → 页面执行函数 */
71
+ tools_execute: Record<string, ToolExecutor>;
72
+ /** 工具名 → UI 交互函数(可能为 undefined) */
73
+ tools_render: Record<string, ToolRender | undefined>;
74
+ /** 透传给 ChatTransport.run 的 context.tools */
75
+ tools_description: Array<{ description: ToolDescription }>;
76
+
77
+ /** 当前是否处于对话执行中;执行中拒绝重复发送、忽略会话切换 */
78
+ isExecuting: boolean;
79
+ /** 当前激活的会话 ID;undefined 表示“新建会话”状态 */
80
+ currentThreadId: string | undefined;
81
+ /** 当前会话已加载的历史消息组 */
82
+ currentMessages: HistoryMessageGroup[];
83
+
84
+ /**
85
+ * 发送一条消息并驱动完整的流式对话流程;
86
+ * 上一轮执行中时以 "当前正在执行中" reject,全部完成(含落库)后 resolve;
87
+ * 流式过程出错时以原始 error reject(同时触发 task:end { status: "error" })。
88
+ */
89
+ sendMessage(message: ChatContentMessage): Promise<void>;
90
+
91
+ /**
92
+ * 订阅任务生命周期事件。同名事件可注册多个 handler,触发时按注册顺序串行调用,
93
+ * handler 内部抛错被吞掉,不会影响 sendMessage 主流程。链式返回 AuiPage。
94
+ */
95
+ on(event: "task:start", handler: TaskStartHandler): this;
96
+ on(event: "task:end", handler: TaskEndHandler): this;
97
+
98
+ /** 取消事件订阅;handler 未注册过则 no-op。链式返回 AuiPage */
99
+ off(event: AuiLifecycleEvent, handler: Function): this;
100
+
101
+ /**
102
+ * 切换到指定会话;threadId 为 undefined 表示进入新建会话状态。
103
+ * 对话执行中调用会被忽略(noLoad 内部调用除外)。
104
+ * @param noLoad 内部参数:true 时跳过历史重载(新建会话后使用)
105
+ */
106
+ activeThread(threadId: string | undefined, noLoad?: boolean): void;
107
+
108
+ /** 删除会话;删除的是当前会话时自动进入新建会话状态 */
109
+ deleteThread(threadId: string): void;
110
+ /** 归档会话;归档的是当前会话时自动进入新建会话状态 */
111
+ archiveThread(threadId: string): void;
112
+ /** 取消归档(不自动切换会话) */
113
+ unarchiveThread(threadId: string): void;
114
+ /** 进入新建会话状态,等价于 activeThread(undefined) */
115
+ newThread(): void;
116
+ }
@@ -0,0 +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;
@@ -0,0 +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;
package/types/index.d.ts CHANGED
@@ -0,0 +1,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 TaskLifecyclePayload,
18
+ type TaskEndPayload,
19
+ type TaskStartHandler,
20
+ type TaskEndHandler
21
+ } from "./auipage.js";
22
+
23
+ /* ---------- 适配器 ---------- */
24
+ export {
25
+ ChatTransportAdapter,
26
+ type ChatTransportAdapterOptions,
27
+ type ChatTransportRun,
28
+ type ChatTransportRunParams,
29
+ type ChatTransportResponse
30
+ } from "./adapters/chat-transport.js";
31
+ export {
32
+ MessageHistoryAdapter,
33
+ type MessageHistoryAdapterOptions,
34
+ type MessageHistoryLoad,
35
+ type MessageHistoryAppend
36
+ } from "./adapters/message-history.js";
37
+ export {
38
+ ThreadListAdapter,
39
+ type ThreadListAdapterOptions,
40
+ type ThreadListList,
41
+ type ThreadListNew,
42
+ type ThreadIdHandler
43
+ } from "./adapters/thread-list.js";
44
+
45
+ /* ---------- 运行时 ---------- */
46
+ export {
47
+ ThreadListRuntime,
48
+ type ThreadListRuntimeOptions,
49
+ type ThreadInitHandler,
50
+ type ThreadActiveHandler,
51
+ type ThreadAppendHandler,
52
+ type ThreadIdUIHandler
53
+ } from "./runtimes/thread-list.js";
54
+ export {
55
+ ChatContentRuntime,
56
+ type ChatContentRuntimeOptions,
57
+ type ChatInitHandler,
58
+ type ChatAppendHandler,
59
+ type ChatAppendReturn,
60
+ type TextStreamUpdater,
61
+ type ToolEndCallback
62
+ } from "./runtimes/chat-content.js";
63
+
64
+ /* ---------- 工具 ---------- */
65
+ export type {
66
+ Tool,
67
+ ToolRender,
68
+ ToolRenderData,
69
+ DefineToolOptions
70
+ } from "./tool.js";
71
+ export { default as defineTool } from "./define-tool.js";
72
+
73
+ /* ---------- 消息与会话 ---------- */
74
+ export type {
75
+ TextContentType,
76
+ TextContentPart,
77
+ ToolCallContentPart,
78
+ ContentPart,
79
+ ChatContentMessage,
80
+ HistoryMessageGroup
81
+ } from "./message.js";
82
+ export type { Thread } from "./thread.js";
83
+
84
+ /* ---------- 流工具 ---------- */
85
+ export {
86
+ default as generator,
87
+ type StreamProducer,
88
+ type StreamNext,
89
+ type StreamDone,
90
+ type StreamError
91
+ } from "./generator.js";
92
+ export {
93
+ MessageStream,
94
+ type MessageSendHandler,
95
+ type MessageEndHandler
96
+ } from "./message-stream.js";
@@ -0,0 +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
+ }
@@ -0,0 +1,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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +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";
@@ -0,0 +1,40 @@
1
+ /**
2
+ * ThreadListRuntime:会话列表(侧边栏)的渲染钩子
3
+ */
4
+ import type { Thread } from "../thread.js";
5
+ import type { AuiPage } from "../auipage.js";
6
+
7
+ /** 首次渲染整个会话列表 */
8
+ export type ThreadInitHandler = (threads: Thread[]) => void;
9
+ /** 切换激活会话;threadId 为 undefined 表示“新建会话”状态 */
10
+ export type ThreadActiveHandler = (threadId: string | undefined) => void;
11
+ /** 追加一个新会话节点 */
12
+ export type ThreadAppendHandler = (thread: Thread) => void;
13
+ /** 以会话 ID 为入参的渲染操作:删除 / 归档 / 取消归档 */
14
+ export type ThreadIdUIHandler = (threadId: string) => void;
15
+
16
+ export interface ThreadListRuntimeOptions {
17
+ init?: ThreadInitHandler;
18
+ active?: ThreadActiveHandler;
19
+ append?: ThreadAppendHandler;
20
+ delete?: ThreadIdUIHandler;
21
+ archive?: ThreadIdUIHandler;
22
+ unarchive?: ThreadIdUIHandler;
23
+ }
24
+
25
+ export declare class ThreadListRuntime {
26
+ constructor(options?: ThreadListRuntimeOptions);
27
+
28
+ /** 实例名,AuiPage 按它去掉 Runtime 后缀后挂载;子类可覆盖 */
29
+ name: string;
30
+
31
+ init: ThreadInitHandler;
32
+ active: ThreadActiveHandler;
33
+ append: ThreadAppendHandler;
34
+ delete: ThreadIdUIHandler;
35
+ archive: ThreadIdUIHandler;
36
+ unarchive: ThreadIdUIHandler;
37
+
38
+ /** 被 AuiPage 挂载后写入的反向引用 */
39
+ aui?: AuiPage;
40
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 会话(Thread)对象约定
3
+ */
4
+
5
+ export interface Thread {
6
+ /** 会话唯一 ID,AuiPage 内部依赖此字段 */
7
+ threadId: string;
8
+ /** 会话标题,通常取首轮用户消息的前缀 */
9
+ title?: string;
10
+ /** 是否归档 */
11
+ archived?: boolean;
12
+ /** 其它业务自定义字段 */
13
+ [key: string]: unknown;
14
+ }