sillytavern 1.4.1
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/.dockerignore +4 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/workflows/npm-publish.yml +32 -0
- package/Dockerfile +49 -0
- package/Start.bat +3 -0
- package/colab/GPU.ipynb +339 -0
- package/colab/extras_server.py +40 -0
- package/colab/globals.py +2 -0
- package/colab/models.py +77 -0
- package/docker/docker-compose.yml +12 -0
- package/docker/docker-entrypoint.sh +28 -0
- package/faq.md +208 -0
- package/package.json +49 -0
- package/poe-client.js +638 -0
- package/poe-test.js +21 -0
- package/poe_graphql/AddHumanMessageMutation.graphql +52 -0
- package/poe_graphql/AddMessageBreakMutation.graphql +17 -0
- package/poe_graphql/AutoSubscriptionMutation.graphql +7 -0
- package/poe_graphql/BioFragment.graphql +8 -0
- package/poe_graphql/ChatAddedSubscription.graphql +5 -0
- package/poe_graphql/ChatFragment.graphql +6 -0
- package/poe_graphql/ChatListPaginationQuery.graphql +316 -0
- package/poe_graphql/ChatPaginationQuery.graphql +26 -0
- package/poe_graphql/ChatViewQuery.graphql +8 -0
- package/poe_graphql/DeleteHumanMessagesMutation.graphql +7 -0
- package/poe_graphql/DeleteMessageMutation.graphql +7 -0
- package/poe_graphql/HandleFragment.graphql +8 -0
- package/poe_graphql/LoginWithVerificationCodeMutation.graphql +13 -0
- package/poe_graphql/MessageAddedSubscription.graphql +115 -0
- package/poe_graphql/MessageDeletedSubscription.graphql +8 -0
- package/poe_graphql/MessageFragment.graphql +13 -0
- package/poe_graphql/MessageRemoveVoteMutation.graphql +7 -0
- package/poe_graphql/MessageSetVoteMutation.graphql +7 -0
- package/poe_graphql/SendVerificationCodeForLoginMutation.graphql +12 -0
- package/poe_graphql/ShareMessagesMutation.graphql +9 -0
- package/poe_graphql/SignupWithVerificationCodeMutation.graphql +13 -0
- package/poe_graphql/StaleChatUpdateMutation.graphql +7 -0
- package/poe_graphql/SubscriptionsMutation.graphql +9 -0
- package/poe_graphql/SummarizePlainPostQuery.graphql +3 -0
- package/poe_graphql/SummarizeQuotePostQuery.graphql +3 -0
- package/poe_graphql/SummarizeSharePostQuery.graphql +3 -0
- package/poe_graphql/UserSnippetFragment.graphql +14 -0
- package/poe_graphql/ViewerInfoQuery.graphql +21 -0
- package/poe_graphql/ViewerMessageLimitUpdatedSubscription.graphql +81 -0
- package/poe_graphql/ViewerStateFragment.graphql +30 -0
- package/poe_graphql/ViewerStateUpdatedSubscription.graphql +63 -0
- package/public/KoboldAI Settings/Ace of Spades 13B.settings +22 -0
- package/public/KoboldAI Settings/Adventurer-NeoX-20B-Erebus.settings +54 -0
- package/public/KoboldAI Settings/Basic Coherence 13B.settings +22 -0
- package/public/KoboldAI Settings/Best Guess 6B.settings +22 -0
- package/public/KoboldAI Settings/Calibrated-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Classic-Pygmalion-2.7b.settings +46 -0
- package/public/KoboldAI Settings/Classic-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Coherent Creativity 6B.settings +22 -0
- package/public/KoboldAI Settings/Default-TavernAI.settings +22 -0
- package/public/KoboldAI Settings/DragonSlayer-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/GPU-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Genesis 13B.settings +22 -0
- package/public/KoboldAI Settings/Godlike.settings +22 -0
- package/public/KoboldAI Settings/Good Winds.settings +22 -0
- package/public/KoboldAI Settings/Lancer-OPT-2.7B-Erebus.settings +54 -0
- package/public/KoboldAI Settings/Liminal Drift.settings +22 -0
- package/public/KoboldAI Settings/Low Rider 13B.settings +22 -0
- package/public/KoboldAI Settings/Luna Moth 6B.settings +22 -0
- package/public/KoboldAI Settings/Mayday.settings +22 -0
- package/public/KoboldAI Settings/Ouroboros.settings +22 -0
- package/public/KoboldAI Settings/Pleasing Results 6B.settings +22 -0
- package/public/KoboldAI Settings/Pro Writer 13B.settings +22 -0
- package/public/KoboldAI Settings/RA - Pygmalion-1.3b.settings +46 -0
- package/public/KoboldAI Settings/Storywriter 6B.settings +22 -0
- package/public/NovelAI Settings/Classic-Euterpe.settings +14 -0
- package/public/NovelAI Settings/Classic-Krake.settings +14 -0
- package/public/OpenAI Settings/Default.settings +15 -0
- package/public/TextGen Settings/Beam Search.settings +15 -0
- package/public/TextGen Settings/Contrastive Search.settings +15 -0
- package/public/TextGen Settings/Default.settings +15 -0
- package/public/TextGen Settings/Deterministic.settings +15 -0
- package/public/TextGen Settings/Kobold (Godlike).settings +15 -0
- package/public/TextGen Settings/Kobold (Liminal Drift).settings +15 -0
- package/public/TextGen Settings/Naive.settings +15 -0
- package/public/TextGen Settings/NovelAI (Best Guess).settings +15 -0
- package/public/TextGen Settings/NovelAI (Decadence).settings +15 -0
- package/public/TextGen Settings/NovelAI (Genesis).settings +15 -0
- package/public/TextGen Settings/NovelAI (Lycaenidae).settings +15 -0
- package/public/TextGen Settings/NovelAI (Ouroboros).settings +15 -0
- package/public/TextGen Settings/NovelAI (Pleasing Results).settings +15 -0
- package/public/TextGen Settings/NovelAI (Sphinx Moth).settings +15 -0
- package/public/TextGen Settings/NovelAI (Storywriter).settings +15 -0
- package/public/TextGen Settings/Pygmalion.settings +15 -0
- package/public/css/fontawesome.css +8488 -0
- package/public/css/notes.css +46 -0
- package/public/css/solid.css +24 -0
- package/public/favicon.ico +0 -0
- package/public/img/No-Image-Placeholder.svg +309 -0
- package/public/img/addbg3.png +0 -0
- package/public/img/ai4.png +0 -0
- package/public/img/apple-icon-114x114.png +0 -0
- package/public/img/apple-icon-144x144.png +0 -0
- package/public/img/apple-icon-57x57.png +0 -0
- package/public/img/apple-icon-72x72.png +0 -0
- package/public/img/book2.png +0 -0
- package/public/img/default-expressions/admiration.png +0 -0
- package/public/img/default-expressions/amusement.png +0 -0
- package/public/img/default-expressions/anger.png +0 -0
- package/public/img/default-expressions/annoyance.png +0 -0
- package/public/img/default-expressions/approval.png +0 -0
- package/public/img/default-expressions/caring.png +0 -0
- package/public/img/default-expressions/confusion.png +0 -0
- package/public/img/default-expressions/curiosity.png +0 -0
- package/public/img/default-expressions/desire.png +0 -0
- package/public/img/default-expressions/desire1.png +0 -0
- package/public/img/default-expressions/desire2.png +0 -0
- package/public/img/default-expressions/disappointment.png +0 -0
- package/public/img/default-expressions/disapproval.png +0 -0
- package/public/img/default-expressions/disgust.png +0 -0
- package/public/img/default-expressions/embarrassment.png +0 -0
- package/public/img/default-expressions/excitement.png +0 -0
- package/public/img/default-expressions/fear.png +0 -0
- package/public/img/default-expressions/gratitude.png +0 -0
- package/public/img/default-expressions/grief.png +0 -0
- package/public/img/default-expressions/joy.png +0 -0
- package/public/img/default-expressions/love.png +0 -0
- package/public/img/default-expressions/nervousness.png +0 -0
- package/public/img/default-expressions/neutral.png +0 -0
- package/public/img/default-expressions/optimism.png +0 -0
- package/public/img/default-expressions/pride.png +0 -0
- package/public/img/default-expressions/realization.png +0 -0
- package/public/img/default-expressions/relief.png +0 -0
- package/public/img/default-expressions/remorse.png +0 -0
- package/public/img/default-expressions/sadness.png +0 -0
- package/public/img/default-expressions/surprise.png +0 -0
- package/public/img/five.png +0 -0
- package/public/img/times-circle.svg +1 -0
- package/public/img/you.png +0 -0
- package/public/index.html +1899 -0
- package/public/notes/1.html +44 -0
- package/public/notes/1.png +0 -0
- package/public/notes/10.html +20 -0
- package/public/notes/11.html +33 -0
- package/public/notes/12.html +27 -0
- package/public/notes/13.html +29 -0
- package/public/notes/13_1.html +24 -0
- package/public/notes/13_2.html +25 -0
- package/public/notes/13_3.html +89 -0
- package/public/notes/14.html +30 -0
- package/public/notes/2.html +37 -0
- package/public/notes/2.png +0 -0
- package/public/notes/3.html +37 -0
- package/public/notes/4.html +105 -0
- package/public/notes/6.html +33 -0
- package/public/notes/7.html +40 -0
- package/public/notes/8.html +19 -0
- package/public/notes/9.html +46 -0
- package/public/notes/advanced_formatting.html +91 -0
- package/public/notes/group_reply_strategy.html +63 -0
- package/public/notes/message_sound.html +33 -0
- package/public/notes/multigen.html +36 -0
- package/public/notes/oai_api_key.html +37 -0
- package/public/notes/textgen_streaming.html +29 -0
- package/public/notes/token-limits.html +68 -0
- package/public/script.js +5131 -0
- package/public/scripts/RossAscends-mods.js +750 -0
- package/public/scripts/bookmarks.js +130 -0
- package/public/scripts/extensions/backgrounds/index.js +129 -0
- package/public/scripts/extensions/backgrounds/manifest.json +11 -0
- package/public/scripts/extensions/backgrounds/style.css +45 -0
- package/public/scripts/extensions/caption/index.js +117 -0
- package/public/scripts/extensions/caption/manifest.json +13 -0
- package/public/scripts/extensions/caption/style.css +23 -0
- package/public/scripts/extensions/dice/droll.js +108 -0
- package/public/scripts/extensions/dice/index.js +96 -0
- package/public/scripts/extensions/dice/manifest.json +11 -0
- package/public/scripts/extensions/dice/style.css +26 -0
- package/public/scripts/extensions/expressions/index.js +387 -0
- package/public/scripts/extensions/expressions/manifest.json +13 -0
- package/public/scripts/extensions/expressions/style.css +115 -0
- package/public/scripts/extensions/floating-prompt/index.js +151 -0
- package/public/scripts/extensions/floating-prompt/manifest.json +11 -0
- package/public/scripts/extensions/floating-prompt/style.css +19 -0
- package/public/scripts/extensions/memory/index.js +358 -0
- package/public/scripts/extensions/memory/manifest.json +13 -0
- package/public/scripts/extensions/memory/style.css +34 -0
- package/public/scripts/extensions.js +288 -0
- package/public/scripts/f-localStorage.js +27 -0
- package/public/scripts/gpt-2-3-tokenizer/README.md +28 -0
- package/public/scripts/gpt-2-3-tokenizer/encoder.js +1 -0
- package/public/scripts/gpt-2-3-tokenizer/mod.js +169 -0
- package/public/scripts/gpt-2-3-tokenizer/vocab.bpe.js +1 -0
- package/public/scripts/gpt-3-tokenizer/array-keyed-map.js +210 -0
- package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js +271 -0
- package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js.map +1 -0
- package/public/scripts/group-chats.js +899 -0
- package/public/scripts/horde.js +214 -0
- package/public/scripts/jquery-3.5.1.min.js +2 -0
- package/public/scripts/jquery-cookie-1.4.1.min.js +2 -0
- package/public/scripts/jquery.transit.min.js +1 -0
- package/public/scripts/kai-settings.js +179 -0
- package/public/scripts/nai-settings.js +108 -0
- package/public/scripts/openai.js +973 -0
- package/public/scripts/poe.js +360 -0
- package/public/scripts/popper.js +2008 -0
- package/public/scripts/popper.js.map +1 -0
- package/public/scripts/power-user.js +571 -0
- package/public/scripts/purify.min.js +3 -0
- package/public/scripts/purify.min.js.map +1 -0
- package/public/scripts/showdown.min.js +3 -0
- package/public/scripts/showdown.min.js.map +1 -0
- package/public/scripts/swiped-events.js +165 -0
- package/public/scripts/textgen-settings.js +194 -0
- package/public/scripts/toolcool-color-picker.js +87 -0
- package/public/scripts/utils.js +109 -0
- package/public/scripts/world-info.js +661 -0
- package/public/sounds/message.mp3 +0 -0
- package/public/style.css +3633 -0
- package/public/webfonts/NotoSans/NotoSans-Black.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Black.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Bold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Bold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Italic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Italic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Light.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Light.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-LightItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-LightItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Medium.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Medium.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Regular.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Regular.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Thin.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Thin.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/stylesheet.css +162 -0
- package/public/webfonts/fa-solid-900.ttf +0 -0
- package/public/webfonts/fa-solid-900.woff2 +0 -0
- package/readme.md +187 -0
- package/server.js +2593 -0
- package/start.sh +24 -0
- package/tools/charaverter/main.mjs +110 -0
- package/tools/charaverter/package.json +10 -0
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
import {
|
|
2
|
+
shuffle,
|
|
3
|
+
onlyUnique,
|
|
4
|
+
debounce,
|
|
5
|
+
delay,
|
|
6
|
+
} from './utils.js';
|
|
7
|
+
import { humanizedDateTime } from "./RossAscends-mods.js";
|
|
8
|
+
import { sortCharactersList } from './power-user.js';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
chat,
|
|
12
|
+
sendSystemMessage,
|
|
13
|
+
printMessages,
|
|
14
|
+
substituteParams,
|
|
15
|
+
characters,
|
|
16
|
+
default_avatar,
|
|
17
|
+
token,
|
|
18
|
+
addOneMessage,
|
|
19
|
+
callPopup,
|
|
20
|
+
clearChat,
|
|
21
|
+
Generate,
|
|
22
|
+
select_rm_info,
|
|
23
|
+
setCharacterId,
|
|
24
|
+
setCharacterName,
|
|
25
|
+
setEditedMessageId,
|
|
26
|
+
is_send_press,
|
|
27
|
+
name1,
|
|
28
|
+
resetChatState,
|
|
29
|
+
setSendButtonState,
|
|
30
|
+
getCharacters,
|
|
31
|
+
system_message_types,
|
|
32
|
+
online_status,
|
|
33
|
+
talkativeness_default,
|
|
34
|
+
selectRightMenuWithAnimation,
|
|
35
|
+
setRightTabSelectedClass,
|
|
36
|
+
default_ch_mes,
|
|
37
|
+
deleteLastMessage,
|
|
38
|
+
showSwipeButtons,
|
|
39
|
+
hideSwipeButtons,
|
|
40
|
+
chat_metadata,
|
|
41
|
+
updateChatMetadata,
|
|
42
|
+
isStreamingEnabled,
|
|
43
|
+
getThumbnailUrl,
|
|
44
|
+
streamingProcessor,
|
|
45
|
+
} from "../script.js";
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
selected_group,
|
|
49
|
+
is_group_automode_enabled,
|
|
50
|
+
is_group_generating,
|
|
51
|
+
group_generation_id,
|
|
52
|
+
groups,
|
|
53
|
+
saveGroupChat,
|
|
54
|
+
generateGroupWrapper,
|
|
55
|
+
deleteGroup,
|
|
56
|
+
getGroupAvatar,
|
|
57
|
+
getGroups,
|
|
58
|
+
printGroups,
|
|
59
|
+
regenerateGroup,
|
|
60
|
+
resetSelectedGroup,
|
|
61
|
+
select_group_chats,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let is_group_generating = false; // Group generation flag
|
|
65
|
+
let is_group_automode_enabled = false;
|
|
66
|
+
let groups = [];
|
|
67
|
+
let selected_group = null;
|
|
68
|
+
let group_generation_id = null;
|
|
69
|
+
|
|
70
|
+
const group_activation_strategy = {
|
|
71
|
+
NATURAL: 0,
|
|
72
|
+
LIST: 1,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const groupAutoModeInterval = setInterval(groupChatAutoModeWorker, 5000);
|
|
76
|
+
const saveGroupDebounced = debounce(async (group) => await _save(group), 500);
|
|
77
|
+
|
|
78
|
+
async function _save(group) {
|
|
79
|
+
await fetch("/editgroup", {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: {
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
"X-CSRF-Token": token,
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify(group),
|
|
86
|
+
});
|
|
87
|
+
await getCharacters();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
// Group chats
|
|
92
|
+
async function regenerateGroup() {
|
|
93
|
+
let generationId = getLastMessageGenerationId();
|
|
94
|
+
|
|
95
|
+
while (chat.length > 0) {
|
|
96
|
+
const lastMes = chat[chat.length - 1];
|
|
97
|
+
const this_generationId = lastMes.extra?.gen_id;
|
|
98
|
+
|
|
99
|
+
// for new generations after the update
|
|
100
|
+
if ((generationId && this_generationId) && generationId !== this_generationId) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
// legacy for generations before the update
|
|
104
|
+
else if (lastMes.is_user || lastMes.is_system) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
deleteLastMessage();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
generateGroupWrapper();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function getGroupChat(id) {
|
|
115
|
+
const response = await fetch("/getgroupchat", {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
"X-CSRF-Token": token,
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify({ id: id }),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (response.ok) {
|
|
125
|
+
const data = await response.json();
|
|
126
|
+
const group = groups.find((x) => x.id === id);
|
|
127
|
+
if (Array.isArray(data) && data.length) {
|
|
128
|
+
data[0].is_group = true;
|
|
129
|
+
for (let key of data) {
|
|
130
|
+
chat.push(key);
|
|
131
|
+
}
|
|
132
|
+
printMessages();
|
|
133
|
+
} else {
|
|
134
|
+
sendSystemMessage(system_message_types.GROUP);
|
|
135
|
+
if (group && Array.isArray(group.members)) {
|
|
136
|
+
for (let name of group.members) {
|
|
137
|
+
const character = characters.find((x) => x.name === name);
|
|
138
|
+
|
|
139
|
+
if (!character) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const mes = getFirstCharacterMessage(character);
|
|
144
|
+
chat.push(mes);
|
|
145
|
+
addOneMessage(mes);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (group) {
|
|
151
|
+
let metadata = group.chat_metadata ?? {};
|
|
152
|
+
updateChatMetadata(metadata, true);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
await saveGroupChat(id, true);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function getFirstCharacterMessage(character) {
|
|
160
|
+
const mes = {};
|
|
161
|
+
mes["is_user"] = false;
|
|
162
|
+
mes["is_system"] = false;
|
|
163
|
+
mes["name"] = character.name;
|
|
164
|
+
mes["is_name"] = true;
|
|
165
|
+
mes["send_date"] = humanizedDateTime();
|
|
166
|
+
mes["mes"] = character.first_mes
|
|
167
|
+
? substituteParams(character.first_mes.trim(), name1, character.name)
|
|
168
|
+
: default_ch_mes;
|
|
169
|
+
mes["force_avatar"] =
|
|
170
|
+
character.avatar != "none"
|
|
171
|
+
? getThumbnailUrl('avatar', character.avatar)
|
|
172
|
+
: default_avatar;
|
|
173
|
+
return mes;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function resetSelectedGroup() {
|
|
177
|
+
selected_group = null;
|
|
178
|
+
is_group_generating = false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function saveGroupChat(id, shouldSaveGroup) {
|
|
182
|
+
const response = await fetch("/savegroupchat", {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: {
|
|
185
|
+
"Content-Type": "application/json",
|
|
186
|
+
"X-CSRF-Token": token,
|
|
187
|
+
},
|
|
188
|
+
body: JSON.stringify({ id: id, chat: [...chat] }),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if (shouldSaveGroup && response.ok) {
|
|
192
|
+
await editGroup(id);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function getGroups() {
|
|
197
|
+
const response = await fetch("/getgroups", {
|
|
198
|
+
method: "POST",
|
|
199
|
+
headers: {
|
|
200
|
+
"Content-Type": "application/json",
|
|
201
|
+
"X-CSRF-Token": token,
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (response.ok) {
|
|
206
|
+
const data = await response.json();
|
|
207
|
+
groups = data.sort((a, b) => a.id - b.id);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
function printGroups() {
|
|
213
|
+
for (let group of groups) {
|
|
214
|
+
const template = $("#group_list_template .group_select").clone();
|
|
215
|
+
template.data("id", group.id);
|
|
216
|
+
template.attr("grid", group.id);
|
|
217
|
+
template.find(".ch_name").text(group.name);
|
|
218
|
+
$("#rm_print_characters_block").prepend(template);
|
|
219
|
+
updateGroupAvatar(group);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function updateGroupAvatar(group) {
|
|
223
|
+
$("#rm_print_characters_block .group_select").each(function () {
|
|
224
|
+
if ($(this).data("id") == group.id) {
|
|
225
|
+
const avatar = getGroupAvatar(group);
|
|
226
|
+
if (avatar) {
|
|
227
|
+
$(this).find(".avatar").replaceWith(avatar);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function getGroupAvatar(group) {
|
|
234
|
+
const memberAvatars = [];
|
|
235
|
+
if (group && Array.isArray(group.members) && group.members.length) {
|
|
236
|
+
for (const member of group.members) {
|
|
237
|
+
const charIndex = characters.findIndex((x) => x.name === member);
|
|
238
|
+
if (charIndex !== -1 && characters[charIndex].avatar !== "none") {
|
|
239
|
+
const avatar = getThumbnailUrl('avatar', characters[charIndex].avatar);
|
|
240
|
+
memberAvatars.push(avatar);
|
|
241
|
+
}
|
|
242
|
+
if (memberAvatars.length === 4) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Cohee: there's probably a smarter way to do this..
|
|
249
|
+
if (memberAvatars.length === 1) {
|
|
250
|
+
const groupAvatar = $("#group_avatars_template .collage_1").clone();
|
|
251
|
+
groupAvatar.find(".img_1").attr("src", memberAvatars[0]);
|
|
252
|
+
return groupAvatar;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (memberAvatars.length === 2) {
|
|
256
|
+
const groupAvatar = $("#group_avatars_template .collage_2").clone();
|
|
257
|
+
groupAvatar.find(".img_1").attr("src", memberAvatars[0]);
|
|
258
|
+
groupAvatar.find(".img_2").attr("src", memberAvatars[1]);
|
|
259
|
+
return groupAvatar;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (memberAvatars.length === 3) {
|
|
263
|
+
const groupAvatar = $("#group_avatars_template .collage_3").clone();
|
|
264
|
+
groupAvatar.find(".img_1").attr("src", memberAvatars[0]);
|
|
265
|
+
groupAvatar.find(".img_2").attr("src", memberAvatars[1]);
|
|
266
|
+
groupAvatar.find(".img_3").attr("src", memberAvatars[2]);
|
|
267
|
+
return groupAvatar;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (memberAvatars.length === 4) {
|
|
271
|
+
const groupAvatar = $("#group_avatars_template .collage_4").clone();
|
|
272
|
+
groupAvatar.find(".img_1").attr("src", memberAvatars[0]);
|
|
273
|
+
groupAvatar.find(".img_2").attr("src", memberAvatars[1]);
|
|
274
|
+
groupAvatar.find(".img_3").attr("src", memberAvatars[2]);
|
|
275
|
+
groupAvatar.find(".img_4").attr("src", memberAvatars[3]);
|
|
276
|
+
return groupAvatar;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// default avatar
|
|
280
|
+
const groupAvatar = $("#group_avatars_template .collage_1").clone();
|
|
281
|
+
groupAvatar.find(".img_1").attr("src", group.avatar_url);
|
|
282
|
+
return groupAvatar;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
async function generateGroupWrapper(by_auto_mode, type = null) {
|
|
287
|
+
if (online_status === "no_connection") {
|
|
288
|
+
is_group_generating = false;
|
|
289
|
+
setSendButtonState(false);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (is_group_generating) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const group = groups.find((x) => x.id === selected_group);
|
|
298
|
+
|
|
299
|
+
if (!group || !Array.isArray(group.members) || !group.members.length) {
|
|
300
|
+
sendSystemMessage(system_message_types.EMPTY);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
hideSwipeButtons();
|
|
306
|
+
is_group_generating = true;
|
|
307
|
+
setCharacterName('');
|
|
308
|
+
setCharacterId(undefined);
|
|
309
|
+
const userInput = $("#send_textarea").val();
|
|
310
|
+
|
|
311
|
+
let typingIndicator = $("#chat .typing_indicator");
|
|
312
|
+
|
|
313
|
+
if (typingIndicator.length === 0 && !isStreamingEnabled()) {
|
|
314
|
+
typingIndicator = $(
|
|
315
|
+
"#typing_indicator_template .typing_indicator"
|
|
316
|
+
).clone();
|
|
317
|
+
typingIndicator.hide();
|
|
318
|
+
$("#chat").append(typingIndicator);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// id of this specific batch for regeneration purposes
|
|
322
|
+
group_generation_id = Date.now();
|
|
323
|
+
const lastMessage = chat[chat.length - 1];
|
|
324
|
+
let messagesBefore = chat.length;
|
|
325
|
+
let lastMessageText = lastMessage.mes;
|
|
326
|
+
let activationText = "";
|
|
327
|
+
let isUserInput = false;
|
|
328
|
+
|
|
329
|
+
if (userInput && userInput.length && !by_auto_mode) {
|
|
330
|
+
isUserInput = true;
|
|
331
|
+
activationText = userInput;
|
|
332
|
+
messagesBefore++;
|
|
333
|
+
} else {
|
|
334
|
+
if (lastMessage && !lastMessage.is_system) {
|
|
335
|
+
activationText = lastMessage.mes;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const activationStrategy = Number(group.activation_strategy ?? group_activation_strategy.NATURAL);
|
|
340
|
+
let activatedMembers = [];
|
|
341
|
+
|
|
342
|
+
if (type === "swipe") {
|
|
343
|
+
activatedMembers = activateSwipe(group.members);
|
|
344
|
+
|
|
345
|
+
if (activatedMembers.length === 0) {
|
|
346
|
+
callPopup('<h3>Deleted group member swiped. To get a reply, add them back to the group.</h3>', 'text');
|
|
347
|
+
throw new Error('Deleted group member swiped');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else if (type === "impersonate") {
|
|
351
|
+
$("#send_textarea").attr("disabled", true);
|
|
352
|
+
activatedMembers = activateImpersonate(group.members);
|
|
353
|
+
}
|
|
354
|
+
else if (activationStrategy === group_activation_strategy.NATURAL) {
|
|
355
|
+
activatedMembers = activateNaturalOrder(group.members, activationText, lastMessage, group.allow_self_responses, isUserInput);
|
|
356
|
+
}
|
|
357
|
+
else if (activationStrategy === group_activation_strategy.LIST) {
|
|
358
|
+
activatedMembers = activateListOrder(group.members);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// now the real generation begins: cycle through every character
|
|
362
|
+
for (const chId of activatedMembers) {
|
|
363
|
+
const generateType = type == "swipe" || type == "impersonate" ? type : "group_chat";
|
|
364
|
+
setCharacterId(chId);
|
|
365
|
+
setCharacterName(characters[chId].name)
|
|
366
|
+
|
|
367
|
+
await Generate(generateType, by_auto_mode);
|
|
368
|
+
|
|
369
|
+
if (type !== "swipe" && type !== "impersonate") {
|
|
370
|
+
// update indicator and scroll down
|
|
371
|
+
typingIndicator
|
|
372
|
+
.find(".typing_indicator_name")
|
|
373
|
+
.text(characters[chId].name);
|
|
374
|
+
$("#chat").append(typingIndicator);
|
|
375
|
+
typingIndicator.show(250, function () {
|
|
376
|
+
typingIndicator.get(0).scrollIntoView({ behavior: "smooth" });
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
while (true) {
|
|
381
|
+
// if not swipe - check if message generated already
|
|
382
|
+
if (type !== "swipe" && chat.length == messagesBefore) {
|
|
383
|
+
await delay(100);
|
|
384
|
+
}
|
|
385
|
+
// if swipe - see if message changed
|
|
386
|
+
else if (type === "swipe") {
|
|
387
|
+
if (isStreamingEnabled()) {
|
|
388
|
+
if (streamingProcessor && !streamingProcessor.isFinished) {
|
|
389
|
+
await delay(100);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
if (lastMessageText === chat[chat.length - 1].mes) {
|
|
397
|
+
await delay(100);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else if (type === "impersonate") {
|
|
405
|
+
if (isStreamingEnabled()) {
|
|
406
|
+
if (streamingProcessor && !streamingProcessor.isFinished) {
|
|
407
|
+
await delay(100);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
if (!$("#send_textarea").val() || $("#send_textarea").val() == userInput) {
|
|
415
|
+
await delay(100);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
messagesBefore++;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// hide and reapply the indicator to the bottom of the list
|
|
429
|
+
typingIndicator.hide(250);
|
|
430
|
+
$("#chat").append(typingIndicator);
|
|
431
|
+
}
|
|
432
|
+
} finally {
|
|
433
|
+
is_group_generating = false;
|
|
434
|
+
$("#send_textarea").attr("disabled", false);
|
|
435
|
+
setSendButtonState(false);
|
|
436
|
+
setCharacterId(undefined);
|
|
437
|
+
setCharacterName('');
|
|
438
|
+
showSwipeButtons();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function getLastMessageGenerationId() {
|
|
443
|
+
let generationId = null;
|
|
444
|
+
if (chat.length > 0) {
|
|
445
|
+
const lastMes = chat[chat.length - 1];
|
|
446
|
+
if (!lastMes.is_user && !lastMes.is_system && lastMes.extra) {
|
|
447
|
+
generationId = lastMes.extra.gen_id;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return generationId;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function activateImpersonate(members) {
|
|
454
|
+
const randomIndex = Math.floor(Math.random() * members.length);
|
|
455
|
+
const activatedNames = [members[randomIndex]];
|
|
456
|
+
const memberIds = activatedNames
|
|
457
|
+
.map((x) => characters.findIndex((y) => y.name === x))
|
|
458
|
+
.filter((x) => x !== -1);
|
|
459
|
+
return memberIds;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function activateSwipe(members) {
|
|
463
|
+
const name = chat[chat.length - 1].name;
|
|
464
|
+
const activatedNames = members.includes(name) ? [name] : [];
|
|
465
|
+
const memberIds = activatedNames
|
|
466
|
+
.map((x) => characters.findIndex((y) => y.name === x))
|
|
467
|
+
.filter((x) => x !== -1);
|
|
468
|
+
return memberIds;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function activateListOrder(members) {
|
|
472
|
+
let activatedNames = members.filter(onlyUnique);
|
|
473
|
+
|
|
474
|
+
// map to character ids
|
|
475
|
+
const memberIds = activatedNames
|
|
476
|
+
.map((x) => characters.findIndex((y) => y.name === x))
|
|
477
|
+
.filter((x) => x !== -1);
|
|
478
|
+
return memberIds;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function activateNaturalOrder(members, input, lastMessage, allowSelfResponses, isUserInput) {
|
|
482
|
+
let activatedNames = [];
|
|
483
|
+
|
|
484
|
+
// prevents the same character from speaking twice
|
|
485
|
+
let bannedUser = !isUserInput && lastMessage && !lastMessage.is_user && lastMessage.name;
|
|
486
|
+
|
|
487
|
+
// ...unless allowed to do so
|
|
488
|
+
if (allowSelfResponses) {
|
|
489
|
+
bannedUser = undefined;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// find mentions (excluding self)
|
|
493
|
+
if (input && input.length) {
|
|
494
|
+
for (let inputWord of extractAllWords(input)) {
|
|
495
|
+
for (let member of members) {
|
|
496
|
+
if (member === bannedUser) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (extractAllWords(member).includes(inputWord)) {
|
|
501
|
+
activatedNames.push(member);
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// activation by talkativeness (in shuffled order, except banned)
|
|
509
|
+
const shuffledMembers = shuffle([...members]);
|
|
510
|
+
for (let member of shuffledMembers) {
|
|
511
|
+
if (member === bannedUser) {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const character = characters.find((x) => x.name === member);
|
|
516
|
+
|
|
517
|
+
if (!character) {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const rollValue = Math.random();
|
|
522
|
+
let talkativeness = Number(character.talkativeness);
|
|
523
|
+
talkativeness = Number.isNaN(talkativeness)
|
|
524
|
+
? talkativeness_default
|
|
525
|
+
: talkativeness;
|
|
526
|
+
if (talkativeness >= rollValue) {
|
|
527
|
+
activatedNames.push(member);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// pick 1 at random if no one was activated
|
|
532
|
+
if (activatedNames.length === 0) {
|
|
533
|
+
const randomIndex = Math.floor(Math.random() * members.length);
|
|
534
|
+
activatedNames.push(members[randomIndex]);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// de-duplicate array of names
|
|
538
|
+
activatedNames = activatedNames.filter(onlyUnique);
|
|
539
|
+
|
|
540
|
+
// map to character ids
|
|
541
|
+
const memberIds = activatedNames
|
|
542
|
+
.map((x) => characters.findIndex((y) => y.name === x))
|
|
543
|
+
.filter((x) => x !== -1);
|
|
544
|
+
return memberIds;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function extractAllWords(value) {
|
|
548
|
+
const words = [];
|
|
549
|
+
|
|
550
|
+
if (!value) {
|
|
551
|
+
return words;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const matches = value.matchAll(/\b\w+\b/gim);
|
|
555
|
+
for (let match of matches) {
|
|
556
|
+
words.push(match[0].toLowerCase());
|
|
557
|
+
}
|
|
558
|
+
return words;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
async function deleteGroup(id) {
|
|
563
|
+
const response = await fetch("/deletegroup", {
|
|
564
|
+
method: "POST",
|
|
565
|
+
headers: {
|
|
566
|
+
"Content-Type": "application/json",
|
|
567
|
+
"X-CSRF-Token": token,
|
|
568
|
+
},
|
|
569
|
+
body: JSON.stringify({ id: id }),
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
if (response.ok) {
|
|
573
|
+
selected_group = null;
|
|
574
|
+
resetChatState();
|
|
575
|
+
clearChat();
|
|
576
|
+
printMessages();
|
|
577
|
+
await getCharacters();
|
|
578
|
+
|
|
579
|
+
$("#rm_info_avatar").html("");
|
|
580
|
+
$("#rm_info_block").transition({ opacity: 0, duration: 0 });
|
|
581
|
+
select_rm_info("Group deleted!");
|
|
582
|
+
$("#rm_info_block").transition({ opacity: 1.0, duration: 2000 });
|
|
583
|
+
|
|
584
|
+
$("#rm_button_selected_ch").children("h2").text('');
|
|
585
|
+
setRightTabSelectedClass();
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
async function editGroup(id, immediately) {
|
|
590
|
+
let group = groups.find((x) => x.id == id);
|
|
591
|
+
group = { ...group, chat_metadata };
|
|
592
|
+
|
|
593
|
+
if (!group) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (immediately) {
|
|
598
|
+
return await _save(group);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
saveGroupDebounced(group);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
async function groupChatAutoModeWorker() {
|
|
605
|
+
if (!is_group_automode_enabled || online_status === "no_connection") {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (!selected_group || is_send_press || is_group_generating) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const group = groups.find((x) => x.id === selected_group);
|
|
614
|
+
|
|
615
|
+
if (!group || !Array.isArray(group.members) || !group.members.length) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
await generateGroupWrapper(true);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
async function modifyGroupMember(chat_id, groupMember, isDelete) {
|
|
623
|
+
const id = groupMember.data("id");
|
|
624
|
+
|
|
625
|
+
const template = groupMember.clone();
|
|
626
|
+
let _thisGroup = groups.find((x) => x.id == chat_id);
|
|
627
|
+
template.data("id", id);
|
|
628
|
+
|
|
629
|
+
if (isDelete) {
|
|
630
|
+
$("#rm_group_add_members").prepend(template);
|
|
631
|
+
} else {
|
|
632
|
+
$("#rm_group_members").prepend(template);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (_thisGroup) {
|
|
636
|
+
if (isDelete) {
|
|
637
|
+
const index = _thisGroup.members.findIndex((x) => x === id);
|
|
638
|
+
if (index !== -1) {
|
|
639
|
+
_thisGroup.members.splice(index, 1);
|
|
640
|
+
}
|
|
641
|
+
} else {
|
|
642
|
+
_thisGroup.members.push(id);
|
|
643
|
+
template.css({ 'order': _thisGroup.members.length });
|
|
644
|
+
}
|
|
645
|
+
await editGroup(selected_group);
|
|
646
|
+
updateGroupAvatar(_thisGroup);
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
template.css({ 'order': 'unset' });
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
groupMember.remove();
|
|
653
|
+
const groupHasMembers = !!$("#rm_group_members").children().length;
|
|
654
|
+
$("#rm_group_submit").prop("disabled", !groupHasMembers);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
async function reorderGroupMember(chat_id, groupMember, direction) {
|
|
658
|
+
const id = groupMember.data("id");
|
|
659
|
+
const group = groups.find((x) => x.id == chat_id);
|
|
660
|
+
|
|
661
|
+
// Existing groups need to modify members list
|
|
662
|
+
if (group && group.members.length > 1) {
|
|
663
|
+
const indexOf = group.members.indexOf(id);
|
|
664
|
+
if (direction == 'down') {
|
|
665
|
+
const next = group.members[indexOf + 1];
|
|
666
|
+
if (next) {
|
|
667
|
+
group.members[indexOf + 1] = group.members[indexOf];
|
|
668
|
+
group.members[indexOf] = next;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (direction == 'up') {
|
|
672
|
+
const prev = group.members[indexOf - 1];
|
|
673
|
+
if (prev) {
|
|
674
|
+
group.members[indexOf - 1] = group.members[indexOf];
|
|
675
|
+
group.members[indexOf] = prev;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
await editGroup(chat_id);
|
|
680
|
+
updateGroupAvatar(group);
|
|
681
|
+
// stupid but lifts the manual reordering
|
|
682
|
+
select_group_chats(chat_id, true);
|
|
683
|
+
}
|
|
684
|
+
// New groups just can't be DOM-ordered
|
|
685
|
+
else {
|
|
686
|
+
if (direction == 'down') {
|
|
687
|
+
groupMember.insertAfter(groupMember.next());
|
|
688
|
+
}
|
|
689
|
+
if (direction == 'up') {
|
|
690
|
+
groupMember.insertBefore(groupMember.prev());
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function select_group_chats(chat_id, skipAnimation) {
|
|
696
|
+
const group = chat_id && groups.find((x) => x.id == chat_id);
|
|
697
|
+
const groupName = group?.name ?? "";
|
|
698
|
+
|
|
699
|
+
$("#rm_group_chat_name").val(groupName);
|
|
700
|
+
$("#rm_group_chat_name").off();
|
|
701
|
+
$("#rm_group_chat_name").on("input", async function () {
|
|
702
|
+
if (chat_id) {
|
|
703
|
+
let _thisGroup = groups.find((x) => x.id == chat_id);
|
|
704
|
+
_thisGroup.name = $(this).val();
|
|
705
|
+
$("#rm_button_selected_ch").children("h2").text(_thisGroup.name);
|
|
706
|
+
await editGroup(chat_id);
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
$("#rm_group_filter").val("").trigger("input");
|
|
710
|
+
|
|
711
|
+
$('input[name="rm_group_activation_strategy"]').off();
|
|
712
|
+
$('input[name="rm_group_activation_strategy"]').on("input", async function (e) {
|
|
713
|
+
if (chat_id) {
|
|
714
|
+
let _thisGroup = groups.find((x) => x.id == chat_id);
|
|
715
|
+
_thisGroup.activation_strategy = Number(e.target.value);
|
|
716
|
+
await editGroup(chat_id);
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
$(`input[name="rm_group_activation_strategy"][value="${Number(group?.activation_strategy ?? group_activation_strategy.NATURAL)}"]`).prop('checked', true);
|
|
720
|
+
|
|
721
|
+
if (!skipAnimation) {
|
|
722
|
+
selectRightMenuWithAnimation('rm_group_chats_block');
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// render characters list
|
|
726
|
+
$("#rm_group_add_members").empty();
|
|
727
|
+
$("#rm_group_members").empty();
|
|
728
|
+
for (let character of characters) {
|
|
729
|
+
const avatar =
|
|
730
|
+
character.avatar != "none"
|
|
731
|
+
? getThumbnailUrl('avatar', character.avatar)
|
|
732
|
+
: default_avatar;
|
|
733
|
+
const template = $("#group_member_template .group_member").clone();
|
|
734
|
+
template.data("id", character.name);
|
|
735
|
+
template.find(".avatar img").attr("src", avatar);
|
|
736
|
+
template.find(".ch_name").text(character.name);
|
|
737
|
+
template.attr("chid", characters.indexOf(character));
|
|
738
|
+
|
|
739
|
+
if (
|
|
740
|
+
group &&
|
|
741
|
+
Array.isArray(group.members) &&
|
|
742
|
+
group.members.includes(character.name)
|
|
743
|
+
) {
|
|
744
|
+
template.css({ 'order': group.members.indexOf(character.name) });
|
|
745
|
+
$("#rm_group_members").append(template);
|
|
746
|
+
} else {
|
|
747
|
+
$("#rm_group_add_members").append(template);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
sortCharactersList("#rm_group_add_members .group_member");
|
|
752
|
+
|
|
753
|
+
const groupHasMembers = !!$("#rm_group_members").children().length;
|
|
754
|
+
$("#rm_group_submit").prop("disabled", !groupHasMembers);
|
|
755
|
+
$("#rm_group_allow_self_responses").prop("checked", group && group.allow_self_responses);
|
|
756
|
+
|
|
757
|
+
// bottom buttons
|
|
758
|
+
if (chat_id) {
|
|
759
|
+
$("#rm_group_submit").hide();
|
|
760
|
+
$("#rm_group_delete").show();
|
|
761
|
+
} else {
|
|
762
|
+
$("#rm_group_submit").show();
|
|
763
|
+
$("#rm_group_delete").hide();
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
$("#rm_group_delete").off();
|
|
767
|
+
$("#rm_group_delete").on("click", function () {
|
|
768
|
+
if (is_group_generating) {
|
|
769
|
+
callPopup('<h3>Not so fast! Wait for the characters to stop typing before deleting the group.</h3>', 'text');
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
$("#dialogue_popup").data("group_id", chat_id);
|
|
774
|
+
callPopup("<h3>Delete the group?</h3>", "del_group");
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
$("#rm_group_allow_self_responses").off();
|
|
778
|
+
$("#rm_group_allow_self_responses").on("input", async function () {
|
|
779
|
+
if (group) {
|
|
780
|
+
const value = $(this).prop("checked");
|
|
781
|
+
group.allow_self_responses = value;
|
|
782
|
+
await editGroup(chat_id);
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// top bar
|
|
787
|
+
if (group) {
|
|
788
|
+
$("#rm_group_automode_label").show();
|
|
789
|
+
$("#rm_button_selected_ch").children("h2").text(groupName);
|
|
790
|
+
setRightTabSelectedClass('rm_button_selected_ch');
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
$("#rm_group_automode_label").hide();
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
$(document).off("click", ".group_member .right_menu_button");
|
|
797
|
+
$(document).on("click", ".group_member .right_menu_button", async function (event) {
|
|
798
|
+
event.stopPropagation();
|
|
799
|
+
const action = $(this).data('action');
|
|
800
|
+
const member = $(this).closest('.group_member');
|
|
801
|
+
|
|
802
|
+
if (action == 'remove') {
|
|
803
|
+
await modifyGroupMember(chat_id, member, true);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
if (action == 'add') {
|
|
807
|
+
await modifyGroupMember(chat_id, member, false);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
if (action == 'up' || action == 'down') {
|
|
811
|
+
await reorderGroupMember(chat_id, member, action);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
sortCharactersList("#rm_group_add_members .group_member");
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
$(document).ready(() => {
|
|
819
|
+
$(document).on("click", ".group_select", async function () {
|
|
820
|
+
const id = $(this).data("id");
|
|
821
|
+
|
|
822
|
+
if (!is_send_press && !is_group_generating) {
|
|
823
|
+
if (selected_group !== id) {
|
|
824
|
+
selected_group = id;
|
|
825
|
+
setCharacterId(undefined);
|
|
826
|
+
setCharacterName('');
|
|
827
|
+
setEditedMessageId(undefined);
|
|
828
|
+
clearChat();
|
|
829
|
+
updateChatMetadata({}, true);
|
|
830
|
+
chat.length = 0;
|
|
831
|
+
await getGroupChat(id);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
select_group_chats(id);
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
$("#rm_group_filter").on("input", function () {
|
|
839
|
+
const searchValue = $(this).val().trim().toLowerCase();
|
|
840
|
+
|
|
841
|
+
if (!searchValue) {
|
|
842
|
+
$("#rm_group_add_members .group_member").show();
|
|
843
|
+
} else {
|
|
844
|
+
$("#rm_group_add_members .group_member").each(function () {
|
|
845
|
+
$(this).children(".ch_name").text().toLowerCase().includes(searchValue)
|
|
846
|
+
? $(this).show()
|
|
847
|
+
: $(this).hide();
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
$("#rm_group_submit").click(async function () {
|
|
853
|
+
let name = $("#rm_group_chat_name").val();
|
|
854
|
+
let allow_self_responses = !!$("#rm_group_allow_self_responses").prop("checked");
|
|
855
|
+
let activation_strategy = $('input[name="rm_group_activation_strategy"]:checked').val() ?? group_activation_strategy.NATURAL;
|
|
856
|
+
const members = $("#rm_group_members .group_member")
|
|
857
|
+
.map((_, x) => $(x).data("id"))
|
|
858
|
+
.toArray();
|
|
859
|
+
|
|
860
|
+
if (!name) {
|
|
861
|
+
name = `Chat with ${members.join(", ")}`;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// placeholder
|
|
865
|
+
const avatar_url = 'img/five.png';
|
|
866
|
+
|
|
867
|
+
const createGroupResponse = await fetch("/creategroup", {
|
|
868
|
+
method: "POST",
|
|
869
|
+
headers: {
|
|
870
|
+
"Content-Type": "application/json",
|
|
871
|
+
"X-CSRF-Token": token,
|
|
872
|
+
},
|
|
873
|
+
body: JSON.stringify({
|
|
874
|
+
name: name,
|
|
875
|
+
members: members,
|
|
876
|
+
avatar_url: avatar_url,
|
|
877
|
+
allow_self_responses: allow_self_responses,
|
|
878
|
+
activation_strategy: activation_strategy,
|
|
879
|
+
chat_metadata: {},
|
|
880
|
+
}),
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
if (createGroupResponse.ok) {
|
|
884
|
+
await getCharacters();
|
|
885
|
+
$("#rm_info_avatar").html("");
|
|
886
|
+
const avatar = $("#avatar_div_div").clone();
|
|
887
|
+
avatar.find("img").attr("src", avatar_url);
|
|
888
|
+
$("#rm_info_avatar").append(avatar);
|
|
889
|
+
$("#rm_info_block").transition({ opacity: 0, duration: 0 });
|
|
890
|
+
select_rm_info("Group chat created");
|
|
891
|
+
$("#rm_info_block").transition({ opacity: 1.0, duration: 2000 });
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
$("#rm_group_automode").on("input", function () {
|
|
896
|
+
const value = $(this).prop("checked");
|
|
897
|
+
is_group_automode_enabled = value;
|
|
898
|
+
});
|
|
899
|
+
});
|