Compare commits
37
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06bde939fb | ||
|
|
7e8663cd9c | ||
|
|
61139aa9b6 | ||
|
|
5e8d463ed4 | ||
|
|
c0a417b240 | ||
|
|
cc053e8356 | ||
|
|
d6b244cd25 | ||
|
|
e7c4f8ee98 | ||
|
|
a8f7e0d900 | ||
|
|
4613abc26e | ||
|
|
dd326d244f | ||
|
|
ccd8287833 | ||
|
|
30eaf26a43 | ||
|
|
98af17a8a4 | ||
|
|
0a9ba91852 | ||
|
|
814734d4af | ||
|
|
8992872765 | ||
|
|
558d72dde2 | ||
|
|
4ad7af3c06 | ||
|
|
bcc42de2e9 | ||
|
|
b4e162324b | ||
|
|
2c61f3be1e | ||
|
|
48e7d605df | ||
|
|
12b4fc50aa | ||
|
|
742d5601be | ||
|
|
4ed1372411 | ||
|
|
86b55c8696 | ||
|
|
1a7f88861d | ||
|
|
800caeb9e0 | ||
|
|
f91050136c | ||
|
|
f199580102 | ||
|
|
eaf2858e43 | ||
|
|
1cfdcd82e1 | ||
|
|
7228502f0b | ||
|
|
4f6977b779 | ||
|
|
8172dcd0ee | ||
|
|
51ad27fb86 |
+1
-1
@@ -75,7 +75,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.**
|
||||
|
||||
* [TavernAI](https://github.com/TavernAI/TavernAI) 1.2.8 by Humi: MIT License
|
||||
* [TavernAI](https://github.com/TavernAI/TavernAI-v1) 1.2.8 by Humi: MIT License
|
||||
* Portions of CncAnon's TavernAITurbo mod used with permission
|
||||
* Visual Novel Mode inspired by the work of PepperTaco (<https://github.com/peppertaco/Tavern/>)
|
||||
* Noto Sans font by Google (OFL license)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
||||
# Publish to npm for a new release or explicitly retry an existing release tag.
|
||||
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
||||
|
||||
name: Node.js Package
|
||||
@@ -6,6 +6,16 @@ name: Node.js Package
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Existing release tag to publish
|
||||
required: true
|
||||
type: string
|
||||
|
||||
env:
|
||||
PUBLISH_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.event.release.tag_name }}
|
||||
PUBLISH_REF: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.tag) || github.ref }}
|
||||
|
||||
permissions:
|
||||
id-token: write # Required for OIDC
|
||||
@@ -16,9 +26,13 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
|
||||
with:
|
||||
ref: ${{ env.PUBLISH_REF }}
|
||||
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3
|
||||
with:
|
||||
node-version: 24
|
||||
- name: Verify release tag matches package version
|
||||
run: test "$(node -p "require('./package.json').version")" = "$PUBLISH_TAG"
|
||||
- run: npm ci --omit=dev --ignore-scripts
|
||||
|
||||
publish-npm:
|
||||
@@ -26,9 +40,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
|
||||
with:
|
||||
ref: ${{ env.PUBLISH_REF }}
|
||||
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3
|
||||
with:
|
||||
node-version: 24
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- run: npm ci --omit=dev --ignore-scripts
|
||||
- run: npm publish
|
||||
# https://github.com/npm/cli/issues/9755
|
||||
- run: npm publish --allow-directory=all
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"chat_completion_source": "openai",
|
||||
"openai_model": "gpt-4-turbo",
|
||||
"openai_model": "gpt-5.6-terra",
|
||||
"claude_model": "claude-sonnet-5",
|
||||
"openrouter_model": "OR_Website",
|
||||
"openrouter_use_fallback": false,
|
||||
@@ -20,8 +20,8 @@
|
||||
"custom_include_body": "",
|
||||
"custom_exclude_body": "",
|
||||
"custom_include_headers": "",
|
||||
"google_model": "gemini-2.5-pro",
|
||||
"vertexai_model": "gemini-2.5-pro",
|
||||
"google_model": "gemini-3.7-flash",
|
||||
"vertexai_model": "gemini-3.7-flash",
|
||||
"temperature": 1,
|
||||
"frequency_penalty": 0,
|
||||
"presence_penalty": 0,
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "sillytavern",
|
||||
"version": "1.18.0",
|
||||
"version": "1.19.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sillytavern",
|
||||
"version": "1.18.0",
|
||||
"version": "1.19.0",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"@adobe/css-tools": "^4.4.4",
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/SillyTavern/SillyTavern.git"
|
||||
},
|
||||
"version": "1.18.0",
|
||||
"version": "1.19.0",
|
||||
"scripts": {
|
||||
"init": "node src/server-init.js",
|
||||
"start": "node server.js",
|
||||
|
||||
+78
-83
@@ -2155,7 +2155,7 @@
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,claude,xai,makersuite,vertexai,aimlapi,openrouter,pollinations,perplexity,cometapi,electronhub,azure_openai,chutes,nanogpt,deepseek">
|
||||
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,claude,xai,makersuite,vertexai,aimlapi,openrouter,pollinations,perplexity,cometapi,electronhub,azure_openai,chutes,nanogpt,deepseek,fireworks">
|
||||
<div class="flex-container oneline-dropdown" title="Constrains effort on reasoning for reasoning models. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response." data-i18n="[title]Constrains effort on reasoning for reasoning models.">
|
||||
<label for="openai_reasoning_effort">
|
||||
<span data-i18n="Reasoning Effort">Reasoning Effort</span>
|
||||
@@ -2172,6 +2172,9 @@
|
||||
<div class="toggle-description justifyLeft marginBot5" data-source="openai,custom,xai,aimlapi,openrouter,pollinations,perplexity,cometapi,electronhub,azure_openai,chutes" data-i18n="OpenAI-compatible effort levels vary by model. Minimum and maximum may use model-specific aliases. Auto does not send an effort level.">
|
||||
OpenAI-compatible effort levels vary by model. Minimum and maximum may use model-specific aliases. Auto does not send an effort level.
|
||||
</div>
|
||||
<div class="toggle-description justifyLeft marginBot5" data-source="fireworks" data-i18n="Fireworks supports low, medium, high, and max as distinct effort levels. Minimum is aliased to low. Auto does not send an effort level.">
|
||||
Fireworks supports low, medium, high, and max as distinct effort levels. Minimum is aliased to low. Auto does not send an effort level.
|
||||
</div>
|
||||
<strong class="toggle-description justifyLeft marginBot5" data-source="openrouter">
|
||||
Request model reasoning = Off with Reasoning Effort = Minimum disables reasoning entirely on models that support that, but can cause errors with some models.
|
||||
</strong>
|
||||
@@ -2593,8 +2596,19 @@
|
||||
<small data-i18n="Example: http://127.0.0.1:5000">Example: http://127.0.0.1:5000</small>
|
||||
<input id="generic_api_url_text" name="generic_api_url" class="text_pole wide100p" value="" autocomplete="off" data-server-history="generic">
|
||||
</div>
|
||||
<datalist id="generic_model_fill"></datalist>
|
||||
<input id="generic_model_textgenerationwebui" list="generic_model_fill" class="text_pole wide100p" placeholder="Model ID (optional)" data-i18n="[placeholder]Model ID (optional)" type="text">
|
||||
<h4 data-i18n="Enter a Model ID">Enter a Model ID</h4>
|
||||
<div class="flex-container">
|
||||
<input list="generic_model_fill" id="generic_model_textgenerationwebui" class="text_pole wide100p" placeholder="Model ID (optional)" data-i18n="[placeholder]Model ID (optional)" type="text" autocomplete="off">
|
||||
<datalist id="generic_model_fill"></datalist>
|
||||
</div>
|
||||
<h4 data-i18n="Available Models">Available Models</h4>
|
||||
<div class="flex-container">
|
||||
<select id="generic_model_select" class="text_pole wide100p">
|
||||
<option value="" data-i18n="-- Connect to the API --">
|
||||
-- Connect to the API --
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div data-tg-type="ooba" class="flex-container flexFlowColumn">
|
||||
<div class="flex-container flexFlowColumn">
|
||||
@@ -2997,8 +3011,8 @@
|
||||
<br>
|
||||
</div>
|
||||
<div class="flex-container width100p">
|
||||
<input id="openai_proxy_password" type="password" class="text_pole flex1" placeholder="" form="openai_form" autocomplete="off" />
|
||||
<div id="openai_proxy_password_show" title="Peek a password" data-i18n="[title]Peek a password" class="menu_button fa-solid fa-eye-slash fa-fw"></div>
|
||||
<input id="openai_proxy_access_key" type="text" class="text_pole flex1 masked-secret" placeholder="" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false" />
|
||||
<div id="openai_proxy_access_key_show" title="Peek a password" data-i18n="[title]Peek a password" class="menu_button fa-solid fa-eye-slash fa-fw"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -3052,6 +3066,9 @@
|
||||
<div>
|
||||
<h4 data-i18n="OpenAI Model">OpenAI Model</h4>
|
||||
<select id="model_openai_select">
|
||||
<optgroup label="GPT-6">
|
||||
<option value="gpt-6-astra">gpt-6-astra</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-5.6">
|
||||
<option value="gpt-5.6">gpt-5.6</option>
|
||||
<option value="gpt-5.6-sol">gpt-5.6-sol</option>
|
||||
@@ -3071,12 +3088,12 @@
|
||||
<option value="gpt-5.4-nano-2026-03-17">gpt-5.4-nano-2026-03-17</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-5.3">
|
||||
<option value="gpt-5.3-chat-latest">gpt-5.3-chat-latest</option>
|
||||
<option value="gpt-5.3-chat-latest">gpt-5.3-chat-latest (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-5.2">
|
||||
<option value="gpt-5.2">gpt-5.2</option>
|
||||
<option value="gpt-5.2-2025-12-11">gpt-5.2-2025-12-11</option>
|
||||
<option value="gpt-5.2-chat-latest">gpt-5.2-chat-latest</option>
|
||||
<option value="gpt-5.2-chat-latest">gpt-5.2-chat-latest (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-5.1">
|
||||
<option value="gpt-5.1">gpt-5.1</option>
|
||||
@@ -3085,69 +3102,56 @@
|
||||
</optgroup>
|
||||
<optgroup label="GPT-5">
|
||||
<option value="gpt-5">gpt-5</option>
|
||||
<option value="gpt-5-2025-08-07">gpt-5-2025-08-07</option>
|
||||
<option value="gpt-5-2025-08-07">gpt-5-2025-08-07 (deprecated)</option>
|
||||
<option value="gpt-5-chat-latest">gpt-5-chat-latest</option>
|
||||
<option value="gpt-5-mini">gpt-5-mini</option>
|
||||
<option value="gpt-5-mini-2025-08-07">gpt-5-mini-2025-08-07</option>
|
||||
<option value="gpt-5-mini-2025-08-07">gpt-5-mini-2025-08-07 (deprecated)</option>
|
||||
<option value="gpt-5-nano">gpt-5-nano</option>
|
||||
<option value="gpt-5-nano-2025-08-07">gpt-5-nano-2025-08-07</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-4o">
|
||||
<option value="gpt-4o">gpt-4o</option>
|
||||
<option value="gpt-4o-2024-11-20">gpt-4o-2024-11-20</option>
|
||||
<option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option>
|
||||
<option value="gpt-4o-2024-05-13">gpt-4o-2024-05-13</option>
|
||||
<option value="chatgpt-4o-latest">chatgpt-4o-latest</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-4o mini">
|
||||
<option value="gpt-4o-mini">gpt-4o-mini</option>
|
||||
<option value="gpt-4o-mini-2024-07-18">gpt-4o-mini-2024-07-18</option>
|
||||
<option value="gpt-5-nano-2025-08-07">gpt-5-nano-2025-08-07 (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-4.1">
|
||||
<option value="gpt-4.1">gpt-4.1</option>
|
||||
<option value="gpt-4.1-2025-04-14">gpt-4.1-2025-04-14</option>
|
||||
<option value="gpt-4.1-mini">gpt-4.1-mini</option>
|
||||
<option value="gpt-4.1-mini-2025-04-14">gpt-4.1-mini-2025-04-14</option>
|
||||
<option value="gpt-4.1-nano">gpt-4.1-nano</option>
|
||||
<option value="gpt-4.1-nano-2025-04-14">gpt-4.1-nano-2025-04-14</option>
|
||||
<option value="gpt-4.1-nano">gpt-4.1-nano (deprecated)</option>
|
||||
<option value="gpt-4.1-nano-2025-04-14">gpt-4.1-nano-2025-04-14 (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="o1">
|
||||
<option value="o1">o1</option>
|
||||
<option value="o1-2024-12-17">o1-2024-12-17</option>
|
||||
<option value="o1-mini">o1-mini</option>
|
||||
<option value="o1-mini-2024-09-12">o1-mini-2024-09-12</option>
|
||||
<option value="o1-preview">o1-preview</option>
|
||||
<option value="o1-preview-2024-09-12">o1-preview-2024-09-12</option>
|
||||
<optgroup label="o4">
|
||||
<option value="o4-mini">o4-mini (deprecated)</option>
|
||||
<option value="o4-mini-2025-04-16">o4-mini-2025-04-16 (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="o3">
|
||||
<option value="o3">o3</option>
|
||||
<option value="o3-2025-04-16">o3-2025-04-16</option>
|
||||
<option value="o3-mini">o3-mini</option>
|
||||
<option value="o3-mini-2025-01-31">o3-mini-2025-01-31</option>
|
||||
<option value="o3-2025-04-16">o3-2025-04-16 (deprecated)</option>
|
||||
<option value="o3-mini">o3-mini (deprecated)</option>
|
||||
<option value="o3-mini-2025-01-31">o3-mini-2025-01-31 (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="o4">
|
||||
<option value="o4-mini">o4-mini</option>
|
||||
<option value="o4-mini-2025-04-16">o4-mini-2025-04-16</option>
|
||||
<optgroup label="o1">
|
||||
<option value="o1">o1 (deprecated)</option>
|
||||
<option value="o1-2024-12-17">o1-2024-12-17 (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-4.5">
|
||||
<option value="gpt-4.5-preview">gpt-4.5-preview</option>
|
||||
<option value="gpt-4.5-preview-2025-02-27">gpt-4.5-preview-2025-02-27</option>
|
||||
<optgroup label="GPT-4o">
|
||||
<option value="gpt-4o">gpt-4o</option>
|
||||
<option value="gpt-4o-2024-11-20">gpt-4o-2024-11-20</option>
|
||||
<option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option>
|
||||
<option value="gpt-4o-2024-05-13">gpt-4o-2024-05-13</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-4o mini">
|
||||
<option value="gpt-4o-mini">gpt-4o-mini</option>
|
||||
<option value="gpt-4o-mini-2024-07-18">gpt-4o-mini-2024-07-18</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-4 Turbo and GPT-4">
|
||||
<option value="gpt-4-turbo">gpt-4-turbo</option>
|
||||
<option value="gpt-4-turbo-2024-04-09">gpt-4-turbo-2024-04-09</option>
|
||||
<option value="gpt-4-turbo-preview">gpt-4-turbo-preview</option>
|
||||
<option value="gpt-4-0125-preview">gpt-4-0125-preview (2024)</option>
|
||||
<option value="gpt-4-1106-preview">gpt-4-1106-preview (2023)</option>
|
||||
<option value="gpt-4">gpt-4</option>
|
||||
<option value="gpt-4-0613">gpt-4-0613 (2023)</option>
|
||||
<option value="gpt-4-0314">gpt-4-0314 (2023)</option>
|
||||
<option value="gpt-4-turbo">gpt-4-turbo (deprecated)</option>
|
||||
<option value="gpt-4-turbo-2024-04-09">gpt-4-turbo-2024-04-09 (deprecated)</option>
|
||||
<option value="gpt-4">gpt-4 (deprecated)</option>
|
||||
<option value="gpt-4-0613">gpt-4-0613 (2023, deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="GPT-3.5 Turbo">
|
||||
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>
|
||||
<option value="gpt-3.5-turbo-0125">gpt-3.5-turbo-0125 (2024)</option>
|
||||
<option value="gpt-3.5-turbo-1106">gpt-3.5-turbo-1106 (2023)</option>
|
||||
<option value="gpt-3.5-turbo-instruct">gpt-3.5-turbo-instruct</option>
|
||||
<option value="gpt-3.5-turbo">gpt-3.5-turbo (deprecated)</option>
|
||||
<option value="gpt-3.5-turbo-0125">gpt-3.5-turbo-0125 (2024, deprecated)</option>
|
||||
<option value="gpt-3.5-turbo-1106">gpt-3.5-turbo-1106 (2023, deprecated)</option>
|
||||
<option value="gpt-3.5-turbo-instruct">gpt-3.5-turbo-instruct (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="Other">
|
||||
<option value="babbage-002">babbage-002</option>
|
||||
@@ -3182,6 +3186,7 @@
|
||||
<h4 data-i18n="Claude Model">Claude Model</h4>
|
||||
<select id="model_claude_select">
|
||||
<optgroup label="Versions">
|
||||
<option value="claude-fable-5-1">claude-fable-5-1</option>
|
||||
<option value="claude-fable-5">claude-fable-5</option>
|
||||
<option value="claude-opus-5">claude-opus-5</option>
|
||||
<option value="claude-sonnet-5">claude-sonnet-5</option>
|
||||
@@ -3306,8 +3311,15 @@
|
||||
<div>
|
||||
<h4 data-i18n="Google Model">Google Model</h4>
|
||||
<select id="model_google_select">
|
||||
<optgroup label="Gemini 3.7">
|
||||
<option value="gemini-3.7-flash">gemini-3.7-flash</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.6">
|
||||
<option value="gemini-3.6-flash">gemini-3.6-flash</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.5">
|
||||
<option value="gemini-3.5-flash">gemini-3.5-flash</option>
|
||||
<option value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.1">
|
||||
<option value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
|
||||
@@ -3315,40 +3327,20 @@
|
||||
<option value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.0">
|
||||
<option value="gemini-3-pro-preview">gemini-3-pro-preview</option>
|
||||
<option value="gemini-3-pro-image">gemini-3-pro-image</option>
|
||||
<option value="gemini-3-flash-preview">gemini-3-flash-preview</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 2.5">
|
||||
<option value="gemini-2.5-pro">gemini-2.5-pro</option>
|
||||
<option value="gemini-2.5-pro-preview-06-05">gemini-2.5-pro-preview-06-05</option>
|
||||
<option value="gemini-2.5-pro-preview-05-06">gemini-2.5-pro-preview-05-06</option>
|
||||
<option value="gemini-2.5-pro-preview-03-25">gemini-2.5-pro-preview-03-25</option>
|
||||
<option value="gemini-2.5-flash">gemini-2.5-flash</option>
|
||||
<option value="gemini-2.5-flash-preview-09-2025">gemini-2.5-flash-preview-09-2025</option>
|
||||
<option value="gemini-2.5-flash-preview-05-20">gemini-2.5-flash-preview-05-20</option>
|
||||
<option value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
|
||||
<option value="gemini-2.5-flash-lite-preview-09-2025">gemini-2.5-flash-lite-preview-09-2025</option>
|
||||
<option value="gemini-2.5-flash-lite-preview-06-17">gemini-2.5-flash-lite-preview-06-17</option>
|
||||
<option value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
|
||||
<option value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 2.0">
|
||||
<option value="gemini-2.0-pro-exp-02-05">gemini-2.0-pro-exp-02-05 → 2.5-exp-03-25</option>
|
||||
<option value="gemini-2.0-pro-exp">gemini-2.0-pro-exp → 2.5-exp-03-25</option>
|
||||
<option value="gemini-exp-1206">gemini-exp-1206 → 2.5-exp-03-25</option>
|
||||
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
|
||||
<option value="gemini-2.0-flash-exp-image-generation">gemini-2.0-flash-exp-image-generation</option>
|
||||
<option value="gemini-2.0-flash-preview-image-generation">gemini-2.0-flash-preview-image-generation</option>
|
||||
<option value="gemini-2.0-flash-exp">gemini-2.0-flash-exp</option>
|
||||
<option value="gemini-2.0-flash">gemini-2.0-flash</option>
|
||||
<option value="gemini-2.0-flash-thinking-exp-01-21">gemini-2.0-flash-thinking-exp-01-21 → 2.5-flash-preview-05-20</option>
|
||||
<option value="gemini-2.0-flash-thinking-exp-1219">gemini-2.0-flash-thinking-exp-1219 → 2.5-flash-preview-05-20</option>
|
||||
<option value="gemini-2.0-flash-thinking-exp">gemini-2.0-flash-thinking-exp → 2.5-flash-preview-05-20</option>
|
||||
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
|
||||
<option value="gemini-2.0-flash-lite-preview-02-05">gemini-2.0-flash-lite-preview-02-05</option>
|
||||
<option value="gemini-2.0-flash-lite-preview">gemini-2.0-flash-lite-preview</option>
|
||||
<option value="gemini-2.0-flash-lite">gemini-2.0-flash-lite</option>
|
||||
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
|
||||
<option value="gemini-2.0-flash">gemini-2.0-flash (deprecated)</option>
|
||||
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
|
||||
<option value="gemini-2.0-flash-lite">gemini-2.0-flash-lite (deprecated)</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemma">
|
||||
<option value="gemma-4-31b-it">gemma-4-31b-it</option>
|
||||
@@ -3489,8 +3481,15 @@
|
||||
<h4 data-i18n="Google Model">Google Model</h4>
|
||||
<select id="model_vertexai_select">
|
||||
<!-- data-mode="full" is for models that require a service account -->
|
||||
<optgroup label="Gemini 3.7">
|
||||
<option value="gemini-3.7-flash">gemini-3.7-flash</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.6">
|
||||
<option value="gemini-3.6-flash">gemini-3.6-flash</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.5">
|
||||
<option value="gemini-3.5-flash">gemini-3.5-flash</option>
|
||||
<option value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.1">
|
||||
<option value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
|
||||
@@ -3498,7 +3497,6 @@
|
||||
<option value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 3.0">
|
||||
<option value="gemini-3-pro-preview">gemini-3-pro-preview</option>
|
||||
<option value="gemini-3-pro-image">gemini-3-pro-image</option>
|
||||
<option value="gemini-3-flash-preview">gemini-3-flash-preview</option>
|
||||
</optgroup>
|
||||
@@ -3507,14 +3505,11 @@
|
||||
<option value="gemini-2.5-flash">gemini-2.5-flash</option>
|
||||
<option value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
|
||||
<option value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
|
||||
<option value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
|
||||
</optgroup>
|
||||
<optgroup label="Gemini 2.0">
|
||||
<option value="gemini-2.0-flash-exp" data-mode="full">gemini-2.0-flash-exp</option>
|
||||
<option value="gemini-2.0-flash-preview-image-generation" data-mode="full">gemini-2.0-flash-preview-image-generation</option>
|
||||
<option value="gemini-2.0-flash">gemini-2.0-flash</option>
|
||||
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
|
||||
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
|
||||
<option value="gemini-2.0-flash">gemini-2.0-flash (deprecated)</option>
|
||||
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
|
||||
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
@@ -3997,7 +3992,7 @@
|
||||
<!-- Azure API Key -->
|
||||
<h4><span data-i18n="Azure API Key">Azure API Key</span></h4>
|
||||
<div class="flex-container">
|
||||
<input id="api_key_azure_openai" data-setting="api_key_azure_openai" class="text_pole flex1" type="password" autocomplete="off">
|
||||
<input id="api_key_azure_openai" data-setting="api_key_azure_openai" class="text_pole flex1" type="text" autocomplete="off">
|
||||
<div title="Manage API keys" data-i18n="[title]Manage API keys" class="menu_button fa-solid fa-key fa-fw manage-api-keys" data-key="api_key_azure_openai"></div>
|
||||
</div>
|
||||
<div class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you click 'Connect'." data-for="api_key_azure_openai">
|
||||
|
||||
+36
-7
@@ -604,6 +604,7 @@ export let is_send_press = false; //Send generation
|
||||
export const isGenerating = () => (is_send_press || is_group_generating);
|
||||
|
||||
let this_del_mes = -1;
|
||||
let deleteToolCallsInDeleteMode = true;
|
||||
|
||||
/** @type {string} */
|
||||
let this_edit_mes_chname = '';
|
||||
@@ -1610,13 +1611,32 @@ export async function deleteLastMessage() {
|
||||
await eventSource.emit(event_types.MESSAGE_DELETED, chat.length);
|
||||
}
|
||||
|
||||
function getMessageDeletionStartId(id, deleteToolCalls = true) {
|
||||
const message = chat[id];
|
||||
if (!deleteToolCalls || message?.is_user || message?.is_system) {
|
||||
return id;
|
||||
}
|
||||
|
||||
let startId = id;
|
||||
while (startId > 0) {
|
||||
const previousMessage = chat[startId - 1];
|
||||
if (!previousMessage?.is_system || !Array.isArray(previousMessage.extra?.tool_invocations)) {
|
||||
break;
|
||||
}
|
||||
startId--;
|
||||
}
|
||||
|
||||
return startId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a message from the chat by its ID, optionally asking for confirmation.
|
||||
* @param {number} id The ID of the message to delete.
|
||||
* @param {number} [swipeDeletionIndex] Deletes the swipe with that index.
|
||||
* @param {boolean} [askConfirmation=false] Whether to ask for confirmation before deleting.
|
||||
* @param {boolean} [deleteToolCalls=true] Whether to delete preceding tool-call messages.
|
||||
*/
|
||||
export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfirmation = false) {
|
||||
export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfirmation = false, deleteToolCalls = true) {
|
||||
const canDeleteSwipe = swipeDeletionIndex !== undefined && swipeDeletionIndex !== null;
|
||||
if (canDeleteSwipe) {
|
||||
if (swipeDeletionIndex < 0) {
|
||||
@@ -1654,13 +1674,19 @@ export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfi
|
||||
return;
|
||||
}
|
||||
|
||||
chat.splice(id, 1);
|
||||
messageElement.remove();
|
||||
const firstMessageId = getMessageDeletionStartId(id, deleteToolCalls);
|
||||
const messageIds = Array.from({ length: id - firstMessageId + 1 }, (_, index) => id - index);
|
||||
|
||||
// Delete from the end so earlier indices remain stable.
|
||||
for (const messageId of messageIds) {
|
||||
chat.splice(messageId, 1);
|
||||
chatElement.find(`.mes[mesid="${messageId}"]`).remove();
|
||||
deleteItemizedPromptForMessage(messageId);
|
||||
}
|
||||
|
||||
chat_metadata.tainted = true;
|
||||
|
||||
const startIndex = [0, minId].includes(id) ? id : null;
|
||||
deleteItemizedPromptForMessage(id);
|
||||
const startIndex = firstMessageId <= minId ? firstMessageId : null;
|
||||
updateViewMessageIds(startIndex);
|
||||
saveChatDebounced();
|
||||
|
||||
@@ -8166,7 +8192,7 @@ function updateMessage(div) {
|
||||
return { mesBlock, text, mes, bias };
|
||||
}
|
||||
|
||||
function openMessageDelete(fromSlashCommand) {
|
||||
function openMessageDelete(fromSlashCommand, deleteToolCalls = true) {
|
||||
closeMessageEditor();
|
||||
hideSwipeButtons();
|
||||
if (fromSlashCommand || (!is_send_press) || (selected_group && !is_group_generating)) {
|
||||
@@ -8185,6 +8211,7 @@ function openMessageDelete(fromSlashCommand) {
|
||||
is_group_generating: ${is_group_generating}`);
|
||||
}
|
||||
this_del_mes = -1;
|
||||
deleteToolCallsInDeleteMode = deleteToolCalls;
|
||||
is_delete_mode = true;
|
||||
}
|
||||
|
||||
@@ -11229,6 +11256,7 @@ jQuery(async function () {
|
||||
});
|
||||
$(this).addClass('selected'); //sets the bg of the mes selected for deletion
|
||||
var i = Number($(this).attr('mesid')); //checks the message ID in the chat
|
||||
i = getMessageDeletionStartId(i, deleteToolCallsInDeleteMode);
|
||||
this_del_mes = i;
|
||||
//as long as the current message ID is less than the total chat length
|
||||
while (i < chat.length) {
|
||||
@@ -11553,6 +11581,7 @@ jQuery(async function () {
|
||||
///////////// OPTIMIZED LISTENERS FOR LEFT SIDE OPTIONS POPUP MENU //////////////////////
|
||||
$('#options [id]').on('click', async function (event, customData) {
|
||||
const fromSlashCommand = customData?.fromSlashCommand || false;
|
||||
const deleteToolCalls = customData?.deleteToolCalls ?? true;
|
||||
var id = $(this).attr('id');
|
||||
|
||||
// Check whether a custom prompt was provided via custom data (for example through a slash command)
|
||||
@@ -11631,7 +11660,7 @@ jQuery(async function () {
|
||||
Generate('continue', buildOrFillAdditionalArgs());
|
||||
}
|
||||
} else if (id == 'option_delete_mes') {
|
||||
setTimeout(() => openMessageDelete(fromSlashCommand), animation_duration);
|
||||
setTimeout(() => openMessageDelete(fromSlashCommand, deleteToolCalls), animation_duration);
|
||||
} else if (id == 'option_close_chat') {
|
||||
await closeCurrentChat();
|
||||
} else if (id === 'option_settings') {
|
||||
|
||||
@@ -41,6 +41,7 @@ import { t } from './i18n.js';
|
||||
import {
|
||||
getUniqueName,
|
||||
isTrueBoolean,
|
||||
uuidv4,
|
||||
} from './utils.js';
|
||||
|
||||
const bookmarkNameToken = 'Checkpoint #';
|
||||
@@ -196,7 +197,8 @@ export async function createBranch(mesId, { swipeId = null } = {}) {
|
||||
|
||||
const lastMes = chat[mesId];
|
||||
const mainChatName = (getCurrentChatDetails()).sessionName;
|
||||
const newMetadata = { main_chat: mainChatName };
|
||||
// Mint a fresh integrity slug so the branch is distinguishable from its parent (#5942)
|
||||
const newMetadata = { main_chat: mainChatName, integrity: uuidv4() };
|
||||
const selectedSwipeId = swipeId === null ? null : Number(swipeId);
|
||||
|
||||
if (selectedSwipeId !== null && (!Number.isInteger(selectedSwipeId) || selectedSwipeId < 0 || selectedSwipeId >= (lastMes?.swipes?.length ?? 0))) {
|
||||
@@ -278,7 +280,8 @@ export async function createNewBookmark(mesId, { forceName = null } = {}) {
|
||||
}
|
||||
|
||||
const mainChat = selected_group ? groups?.find(x => x.id == selected_group)?.chat_id : characters[this_chid].chat;
|
||||
const newMetadata = { main_chat: mainChat };
|
||||
// Mint a fresh integrity slug so the checkpoint is distinguishable from its parent (#5942)
|
||||
const newMetadata = { main_chat: mainChat, integrity: uuidv4() };
|
||||
await saveItemizedPrompts(name);
|
||||
|
||||
if (selected_group) {
|
||||
|
||||
@@ -1797,6 +1797,15 @@ export async function loadExtensionSettings(settings, versionChanged, enableAuto
|
||||
extensionTypes = Object.fromEntries(extensions.map(x => [x.name, x.type]));
|
||||
manifests = await getManifests(extensionNames);
|
||||
|
||||
// An extension without a loadable manifest cannot be used: drop it so state queries
|
||||
// and the extensions list do not report a ghost entry (e.g. leftover folder on disk)
|
||||
const namesWithoutManifest = extensionNames.filter(name => !Object.hasOwn(manifests, name));
|
||||
if (namesWithoutManifest.length) {
|
||||
console.warn('Ignoring extensions without a loadable manifest.json:', namesWithoutManifest);
|
||||
extensionNames = extensionNames.filter(name => Object.hasOwn(manifests, name));
|
||||
namesWithoutManifest.forEach(name => delete extensionTypes[name]);
|
||||
}
|
||||
|
||||
if (versionChanged && enableAutoUpdate) {
|
||||
await autoUpdateExtensions(false);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ function migrateSettings() {
|
||||
if (extension_settings.caption.source === 'openai') {
|
||||
extension_settings.caption.source = 'multimodal';
|
||||
extension_settings.caption.multimodal_api = 'openai';
|
||||
extension_settings.caption.multimodal_model = 'gpt-4-turbo';
|
||||
extension_settings.caption.multimodal_model = 'gpt-5.6-luna';
|
||||
}
|
||||
|
||||
if (['google', 'vertexai'].includes(extension_settings.caption.multimodal_api)) {
|
||||
@@ -55,7 +55,7 @@ function migrateSettings() {
|
||||
}
|
||||
|
||||
if (!extension_settings.caption.multimodal_model) {
|
||||
extension_settings.caption.multimodal_model = 'gpt-4-turbo';
|
||||
extension_settings.caption.multimodal_model = 'gpt-5.6-luna';
|
||||
}
|
||||
|
||||
if (!extension_settings.caption.prompt) {
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<option data-type="cohere" value="c4ai-aya-vision-8b">c4ai-aya-vision-8b</option>
|
||||
<option data-type="cohere" value="c4ai-aya-vision-32b">c4ai-aya-vision-32b</option>
|
||||
<option data-type="cohere" value="command-a-vision-07-2025">command-a-vision-07-2025</option>
|
||||
<option data-type="openai" value="gpt-6-astra">gpt-6-astra</option>
|
||||
<option data-type="openai" value="gpt-5.6">gpt-5.6</option>
|
||||
<option data-type="openai" value="gpt-5.6-sol">gpt-5.6-sol</option>
|
||||
<option data-type="openai" value="gpt-5.6-terra">gpt-5.6-terra</option>
|
||||
@@ -86,20 +87,17 @@
|
||||
<option data-type="openai" value="gpt-4.1-mini-2025-04-14">gpt-4.1-mini-2025-04-14</option>
|
||||
<option data-type="openai" value="gpt-4.1-nano">gpt-4.1-nano</option>
|
||||
<option data-type="openai" value="gpt-4.1-nano-2025-04-14">gpt-4.1-nano-2025-04-14</option>
|
||||
<option data-type="openai" value="gpt-4-vision-preview">gpt-4-vision-preview</option>
|
||||
<option data-type="openai" value="gpt-4-turbo">gpt-4-turbo</option>
|
||||
<option data-type="openai" value="gpt-4o">gpt-4o</option>
|
||||
<option data-type="openai" value="gpt-4o-mini">gpt-4o-mini</option>
|
||||
<option data-type="openai" value="gpt-4o-mini-2024-07-18">gpt-4o-mini-2024-07-18</option>
|
||||
<option data-type="openai" value="chatgpt-4o-latest">chatgpt-4o-latest</option>
|
||||
<option data-type="openai" value="o1">o1</option>
|
||||
<option data-type="openai" value="o1-2024-12-17">o1-2024-12-17</option>
|
||||
<option data-type="openai" value="o3">o3</option>
|
||||
<option data-type="openai" value="o3-2025-04-16">o3-2025-04-16</option>
|
||||
<option data-type="openai" value="o4-mini">o4-mini</option>
|
||||
<option data-type="openai" value="o4-mini-2025-04-16">o4-mini-2025-04-16</option>
|
||||
<option data-type="openai" value="gpt-4.5-preview">gpt-4.5-preview</option>
|
||||
<option data-type="openai" value="gpt-4.5-preview-2025-02-27">gpt-4.5-preview-2025-02-27</option>
|
||||
<option data-type="anthropic" value="claude-fable-5-1">claude-fable-5-1</option>
|
||||
<option data-type="anthropic" value="claude-fable-5">claude-fable-5</option>
|
||||
<option data-type="anthropic" value="claude-opus-5">claude-opus-5</option>
|
||||
<option data-type="anthropic" value="claude-sonnet-5">claude-sonnet-5</option>
|
||||
@@ -117,38 +115,22 @@
|
||||
<option data-type="anthropic" value="claude-opus-4-20250514">claude-opus-4-20250514</option>
|
||||
<option data-type="anthropic" value="claude-sonnet-4-0">claude-sonnet-4-0</option>
|
||||
<option data-type="anthropic" value="claude-sonnet-4-20250514">claude-sonnet-4-20250514</option>
|
||||
<option data-type="google" value="gemini-3.7-flash">gemini-3.7-flash</option>
|
||||
<option data-type="google" value="gemini-3.6-flash">gemini-3.6-flash</option>
|
||||
<option data-type="google" value="gemini-3.5-flash">gemini-3.5-flash</option>
|
||||
<option data-type="google" value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
|
||||
<option data-type="google" value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
|
||||
<option data-type="google" value="gemini-3.1-flash-lite">gemini-3.1-flash-lite</option>
|
||||
<option data-type="google" value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
|
||||
<option data-type="google" value="gemini-3-pro-preview">gemini-3-pro-preview</option>
|
||||
<option data-type="google" value="gemini-3-pro-image">gemini-3-pro-image</option>
|
||||
<option data-type="google" value="gemini-3-flash-preview">gemini-3-flash-preview</option>
|
||||
<option data-type="google" value="gemini-2.5-pro">gemini-2.5-pro</option>
|
||||
<option data-type="google" value="gemini-2.5-pro-preview-06-05">gemini-2.5-pro-preview-06-05</option>
|
||||
<option data-type="google" value="gemini-2.5-pro-preview-05-06">gemini-2.5-pro-preview-05-06</option>
|
||||
<option data-type="google" value="gemini-2.5-pro-preview-03-25">gemini-2.5-pro-preview-03-25</option>
|
||||
<option data-type="google" value="gemini-2.5-flash">gemini-2.5-flash</option>
|
||||
<option data-type="google" value="gemini-2.5-flash-preview-09-2025">gemini-2.5-flash-preview-09-2025</option>
|
||||
<option data-type="google" value="gemini-2.5-flash-preview-05-20">gemini-2.5-flash-preview-05-20</option>
|
||||
<option data-type="google" value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
|
||||
<option data-type="google" value="gemini-2.5-flash-lite-preview-09-2025">gemini-2.5-flash-lite-preview-09-2025</option>
|
||||
<option data-type="google" value="gemini-2.5-flash-lite-preview-06-17">gemini-2.5-flash-lite-preview-06-17</option>
|
||||
<option data-type="google" value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
|
||||
<option data-type="google" value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
|
||||
<option data-type="google" value="gemini-2.0-pro-exp-02-05">gemini-2.0-pro-exp-02-05 → 2.5-exp-03-25</option>
|
||||
<option data-type="google" value="gemini-2.0-pro-exp">gemini-2.0-pro-exp → 2.5-exp-03-25</option>
|
||||
<option data-type="google" value="gemini-exp-1206">gemini-exp-1206 → 2.5-exp-03-25</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-exp-image-generation">gemini-2.0-flash-exp-image-generation</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-exp">gemini-2.0-flash-exp</option>
|
||||
<option data-type="google" value="gemini-2.0-flash">gemini-2.0-flash</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-thinking-exp-01-21">gemini-2.0-flash-thinking-exp-01-21 → 2.5-flash-preview-5-20</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-thinking-exp-1219">gemini-2.0-flash-thinking-exp-1219 → 2.5-flash-preview-05-20</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-thinking-exp">gemini-2.0-flash-thinking-exp → 2.5-flash-preview-05-20</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-lite-preview-02-05">gemini-2.0-flash-lite-preview-02-05</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-lite-preview">gemini-2.0-flash-lite-preview</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
|
||||
<option data-type="google" value="gemini-2.0-flash">gemini-2.0-flash (deprecated)</option>
|
||||
<option data-type="google" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
|
||||
<option data-type="google" value="learnlm-2.0-flash-experimental">learnlm-2.0-flash-experimental</option>
|
||||
<option data-type="google" value="gemini-robotics-er-1.5-preview">gemini-robotics-er-1.5-preview</option>
|
||||
<option data-type="google" value="gemma-4-31b-it">gemma-4-31b-it</option>
|
||||
@@ -156,20 +138,21 @@
|
||||
<option data-type="google" value="gemma-3-27b-it">gemma-3-27b-it</option>
|
||||
<option data-type="google" value="gemma-3-12b-it">gemma-3-12b-it</option>
|
||||
<option data-type="google" value="gemma-3-4b-it">gemma-3-4b-it</option>
|
||||
<option data-type="vertexai" value="gemini-3.7-flash">gemini-3.7-flash</option>
|
||||
<option data-type="vertexai" value="gemini-3.6-flash">gemini-3.6-flash</option>
|
||||
<option data-type="vertexai" value="gemini-3.5-flash">gemini-3.5-flash</option>
|
||||
<option data-type="vertexai" value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
|
||||
<option data-type="vertexai" value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
|
||||
<option data-type="vertexai" value="gemini-3.1-flash-lite">gemini-3.1-flash-lite</option>
|
||||
<option data-type="vertexai" value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
|
||||
<option data-type="vertexai" value="gemini-3-pro-preview">gemini-3-pro-preview</option>
|
||||
<option data-type="vertexai" value="gemini-3-pro-image">gemini-3-pro-image</option>
|
||||
<option data-type="vertexai" value="gemini-3-flash-preview">gemini-3-flash-preview</option>
|
||||
<option data-type="vertexai" value="gemini-2.5-pro">gemini-2.5-pro</option>
|
||||
<option data-type="vertexai" value="gemini-2.5-flash">gemini-2.5-flash</option>
|
||||
<option data-type="vertexai" value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
|
||||
<option data-type="vertexai" value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
|
||||
<option data-type="vertexai" value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
|
||||
<option data-type="vertexai" value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
|
||||
<option data-type="vertexai" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
|
||||
<option data-type="vertexai" value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
|
||||
<option data-type="vertexai" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
|
||||
<option data-type="groq" value="meta-llama/llama-4-scout-17b-16e-instruct">meta-llama/llama-4-scout-17b-16e-instruct</option>
|
||||
<option data-type="groq" value="meta-llama/llama-4-maverick-17b-128e-instruct">meta-llama/llama-4-maverick-17b-128e-instruct</option>
|
||||
<option data-type="ollama" value="ollama_current" data-i18n="currently_selected">[Currently selected]</option>
|
||||
|
||||
@@ -1717,8 +1717,10 @@ async function setExpression(spriteFolderName, expression, { force = false, over
|
||||
* @param {string} expression - The expression label to use for the default image
|
||||
*/
|
||||
function setDefaultEmojiForImage(img, expression) {
|
||||
if (extension_settings.expressions.custom?.includes(expression)) {
|
||||
console.debug(`Can't set default emoji for a custom expression (${expression}). setting to ${DEFAULT_FALLBACK_EXPRESSION} instead.`);
|
||||
// Classifiers can return a falsy, literal "null"/"undefined", or otherwise unknown label,
|
||||
// and custom expressions have no default assets; only known labels have an image (#5863).
|
||||
if (!DEFAULT_EXPRESSIONS.includes(expression)) {
|
||||
console.debug(`Can't set default emoji for expression (${expression}). setting to ${DEFAULT_FALLBACK_EXPRESSION} instead.`);
|
||||
expression = DEFAULT_FALLBACK_EXPRESSION;
|
||||
}
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ export class SettingsUi {
|
||||
if (name && name.length > 0) {
|
||||
const oldQrs = QuickReplySet.get(name);
|
||||
if (oldQrs) {
|
||||
const replace = Popup.show.confirm('Replace existing Quick Reply set', `A Quick Reply Set named "${name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
|
||||
const replace = await Popup.show.confirm('Replace existing Quick Reply set', `A Quick Reply Set named "${name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
|
||||
if (replace) {
|
||||
const idx = QuickReplySet.list.indexOf(oldQrs);
|
||||
await this.doDeleteQrSet(oldQrs);
|
||||
@@ -444,7 +444,7 @@ export class SettingsUi {
|
||||
qrs.init();
|
||||
const oldQrs = QuickReplySet.get(props.name);
|
||||
if (oldQrs) {
|
||||
const replace = Popup.show.confirm('Replace existing Quick Reply set', `A Quick Reply Set named "${name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
|
||||
const replace = await Popup.show.confirm('Replace existing Quick Reply set', `A Quick Reply Set named "${props.name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
|
||||
if (replace) {
|
||||
const idx = QuickReplySet.list.indexOf(oldQrs);
|
||||
await this.doDeleteQrSet(oldQrs);
|
||||
|
||||
@@ -55,10 +55,6 @@ class MiniMaxTtsProvider {
|
||||
<i class="fa-solid fa-key"></i>
|
||||
<span>Click to set API Key</span>
|
||||
</div>
|
||||
<div id="minimax_group_id" class="menu_button menu_button_icon manage-api-keys" data-key="minimax_group_id">
|
||||
<i class="fa-solid fa-key"></i>
|
||||
<span>Click to set Group ID</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tts_block">
|
||||
<label for="minimax_tts_api_host">API Host</label>
|
||||
@@ -173,9 +169,8 @@ class MiniMaxTtsProvider {
|
||||
|
||||
constructor() {
|
||||
this.handler = async function (/** @type {string} */ key) {
|
||||
if (![SECRET_KEYS.MINIMAX, SECRET_KEYS.MINIMAX_GROUP_ID].includes(key)) return;
|
||||
if (key !== SECRET_KEYS.MINIMAX) return;
|
||||
$('#api_key_minimax').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX]);
|
||||
$('#minimax_group_id').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]);
|
||||
await this.onRefreshClick();
|
||||
}.bind(this);
|
||||
}
|
||||
@@ -588,13 +583,12 @@ class MiniMaxTtsProvider {
|
||||
}
|
||||
|
||||
$('#api_key_minimax').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX]);
|
||||
$('#minimax_group_id').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]);
|
||||
[event_types.SECRET_WRITTEN, event_types.SECRET_DELETED, event_types.SECRET_ROTATED].forEach(event => {
|
||||
eventSource.on(event, this.handler);
|
||||
});
|
||||
|
||||
// Only check ready status when API credentials are available
|
||||
if (secret_state[SECRET_KEYS.MINIMAX] && secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
|
||||
if (secret_state[SECRET_KEYS.MINIMAX]) {
|
||||
try {
|
||||
await this.checkReady();
|
||||
console.debug('MiniMax TTS: Settings loaded and ready');
|
||||
@@ -608,8 +602,8 @@ class MiniMaxTtsProvider {
|
||||
|
||||
// Perform a simple readiness check
|
||||
async checkReady() {
|
||||
if (!secret_state[SECRET_KEYS.MINIMAX] || !secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
|
||||
const error = new Error('API Key and Group ID are required');
|
||||
if (!secret_state[SECRET_KEYS.MINIMAX]) {
|
||||
const error = new Error('API Key is required');
|
||||
console.error('MiniMax TTS checkReady error:', error.message);
|
||||
throw error;
|
||||
}
|
||||
@@ -709,8 +703,8 @@ class MiniMaxTtsProvider {
|
||||
|
||||
async fetchTtsVoiceObjects() {
|
||||
try {
|
||||
if (!secret_state[SECRET_KEYS.MINIMAX] || !secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
|
||||
console.warn('MiniMax TTS: API Key and Group ID required for fetching voices');
|
||||
if (!secret_state[SECRET_KEYS.MINIMAX]) {
|
||||
console.warn('MiniMax TTS: API Key required for fetching voices');
|
||||
console.warn('Using all available voices (default + custom). Please check your API credentials');
|
||||
return this.getAllVoices();
|
||||
}
|
||||
@@ -775,8 +769,8 @@ class MiniMaxTtsProvider {
|
||||
async fetchTtsGeneration(inputText, voiceId, language = null) {
|
||||
console.info(`Generating new MiniMax TTS for voice_id ${voiceId}`);
|
||||
|
||||
if (!secret_state[SECRET_KEYS.MINIMAX] || !secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
|
||||
const error = new Error('API Key and Group ID are required');
|
||||
if (!secret_state[SECRET_KEYS.MINIMAX]) {
|
||||
const error = new Error('API Key is required');
|
||||
console.error('MiniMax TTS fetchTtsGeneration error:', error.message);
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -1908,13 +1908,14 @@ async function uploadGroupAvatar(event) {
|
||||
|
||||
$('#dialogue_popup').addClass('large_dialogue_popup wide_dialogue_popup');
|
||||
|
||||
const croppedImage = await callGenericPopup('Set the crop position of the avatar image', POPUP_TYPE.CROP, '', { cropImage: result });
|
||||
const croppedImage = power_user.never_resize_avatars ? result :
|
||||
await callGenericPopup('Set the crop position of the avatar image', POPUP_TYPE.CROP, '', { cropImage: result });
|
||||
|
||||
if (!croppedImage) {
|
||||
return;
|
||||
}
|
||||
|
||||
let thumbnail = await createThumbnail(String(croppedImage), 200, 300);
|
||||
let thumbnail = await createThumbnail(String(croppedImage), 300, 300);
|
||||
//remove data:image/whatever;base64
|
||||
thumbnail = thumbnail.replace(/^data:image\/[a-z]+;base64,/, '');
|
||||
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
||||
|
||||
@@ -205,7 +205,7 @@ export function loadNovelPreset(preset) {
|
||||
nai_settings.logit_bias = preset.logit_bias || [];
|
||||
nai_settings.preamble = preset.preamble || default_preamble;
|
||||
nai_settings.min_p = preset.min_p || 0;
|
||||
nai_settings.math1_temp = preset.math1_temp || 1;
|
||||
nai_settings.math1_temp = preset.math1_temp ?? 1;
|
||||
nai_settings.math1_quad = preset.math1_quad || 0;
|
||||
nai_settings.math1_quad_entropy_scale = preset.math1_quad_entropy_scale || 0;
|
||||
nai_settings.extensions = preset.extensions || {};
|
||||
@@ -259,7 +259,7 @@ export function loadNovelSettings(data, settings) {
|
||||
nai_settings.order = settings.order || default_order;
|
||||
nai_settings.logit_bias = settings.logit_bias || [];
|
||||
nai_settings.min_p = settings.min_p || 0;
|
||||
nai_settings.math1_temp = settings.math1_temp || 1;
|
||||
nai_settings.math1_temp = settings.math1_temp ?? 1;
|
||||
nai_settings.math1_quad = settings.math1_quad || 0;
|
||||
nai_settings.math1_quad_entropy_scale = settings.math1_quad_entropy_scale || 0;
|
||||
nai_settings.extensions = settings.extensions || {};
|
||||
|
||||
+97
-28
@@ -14,6 +14,7 @@ import {
|
||||
extension_prompt_roles,
|
||||
extension_prompt_types,
|
||||
Generate,
|
||||
getCurrentChatId,
|
||||
getExtensionPrompt,
|
||||
getExtensionPromptMaxDepth,
|
||||
getMediaDisplay,
|
||||
@@ -376,7 +377,7 @@ export const settingsToUpdate = {
|
||||
prompts: ['', 'prompts', false, false],
|
||||
prompt_order: ['', 'prompt_order', false, false],
|
||||
show_external_models: ['#openai_show_external_models', 'show_external_models', true, true],
|
||||
proxy_password: ['#openai_proxy_password', 'proxy_password', false, true],
|
||||
proxy_password: ['#openai_proxy_access_key', 'proxy_password', false, true],
|
||||
assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false, false],
|
||||
assistant_impersonation: ['#claude_assistant_impersonation', 'assistant_impersonation', false, false],
|
||||
use_sysprompt: ['#use_sysprompt', 'use_sysprompt', true, false],
|
||||
@@ -436,10 +437,10 @@ const default_settings = {
|
||||
personality_format: default_personality_format,
|
||||
sort_models: 'alphabetically',
|
||||
group_models: false,
|
||||
openai_model: 'gpt-4-turbo',
|
||||
openai_model: 'gpt-5.6-terra',
|
||||
claude_model: 'claude-sonnet-5',
|
||||
google_model: 'gemini-2.5-pro',
|
||||
vertexai_model: 'gemini-2.5-pro',
|
||||
google_model: 'gemini-3.7-flash',
|
||||
vertexai_model: 'gemini-3.7-flash',
|
||||
ai21_model: 'jamba-large',
|
||||
mistralai_model: 'mistral-large-latest',
|
||||
cohere_model: 'command-r-plus',
|
||||
@@ -1622,6 +1623,21 @@ export async function prepareOpenAIMessages({
|
||||
return [chat, promptManager.tokenHandler.counts];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a human-readable message from a Chat Completion error response.
|
||||
* Providers can return an error object without a message field, or the error as
|
||||
* a plain string. statusText is only used for non-2xx responses, since for an
|
||||
* HTTP 200 carrying an error payload it is just "OK" (#5647).
|
||||
* @param {object} data Parsed response body
|
||||
* @param {Response} response Fetch response
|
||||
* @returns {string} Error message to display and throw
|
||||
*/
|
||||
function getChatCompletionErrorMessage(data, response) {
|
||||
const error = data?.error ?? data?.detail?.error;
|
||||
const message = typeof error === 'string' ? error : (error?.message || error?.code || error?.type);
|
||||
return String(message || (!response.ok && response.statusText) || t`Unknown error`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles errors during streaming requests.
|
||||
* @param {Response} response
|
||||
@@ -1644,7 +1660,7 @@ export function tryParseStreamingError(response, decoded, { quiet = false } = {}
|
||||
// if trying to fix "[object Object]" displayed to users, start here
|
||||
|
||||
if (data.error) {
|
||||
!quiet && toastr.error(data.error.message || response.statusText, 'Chat Completion API');
|
||||
!quiet && toastr.error(getChatCompletionErrorMessage(data, response), 'Chat Completion API');
|
||||
throw new Error(data);
|
||||
}
|
||||
|
||||
@@ -1654,7 +1670,7 @@ export function tryParseStreamingError(response, decoded, { quiet = false } = {}
|
||||
}
|
||||
|
||||
if (data.detail) {
|
||||
!quiet && toastr.error(data.detail?.error?.message || response.statusText, 'Chat Completion API');
|
||||
!quiet && toastr.error(getChatCompletionErrorMessage(data, response), 'Chat Completion API');
|
||||
throw new Error(data);
|
||||
}
|
||||
} catch {
|
||||
@@ -2289,14 +2305,12 @@ function saveModelList(data) {
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.FIREWORKS) {
|
||||
$('#model_fireworks_select').empty();
|
||||
model_list.sort((a, b) => (a?.name || a?.id || '').localeCompare(b?.name || b?.id || ''));
|
||||
model_list.forEach((model) => {
|
||||
if (!model?.supports_chat) {
|
||||
return;
|
||||
}
|
||||
$('#model_fireworks_select').append(
|
||||
$('<option>', {
|
||||
value: model.id,
|
||||
text: model.id,
|
||||
text: model.name || model.id,
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -2546,6 +2560,7 @@ function getReasoningEffort(settings = null, model = null) {
|
||||
chat_completion_sources.ELECTRONHUB,
|
||||
chat_completion_sources.CHUTES,
|
||||
chat_completion_sources.DEEPSEEK,
|
||||
chat_completion_sources.FIREWORKS,
|
||||
];
|
||||
|
||||
if (!reasoningEffortSources.includes(settings.chat_completion_source)) {
|
||||
@@ -2567,6 +2582,17 @@ function getReasoningEffort(settings = null, model = null) {
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.chat_completion_source === chat_completion_sources.FIREWORKS) {
|
||||
switch (settings.reasoning_effort) {
|
||||
case reasoning_effort_types.auto:
|
||||
return undefined;
|
||||
case reasoning_effort_types.min:
|
||||
return reasoning_effort_types.low;
|
||||
default:
|
||||
return settings.reasoning_effort;
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.chat_completion_source === chat_completion_sources.CUSTOM && /^koboldcpp\/(.+)$/.test(model)) {
|
||||
switch (settings.reasoning_effort) {
|
||||
case reasoning_effort_types.auto:
|
||||
@@ -2605,6 +2631,10 @@ function getReasoningEffort(settings = null, model = null) {
|
||||
|
||||
return reasoning_effort_types.low;
|
||||
case reasoning_effort_types.max:
|
||||
if ([chat_completion_sources.OPENAI, chat_completion_sources.AZURE_OPENAI].includes(settings.chat_completion_source)
|
||||
&& /^gpt-6-astra/.test(model)) {
|
||||
return reasoning_effort_types.max;
|
||||
}
|
||||
if ([chat_completion_sources.OPENAI, chat_completion_sources.AZURE_OPENAI].includes(settings.chat_completion_source)
|
||||
&& /^gpt-5\.6/.test(model)) {
|
||||
// GPT-5.6 reserves "max" effort for the Responses API.
|
||||
@@ -2665,6 +2695,20 @@ export async function createGenerationParameters(settings, model, type, messages
|
||||
}
|
||||
messages = messages.filter(msg => msg && typeof msg === 'object');
|
||||
|
||||
// DeepSeek only accepts image blocks in user messages. Media can also be
|
||||
// attached to system and assistant messages by the shared inlining path.
|
||||
const isDeepSeekVisionModel = typeof model === 'string' && model.toLowerCase().includes('deepseek-v4-flash-vision-exp');
|
||||
if (isDeepSeekVisionModel) {
|
||||
messages = messages.flatMap((message) => {
|
||||
if (!['system', 'assistant'].includes(message.role) || !Array.isArray(message.content)) {
|
||||
return [message];
|
||||
}
|
||||
|
||||
const content = message.content.filter(block => block?.type !== 'image_url');
|
||||
return content.length > 0 ? [{ ...message, content }] : [];
|
||||
});
|
||||
}
|
||||
|
||||
// "OpenAI-like" sources
|
||||
const gptSources = [
|
||||
chat_completion_sources.OPENAI,
|
||||
@@ -2854,6 +2898,10 @@ export async function createGenerationParameters(settings, model, type, messages
|
||||
generate_data.nanogpt_payg_override = settings.nanogpt_payg_override;
|
||||
}
|
||||
|
||||
if (settings.chat_completion_source === chat_completion_sources.FIREWORKS && type !== 'quiet') {
|
||||
generate_data.chat_id = getCurrentChatId();
|
||||
}
|
||||
|
||||
if ([chat_completion_sources.MAKERSUITE, chat_completion_sources.VERTEXAI].includes(settings.chat_completion_source)) {
|
||||
const stopStringsLimit = 5;
|
||||
generate_data.top_k = Number(settings.top_k_openai);
|
||||
@@ -3046,9 +3094,18 @@ export async function createGenerationParameters(settings, model, type, messages
|
||||
}
|
||||
}
|
||||
|
||||
// Claude Fable and Claude 5 generation models removed sampling parameters and reject
|
||||
// them with HTTP 400, including via OpenAI-compatible proxies. Unanchored to also match
|
||||
// prefixed ids like 'anthropic/claude-fable-5'.
|
||||
if (gptSources.includes(settings.chat_completion_source) && /gpt-6-astra/.test(model)) {
|
||||
generate_data.max_completion_tokens = generate_data.max_tokens;
|
||||
delete generate_data.max_tokens;
|
||||
delete generate_data.temperature;
|
||||
delete generate_data.top_p;
|
||||
delete generate_data.logprobs;
|
||||
delete generate_data.top_logprobs;
|
||||
}
|
||||
|
||||
// Claude Fable / Claude 5 models removed sampling parameters and reject them with HTTP 400,
|
||||
// including via OpenAI-compatible proxies. Unanchored to also match prefixed ids
|
||||
// like 'anthropic/claude-fable-5' or 'anthropic/claude-opus-5'.
|
||||
if (/claude-(fable|opus-5|sonnet-5)/.test(model)) {
|
||||
delete generate_data.temperature;
|
||||
delete generate_data.top_p;
|
||||
@@ -3056,7 +3113,7 @@ export async function createGenerationParameters(settings, model, type, messages
|
||||
delete generate_data.frequency_penalty;
|
||||
delete generate_data.presence_penalty;
|
||||
// Keep reasoning_effort for the native Claude source, where the backend maps it to
|
||||
// adaptive thinking; proxies may translate it into a thinking budget that Fable rejects.
|
||||
// adaptive thinking; proxies may translate it into a thinking budget that these models reject.
|
||||
if (settings.chat_completion_source !== chat_completion_sources.CLAUDE) {
|
||||
delete generate_data.reasoning_effort;
|
||||
}
|
||||
@@ -3137,7 +3194,7 @@ async function sendOpenAIRequest(type, messages, signal, { jsonSchema = null } =
|
||||
checkModerationError(data);
|
||||
|
||||
if (data.error) {
|
||||
const message = data.error.message || response.statusText || t`Unknown error`;
|
||||
const message = getChatCompletionErrorMessage(data, response);
|
||||
toastr.error(message, t`API returned an error`);
|
||||
throw new Error(message);
|
||||
}
|
||||
@@ -3229,7 +3286,7 @@ export function getStreamingReply(data, state, { chatCompletionSource = null, ov
|
||||
}
|
||||
});
|
||||
return data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? '';
|
||||
} else if ([chat_completion_sources.CUSTOM, chat_completion_sources.POLLINATIONS, chat_completion_sources.AIMLAPI, chat_completion_sources.MOONSHOT, chat_completion_sources.COMETAPI, chat_completion_sources.ELECTRONHUB, chat_completion_sources.NANOGPT, chat_completion_sources.ZAI, chat_completion_sources.SILICONFLOW, chat_completion_sources.CHUTES, chat_completion_sources.WORKERS_AI].includes(chat_completion_source)) {
|
||||
} else if ([chat_completion_sources.CUSTOM, chat_completion_sources.POLLINATIONS, chat_completion_sources.AIMLAPI, chat_completion_sources.MOONSHOT, chat_completion_sources.COMETAPI, chat_completion_sources.ELECTRONHUB, chat_completion_sources.NANOGPT, chat_completion_sources.ZAI, chat_completion_sources.SILICONFLOW, chat_completion_sources.CHUTES, chat_completion_sources.WORKERS_AI, chat_completion_sources.FIREWORKS].includes(chat_completion_source)) {
|
||||
if (show_thoughts) {
|
||||
state.reasoning +=
|
||||
data.choices?.filter(x => x?.delta?.reasoning_content)?.[0]?.delta?.reasoning_content ??
|
||||
@@ -5035,6 +5092,7 @@ function getMaxContextOpenAI(value) {
|
||||
|
||||
/** @type {[RegExp, number][]} */
|
||||
const contextMap = [
|
||||
[/^gpt-6-astra/, max_1050k],
|
||||
[/^gpt-5\.6/, max_1050k],
|
||||
[/^gpt-5\.[45]/, max_1mil],
|
||||
[/^gpt-5/, max_400k],
|
||||
@@ -5672,7 +5730,7 @@ async function onModelChange() {
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.CLAUDE) {
|
||||
if (oai_settings.max_context_unlocked) {
|
||||
$('#openai_max_context').attr('max', unlocked_max);
|
||||
} else if (/^claude-(sonnet-4-5|sonnet-4-6|opus-4-6|opus-4-7|opus-4-8|fable|opus-5|sonnet-5)/.test(value)) {
|
||||
} else if (/^claude-(sonnet-4-5|sonnet-4-6|sonnet-5|opus-4-6|opus-4-7|opus-4-8|opus-5|fable)/.test(value)) {
|
||||
$('#openai_max_context').attr('max', max_1mil);
|
||||
} else if (/^claude-(3|opus|haiku|sonnet)/.test(value)) {
|
||||
$('#openai_max_context').attr('max', max_200k);
|
||||
@@ -6135,10 +6193,8 @@ function reconnectOpenAi() {
|
||||
}
|
||||
}
|
||||
|
||||
function onProxyPasswordShowClick() {
|
||||
const $input = $('#openai_proxy_password');
|
||||
const type = $input.attr('type') === 'password' ? 'text' : 'password';
|
||||
$input.attr('type', type);
|
||||
function onProxyAccessKeyShowClick() {
|
||||
$('#openai_proxy_access_key').toggleClass('masked-secret');
|
||||
$(this).toggleClass('fa-eye-slash fa-eye');
|
||||
}
|
||||
|
||||
@@ -6185,6 +6241,7 @@ export function isImageInliningSupported() {
|
||||
'gpt-4.1',
|
||||
'gpt-4.5-preview',
|
||||
'gpt-4o',
|
||||
'gpt-6-astra',
|
||||
'gpt-5',
|
||||
'o1',
|
||||
'o3',
|
||||
@@ -6192,10 +6249,10 @@ export function isImageInliningSupported() {
|
||||
// Claude
|
||||
'claude-3',
|
||||
'claude-fable',
|
||||
'claude-opus-5',
|
||||
'claude-sonnet-5',
|
||||
'claude-opus-4',
|
||||
'claude-opus-5',
|
||||
'claude-sonnet-4',
|
||||
'claude-sonnet-5',
|
||||
'claude-haiku-4',
|
||||
// Cohere
|
||||
'c4ai-aya-vision',
|
||||
@@ -6228,6 +6285,8 @@ export function isImageInliningSupported() {
|
||||
'moonshot-v1-128k-vision-preview',
|
||||
'kimi-k2.5',
|
||||
'kimi-latest',
|
||||
// DeepSeek
|
||||
'deepseek-v4-flash-vision-exp',
|
||||
// Z.AI (GLM)
|
||||
'glm-4.5v',
|
||||
'glm-4.6v',
|
||||
@@ -6287,10 +6346,14 @@ export function isImageInliningSupported() {
|
||||
return visionSupportedModels.some(model => oai_settings.zai_model.includes(model));
|
||||
case chat_completion_sources.SILICONFLOW:
|
||||
return visionSupportedModels.some(model => oai_settings.siliconflow_model.includes(model));
|
||||
case chat_completion_sources.DEEPSEEK:
|
||||
return visionSupportedModels.some(model => oai_settings.deepseek_model.includes(model));
|
||||
case chat_completion_sources.WORKERS_AI: {
|
||||
const waiModel = Array.isArray(model_list) && model_list.find(m => m.id === oai_settings.workers_ai_model);
|
||||
return Boolean(waiModel && Array.isArray(waiModel.properties) && waiModel.properties.some(p => p.property_id === 'vision' && p.value === 'true'));
|
||||
}
|
||||
case chat_completion_sources.FIREWORKS:
|
||||
return (Array.isArray(model_list) && model_list.find(m => m.id === oai_settings.fireworks_model)?.supports_image_input);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -6459,7 +6522,7 @@ function setProxyPreset(name, url, password) {
|
||||
oai_settings.reverse_proxy = url;
|
||||
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
|
||||
oai_settings.proxy_password = password;
|
||||
$('#openai_proxy_password').val(oai_settings.proxy_password);
|
||||
$('#openai_proxy_access_key').val(oai_settings.proxy_password);
|
||||
reconnectOpenAi();
|
||||
}
|
||||
|
||||
@@ -6478,7 +6541,7 @@ function onProxyPresetChange() {
|
||||
$('#save_proxy').on('click', async function () {
|
||||
const presetName = $('#openai_reverse_proxy_name').val();
|
||||
const reverseProxy = $('#openai_reverse_proxy').val();
|
||||
const proxyPassword = $('#openai_proxy_password').val();
|
||||
const proxyPassword = $('#openai_proxy_access_key').val();
|
||||
|
||||
setProxyPreset(presetName, reverseProxy, proxyPassword);
|
||||
saveSettingsDebounced();
|
||||
@@ -6512,7 +6575,7 @@ $('#delete_proxy').on('click', async function () {
|
||||
oai_settings.reverse_proxy = selected_proxy.url;
|
||||
$('#openai_reverse_proxy').val(selected_proxy.url);
|
||||
oai_settings.proxy_password = selected_proxy.password;
|
||||
$('#openai_proxy_password').val(selected_proxy.password);
|
||||
$('#openai_proxy_access_key').val(selected_proxy.password);
|
||||
|
||||
saveSettingsDebounced();
|
||||
$('#openai_proxy_preset').val(selected_proxy.name);
|
||||
@@ -6927,11 +6990,17 @@ export function initOpenAI() {
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#openai_proxy_password').on('input', function () {
|
||||
$('#openai_proxy_access_key').on('input', function () {
|
||||
oai_settings.proxy_password = String($(this).val());
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#openai_proxy_access_key').on('copy cut', function (event) {
|
||||
if ($(this).hasClass('masked-secret')) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$('#claude_assistant_prefill').on('input', function () {
|
||||
oai_settings.assistant_prefill = String($(this).val());
|
||||
saveSettingsDebounced();
|
||||
@@ -7321,7 +7390,7 @@ export function initOpenAI() {
|
||||
$('#openai_logit_bias_export_preset').on('click', onLogitBiasPresetExportClick);
|
||||
$('#openai_logit_bias_delete_preset').on('click', onLogitBiasPresetDeleteClick);
|
||||
$('#import_oai_preset').on('click', onImportPresetClick);
|
||||
$('#openai_proxy_password_show').on('click', onProxyPasswordShowClick);
|
||||
$('#openai_proxy_access_key_show').on('click', onProxyAccessKeyShowClick);
|
||||
$('#customize_additional_parameters').on('click', onCustomizeParametersClick);
|
||||
$('#openai_proxy_preset').on('change', onProxyPresetChange);
|
||||
}
|
||||
|
||||
@@ -2818,9 +2818,10 @@ async function loadUntilMesId(mesId) {
|
||||
return target;
|
||||
}
|
||||
|
||||
async function doMesCut(_, text) {
|
||||
async function doMesCut(args, text) {
|
||||
console.debug(`was asked to cut message id #${text}`);
|
||||
const range = stringToRange(text, 0, chat.length - 1);
|
||||
const deleteToolCalls = args?.toolcalls === undefined || isTrueBoolean(args.toolcalls);
|
||||
|
||||
//reject invalid args or no args
|
||||
if (!range) {
|
||||
@@ -2828,12 +2829,16 @@ async function doMesCut(_, text) {
|
||||
return;
|
||||
}
|
||||
|
||||
let totalMesToCut = (range.end - range.start) + 1;
|
||||
let mesIDToCut = range.start;
|
||||
const messagesToCut = chat.slice(range.start, range.end + 1);
|
||||
let cutText = '';
|
||||
|
||||
for (let i = 0; i < totalMesToCut; i++) {
|
||||
cutText += (chat[mesIDToCut]?.mes || '') + '\n';
|
||||
for (const message of messagesToCut) {
|
||||
const mesIDToCut = chat.indexOf(message);
|
||||
if (mesIDToCut === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cutText += (message?.mes || '') + '\n';
|
||||
let mesToCut = $('#chat').find(`.mes[mesid=${mesIDToCut}]`);
|
||||
|
||||
if (!mesToCut.length) {
|
||||
@@ -2845,7 +2850,7 @@ async function doMesCut(_, text) {
|
||||
}
|
||||
|
||||
setEditedMessageId(mesIDToCut);
|
||||
await deleteMessage(mesIDToCut, null, false);
|
||||
await deleteMessage(mesIDToCut, null, false, deleteToolCalls);
|
||||
}
|
||||
|
||||
await saveChatConditional();
|
||||
@@ -2853,7 +2858,7 @@ async function doMesCut(_, text) {
|
||||
return cutText;
|
||||
}
|
||||
|
||||
async function doDelMode(_, text) {
|
||||
async function doDelMode(args, text) {
|
||||
//reject invalid args
|
||||
if (text && isNaN(text)) {
|
||||
toastr.warning('Must enter a number or nothing.');
|
||||
@@ -2862,7 +2867,8 @@ async function doDelMode(_, text) {
|
||||
|
||||
// Just enter the delete mode.
|
||||
if (!text) {
|
||||
$('#option_delete_mes').trigger('click', { fromSlashCommand: true });
|
||||
const deleteToolCalls = args?.toolcalls === undefined || isTrueBoolean(args.toolcalls);
|
||||
$('#option_delete_mes').trigger('click', { fromSlashCommand: true, deleteToolCalls });
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -2879,7 +2885,7 @@ async function doDelMode(_, text) {
|
||||
}
|
||||
|
||||
const range = `${chat.length - count}-${chat.length - 1}`;
|
||||
return doMesCut(_, range);
|
||||
return doMesCut(args, range);
|
||||
}
|
||||
|
||||
function doResetPanels() {
|
||||
@@ -4145,6 +4151,15 @@ jQuery(() => {
|
||||
name: 'del',
|
||||
callback: doDelMode,
|
||||
aliases: ['delete', 'delmode'],
|
||||
namedArgumentList: [
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'toolcalls',
|
||||
description: 'also delete associated tool-call messages',
|
||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||
defaultValue: 'true',
|
||||
enumList: commonEnumProviders.boolean('trueFalse')(),
|
||||
}),
|
||||
],
|
||||
unnamedArgumentList: [
|
||||
new SlashCommandArgument(
|
||||
'optional number', [ARGUMENT_TYPE.NUMBER], false,
|
||||
@@ -4157,6 +4172,15 @@ jQuery(() => {
|
||||
name: 'cut',
|
||||
callback: doMesCut,
|
||||
returns: 'the text of cut messages separated by a newline',
|
||||
namedArgumentList: [
|
||||
SlashCommandNamedArgument.fromProps({
|
||||
name: 'toolcalls',
|
||||
description: 'also delete associated tool-call messages',
|
||||
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||
defaultValue: 'true',
|
||||
enumList: commonEnumProviders.boolean('trueFalse')(),
|
||||
}),
|
||||
],
|
||||
unnamedArgumentList: [
|
||||
SlashCommandArgument.fromProps({
|
||||
description: 'number or range',
|
||||
|
||||
@@ -154,6 +154,7 @@ export function extractReasoningFromData(data, {
|
||||
case chat_completion_sources.SILICONFLOW:
|
||||
case chat_completion_sources.ZAI:
|
||||
case chat_completion_sources.WORKERS_AI:
|
||||
case chat_completion_sources.FIREWORKS:
|
||||
case chat_completion_sources.CUSTOM: {
|
||||
return data?.choices?.[0]?.message?.reasoning_content
|
||||
?? data?.choices?.[0]?.message?.reasoning
|
||||
|
||||
+18
-14
@@ -2289,28 +2289,32 @@ function printViewTagList(tagContainer, empty = true) {
|
||||
function removeMissingTagFilters() {
|
||||
const tagIds = new Set(tags.map(tag => tag.id));
|
||||
const assignedTagIds = new Set(Object.values(tag_map).flat());
|
||||
const openBogusFolderIds = new Set(getOpenBogusFolders().map(tag => tag.id));
|
||||
const isEmptyOpenBogusFolder = (tagId) => openBogusFolderIds.has(tagId) && !assignedTagIds.has(tagId);
|
||||
// Filter lists only print tags that are assigned to at least one entity. A filter on an unassigned
|
||||
// tag therefore has no element to toggle, and "Clear all filters" can't reset it either, because it
|
||||
// works by clicking the printed elements. Drop those filters instead of leaving them stuck.
|
||||
const isUnclearable = (tagId) => !tagIds.has(tagId) || !assignedTagIds.has(tagId);
|
||||
|
||||
for (const helper of [groupCandidatesFilter, groupMembersFilter, entitiesFilter]) {
|
||||
const { selected, excluded } = helper.getFilterData(FILTER_TYPES.TAG);
|
||||
const storagePrefix = getFilterStorageKey(helper);
|
||||
let anyRemoved = false;
|
||||
|
||||
if (Array.isArray(selected)) {
|
||||
for (let i = selected.length - 1; i >= 0; i--) {
|
||||
if (!tagIds.has(selected[i]) || isEmptyOpenBogusFolder(selected[i])) {
|
||||
selected.splice(i, 1);
|
||||
anyRemoved = true;
|
||||
}
|
||||
for (const tagIdList of [selected, excluded]) {
|
||||
if (!Array.isArray(tagIdList)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(excluded)) {
|
||||
for (let i = excluded.length - 1; i >= 0; i--) {
|
||||
if (!tagIds.has(excluded[i]) || isEmptyOpenBogusFolder(excluded[i])) {
|
||||
excluded.splice(i, 1);
|
||||
anyRemoved = true;
|
||||
for (let i = tagIdList.length - 1; i >= 0; i--) {
|
||||
if (!isUnclearable(tagIdList[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (storagePrefix) {
|
||||
accountStorage.removeItem(`${storagePrefix}_tag_${tagIdList[i]}`);
|
||||
}
|
||||
|
||||
tagIdList.splice(i, 1);
|
||||
anyRemoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -610,15 +610,37 @@ export function loadGenericModels(data) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.sort((a, b) => a.id.localeCompare(b.id));
|
||||
const models = data
|
||||
.filter(model => model && typeof model.id === 'string' && model.id.length > 0)
|
||||
.sort((a, b) => a.id.localeCompare(b.id));
|
||||
|
||||
const dataList = $('#generic_model_fill');
|
||||
dataList.empty();
|
||||
|
||||
for (const model of data) {
|
||||
const modelSelect = $('#generic_model_select');
|
||||
modelSelect.empty();
|
||||
modelSelect.append($('<option>', { value: '' }));
|
||||
|
||||
for (const model of models) {
|
||||
const option = document.createElement('option');
|
||||
option.value = model.id;
|
||||
option.text = model.id;
|
||||
dataList.append(option);
|
||||
|
||||
const selectOption = document.createElement('option');
|
||||
selectOption.value = model.id;
|
||||
selectOption.text = model.id;
|
||||
selectOption.selected = model.id === textgen_settings.generic_model;
|
||||
modelSelect.append(selectOption);
|
||||
}
|
||||
|
||||
// Keep free-text entry for IDs that are not in the /v1/models list
|
||||
if (textgen_settings.generic_model && !models.find(x => x.id === textgen_settings.generic_model)) {
|
||||
modelSelect.append($('<option>', {
|
||||
value: textgen_settings.generic_model,
|
||||
text: textgen_settings.generic_model,
|
||||
selected: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1051,6 +1073,13 @@ function onLlamaCppModelSelect() {
|
||||
$('#api_button_textgenerationwebui').trigger('click');
|
||||
}
|
||||
|
||||
function onGenericModelSelect() {
|
||||
const modelId = String($('#generic_model_select').val() ?? '');
|
||||
textgen_settings.generic_model = modelId;
|
||||
$('#generic_model_textgenerationwebui').val(modelId);
|
||||
$('#api_button_textgenerationwebui').trigger('click');
|
||||
}
|
||||
|
||||
function onOpenRouterModelSelect() {
|
||||
const modelId = String($('#openrouter_model').val());
|
||||
textgen_settings.openrouter_model = modelId;
|
||||
@@ -1368,6 +1397,7 @@ export function initTextGenModels() {
|
||||
$('#tabby_download_model').on('click', downloadTabbyModel);
|
||||
$('#tabby_model').on('change', onTabbyModelSelect);
|
||||
$('#llamacpp_model').on('change', onLlamaCppModelSelect);
|
||||
$('#generic_model_select').on('change', onGenericModelSelect);
|
||||
$('#featherless_model').on('change', () => onFeatherlessModelSelect(String($('#featherless_model').val())));
|
||||
|
||||
const providersSelect = $('.openrouter_providers');
|
||||
@@ -1421,6 +1451,13 @@ export function initTextGenModels() {
|
||||
width: '100%',
|
||||
allowClear: true,
|
||||
});
|
||||
$('#generic_model_select').select2({
|
||||
placeholder: t`Select a model`,
|
||||
searchInputPlaceholder: t`Search models...`,
|
||||
searchInputCssClass: 'text_pole',
|
||||
width: '100%',
|
||||
allowClear: true,
|
||||
});
|
||||
$('#model_infermaticai_select').select2({
|
||||
placeholder: t`Select a model`,
|
||||
searchInputPlaceholder: t`Search models...`,
|
||||
|
||||
@@ -639,7 +639,7 @@ export function getTokenizerModel() {
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.ELECTRONHUB && oai_settings.electronhub_model) {
|
||||
if (oai_settings.electronhub_model.includes('gpt-4o') || oai_settings.electronhub_model.includes('gpt-5')) {
|
||||
if (oai_settings.electronhub_model.includes('gpt-4o') || oai_settings.electronhub_model.includes('gpt-5') || oai_settings.electronhub_model.includes('gpt-6-astra')) {
|
||||
return gpt4oTokenizer;
|
||||
} else if (oai_settings.electronhub_model.includes('gpt-4.1') || oai_settings.electronhub_model.includes('gpt-4.5')) {
|
||||
return gpt4oTokenizer;
|
||||
|
||||
@@ -580,7 +580,13 @@ export class ToolManager {
|
||||
}
|
||||
|
||||
if (typeof deltaValue === 'string') {
|
||||
if (typeof targetValue === 'string') {
|
||||
// `id`, `name`, `type` are sent in full by some providers on every
|
||||
// streaming chunk; concatenating them would duplicate the value.
|
||||
if (key === 'id' || key === 'name' || key === 'type') {
|
||||
if (!targetValue) {
|
||||
target[key] = deltaValue;
|
||||
}
|
||||
} else if (typeof targetValue === 'string') {
|
||||
// Concatenate strings
|
||||
target[key] = targetValue + deltaValue;
|
||||
} else {
|
||||
@@ -613,6 +619,12 @@ export class ToolManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
// GPT-6 Astra supports tool calling only through the Responses API.
|
||||
if ([chat_completion_sources.OPENAI, chat_completion_sources.AZURE_OPENAI].includes(settings.chat_completion_source)
|
||||
&& /^gpt-6-astra/.test(model)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Post-processing will forcefully remove past tool calls from the prompt, making them useless
|
||||
const { NONE, MERGE_TOOLS, SEMI_TOOLS, STRICT_TOOLS } = custom_prompt_post_processing_types;
|
||||
const allowedPromptPostProcessing = [NONE, MERGE_TOOLS, SEMI_TOOLS, STRICT_TOOLS];
|
||||
|
||||
@@ -2681,6 +2681,11 @@ textarea::placeholder {
|
||||
height: fit-content;
|
||||
}
|
||||
|
||||
/* Keep non-login secrets visually masked without using password input semantics. */
|
||||
.masked-secret {
|
||||
-webkit-text-security: disc;
|
||||
}
|
||||
|
||||
select.text_pole {
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ import yaml from 'yaml';
|
||||
import color from 'chalk';
|
||||
import _ from 'lodash';
|
||||
import { serverDirectory } from './server-directory.js';
|
||||
import { keyToEnv, setConfigFilePath } from './util.js';
|
||||
import { keyToEnv, setConfigFilePath, stringToBool } from './util.js';
|
||||
|
||||
const keyMigrationMap = [
|
||||
{
|
||||
@@ -181,7 +181,7 @@ export function addMissingConfigValues(configPath) {
|
||||
const newEnvKey = keyToEnv(newKey);
|
||||
if (process.env[oldEnvKey] && !process.env[newEnvKey]) {
|
||||
const oldValue = process.env[oldEnvKey];
|
||||
const newValue = migrate(oldValue);
|
||||
const newValue = migrate(stringToBool(oldValue));
|
||||
process.env[newEnvKey] = newValue;
|
||||
delete process.env[oldEnvKey];
|
||||
console.warn(color.yellow(`Warning: Using a deprecated environment variable: ${oldEnvKey}. Please use ${newEnvKey} instead.`));
|
||||
|
||||
+2
-1
@@ -456,7 +456,7 @@ export const AZURE_OPENAI_KEYS = [
|
||||
'reasoning_effort',
|
||||
];
|
||||
|
||||
export const OPENAI_VERBOSITY_MODELS = /^gpt-5/;
|
||||
export const OPENAI_VERBOSITY_MODELS = /^(?:gpt-5|gpt-6-astra)/;
|
||||
|
||||
export const OPENAI_REASONING_EFFORT_MODELS = [
|
||||
'o1',
|
||||
@@ -491,6 +491,7 @@ export const OPENAI_REASONING_EFFORT_MODELS = [
|
||||
'gpt-5.6-sol',
|
||||
'gpt-5.6-terra',
|
||||
'gpt-5.6-luna',
|
||||
'gpt-6-astra',
|
||||
];
|
||||
|
||||
export const OPENAI_REASONING_EFFORT_MAP = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable dot-notation */
|
||||
import { createHmac } from 'node:crypto';
|
||||
import process from 'node:process';
|
||||
import util from 'node:util';
|
||||
import express from 'express';
|
||||
@@ -66,6 +67,8 @@ import {
|
||||
getWebTokenizer,
|
||||
} from '../tokenizers.js';
|
||||
import { getVertexAIAuth, getProjectIdFromServiceAccount } from '../google.js';
|
||||
import { getCookieSecret } from '../../users.js';
|
||||
import { fetchGoogleModels, GoogleModelsHttpError } from './google-models.js';
|
||||
|
||||
const API_OPENAI = 'https://api.openai.com/v1';
|
||||
const API_CLAUDE = 'https://api.anthropic.com/v1';
|
||||
@@ -108,6 +111,18 @@ const cachingAtDepth = (() => {
|
||||
})();
|
||||
const enableAdaptiveThinking = getConfigValue('claude.enableAdaptiveThinking', true, 'boolean');
|
||||
|
||||
/**
|
||||
* Lazily-cached HMAC key (instance cookie secret) for session-affinity hashing.
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
let affinityKey;
|
||||
function getAffinityKey() {
|
||||
if (affinityKey === undefined) {
|
||||
affinityKey = getCookieSecret(globalThis.DATA_ROOT);
|
||||
}
|
||||
return affinityKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache for cacheable (writing) OpenRouter model IDs.
|
||||
* @type {string[]}
|
||||
@@ -235,8 +250,8 @@ async function sendClaudeRequest(request, response) {
|
||||
const convertedPrompt = convertClaudeMessages(request.body.messages, request.body.assistant_prefill, useSystemPrompt, useTools, getPromptNames(request));
|
||||
// Unanchored to also match prefixed ids passed through proxies, e.g. 'anthropic/claude-fable-5'
|
||||
const isFableModel = /claude-fable/.test(request.body.model);
|
||||
// Claude 5 generation (opus-5, sonnet-5): adaptive-only thinking, sampling parameters removed, no prefill
|
||||
const isClaude5Model = /^claude-(opus-5|sonnet-5)/.test(request.body.model);
|
||||
const isFable51Model = /claude-fable-5-1/.test(request.body.model);
|
||||
const isClaude5Model = /claude-(opus-5|sonnet-5)/.test(request.body.model);
|
||||
const useThinking = /^claude-(3-7|opus-4|sonnet-4|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model) || isFableModel || isClaude5Model;
|
||||
const useWebSearch = (/^claude-(3-5|3-7|opus-4|sonnet-4|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model) || isFableModel || isClaude5Model) && Boolean(request.body.enable_web_search);
|
||||
const isLimitedSampling = /^claude-(opus-4-1|sonnet-4-5|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6)/.test(request.body.model);
|
||||
@@ -284,15 +299,24 @@ async function sendClaudeRequest(request, response) {
|
||||
}
|
||||
}
|
||||
|
||||
// Structured output is a forced tool
|
||||
// Fable 5.1 rejects forced tools, but supports native JSON outputs.
|
||||
if (request.body.json_schema) {
|
||||
const jsonTool = {
|
||||
name: request.body.json_schema.name,
|
||||
description: request.body.json_schema.description || 'Well-formed JSON object',
|
||||
input_schema: request.body.json_schema.value,
|
||||
};
|
||||
requestBody.tools = [...(requestBody.tools || []), jsonTool];
|
||||
requestBody.tool_choice = { type: 'tool', name: request.body.json_schema.name };
|
||||
if (isFable51Model) {
|
||||
requestBody.output_config = {
|
||||
format: {
|
||||
type: 'json_schema',
|
||||
schema: request.body.json_schema.value,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
const jsonTool = {
|
||||
name: request.body.json_schema.name,
|
||||
description: request.body.json_schema.description || 'Well-formed JSON object',
|
||||
input_schema: request.body.json_schema.value,
|
||||
};
|
||||
requestBody.tools = [...(requestBody.tools || []), jsonTool];
|
||||
requestBody.tool_choice = { type: 'tool', name: request.body.json_schema.name };
|
||||
}
|
||||
}
|
||||
|
||||
if (useWebSearch) {
|
||||
@@ -341,8 +365,8 @@ async function sendClaudeRequest(request, response) {
|
||||
requestBody.output_config.effort = budgetTokens;
|
||||
// top_k is not allowed in adaptive mode
|
||||
delete requestBody.top_k;
|
||||
} else if (useThinking && isFableModel && reasoningEffort === 'auto' && includeReasoning) {
|
||||
// Fable auto thinking is already enabled, but readable summaries require an explicit display request.
|
||||
} else if (useThinking && (isFableModel || isClaude5Model) && reasoningEffort === 'auto' && includeReasoning) {
|
||||
// Fable/Claude 5 auto thinking is already enabled, but readable summaries require an explicit display request.
|
||||
fixThinkingPrefill = true;
|
||||
requestBody.thinking = { type: 'adaptive', display: 'summarized' };
|
||||
} else if (useThinking && Number.isInteger(budgetTokens)) {
|
||||
@@ -501,6 +525,8 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
|
||||
const isThinkingConfigModel = m => (/^gemini-2.5-(flash|pro)/.test(m) && !/-image(-preview)?$/.test(m)) || (/^gemini-3[.\d]*-(flash|pro)/.test(m));
|
||||
const isImageSizeModel = m => /^gemini-3/.test(m);
|
||||
// https://ai.google.dev/gemini-api/docs/latest-model#api-changes-and-parameter-updates
|
||||
const noSamplingModel = /gemini-3\.[67]-flash|gemini-3\.5-flash-lite/.test(model);
|
||||
|
||||
const noSearchModels = [
|
||||
'gemini-2.0-flash-lite',
|
||||
@@ -514,6 +540,13 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
delete generationConfig.stopSequences;
|
||||
}
|
||||
|
||||
if (noSamplingModel) {
|
||||
delete generationConfig.temperature;
|
||||
delete generationConfig.topP;
|
||||
delete generationConfig.topK;
|
||||
delete generationConfig.candidateCount;
|
||||
}
|
||||
|
||||
const enableImageModality = requestImages && imageGenerationModels.includes(model);
|
||||
const enableImageConfig = enableImageModality && (aspectRatio || imageSize);
|
||||
if (enableImageModality) {
|
||||
@@ -1817,9 +1850,61 @@ router.post('/status', async function (request, statusResponse) {
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.FIREWORKS) {
|
||||
apiUrl = API_FIREWORKS;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.FIREWORKS, request.body.secret_id);
|
||||
headers = {};
|
||||
const modelsUrl = 'https://api.fireworks.ai/v1/accounts/fireworks/models?filter=supports_serverless%3Dtrue&pageSize=200';
|
||||
|
||||
try {
|
||||
const response = await fetch(modelsUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + apiKey,
|
||||
...headers,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data?.models)
|
||||
? data.models
|
||||
.filter(m => m?.contextLength > 0 && m?.kind !== 'EMBEDDING_MODEL')
|
||||
.map(m => ({
|
||||
id: m.name,
|
||||
name: m.displayName,
|
||||
context_length: m.contextLength,
|
||||
supports_tools: m.supportsTools,
|
||||
supports_image_input: m.supportsImageInput,
|
||||
}))
|
||||
: [];
|
||||
|
||||
// Add fast router versions for models that have them
|
||||
const fastRouters = {
|
||||
'accounts/fireworks/models/glm-5p2': 'accounts/fireworks/routers/glm-5p2-fast',
|
||||
'accounts/fireworks/models/kimi-k2p6': 'accounts/fireworks/routers/kimi-k2p6-fast',
|
||||
'accounts/fireworks/models/kimi-k2p7-code': 'accounts/fireworks/routers/kimi-k2p7-code-fast',
|
||||
'accounts/fireworks/models/kimi-k3': 'accounts/fireworks/routers/kimi-k3-fast',
|
||||
};
|
||||
for (const [standardId, fastId] of Object.entries(fastRouters)) {
|
||||
const standard = models.find(m => m.id === standardId);
|
||||
if (standard) {
|
||||
models.push({
|
||||
...standard,
|
||||
id: fastId,
|
||||
name: standard.name + ' (fast)',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.debug('Available Fireworks models:', models.map(m => m.id));
|
||||
return statusResponse.send({ data: models });
|
||||
} else {
|
||||
console.warn('Fireworks models endpoint failed:', response.status, response.statusText);
|
||||
return statusResponse.send({ error: true, data: { data: [] } });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching Fireworks models:', error);
|
||||
return statusResponse.send({ error: true, data: { data: [] } });
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MAKERSUITE) {
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MAKERSUITE, request.body.secret_id);
|
||||
apiUrl = trimTrailingSlash(request.body.reverse_proxy || API_MAKERSUITE);
|
||||
@@ -1834,26 +1919,15 @@ router.post('/status', async function (request, statusResponse) {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(modelsUrl);
|
||||
|
||||
if (response.ok) {
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
// Transform Google AI Studio models to OpenAI format
|
||||
const models = data.models
|
||||
?.filter(model => model.supportedGenerationMethods?.includes('generateContent'))
|
||||
?.map(model => ({
|
||||
...model,
|
||||
id: model.name.replace('models/', ''),
|
||||
})) || [];
|
||||
|
||||
console.info('Available Google AI Studio models:', models.map(m => m.id));
|
||||
return statusResponse.send({ data: models });
|
||||
} else {
|
||||
console.warn('Google AI Studio models endpoint failed:', response.status, response.statusText);
|
||||
const models = await fetchGoogleModels(modelsUrl);
|
||||
console.info('Available Google AI Studio models:', models.map(m => m.id));
|
||||
return statusResponse.send({ data: models });
|
||||
} catch (error) {
|
||||
if (error instanceof GoogleModelsHttpError) {
|
||||
console.warn('Google AI Studio models endpoint failed:', error.status, error.statusText);
|
||||
return statusResponse.send({ error: true, bypass: true, data: { data: [] } });
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
console.error('Error fetching Google AI Studio models:', error);
|
||||
return statusResponse.send({ error: true, bypass: true, data: { data: [] } });
|
||||
}
|
||||
@@ -2382,6 +2456,9 @@ router.post('/generate', async function (request, response) {
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.FIREWORKS, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
if (request.body.reasoning_effort) {
|
||||
bodyParams['reasoning_effort'] = request.body.reasoning_effort;
|
||||
}
|
||||
if (request.body.json_schema) {
|
||||
bodyParams['response_format'] = {
|
||||
type: 'json_schema',
|
||||
@@ -2393,6 +2470,9 @@ router.post('/generate', async function (request, response) {
|
||||
},
|
||||
};
|
||||
}
|
||||
if (request.body.chat_id) {
|
||||
headers['x-session-affinity'] = createHmac('sha256', getAffinityKey()).update(request.body.chat_id).digest('hex').slice(0, 16);
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.NANOGPT) {
|
||||
apiUrl = API_NANOGPT;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.NANOGPT, request.body.secret_id);
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const GOOGLE_MODELS_PAGE_SIZE = 1000;
|
||||
|
||||
export class GoogleModelsHttpError extends Error {
|
||||
/**
|
||||
* @param {number} status HTTP status code
|
||||
* @param {string} statusText HTTP status text
|
||||
*/
|
||||
constructor(status, statusText) {
|
||||
super(`Google AI Studio models endpoint returned ${status} ${statusText}`.trim());
|
||||
this.name = 'GoogleModelsHttpError';
|
||||
this.status = status;
|
||||
this.statusText = statusText;
|
||||
}
|
||||
}
|
||||
|
||||
export class GoogleModelsResponseError extends Error {
|
||||
/**
|
||||
* @param {string} message Error message
|
||||
* @param {ErrorOptions} [options] Error options
|
||||
*/
|
||||
constructor(message, options) {
|
||||
super(message, options);
|
||||
this.name = 'GoogleModelsResponseError';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches every page of Google AI Studio models and converts supported models.
|
||||
*
|
||||
* @param {string | URL} modelsUrl Google AI Studio models endpoint
|
||||
* @param {typeof fetch} [fetchImpl] Fetch implementation
|
||||
* @returns {Promise<object[]>} Models that support content generation
|
||||
*/
|
||||
export async function fetchGoogleModels(modelsUrl, fetchImpl = fetch) {
|
||||
const requestUrl = new URL(modelsUrl);
|
||||
requestUrl.searchParams.set('pageSize', String(GOOGLE_MODELS_PAGE_SIZE));
|
||||
requestUrl.searchParams.delete('pageToken');
|
||||
|
||||
const models = [];
|
||||
const pageTokens = new Set();
|
||||
let pageNumber = 1;
|
||||
|
||||
while (true) {
|
||||
let response;
|
||||
|
||||
try {
|
||||
response = await fetchImpl(requestUrl.toString());
|
||||
} catch (cause) {
|
||||
throw new GoogleModelsResponseError(`Failed to fetch Google AI Studio models page ${pageNumber}.`, { cause });
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new GoogleModelsHttpError(response.status, response.statusText);
|
||||
}
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = await response.json();
|
||||
} catch (cause) {
|
||||
throw new GoogleModelsResponseError(`Failed to parse Google AI Studio models page ${pageNumber}.`, { cause });
|
||||
}
|
||||
|
||||
if (!data || !Array.isArray(data.models)) {
|
||||
throw new GoogleModelsResponseError(`Google AI Studio models page ${pageNumber} has an invalid models field.`);
|
||||
}
|
||||
|
||||
models.push(...data.models);
|
||||
|
||||
const nextPageToken = data.nextPageToken;
|
||||
if (nextPageToken === undefined || nextPageToken === '') {
|
||||
break;
|
||||
}
|
||||
if (typeof nextPageToken !== 'string') {
|
||||
throw new GoogleModelsResponseError(`Google AI Studio models page ${pageNumber} has an invalid nextPageToken.`);
|
||||
}
|
||||
if (pageTokens.has(nextPageToken)) {
|
||||
throw new GoogleModelsResponseError(`Google AI Studio models pagination repeated token on page ${pageNumber}.`);
|
||||
}
|
||||
|
||||
pageTokens.add(nextPageToken);
|
||||
requestUrl.searchParams.set('pageToken', nextPageToken);
|
||||
pageNumber++;
|
||||
}
|
||||
|
||||
return models
|
||||
.filter(model => model?.supportedGenerationMethods?.includes('generateContent'))
|
||||
.map((model, index) => {
|
||||
if (typeof model.name !== 'string') {
|
||||
throw new GoogleModelsResponseError(`Google AI Studio model at index ${index} has an invalid name.`);
|
||||
}
|
||||
|
||||
return {
|
||||
...model,
|
||||
id: model.name.replace('models/', ''),
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import storage from 'node-persist';
|
||||
|
||||
import { AVATAR_WIDTH, AVATAR_HEIGHT, DEFAULT_AVATAR_PATH } from '../constants.js';
|
||||
import { default as validateAvatarUrlMiddleware, getFileNameValidationFunction, forbiddenRegExp } from '../middleware/validateFileName.js';
|
||||
import { deepMerge, humanizedDateTime, tryParse, MemoryLimitedMap, getConfigValue, mutateJsonString, clientRelativePath, getUniqueName, sanitizeSafeCharacterReplacements } from '../util.js';
|
||||
import { deepMerge, humanizedDateTime, tryParse, MemoryLimitedMap, getConfigValue, mutateJsonString, clientRelativePath, getUniqueName, sanitizeSafeCharacterReplacements, getArrayBufferSlice } from '../util.js';
|
||||
import { TavernCardValidator } from '../validator/TavernCardValidator.js';
|
||||
import { parse, read, write } from '../character-card-parser.js';
|
||||
import { readWorldInfoFile } from './worldinfo.js';
|
||||
@@ -765,7 +765,7 @@ async function importFromYaml(uploadPath, context, preservedFileName) {
|
||||
async function importFromCharX(uploadPath, { request }, preservedFileName) {
|
||||
const fileBuffer = fs.readFileSync(uploadPath);
|
||||
// Create a properly-sized ArrayBuffer (Node's buffer pool can cause oversized .buffer)
|
||||
const data = fileBuffer.buffer.slice(fileBuffer.byteOffset, fileBuffer.byteOffset + fileBuffer.byteLength);
|
||||
const data = getArrayBufferSlice(fileBuffer);
|
||||
fs.unlinkSync(uploadPath);
|
||||
|
||||
const parser = new CharXParser(data);
|
||||
@@ -801,7 +801,7 @@ async function importFromCharX(uploadPath, { request }, preservedFileName) {
|
||||
}
|
||||
|
||||
async function importFromByaf(uploadPath, { request }, preservedFileName) {
|
||||
const data = (await fsPromises.readFile(uploadPath)).buffer;
|
||||
const data = getArrayBufferSlice(await fsPromises.readFile(uploadPath));
|
||||
await fsPromises.unlink(uploadPath);
|
||||
console.info('Importing from BYAF');
|
||||
|
||||
@@ -1081,7 +1081,9 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res
|
||||
|
||||
// Rename chats folder
|
||||
if (fs.existsSync(oldChatsPath) && !fs.existsSync(newChatsPath)) {
|
||||
fs.cpSync(oldChatsPath, newChatsPath, { recursive: true });
|
||||
// Supplying a filter avoids a Node.js Windows copyDir crash while preserving all entries.
|
||||
// https://github.com/nodejs/node/issues/63970
|
||||
fs.cpSync(oldChatsPath, newChatsPath, { recursive: true, filter: () => true });
|
||||
fs.rmSync(oldChatsPath, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
|
||||
+40
-12
@@ -1,3 +1,4 @@
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import readline from 'node:readline';
|
||||
@@ -30,6 +31,23 @@ const checkIntegrity = !!getConfigValue('backups.chat.checkIntegrity', true, 'bo
|
||||
|
||||
export const CHAT_BACKUPS_PREFIX = 'chat_';
|
||||
|
||||
/**
|
||||
* Builds a stable filename key for a chat's backups.
|
||||
* Non-ASCII characters are replaced with underscores, so names such as CJK ones
|
||||
* would all collapse to the same key and share one backup quota. A short hash of
|
||||
* the raw name keeps those keys distinct while ASCII names stay unchanged (#5780).
|
||||
* @param {string} name The name of the chat.
|
||||
* @returns {string} Sanitized filename key for the backup files.
|
||||
*/
|
||||
export function getBackupKey(name) {
|
||||
const sanitized = sanitize(name).replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
||||
if (/[^\x20-\x7E]/.test(name)) {
|
||||
const hash = crypto.createHash('sha256').update(name).digest('hex').slice(0, 8);
|
||||
return `${sanitized}_${hash}`;
|
||||
}
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a chat to the backups directory.
|
||||
* @param {string} directory The user's backup directory.
|
||||
@@ -44,8 +62,7 @@ function backupChat(directory, name, data, backupPrefix = CHAT_BACKUPS_PREFIX) {
|
||||
if (!fs.existsSync(directory)) {
|
||||
console.error(`The chat couldn't be backed up because no directory exists at ${directory}!`);
|
||||
}
|
||||
// replace non-alphanumeric characters with underscores
|
||||
name = sanitize(name).replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
||||
name = getBackupKey(name);
|
||||
|
||||
const backupFile = path.join(directory, `${backupPrefix}${name}_${generateTimestamp()}.jsonl`);
|
||||
|
||||
@@ -66,15 +83,19 @@ function backupChat(directory, name, data, backupPrefix = CHAT_BACKUPS_PREFIX) {
|
||||
const backupFunctions = new Map();
|
||||
|
||||
/**
|
||||
* Gets a backup function for a user.
|
||||
* Gets a backup function for a user and chat.
|
||||
* Throttling is keyed per user and chat so that rapid saves in one chat cannot
|
||||
* swallow the throttled backup of another chat saved in the same window.
|
||||
* @param {string} handle User handle
|
||||
* @param {string} name The name of the chat, as passed to backupChat
|
||||
* @returns {typeof backupChat} Backup function
|
||||
*/
|
||||
function getBackupFunction(handle) {
|
||||
if (!backupFunctions.has(handle)) {
|
||||
backupFunctions.set(handle, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true }));
|
||||
function getBackupFunction(handle, name) {
|
||||
const key = `${handle} ${name}`;
|
||||
if (!backupFunctions.has(key)) {
|
||||
backupFunctions.set(key, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true }));
|
||||
}
|
||||
return backupFunctions.get(handle) || (() => { });
|
||||
return backupFunctions.get(key) || (() => { });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,12 +487,19 @@ export async function getChatInfo(pathToFile, additionalData = {}, withMetadata
|
||||
|
||||
res(chatData);
|
||||
} else {
|
||||
console.warn('Found an invalid or corrupted chat file:', pathToFile);
|
||||
res({});
|
||||
// The last line is unparseable or lacks known fields (e.g. a truncated write or an external edit).
|
||||
// Resolve a degraded preview from the stat data instead of hiding an otherwise intact chat
|
||||
// from the chat list, search and recents.
|
||||
console.warn('Found an invalid or corrupted last line in a chat file:', pathToFile);
|
||||
// Exclude both the metadata line and the unreadable trailing line.
|
||||
chatData.chat_items = Math.max(itemCounter - 2, 0);
|
||||
chatData.mes = '[The message is empty]';
|
||||
chatData.match = hasMatcher ? hasAnyMatch : true;
|
||||
res(chatData);
|
||||
}
|
||||
} else {
|
||||
// The file was truncated after the stat reported a non-zero size
|
||||
res({});
|
||||
// The file was truncated after the stat reported a non-zero size; treat it like an empty chat
|
||||
res(chatData);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -511,7 +539,7 @@ export async function trySaveChat(chatData, filePath, skipIntegrityCheck = false
|
||||
throw new IntegrityMismatchError(`Chat integrity check failed for "${filePath}". The expected integrity slug was "${chatIntegritySlug}".`);
|
||||
}
|
||||
tryWriteFileSync(filePath, jsonlData);
|
||||
getBackupFunction(handle)(backupDirectory, cardName, jsonlData);
|
||||
getBackupFunction(handle, cardName)(backupDirectory, cardName, jsonlData);
|
||||
}
|
||||
|
||||
router.post('/save', validateAvatarUrlMiddleware, async function (request, response) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import sanitize from 'sanitize-filename';
|
||||
import { CheckRepoActions, default as simpleGit } from 'simple-git';
|
||||
|
||||
import { PUBLIC_DIRECTORIES } from '../constants.js';
|
||||
import { getConfigValue, isValidUrl } from '../util.js';
|
||||
import { color, getConfigValue, isValidUrl } from '../util.js';
|
||||
import { createGitClient } from '../git/client.js';
|
||||
|
||||
const gitBackend = getConfigValue('git.backend', 'auto');
|
||||
@@ -486,17 +486,35 @@ router.get('/discover', function (request, response) {
|
||||
fs.mkdirSync(PUBLIC_DIRECTORIES.globalExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* A directory without a manifest.json is not a usable extension: typically a leftover
|
||||
* from a manual deletion (e.g. a locked .git directory on Windows). Listing it would
|
||||
* make the client report a ghost extension and request its manifest in vain on every load.
|
||||
* @param {string} parentDirectory Directory containing extension folders
|
||||
* @param {string} folder Extension folder name
|
||||
* @returns {boolean} Whether the folder contains a manifest
|
||||
*/
|
||||
const hasManifest = (parentDirectory, folder) => {
|
||||
const manifestExists = fs.existsSync(path.join(parentDirectory, folder, 'manifest.json'));
|
||||
if (!manifestExists) {
|
||||
console.warn(color.yellow(`Extension folder "${path.join(parentDirectory, folder)}" has no manifest.json and was skipped. Remove the folder to get rid of this warning.`));
|
||||
}
|
||||
return manifestExists;
|
||||
};
|
||||
|
||||
// Get all folders in system extensions folder, excluding third-party
|
||||
const builtInExtensions = fs
|
||||
.readdirSync(PUBLIC_DIRECTORIES.extensions)
|
||||
.filter(f => fs.statSync(path.join(PUBLIC_DIRECTORIES.extensions, f)).isDirectory())
|
||||
.filter(f => f !== 'third-party')
|
||||
.filter(f => hasManifest(PUBLIC_DIRECTORIES.extensions, f))
|
||||
.map(f => ({ type: 'system', name: f }));
|
||||
|
||||
// Get all folders in local extensions folder
|
||||
const userExtensions = fs
|
||||
.readdirSync(path.join(request.user.directories.extensions))
|
||||
.filter(f => fs.statSync(path.join(request.user.directories.extensions, f)).isDirectory())
|
||||
.filter(f => hasManifest(request.user.directories.extensions, f))
|
||||
.map(f => ({ type: 'local', name: `third-party/${f}` }));
|
||||
|
||||
// Get all folders in global extensions folder
|
||||
@@ -504,6 +522,7 @@ router.get('/discover', function (request, response) {
|
||||
const globalExtensions = fs
|
||||
.readdirSync(PUBLIC_DIRECTORIES.globalExtensions)
|
||||
.filter(f => fs.statSync(path.join(PUBLIC_DIRECTORIES.globalExtensions, f)).isDirectory())
|
||||
.filter(f => hasManifest(PUBLIC_DIRECTORIES.globalExtensions, f))
|
||||
.map(f => ({ type: 'global', name: `third-party/${f}` }))
|
||||
.filter(f => !userExtensions.some(e => e.name === f.name));
|
||||
|
||||
|
||||
@@ -33,12 +33,11 @@ router.post('/generate-voice', async (request, response) => {
|
||||
} = request.body;
|
||||
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.MINIMAX);
|
||||
const groupId = readSecret(request.user.directories, SECRET_KEYS.MINIMAX_GROUP_ID);
|
||||
|
||||
// Validate required parameters
|
||||
if (!text || !voiceId || !apiKey || !groupId) {
|
||||
if (!text || !voiceId || !apiKey) {
|
||||
console.warn('MiniMax TTS: Missing required parameters');
|
||||
return response.status(400).json({ error: 'Missing required parameters: text, voiceId, apiKey, and groupId are required' });
|
||||
return response.status(400).json({ error: 'Missing required parameters: text, voiceId, and apiKey are required' });
|
||||
}
|
||||
|
||||
const requestBody = {
|
||||
@@ -64,7 +63,7 @@ router.post('/generate-voice', async (request, response) => {
|
||||
requestBody.lang = language;
|
||||
}
|
||||
|
||||
const apiUrl = `${apiHost}/v1/t2a_v2?GroupId=${groupId}`;
|
||||
const apiUrl = `${apiHost}/v1/t2a_v2`;
|
||||
|
||||
console.debug('MiniMax TTS Request:', {
|
||||
url: apiUrl,
|
||||
|
||||
@@ -235,19 +235,6 @@ router.post('/caption-image', async (request, response) => {
|
||||
apiUrl = `${trimV1(request.body.server_url)}/v1/chat/completions`;
|
||||
}
|
||||
|
||||
if (request.body.api === 'ooba') {
|
||||
const imgMessage = body.messages.pop();
|
||||
body.messages.push({
|
||||
role: 'user',
|
||||
content: imgMessage?.content?.[0]?.text,
|
||||
});
|
||||
body.messages.push({
|
||||
role: 'user',
|
||||
content: [],
|
||||
image_url: imgMessage?.content?.[1]?.image_url?.url,
|
||||
});
|
||||
}
|
||||
|
||||
setAdditionalHeaders(request, { headers }, apiUrl);
|
||||
console.debug('Multimodal captioning request', body);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ pollinations.post('/voices', async (req, res) => {
|
||||
throw new Error('Invalid data format received from Pollinations');
|
||||
}
|
||||
|
||||
const audioModelData = data.find(m => m.name === model);
|
||||
const audioModelData = data.find(m => m.name === model || m.aliases?.includes(model));
|
||||
if (!audioModelData || !Array.isArray(audioModelData.voices)) {
|
||||
throw new Error('No voices found for the specified model');
|
||||
}
|
||||
|
||||
@@ -611,7 +611,8 @@ comfy.post('/generate', async (request, response) => {
|
||||
}
|
||||
const outputs = Object.keys(item.outputs).map(it => item.outputs[it]);
|
||||
console.debug('ComfyUI outputs:', outputs);
|
||||
const imgInfo = outputs.map(it => it.images).flat()[0] ?? outputs.map(it => it.gifs).flat()[0];
|
||||
const imgInfo = outputs.map(it => it.images).filter(Array.isArray).flat()[0]
|
||||
?? outputs.map(it => it.gifs).filter(Array.isArray).flat()[0];
|
||||
if (!imgInfo) {
|
||||
throw new Error('ComfyUI did not return any recognizable outputs.');
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ export function getTokenizerModel(requestModel) {
|
||||
return 'o1';
|
||||
}
|
||||
|
||||
if (requestModel.includes('gpt-5') || requestModel.includes('o3') || requestModel.includes('o4-mini')) {
|
||||
if (requestModel.includes('gpt-5') || requestModel.includes('gpt-6-astra') || requestModel.includes('o3') || requestModel.includes('o4-mini')) {
|
||||
return 'o1';
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,12 @@ export default async function corsProxyMiddleware(req, res) {
|
||||
|
||||
headersToRemove.forEach(header => delete headers[header]);
|
||||
|
||||
// Force a set of encodings that node-fetch/undici can transparently decompress.
|
||||
// Some origins (e.g. Cloudflare-fronted sites) will respond with zstd when a browser's
|
||||
// full Accept-Encoding list is forwarded as-is; undici does not decode zstd, so the raw
|
||||
// compressed bytes would otherwise be piped straight through to the client as garbage.
|
||||
headers['accept-encoding'] = 'gzip, deflate, br';
|
||||
|
||||
const bodyMethods = ['POST', 'PUT', 'PATCH'];
|
||||
|
||||
const response = await fetch(url, {
|
||||
|
||||
@@ -453,13 +453,17 @@ export function convertGooglePrompt(messages, model, useSysPrompt, names) {
|
||||
const system_instruction = { parts: sysPrompt.map(text => ({ text })) };
|
||||
const toolNameMap = {};
|
||||
|
||||
// https://ai.google.dev/gemini-api/docs/latest-model#prefilled-model-turn-validation
|
||||
const noPrefillModel = /gemini-3\.[67]-flash|gemini-3\.5-flash-lite/.test(model);
|
||||
|
||||
const contents = [];
|
||||
messages.forEach((message, index) => {
|
||||
// fix the roles
|
||||
if (message.role === 'system' || message.role === 'tool') {
|
||||
message.role = 'user';
|
||||
} else if (message.role === 'assistant') {
|
||||
message.role = 'model';
|
||||
// A trailing model turn is a prefill, which is rejected by the newest models
|
||||
message.role = noPrefillModel && index === messages.length - 1 ? 'user' : 'model';
|
||||
}
|
||||
|
||||
// Convert the content to an array of parts
|
||||
@@ -1259,11 +1263,13 @@ export function calculateGoogleBudgetTokens(maxTokens, reasoningEffort, model) {
|
||||
}
|
||||
|
||||
function getGemini3FlashBudget() {
|
||||
// https://ai.google.dev/gemini-api/docs/models/gemini-3.7-flash
|
||||
const noMinimalThinking = /gemini-3\.7-flash/.test(model);
|
||||
switch (reasoningEffort) {
|
||||
case REASONING_EFFORT.auto:
|
||||
return null;
|
||||
case REASONING_EFFORT.min:
|
||||
return 'minimal';
|
||||
return noMinimalThinking ? 'low' : 'minimal';
|
||||
case REASONING_EFFORT.low:
|
||||
return 'low';
|
||||
case REASONING_EFFORT.medium:
|
||||
|
||||
+14
@@ -486,6 +486,20 @@ export async function readAllChunks(readableStream) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a precisely-sized ArrayBuffer from a Uint8Array view such as a Node Buffer.
|
||||
* This avoids leaking unrelated bytes from the underlying backing store.
|
||||
* @param {Uint8Array} view Source byte view
|
||||
* @returns {ArrayBuffer} Exact ArrayBuffer slice for the provided view
|
||||
*/
|
||||
export function getArrayBufferSlice(view) {
|
||||
if (!(view instanceof Uint8Array)) {
|
||||
throw new TypeError('Expected Uint8Array');
|
||||
}
|
||||
|
||||
return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
|
||||
}
|
||||
|
||||
function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals';
|
||||
import archiver from 'archiver';
|
||||
|
||||
import { ByafParser } from '../src/byaf.js';
|
||||
import { getArrayBufferSlice } from '../src/util.js';
|
||||
|
||||
// The parser reads the default avatar from a repo-root-relative path
|
||||
const originalCwd = process.cwd();
|
||||
beforeAll(() => process.chdir(path.resolve(originalCwd, '..')));
|
||||
afterAll(() => process.chdir(originalCwd));
|
||||
|
||||
/**
|
||||
* Builds a minimal valid BYAF archive in memory.
|
||||
* @returns {Promise<Buffer>} Zipped BYAF bytes
|
||||
*/
|
||||
function buildByafArchive() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const archive = archiver('zip', { zlib: { level: 9 } });
|
||||
const chunks = [];
|
||||
archive.on('data', chunk => chunks.push(chunk));
|
||||
archive.on('error', reject);
|
||||
archive.on('end', () => resolve(Buffer.concat(chunks)));
|
||||
|
||||
archive.append(JSON.stringify({
|
||||
characters: ['characters/character.json'],
|
||||
scenarios: ['scenarios/scenario.json'],
|
||||
}), { name: 'manifest.json' });
|
||||
archive.append(JSON.stringify({
|
||||
name: 'Byaf Test Character',
|
||||
persona: 'A test persona.',
|
||||
images: [{ path: 'images/icon.png', label: '' }],
|
||||
}), { name: 'characters/character.json' });
|
||||
const pngPixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==', 'base64');
|
||||
archive.append(pngPixel, { name: 'characters/images/icon.png' });
|
||||
archive.append(JSON.stringify({
|
||||
name: 'Test Scenario',
|
||||
messages: [],
|
||||
}), { name: 'scenarios/scenario.json' });
|
||||
archive.finalize();
|
||||
});
|
||||
}
|
||||
|
||||
describe('BYAF import buffer handling', () => {
|
||||
/** @type {Buffer} */
|
||||
let zipBuffer;
|
||||
/** @type {Buffer} */
|
||||
let pooledView;
|
||||
|
||||
beforeAll(async () => {
|
||||
zipBuffer = await buildByafArchive();
|
||||
// Simulate Node's buffer pooling: the archive bytes sit at an offset inside
|
||||
// a larger backing buffer surrounded by unrelated bytes.
|
||||
const backing = Buffer.alloc(zipBuffer.length + 8192, 0xFF);
|
||||
zipBuffer.copy(backing, 4096);
|
||||
pooledView = backing.subarray(4096, 4096 + zipBuffer.length);
|
||||
});
|
||||
|
||||
test('parses a real BYAF archive from an exact ArrayBuffer slice of a pooled view', async () => {
|
||||
const exact = getArrayBufferSlice(pooledView);
|
||||
expect(exact.byteLength).toBe(zipBuffer.length);
|
||||
|
||||
const parser = new ByafParser(exact);
|
||||
const result = await parser.parse();
|
||||
expect(result.card?.data?.name).toBe('Byaf Test Character');
|
||||
});
|
||||
|
||||
test('the raw oversized backing buffer is not parseable, which is why callers must slice', async () => {
|
||||
const parser = new ByafParser(pooledView.buffer);
|
||||
await expect(parser.parse()).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
import { beforeAll, afterAll, describe, test, expect } from '@jest/globals';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
// chats.js reads these config values at module load. Environment variables take
|
||||
// precedence over config.yaml, so setting them here lets the module import
|
||||
// without a config file present. The short throttle interval keeps lodash
|
||||
// timers from delaying the Jest process while still being long enough that a
|
||||
// per-user (rather than per-chat) throttle would defer the second chat's backup.
|
||||
process.env.SILLYTAVERN_BACKUPS_CHAT_ENABLED = 'true';
|
||||
process.env.SILLYTAVERN_BACKUPS_CHAT_MAXTOTALBACKUPS = '-1';
|
||||
process.env.SILLYTAVERN_BACKUPS_CHAT_THROTTLEINTERVAL = '200';
|
||||
process.env.SILLYTAVERN_BACKUPS_CHAT_CHECKINTEGRITY = 'false';
|
||||
process.env.SILLYTAVERN_BACKUPS_COMMON_NUMBEROFBACKUPS = '1';
|
||||
|
||||
/** @type {import('../src/endpoints/chats.js')} */
|
||||
let chats;
|
||||
let workDir;
|
||||
|
||||
beforeAll(async () => {
|
||||
chats = await import('../src/endpoints/chats.js');
|
||||
workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'st-backups-'));
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
fs.rmSync(workDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
/**
|
||||
* Builds a minimal chat array like the client sends it.
|
||||
* @param {string} message Message text
|
||||
* @returns {object[]} Chat array
|
||||
*/
|
||||
function makeChat(message) {
|
||||
return [
|
||||
{ user_name: 'User', character_name: 'Char', chat_metadata: {} },
|
||||
{ name: 'Char', is_user: false, mes: message },
|
||||
];
|
||||
}
|
||||
|
||||
describe('getBackupKey', () => {
|
||||
test('keeps plain ASCII names unchanged', () => {
|
||||
expect(chats.getBackupKey('Seraphina')).toBe('seraphina');
|
||||
expect(chats.getBackupKey('Some Test')).toBe('some_test');
|
||||
});
|
||||
|
||||
test('produces distinct stable keys for names that sanitize identically', () => {
|
||||
const keyA = chats.getBackupKey('雷电将军');
|
||||
const keyB = chats.getBackupKey('测试角色');
|
||||
|
||||
expect(keyA).not.toBe(keyB);
|
||||
expect(chats.getBackupKey('雷电将军')).toBe(keyA);
|
||||
});
|
||||
});
|
||||
|
||||
describe('chat backups', () => {
|
||||
test('chats with equal-length CJK names get independent backups and quotas', async () => {
|
||||
const backupsDir = path.join(workDir, 'backups');
|
||||
const chatsDir = path.join(workDir, 'chats');
|
||||
fs.mkdirSync(backupsDir, { recursive: true });
|
||||
fs.mkdirSync(chatsDir, { recursive: true });
|
||||
|
||||
// numberOfBackups is 1: with a shared backup key, the second chat's
|
||||
// backup would evict the first; with a shared throttle, it would not be
|
||||
// written at the leading edge at all
|
||||
await chats.trySaveChat(makeChat('first'), path.join(chatsDir, 'a.jsonl'), true, 'test-user', '雷电将军', backupsDir);
|
||||
await chats.trySaveChat(makeChat('second'), path.join(chatsDir, 'b.jsonl'), true, 'test-user', '测试角色', backupsDir);
|
||||
|
||||
const backupFiles = fs.readdirSync(backupsDir);
|
||||
expect(backupFiles).toHaveLength(2);
|
||||
|
||||
const keyA = chats.getBackupKey('雷电将军');
|
||||
const keyB = chats.getBackupKey('测试角色');
|
||||
expect(backupFiles.some(f => f.startsWith(`chat_${keyA}_`))).toBe(true);
|
||||
expect(backupFiles.some(f => f.startsWith(`chat_${keyB}_`))).toBe(true);
|
||||
});
|
||||
});
|
||||
+31
-3
@@ -85,7 +85,10 @@ describe('getChatInfo', () => {
|
||||
fs.writeFileSync(chatFile, '');
|
||||
jest.spyOn(fs.promises, 'stat').mockResolvedValue(/** @type {any} */({ size: 100, mtimeMs: 1_000_000 }));
|
||||
const info = await chats.getChatInfo(chatFile);
|
||||
expect(info).toEqual({});
|
||||
expect(info.file_name).toBe('chat.jsonl');
|
||||
expect(info.chat_items).toBe(0);
|
||||
expect(info.mes).toBe('[The chat is empty]');
|
||||
expect(info.match).toBe(false);
|
||||
});
|
||||
|
||||
test('rejects with the original error for non-ENOENT stat failures', async () => {
|
||||
@@ -94,9 +97,34 @@ describe('getChatInfo', () => {
|
||||
await expect(chats.getChatInfo(chatFile)).rejects.toThrow('EACCES');
|
||||
});
|
||||
|
||||
test('resolves an empty object for a corrupted chat file', async () => {
|
||||
test('resolves a degraded preview for a fully corrupted chat file', async () => {
|
||||
fs.writeFileSync(chatFile, 'not json at all\nstill not json');
|
||||
const info = await chats.getChatInfo(chatFile);
|
||||
expect(info).toEqual({});
|
||||
expect(info.file_id).toBe('chat');
|
||||
expect(info.file_name).toBe('chat.jsonl');
|
||||
expect(info.chat_items).toBe(0);
|
||||
expect(info.mes).toBe('[The message is empty]');
|
||||
expect(info.match).toBe(true);
|
||||
});
|
||||
|
||||
test('resolves a degraded preview when only the last line is unparseable', async () => {
|
||||
// e.g. a partially flushed write or an external edit truncated the final line
|
||||
fs.writeFileSync(chatFile, makeChatJsonl() + '\n' + '{"name": "User", "is_user": true, "mes": "Trunc');
|
||||
const info = await chats.getChatInfo(chatFile);
|
||||
expect(info.file_id).toBe('chat');
|
||||
expect(info.file_name).toBe('chat.jsonl');
|
||||
expect(info.chat_items).toBe(2);
|
||||
expect(info.mes).toBe('[The message is empty]');
|
||||
expect(info.match).toBe(true);
|
||||
});
|
||||
|
||||
test('matcher still applies to intact messages when the last line is unparseable', async () => {
|
||||
fs.writeFileSync(chatFile, makeChatJsonl() + '\n' + '{"broken');
|
||||
const matching = await chats.getChatInfo(chatFile, {}, false, lines => lines.some(l => l.includes('Second')));
|
||||
expect(matching.match).toBe(true);
|
||||
expect(matching.file_name).toBe('chat.jsonl');
|
||||
const nonMatching = await chats.getChatInfo(chatFile, {}, false, lines => lines.some(l => l.includes('nope')));
|
||||
expect(nonMatching.match).toBe(false);
|
||||
expect(nonMatching.file_name).toBe('chat.jsonl');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { afterEach, beforeEach, describe, expect, jest, test } from '@jest/globals';
|
||||
import { addMissingConfigValues } from '../src/config-init.js';
|
||||
|
||||
const oldEnvKey = 'SILLYTAVERN_DISABLETHUMBNAILS';
|
||||
const newEnvKey = 'SILLYTAVERN_THUMBNAILS_ENABLED';
|
||||
|
||||
describe('addMissingConfigValues', () => {
|
||||
let tempDirectory;
|
||||
let configPath;
|
||||
|
||||
beforeEach(() => {
|
||||
tempDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'sillytavern-config-'));
|
||||
configPath = path.join(tempDirectory, 'config.yaml');
|
||||
fs.writeFileSync(configPath, '{}\n');
|
||||
delete process.env[oldEnvKey];
|
||||
delete process.env[newEnvKey];
|
||||
jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env[oldEnvKey];
|
||||
delete process.env[newEnvKey];
|
||||
fs.rmSync(tempDirectory, { recursive: true, force: true });
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
test.each([
|
||||
['false', 'true'],
|
||||
['true', 'false'],
|
||||
])('migrates the boolean environment value %s to %s', (oldValue, newValue) => {
|
||||
process.env[oldEnvKey] = oldValue;
|
||||
|
||||
addMissingConfigValues(configPath);
|
||||
|
||||
expect(process.env[newEnvKey]).toBe(newValue);
|
||||
expect(process.env[oldEnvKey]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals';
|
||||
|
||||
// extensions.js reads these config values at module load or per request; the env var
|
||||
// overrides avoid needing a config.yaml in the test environment
|
||||
process.env.SILLYTAVERN_GIT_BACKEND = 'auto';
|
||||
process.env.SILLYTAVERN_EXTENSIONS_ENABLED = 'true';
|
||||
|
||||
// The extensions endpoint resolves the built-in extensions folder relative to the repo root
|
||||
const originalCwd = process.cwd();
|
||||
beforeAll(() => process.chdir(path.resolve(originalCwd, '..')));
|
||||
afterAll(() => process.chdir(originalCwd));
|
||||
|
||||
describe('extensions discover', () => {
|
||||
/** @type {import('node:http').Server} */
|
||||
let server;
|
||||
let baseUrl;
|
||||
let userExtensionsDir;
|
||||
|
||||
beforeAll(async () => {
|
||||
userExtensionsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'st-extensions-'));
|
||||
|
||||
// A valid extension with a manifest
|
||||
fs.mkdirSync(path.join(userExtensionsDir, 'Valid-Extension'));
|
||||
fs.writeFileSync(path.join(userExtensionsDir, 'Valid-Extension', 'manifest.json'), JSON.stringify({ display_name: 'Valid' }));
|
||||
|
||||
// A leftover folder without a manifest (e.g. locked .git remnant after manual deletion)
|
||||
fs.mkdirSync(path.join(userExtensionsDir, 'Deleted-Husk'));
|
||||
fs.mkdirSync(path.join(userExtensionsDir, 'Deleted-Husk', '.git'));
|
||||
|
||||
const { default: express } = await import('express');
|
||||
const { router } = await import('../src/endpoints/extensions.js');
|
||||
const app = express();
|
||||
app.use((req, _res, next) => {
|
||||
req.user = {
|
||||
profile: { handle: 'test-user' },
|
||||
directories: { extensions: userExtensionsDir },
|
||||
};
|
||||
next();
|
||||
});
|
||||
app.use(router);
|
||||
server = app.listen(0, '127.0.0.1');
|
||||
await new Promise(resolve => server.once('listening', resolve));
|
||||
baseUrl = `http://127.0.0.1:${server.address().port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
|
||||
fs.rmSync(userExtensionsDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('lists folders with a manifest and skips folders without one', async () => {
|
||||
const response = await fetch(`${baseUrl}/discover`);
|
||||
expect(response.status).toBe(200);
|
||||
const extensions = await response.json();
|
||||
const names = extensions.map(x => x.name);
|
||||
expect(names).toContain('third-party/Valid-Extension');
|
||||
expect(names).not.toContain('third-party/Deleted-Husk');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { testSetup } from './frontent-test-utils.js';
|
||||
|
||||
test.describe('deleting assistant messages with tool calls', () => {
|
||||
test.beforeEach(testSetup.awaitST);
|
||||
|
||||
test('deletes preceding tool calls unless explicitly disabled', async ({ page }) => {
|
||||
const result = await page.evaluate(async () => {
|
||||
const { addOneMessage, chat, deleteMessage, newAssistantChat } = await import('./script.js');
|
||||
const commands = window.SillyTavern.getContext().SlashCommandParser.commands;
|
||||
const testMessages = new Set(['Run a tool', 'Tool result', 'Done']);
|
||||
const snapshot = () => chat
|
||||
.filter(message => testMessages.has(message.mes))
|
||||
.map(message => ({
|
||||
mes: message.mes,
|
||||
toolCall: Array.isArray(message.extra?.tool_invocations),
|
||||
}));
|
||||
|
||||
const addMessages = async () => {
|
||||
const messages = [
|
||||
{ name: 'User', is_user: true, is_system: false, mes: 'Run a tool', extra: {} },
|
||||
{
|
||||
name: 'System',
|
||||
is_user: false,
|
||||
is_system: true,
|
||||
mes: 'Tool result',
|
||||
extra: { isSmallSys: true, tool_invocations: [{ id: 'call-1', name: 'lookup' }] },
|
||||
},
|
||||
{ name: 'Assistant', is_user: false, is_system: false, mes: 'Done', extra: {} },
|
||||
];
|
||||
for (const message of messages) {
|
||||
chat.push(message);
|
||||
await addOneMessage(message);
|
||||
}
|
||||
};
|
||||
|
||||
await newAssistantChat({ temporary: true });
|
||||
await addMessages();
|
||||
await deleteMessage(chat.length - 1, undefined, false);
|
||||
const automatic = snapshot();
|
||||
|
||||
await newAssistantChat({ temporary: true });
|
||||
await addMessages();
|
||||
await commands.cut.callback({ toolcalls: 'false' }, String(chat.length - 1));
|
||||
const disabled = snapshot();
|
||||
|
||||
await newAssistantChat({ temporary: true });
|
||||
await addMessages();
|
||||
chat.push({ name: 'Assistant', is_user: false, is_system: false, mes: 'Later', extra: {} });
|
||||
await addOneMessage(chat.at(-1));
|
||||
await commands.del.callback({ toolcalls: 'true' }, '2');
|
||||
const range = chat
|
||||
.filter(message => new Set([...testMessages, 'Later']).has(message.mes))
|
||||
.map(message => message.mes);
|
||||
|
||||
await newAssistantChat({ temporary: true });
|
||||
await addMessages();
|
||||
document.querySelector('#option_delete_mes').click();
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
document.querySelector(`.mes[mesid="${chat.length - 1}"]`).click();
|
||||
document.querySelector('#dialogue_del_mes_ok').click();
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
const deleteMode = snapshot();
|
||||
|
||||
return { automatic, deleteMode, disabled, range };
|
||||
});
|
||||
|
||||
expect(result.automatic).toEqual([{ mes: 'Run a tool', toolCall: false }]);
|
||||
expect(result.disabled).toEqual([
|
||||
{ mes: 'Run a tool', toolCall: false },
|
||||
{ mes: 'Tool result', toolCall: true },
|
||||
]);
|
||||
expect(result.range).toEqual(['Run a tool']);
|
||||
expect(result.deleteMode).toEqual([{ mes: 'Run a tool', toolCall: false }]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { testSetup } from './frontent-test-utils.js';
|
||||
|
||||
test.describe('Quick Reply overwrite cancellation', () => {
|
||||
test.beforeEach(testSetup.awaitST);
|
||||
|
||||
for (const operation of ['create', 'import']) {
|
||||
test(`should keep the existing set when ${operation} overwrite is cancelled`, async ({ page }) => {
|
||||
const result = await page.evaluate(async (operation) => {
|
||||
const { Popup, POPUP_RESULT } = await import('./scripts/popup.js');
|
||||
const { QuickReplySet } = await import('./scripts/extensions/quick-reply/src/QuickReplySet.js');
|
||||
const { SettingsUi } = await import('./scripts/extensions/quick-reply/src/ui/SettingsUi.js');
|
||||
|
||||
const setName = 'STAGE_REPRO_OVERWRITE_CANCEL';
|
||||
const existingSet = { name: setName };
|
||||
const originalSets = QuickReplySet.list;
|
||||
const originalInput = Popup.show.input;
|
||||
const originalConfirm = Popup.show.confirm;
|
||||
const originalFrom = QuickReplySet.from;
|
||||
const originalAddQuickReply = QuickReplySet.prototype.addQuickReply;
|
||||
let deleteCalls = 0;
|
||||
let confirmMessage = '';
|
||||
|
||||
try {
|
||||
QuickReplySet.list = [existingSet];
|
||||
Popup.show.input = async () => setName;
|
||||
Popup.show.confirm = async (_title, message) => {
|
||||
confirmMessage = message;
|
||||
return POPUP_RESULT.NEGATIVE;
|
||||
};
|
||||
QuickReplySet.prototype.addQuickReply = () => {};
|
||||
QuickReplySet.from = props => ({
|
||||
...props,
|
||||
qrList: [],
|
||||
init: () => {},
|
||||
save: async () => {},
|
||||
});
|
||||
|
||||
const settingsUi = new SettingsUi({});
|
||||
settingsUi.currentSet = document.createElement('select');
|
||||
settingsUi.doDeleteQrSet = async () => deleteCalls++;
|
||||
settingsUi.rerender = () => {};
|
||||
settingsUi.onQrSetChange = () => {};
|
||||
settingsUi.prepareGlobalSetList = () => {};
|
||||
settingsUi.prepareChatSetList = () => {};
|
||||
settingsUi.prepareCharacterSetList = () => {};
|
||||
|
||||
if (operation === 'create') {
|
||||
await settingsUi.addQrSet();
|
||||
} else {
|
||||
const file = {
|
||||
name: 'duplicate.json',
|
||||
text: async () => JSON.stringify({ version: 2, name: setName, qrList: [] }),
|
||||
};
|
||||
await settingsUi.importSingleQrSet(file);
|
||||
}
|
||||
|
||||
return {
|
||||
confirmMessage,
|
||||
deleteCalls,
|
||||
setNames: QuickReplySet.list.map(set => set.name),
|
||||
setName,
|
||||
};
|
||||
} finally {
|
||||
QuickReplySet.list = originalSets;
|
||||
Popup.show.input = originalInput;
|
||||
Popup.show.confirm = originalConfirm;
|
||||
QuickReplySet.from = originalFrom;
|
||||
QuickReplySet.prototype.addQuickReply = originalAddQuickReply;
|
||||
}
|
||||
}, operation);
|
||||
|
||||
expect(result.confirmMessage).toContain(`"${result.setName}"`);
|
||||
expect(result.deleteCalls).toBe(0);
|
||||
expect(result.setNames).toEqual([result.setName]);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,123 @@
|
||||
import { describe, expect, jest, test } from '@jest/globals';
|
||||
import {
|
||||
fetchGoogleModels,
|
||||
GoogleModelsHttpError,
|
||||
GoogleModelsResponseError,
|
||||
} from '../src/endpoints/backends/google-models.js';
|
||||
|
||||
function createResponse(data, overrides = {}) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
json: async () => data,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('Google AI Studio model pagination', () => {
|
||||
test('fetches every page and returns generateContent models', async () => {
|
||||
const fetchMock = jest.fn()
|
||||
.mockResolvedValueOnce(createResponse({
|
||||
models: [
|
||||
{
|
||||
name: 'models/gemini-2.5-flash',
|
||||
supportedGenerationMethods: ['generateContent', 'countTokens'],
|
||||
},
|
||||
{
|
||||
name: 'models/gemini-embedding-001',
|
||||
supportedGenerationMethods: ['embedContent'],
|
||||
},
|
||||
],
|
||||
nextPageToken: 'second-page',
|
||||
}))
|
||||
.mockResolvedValueOnce(createResponse({
|
||||
models: [{
|
||||
name: 'models/gemini-2.5-pro',
|
||||
supportedGenerationMethods: ['generateContent'],
|
||||
}],
|
||||
}));
|
||||
|
||||
const models = await fetchGoogleModels('https://example.com/v1beta/models?key=secret', fetchMock);
|
||||
|
||||
expect(models).toEqual([
|
||||
{
|
||||
id: 'gemini-2.5-flash',
|
||||
name: 'models/gemini-2.5-flash',
|
||||
supportedGenerationMethods: ['generateContent', 'countTokens'],
|
||||
},
|
||||
{
|
||||
id: 'gemini-2.5-pro',
|
||||
name: 'models/gemini-2.5-pro',
|
||||
supportedGenerationMethods: ['generateContent'],
|
||||
},
|
||||
]);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
const firstUrl = new URL(fetchMock.mock.calls[0][0]);
|
||||
expect(firstUrl.searchParams.get('key')).toBe('secret');
|
||||
expect(firstUrl.searchParams.get('pageSize')).toBe('1000');
|
||||
expect(firstUrl.searchParams.has('pageToken')).toBe(false);
|
||||
|
||||
const secondUrl = new URL(fetchMock.mock.calls[1][0]);
|
||||
expect(secondUrl.searchParams.get('key')).toBe('secret');
|
||||
expect(secondUrl.searchParams.get('pageSize')).toBe('1000');
|
||||
expect(secondUrl.searchParams.get('pageToken')).toBe('second-page');
|
||||
});
|
||||
|
||||
test('preserves reverse proxy query parameters', async () => {
|
||||
const fetchMock = jest.fn().mockResolvedValue(createResponse({ models: [] }));
|
||||
|
||||
await fetchGoogleModels('https://proxy.example/v1beta/models?tenant=test', fetchMock);
|
||||
|
||||
const requestUrl = new URL(fetchMock.mock.calls[0][0]);
|
||||
expect(requestUrl.searchParams.get('tenant')).toBe('test');
|
||||
expect(requestUrl.searchParams.get('pageSize')).toBe('1000');
|
||||
});
|
||||
|
||||
test('rejects an HTTP failure without returning partial models', async () => {
|
||||
const fetchMock = jest.fn()
|
||||
.mockResolvedValueOnce(createResponse({
|
||||
models: [],
|
||||
nextPageToken: 'second-page',
|
||||
}))
|
||||
.mockResolvedValueOnce(createResponse(null, {
|
||||
ok: false,
|
||||
status: 503,
|
||||
statusText: 'Service Unavailable',
|
||||
}));
|
||||
|
||||
await expect(fetchGoogleModels('https://example.com/v1beta/models', fetchMock))
|
||||
.rejects.toEqual(expect.objectContaining({
|
||||
name: GoogleModelsHttpError.name,
|
||||
status: 503,
|
||||
statusText: 'Service Unavailable',
|
||||
}));
|
||||
});
|
||||
|
||||
test('rejects a malformed models field', async () => {
|
||||
const fetchMock = jest.fn().mockResolvedValue(createResponse({ models: null }));
|
||||
|
||||
await expect(fetchGoogleModels('https://example.com/v1beta/models', fetchMock))
|
||||
.rejects.toThrow('invalid models field');
|
||||
});
|
||||
|
||||
test('rejects a repeated page token', async () => {
|
||||
const fetchMock = jest.fn()
|
||||
.mockResolvedValueOnce(createResponse({ models: [], nextPageToken: 'repeated' }))
|
||||
.mockResolvedValueOnce(createResponse({ models: [], nextPageToken: 'repeated' }));
|
||||
|
||||
await expect(fetchGoogleModels('https://example.com/v1beta/models', fetchMock))
|
||||
.rejects.toBeInstanceOf(GoogleModelsResponseError);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test('rejects a supported model without a valid name', async () => {
|
||||
const fetchMock = jest.fn().mockResolvedValue(createResponse({
|
||||
models: [{ supportedGenerationMethods: ['generateContent'] }],
|
||||
}));
|
||||
|
||||
await expect(fetchGoogleModels('https://example.com/v1beta/models', fetchMock))
|
||||
.rejects.toThrow('invalid name');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
import { beforeAll, describe, expect, jest, test } from '@jest/globals';
|
||||
|
||||
const jqueryElement = {
|
||||
append: jest.fn(function () { return this; }),
|
||||
children: jest.fn(() => ({ each: jest.fn() })),
|
||||
detach: jest.fn(function () { return this; }),
|
||||
empty: jest.fn(function () { return this; }),
|
||||
find: jest.fn(function () { return this; }),
|
||||
on: jest.fn(function () { return this; }),
|
||||
prop: jest.fn(function () { return this; }),
|
||||
trigger: jest.fn(function () { return this; }),
|
||||
val: jest.fn(function () { return this; }),
|
||||
};
|
||||
|
||||
global.$ = jest.fn(() => jqueryElement);
|
||||
|
||||
jest.unstable_mockModule('../public/script.js', () => ({
|
||||
abortStatusCheck: { signal: undefined },
|
||||
event_types: {},
|
||||
eventSource: { emit: jest.fn() },
|
||||
getRequestHeaders: jest.fn(),
|
||||
getStoppingStrings: jest.fn(),
|
||||
resultCheckStatus: jest.fn(),
|
||||
saveSettingsDebounced: jest.fn(),
|
||||
setGenerationParamsFromPreset: jest.fn(),
|
||||
setOnlineStatus: jest.fn(),
|
||||
startStatusLoading: jest.fn(),
|
||||
}));
|
||||
jest.unstable_mockModule('../public/scripts/power-user.js', () => ({
|
||||
MAX_CONTEXT_DEFAULT: 8192,
|
||||
MAX_RESPONSE_DEFAULT: 150,
|
||||
power_user: {},
|
||||
}));
|
||||
jest.unstable_mockModule('../public/scripts/tokenizers.js', () => ({
|
||||
getTextTokens: jest.fn(),
|
||||
tokenizers: { NONE: 0, NERD: 1, NERD2: 2, LLAMA3: 3 },
|
||||
}));
|
||||
jest.unstable_mockModule('../public/scripts/sse-stream.js', () => ({ getEventSourceStream: jest.fn() }));
|
||||
jest.unstable_mockModule('../public/scripts/utils.js', () => ({
|
||||
getSortableDelay: jest.fn(),
|
||||
getStringHash: jest.fn(),
|
||||
onlyUnique: jest.fn(),
|
||||
}));
|
||||
jest.unstable_mockModule('../public/scripts/logit-bias.js', () => ({
|
||||
BIAS_CACHE: new Map(),
|
||||
createNewLogitBiasEntry: jest.fn(),
|
||||
displayLogitBias: jest.fn(),
|
||||
getLogitBiasListResult: jest.fn(),
|
||||
}));
|
||||
jest.unstable_mockModule('../public/scripts/secrets.js', () => ({
|
||||
SECRET_KEYS: {},
|
||||
secret_state: {},
|
||||
writeSecret: jest.fn(),
|
||||
}));
|
||||
|
||||
let loadNovelPreset;
|
||||
let loadNovelSettings;
|
||||
let naiSettings;
|
||||
|
||||
beforeAll(async () => {
|
||||
({
|
||||
loadNovelPreset,
|
||||
loadNovelSettings,
|
||||
nai_settings: naiSettings,
|
||||
} = await import('../public/scripts/nai-settings.js'));
|
||||
});
|
||||
|
||||
describe('NovelAI settings', () => {
|
||||
test('preserves a zero Math1 temperature when loading settings', () => {
|
||||
loadNovelSettings(
|
||||
{ novelai_setting_names: [], novelai_settings: [] },
|
||||
{ ...naiSettings, math1_temp: 0 },
|
||||
);
|
||||
expect(naiSettings.math1_temp).toBe(0);
|
||||
|
||||
naiSettings.math1_temp = 1;
|
||||
loadNovelPreset({ ...naiSettings, genamt: 150, math1_temp: 0 });
|
||||
expect(naiSettings.math1_temp).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, jest, test } from '@jest/globals';
|
||||
|
||||
const fetchMock = jest.fn();
|
||||
jest.unstable_mockModule('node-fetch', () => ({ default: fetchMock }));
|
||||
jest.unstable_mockModule('../src/transformers.js', () => ({ getPipeline: jest.fn() }));
|
||||
jest.unstable_mockModule('../src/endpoints/secrets.js', () => ({
|
||||
readSecret: jest.fn(),
|
||||
SECRET_KEYS: {},
|
||||
}));
|
||||
|
||||
describe('Pollinations TTS model aliases', () => {
|
||||
/** @type {import('node:http').Server} */
|
||||
let server;
|
||||
let baseUrl;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { default: express } = await import('express');
|
||||
const { router: speechRouter } = await import('../src/endpoints/speech.js');
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use('/speech', speechRouter);
|
||||
server = app.listen(0, '127.0.0.1');
|
||||
await new Promise(resolve => server.once('listening', resolve));
|
||||
const address = server.address();
|
||||
baseUrl = `http://127.0.0.1:${address.port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.mockReset();
|
||||
});
|
||||
|
||||
test.each([undefined, 'openai-audio', 'openai/gpt-audio-mini'])('looks up voices for %s', async (model) => {
|
||||
fetchMock.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => [{ name: 'openai/gpt-audio-mini', aliases: ['openai-audio'], voices: ['alloy', 'nova'] }],
|
||||
});
|
||||
|
||||
const response = await fetch(`${baseUrl}/speech/pollinations/voices`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ model }),
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toEqual(['alloy', 'nova']);
|
||||
});
|
||||
|
||||
test('still accepts catalogs without aliases', async () => {
|
||||
fetchMock.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => [{ name: 'openai-audio', voices: ['alloy'] }],
|
||||
});
|
||||
|
||||
const response = await fetch(`${baseUrl}/speech/pollinations/voices`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: '{}',
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toEqual(['alloy']);
|
||||
});
|
||||
});
|
||||
@@ -166,6 +166,27 @@ describe('calculateGoogleBudgetTokens', () => {
|
||||
test('max returns high', () => expect(mod.calculateGoogleBudgetTokens(8192, 'max', 'gemini-3.5-flash')).toBe('high'));
|
||||
});
|
||||
|
||||
test('Gemini 3.7 Flash uses Gemini 3 thinking levels without minimal', () => {
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'auto', 'gemini-3.7-flash')).toBeNull();
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'min', 'gemini-3.7-flash')).toBe('low');
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'medium', 'gemini-3.7-flash')).toBe('medium');
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'max', 'gemini-3.7-flash')).toBe('high');
|
||||
});
|
||||
|
||||
test('Gemini 3.6 Flash uses Gemini 3 thinking levels', () => {
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'auto', 'gemini-3.6-flash')).toBeNull();
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'min', 'gemini-3.6-flash')).toBe('minimal');
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'medium', 'gemini-3.6-flash')).toBe('medium');
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'max', 'gemini-3.6-flash')).toBe('high');
|
||||
});
|
||||
|
||||
test('Gemini 3.5 Flash-Lite uses Gemini 3 thinking levels', () => {
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'auto', 'gemini-3.5-flash-lite')).toBeNull();
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'min', 'gemini-3.5-flash-lite')).toBe('minimal');
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'medium', 'gemini-3.5-flash-lite')).toBe('medium');
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'max', 'gemini-3.5-flash-lite')).toBe('high');
|
||||
});
|
||||
|
||||
test('stable Gemini 3.1 Flash-Lite uses Gemini 3 thinking levels', () => {
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'min', 'gemini-3.1-flash-lite')).toBe('minimal');
|
||||
expect(mod.calculateGoogleBudgetTokens(8192, 'medium', 'gemini-3.1-flash-lite')).toBe('medium');
|
||||
@@ -1041,6 +1062,29 @@ describe('convertGooglePrompt', () => {
|
||||
expect(result.contents.filter(c => c.role === 'user')).toHaveLength(1);
|
||||
});
|
||||
|
||||
for (const model of ['gemini-3.7-flash', 'gemini-3.6-flash', 'gemini-3.5-flash-lite']) {
|
||||
test(`merges a trailing prefill into the user turn on ${model}`, () => {
|
||||
const messages = [
|
||||
{ role: 'user', content: 'Hi' },
|
||||
{ role: 'assistant', content: 'Prefill' },
|
||||
];
|
||||
const result = mod.convertGooglePrompt(messages, model, false, names);
|
||||
expect(result.contents).toHaveLength(1);
|
||||
expect(result.contents[0].role).toBe('user');
|
||||
expect(result.contents[0].parts[0].text).toBe('Hi\n\nPrefill');
|
||||
});
|
||||
}
|
||||
|
||||
test('keeps non-trailing model turns on models without prefill support', () => {
|
||||
const messages = [
|
||||
{ role: 'user', content: 'Hi' },
|
||||
{ role: 'assistant', content: 'Hello' },
|
||||
{ role: 'user', content: 'How are you?' },
|
||||
];
|
||||
const result = mod.convertGooglePrompt(messages, 'gemini-3.6-flash', false, names);
|
||||
expect(result.contents.map(c => c.role)).toEqual(['user', 'model', 'user']);
|
||||
});
|
||||
|
||||
test('converts image_url to inlineData', () => {
|
||||
const messages = [
|
||||
{ role: 'user', content: [
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, test, expect } from '@jest/globals';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const indexHtml = fs.readFileSync(new URL('../public/index.html', import.meta.url), 'utf8');
|
||||
const openaiJs = fs.readFileSync(new URL('../public/scripts/openai.js', import.meta.url), 'utf8');
|
||||
const styleCss = fs.readFileSync(new URL('../public/style.css', import.meta.url), 'utf8');
|
||||
const inputTags = indexHtml.match(/<input\b[^>]*>/gi) ?? [];
|
||||
|
||||
function getInputById(id) {
|
||||
return inputTags.find(tag => tag.includes(`id="${id}"`));
|
||||
}
|
||||
|
||||
describe('secret inputs', () => {
|
||||
test('keeps the proxy access key out of password manager form detection', () => {
|
||||
const input = getInputById('openai_proxy_access_key');
|
||||
|
||||
expect(input).toBeDefined();
|
||||
expect(input).toContain('type="text"');
|
||||
expect(input).toContain('masked-secret');
|
||||
expect(input).not.toMatch(/\sform=/i);
|
||||
expect(indexHtml).not.toContain('id="openai_proxy_password"');
|
||||
expect(openaiJs).not.toContain('#openai_proxy_password');
|
||||
expect(openaiJs).toMatch(/proxy_password:\s*\['#openai_proxy_access_key', 'proxy_password'/);
|
||||
expect(openaiJs).toMatch(/\$\('#openai_proxy_access_key'\)\.toggleClass\('masked-secret'\)/);
|
||||
expect(openaiJs).toMatch(/\$\('#openai_proxy_access_key'\)\.on\('copy cut', function \(event\) \{\s*if \(\$\(this\)\.hasClass\('masked-secret'\)\) \{\s*event\.preventDefault\(\);/s);
|
||||
expect(styleCss).toMatch(/\.masked-secret\s*{[^}]*-webkit-text-security:\s*disc;/s);
|
||||
});
|
||||
|
||||
test('uses a regular text input for the Azure API key', () => {
|
||||
const input = getInputById('api_key_azure_openai');
|
||||
|
||||
expect(input).toBeDefined();
|
||||
expect(input).toContain('type="text"');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, jest, test } from '@jest/globals';
|
||||
|
||||
const fetchMock = jest.fn();
|
||||
jest.unstable_mockModule('node-fetch', () => ({ default: fetchMock }));
|
||||
jest.unstable_mockModule('../src/endpoints/secrets.js', () => ({
|
||||
readSecret: jest.fn(),
|
||||
SECRET_KEYS: {},
|
||||
}));
|
||||
|
||||
describe('ComfyUI generation', () => {
|
||||
/** @type {import('node:http').Server} */
|
||||
let server;
|
||||
let baseUrl;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { default: express } = await import('express');
|
||||
const { router } = await import('../src/endpoints/stable-diffusion.js');
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use(router);
|
||||
server = app.listen(0, '127.0.0.1');
|
||||
await new Promise(resolve => server.once('listening', resolve));
|
||||
const address = server.address();
|
||||
baseUrl = `http://127.0.0.1:${address.port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.mockReset();
|
||||
});
|
||||
|
||||
test('skips output nodes without images', async () => {
|
||||
fetchMock
|
||||
.mockResolvedValueOnce({ ok: true, json: async () => ({ prompt_id: 'prompt-1' }) })
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
'prompt-1': {
|
||||
status: { status_str: 'success' },
|
||||
outputs: {
|
||||
117: { a_images: [{ filename: 'comparison.png' }] },
|
||||
197: { images: [{ filename: 'result.png', subfolder: '', type: 'temp' }] },
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
.mockResolvedValueOnce({ ok: true, arrayBuffer: async () => Uint8Array.from([1, 2, 3]).buffer });
|
||||
|
||||
const response = await fetch(`${baseUrl}/comfy/generate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: 'http://127.0.0.1:8188', prompt: '{}' }),
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toEqual({ format: 'png', data: 'AQID' });
|
||||
});
|
||||
|
||||
test('falls back to gifs when no output node has images', async () => {
|
||||
fetchMock
|
||||
.mockResolvedValueOnce({ ok: true, json: async () => ({ prompt_id: 'prompt-2' }) })
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
'prompt-2': {
|
||||
status: { status_str: 'success' },
|
||||
outputs: {
|
||||
10: { text: ['some non-media output'] },
|
||||
42: { gifs: [{ filename: 'animation.webp', subfolder: '', type: 'output' }] },
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
.mockResolvedValueOnce({ ok: true, arrayBuffer: async () => Uint8Array.from([4, 5, 6]).buffer });
|
||||
|
||||
const response = await fetch(`${baseUrl}/comfy/generate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: 'http://127.0.0.1:8188', prompt: '{}' }),
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.json()).toEqual({ format: 'webp', data: 'BAUG' });
|
||||
});
|
||||
|
||||
test('reports an error when no output has images or gifs', async () => {
|
||||
fetchMock
|
||||
.mockResolvedValueOnce({ ok: true, json: async () => ({ prompt_id: 'prompt-3' }) })
|
||||
.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
'prompt-3': {
|
||||
status: { status_str: 'success' },
|
||||
outputs: {
|
||||
10: { text: ['no media at all'] },
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const response = await fetch(`${baseUrl}/comfy/generate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: 'http://127.0.0.1:8188', prompt: '{}' }),
|
||||
});
|
||||
|
||||
expect(response.status).toBe(500);
|
||||
expect(await response.text()).toContain('did not return any recognizable outputs');
|
||||
});
|
||||
});
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
generateTimestamp,
|
||||
mergeObjectWithYaml,
|
||||
excludeKeysByYaml,
|
||||
getArrayBufferSlice,
|
||||
Cache,
|
||||
MemoryLimitedMap,
|
||||
} from '../src/util';
|
||||
@@ -519,6 +520,25 @@ describe('mergeObjectWithYaml', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getArrayBufferSlice', () => {
|
||||
test('returns an exact ArrayBuffer for Buffer views', () => {
|
||||
const source = Buffer.alloc(16, 0);
|
||||
source.write('abc', 4, 'utf8');
|
||||
const view = source.subarray(4, 7);
|
||||
|
||||
expect(view.byteLength).toBe(3);
|
||||
expect(view.buffer.byteLength).toBe(16);
|
||||
|
||||
const exact = getArrayBufferSlice(view);
|
||||
expect(exact.byteLength).toBe(3);
|
||||
expect(Buffer.from(exact).toString('utf8')).toBe('abc');
|
||||
});
|
||||
|
||||
test('throws for non-Uint8Array input', () => {
|
||||
expect(() => getArrayBufferSlice('abc')).toThrow(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('excludeKeysByYaml', () => {
|
||||
test('should delete keys listed in a YAML array', () => {
|
||||
const obj = { a: 1, b: 2, c: 3 };
|
||||
|
||||
Reference in New Issue
Block a user