koishi-plugin-chatluna 1.0.0-beta.100
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/README.MD +173 -0
- package/lib/authorization/service.d.ts +25 -0
- package/lib/authorization/types.d.ts +36 -0
- package/lib/cache.d.ts +18 -0
- package/lib/chains/chain.d.ts +67 -0
- package/lib/chains/index.cjs +1055 -0
- package/lib/chains/index.d.ts +2 -0
- package/lib/chains/index.mjs +1014 -0
- package/lib/chains/rooms.d.ts +25 -0
- package/lib/command.d.ts +3 -0
- package/lib/commands/auth.d.ts +4 -0
- package/lib/commands/chat.d.ts +4 -0
- package/lib/commands/model.d.ts +4 -0
- package/lib/commands/preset.d.ts +4 -0
- package/lib/commands/providers.d.ts +4 -0
- package/lib/commands/room.d.ts +4 -0
- package/lib/config.d.ts +42 -0
- package/lib/index.cjs +6710 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.mjs +6727 -0
- package/lib/llm-core/agent/openai/index.d.ts +25 -0
- package/lib/llm-core/agent/openai/output_parser.d.ts +61 -0
- package/lib/llm-core/agent/openai/prompt.d.ts +2 -0
- package/lib/llm-core/agent/types.d.ts +135 -0
- package/lib/llm-core/chain/base.cjs +176 -0
- package/lib/llm-core/chain/base.d.ts +61 -0
- package/lib/llm-core/chain/base.mjs +157 -0
- package/lib/llm-core/chain/chat_chain.d.ts +23 -0
- package/lib/llm-core/chain/long_memory_chain.d.ts +25 -0
- package/lib/llm-core/chain/out_parsers.d.ts +11 -0
- package/lib/llm-core/chain/plugin_chat_chain.d.ts +33 -0
- package/lib/llm-core/chain/prompt.cjs +315 -0
- package/lib/llm-core/chain/prompt.d.ts +38 -0
- package/lib/llm-core/chain/prompt.mjs +300 -0
- package/lib/llm-core/chain/wrapper_chain.cjs +98 -0
- package/lib/llm-core/chain/wrapper_chain.d.ts +21 -0
- package/lib/llm-core/chain/wrapper_chain.mjs +78 -0
- package/lib/llm-core/chat/app.cjs +538 -0
- package/lib/llm-core/chat/app.d.ts +54 -0
- package/lib/llm-core/chat/app.mjs +529 -0
- package/lib/llm-core/chat/default.d.ts +3 -0
- package/lib/llm-core/memory/authors_note/index.d.ts +3 -0
- package/lib/llm-core/memory/history/index.d.ts +3 -0
- package/lib/llm-core/memory/lore_book/index.d.ts +24 -0
- package/lib/llm-core/memory/message/database_history.d.ts +55 -0
- package/lib/llm-core/model/base.cjs +64 -0
- package/lib/llm-core/model/base.d.ts +18 -0
- package/lib/llm-core/model/base.mjs +42 -0
- package/lib/llm-core/model/in_memory.cjs +70 -0
- package/lib/llm-core/model/in_memory.d.ts +15 -0
- package/lib/llm-core/model/in_memory.mjs +46 -0
- package/lib/llm-core/platform/api.cjs +42 -0
- package/lib/llm-core/platform/api.d.ts +60 -0
- package/lib/llm-core/platform/api.mjs +20 -0
- package/lib/llm-core/platform/client.cjs +85 -0
- package/lib/llm-core/platform/client.d.ts +26 -0
- package/lib/llm-core/platform/client.mjs +60 -0
- package/lib/llm-core/platform/config.cjs +130 -0
- package/lib/llm-core/platform/config.d.ts +40 -0
- package/lib/llm-core/platform/config.mjs +100 -0
- package/lib/llm-core/platform/index.d.ts +6 -0
- package/lib/llm-core/platform/model.cjs +498 -0
- package/lib/llm-core/platform/model.d.ts +116 -0
- package/lib/llm-core/platform/model.mjs +486 -0
- package/lib/llm-core/platform/service.cjs +276 -0
- package/lib/llm-core/platform/service.d.ts +59 -0
- package/lib/llm-core/platform/service.mjs +260 -0
- package/lib/llm-core/platform/types.cjs +34 -0
- package/lib/llm-core/platform/types.d.ts +53 -0
- package/lib/llm-core/platform/types.mjs +10 -0
- package/lib/llm-core/prompt/format.d.ts +5 -0
- package/lib/llm-core/prompt/index.cjs +348 -0
- package/lib/llm-core/prompt/index.d.ts +1 -0
- package/lib/llm-core/prompt/index.mjs +331 -0
- package/lib/llm-core/prompt/preset_prompt_parse.d.ts +4 -0
- package/lib/llm-core/prompt/type.d.ts +84 -0
- package/lib/llm-core/utils/chunk.d.ts +1 -0
- package/lib/llm-core/utils/count_tokens.cjs +156 -0
- package/lib/llm-core/utils/count_tokens.d.ts +12 -0
- package/lib/llm-core/utils/count_tokens.mjs +130 -0
- package/lib/llm-core/utils/tiktoken.d.ts +4 -0
- package/lib/middleware.d.ts +3 -0
- package/lib/middlewares/add_preset.d.ts +12 -0
- package/lib/middlewares/add_user_to_auth_group.d.ts +9 -0
- package/lib/middlewares/allow_reply.d.ts +9 -0
- package/lib/middlewares/black_list.d.ts +9 -0
- package/lib/middlewares/censor.d.ts +9 -0
- package/lib/middlewares/chat_time_limit_check.d.ts +25 -0
- package/lib/middlewares/chat_time_limit_save.d.ts +9 -0
- package/lib/middlewares/check_room.d.ts +9 -0
- package/lib/middlewares/clear_balance.d.ts +9 -0
- package/lib/middlewares/clear_room.d.ts +9 -0
- package/lib/middlewares/clone_preset.d.ts +15 -0
- package/lib/middlewares/cooldown_time.d.ts +9 -0
- package/lib/middlewares/create_auth_group.d.ts +20 -0
- package/lib/middlewares/create_room.d.ts +21 -0
- package/lib/middlewares/delete_preset.d.ts +12 -0
- package/lib/middlewares/delete_room.d.ts +9 -0
- package/lib/middlewares/invite_room.d.ts +14 -0
- package/lib/middlewares/join_room.d.ts +9 -0
- package/lib/middlewares/kick_member.d.ts +9 -0
- package/lib/middlewares/kick_user_form_auth_group.d.ts +9 -0
- package/lib/middlewares/leave_room.d.ts +9 -0
- package/lib/middlewares/lifecycle.d.ts +29 -0
- package/lib/middlewares/list_all_embeddings.d.ts +9 -0
- package/lib/middlewares/list_all_model.d.ts +13 -0
- package/lib/middlewares/list_all_preset.d.ts +9 -0
- package/lib/middlewares/list_all_vectorstore.d.ts +9 -0
- package/lib/middlewares/list_auth_group.d.ts +12 -0
- package/lib/middlewares/list_room.d.ts +9 -0
- package/lib/middlewares/mute_user.d.ts +9 -0
- package/lib/middlewares/query_balance.d.ts +9 -0
- package/lib/middlewares/read_chat_message.d.ts +9 -0
- package/lib/middlewares/render_message.d.ts +15 -0
- package/lib/middlewares/request_model.d.ts +17 -0
- package/lib/middlewares/resolve_model.d.ts +9 -0
- package/lib/middlewares/resolve_room.d.ts +14 -0
- package/lib/middlewares/rollback_chat.d.ts +9 -0
- package/lib/middlewares/room_info.d.ts +9 -0
- package/lib/middlewares/room_permission.d.ts +9 -0
- package/lib/middlewares/set_auth_group.d.ts +9 -0
- package/lib/middlewares/set_auto_update_room.d.ts +12 -0
- package/lib/middlewares/set_balance.d.ts +13 -0
- package/lib/middlewares/set_default_embeddings.d.ts +16 -0
- package/lib/middlewares/set_default_vectorstore.d.ts +12 -0
- package/lib/middlewares/set_preset.d.ts +12 -0
- package/lib/middlewares/set_room.d.ts +9 -0
- package/lib/middlewares/stop_chat.d.ts +9 -0
- package/lib/middlewares/switch_room.d.ts +9 -0
- package/lib/middlewares/thinking_message_recall.d.ts +9 -0
- package/lib/middlewares/thinking_message_send.d.ts +17 -0
- package/lib/middlewares/transfer_room.d.ts +9 -0
- package/lib/middlewares/wipe.d.ts +13 -0
- package/lib/preset.cjs +220 -0
- package/lib/preset.d.ts +23 -0
- package/lib/preset.mjs +192 -0
- package/lib/render.d.ts +13 -0
- package/lib/renders/default.d.ts +9 -0
- package/lib/renders/image.d.ts +14 -0
- package/lib/renders/mixed-image.d.ts +16 -0
- package/lib/renders/mixed-voice.d.ts +14 -0
- package/lib/renders/raw.d.ts +5 -0
- package/lib/renders/text.d.ts +7 -0
- package/lib/renders/voice.d.ts +7 -0
- package/lib/services/chat.cjs +1308 -0
- package/lib/services/chat.d.ts +112 -0
- package/lib/services/chat.mjs +1296 -0
- package/lib/services/message_transform.d.ts +9 -0
- package/lib/services/types.d.ts +23 -0
- package/lib/types.d.ts +54 -0
- package/lib/utils/buffer_text.d.ts +20 -0
- package/lib/utils/error.cjs +114 -0
- package/lib/utils/error.d.ts +53 -0
- package/lib/utils/error.mjs +89 -0
- package/lib/utils/koishi.cjs +35 -0
- package/lib/utils/koishi.d.ts +3 -0
- package/lib/utils/koishi.mjs +13 -0
- package/lib/utils/lock.cjs +74 -0
- package/lib/utils/lock.d.ts +9 -0
- package/lib/utils/lock.mjs +52 -0
- package/lib/utils/logger.cjs +55 -0
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.mjs +31 -0
- package/lib/utils/pagination.cjs +73 -0
- package/lib/utils/pagination.d.ts +20 -0
- package/lib/utils/pagination.mjs +51 -0
- package/lib/utils/promise.cjs +75 -0
- package/lib/utils/promise.d.ts +8 -0
- package/lib/utils/promise.mjs +51 -0
- package/lib/utils/queue.cjs +87 -0
- package/lib/utils/queue.d.ts +9 -0
- package/lib/utils/queue.mjs +68 -0
- package/lib/utils/request.cjs +159 -0
- package/lib/utils/request.d.ts +17 -0
- package/lib/utils/request.mjs +125 -0
- package/lib/utils/sse.cjs +203 -0
- package/lib/utils/sse.d.ts +21 -0
- package/lib/utils/sse.mjs +182 -0
- package/lib/utils/stream.cjs +61 -0
- package/lib/utils/stream.d.ts +1 -0
- package/lib/utils/stream.mjs +39 -0
- package/lib/utils/string.cjs +136 -0
- package/lib/utils/string.d.ts +10 -0
- package/lib/utils/string.mjs +106 -0
- package/lib/utils/types.cjs +17 -0
- package/lib/utils/types.d.ts +1 -0
- package/lib/utils/types.mjs +0 -0
- package/package.json +264 -0
- package/resources/css/code.css +118 -0
- package/resources/css/main.css +412 -0
- package/resources/out.html +65 -0
- package/resources/presets/catgirl.yml +23 -0
- package/resources/presets/chatgpt.yml +12 -0
- package/resources/presets/empty.yml +5 -0
- package/resources/template.html +63 -0
package/README.MD
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="./logo.png" alt="Project Logo" title="Project Logo" />
|
|
4
|
+
|
|
5
|
+
[中文](./README.MD) | English
|
|
6
|
+
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
_A bot plugin for LLM chat services with multi-model integration, extensibility, and various output formats._
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/koishi-plugin-chatluna) [](https://www.npmjs.com/package/koishi-plugin-chatluna)  
|
|
12
|
+
|
|
13
|
+
[](https://t.me/koishi_chatluna) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=eEBVq6GK7HYX2y61x55WD6hnXTIRop-0&authKey=i4pG5%2BJ%2FY8auWprBubhremTkn3vroPigQq5m9RENGBLrLmlj%2BSu3G%2BqllK7Wts2M&noverify=0&group_code=282381753) [-green)](https://chatluna.chat/)
|
|
14
|
+
|
|
15
|
+
**Project Status: Iterating towards v1.0 (Contributors needed for documentation)**
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
## Screenshots
|
|
20
|
+
|
|
21
|
+
Work in progress...
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- 🚀 Highly extensible (LangChain & Koishi APIs)
|
|
26
|
+
- 🎭 Custom conversation presets
|
|
27
|
+
- 🛡️ Rate limiting & blacklist system
|
|
28
|
+
- 🎨 Multi-format output (text, voice, image, mixed)
|
|
29
|
+
- 🧠 Context-aware with long-term memory
|
|
30
|
+
- 🔀 Three modes: chat, browsing, plugin
|
|
31
|
+
- 🔒 Content moderation via [Koishi censor](https://censor.koishi.chat/)
|
|
32
|
+
|
|
33
|
+
## Roadmap
|
|
34
|
+
|
|
35
|
+
- [x] Room-based conversation system
|
|
36
|
+
- [x] Content moderation
|
|
37
|
+
- [x] TTS support (via [vits service](https://github.com/initialencounter/mykoishi/blame/master/vits/readme.md))
|
|
38
|
+
- [x] Image rendering for replies
|
|
39
|
+
- [x] Multi-model integration
|
|
40
|
+
- [x] Preset system
|
|
41
|
+
- [x] ~~Conversation import/export~~ (abandoned)
|
|
42
|
+
- [x] v1 refactoring
|
|
43
|
+
- [x] Streaming responses
|
|
44
|
+
- [x] i18n support
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
Install the plugin in Koishi for basic functionality. For detailed setup, see our [docs](https://chatluna.chat/guide/getting-started.html).
|
|
49
|
+
|
|
50
|
+
## Supported Models
|
|
51
|
+
|
|
52
|
+
| Model/Platform | Integration | Features | Notes |
|
|
53
|
+
|:---------------|:------------|:---------|:------|
|
|
54
|
+
| [OpenAI](./packages/openai-adapter/README.md) | Official API | Customizable, plugin/browsing modes | Paid API |
|
|
55
|
+
| [Azure OpenAI](./packages/azure-openai-adapter/README.md) | Official API | Similar to OpenAI | Paid API |
|
|
56
|
+
| [Google Gemini](./packages/gemini-adapter/README.md) | Official API | Fast, outperforms GPT-3.5 | Requires account, may be charged |
|
|
57
|
+
| [New Bing](./packages/newbing-adapter/README.md) | Reverse-engineered | Web search, no login required | Proxy needed, CAPTCHA required |
|
|
58
|
+
| [Claude API](./packages/claude-adapter) | Official API | Large context, often beats GPT-3.5 | Paid, no Function Call |
|
|
59
|
+
| [Tongyi Qianwen](./packages/qwen-adapter/README.md) | Official API | Free quota available | Slightly better than Zhipu |
|
|
60
|
+
| [Zhipu](./packages/zhipu-adapter/README.md) | Official API | Free tokens for new users | Better than Xunfei Spark |
|
|
61
|
+
| [Xunfei Spark](./packages/spark-adapter/README.md) | Official API | Free quota for new users | Similar to GPT-3.5 |
|
|
62
|
+
| [Wenxin Yiyan](./packages/wenxin-adapter/README.md) | Official API | Baidu's model | Slightly worse than Xunfei Spark |
|
|
63
|
+
| [Hunyuan](./packages/hunyuan-adapter/README.md) | Official API | Tencent's model | Better than Wenxin Yiyan |
|
|
64
|
+
| [Ollama](./packages/ollama-adapter/README.md) | Self-hosted | Open-source, CPU/GPU support | Requires backend setup |
|
|
65
|
+
| [GPT Free](./packages/gptfree-adapter/README.md) | Unofficial | Uses other websites' GPT models | Unstable, may fail |
|
|
66
|
+
| [ChatGLM](./packages/chatglm-adapter/README.md) | Self-hosted | Can be self-hosted | Requires backend, suboptimal performance |
|
|
67
|
+
| [RWKV](./packages/rwkv-adapter/README.md) | Self-hosted | Open-source model | Requires backend setup |
|
|
68
|
+
|
|
69
|
+
[Web search support](/packages/search-service/README.md):
|
|
70
|
+
|
|
71
|
+
- Google (API)
|
|
72
|
+
- Bing (API)
|
|
73
|
+
- DuckDuckGO (Lite & Web)
|
|
74
|
+
|
|
75
|
+
## Presets
|
|
76
|
+
|
|
77
|
+
From `1.0.0-alpha.10`, we use YAML for more customizable presets. Default preset: [catgirl.yml](/packages/core/resources/presets/catgirl.yml)
|
|
78
|
+
|
|
79
|
+
Preset folder: `<koishi_dir>/data/chathub/presets`
|
|
80
|
+
|
|
81
|
+
For more info, see [preset system docs](https://chatluna.chat/guide/preset-system/introduction.html).
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
Clone the repo:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# yarn
|
|
89
|
+
yarn clone ChatLunaLab/chatluna
|
|
90
|
+
# npm
|
|
91
|
+
npm run clone ChatLunaLab/chatluna
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Update `tsconfig.json`:
|
|
95
|
+
|
|
96
|
+
``` json
|
|
97
|
+
{
|
|
98
|
+
"extends": "./tsconfig.base",
|
|
99
|
+
"compilerOptions": {
|
|
100
|
+
"baseUrl": ".",
|
|
101
|
+
"paths": {
|
|
102
|
+
"koishi-plugin-chatluna-*": ["external/chatluna/packages/*/src"]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Build the project:
|
|
109
|
+
|
|
110
|
+
``` bash
|
|
111
|
+
# yarn
|
|
112
|
+
yarn workspace @root/chatluna-koishi build
|
|
113
|
+
# npm
|
|
114
|
+
npm run build -w @root/chatluna-koishi
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Start development with `yarn dev` or `npm run dev`.
|
|
118
|
+
|
|
119
|
+
> Note: HMR may not be fully compatible. If issues occur, rebuild and restart.
|
|
120
|
+
|
|
121
|
+
## Contributing
|
|
122
|
+
|
|
123
|
+
We need help with:
|
|
124
|
+
|
|
125
|
+
- [ ] Web UI
|
|
126
|
+
- [ ] HTTP Server
|
|
127
|
+
- [ ] Project Documentation
|
|
128
|
+
|
|
129
|
+
PRs and discussions are welcome!
|
|
130
|
+
|
|
131
|
+
## Contributors
|
|
132
|
+
|
|
133
|
+
<a href="https://github.com/ChatLunaLab/chatluna/graphs/contributors">
|
|
134
|
+
<img src="https://contrib.rocks/image?repo=ChatLunaLab/chatluna" />
|
|
135
|
+
</a>
|
|
136
|
+
|
|
137
|
+

|
|
138
|
+
|
|
139
|
+
[](https://star-history.com/#ChatLunaLab/chatluna)
|
|
140
|
+
|
|
141
|
+
## Usage Notice
|
|
142
|
+
|
|
143
|
+
Developed by [ChatLunaLab](https://github.com/ChatLunaLab).
|
|
144
|
+
|
|
145
|
+
ChatLuna is an LLM-based chatbot framework. We collaborate with the open-source community to advance LLM technology. Users must comply with open-source agreements and avoid using this project for potentially harmful purposes or unevaluated services.
|
|
146
|
+
|
|
147
|
+
This project doesn't provide AI services directly. Users must obtain API access from AI service providers.
|
|
148
|
+
|
|
149
|
+
Users are responsible for complying with local laws and using locally available AI services.
|
|
150
|
+
|
|
151
|
+
The project isn't responsible for algorithm-generated results. All results and operations are the user's responsibility.
|
|
152
|
+
|
|
153
|
+
Users configure their own data storage. The project doesn't provide direct data storage.
|
|
154
|
+
|
|
155
|
+
The project isn't liable for user-caused data security issues, public opinion risks, or model misuse.
|
|
156
|
+
|
|
157
|
+
## Acknowledgments
|
|
158
|
+
|
|
159
|
+
Thanks to these projects:
|
|
160
|
+
|
|
161
|
+
[koishi-plugin-openai](https://github.com/TomLBZ/koishi-plugin-openai)
|
|
162
|
+
|
|
163
|
+
[node-chatgpt-api](https://github.com/waylaidwanderer/node-chatgpt-api)
|
|
164
|
+
|
|
165
|
+
[poe-api](https://github.com/ading2210/poe-api)
|
|
166
|
+
|
|
167
|
+
[Bard](https://github.com/muhiris/wgpt)
|
|
168
|
+
|
|
169
|
+
[chathub](https://github.com/chathub-dev/chathub)
|
|
170
|
+
|
|
171
|
+
Thanks to [JetBrains](https://www.jetbrains.com/?from=ChatLuna) for open-source [WebStorm](https://www.jetbrains.com/webstorm/?from=ChatLuna) licenses.
|
|
172
|
+
|
|
173
|
+
[<img src=".github/jetbrains-variant-3.png" width="200"/>](https://www.jetbrains.com/?from=ChatLuna)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Context, Service, Session } from 'koishi';
|
|
2
|
+
import { ChatHubAuthGroup, ChatHubAuthUser } from './types';
|
|
3
|
+
export declare class ChatLunaAuthService extends Service {
|
|
4
|
+
readonly ctx: Context;
|
|
5
|
+
config: any;
|
|
6
|
+
constructor(ctx: Context, config: any);
|
|
7
|
+
getUser(session: Session, userId?: string): Promise<ChatHubAuthUser>;
|
|
8
|
+
private _createUser;
|
|
9
|
+
createAuthGroup(session: Session, group: ChatHubAuthGroup): Promise<void>;
|
|
10
|
+
resolveAuthGroup(session: Session, platform: string, userId?: string): Promise<ChatHubAuthGroup>;
|
|
11
|
+
getAuthGroups(platform?: string): Promise<ChatHubAuthGroup[]>;
|
|
12
|
+
getAuthGroup(name: string, throwError?: boolean): Promise<ChatHubAuthGroup>;
|
|
13
|
+
calculateBalance(session: Session, platform: string, usedTokenNumber: number, userId?: string): Promise<number>;
|
|
14
|
+
getBalance(session: Session, userId?: string): Promise<number>;
|
|
15
|
+
modifyBalance(session: Session, amount: number, userId?: string): Promise<number>;
|
|
16
|
+
setBalance(session: Session, amount: number, userId?: string): Promise<number>;
|
|
17
|
+
private _getAuthGroup;
|
|
18
|
+
resetAuthGroup(authGroupId: number): Promise<ChatHubAuthGroup>;
|
|
19
|
+
increaseAuthGroupCount(authGroupId: number): Promise<void>;
|
|
20
|
+
addUserToGroup(user: ChatHubAuthUser, groupName: string): Promise<void>;
|
|
21
|
+
removeUserFormGroup(user: ChatHubAuthUser, groupName: string): Promise<void>;
|
|
22
|
+
setAuthGroup(groupName: string, group: Partial<ChatHubAuthGroup>): Promise<void>;
|
|
23
|
+
private _initAuthGroup;
|
|
24
|
+
private _defineDatabase;
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ChatLunaAuthService } from './service';
|
|
2
|
+
export interface ChatHubAuthUser {
|
|
3
|
+
userId: string;
|
|
4
|
+
balance: number;
|
|
5
|
+
authType: AuthType;
|
|
6
|
+
}
|
|
7
|
+
export interface ChatHubAuthJoinedUser {
|
|
8
|
+
userId: string;
|
|
9
|
+
groupId: number;
|
|
10
|
+
groupName: string;
|
|
11
|
+
id: number;
|
|
12
|
+
}
|
|
13
|
+
export type AuthType = 'guest' | 'user' | 'admin';
|
|
14
|
+
export interface ChatHubAuthGroup {
|
|
15
|
+
name: string;
|
|
16
|
+
platform?: string;
|
|
17
|
+
priority: number;
|
|
18
|
+
id: number;
|
|
19
|
+
limitPerMin: number;
|
|
20
|
+
limitPerDay: number;
|
|
21
|
+
costPerToken: number;
|
|
22
|
+
currentLimitPerMin?: number;
|
|
23
|
+
currentLimitPerDay?: number;
|
|
24
|
+
lastCallTime?: number;
|
|
25
|
+
supportModels: string[];
|
|
26
|
+
}
|
|
27
|
+
declare module 'koishi' {
|
|
28
|
+
interface Context {
|
|
29
|
+
chatluna_auth: ChatLunaAuthService;
|
|
30
|
+
}
|
|
31
|
+
interface Tables {
|
|
32
|
+
chathub_auth_group: ChatHubAuthGroup;
|
|
33
|
+
chathub_auth_user: ChatHubAuthUser;
|
|
34
|
+
chathub_auth_joined_user: ChatHubAuthJoinedUser;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/lib/cache.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Tables } from '@koishijs/cache';
|
|
2
|
+
import { Context } from 'koishi';
|
|
3
|
+
import { Config } from './config';
|
|
4
|
+
export declare class Cache<K extends keyof Tables, T extends Tables[K]> {
|
|
5
|
+
private ctx;
|
|
6
|
+
readonly config: Config;
|
|
7
|
+
readonly tableName: K;
|
|
8
|
+
constructor(ctx: Context, config: Config, tableName: K);
|
|
9
|
+
get(id: string): Promise<T>;
|
|
10
|
+
set(id: string, value: T): Promise<void>;
|
|
11
|
+
delete(id: string): Promise<void>;
|
|
12
|
+
clear(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
declare module '@koishijs/cache' {
|
|
15
|
+
interface Tables {
|
|
16
|
+
'chathub/keys': string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Context, h, Session } from 'koishi';
|
|
2
|
+
import { Config } from '../config';
|
|
3
|
+
import '../middlewares/lifecycle';
|
|
4
|
+
/**
|
|
5
|
+
* ChatChain为消息的发送和接收提供了一个统一的中间提供交互
|
|
6
|
+
*/
|
|
7
|
+
export declare class ChatChain {
|
|
8
|
+
private readonly ctx;
|
|
9
|
+
private readonly config;
|
|
10
|
+
readonly _graph: ChatChainDependencyGraph;
|
|
11
|
+
private readonly _senders;
|
|
12
|
+
private isSetErrorMessage;
|
|
13
|
+
constructor(ctx: Context, config: Config);
|
|
14
|
+
receiveMessage(session: Session, ctx?: Context): Promise<boolean>;
|
|
15
|
+
receiveCommand(session: Session, command: string, options?: ChainMiddlewareContextOptions): Promise<boolean>;
|
|
16
|
+
middleware<T extends keyof ChainMiddlewareName>(name: T, middleware: ChainMiddlewareFunction, ctx?: Context): ChainMiddleware;
|
|
17
|
+
sender(sender: ChatChainSender): void;
|
|
18
|
+
private _runMiddleware;
|
|
19
|
+
private sendMessage;
|
|
20
|
+
}
|
|
21
|
+
declare class ChatChainDependencyGraph {
|
|
22
|
+
private _tasks;
|
|
23
|
+
private _dependencies;
|
|
24
|
+
private _eventEmitter;
|
|
25
|
+
private _listeners;
|
|
26
|
+
constructor();
|
|
27
|
+
addNode(middleware: ChainMiddleware): void;
|
|
28
|
+
removeNode(name: string): void;
|
|
29
|
+
once(name: string, listener: (...args: any[]) => void): void;
|
|
30
|
+
before(taskA: ChainMiddleware | string, taskB: ChainMiddleware | string): void;
|
|
31
|
+
after(taskA: ChainMiddleware | string, taskB: ChainMiddleware | string): void;
|
|
32
|
+
getDependencies(task: string): Set<string>;
|
|
33
|
+
getDependents(task: string): string[];
|
|
34
|
+
build(): ChainMiddleware[];
|
|
35
|
+
}
|
|
36
|
+
export declare class ChainMiddleware {
|
|
37
|
+
readonly name: string;
|
|
38
|
+
private readonly execute;
|
|
39
|
+
private readonly graph;
|
|
40
|
+
constructor(name: string, execute: ChainMiddlewareFunction, graph: ChatChainDependencyGraph);
|
|
41
|
+
before<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
42
|
+
after<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
43
|
+
run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | ChainMiddlewareRunStatus | h[][]>;
|
|
44
|
+
}
|
|
45
|
+
export interface ChainMiddlewareContext {
|
|
46
|
+
config: Config;
|
|
47
|
+
ctx: Context;
|
|
48
|
+
session: Session;
|
|
49
|
+
message: string | h[] | h[][];
|
|
50
|
+
options?: ChainMiddlewareContextOptions;
|
|
51
|
+
command?: string;
|
|
52
|
+
recallThinkingMessage?: () => Promise<void>;
|
|
53
|
+
send: (message: h[][] | h[] | h | string) => Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export interface ChainMiddlewareContextOptions {
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}
|
|
58
|
+
export interface ChainMiddlewareName {
|
|
59
|
+
}
|
|
60
|
+
export type ChainMiddlewareFunction = (session: Session, context: ChainMiddlewareContext) => Promise<string | h[] | h[][] | ChainMiddlewareRunStatus | null>;
|
|
61
|
+
export type ChatChainSender = (session: Session, message: (h[] | h | string)[]) => Promise<void>;
|
|
62
|
+
export declare enum ChainMiddlewareRunStatus {
|
|
63
|
+
SKIPPED = 0,
|
|
64
|
+
STOP = 1,
|
|
65
|
+
CONTINUE = 2
|
|
66
|
+
}
|
|
67
|
+
export {};
|