@wabot-dev/framework 0.4.3 → 0.5.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/dist/src/addon/chat-controller/cmd/CmdChannel.js +2 -2
- package/dist/src/addon/chat-controller/socket/SocketChannel.js +4 -4
- package/dist/src/addon/chat-controller/telegram/TelegramChannel.js +5 -3
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppChannel.js +3 -3
- package/dist/src/feature/chat-bot/Chat.js +9 -0
- package/dist/src/feature/chat-bot/ChatBot.js +4 -4
- package/dist/src/feature/mindset/IMindset.js +3 -0
- package/dist/src/feature/mindset/MindsetOperator.js +28 -22
- package/dist/src/index.d.ts +20 -10
- package/package.json +1 -1
|
@@ -54,12 +54,12 @@ let CmdChannel = CmdChannel_1 = class CmdChannel {
|
|
|
54
54
|
this.auth.assign(authInfo);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
this.callBack({
|
|
57
|
+
await this.callBack({
|
|
58
58
|
chatConnection,
|
|
59
59
|
message: {
|
|
60
60
|
text: trimmedInput,
|
|
61
61
|
},
|
|
62
|
-
reply: (message) => {
|
|
62
|
+
reply: async (message) => {
|
|
63
63
|
console.log(`\n[${message.senderName}]: ${message.text}\n`);
|
|
64
64
|
this.rl.prompt();
|
|
65
65
|
if (this.auth.isAssigned()) {
|
|
@@ -48,7 +48,7 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
|
|
|
48
48
|
constructor(auth) {
|
|
49
49
|
this.auth = auth;
|
|
50
50
|
}
|
|
51
|
-
onMessage(message, socket) {
|
|
51
|
+
async onMessage(message, socket) {
|
|
52
52
|
if (!channel.callBack)
|
|
53
53
|
return;
|
|
54
54
|
const trimmedInput = message.text.trim();
|
|
@@ -60,13 +60,13 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
|
|
|
60
60
|
chatType: 'PRIVATE',
|
|
61
61
|
channelName: SocketChannel_1.name,
|
|
62
62
|
};
|
|
63
|
-
channel.callBack({
|
|
63
|
+
await channel.callBack({
|
|
64
64
|
chatConnection,
|
|
65
65
|
message: {
|
|
66
66
|
text: message.text,
|
|
67
67
|
senderName: message.senderName,
|
|
68
68
|
},
|
|
69
|
-
reply: (message) => {
|
|
69
|
+
reply: async (message) => {
|
|
70
70
|
socket.emit('message', message);
|
|
71
71
|
},
|
|
72
72
|
injectInstances: [
|
|
@@ -80,7 +80,7 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
|
|
|
80
80
|
onSocketEvent('message'),
|
|
81
81
|
__metadata("design:type", Function),
|
|
82
82
|
__metadata("design:paramtypes", [SocketChannelReceivedMessage, Socket]),
|
|
83
|
-
__metadata("design:returntype",
|
|
83
|
+
__metadata("design:returntype", Promise)
|
|
84
84
|
], SocketChannelController.prototype, "onMessage", null);
|
|
85
85
|
SocketChannelController = __decorate([
|
|
86
86
|
socketController(channel.config.namespace),
|
|
@@ -21,14 +21,16 @@ let TelegramChannel = TelegramChannel_1 = class TelegramChannel {
|
|
|
21
21
|
chatType: ctx.message.chat.type === 'private' ? 'PRIVATE' : 'GROUP',
|
|
22
22
|
channelName: TelegramChannel_1.name,
|
|
23
23
|
};
|
|
24
|
-
callback({
|
|
24
|
+
await callback({
|
|
25
25
|
chatConnection,
|
|
26
26
|
message: {
|
|
27
27
|
senderName: ctx.from.first_name,
|
|
28
28
|
text: ctx.message.text,
|
|
29
29
|
},
|
|
30
|
-
reply: (replyMessage) => {
|
|
31
|
-
|
|
30
|
+
reply: async (replyMessage) => {
|
|
31
|
+
if (!replyMessage.text)
|
|
32
|
+
return;
|
|
33
|
+
await ctx.reply(replyMessage.text);
|
|
32
34
|
},
|
|
33
35
|
});
|
|
34
36
|
});
|
|
@@ -20,11 +20,11 @@ let WhatsAppChannel = class WhatsAppChannel {
|
|
|
20
20
|
to: this.config.number,
|
|
21
21
|
listener: async (message) => {
|
|
22
22
|
try {
|
|
23
|
-
callback({
|
|
23
|
+
await callback({
|
|
24
24
|
chatConnection: message.chatConnection,
|
|
25
25
|
message: message.message,
|
|
26
|
-
reply: (replyMessage) => {
|
|
27
|
-
this.sender.sendWhatsApp({
|
|
26
|
+
reply: async (replyMessage) => {
|
|
27
|
+
await this.sender.sendWhatsApp({
|
|
28
28
|
from: this.config.number,
|
|
29
29
|
to: message.chatConnection.id,
|
|
30
30
|
message: replyMessage,
|
|
@@ -24,6 +24,15 @@ class Chat extends Entity {
|
|
|
24
24
|
}
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
|
+
getConnectionByChannel(channelName) {
|
|
28
|
+
return this.data.connections.find((a) => a.channelName === channelName) ?? null;
|
|
29
|
+
}
|
|
30
|
+
addConnection(connection) {
|
|
31
|
+
if (this.hasConnection(connection)) {
|
|
32
|
+
throw new Error('Connection already exists');
|
|
33
|
+
}
|
|
34
|
+
this.data.connections.push(connection);
|
|
35
|
+
}
|
|
27
36
|
hasAssociation(type, id) {
|
|
28
37
|
return this.data.associations?.some((a) => a.type === type && a.id === id) ?? false;
|
|
29
38
|
}
|
|
@@ -21,10 +21,10 @@ let ChatBot = class ChatBot {
|
|
|
21
21
|
humanMessage: message,
|
|
22
22
|
});
|
|
23
23
|
await this.memory.create(newChatItem);
|
|
24
|
-
this.processLoop(callback);
|
|
24
|
+
await this.processLoop(callback);
|
|
25
25
|
}
|
|
26
26
|
async processLoop(callback) {
|
|
27
|
-
const prevItems = await this.memory.findLastItems(
|
|
27
|
+
const prevItems = await this.memory.findLastItems(16);
|
|
28
28
|
if (prevItems.length === 0) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
@@ -57,13 +57,13 @@ let ChatBot = class ChatBot {
|
|
|
57
57
|
const newChatItem = new ChatItem(newItemData);
|
|
58
58
|
await this.memory.create(newChatItem);
|
|
59
59
|
if (newItemData.type === 'botMessage') {
|
|
60
|
-
callback(newChatItem.botMessage);
|
|
60
|
+
await callback(newChatItem.botMessage);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
if (newItemsData.length == 0 || newItemsData[newItemsData.length - 1].type === 'botMessage') {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
this.processLoop(callback);
|
|
66
|
+
await this.processLoop(callback);
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
ChatBot = __decorate([
|
|
@@ -16,6 +16,9 @@ let MindsetOperator = class MindsetOperator {
|
|
|
16
16
|
this.container = container;
|
|
17
17
|
this.metadata = metadataStore.getMindsetInfo(this.mindset.constructor);
|
|
18
18
|
}
|
|
19
|
+
context() {
|
|
20
|
+
return this.mindset.context();
|
|
21
|
+
}
|
|
19
22
|
identity() {
|
|
20
23
|
return this.mindset.identity();
|
|
21
24
|
}
|
|
@@ -32,7 +35,8 @@ let MindsetOperator = class MindsetOperator {
|
|
|
32
35
|
return this.mindset.llms();
|
|
33
36
|
}
|
|
34
37
|
async systemPrompt() {
|
|
35
|
-
let [identity, skills, limits, workflow] = await Promise.all([
|
|
38
|
+
let [context, identity, skills, limits, workflow] = await Promise.all([
|
|
39
|
+
this.context(),
|
|
36
40
|
this.identity(),
|
|
37
41
|
this.skills(),
|
|
38
42
|
this.limits(),
|
|
@@ -40,33 +44,35 @@ let MindsetOperator = class MindsetOperator {
|
|
|
40
44
|
]);
|
|
41
45
|
const language = identity.language.replaceAll('#', ' ');
|
|
42
46
|
const name = identity.name.replaceAll('#', ' ');
|
|
43
|
-
const age = identity.age ? identity.age.toString().replaceAll('#', ' ') : null;
|
|
44
47
|
const personality = identity.personality ? identity.personality.replaceAll('#', ' ') : null;
|
|
48
|
+
context = context.replaceAll('#', ' ');
|
|
45
49
|
skills = skills.replaceAll('#', ' ');
|
|
46
50
|
limits = limits.replaceAll('#', ' ');
|
|
47
51
|
workflow = workflow.replaceAll('#', ' ');
|
|
48
52
|
const systemPrompt = `
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
${age ? 'you are ' + age + ' years old.' : ''}
|
|
54
|
-
|
|
55
|
-
${personality ? '## Personality (in your main language) \n' + personality : ''}
|
|
56
|
-
|
|
57
|
-
## Skills (in your main language)
|
|
58
|
-
${skills}
|
|
53
|
+
# System Instructions
|
|
54
|
+
you should act as a assistant.
|
|
55
|
+
your main language is ${language}.
|
|
56
|
+
your name is ${name}.
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
${personality ? '## Personality (in your main language) \n' + personality : ''}
|
|
59
|
+
|
|
60
|
+
## Context (in your main language)
|
|
61
|
+
${context}
|
|
62
|
+
|
|
63
|
+
## Skills (in your main language)
|
|
64
|
+
${skills}
|
|
65
|
+
|
|
66
|
+
## Workflow (in your main language)
|
|
67
|
+
${workflow}
|
|
68
|
+
|
|
69
|
+
## System limitations (in your main language)
|
|
70
|
+
${limits}
|
|
71
|
+
|
|
72
|
+
## Chat memory
|
|
73
|
+
Next you will receive a chat history,
|
|
74
|
+
you should use this information to answer the user.
|
|
75
|
+
`;
|
|
70
76
|
return systemPrompt;
|
|
71
77
|
}
|
|
72
78
|
tools() {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -597,6 +597,12 @@ declare class Chat extends Entity<IChatData> {
|
|
|
597
597
|
id: string;
|
|
598
598
|
}[];
|
|
599
599
|
hasConnection(connection: IChatConnection): boolean;
|
|
600
|
+
getConnectionByChannel(channelName: string): {
|
|
601
|
+
chatType: "GROUP" | "PRIVATE";
|
|
602
|
+
channelName: string;
|
|
603
|
+
id: string;
|
|
604
|
+
} | null;
|
|
605
|
+
addConnection(connection: IChatConnection): void;
|
|
600
606
|
hasAssociation(type: string, id: string): boolean;
|
|
601
607
|
getAssociationsByType(type: string): {
|
|
602
608
|
type: string;
|
|
@@ -611,7 +617,6 @@ declare class Chat extends Entity<IChatData> {
|
|
|
611
617
|
interface IMindsetIdentity {
|
|
612
618
|
name: string;
|
|
613
619
|
language: string;
|
|
614
|
-
age?: number;
|
|
615
620
|
personality?: string;
|
|
616
621
|
emotions?: string;
|
|
617
622
|
}
|
|
@@ -620,6 +625,7 @@ interface IMindsetLlm {
|
|
|
620
625
|
model: string;
|
|
621
626
|
}
|
|
622
627
|
interface IMindset {
|
|
628
|
+
context(): Promise<string>;
|
|
623
629
|
identity(): Promise<IMindsetIdentity>;
|
|
624
630
|
skills(): Promise<string>;
|
|
625
631
|
limits(): Promise<string>;
|
|
@@ -627,6 +633,7 @@ interface IMindset {
|
|
|
627
633
|
llms(): Promise<IMindsetLlm[]>;
|
|
628
634
|
}
|
|
629
635
|
declare class Mindset implements IMindset {
|
|
636
|
+
context(): Promise<string>;
|
|
630
637
|
identity(): Promise<IMindsetIdentity>;
|
|
631
638
|
skills(): Promise<string>;
|
|
632
639
|
limits(): Promise<string>;
|
|
@@ -725,6 +732,7 @@ declare class MindsetOperator implements IMindset {
|
|
|
725
732
|
private container;
|
|
726
733
|
private metadata;
|
|
727
734
|
constructor(mindset: Mindset, container: Container, metadataStore: MindsetMetadataStore);
|
|
735
|
+
context(): Promise<string>;
|
|
728
736
|
identity(): Promise<IMindsetIdentity>;
|
|
729
737
|
skills(): Promise<string>;
|
|
730
738
|
limits(): Promise<string>;
|
|
@@ -758,6 +766,8 @@ interface IChatMessage {
|
|
|
758
766
|
senderName?: string;
|
|
759
767
|
text?: string;
|
|
760
768
|
images?: IChatMessageImage[];
|
|
769
|
+
object?: object;
|
|
770
|
+
metadata?: Record<string, string>;
|
|
761
771
|
}
|
|
762
772
|
|
|
763
773
|
interface IFunctionCall {
|
|
@@ -834,7 +844,7 @@ declare class ChatMemory implements IChatMemory {
|
|
|
834
844
|
}
|
|
835
845
|
|
|
836
846
|
interface IChatBot {
|
|
837
|
-
sendMessage(message: IChatMessage, callback: (message: IChatMessage) => void): void | Promise<void>;
|
|
847
|
+
sendMessage(message: IChatMessage, callback: (message: IChatMessage) => Promise<void>): void | Promise<void>;
|
|
838
848
|
}
|
|
839
849
|
|
|
840
850
|
declare class ChatBot implements IChatBot {
|
|
@@ -842,8 +852,8 @@ declare class ChatBot implements IChatBot {
|
|
|
842
852
|
private adapter;
|
|
843
853
|
private mindset;
|
|
844
854
|
constructor(memory: ChatMemory, adapter: ChatAdapter, mindset: MindsetOperator);
|
|
845
|
-
sendMessage(message: IChatMessage, callback: (message: IChatMessage) => void): Promise<void>;
|
|
846
|
-
protected processLoop(callback: (message: IChatMessage) => void): Promise<void>;
|
|
855
|
+
sendMessage(message: IChatMessage, callback: (message: IChatMessage) => Promise<void>): Promise<void>;
|
|
856
|
+
protected processLoop(callback: (message: IChatMessage) => Promise<void>): Promise<void>;
|
|
847
857
|
}
|
|
848
858
|
|
|
849
859
|
interface IChatRepository {
|
|
@@ -885,7 +895,7 @@ interface IChatControllerMetadata {
|
|
|
885
895
|
|
|
886
896
|
interface IReceivedMessage {
|
|
887
897
|
message: IChatMessage;
|
|
888
|
-
reply: (message: IChatMessage) => void
|
|
898
|
+
reply: (message: IChatMessage) => Promise<Record<string, string> | void>;
|
|
889
899
|
}
|
|
890
900
|
|
|
891
901
|
interface IChannelMessage extends IReceivedMessage {
|
|
@@ -894,7 +904,7 @@ interface IChannelMessage extends IReceivedMessage {
|
|
|
894
904
|
}
|
|
895
905
|
|
|
896
906
|
interface IChatChannel {
|
|
897
|
-
listen(callback: (received: IChannelMessage) => void): void;
|
|
907
|
+
listen(callback: (received: IChannelMessage) => Promise<void>): void;
|
|
898
908
|
connect(): void;
|
|
899
909
|
}
|
|
900
910
|
|
|
@@ -1505,7 +1515,7 @@ declare class CmdChannel implements IChatChannel {
|
|
|
1505
1515
|
private rl;
|
|
1506
1516
|
private callBack;
|
|
1507
1517
|
constructor(auth: Auth<any>);
|
|
1508
|
-
listen(callback: (message: IChannelMessage) => void): void;
|
|
1518
|
+
listen(callback: (message: IChannelMessage) => Promise<void>): void;
|
|
1509
1519
|
connect(): void;
|
|
1510
1520
|
}
|
|
1511
1521
|
declare function writeJsonToFile<T>(filename: string, data: T): void;
|
|
@@ -1540,7 +1550,7 @@ declare class SocketChannel implements IChatChannel {
|
|
|
1540
1550
|
private controller;
|
|
1541
1551
|
constructor(config: SocketChannelConfig);
|
|
1542
1552
|
private configController;
|
|
1543
|
-
listen(callback: (message: IChannelMessage) => void): void;
|
|
1553
|
+
listen(callback: (message: IChannelMessage) => Promise<void>): void;
|
|
1544
1554
|
connect(): void;
|
|
1545
1555
|
}
|
|
1546
1556
|
|
|
@@ -1558,7 +1568,7 @@ declare class TelegramChannel implements IChatChannel {
|
|
|
1558
1568
|
private config;
|
|
1559
1569
|
private bot;
|
|
1560
1570
|
constructor(config: TelegramChannelConfig);
|
|
1561
|
-
listen(callback: (message: IChannelMessage) => void): void;
|
|
1571
|
+
listen(callback: (message: IChannelMessage) => Promise<void>): void;
|
|
1562
1572
|
connect(): void;
|
|
1563
1573
|
}
|
|
1564
1574
|
|
|
@@ -1723,7 +1733,7 @@ declare class WhatsAppChannel implements IChatChannel {
|
|
|
1723
1733
|
private receiver;
|
|
1724
1734
|
private logger;
|
|
1725
1735
|
constructor(config: WhatsappChannelConfig, sender: WhatsAppSender, receiver: WhatsAppReceiver);
|
|
1726
|
-
listen(callback: (message: IChannelMessage) => void): void;
|
|
1736
|
+
listen(callback: (message: IChannelMessage) => Promise<void>): void;
|
|
1727
1737
|
connect(): void;
|
|
1728
1738
|
}
|
|
1729
1739
|
|