@auipage/core 0.1.0-alpha.4 → 0.1.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.
@@ -1,18 +1,18 @@
1
- import { initOption } from "oipage/web/option/index.js";
2
- import { EmptyFunction } from "./tools/enum.js";
3
-
4
- const DEFAUTL_OPTIONS = {
5
- init: EmptyFunction,
6
- append: EmptyFunction,
7
- };
8
-
9
- function ChatContentRuntime(options) {
10
- this.name="ChatContentRuntime";
11
-
12
- let value = initOption(options, { ...DEFAUTL_OPTIONS });
13
- for (let key in DEFAUTL_OPTIONS) {
14
- this[key] = value[key];
15
- }
16
- }
17
-
18
- export default ChatContentRuntime;
1
+ import { initOption } from "oipage/web/option/index.js";
2
+ import { EmptyFunction } from "./tools/enum.js";
3
+
4
+ const DEFAUTL_OPTIONS = {
5
+ init: EmptyFunction,
6
+ append: EmptyFunction,
7
+ };
8
+
9
+ function ChatContentRuntime(options) {
10
+ this.name="ChatContentRuntime";
11
+
12
+ let value = initOption(options, { ...DEFAUTL_OPTIONS });
13
+ for (let key in DEFAUTL_OPTIONS) {
14
+ this[key] = value[key];
15
+ }
16
+ }
17
+
18
+ export default ChatContentRuntime;
@@ -1,18 +1,18 @@
1
- import { initOption } from "oipage/web/option/index.js";
2
- import { EmptyFunction } from "./tools/enum.js";
3
-
4
- const DEFAUTL_OPTIONS = {
5
- run: EmptyFunction,
6
- response: EmptyFunction,
7
- };
8
-
9
- function ChatTransportAdapter(options) {
10
- this.name="ChatTransportAdapter";
11
-
12
- let value = initOption(options, { ...DEFAUTL_OPTIONS });
13
- for (let key in DEFAUTL_OPTIONS) {
14
- this[key] = value[key];
15
- }
16
- }
17
-
1
+ import { initOption } from "oipage/web/option/index.js";
2
+ import { EmptyFunction } from "./tools/enum.js";
3
+
4
+ const DEFAUTL_OPTIONS = {
5
+ run: EmptyFunction,
6
+ response: EmptyFunction,
7
+ };
8
+
9
+ function ChatTransportAdapter(options) {
10
+ this.name="ChatTransportAdapter";
11
+
12
+ let value = initOption(options, { ...DEFAUTL_OPTIONS });
13
+ for (let key in DEFAUTL_OPTIONS) {
14
+ this[key] = value[key];
15
+ }
16
+ }
17
+
18
18
  export default ChatTransportAdapter;
@@ -1,18 +1,18 @@
1
- import { initOption } from "oipage/web/option/index.js";
2
- import { EmptyFunction } from "./tools/enum.js";
3
-
4
- const DEFAUTL_OPTIONS = {
5
- load: EmptyFunction,
6
- append: EmptyFunction
7
- };
8
-
9
- function MessageHistoryAdapter(options) {
10
- this.name="MessageHistoryAdapter";
11
-
12
- let value = initOption(options, { ...DEFAUTL_OPTIONS });
13
- for (let key in DEFAUTL_OPTIONS) {
14
- this[key] = value[key];
15
- }
16
- }
17
-
1
+ import { initOption } from "oipage/web/option/index.js";
2
+ import { EmptyFunction } from "./tools/enum.js";
3
+
4
+ const DEFAUTL_OPTIONS = {
5
+ load: EmptyFunction,
6
+ append: EmptyFunction
7
+ };
8
+
9
+ function MessageHistoryAdapter(options) {
10
+ this.name="MessageHistoryAdapter";
11
+
12
+ let value = initOption(options, { ...DEFAUTL_OPTIONS });
13
+ for (let key in DEFAUTL_OPTIONS) {
14
+ this[key] = value[key];
15
+ }
16
+ }
17
+
18
18
  export default MessageHistoryAdapter;
@@ -1,8 +1,8 @@
1
- import { EmptyFunction } from "./tools/enum.js";
2
-
3
- function MessageStream(send, end) {
4
- this.send = send || EmptyFunction;
5
- this.end = end || EmptyFunction;
6
- }
7
-
1
+ import { EmptyFunction } from "./tools/enum.js";
2
+
3
+ function MessageStream(send, end) {
4
+ this.send = send || EmptyFunction;
5
+ this.end = end || EmptyFunction;
6
+ }
7
+
8
8
  export default MessageStream;
