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.
Files changed (259) hide show
  1. package/.dockerignore +4 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. package/.github/workflows/npm-publish.yml +32 -0
  5. package/Dockerfile +49 -0
  6. package/Start.bat +3 -0
  7. package/colab/GPU.ipynb +339 -0
  8. package/colab/extras_server.py +40 -0
  9. package/colab/globals.py +2 -0
  10. package/colab/models.py +77 -0
  11. package/docker/docker-compose.yml +12 -0
  12. package/docker/docker-entrypoint.sh +28 -0
  13. package/faq.md +208 -0
  14. package/package.json +49 -0
  15. package/poe-client.js +638 -0
  16. package/poe-test.js +21 -0
  17. package/poe_graphql/AddHumanMessageMutation.graphql +52 -0
  18. package/poe_graphql/AddMessageBreakMutation.graphql +17 -0
  19. package/poe_graphql/AutoSubscriptionMutation.graphql +7 -0
  20. package/poe_graphql/BioFragment.graphql +8 -0
  21. package/poe_graphql/ChatAddedSubscription.graphql +5 -0
  22. package/poe_graphql/ChatFragment.graphql +6 -0
  23. package/poe_graphql/ChatListPaginationQuery.graphql +316 -0
  24. package/poe_graphql/ChatPaginationQuery.graphql +26 -0
  25. package/poe_graphql/ChatViewQuery.graphql +8 -0
  26. package/poe_graphql/DeleteHumanMessagesMutation.graphql +7 -0
  27. package/poe_graphql/DeleteMessageMutation.graphql +7 -0
  28. package/poe_graphql/HandleFragment.graphql +8 -0
  29. package/poe_graphql/LoginWithVerificationCodeMutation.graphql +13 -0
  30. package/poe_graphql/MessageAddedSubscription.graphql +115 -0
  31. package/poe_graphql/MessageDeletedSubscription.graphql +8 -0
  32. package/poe_graphql/MessageFragment.graphql +13 -0
  33. package/poe_graphql/MessageRemoveVoteMutation.graphql +7 -0
  34. package/poe_graphql/MessageSetVoteMutation.graphql +7 -0
  35. package/poe_graphql/SendVerificationCodeForLoginMutation.graphql +12 -0
  36. package/poe_graphql/ShareMessagesMutation.graphql +9 -0
  37. package/poe_graphql/SignupWithVerificationCodeMutation.graphql +13 -0
  38. package/poe_graphql/StaleChatUpdateMutation.graphql +7 -0
  39. package/poe_graphql/SubscriptionsMutation.graphql +9 -0
  40. package/poe_graphql/SummarizePlainPostQuery.graphql +3 -0
  41. package/poe_graphql/SummarizeQuotePostQuery.graphql +3 -0
  42. package/poe_graphql/SummarizeSharePostQuery.graphql +3 -0
  43. package/poe_graphql/UserSnippetFragment.graphql +14 -0
  44. package/poe_graphql/ViewerInfoQuery.graphql +21 -0
  45. package/poe_graphql/ViewerMessageLimitUpdatedSubscription.graphql +81 -0
  46. package/poe_graphql/ViewerStateFragment.graphql +30 -0
  47. package/poe_graphql/ViewerStateUpdatedSubscription.graphql +63 -0
  48. package/public/KoboldAI Settings/Ace of Spades 13B.settings +22 -0
  49. package/public/KoboldAI Settings/Adventurer-NeoX-20B-Erebus.settings +54 -0
  50. package/public/KoboldAI Settings/Basic Coherence 13B.settings +22 -0
  51. package/public/KoboldAI Settings/Best Guess 6B.settings +22 -0
  52. package/public/KoboldAI Settings/Calibrated-Pygmalion-6b.settings +47 -0
  53. package/public/KoboldAI Settings/Classic-Pygmalion-2.7b.settings +46 -0
  54. package/public/KoboldAI Settings/Classic-Pygmalion-6b.settings +47 -0
  55. package/public/KoboldAI Settings/Coherent Creativity 6B.settings +22 -0
  56. package/public/KoboldAI Settings/Default-TavernAI.settings +22 -0
  57. package/public/KoboldAI Settings/DragonSlayer-Pygmalion-6b.settings +47 -0
  58. package/public/KoboldAI Settings/GPU-Pygmalion-6b.settings +47 -0
  59. package/public/KoboldAI Settings/Genesis 13B.settings +22 -0
  60. package/public/KoboldAI Settings/Godlike.settings +22 -0
  61. package/public/KoboldAI Settings/Good Winds.settings +22 -0
  62. package/public/KoboldAI Settings/Lancer-OPT-2.7B-Erebus.settings +54 -0
  63. package/public/KoboldAI Settings/Liminal Drift.settings +22 -0
  64. package/public/KoboldAI Settings/Low Rider 13B.settings +22 -0
  65. package/public/KoboldAI Settings/Luna Moth 6B.settings +22 -0
  66. package/public/KoboldAI Settings/Mayday.settings +22 -0
  67. package/public/KoboldAI Settings/Ouroboros.settings +22 -0
  68. package/public/KoboldAI Settings/Pleasing Results 6B.settings +22 -0
  69. package/public/KoboldAI Settings/Pro Writer 13B.settings +22 -0
  70. package/public/KoboldAI Settings/RA - Pygmalion-1.3b.settings +46 -0
  71. package/public/KoboldAI Settings/Storywriter 6B.settings +22 -0
  72. package/public/NovelAI Settings/Classic-Euterpe.settings +14 -0
  73. package/public/NovelAI Settings/Classic-Krake.settings +14 -0
  74. package/public/OpenAI Settings/Default.settings +15 -0
  75. package/public/TextGen Settings/Beam Search.settings +15 -0
  76. package/public/TextGen Settings/Contrastive Search.settings +15 -0
  77. package/public/TextGen Settings/Default.settings +15 -0
  78. package/public/TextGen Settings/Deterministic.settings +15 -0
  79. package/public/TextGen Settings/Kobold (Godlike).settings +15 -0
  80. package/public/TextGen Settings/Kobold (Liminal Drift).settings +15 -0
  81. package/public/TextGen Settings/Naive.settings +15 -0
  82. package/public/TextGen Settings/NovelAI (Best Guess).settings +15 -0
  83. package/public/TextGen Settings/NovelAI (Decadence).settings +15 -0
  84. package/public/TextGen Settings/NovelAI (Genesis).settings +15 -0
  85. package/public/TextGen Settings/NovelAI (Lycaenidae).settings +15 -0
  86. package/public/TextGen Settings/NovelAI (Ouroboros).settings +15 -0
  87. package/public/TextGen Settings/NovelAI (Pleasing Results).settings +15 -0
  88. package/public/TextGen Settings/NovelAI (Sphinx Moth).settings +15 -0
  89. package/public/TextGen Settings/NovelAI (Storywriter).settings +15 -0
  90. package/public/TextGen Settings/Pygmalion.settings +15 -0
  91. package/public/css/fontawesome.css +8488 -0
  92. package/public/css/notes.css +46 -0
  93. package/public/css/solid.css +24 -0
  94. package/public/favicon.ico +0 -0
  95. package/public/img/No-Image-Placeholder.svg +309 -0
  96. package/public/img/addbg3.png +0 -0
  97. package/public/img/ai4.png +0 -0
  98. package/public/img/apple-icon-114x114.png +0 -0
  99. package/public/img/apple-icon-144x144.png +0 -0
  100. package/public/img/apple-icon-57x57.png +0 -0
  101. package/public/img/apple-icon-72x72.png +0 -0
  102. package/public/img/book2.png +0 -0
  103. package/public/img/default-expressions/admiration.png +0 -0
  104. package/public/img/default-expressions/amusement.png +0 -0
  105. package/public/img/default-expressions/anger.png +0 -0
  106. package/public/img/default-expressions/annoyance.png +0 -0
  107. package/public/img/default-expressions/approval.png +0 -0
  108. package/public/img/default-expressions/caring.png +0 -0
  109. package/public/img/default-expressions/confusion.png +0 -0
  110. package/public/img/default-expressions/curiosity.png +0 -0
  111. package/public/img/default-expressions/desire.png +0 -0
  112. package/public/img/default-expressions/desire1.png +0 -0
  113. package/public/img/default-expressions/desire2.png +0 -0
  114. package/public/img/default-expressions/disappointment.png +0 -0
  115. package/public/img/default-expressions/disapproval.png +0 -0
  116. package/public/img/default-expressions/disgust.png +0 -0
  117. package/public/img/default-expressions/embarrassment.png +0 -0
  118. package/public/img/default-expressions/excitement.png +0 -0
  119. package/public/img/default-expressions/fear.png +0 -0
  120. package/public/img/default-expressions/gratitude.png +0 -0
  121. package/public/img/default-expressions/grief.png +0 -0
  122. package/public/img/default-expressions/joy.png +0 -0
  123. package/public/img/default-expressions/love.png +0 -0
  124. package/public/img/default-expressions/nervousness.png +0 -0
  125. package/public/img/default-expressions/neutral.png +0 -0
  126. package/public/img/default-expressions/optimism.png +0 -0
  127. package/public/img/default-expressions/pride.png +0 -0
  128. package/public/img/default-expressions/realization.png +0 -0
  129. package/public/img/default-expressions/relief.png +0 -0
  130. package/public/img/default-expressions/remorse.png +0 -0
  131. package/public/img/default-expressions/sadness.png +0 -0
  132. package/public/img/default-expressions/surprise.png +0 -0
  133. package/public/img/five.png +0 -0
  134. package/public/img/times-circle.svg +1 -0
  135. package/public/img/you.png +0 -0
  136. package/public/index.html +1899 -0
  137. package/public/notes/1.html +44 -0
  138. package/public/notes/1.png +0 -0
  139. package/public/notes/10.html +20 -0
  140. package/public/notes/11.html +33 -0
  141. package/public/notes/12.html +27 -0
  142. package/public/notes/13.html +29 -0
  143. package/public/notes/13_1.html +24 -0
  144. package/public/notes/13_2.html +25 -0
  145. package/public/notes/13_3.html +89 -0
  146. package/public/notes/14.html +30 -0
  147. package/public/notes/2.html +37 -0
  148. package/public/notes/2.png +0 -0
  149. package/public/notes/3.html +37 -0
  150. package/public/notes/4.html +105 -0
  151. package/public/notes/6.html +33 -0
  152. package/public/notes/7.html +40 -0
  153. package/public/notes/8.html +19 -0
  154. package/public/notes/9.html +46 -0
  155. package/public/notes/advanced_formatting.html +91 -0
  156. package/public/notes/group_reply_strategy.html +63 -0
  157. package/public/notes/message_sound.html +33 -0
  158. package/public/notes/multigen.html +36 -0
  159. package/public/notes/oai_api_key.html +37 -0
  160. package/public/notes/textgen_streaming.html +29 -0
  161. package/public/notes/token-limits.html +68 -0
  162. package/public/script.js +5131 -0
  163. package/public/scripts/RossAscends-mods.js +750 -0
  164. package/public/scripts/bookmarks.js +130 -0
  165. package/public/scripts/extensions/backgrounds/index.js +129 -0
  166. package/public/scripts/extensions/backgrounds/manifest.json +11 -0
  167. package/public/scripts/extensions/backgrounds/style.css +45 -0
  168. package/public/scripts/extensions/caption/index.js +117 -0
  169. package/public/scripts/extensions/caption/manifest.json +13 -0
  170. package/public/scripts/extensions/caption/style.css +23 -0
  171. package/public/scripts/extensions/dice/droll.js +108 -0
  172. package/public/scripts/extensions/dice/index.js +96 -0
  173. package/public/scripts/extensions/dice/manifest.json +11 -0
  174. package/public/scripts/extensions/dice/style.css +26 -0
  175. package/public/scripts/extensions/expressions/index.js +387 -0
  176. package/public/scripts/extensions/expressions/manifest.json +13 -0
  177. package/public/scripts/extensions/expressions/style.css +115 -0
  178. package/public/scripts/extensions/floating-prompt/index.js +151 -0
  179. package/public/scripts/extensions/floating-prompt/manifest.json +11 -0
  180. package/public/scripts/extensions/floating-prompt/style.css +19 -0
  181. package/public/scripts/extensions/memory/index.js +358 -0
  182. package/public/scripts/extensions/memory/manifest.json +13 -0
  183. package/public/scripts/extensions/memory/style.css +34 -0
  184. package/public/scripts/extensions.js +288 -0
  185. package/public/scripts/f-localStorage.js +27 -0
  186. package/public/scripts/gpt-2-3-tokenizer/README.md +28 -0
  187. package/public/scripts/gpt-2-3-tokenizer/encoder.js +1 -0
  188. package/public/scripts/gpt-2-3-tokenizer/mod.js +169 -0
  189. package/public/scripts/gpt-2-3-tokenizer/vocab.bpe.js +1 -0
  190. package/public/scripts/gpt-3-tokenizer/array-keyed-map.js +210 -0
  191. package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js +271 -0
  192. package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js.map +1 -0
  193. package/public/scripts/group-chats.js +899 -0
  194. package/public/scripts/horde.js +214 -0
  195. package/public/scripts/jquery-3.5.1.min.js +2 -0
  196. package/public/scripts/jquery-cookie-1.4.1.min.js +2 -0
  197. package/public/scripts/jquery.transit.min.js +1 -0
  198. package/public/scripts/kai-settings.js +179 -0
  199. package/public/scripts/nai-settings.js +108 -0
  200. package/public/scripts/openai.js +973 -0
  201. package/public/scripts/poe.js +360 -0
  202. package/public/scripts/popper.js +2008 -0
  203. package/public/scripts/popper.js.map +1 -0
  204. package/public/scripts/power-user.js +571 -0
  205. package/public/scripts/purify.min.js +3 -0
  206. package/public/scripts/purify.min.js.map +1 -0
  207. package/public/scripts/showdown.min.js +3 -0
  208. package/public/scripts/showdown.min.js.map +1 -0
  209. package/public/scripts/swiped-events.js +165 -0
  210. package/public/scripts/textgen-settings.js +194 -0
  211. package/public/scripts/toolcool-color-picker.js +87 -0
  212. package/public/scripts/utils.js +109 -0
  213. package/public/scripts/world-info.js +661 -0
  214. package/public/sounds/message.mp3 +0 -0
  215. package/public/style.css +3633 -0
  216. package/public/webfonts/NotoSans/NotoSans-Black.woff +0 -0
  217. package/public/webfonts/NotoSans/NotoSans-Black.woff2 +0 -0
  218. package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff +0 -0
  219. package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff2 +0 -0
  220. package/public/webfonts/NotoSans/NotoSans-Bold.woff +0 -0
  221. package/public/webfonts/NotoSans/NotoSans-Bold.woff2 +0 -0
  222. package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff +0 -0
  223. package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff2 +0 -0
  224. package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff +0 -0
  225. package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff2 +0 -0
  226. package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff +0 -0
  227. package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff2 +0 -0
  228. package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff +0 -0
  229. package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff2 +0 -0
  230. package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff +0 -0
  231. package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff2 +0 -0
  232. package/public/webfonts/NotoSans/NotoSans-Italic.woff +0 -0
  233. package/public/webfonts/NotoSans/NotoSans-Italic.woff2 +0 -0
  234. package/public/webfonts/NotoSans/NotoSans-Light.woff +0 -0
  235. package/public/webfonts/NotoSans/NotoSans-Light.woff2 +0 -0
  236. package/public/webfonts/NotoSans/NotoSans-LightItalic.woff +0 -0
  237. package/public/webfonts/NotoSans/NotoSans-LightItalic.woff2 +0 -0
  238. package/public/webfonts/NotoSans/NotoSans-Medium.woff +0 -0
  239. package/public/webfonts/NotoSans/NotoSans-Medium.woff2 +0 -0
  240. package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff +0 -0
  241. package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff2 +0 -0
  242. package/public/webfonts/NotoSans/NotoSans-Regular.woff +0 -0
  243. package/public/webfonts/NotoSans/NotoSans-Regular.woff2 +0 -0
  244. package/public/webfonts/NotoSans/NotoSans-SemiBold.woff +0 -0
  245. package/public/webfonts/NotoSans/NotoSans-SemiBold.woff2 +0 -0
  246. package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff +0 -0
  247. package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff2 +0 -0
  248. package/public/webfonts/NotoSans/NotoSans-Thin.woff +0 -0
  249. package/public/webfonts/NotoSans/NotoSans-Thin.woff2 +0 -0
  250. package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff +0 -0
  251. package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff2 +0 -0
  252. package/public/webfonts/NotoSans/stylesheet.css +162 -0
  253. package/public/webfonts/fa-solid-900.ttf +0 -0
  254. package/public/webfonts/fa-solid-900.woff2 +0 -0
  255. package/readme.md +187 -0
  256. package/server.js +2593 -0
  257. package/start.sh +24 -0
  258. package/tools/charaverter/main.mjs +110 -0
  259. package/tools/charaverter/package.json +10 -0
