anymore520 commited on
Commit
a8673b3
·
verified ·
1 Parent(s): 3ff0e29

Upload 4 files

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -35
  2. Dockerfile +98 -0
  3. README.md +384 -11
  4. entrypoint.sh +336 -0
.gitattributes CHANGED
@@ -1,35 +1,35 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:lts-alpine3.19
2
+
3
+ # Arguments
4
+ ARG APP_HOME=/home/node/app
5
+ ARG PLUGINS="" # Comma-separated list of plugin git URLs
6
+ ARG USERNAME=""
7
+ ARG PASSWORD=""
8
+
9
+ # Install system dependencies
10
+ # Add unzip for extracting the application code
11
+ # Keep git for potential use by scripts or future plugin updates
12
+ # Add wget to download the zip file
13
+ # Add curl for health checks and keep-alive
14
+ # Add dos2unix to fix CRLF issues
15
+ RUN apk add --no-cache gcompat tini git unzip wget curl dos2unix
16
+
17
+ # Create app directory
18
+ WORKDIR ${APP_HOME}
19
+
20
+ # Set NODE_ENV to production and set credentials from ARGs
21
+ ENV NODE_ENV=production
22
+ ENV APP_HOME=${APP_HOME}
23
+ ENV USERNAME=${USERNAME}
24
+ ENV PASSWORD=${PASSWORD}
25
+
26
+ # --- BEGIN: Clone SillyTavern Core from GitHub (release branch) ---
27
+ RUN \
28
+ echo "*** Cloning SillyTavern Core from GitHub (release branch) ***" && \
29
+ # Clone the specific branch into the current directory
30
+ git clone -b release --depth 1 https://github.com/SillyTavern/SillyTavern.git . && \
31
+ echo "*** Cloning complete. ***"
32
+ # --- END: Clone SillyTavern Core ---
33
+
34
+ # --- BEGIN: Remove root .gitignore if exists ---
35
+ RUN \
36
+ echo "*** Attempting to remove root .gitignore if it exists ***" && \
37
+ rm -f .gitignore && \
38
+ echo "*** Root .gitignore removed (if it existed). ***"
39
+ # --- END: Remove root .gitignore ---
40
+
41
+ # Install base SillyTavern dependencies (package*.json should be in the cloned root)
42
+ RUN \
43
+ echo "*** Install Base npm packages ***" && \
44
+ if [ -f package.json ]; then \
45
+ # Added --force to potentially overcome file system issues in docker/overlayfs
46
+ npm i --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force; \
47
+ else \
48
+ echo "No package.json found in root, skipping base npm install."; \
49
+ fi
50
+
51
+ # Go back to the main app directory (redundant but safe)
52
+ WORKDIR ${APP_HOME}
53
+
54
+ # Create config directory. config.yaml will be handled at runtime by ENTRYPOINT
55
+ RUN mkdir -p config
56
+
57
+ # Pre-compile public libraries (build-lib.js should be in the unzipped structure)
58
+ RUN \
59
+ echo "*** Run Webpack ***" && \
60
+ # Check if build-lib.js exists before running
61
+ if [ -f "./docker/build-lib.js" ]; then \
62
+ node "./docker/build-lib.js"; \
63
+ elif [ -f "./build-lib.js" ]; then \
64
+ node "./build-lib.js"; \
65
+ else \
66
+ echo "build-lib.js not found, skipping Webpack build."; \
67
+ fi
68
+
69
+ # Cleanup unnecessary files (like the docker dir if it exists in the zip) and make entrypoint executable
70
+ # This block is removed as we no longer use docker-entrypoint.sh
71
+ # RUN \
72
+ # echo "*** Cleanup and Permissions ***" && \
73
+ # ...
74
+
75
+ # Fix potential git safe.directory issues if git commands are run later by scripts
76
+ RUN git config --global --add safe.directory "${APP_HOME}"
77
+
78
+ # Ensure the node user owns the application directory and its contents
79
+ RUN chown -R node:node ${APP_HOME}
80
+
81
+ # No longer download external health.sh
82
+ # RUN git clone --depth 1 https://github.com/fuwei99/docker-health.sh.git /tmp/health_repo && \
83
+ # cp /tmp/health_repo/health.sh ${APP_HOME}/health.sh && \
84
+ # rm -rf /tmp/health_repo
85
+
86
+ # Make the downloaded script executable
87
+ # RUN chmod +x ${APP_HOME}/health.sh
88
+
89
+ # Copy the entrypoint script from the repository
90
+ COPY entrypoint.sh /usr/local/bin/entrypoint.sh
91
+
92
+ # Make the new entrypoint executable
93
+ RUN chmod +x /usr/local/bin/entrypoint.sh
94
+
95
+ EXPOSE 8000
96
+
97
+ # Entrypoint: Execute the self-contained startup script
98
+ ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"]
README.md CHANGED
@@ -1,11 +1,384 @@
1
- ---
2
- title: SillyTavern Dev
3
- emoji: 📚
4
- colorFrom: indigo
5
- colorTo: indigo
6
- sdk: docker
7
- pinned: false
8
- license: mit
9
- ---
10
-
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: SillyTavern Docker & HF部署
3
+ emoji: 🥂
4
+ colorFrom: pink
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ app_port: 8000
9
+ ---
10
+
11
+ # 最简单的方法:一键部署
12
+
13
+ > **⚠️ 重要提示:** 部署界面中的 **visibility** 一定要改为 **public**,否则无法正常使用!
14
+
15
+ 如果你不想手动配置,可以直接点击下方按钮,一键将 SillyTavern Docker 部署到你自己的 Hugging Face Space 中(需要先注册 Hugging Face 账号):
16
+
17
+ [![部署到 Hugging Face Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/deploy-to-spaces-lg.svg)](https://huggingface.co/spaces/malt666/Tavern-Docker?duplicate=true)
18
+
19
+ ## 环境变量配置指南
20
+
21
+ 点击部署按钮后,请按照下表配置环境变量:
22
+
23
+ ### 基本配置(必填项)
24
+
25
+ | 环境变量 | 说明 | 示例值 |
26
+ |---------|------|--------|
27
+ | **PLUGINS** | 云备份插件链接 | `https://github.com/fuwei99/cloud-saves.git` |
28
+ | **认证配置** | USERNAME/PASSWORD 和 CONFIG_YAML 二选一 | - |
29
+
30
+ #### 认证方式(二选一):
31
+
32
+ 1. **USERNAME/PASSWORD**(推荐)
33
+ - 简单直接填写用户名和密码,用于酒馆的登录
34
+
35
+ 2. **CONFIG_YAML**
36
+ - 见下方命令行格式
37
+ - 记得修改配置中的用户名和密码
38
+ - **注意**:由于 Hugging Face 的部署界面有 bug,复制的内容可能会变成一行
39
+ - **解决方法**:部署后进入 Settings → Secrets,点击 CONFIG_YAML 旁边的 replace,重新复制粘贴
40
+
41
+ ### 扩展配置
42
+
43
+ | 环境变量 | 说明 | 示例值 |
44
+ |---------|------|--------|
45
+ | **EXTENSIONS** | 扩展链接列表,用英文逗号分隔 | `https://github.com/N0VI028/JS-Slash-Runner,https://gitee.com/muyoou/st-memory-enhancement` |
46
+ | **INSTALL_FOR_ALL_USERS** | 扩展安装模式 | `true` 或 `false` |
47
+
48
+ > **扩展安装模式INSTALL_FOR_ALL_USERS**:
49
+ > - `true`:安装到全局(推荐)
50
+ > - `false`:仅安装到 default-user
51
+ > - 不填写:默认安装到 default-user
52
+
53
+ ### 可选配置(cloud-saves 插件相关,自动配置基本信息,注意自动保存还是要自己开启,这里只是配置好信息)
54
+
55
+ | 环境变量 | 说明 | 默认值 |
56
+ |---------|------|-------|
57
+ | **REPO_URL** | GitHub 仓库地址 | - |
58
+ | **GITHUB_TOKEN** | GitHub 访问令牌 | - |
59
+ | **AUTOSAVE_INTERVAL** | 自动保存间隔(秒) | 30 |
60
+ | **AUTOSAVE_TARGET_TAG** | 自动保存目标标签 | 空 |
61
+
62
+ ---
63
+
64
+ ## 如何读取或者保存存档
65
+
66
+ 教程见: https://github.com/fuwei99/cloud-saves
67
+
68
+ * 对于推荐安装的 `cloud-saves` 插件,其管理界面通常位于:
69
+ `http://<你的SillyTavern访问地址>/api/plugins/cloud-saves/ui`
70
+ 例如,如果是本地部署,则为 `http://127.0.0.1:8000/api/plugins/cloud-saves/ui`。如果是 Hugging Face Space,则将 `<你的SillyTavern访问地址>` 替换为你的 Space 公共 URL
71
+
72
+ 其他插件的访问路径请参考其各自的文档。
73
+
74
+
75
+ ---
76
+
77
+ # SillyTavern Docker 与 Hugging Face 部署指南
78
+
79
+ 本指南说明了如何使用提供的 `Dockerfile` 来构建和运行 SillyTavern,以及如何在 Hugging Face Spaces 上进行部署。部署的核心思想是通过环境变量在容器启动时动态配置 SillyTavern 和安装插件。
80
+
81
+ ## 关键文件
82
+
83
+ * `Dockerfile`: 用于构建 SillyTavern 运行环境的 Docker 镜像。它会:
84
+ * 基于官方 Node.js Alpine 镜像。
85
+ * 安装必要的系统依赖(如 `git`)。
86
+ * 从 GitHub 克隆 SillyTavern 的 `staging` 分支代码。
87
+ * 设置工作目录和用户权限。
88
+ * 定义容器启动时的 `ENTRYPOINT` 脚本,该脚本负责:
89
+ * 读取 `CONFIG_YAML` 环境变量并写入 `./config.yaml` 文件。
90
+ * 读取 `PLUGINS` 环境变量,并克隆、安装指定的插件。
91
+ * 启动 SillyTavern 服务器 (`node server.js`)。
92
+ * `README.md`: 本说明文件。
93
+
94
+ ## 配置方式:环境变量
95
+
96
+ 我们通过两个主要的环境变量来配置容器:
97
+
98
+ 1. `CONFIG_YAML`: **必需**。
99
+ * **作用**: 定义 SillyTavern 的运行配置。
100
+ * **内容**: 下面是推荐的默认配置内容。你可以直接复制粘贴使用,但**强烈建议你修改其中的认证信息**。
101
+ * **推荐配置内容**:
102
+ ```yaml
103
+ dataRoot: ./data
104
+ listen: true
105
+ listenAddress:
106
+ ipv4: 0.0.0.0
107
+ ipv6: '[::]'
108
+ protocol:
109
+ ipv4: true
110
+ ipv6: false
111
+ dnsPreferIPv6: false
112
+ autorunHostname: "auto"
113
+ port: 8000
114
+ autorunPortOverride: -1
115
+ ssl:
116
+ enabled: false
117
+ certPath: "./certs/cert.pem"
118
+ keyPath: "./certs/privkey.pem"
119
+ whitelistMode: false
120
+ enableForwardedWhitelist: false
121
+ whitelist:
122
+ - ::1
123
+ - 127.0.0.1
124
+ whitelistDockerHosts: true
125
+ basicAuthMode: true
126
+ basicAuthUser:
127
+ username: "用户名" # 请务必修改为你自己的用户名
128
+ password: "密码" # 请务必修改为你自己的密码
129
+ enableCorsProxy: false
130
+ requestProxy:
131
+ enabled: false
132
+ url: "socks5://username:password@example.com:1080"
133
+ bypass:
134
+ - localhost
135
+ - 127.0.0.1
136
+ enableUserAccounts: false
137
+ enableDiscreetLogin: false
138
+ autheliaAuth: false
139
+ perUserBasicAuth: false
140
+ sessionTimeout: -1
141
+ disableCsrfProtection: false
142
+ securityOverride: false
143
+ logging:
144
+ enableAccessLog: true
145
+ minLogLevel: 0
146
+ rateLimiting:
147
+ preferRealIpHeader: false
148
+ autorun: false
149
+ avoidLocalhost: false
150
+ backups:
151
+ common:
152
+ numberOfBackups: 50
153
+ chat:
154
+ enabled: true
155
+ checkIntegrity: true
156
+ maxTotalBackups: -1
157
+ throttleInterval: 10000
158
+ thumbnails:
159
+ enabled: true
160
+ format: "jpg"
161
+ quality: 95
162
+ dimensions: { 'bg': [160, 90], 'avatar': [96, 144] }
163
+ performance:
164
+ lazyLoadCharacters: false
165
+ memoryCacheCapacity: '100mb'
166
+ useDiskCache: true
167
+ allowKeysExposure: true
168
+ skipContentCheck: false
169
+ whitelistImportDomains:
170
+ - localhost
171
+ - cdn.discordapp.com
172
+ - files.catbox.moe
173
+ - raw.githubusercontent.com
174
+ requestOverrides: []
175
+ extensions:
176
+ enabled: true
177
+ autoUpdate: false
178
+ models:
179
+ autoDownload: true
180
+ classification: Cohee/distilbert-base-uncased-go-emotions-onnx
181
+ captioning: Xenova/vit-gpt2-image-captioning
182
+ embedding: Cohee/jina-embeddings-v2-base-en
183
+ speechToText: Xenova/whisper-small
184
+ textToSpeech: Xenova/speecht5_tts
185
+ enableDownloadableTokenizers: true
186
+ promptPlaceholder: "[Start a new chat]"
187
+ openai:
188
+ randomizeUserId: false
189
+ captionSystemPrompt: ""
190
+ deepl:
191
+ formality: default
192
+ mistral:
193
+ enablePrefix: false
194
+ ollama:
195
+ keepAlive: -1
196
+ batchSize: -1
197
+ claude:
198
+ enableSystemPromptCache: false
199
+ cachingAtDepth: -1
200
+ enableServerPlugins: true
201
+ enableServerPluginsAutoUpdate: false
202
+ ```
203
+ * **⚠️ 重要警告**: 请务必修改上方配置中 `basicAuthUser` 下的 `username` 和 `password` 为你自己的凭据,以确保安全!**不要使用默认的 "用户名" 和 "密码"!**
204
+ * **注意**: 必须是有效的 YAML 格式,且**不应包含任何 `#` 开头的注释行**。
205
+
206
+ 2. `PLUGINS`: **可选**。
207
+ * **作用**: 指定需要在容器启动时自动安装的 SillyTavern 插件。
208
+ * **内容**: 一个**逗号分隔**的插件 Git 仓库 URL 列表。
209
+ * **推荐安装**: 强烈建议安装 `cloud-saves` 插件,以便在不同部署环境(如本地和 Hugging Face)之间同步数据。
210
+ * **插件地址**: `https://github.com/fuwei99/cloud-saves.git`
211
+ * **重要前置条件**: 为了让容器/Hugging Face Space 能够拉取你的存档,你**必须**先在你本地的 SillyTavern 中安装好 `cloud-saves` 插件,并**至少进行一次数据存档操作**。这样,远程部署的环境才能通过该插件下载你的存档。
212
+ * **格式示例**: `https://github.com/fuwei99/cloud-saves.git` (注意包含推荐的 cloud-saves 插件)
213
+ * **注意**: URL 之间**只能用英文逗号 `,` 分隔**,且逗号前后**不能有空格**。如果留空或不提供此变量,则不会安装额外插件。
214
+
215
+ 3. `EXTENSIONS`: **可选**。
216
+ * **作用**: 指定需要在容器启动时自动安装的 SillyTavern 扩展(Extensions)。
217
+ * **内容**: 一个**逗号分隔**的扩展 Git 仓库 URL 列表。
218
+ * **安装时机**: 扩展会在项目启动之后自动安装,确保 SillyTavern 目录结构已经准备完毕。
219
+ * **格式示例**: `https://github.com/user1/extension1.git,https://github.com/user2/extension2.git`
220
+ * **注意**: URL 之间**只能用英文逗号 `,` 分隔**,且逗号前后**不能有空格**。如果留空或不提供此变量,则不会安装额外扩展。
221
+
222
+ 4. `INSTALL_FOR_ALL_USERS`: **可选**。
223
+ * **作用**: 控制扩展的安装位置模式。
224
+ * **可选值**:
225
+ * `true`: 扩展安装到 `public/scripts/extensions/third-party` 目录下,对**所有用户**生效(系统级安装)。
226
+ * `false` 或任何其他值,或变量不存在: 扩展安装到 `data/default-user/extensions` 目录下,仅对**默认用户**生效(用户级安装)。
227
+ * **默认行为**: 如果不设置此环境变量,默认安装到用户级目录。
228
+ * **格式示例**: `true` 或 `false`
229
+
230
+ 5. `REPO_URL`: **可选**。
231
+ * **作用**: 为 cloud-saves 插件提供 GitHub 仓库 URL,用于自动配置插件。
232
+ * **前置条件**: 需要同时安装 cloud-saves 插件(通过 `PLUGINS` 环境变量)。
233
+ * **格式示例**: `https://github.com/yourusername/yourrepo`
234
+ * **说明**: 这是你用来存储 SillyTavern 数据备份的 GitHub 仓库地址。
235
+
236
+ 6. `GITHUB_TOKEN`: **可选**。
237
+ * **作用**: 为 cloud-saves 插件提供 GitHub 访问令牌,用于自动配置插件。
238
+ * **前置条件**: 需要同时设置 `REPO_URL` 和安装 cloud-saves 插件。
239
+ * **格式示例**: `ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
240
+ * **获取方式**: 在 GitHub Settings -> Developer settings -> Personal access tokens -> Tokens (classic) 中创建,需要 `repo` 权限。
241
+ * **自动配置**: 如果同时提供了 `REPO_URL` 和 `GITHUB_TOKEN`,且安装了 cloud-saves 插件,系统会自动创建插件的配置文件。
242
+
243
+ 7. `AUTOSAVE_INTERVAL`: **可选**。
244
+ * **作用**: 设置 cloud-saves 插件的自动保存间隔时间(秒)。
245
+ * **前置条件**: 需要同时设置 `REPO_URL` 和 `GITHUB_TOKEN`。
246
+ * **格式示例**: `30`(表示每30秒自动保存一次)
247
+ * **默认值**: 如果不设置,默认为 `30` 秒。
248
+
249
+ 8. `AUTOSAVE_TARGET_TAG`: **可选**。
250
+ * **作用**: 设置 cloud-saves 插件的自动保存目标标签。
251
+ * **前置条件**: 需要同时设置 `REPO_URL` 和 `GITHUB_TOKEN`。
252
+ * **格式示例**: `auto-backup` 或 `daily-save`
253
+ * **默认值**: 如果不设置,默认为空字符串。
254
+
255
+ ## 方法一:本地 Docker 部署
256
+
257
+ 你可以在本地使用 Docker 来构建和运行 SillyTavern。
258
+
259
+ 1. **构建镜像**: 在包含 `Dockerfile` 的目录下,运行:
260
+ ```bash
261
+ docker build -t sillytavern-local .
262
+ ```
263
+ 将 `sillytavern-local` 替换为你想要的镜像名称。
264
+
265
+ 2. **准备配置**: 将你的 `config.yaml` 内容(无注释)准备好。
266
+
267
+ 3. **运行容器**: 使用 `docker run` 命令,并通过 `-e` 参数传递环境变量。
268
+ * 将上方提供的**推荐配置内容**复制,并作为 `CONFIG_YAML` 环境变量的值。**确保你已经修改了其中的用户名和密码!**
269
+ * 如果你需要安装插件(**推荐安装 `cloud-saves`**),请准备好插件 URL 列表。
270
+
271
+ ```bash
272
+ # 示例:使用推荐配置并安装 cloud-saves 插件
273
+ # 1. 将推荐配置(修改密码后)保存到名为 config_no_comments.yaml 的文件中
274
+ # 2. 运行以下命令
275
+
276
+ docker run -p 8000:8000 --name my-sillytavern \\
277
+ -e CONFIG_YAML="$(cat config_no_comments.yaml)" \\
278
+ -e PLUGINS='https://github.com/fuwei99/cloud-saves.git' \\
279
+ -e EXTENSIONS='https://github.com/user1/extension1.git,https://github.com/user2/extension2.git' \\
280
+ -e INSTALL_FOR_ALL_USERS=false \\
281
+ -e REPO_URL='https://github.com/yourusername/yourrepo' \\
282
+ -e GITHUB_TOKEN='ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \\
283
+ -e AUTOSAVE_INTERVAL=30 \\
284
+ -e AUTOSAVE_TARGET_TAG=auto-backup \\
285
+ sillytavern-local
286
+
287
+ # 如果你需要安装更多插件,用逗号隔开添加到 PLUGINS 变量中
288
+ # 例如:
289
+ # docker run -p 8000:8000 --name my-sillytavern \
290
+ # -e CONFIG_YAML="$(cat config_no_comments.yaml)" \
291
+ # -e PLUGINS='https://github.com/fuwei99/cloud-saves.git,https://github.com/user/other-plugin.git' \
292
+ # -e EXTENSIONS='https://github.com/user1/extension1.git,https://github.com/user2/extension2.git' \
293
+ # -e INSTALL_FOR_ALL_USERS=false \
294
+ # -e REPO_URL='https://github.com/yourusername/yourrepo' \
295
+ # -e GITHUB_TOKEN='ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
296
+ # -e AUTOSAVE_INTERVAL=30 \
297
+ # -e AUTOSAVE_TARGET_TAG=auto-backup \
298
+ # sillytavern-local
299
+ ```
300
+ * `-p 8000:8000`: 将容器的 8000 端口映射到宿主机的 8000 端口。
301
+ * `--name my-sillytavern`: 为容器命名,方便管理。
302
+ * `-e CONFIG_YAML="$(cat config_no_comments.yaml)"`: 从文件读取配置内容并传递。这是处理多行 YAML 最可靠的方式。**再次确认:运行前务必修改 `config_no_comments.yaml` 文件中的用户名和密码!**
303
+ * `-e PLUGINS='...'`: 传递插件列表,这里以安装 `cloud-saves` 为例。
304
+ * `-e EXTENSIONS='...'`: 传递扩展列表,这里以安装 `extension1` 和 `extension2` 为例。
305
+ * `-e INSTALL_FOR_ALL_USERS=false`: 设置扩展安装模式为用户级安装。
306
+ * `-e REPO_URL='...'`: 传递 REPO_URL 环境变量。
307
+ * `-e GITHUB_TOKEN='...'`: 传递 GITHUB_TOKEN 环境变量。
308
+ * `-e AUTOSAVE_INTERVAL=30`: 设置 AUTOSAVE_INTERVAL 环���变量。
309
+ * `-e AUTOSAVE_TARGET_TAG=auto-backup`: 设置 AUTOSAVE_TARGET_TAG 环境变量。
310
+
311
+ 4. **访问**: 打开浏览器访问 `http://localhost:8000`。
312
+
313
+ ## 方法二:Hugging Face Spaces 部署
314
+
315
+ 这是推荐的在线部署方式,利用 Hugging Face 的免费计算资源和 Secrets 管理功能。
316
+
317
+ 1. **创建 Space**: 在 Hugging Face 上创建一个新的 Space,选择 **Docker** SDK。
318
+
319
+ 2. **上传文件**: 将本项目中的 `Dockerfile` 和 `README.md` 文件上传到你的 Space 仓库根目录。
320
+
321
+ 3. **配置 Secrets**: 进入你的 Space 页面的 **Settings -> Secrets** 部分。
322
+ * **添加 `CONFIG_YAML` Secret**:
323
+ * 点击 "New secret"。
324
+ * 名称 (Name) 输入: `CONFIG_YAML`
325
+ * 值 (Value) 粘贴: **复制上方提供的推荐配置内容**。**再次强调:粘贴前请务必修改 `basicAuthUser` 下的 `username` 和 `password` 为你自己的安全凭据!**
326
+ * 点击 "Add secret"。
327
+ * **(推荐) 添加 `PLUGINS` Secret**:
328
+ * 再次点击 "New secret"。
329
+ * 名称 (Name) 输入: `PLUGINS`
330
+ * 值 (Value) 粘贴: 推荐至少包含 `cloud-saves` 插件。例如:`https://github.com/fuwei99/cloud-saves.git`。如果你需要其他插件,用逗号隔开添加,例如:`https://github.com/fuwei99/cloud-saves.git,https://github.com/user/other-plugin.git`。
331
+ * **重要提醒**: 请确保你已经在本地 SillyTavern 安装了 `cloud-saves` 并至少进行了一次存档。
332
+ * 点击 "Add secret"。如果你确实不需要任何额外插件,可以跳过这一步。
333
+
334
+ * **(可选) 添加 `EXTENSIONS` Secret**:
335
+ * 再次点击 "New secret"。
336
+ * 名称 (Name) 输入: `EXTENSIONS`
337
+ * 值 (Value) 粘贴: 你需要安装的扩展 Git URL 列表,用逗号隔开。例如:`https://github.com/user1/extension1.git,https://github.com/user2/extension2.git`。
338
+ * 点击 "Add secret"。如果你不需要安装扩展,可以跳过这一步。
339
+
340
+ * **(可选) 添加 `INSTALL_FOR_ALL_USERS` Secret**:
341
+ * 如果你添加了 `EXTENSIONS` Secret,可以继续添加这个 Secret 来控制扩展安装模式。
342
+ * 再次点击 "New secret"。
343
+ * 名称 (Name) 输入: `INSTALL_FOR_ALL_USERS`
344
+ * 值 (Value) 输入: `true`(系统级安装,所有用户可用)或 `false`(用户级安装,仅默认用户可用)。
345
+ * **推荐**: 对于 Hugging Face Space 单用户环境,建议设置为 `false` 或不设置此 Secret。
346
+ * 点击 "Add secret"。如果不设置,默认为用户级安装。
347
+
348
+ * **(可选) 添加 `REPO_URL` Secret**:
349
+ * 再次点击 "New secret"。
350
+ * 名称 (Name) 输入: `REPO_URL`
351
+ * 值 (Value) 输入: 你的 GitHub 仓库地址,用于 cloud-saves 插件自动配置。例如:`https://github.com/yourusername/yourrepo`
352
+ * 点击 "Add secret"。
353
+
354
+ * **(可选) 添加 `GITHUB_TOKEN` Secret**:
355
+ * 再次点击 "New secret"。
356
+ * 名称 (Name) 输入: `GITHUB_TOKEN`
357
+ * 值 (Value) 输入: 你的 GitHub 访问令牌,用于 cloud-saves 插件自动配置。例如:`ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
358
+ * 点击 "Add secret"。
359
+
360
+ * **(可选) 添加 `AUTOSAVE_INTERVAL` Secret**:
361
+ * 再次点击 "New secret"。
362
+ * 名称 (Name) 输入: `AUTOSAVE_INTERVAL`
363
+ * 值 (Value) 输入: 自动保存间隔秒数,不填写默认为30秒
364
+ * 点击 "Add secret"。
365
+
366
+ * **(可选) 添加 `AUTOSAVE_TARGET_TAG` Secret**:
367
+ * 再次点击 "New secret"。
368
+ * 名称 (Name) 输入: `AUTOSAVE_TARGET_TAG`
369
+ * 值 (Value) 输入: 自动保存目标标签,不填写默认为空
370
+ * 点击 "Add secret"。
371
+
372
+ 4. **构建与启动**: Hugging Face 会自动检测到 `Dockerfile` 和 Secrets,并开始构建镜像、启动容器。你可以在 Space 的 **Logs** 标签页查看构建和启动过程。
373
+
374
+ 5. **访问**: 构建成功并启动后,通过 Space 提供的公共 URL 访问 SillyTavern 界面。
375
+
376
+ ## 插件访问
377
+
378
+ 如果通过 `PLUGINS` 环境变量安装了插件,你需要根据各个插件的说明文档找到访问其界面的路径。
379
+
380
+ * 对于推荐安装的 `cloud-saves` 插件,其管理界面通常位于:
381
+ `http://<你的SillyTavern访问地址>/api/plugins/cloud-saves/ui`
382
+ 例如,如果是本地部署,则为 `http://127.0.0.1:8000/api/plugins/cloud-saves/ui`。如果是 Hugging Face Space,则将 `<你的SillyTavern访问地址>` 替换为你的 Space 公共 URL。
383
+
384
+ 其他插件的访问路径请参考其各自的文档。
entrypoint.sh ADDED
@@ -0,0 +1,336 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ CONFIG_FILE="${APP_HOME}/config.yaml"
5
+
6
+ # Priority 1: Use USERNAME/PASSWORD if both are provided
7
+ if [ -n "${USERNAME}" ] && [ -n "${PASSWORD}" ]; then
8
+ echo "--- Basic auth enabled: Creating config.yaml with provided credentials. ---"
9
+
10
+ cat <<EOT > ${CONFIG_FILE}
11
+ dataRoot: ./data
12
+ listen: true
13
+ listenAddress:
14
+ ipv4: 0.0.0.0
15
+ ipv6: '[::]'
16
+ protocol:
17
+ ipv4: true
18
+ ipv6: false
19
+ dnsPreferIPv6: false
20
+ autorunHostname: "auto"
21
+ port: 8000
22
+ autorunPortOverride: -1
23
+ ssl:
24
+ enabled: false
25
+ certPath: "./certs/cert.pem"
26
+ keyPath: "./certs/privkey.pem"
27
+ whitelistMode: false
28
+ enableForwardedWhitelist: false
29
+ whitelist:
30
+ - ::1
31
+ - 127.0.0.1
32
+ whitelistDockerHosts: true
33
+ basicAuthMode: true
34
+ basicAuthUser:
35
+ username: "${USERNAME}"
36
+ password: "${PASSWORD}"
37
+ enableCorsProxy: false
38
+ requestProxy:
39
+ enabled: false
40
+ url: "socks5://username:password@example.com:1080"
41
+ bypass:
42
+ - localhost
43
+ - 127.0.0.1
44
+ enableUserAccounts: false
45
+ enableDiscreetLogin: false
46
+ autheliaAuth: false
47
+ perUserBasicAuth: false
48
+ sessionTimeout: -1
49
+ disableCsrfProtection: false
50
+ securityOverride: false
51
+ logging:
52
+ enableAccessLog: true
53
+ minLogLevel: 0
54
+ rateLimiting:
55
+ preferRealIpHeader: false
56
+ autorun: false
57
+ avoidLocalhost: false
58
+ backups:
59
+ common:
60
+ numberOfBackups: 50
61
+ chat:
62
+ enabled: true
63
+ checkIntegrity: true
64
+ maxTotalBackups: -1
65
+ throttleInterval: 10000
66
+ thumbnails:
67
+ enabled: true
68
+ format: "jpg"
69
+ quality: 95
70
+ dimensions: { 'bg': [160, 90], 'avatar': [96, 144] }
71
+ performance:
72
+ lazyLoadCharacters: false
73
+ memoryCacheCapacity: '100mb'
74
+ useDiskCache: true
75
+ allowKeysExposure: true
76
+ skipContentCheck: false
77
+ whitelistImportDomains:
78
+ - localhost
79
+ - cdn.discordapp.com
80
+ - files.catbox.moe
81
+ - raw.githubusercontent.com
82
+ requestOverrides: []
83
+ extensions:
84
+ enabled: true
85
+ autoUpdate: false
86
+ models:
87
+ autoDownload: true
88
+ classification: Cohee/distilbert-base-uncased-go-emotions-onnx
89
+ captioning: Xenova/vit-gpt2-image-captioning
90
+ embedding: Cohee/jina-embeddings-v2-base-en
91
+ speechToText: Xenova/whisper-small
92
+ textToSpeech: Xenova/speecht5_tts
93
+ enableDownloadableTokenizers: true
94
+ promptPlaceholder: "[Start a new chat]"
95
+ openai:
96
+ randomizeUserId: false
97
+ captionSystemPrompt: ""
98
+ deepl:
99
+ formality: default
100
+ mistral:
101
+ enablePrefix: false
102
+ ollama:
103
+ keepAlive: -1
104
+ batchSize: -1
105
+ claude:
106
+ enableSystemPromptCache: false
107
+ cachingAtDepth: -1
108
+ enableServerPlugins: true
109
+ enableServerPluginsAutoUpdate: false
110
+ EOT
111
+
112
+ # Priority 2: Use CONFIG_YAML if provided (and username/password are not)
113
+ elif [ -n "${CONFIG_YAML}" ]; then
114
+ echo "--- Found CONFIG_YAML, creating config.yaml from environment variable. ---"
115
+ printf '%s\n' "${CONFIG_YAML}" > ${CONFIG_FILE}
116
+
117
+ # Priority 3: No config provided, let the app use its defaults
118
+ else
119
+ echo "--- No user/pass or CONFIG_YAML provided. App will use its default settings. ---"
120
+ fi
121
+
122
+ # --- BEGIN: Update SillyTavern Core at Runtime ---
123
+ echo '--- Attempting to update SillyTavern Core from GitHub (staging branch) ---'
124
+ if [ -d ".git" ] && [ "$(git rev-parse --abbrev-ref HEAD)" = "staging" ]; then
125
+ echo 'Existing staging branch found. Resetting and pulling latest changes...'
126
+ git reset --hard HEAD && \
127
+ git pull origin staging || echo 'WARN: git pull failed, continuing with code from build time.'
128
+ echo '--- SillyTavern Core update check finished. ---'
129
+ else
130
+ echo 'WARN: .git directory not found or not on staging branch. Skipping runtime update. Code from build time will be used.'
131
+ fi
132
+ # --- END: Update SillyTavern Core at Runtime ---
133
+
134
+ # --- BEGIN: Configure Git default identity at Runtime ---
135
+ echo '--- Configuring Git default user identity at runtime ---'
136
+ git config --global user.name "SillyTavern Sync" && \
137
+ git config --global user.email "sillytavern-sync@example.com" && \
138
+ git config --global --add safe.directory "${APP_HOME}/data"
139
+ echo '--- Git identity configured for runtime user. ---'
140
+ # --- END: Configure Git default identity at Runtime ---
141
+
142
+ # --- BEGIN: Dynamically Install Plugins at Runtime ---
143
+ echo '--- Checking for PLUGINS environment variable ---'
144
+ if [ -n "$PLUGINS" ]; then
145
+ echo "*** Installing Plugins specified in PLUGINS environment variable: $PLUGINS ***"
146
+ # Ensure plugins directory exists
147
+ mkdir -p ./plugins && chown node:node ./plugins
148
+ # Set comma as delimiter
149
+ IFS=','
150
+ # Loop through each plugin URL
151
+ for plugin_url in $PLUGINS; do
152
+ # Trim leading/trailing whitespace
153
+ plugin_url=$(echo "$plugin_url" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
154
+ if [ -z "$plugin_url" ]; then continue; fi
155
+ # Extract plugin name
156
+ plugin_name_git=$(basename "$plugin_url")
157
+ plugin_name=${plugin_name_git%.git}
158
+ plugin_dir="./plugins/$plugin_name"
159
+ echo "--- Installing plugin: $plugin_name from $plugin_url into $plugin_dir ---"
160
+ # Remove existing dir if it exists
161
+ rm -rf "$plugin_dir"
162
+ # Clone the plugin (run as root, fix perms later)
163
+ git clone --depth 1 "$plugin_url" "$plugin_dir"
164
+ if [ -f "$plugin_dir/package.json" ]; then
165
+ echo "--- Installing dependencies for $plugin_name ---"
166
+ (cd "$plugin_dir" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force) || echo "WARN: Failed to install dependencies for $plugin_name"
167
+ else
168
+ echo "--- No package.json found for $plugin_name, skipping dependency install. ---"
169
+ fi || echo "WARN: Failed to clone $plugin_name from $plugin_url, skipping..."
170
+
171
+ # Configure cloud-saves plugin if this is the cloud-saves plugin
172
+ if [ "$plugin_name" = "cloud-saves" ]; then
173
+ echo "--- Detected cloud-saves plugin, checking for configuration environment variables ---"
174
+
175
+ # Set default values
176
+ REPO_URL_VALUE=${REPO_URL:-"https://github.com/fuwei99/sillytravern"}
177
+ GITHUB_TOKEN_VALUE=${GITHUB_TOKEN:-""}
178
+ AUTOSAVE_INTERVAL_VALUE=${AUTOSAVE_INTERVAL:-30}
179
+ AUTOSAVE_TARGET_TAG_VALUE=${AUTOSAVE_TARGET_TAG:-""}
180
+
181
+ # Always set autosave to false as required
182
+ AUTOSAVE_ENABLED="false"
183
+
184
+ echo "--- Creating cloud-saves plugin configuration file ---"
185
+ CONFIG_JSON_FILE="$plugin_dir/config.json"
186
+
187
+ # Generate config.json file
188
+ cat <<EOT > ${CONFIG_JSON_FILE}
189
+ {
190
+ "repo_url": "${REPO_URL_VALUE}",
191
+ "branch": "main",
192
+ "username": "cloud-saves",
193
+ "github_token": "${GITHUB_TOKEN_VALUE}",
194
+ "display_name": "",
195
+ "is_authorized": true,
196
+ "last_save": null,
197
+ "current_save": null,
198
+ "has_temp_stash": false,
199
+ "autoSaveEnabled": ${AUTOSAVE_ENABLED},
200
+ "autoSaveInterval": ${AUTOSAVE_INTERVAL_VALUE},
201
+ "autoSaveTargetTag": "${AUTOSAVE_TARGET_TAG_VALUE}"
202
+ }
203
+ EOT
204
+
205
+ # Set correct permissions for config file
206
+ chown node:node ${CONFIG_JSON_FILE}
207
+
208
+ echo "--- cloud-saves plugin configuration file created at: ${CONFIG_JSON_FILE} ---"
209
+ fi
210
+ done
211
+ # Reset IFS
212
+ unset IFS
213
+ # Fix permissions for plugins directory after installation
214
+ echo "--- Setting permissions for plugins directory ---"
215
+ chown -R node:node ./plugins
216
+ echo "*** Plugin installation finished. ***"
217
+ else
218
+ echo 'PLUGINS environment variable is not set or empty, skipping runtime plugin installation.'
219
+ fi
220
+ # --- END: Dynamically Install Plugins at Runtime ---
221
+
222
+ echo "*** Starting SillyTavern... ***"
223
+ node ${APP_HOME}/server.js &
224
+ SERVER_PID=$!
225
+
226
+ echo "SillyTavern server started with PID ${SERVER_PID}. Waiting for it to become responsive..."
227
+
228
+ # --- Health Check Logic ---
229
+ HEALTH_CHECK_URL="http://localhost:8000/"
230
+ CURL_COMMAND="curl -sf"
231
+
232
+ # If basic auth is enabled, provide credentials to curl for health checks
233
+ if [ -n "${USERNAME}" ] && [ -n "${PASSWORD}" ]; then
234
+ echo "--- Health check will use basic auth credentials. ---"
235
+ # The -u flag provides user:password for basic auth
236
+ CURL_COMMAND="curl -sf -u \"${USERNAME}:${PASSWORD}\""
237
+ fi
238
+
239
+ # Health check loop
240
+ RETRY_COUNT=0
241
+ MAX_RETRIES=12 # Wait for 60 seconds max
242
+ # Use eval to correctly execute the command string with quotes
243
+ while ! eval "${CURL_COMMAND} ${HEALTH_CHECK_URL}" > /dev/null; do
244
+ RETRY_COUNT=$((RETRY_COUNT+1))
245
+ if [ ${RETRY_COUNT} -ge ${MAX_RETRIES} ]; then
246
+ echo "SillyTavern failed to start. Exiting."
247
+ kill ${SERVER_PID}
248
+ exit 1
249
+ fi
250
+ echo "SillyTavern is still starting or not responsive on port 8000, waiting 5 seconds..."
251
+ sleep 5
252
+ done
253
+
254
+ echo "SillyTavern started successfully! Beginning periodic keep-alive..."
255
+
256
+ # --- BEGIN: Install Extensions after SillyTavern startup ---
257
+ install_extensions() {
258
+ echo "--- Waiting 40 seconds before installing extensions... ---"
259
+ sleep 40
260
+
261
+ echo "--- Checking for EXTENSIONS environment variable ---"
262
+ if [ -n "$EXTENSIONS" ]; then
263
+ echo "*** Installing Extensions specified in EXTENSIONS environment variable: $EXTENSIONS ***"
264
+
265
+ # Determine installation directory based on INSTALL_FOR_ALL_USERS
266
+ if [ "$INSTALL_FOR_ALL_USERS" = "true" ]; then
267
+ # System-level installation (for all users)
268
+ EXTENSIONS_DIR="./public/scripts/extensions/third-party"
269
+ echo "Installing extensions for all users in: $EXTENSIONS_DIR"
270
+ else
271
+ # User-level installation (for default user only)
272
+ EXTENSIONS_DIR="./data/default-user/extensions"
273
+ echo "Installing extensions for default user in: $EXTENSIONS_DIR"
274
+ fi
275
+
276
+ # Ensure extensions directory exists
277
+ mkdir -p "$EXTENSIONS_DIR" && chown node:node "$EXTENSIONS_DIR"
278
+
279
+ # Set comma as delimiter
280
+ IFS=','
281
+
282
+ # Loop through each extension URL
283
+ for extension_url in $EXTENSIONS; do
284
+ # Trim leading/trailing whitespace
285
+ extension_url=$(echo "$extension_url" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
286
+ if [ -z "$extension_url" ]; then continue; fi
287
+
288
+ # Extract extension name
289
+ extension_name_git=$(basename "$extension_url")
290
+ extension_name=${extension_name_git%.git}
291
+ extension_dir="$EXTENSIONS_DIR/$extension_name"
292
+
293
+ echo "--- Installing extension: $extension_name from $extension_url into $extension_dir ---"
294
+
295
+ # Remove existing dir if it exists
296
+ rm -rf "$extension_dir"
297
+
298
+ # Clone the extension
299
+ git clone --depth 1 "$extension_url" "$extension_dir"
300
+
301
+ # Check if extension has package.json and install dependencies if needed
302
+ if [ -f "$extension_dir/package.json" ]; then
303
+ echo "--- Installing dependencies for $extension_name ---"
304
+ (cd "$extension_dir" && npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev --force && npm cache clean --force) || echo "WARN: Failed to install dependencies for $extension_name"
305
+ else
306
+ echo "--- No package.json found for $extension_name, skipping dependency install. ---"
307
+ fi || echo "WARN: Failed to clone $extension_name from $extension_url, skipping..."
308
+ done
309
+
310
+ # Reset IFS
311
+ unset IFS
312
+
313
+ # Fix permissions for extensions directory after installation
314
+ echo "--- Setting permissions for extensions directory ---"
315
+ chown -R node:node "$EXTENSIONS_DIR"
316
+
317
+ echo "*** Extensions installation finished. ***"
318
+ else
319
+ echo 'EXTENSIONS environment variable is not set or empty, skipping extensions installation.'
320
+ fi
321
+ }
322
+
323
+ # Run the extension installation in the background
324
+ install_extensions &
325
+ # --- END: Install Extensions after SillyTavern startup ---
326
+
327
+ # Keep-alive loop
328
+ while kill -0 ${SERVER_PID} 2>/dev/null; do
329
+ echo "Sending keep-alive request to ${HEALTH_CHECK_URL}"
330
+ # Use eval here as well for the keep-alive command
331
+ eval "${CURL_COMMAND} ${HEALTH_CHECK_URL}" > /dev/null || echo "Keep-alive request failed."
332
+ echo "Keep-alive request sent. Sleeping for 30 minutes."
333
+ sleep 1800
334
+ done &
335
+
336
+ wait ${SERVER_PID}