@@ -1,21 +1,21 @@
1
- import { initOption } from "oipage/web/option/index.js";
2
- import { EmptyFunction } from "./tools/enum.js";
3
-
4
- const DEFAUTL_OPTIONS = {
5
- list: EmptyFunction,
6
- new: EmptyFunction,
7
- archive: EmptyFunction,
8
- unarchive: EmptyFunction,
9
- delete: EmptyFunction
10
- };
11
-
12
- function ThreadListAdapter(options) {
13
- this.name="ThreadListAdapter";
14
-
15
- let value = initOption(options, { ...DEFAUTL_OPTIONS });
16
- for (let key in DEFAUTL_OPTIONS) {
17
- this[key] = value[key];
18
- }
19
- }
20
-
1
+ import { initOption } from "oipage/web/option/index.js";
2
+ import { EmptyFunction } from "./tools/enum.js";
3
+
4
+ const DEFAUTL_OPTIONS = {
5
+ list: EmptyFunction,
6
+ new: EmptyFunction,
7
+ archive: EmptyFunction,
8
+ unarchive: EmptyFunction,
9
+ delete: EmptyFunction
10
+ };
11
+
12
+ function ThreadListAdapter(options) {
13
+ this.name="ThreadListAdapter";
14
+
15
+ let value = initOption(options, { ...DEFAUTL_OPTIONS });
16
+ for (let key in DEFAUTL_OPTIONS) {
17
+ this[key] = value[key];
18
+ }
19
+ }
20
+
21
21
  export default ThreadListAdapter;
