@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,40 +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
|
-
}
|
|
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
|
+
}
|
package/types/thread.d.ts
CHANGED
|
@@ -1,14 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* toModelMessages:把页面侧历史消息(富片段)转换为模型线上消息
|
|
3
|
+
*/
|
|
4
|
+
import type { ChatMessage } from "@auipage/types";
|
|
5
|
+
import type { ChatContentMessage, HistoryMessageGroup } from "./message.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param input 历史消息组数组或消息数组
|
|
9
|
+
* @returns 可直接作为 completions.messages 的数组
|
|
10
|
+
*/
|
|
11
|
+
declare function toModelMessages(
|
|
12
|
+
input: Array<HistoryMessageGroup | ChatContentMessage>
|
|
13
|
+
): ChatMessage[];
|
|
14
|
+
|
|
15
|
+
export default toModelMessages;
|
package/types/tool.d.ts
CHANGED
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 页面侧(前端)工具定义
|
|
3
|
-
*/
|
|
4
|
-
import type {
|
|
5
|
-
MaybePromise,
|
|
6
|
-
ToolCallStatus,
|
|
7
|
-
ToolDescription,
|
|
8
|
-
ToolExecutor
|
|
9
|
-
} from "@auipage/types";
|
|
10
|
-
|
|
11
|
-
/** render 收到的数据:入参、execute 的执行结果与状态,以及工具事件上的其它字段 */
|
|
12
|
-
export interface ToolRenderData {
|
|
13
|
-
/** 模型解析出的入参 */
|
|
14
|
-
args: Record<string, unknown>;
|
|
15
|
-
/** execute 的执行结果(异常时为错误对象) */
|
|
16
|
-
result: unknown;
|
|
17
|
-
/** execute 的执行状态 */
|
|
18
|
-
status: ToolCallStatus;
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 页面侧(前端)工具定义
|
|
3
|
+
*/
|
|
4
|
+
import type {
|
|
5
|
+
MaybePromise,
|
|
6
|
+
ToolCallStatus,
|
|
7
|
+
ToolDescription,
|
|
8
|
+
ToolExecutor
|
|
9
|
+
} from "@auipage/types";
|
|
10
|
+
|
|
11
|
+
/** render 收到的数据:入参、execute 的执行结果与状态,以及工具事件上的其它字段 */
|
|
12
|
+
export interface ToolRenderData {
|
|
13
|
+
/** 模型解析出的入参 */
|
|
14
|
+
args: Record<string, unknown>;
|
|
15
|
+
/** execute 的执行结果(异常时为错误对象) */
|
|
16
|
+
result: unknown;
|
|
17
|
+
/** execute 的执行状态 */
|
|
18
|
+
status: ToolCallStatus;
|
|
19
|
+
/** 当前任务 id(0.2.0 起提供) */
|
|
20
|
+
taskId?: string;
|
|
21
|
+
/** 主动结束这一轮:内容保留、标记 stopped、sendMessage resolve(0.2.0 起提供) */
|
|
22
|
+
stop?: () => boolean;
|
|
23
|
+
/** 取消这一轮:丢弃界面、标记 cancelled、sendMessage 以 "已取消" reject(0.2.0 起提供) */
|
|
24
|
+
cancel?: () => boolean;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* UI 交互函数:execute 完成后调用,可在页面上完成弹窗、表单补充等交互;
|
|
30
|
+
* 其返回值(可 Promise)才是最终回传给模型的结果。
|
|
31
|
+
*/
|
|
32
|
+
export type ToolRender = (data: ToolRenderData) => MaybePromise<unknown>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 注册到 AuiPage 的工具。
|
|
36
|
+
* execute / render 均可缺省,但缺省 execute 的工具只有在
|
|
37
|
+
* @auipage/agent 的 CreateTool 前后端桥接场景下才能正常工作。
|
|
38
|
+
*/
|
|
39
|
+
export interface Tool {
|
|
40
|
+
description: ToolDescription;
|
|
41
|
+
execute?: ToolExecutor;
|
|
42
|
+
render?: ToolRender;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** defineTool 的平铺入参 */
|
|
46
|
+
export interface DefineToolOptions {
|
|
47
|
+
/** 工具名,对应 description.function.name */
|
|
48
|
+
name: string;
|
|
49
|
+
/** 给模型看的功能描述 */
|
|
50
|
+
description: string;
|
|
51
|
+
/** 入参 JSON Schema */
|
|
52
|
+
parameters: Record<string, unknown>;
|
|
53
|
+
/** 页面侧执行函数 */
|
|
54
|
+
execute?: ToolExecutor;
|
|
55
|
+
/** UI 交互函数 */
|
|
56
|
+
render?: ToolRender;
|
|
57
|
+
}
|