@auipage/core 0.1.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/.mailmap +1 -0
- package/AUTHORS.txt +6 -0
- package/CHANGELOG +4 -0
- package/README.md +30 -0
- package/package.json +31 -0
- package/src/AuiPage.js +75 -0
- package/src/ChatContentRuntime.js +14 -0
- package/src/ChatTransportAdapter.js +14 -0
- package/src/MessageHistoryAdapter.js +15 -0
- package/src/ThreadListAdapter.js +19 -0
- package/src/ThreadListRuntime.js +19 -0
- package/src/defineTool.js +5 -0
- package/src/generator.js +64 -0
- package/src/index.js +11 -0
- package/types/index.d.ts +0 -0
package/.mailmap
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
zxl20070701 <1904314465@qq.com>
|
package/AUTHORS.txt
ADDED
package/CHANGELOG
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# [@auipage/core](https://github.com/handless-ui/auipage/packages/core/README.md)
|
|
2
|
+
智能体快速开发框架,用于快速开发智能体网页应用。
|
|
3
|
+
|
|
4
|
+
<p>
|
|
5
|
+
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@auipage/core&interval=7">
|
|
6
|
+
<img src="https://img.shields.io/npm/dm/@auipage/core.svg" alt="downloads">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@auipage/core">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@auipage/core.svg" alt="npm">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/handless-ui/auipage" target='_blank'>
|
|
12
|
+
<img alt="GitHub repo stars" src="https://img.shields.io/github/stars/handless-ui/auipage?style=social">
|
|
13
|
+
</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<img src="https://nodei.co/npm/@auipage/core.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
17
|
+
|
|
18
|
+
## 如何使用?
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install --save @auipage/core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
安装后,即可在项目中使用。
|
|
25
|
+
|
|
26
|
+
## 版权
|
|
27
|
+
|
|
28
|
+
MIT License
|
|
29
|
+
|
|
30
|
+
Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@auipage/core",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "@auipage/core",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"typings": "types/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prepublishOnly": "node ../../swap-pkg.js --mode=publish",
|
|
11
|
+
"postpublish": "node ../../swap-pkg.js --mode=restore"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/handless-ui/auipage.git",
|
|
16
|
+
"directory": "packages/core"
|
|
17
|
+
},
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "zxl20070701",
|
|
20
|
+
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/handless-ui/auipage/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/handless-ui/auipage#readme",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@auipage/types": "^0.1.0-alpha.0",
|
|
29
|
+
"oipage": "^2.1.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/AuiPage.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
function AuiPage(options) {
|
|
2
|
+
|
|
3
|
+
for (let instance of Object.values(options.adapter)) {
|
|
4
|
+
instance.aui = this;
|
|
5
|
+
this.adapter[instance.constructor.name.replace("Adapter", "")] = instance;
|
|
6
|
+
}
|
|
7
|
+
for (let instance of Object.values(options.runtime)) {
|
|
8
|
+
instance.aui = this;
|
|
9
|
+
this.runtime[instance.constructor.name.replace("Runtime", "")] = instance;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 当前激活的会话ID
|
|
13
|
+
this.currentThreadId = void 0;
|
|
14
|
+
|
|
15
|
+
// 当前会话内容
|
|
16
|
+
this.currentMessages = [];
|
|
17
|
+
|
|
18
|
+
// 请求对话列表
|
|
19
|
+
this.adapter.ThreadList.list().then((threads) => {
|
|
20
|
+
|
|
21
|
+
// 在页面中显示对话列表
|
|
22
|
+
this.runtime.ThreadList.init(threads);
|
|
23
|
+
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
AuiPage.prototype.adapter = {};
|
|
29
|
+
AuiPage.prototype.runtime = {};
|
|
30
|
+
|
|
31
|
+
AuiPage.prototype.sendMessage = function (message) {
|
|
32
|
+
this.currentMessages.push(message);
|
|
33
|
+
|
|
34
|
+
let generator = this.adapter.ChatTransport.run({
|
|
35
|
+
messages: this.currentMessages,
|
|
36
|
+
context: {
|
|
37
|
+
tools: []
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
(function doit() {
|
|
42
|
+
generator.next().then(res => {
|
|
43
|
+
if (!res.done) {
|
|
44
|
+
|
|
45
|
+
console.log(res.value);
|
|
46
|
+
|
|
47
|
+
doit();
|
|
48
|
+
}
|
|
49
|
+
}, err => {
|
|
50
|
+
console.error(err);
|
|
51
|
+
});
|
|
52
|
+
})();
|
|
53
|
+
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
AuiPage.prototype.activeThread = function (threadId) {
|
|
57
|
+
if (this.currentThreadId === threadId) return;
|
|
58
|
+
|
|
59
|
+
this.currentThreadId = threadId;
|
|
60
|
+
this.runtime.ThreadList.active(threadId);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
AuiPage.prototype.deleteThread = function (threadId) {
|
|
64
|
+
this.runtime.ThreadList.delete(threadId);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
AuiPage.prototype.archiveThread = function (threadId) {
|
|
68
|
+
this.runtime.ThreadList.archive(threadId);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
AuiPage.prototype.newThread = function () {
|
|
72
|
+
this.activeThread(void 0);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default AuiPage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { initOption } from "oipage/web/option/index.js";
|
|
2
|
+
|
|
3
|
+
const DEFAUTL_OPTIONS = {
|
|
4
|
+
init: void 0,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
function ChatContentRuntime(options) {
|
|
8
|
+
let value = initOption(options, { ...DEFAUTL_OPTIONS });
|
|
9
|
+
for (let key in DEFAUTL_OPTIONS) {
|
|
10
|
+
this[key] = value[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default ChatContentRuntime;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { initOption } from "oipage/web/option/index.js";
|
|
2
|
+
|
|
3
|
+
const DEFAUTL_OPTIONS = {
|
|
4
|
+
run: void 0
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
function ChatTransportAdapter(options) {
|
|
8
|
+
let value = initOption(options, { ...DEFAUTL_OPTIONS });
|
|
9
|
+
for (let key in DEFAUTL_OPTIONS) {
|
|
10
|
+
this[key] = value[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default ChatTransportAdapter;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { initOption } from "oipage/web/option/index.js";
|
|
2
|
+
|
|
3
|
+
const DEFAUTL_OPTIONS = {
|
|
4
|
+
load: void 0,
|
|
5
|
+
append: void 0
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
function MessageHistoryAdapter(options) {
|
|
9
|
+
let value = initOption(options, { ...DEFAUTL_OPTIONS });
|
|
10
|
+
for (let key in DEFAUTL_OPTIONS) {
|
|
11
|
+
this[key] = value[key];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default MessageHistoryAdapter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { initOption } from "oipage/web/option/index.js";
|
|
2
|
+
|
|
3
|
+
const DEFAUTL_OPTIONS = {
|
|
4
|
+
list: void 0,
|
|
5
|
+
new: void 0,
|
|
6
|
+
rename: void 0,
|
|
7
|
+
archive: void 0,
|
|
8
|
+
unarchive: void 0,
|
|
9
|
+
delete: void 0
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function ThreadListAdapter(options) {
|
|
13
|
+
let value = initOption(options, { ...DEFAUTL_OPTIONS });
|
|
14
|
+
for (let key in DEFAUTL_OPTIONS) {
|
|
15
|
+
this[key] = value[key];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default ThreadListAdapter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { initOption } from "oipage/web/option/index.js";
|
|
2
|
+
|
|
3
|
+
const DEFAUTL_OPTIONS = {
|
|
4
|
+
init: void 0,
|
|
5
|
+
active: void 0,
|
|
6
|
+
delete: void 0,
|
|
7
|
+
archive: void 0,
|
|
8
|
+
append: void 0,
|
|
9
|
+
retitle: void 0,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function ThreadListRuntime(options) {
|
|
13
|
+
let value = initOption(options, { ...DEFAUTL_OPTIONS });
|
|
14
|
+
for (let key in DEFAUTL_OPTIONS) {
|
|
15
|
+
this[key] = value[key];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default ThreadListRuntime;
|
package/src/generator.js
ADDED
|
@@ -0,0 +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
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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";
|
package/types/index.d.ts
ADDED
|
File without changes
|