@@ -1,22 +1,22 @@
1
- import { initOption } from "oipage/web/option/index.js";
2
- import { EmptyFunction } from "./tools/enum.js";
3
-
4
- const DEFAUTL_OPTIONS = {
5
- init: EmptyFunction,
6
- active: EmptyFunction,
7
- delete: EmptyFunction,
8
- archive: EmptyFunction,
9
- unarchive: EmptyFunction,
10
- append: EmptyFunction,
11
- };
12
-
13
- function ThreadListRuntime(options) {
14
- this.name="ThreadListRuntime";
15
-
16
- let value = initOption(options, { ...DEFAUTL_OPTIONS });
17
- for (let key in DEFAUTL_OPTIONS) {
18
- this[key] = value[key];
19
- }
20
- }
21
-
22
- export default ThreadListRuntime;
1
+ import { initOption } from "oipage/web/option/index.js";
2
+ import { EmptyFunction } from "./tools/enum.js";
3
+
4
+ const DEFAUTL_OPTIONS = {
5
+ init: EmptyFunction,
6
+ active: EmptyFunction,
7
+ delete: EmptyFunction,
8
+ archive: EmptyFunction,
9
+ unarchive: EmptyFunction,
10
+ append: EmptyFunction,
11
+ };
12
+
13
+ function ThreadListRuntime(options) {
14
+ this.name="ThreadListRuntime";
15
+
16
+ let value = initOption(options, { ...DEFAUTL_OPTIONS });
17
+ for (let key in DEFAUTL_OPTIONS) {
18
+ this[key] = value[key];
19
+ }
20
+ }
21
+
22
+ export default ThreadListRuntime;
package/src/defineTool.js CHANGED
@@ -1,14 +1,14 @@
1
- export default function (options) {
2
- return {
3
- description: {
4
- type: "function",
5
- function: {
6
- name: options.name,
7
- description: options.description,
8
- parameters: options.parameters
9
- }
10
- },
11
- execute: options.execute,
12
- render: options.render
13
- };
1
+ export default function (options) {
2
+ return {
3
+ description: {
4
+ type: "function",
5
+ function: {
6
+ name: options.name,
7
+ description: options.description,
8
+ parameters: options.parameters
9
+ }
10
+ },
11
+ execute: options.execute,
12
+ render: options.render
13
+ };
14
14
  };
package/src/generator.js CHANGED
@@ -1,64 +1,64 @@
1
- export default async function* (rawFun) {
2
-
3
- // 已产出但尚未被消费的值缓冲
4
- const queue = [];
5
- // 当前等待消费者请求的 Promise 控制器;同时最多一个
6
- let pending = null;
7
- // 生产者是否已结束
8
- let ended = false;
9
- // 生产者是否已报错;一旦设置,后续 next/done 调用被忽略
10
- let errored = null;
11
-
12
- // 启动生产者,三个回调驱动数据流
13
- rawFun(
14
- // next:推送下一个值
15
- (value) => {
16
- if (errored) return;
17
- if (pending) {
18
- // 有等待中的消费者,立刻交值
19
- pending.resolve({ value, done: false });
20
- pending = null;
21
- } else {
22
- // 否则入队缓存
23
- queue.push(value);
24
- }
25
- },
26
- // done:结束
27
- () => {
28
- if (errored) return;
29
- ended = true;
30
- if (pending) {
31
- pending.resolve({ value: void 0, done: true });
32
- pending = null;
33
- }
34
- },
35
- // error:异常
36
- (err) => {
37
- errored = err;
38
- if (pending) {
39
- pending.reject(err);
40
- pending = null;
41
- }
42
- }
43
- );
44
-
45
- // 消费者主循环
46
- while (true) {
47
- if (errored) throw errored;
48
- // 优先消费缓冲
49
- if (queue.length) {
50
- yield queue.shift();
51
- continue;
52
- }
53
- // 缓冲空且生产者已结束 → 终止迭代
54
- if (ended) return;
55
- // 缓冲空且未结束 → 挂起等待生产者回调唤醒
56
- const result = await new Promise((resolve, reject) => {
57
- pending = { resolve, reject };
58
- });
59
- // 被唤醒后再判一次 error,防止回调已设 errored 但未分发
60
- if (errored) throw errored;
61
- if (result.done) return;
62
- yield result.value;
63
- }
64
- }
1
+ export default async function* (rawFun) {
2
+
3
+ // 已产出但尚未被消费的值缓冲
4
+ const queue = [];
5
+ // 当前等待消费者请求的 Promise 控制器;同时最多一个
6
+ let pending = null;
7
+ // 生产者是否已结束
8
+ let ended = false;
9
+ // 生产者是否已报错;一旦设置,后续 next/done 调用被忽略
10
+ let errored = null;
11
+
12
+ // 启动生产者,三个回调驱动数据流
13
+ rawFun(
14
+ // next:推送下一个值
15
+ (value) => {
16
+ if (errored) return;
17
+ if (pending) {
18
+ // 有等待中的消费者,立刻交值
19
+ pending.resolve({ value, done: false });
20
+ pending = null;
21
+ } else {
22
+ // 否则入队缓存
23
+ queue.push(value);
24
+ }
25
+ },
26
+ // done:结束
27
+ () => {
28
+ if (errored) return;
29
+ ended = true;
30
+ if (pending) {
31
+ pending.resolve({ value: void 0, done: true });
32
+ pending = null;
33
+ }
34
+ },
35
+ // error:异常
36
+ (err) => {
37
+ errored = err;
38
+ if (pending) {
39
+ pending.reject(err);
40
+ pending = null;
41
+ }
42
+ }
43
+ );
44
+
45
+ // 消费者主循环
46
+ while (true) {
47
+ if (errored) throw errored;
48
+ // 优先消费缓冲
49
+ if (queue.length) {
50
+ yield queue.shift();
51
+ continue;
52
+ }
53
+ // 缓冲空且生产者已结束 → 终止迭代
54
+ if (ended) return;
55
+ // 缓冲空且未结束 → 挂起等待生产者回调唤醒
56
+ const result = await new Promise((resolve, reject) => {
57
+ pending = { resolve, reject };
58
+ });
59
+ // 被唤醒后再判一次 error,防止回调已设 errored 但未分发
60
+ if (errored) throw errored;
61
+ if (result.done) return;
62
+ yield result.value;
63
+ }
64
+ }
package/src/index.js CHANGED
@@ -1,12 +1,12 @@
1
- export { default as AuiPage } from "./AuiPage.js";
2
-
3
- export { default as ChatTransportAdapter } from "./ChatTransportAdapter.js";
4
- export { default as MessageHistoryAdapter } from "./MessageHistoryAdapter.js";
5
- export { default as ThreadListAdapter } from "./ThreadListAdapter.js";
6
-
7
- export { default as ThreadListRuntime } from "./ThreadListRuntime.js";
8
- export { default as ChatContentRuntime } from "./ChatContentRuntime.js";
9
-
10
- export { default as defineTool } from "./defineTool.js";
11
- export { default as generator } from "./generator.js";
1
+ export { default as AuiPage } from "./AuiPage.js";
2
+
3
+ export { default as ChatTransportAdapter } from "./ChatTransportAdapter.js";
4
+ export { default as MessageHistoryAdapter } from "./MessageHistoryAdapter.js";
5
+ export { default as ThreadListAdapter } from "./ThreadListAdapter.js";
6
+
7
+ export { default as ThreadListRuntime } from "./ThreadListRuntime.js";
8
+ export { default as ChatContentRuntime } from "./ChatContentRuntime.js";
9
+
10
+ export { default as defineTool } from "./defineTool.js";
11
+ export { default as generator } from "./generator.js";
12
12
  export { default as MessageStream } from "./MessageStream.js";
@@ -1,16 +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;
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
16
  }
@@ -1,57 +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
- }
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
+ }
@@ -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
+ }