@@ -0,0 +1,130 @@
1
+ import {
2
+ characters,
3
+ saveChat,
4
+ sendSystemMessage,
5
+ token,
6
+ system_messages,
7
+ system_message_types,
8
+ this_chid,
9
+ openCharacterChat,
10
+ chat_metadata,
11
+ callPopup,
12
+ } from "../script.js";
13
+ import { selected_group } from "./group-chats.js";
14
+
15
+ import {
16
+ stringFormat,
17
+ } from "./utils.js";
18
+
19
+ export {
20
+ showBookmarksButtons,
21
+ }
22
+
23
+ const bookmarkNameToken = 'Bookmark #';
24
+
25
+ async function getExistingChatNames() {
26
+ const response = await fetch("/getallchatsofcharacter", {
27
+ method: 'POST',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ "X-CSRF-Token": token,
31
+ },
32
+ body: JSON.stringify({ avatar_url: characters[this_chid].avatar })
33
+ });
34
+
35
+ if (response.ok) {
36
+ const data = await response.json();
37
+ return Object.values(data).map(x => x.file_name.replace('.jsonl', ''));
38
+ }
39
+ }
40
+
41
+ async function getBookmarkName() {
42
+ const chatNames = await getExistingChatNames();
43
+ const popupText = `<h3>Enter the bookmark name:<h3>
44
+ <small>Using existing name will overwrite your bookmark chat.
45
+ <br>Leave empty to auto-generate.</small>`;
46
+ let name = await callPopup(popupText, 'input');
47
+
48
+ if (name === false) {
49
+ return null;
50
+ }
51
+ else if (name === '') {
52
+ for (let i = 0; i < 1000; i++) {
53
+ name = bookmarkNameToken + i;
54
+ if (!chatNames.includes(name)) {
55
+ break;
56
+ }
57
+ }
58
+ }
59
+
60
+ return name;
61
+ }
62
+
63
+ function getMainChatName() {
64
+ if (chat_metadata) {
65
+ if (chat_metadata['main_chat']) {
66
+ return chat_metadata['main_chat'];
67
+ }
68
+ else if (characters[this_chid].chat && characters[this_chid].chat.includes(bookmarkNameToken)) {
69
+ const tokenIndex = characters[this_chid].chat.lastIndexOf(bookmarkNameToken);
70
+ chat_metadata['main_chat'] = characters[this_chid].chat.substring(0, tokenIndex).trim();
71
+ return chat_metadata['main_chat'];
72
+ }
73
+ }
74
+ return null;
75
+ }
76
+
77
+ function showBookmarksButtons() {
78
+ try {
79
+ // In groups or without an active chat
80
+ if (selected_group || !characters[this_chid].chat) {
81
+ $("#option_back_to_main").hide();
82
+ $("#option_new_bookmark").hide();
83
+ }
84
+ // In main chat
85
+ else if (!chat_metadata['main_chat']) {
86
+ $("#option_back_to_main").hide();
87
+ $("#option_new_bookmark").show();
88
+
89
+ }
90
+ // In bookmark chat
91
+ else {
92
+ $("#option_back_to_main").show();
93
+ $("#option_new_bookmark").show();
94
+ }
95
+ }
96
+ catch {
97
+ $("#option_back_to_main").hide();
98
+ $("#option_new_bookmark").hide();
99
+ }
100
+ }
101
+
102
+ $(document).ready(function () {
103
+ $('#option_new_bookmark').on('click', async function () {
104
+ if (selected_group) {
105
+ alert('Chat bookmarks unsupported for groups');
106
+ throw new Error();
107
+ }
108
+
109
+ let name = await getBookmarkName(characters[this_chid].chat);
110
+
111
+ if (!name) {
112
+ return;
113
+ }
114
+
115
+ const newMetadata = { main_chat: characters[this_chid].chat };
116
+ saveChat(name, newMetadata);
117
+ let mainMessage = stringFormat(system_messages[system_message_types.BOOKMARK_CREATED].mes, name, name);
118
+ sendSystemMessage(system_message_types.BOOKMARK_CREATED, mainMessage);
119
+ saveChat();
120
+ });
121
+
122
+ $('#option_back_to_main').on('click', async function () {
123
+ const mainChatName = getMainChatName(characters[this_chid].chat);
124
+ const allChats = await getExistingChatNames();
125
+
126
+ if (allChats.includes(mainChatName)) {
127
+ openCharacterChat(mainChatName);
128
+ }
129
+ });
130
+ });
@@ -0,0 +1,129 @@
1
+ import { getContext } from "../../extensions.js";
2
+ export { MODULE_NAME };
3
+
4
+ const MODULE_NAME = 'backgrounds';
5
+ const METADATA_KEY = 'custom_background';
6
+ const UPDATE_INTERVAL = 1000;
7
+
8
+ async function moduleWorker() {
9
+ if (hasCustomBackground()) {
10
+ $('#unlock_background').show();
11
+ $('#lock_background').hide();
12
+ setCustomBackground();
13
+ }
14
+ else {
15
+ $('#unlock_background').hide();
16
+ $('#lock_background').show();
17
+ unsetCustomBackground();
18
+ }
19
+ }
20
+
21
+ function onLockBackgroundClick() {
22
+ const bgImage = window.getComputedStyle(document.getElementById('bg1')).backgroundImage;
23
+
24
+ // Extract the URL from the CSS string
25
+ const urlRegex = /url\((['"])?(.*?)\1\)/;
26
+ const matches = bgImage.match(urlRegex);
27
+ const url = matches[2];
28
+
29
+ // Remove the protocol and host, leaving the relative URL
30
+ const relativeUrl = new URL(url).pathname;
31
+ const relativeBgImage = `url("${relativeUrl}")`
32
+
33
+ saveBackgroundMetadata(relativeBgImage);
34
+ setCustomBackground();
35
+ $('#unlock_background').show();
36
+ $('#lock_background').hide();
37
+ }
38
+
39
+ function onUnlockBackgroundClick() {
40
+ removeBackgroundMetadata();
41
+ unsetCustomBackground();
42
+ $('#unlock_background').hide();
43
+ $('#lock_background').show();
44
+ }
45
+
46
+ function hasCustomBackground() {
47
+ const context = getContext();
48
+ return !!context.chatMetadata[METADATA_KEY];
49
+ }
50
+
51
+ function saveBackgroundMetadata(file) {
52
+ const context = getContext();
53
+ context.chatMetadata[METADATA_KEY] = file;
54
+ context.saveChat();
55
+ }
56
+
57
+ function removeBackgroundMetadata() {
58
+ const context = getContext();
59
+ delete context.chatMetadata[METADATA_KEY];
60
+ context.saveChat();
61
+ }
62
+
63
+ function setCustomBackground() {
64
+ const context = getContext();
65
+ const file = context.chatMetadata[METADATA_KEY];
66
+
67
+ // bg already set
68
+ if (document.getElementById("bg_custom").style.backgroundImage == file) {
69
+ return;
70
+ }
71
+
72
+ $("#bg_custom").css("background-image", file);
73
+ $("#custom_bg_preview").css("background-image", file);
74
+ }
75
+
76
+ function unsetCustomBackground() {
77
+ $("#bg_custom").css("background-image", 'none');
78
+ $("#custom_bg_preview").css("background-image", 'none');
79
+ }
80
+
81
+ function onSelectBackgroundClick() {
82
+ const bgfile = $(this).attr("bgfile");
83
+
84
+ if (hasCustomBackground()) {
85
+ saveBackgroundMetadata(`url("backgrounds/${bgfile}")`);
86
+ setCustomBackground();
87
+ }
88
+ }
89
+
90
+ $(document).ready(function () {
91
+ function addSettings() {
92
+ const html = `
93
+ <div class="background_settings">
94
+ <div class="inline-drawer">
95
+ <div class="inline-drawer-toggle inline-drawer-header">
96
+ <b>Character Backgrounds</b>
97
+ <div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
98
+ </div>
99
+ <div class="inline-drawer-content">
100
+ <div class="background_controls">
101
+ <div id="lock_background" class="menu_button">
102
+ <i class="fa-solid fa-lock"></i>
103
+ Lock
104
+ </div>
105
+ <div id="unlock_background" class="menu_button">
106
+ <i class="fa-solid fa-unlock"></i>
107
+ Unlock
108
+ </div>
109
+ <small>
110
+ Press "Lock" to assign a currently selected background to a character or group chat.<br>
111
+ Any background image selected while lock is engaged will be saved automatically.
112
+ </small>
113
+ </div>
114
+ <div>Preview</div>
115
+ <div id="custom_bg_preview">
116
+ </div>
117
+ </div>
118
+ </div>
119
+ </div>
120
+ `;
121
+ $('#extensions_settings').append(html);
122
+ $('#lock_background').on('click', onLockBackgroundClick);
123
+ $('#unlock_background').on('click', onUnlockBackgroundClick);
124
+ $(document).on("click", ".bg_example", onSelectBackgroundClick);
125
+ }
126
+
127
+ addSettings();
128
+ setInterval(moduleWorker, UPDATE_INTERVAL);
129
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "display_name": "Character Backgrounds",
3
+ "loading_order": 7,
4
+ "requires": [],
5
+ "optional": [],
6
+ "js": "index.js",
7
+ "css": "style.css",
8
+ "author": "Cohee#1207",
9
+ "version": "1.0.0",
10
+ "homePage": "https://github.com/Cohee1207/SillyTavern"
11
+ }
@@ -0,0 +1,45 @@
1
+ #custom_bg_preview {
2
+ width: 160px;
3
+ height: 90px;
4
+ background-color: var(--grey30a);
5
+ background-repeat: no-repeat;
6
+ background-attachment: fixed;
7
+ background-size: cover;
8
+ border-radius: 20px;
9
+ border: 1px solid var(--black50a);
10
+ box-shadow: 0 0 7px var(--black50a);
11
+ margin: 5px;
12
+ }
13
+
14
+ #custom_bg_preview::before {
15
+ content: 'No Background';
16
+ color: white;
17
+ position: relative;
18
+ width: 100%;
19
+ height: 100%;
20
+ display: flex;
21
+ align-items: center;
22
+ justify-content: center;
23
+ }
24
+
25
+ #custom_bg_preview:not([style*="background-image: none"])::before {
26
+ display: none;
27
+ }
28
+
29
+ .background_controls .menu_button {
30
+ display: flex;
31
+ flex-direction: row;
32
+ align-items: center;
33
+ column-gap: 10px;
34
+ }
35
+
36
+ .background_controls {
37
+ display: flex;
38
+ flex-direction: row;
39
+ align-items: center;
40
+ column-gap: 10px;
41
+ }
42
+
43
+ .background_controls small {
44
+ flex-grow: 1;
45
+ }
@@ -0,0 +1,117 @@
1
+ import { getBase64Async } from "../../utils.js";
2
+ import { getContext, getApiUrl } from "../../extensions.js";
3
+ export { MODULE_NAME };
4
+
5
+ const MODULE_NAME = 'caption';
6
+ const UPDATE_INTERVAL = 1000;
7
+
8
+ async function moduleWorker() {
9
+ const context = getContext();
10
+
11
+ context.onlineStatus === 'no_connection'
12
+ ? $('#send_picture').hide(200)
13
+ : $('#send_picture').show(200);
14
+ }
15
+
16
+ async function setImageIcon() {
17
+ try {
18
+ const sendButton = document.getElementById('send_picture');
19
+ sendButton.classList.add('fa-image');
20
+ sendButton.classList.remove('fa-hourglass-half', 'fa-fade');
21
+ }
22
+ catch (error) {
23
+ console.log(error);
24
+ }
25
+ }
26
+
27
+ async function setSpinnerIcon() {
28
+ try {
29
+ const sendButton = document.getElementById('send_picture');
30
+ sendButton.classList.remove('fa-image');
31
+ sendButton.classList.add('fa-hourglass-half', 'fa-fade');
32
+ }
33
+ catch (error) {
34
+ console.log(error);
35
+ }
36
+ }
37
+
38
+ async function sendCaptionedMessage(caption, image) {
39
+ const context = getContext();
40
+ const messageText = `[${context.name1} sends ${context.name2 ?? ''} a picture that contains: ${caption}]`;
41
+ const message = {
42
+ name: context.name1,
43
+ is_user: true,
44
+ is_name: true,
45
+ send_date: Date.now(),
46
+ mes: messageText,
47
+ extra: { image: image },
48
+ title: caption
49
+ };
50
+ context.chat.push(message);
51
+ context.addOneMessage(message);
52
+ await context.generate();
53
+ }
54
+
55
+ async function onSelectImage(e) {
56
+ setSpinnerIcon();
57
+ const file = e.target.files[0];
58
+
59
+ if (!file) {
60
+ return;
61
+ }
62
+
63
+ try {
64
+ const base64Img = await getBase64Async(file);
65
+ const url = new URL(getApiUrl());
66
+ url.pathname = '/api/caption';
67
+
68
+ const apiResult = await fetch(url, {
69
+ method: 'POST',
70
+ headers: {
71
+ 'Content-Type': 'application/json',
72
+ 'Bypass-Tunnel-Reminder': 'bypass',
73
+ },
74
+ body: JSON.stringify({ image: base64Img.split(',')[1] })
75
+ });
76
+
77
+ if (apiResult.ok) {
78
+ const data = await apiResult.json();
79
+ const caption = data.caption;
80
+ const imageToSave = data.thumbnail ? `data:image/jpeg;base64,${data.thumbnail}` : base64Img;
81
+ await sendCaptionedMessage(caption, imageToSave);
82
+ }
83
+ }
84
+ catch (error) {
85
+ console.log(error);
86
+ }
87
+ finally {
88
+ e.target.form.reset();
89
+ setImageIcon();
90
+ }
91
+ }
92
+
93
+ $(document).ready(function () {
94
+ function addSendPictureButton() {
95
+ const sendButton = document.createElement('div');
96
+ sendButton.id = 'send_picture';
97
+ sendButton.classList.add('fa-solid');
98
+ $(sendButton).hide();
99
+ $(sendButton).on('click', () => $('#img_file').click());
100
+ $('#send_but_sheld').prepend(sendButton);
101
+ }
102
+ function addPictureSendForm() {
103
+ const inputHtml = `<input id="img_file" type="file" accept="image/*">`;
104
+ const imgForm = document.createElement('form');
105
+ imgForm.id = 'img_form';
106
+ $(imgForm).append(inputHtml);
107
+ $(imgForm).hide();
108
+ $('#form_sheld').append(imgForm);
109
+ $('#img_file').on('change', onSelectImage);
110
+ }
111
+
112
+ addPictureSendForm();
113
+ addSendPictureButton();
114
+ setImageIcon();
115
+ moduleWorker();
116
+ setInterval(moduleWorker, UPDATE_INTERVAL);
117
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "display_name": "Image Captioning",
3
+ "loading_order": 4,
4
+ "requires": [
5
+ "caption"
6
+ ],
7
+ "optional": [],
8
+ "js": "index.js",
9
+ "css": "style.css",
10
+ "author": "Cohee#1207",
11
+ "version": "1.0.0",
12
+ "homePage": "https://github.com/Cohee1207/SillyTavern"
13
+ }
@@ -0,0 +1,23 @@
1
+ #send_picture {
2
+ order: 200;
3
+ width: 40px;
4
+ height: 40px;
5
+ margin: 0;
6
+ padding: 1px;
7
+ outline: none;
8
+ border: none;
9
+ cursor: pointer;
10
+ transition: 0.3s;
11
+ filter: brightness(0.7);
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: center;
15
+ }
16
+
17
+ #send_picture:hover {
18
+ opacity: 1;
19
+ }
20
+
21
+ #img_form {
22
+ display: none;
23
+ }
@@ -0,0 +1,108 @@
1
+ // Borrowed from the Droll library by thebinarypenguin
2
+ // https://github.com/thebinarypenguin/droll
3
+ // Licensed under MIT license
4
+ var droll = {};
5
+
6
+ // Define a "class" to represent a formula
7
+ function DrollFormula() {
8
+ this.numDice = 0;
9
+ this.numSides = 0;
10
+ this.modifier = 0;
11
+
12
+ this.minResult = 0;
13
+ this.maxResult = 0;
14
+ this.avgResult = 0;
15
+ }
16
+
17
+ // Define a "class" to represent the results of the roll
18
+ function DrollResult() {
19
+ this.rolls = [];
20
+ this.modifier = 0;
21
+ this.total = 0;
22
+ }
23
+
24
+ /**
25
+ * Returns a string representation of the roll result
26
+ */
27
+ DrollResult.prototype.toString = function () {
28
+ if (this.rolls.length === 1 && this.modifier === 0) {
29
+ return this.rolls[0] + '';
30
+ }
31
+
32
+ if (this.rolls.length > 1 && this.modifier === 0) {
33
+ return this.rolls.join(' + ') + ' = ' + this.total;
34
+ }
35
+
36
+ if (this.rolls.length === 1 && this.modifier > 0) {
37
+ return this.rolls[0] + ' + ' + this.modifier + ' = ' + this.total;
38
+ }
39
+
40
+ if (this.rolls.length > 1 && this.modifier > 0) {
41
+ return this.rolls.join(' + ') + ' + ' + this.modifier + ' = ' + this.total;
42
+ }
43
+
44
+ if (this.rolls.length === 1 && this.modifier < 0) {
45
+ return this.rolls[0] + ' - ' + Math.abs(this.modifier) + ' = ' + this.total;
46
+ }
47
+
48
+ if (this.rolls.length > 1 && this.modifier < 0) {
49
+ return this.rolls.join(' + ') + ' - ' + Math.abs(this.modifier) + ' = ' + this.total;
50
+ }
51
+ };
52
+
53
+ /**
54
+ * Parse the formula into its component pieces.
55
+ * Returns a DrollFormula object on success or false on failure.
56
+ */
57
+ droll.parse = function (formula) {
58
+ var pieces = null;
59
+ var result = new DrollFormula();
60
+
61
+ pieces = formula.match(/^([1-9]\d*)?d([1-9]\d*)([+-]\d+)?$/i);
62
+ if (!pieces) { return false; }
63
+
64
+ result.numDice = (pieces[1] - 0) || 1;
65
+ result.numSides = (pieces[2] - 0);
66
+ result.modifier = (pieces[3] - 0) || 0;
67
+
68
+ result.minResult = (result.numDice * 1) + result.modifier;
69
+ result.maxResult = (result.numDice * result.numSides) + result.modifier;
70
+ result.avgResult = (result.maxResult + result.minResult) / 2;
71
+
72
+ return result;
73
+ };
74
+
75
+ /**
76
+ * Test the validity of the formula.
77
+ * Returns true on success or false on failure.
78
+ */
79
+ droll.validate = function (formula) {
80
+ return (droll.parse(formula)) ? true : false;
81
+ };
82
+
83
+ /**
84
+ * Roll the dice defined by the formula.
85
+ * Returns a DrollResult object on success or false on failure.
86
+ */
87
+ droll.roll = function (formula) {
88
+ var pieces = null;
89
+ var result = new DrollResult();
90
+
91
+ pieces = droll.parse(formula);
92
+ if (!pieces) { return false; }
93
+
94
+ for (var a = 0; a < pieces.numDice; a++) {
95
+ result.rolls[a] = (1 + Math.floor(Math.random() * pieces.numSides));
96
+ }
97
+
98
+ result.modifier = pieces.modifier;
99
+
100
+ for (var b = 0; b < result.rolls.length; b++) {
101
+ result.total += result.rolls[b];
102
+ }
103
+ result.total += result.modifier;
104
+
105
+ return result;
106
+ };
107
+
108
+ // END OF DROLL CODE
@@ -0,0 +1,96 @@
1
+ import { callPopup } from "../../../script.js";
2
+ import { getContext } from "../../extensions.js";
3
+ export { MODULE_NAME };
4
+
5
+ const MODULE_NAME = 'dice';
6
+ const UPDATE_INTERVAL = 1000;
7
+
8
+ function setDiceIcon() {
9
+ const sendButton = document.getElementById('roll_dice');
10
+ /* sendButton.style.backgroundImage = `url(/img/dice-solid.svg)`; */
11
+ sendButton.classList.remove('spin');
12
+ }
13
+
14
+ async function doDiceRoll() {
15
+ let value = $(this).data('value');
16
+
17
+ if (value == 'custom') {
18
+ value = await callPopup('Enter the dice formula:<br><i>(for example, <tt>2d6</tt>)</i>', 'input');
19
+ }
20
+
21
+ const isValid = droll.validate(value);
22
+
23
+ if (isValid) {
24
+ const result = droll.roll(value);
25
+ const context = getContext();
26
+ context.sendSystemMessage('generic', `${context.name1} rolls a ${value}. The result is: ${result.total}`);
27
+ }
28
+ }
29
+
30
+ function addDiceRollButton() {
31
+ const buttonHtml = `
32
+ <div id="roll_dice" class="fa-solid fa-dice" /></div>
33
+ `;
34
+ const dropdownHtml = `
35
+ <div id="dice_dropdown">
36
+ <ul class="list-group">
37
+ <li class="list-group-item" data-value="d4">d4</li>
38
+ <li class="list-group-item" data-value="d6">d6</li>
39
+ <li class="list-group-item" data-value="d8">d8</li>
40
+ <li class="list-group-item" data-value="d10">d10</li>
41
+ <li class="list-group-item" data-value="d12">d12</li>
42
+ <li class="list-group-item" data-value="d20">d20</li>
43
+ <li class="list-group-item" data-value="d100">d100</li>
44
+ <li class="list-group-item" data-value="custom">...</li>
45
+ </ul>
46
+ </div>`;
47
+
48
+ $('#send_but_sheld').prepend(buttonHtml);
49
+ $(document.body).append(dropdownHtml)
50
+ $('#dice_dropdown li').on('click', doDiceRoll);
51
+ const button = $('#roll_dice');
52
+ const dropdown = $('#dice_dropdown');
53
+ dropdown.hide();
54
+ button.hide();
55
+
56
+ let popper = Popper.createPopper(button.get(0), dropdown.get(0), {
57
+ placement: 'top-start',
58
+ });
59
+
60
+ $(document).on('click touchend', function (e) {
61
+ const target = $(e.target);
62
+ if (target.is(dropdown)) return;
63
+ if (target.is(button) && !dropdown.is(":visible")) {
64
+ e.preventDefault();
65
+
66
+ dropdown.show(200);
67
+ popper.update();
68
+ } else {
69
+ dropdown.hide(200);
70
+ }
71
+ });
72
+ }
73
+
74
+ function addDiceScript() {
75
+ if (!window.droll) {
76
+ const script = document.createElement('script');
77
+ script.src = "/scripts/extensions/dice/droll.js";
78
+ document.body.appendChild(script);
79
+ }
80
+ }
81
+
82
+ async function moduleWorker() {
83
+ const context = getContext();
84
+
85
+ context.onlineStatus === 'no_connection'
86
+ ? $('#roll_dice').hide(200)
87
+ : $('#roll_dice').show(200);
88
+ }
89
+
90
+ $(document).ready(function () {
91
+ addDiceScript();
92
+ addDiceRollButton();
93
+ setDiceIcon();
94
+ moduleWorker();
95
+ setInterval(moduleWorker, UPDATE_INTERVAL);
96
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "display_name": "D&D Dice",
3
+ "loading_order": 5,
4
+ "requires": [],
5
+ "optional": [],
6
+ "js": "index.js",
7
+ "css": "style.css",
8
+ "author": "Cohee#1207",
9
+ "version": "1.0.0",
10
+ "homePage": "https://github.com/Cohee1207/SillyTavern"
11
+ }