Compare commits
47
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5da9808a4d | ||
|
|
c345b65853 | ||
|
|
ebbb8057c2 | ||
|
|
4d67a6986b | ||
|
|
d72f4b6fcb | ||
|
|
737cb95adb | ||
|
|
1a561f3bb0 | ||
|
|
f4f390f325 | ||
|
|
6a325d2b22 | ||
|
|
a7f144f28b | ||
|
|
7d3d1231a9 | ||
|
|
24379db88d | ||
|
|
ff10249ab5 | ||
|
|
64e8c8d964 | ||
|
|
f3521e7007 | ||
|
|
fb915b4321 | ||
|
|
fa9a28c6f3 | ||
|
|
ff4c6fa1bb | ||
|
|
81c85f8049 | ||
|
|
67eba1b472 | ||
|
|
df27574247 | ||
|
|
a9c377c3c8 | ||
|
|
94a5773412 | ||
|
|
5e68410d4e | ||
|
|
5ec635aa40 | ||
|
|
700fc05411 | ||
|
|
c9c652eece | ||
|
|
d96d1451ab | ||
|
|
a45ec30cf0 | ||
|
|
8d8e3833f6 | ||
|
|
760263b78a | ||
|
|
128888f605 | ||
|
|
8e8f501279 | ||
|
|
9e0ecefd64 | ||
|
|
0f4a0147fd | ||
|
|
21e8cf9060 | ||
|
|
e2d8c0200f | ||
|
|
04ef0632ee | ||
|
|
d2b2b1b4a6 | ||
|
|
a8021ee6e1 | ||
|
|
63feac9423 | ||
|
|
c918f4f36d | ||
|
|
b89293418d | ||
|
|
ff1ca1412a | ||
|
|
6bd766f857 | ||
|
|
004f1336e6 | ||
|
|
b4c721d7bc |
@@ -19,7 +19,7 @@ jobs:
|
||||
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3
|
||||
with:
|
||||
node-version: 24
|
||||
- run: npm ci
|
||||
- run: npm ci --omit=dev --ignore-scripts
|
||||
|
||||
publish-npm:
|
||||
needs: build
|
||||
@@ -30,5 +30,5 @@ jobs:
|
||||
with:
|
||||
node-version: 24
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- run: npm ci
|
||||
- run: npm ci --omit=dev --ignore-scripts
|
||||
- run: npm publish
|
||||
|
||||
@@ -34,10 +34,10 @@ jobs:
|
||||
# https://github.com/marketplace/actions/setup-node-js-environment
|
||||
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
|
||||
with:
|
||||
node-version: 20
|
||||
node-version: 24
|
||||
|
||||
- name: Run npm install
|
||||
run: npm ci
|
||||
run: npm ci --ignore-scripts
|
||||
|
||||
- name: Run ESLint
|
||||
# Action ESLint
|
||||
@@ -72,13 +72,13 @@ jobs:
|
||||
# https://github.com/marketplace/actions/setup-node-js-environment
|
||||
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
|
||||
with:
|
||||
node-version: 20
|
||||
node-version: 24
|
||||
|
||||
- name: Install root dependencies
|
||||
run: npm ci
|
||||
run: npm ci --ignore-scripts
|
||||
|
||||
- name: Install test dependencies
|
||||
run: npm ci --prefix tests
|
||||
run: npm ci --ignore-scripts --prefix tests
|
||||
|
||||
- name: Run unit tests
|
||||
run: npm run test:unit --prefix tests
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"js/ts.tsdk.promptToUseWorkspaceVersion": true,
|
||||
"js/ts.tsdk.path": "./node_modules/typescript/lib"
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ COPY --chown=node:node . ./
|
||||
|
||||
RUN \
|
||||
echo "*** Install npm packages ***" && \
|
||||
npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev && npm cache clean --force
|
||||
npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts && npm cache clean --force
|
||||
|
||||
# Create config directory and link config.yaml. Added hardcoded dirs(constants.js?)
|
||||
# that must be present for Non-Root Mode and volumeless docker runs.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@echo off
|
||||
pushd %~dp0
|
||||
set NODE_ENV=production
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
|
||||
node server.js %*
|
||||
pause
|
||||
popd
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ if %errorlevel% neq 0 (
|
||||
)
|
||||
)
|
||||
set NODE_ENV=production
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
|
||||
node server.js %*
|
||||
:end
|
||||
pause
|
||||
|
||||
@@ -102,7 +102,7 @@ if %errorlevel% neq 0 (
|
||||
|
||||
echo Installing npm packages and starting server
|
||||
set NODE_ENV=production
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
|
||||
node server.js %*
|
||||
|
||||
:end
|
||||
|
||||
@@ -127,6 +127,13 @@ sso:
|
||||
# as that used for authentik. (Ensure the username in authentik
|
||||
# is an exact match in lowercase with that in sillytavern).
|
||||
authentikAuth: false
|
||||
# List of trusted proxy IPs for SSO authentication.
|
||||
# Supports wildcards or CIDR notation for subnets.
|
||||
# Example: ['127.0.0.1', '192.168.1.1']
|
||||
# Set to ['*'] to trust all proxies (NOT RECOMMENDED unless you have other security measures in place)
|
||||
trustedProxies:
|
||||
- ::1
|
||||
- 127.0.0.1
|
||||
|
||||
# Host whitelist configuration. Recommended if you're using a listen mode
|
||||
hostWhitelist:
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Not found</title>
|
||||
<title>Not Found</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Not found</h1>
|
||||
<h1>Not Found</h1>
|
||||
<p>
|
||||
The requested URL was not found on this server.
|
||||
</p>
|
||||
@@ -642,5 +642,37 @@
|
||||
{
|
||||
"filename": "presets/reasoning/Think XML.json",
|
||||
"type": "reasoning"
|
||||
},
|
||||
{
|
||||
"filename": "presets/reasoning/Gemma 4.json",
|
||||
"type": "reasoning"
|
||||
},
|
||||
{
|
||||
"filename": "presets/instruct/Gemma 4.json",
|
||||
"type": "instruct"
|
||||
},
|
||||
{
|
||||
"filename": "presets/context/Gemma 4.json",
|
||||
"type": "context"
|
||||
},
|
||||
{
|
||||
"filename": "user.css",
|
||||
"type": "stylesheet"
|
||||
},
|
||||
{
|
||||
"filename": "errors/forbidden-by-whitelist.html",
|
||||
"type": "error_page"
|
||||
},
|
||||
{
|
||||
"filename": "errors/host-not-allowed.html",
|
||||
"type": "error_page"
|
||||
},
|
||||
{
|
||||
"filename": "errors/unauthorized.html",
|
||||
"type": "error_page"
|
||||
},
|
||||
{
|
||||
"filename": "errors/url-not-found.html",
|
||||
"type": "error_page"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"story_string": "{{#if anchorBefore}}{{anchorBefore}}\n{{/if}}{{#if system}}{{system}}\n{{/if}}{{#if wiBefore}}{{wiBefore}}\n{{/if}}{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{personality}}\n{{/if}}{{#if scenario}}{{scenario}}\n{{/if}}{{#if wiAfter}}{{wiAfter}}\n{{/if}}{{#if persona}}{{persona}}\n{{/if}}{{#if anchorAfter}}{{anchorAfter}}\n{{/if}}{{trim}}",
|
||||
"example_separator": "",
|
||||
"chat_start": "",
|
||||
"use_stop_strings": false,
|
||||
"names_as_stop_strings": true,
|
||||
"story_string_position": 0,
|
||||
"story_string_depth": 1,
|
||||
"story_string_role": 0,
|
||||
"always_force_name2": true,
|
||||
"trim_sentences": false,
|
||||
"single_line": false,
|
||||
"name": "Gemma 4"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"input_sequence": "<|turn>user\n",
|
||||
"output_sequence": "<|turn>model\n",
|
||||
"last_output_sequence": "",
|
||||
"system_sequence": "<|turn>system\n",
|
||||
"stop_sequence": "<turn|>",
|
||||
"wrap": false,
|
||||
"macro": true,
|
||||
"names_behavior": "force",
|
||||
"activation_regex": "",
|
||||
"first_output_sequence": "",
|
||||
"skip_examples": false,
|
||||
"output_suffix": "<turn|>\n",
|
||||
"input_suffix": "<turn|>\n",
|
||||
"system_suffix": "<turn|>\n",
|
||||
"user_alignment_message": "",
|
||||
"system_same_as_user": false,
|
||||
"last_system_sequence": "",
|
||||
"first_input_sequence": "",
|
||||
"last_input_sequence": "",
|
||||
"sequences_as_stop_strings": true,
|
||||
"story_string_prefix": "<|turn>system\n",
|
||||
"story_string_suffix": "<turn|>\n",
|
||||
"name": "Gemma 4"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "Gemma 4",
|
||||
"prefix": "<|channel>thought\n",
|
||||
"suffix": "<channel|>",
|
||||
"separator": "\n\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Function to handle startup logic (Config check + Postinstall + Start)
|
||||
# Function to handle startup logic (Config check + init + Start)
|
||||
start_sillytavern() {
|
||||
local PREFIX="$1"
|
||||
shift # Remove the first argument (PREFIX) so $@ contains the rest
|
||||
@@ -11,8 +11,8 @@ start_sillytavern() {
|
||||
$PREFIX cp "default/config.yaml" "config/config.yaml"
|
||||
fi
|
||||
|
||||
# Execute postinstall to auto-populate config.yaml with missing values
|
||||
$PREFIX npm run postinstall
|
||||
# Execute init script to auto-populate config.yaml with missing values
|
||||
$PREFIX npm run init
|
||||
|
||||
# Start the server
|
||||
exec $PREFIX node server.js --listen "$@"
|
||||
|
||||
Generated
+2
-2
@@ -7,7 +7,6 @@
|
||||
"": {
|
||||
"name": "sillytavern",
|
||||
"version": "1.17.0",
|
||||
"hasInstallScript": true,
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"@adobe/css-tools": "^4.4.4",
|
||||
@@ -139,7 +138,8 @@
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-jsdoc": "^48.10.0",
|
||||
"eslint-plugin-playwright": "^2.3.0"
|
||||
"eslint-plugin-playwright": "^2.3.0",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20"
|
||||
|
||||
+3
-2
@@ -115,6 +115,7 @@
|
||||
},
|
||||
"version": "1.17.0",
|
||||
"scripts": {
|
||||
"init": "node src/server-init.js",
|
||||
"start": "node server.js",
|
||||
"debug": "node --inspect server.js",
|
||||
"start:global": "node server.js --global",
|
||||
@@ -122,7 +123,6 @@
|
||||
"start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js",
|
||||
"start:bun": "bun server.js",
|
||||
"start:no-csrf": "node server.js --disableCsrf",
|
||||
"postinstall": "node post-install.js",
|
||||
"lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js",
|
||||
"lint:fix": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js --fix",
|
||||
"plugins:update": "node plugins update",
|
||||
@@ -167,6 +167,7 @@
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-jsdoc": "^48.10.0",
|
||||
"eslint-plugin-playwright": "^2.3.0"
|
||||
"eslint-plugin-playwright": "^2.3.0",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
/**
|
||||
* Scripts to be done before starting the server for the first time.
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import yaml from 'yaml';
|
||||
import chalk from 'chalk';
|
||||
import { createRequire } from 'node:module';
|
||||
import { addMissingConfigValues } from './src/config-init.js';
|
||||
|
||||
/**
|
||||
* Colorizes console output.
|
||||
*/
|
||||
const color = chalk;
|
||||
|
||||
/**
|
||||
* Converts the old config.conf file to the new config.yaml format.
|
||||
*/
|
||||
function convertConfig() {
|
||||
if (fs.existsSync('./config.conf')) {
|
||||
if (fs.existsSync('./config.yaml')) {
|
||||
console.log(color.yellow('Both config.conf and config.yaml exist. Please delete config.conf manually.'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(color.blue('Converting config.conf to config.yaml. Your old config.conf will be renamed to config.conf.bak'));
|
||||
fs.renameSync('./config.conf', './config.conf.cjs'); // Force loading as CommonJS
|
||||
const require = createRequire(import.meta.url);
|
||||
const config = require(path.join(process.cwd(), './config.conf.cjs'));
|
||||
fs.copyFileSync('./config.conf.cjs', './config.conf.bak');
|
||||
fs.rmSync('./config.conf.cjs');
|
||||
fs.writeFileSync('./config.yaml', yaml.stringify(config));
|
||||
console.log(color.green('Conversion successful. Please check your config.yaml and fix it if necessary.'));
|
||||
} catch (error) {
|
||||
console.error(color.red('FATAL: Config conversion failed. Please check your config.conf file and try again.'), error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the default config files if they don't exist yet.
|
||||
*/
|
||||
function createDefaultFiles() {
|
||||
/**
|
||||
* @typedef DefaultItem
|
||||
* @type {object}
|
||||
* @property {'file' | 'directory'} type - Whether the item should be copied as a single file or merged into a directory structure.
|
||||
* @property {string} defaultPath - The path to the default item (typically in `default/`).
|
||||
* @property {string} productionPath - The path to the copied item for production use.
|
||||
*/
|
||||
|
||||
/** @type {DefaultItem[]} */
|
||||
const defaultItems = [
|
||||
{
|
||||
type: 'file',
|
||||
defaultPath: './default/config.yaml',
|
||||
productionPath: './config.yaml',
|
||||
},
|
||||
{
|
||||
type: 'directory',
|
||||
defaultPath: './default/public/',
|
||||
productionPath: './public/',
|
||||
},
|
||||
];
|
||||
|
||||
for (const defaultItem of defaultItems) {
|
||||
try {
|
||||
if (defaultItem.type === 'file') {
|
||||
if (!fs.existsSync(defaultItem.productionPath)) {
|
||||
fs.copyFileSync(
|
||||
defaultItem.defaultPath,
|
||||
defaultItem.productionPath,
|
||||
);
|
||||
console.log(
|
||||
color.green(`Created default file: ${defaultItem.productionPath}`),
|
||||
);
|
||||
}
|
||||
} else if (defaultItem.type === 'directory') {
|
||||
fs.cpSync(defaultItem.defaultPath, defaultItem.productionPath, {
|
||||
force: false, // Don't overwrite existing files!
|
||||
recursive: true,
|
||||
});
|
||||
console.log(
|
||||
color.green(`Synchronized missing files: ${defaultItem.productionPath}`),
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
'FATAL: Unexpected default file format in `post-install.js#createDefaultFiles()`.',
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
color.red(
|
||||
`FATAL: Could not write default ${defaultItem.type}: ${defaultItem.productionPath}`,
|
||||
),
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 0. Convert config.conf to config.yaml
|
||||
convertConfig();
|
||||
// 1. Create default config files
|
||||
createDefaultFiles();
|
||||
// 2. Add missing config values
|
||||
addMissingConfigValues(path.join(process.cwd(), './config.yaml'));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Looking for user.css?
|
||||
|
||||
user.css is now located under your data root directory in the "_css" folder.
|
||||
|
||||
Example for the default data root:
|
||||
|
||||
/data/_css/user.css
|
||||
@@ -17,6 +17,7 @@
|
||||
.welcomePanel.recentHidden .welcomeRecent,
|
||||
.welcomePanel.recentHidden .recentChatsTitle,
|
||||
.welcomePanel.recentHidden .hideRecentChats,
|
||||
.welcomePanel.recentHidden .recentChatsSettings,
|
||||
.welcomePanel:not(.recentHidden) .showRecentChats {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="64" height="64">
|
||||
<path d="M8.16 23h21.177v-5.86l-4.023-2.307-.694-.3-16.46.113z" fill="none" />
|
||||
<path
|
||||
d="M22.012 22.222c.197-.675.122-1.294-.206-1.754-.3-.422-.807-.666-1.416-.694l-11.545-.15c-.075 0-.14-.038-.178-.094s-.047-.13-.028-.206c.038-.113.15-.197.272-.206l11.648-.15c1.38-.066 2.88-1.182 3.404-2.55l.666-1.735a.38.38 0 0 0 .02-.225c-.75-3.395-3.78-5.927-7.4-5.927-3.34 0-6.17 2.157-7.184 5.15-.657-.488-1.5-.75-2.392-.666-1.604.16-2.9 1.444-3.048 3.048a3.58 3.58 0 0 0 .084 1.191A4.84 4.84 0 0 0 0 22.1c0 .234.02.47.047.703.02.113.113.197.225.197H21.58a.29.29 0 0 0 .272-.206l.16-.572z"
|
||||
/>
|
||||
<path
|
||||
d="M25.688 14.803l-.32.01c-.075 0-.14.056-.17.13l-.45 1.566c-.197.675-.122 1.294.206 1.754.3.422.807.666 1.416.694l2.457.15c.075 0 .14.038.178.094s.047.14.028.206c-.038.113-.15.197-.272.206l-2.56.15c-1.388.066-2.88 1.182-3.404 2.55l-.188.478c-.038.094.028.188.13.188h8.797a.23.23 0 0 0 .225-.169A6.41 6.41 0 0 0 32 21.106a6.32 6.32 0 0 0-6.312-6.302"
|
||||
/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
+34
-12
@@ -697,7 +697,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,claude,aimlapi,openrouter,ai21,makersuite,vertexai,mistralai,custom,cohere,perplexity,groq,siliconflow,electronhub,chutes,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,zai">
|
||||
<div class="range-block" data-source="openai,claude,aimlapi,openrouter,ai21,makersuite,vertexai,mistralai,custom,cohere,perplexity,groq,siliconflow,electronhub,chutes,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,zai,workers_ai">
|
||||
<div class="range-block-title" data-i18n="Temperature">
|
||||
Temperature
|
||||
</div>
|
||||
@@ -710,7 +710,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,aimlapi,openrouter,custom,cohere,perplexity,groq,siliconflow,mistralai,electronhub,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,chutes">
|
||||
<div class="range-block" data-source="openai,aimlapi,openrouter,custom,cohere,perplexity,groq,siliconflow,mistralai,electronhub,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,chutes,workers_ai">
|
||||
<div class="range-block-title" data-i18n="Frequency Penalty">
|
||||
Frequency Penalty
|
||||
</div>
|
||||
@@ -723,7 +723,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,aimlapi,openrouter,custom,cohere,perplexity,groq,siliconflow,mistralai,electronhub,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,chutes">
|
||||
<div class="range-block" data-source="openai,aimlapi,openrouter,custom,cohere,perplexity,groq,siliconflow,mistralai,electronhub,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,chutes,workers_ai">
|
||||
<div class="range-block-title" data-i18n="Presence Penalty">
|
||||
Presence Penalty
|
||||
</div>
|
||||
@@ -736,7 +736,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="claude,aimlapi,openrouter,makersuite,vertexai,cohere,perplexity,electronhub,chutes,nanogpt">
|
||||
<div class="range-block" data-source="claude,aimlapi,openrouter,makersuite,vertexai,cohere,perplexity,electronhub,chutes,nanogpt,workers_ai">
|
||||
<div class="range-block-title" data-i18n="Top K">
|
||||
Top K
|
||||
</div>
|
||||
@@ -749,7 +749,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,claude,aimlapi,openrouter,ai21,makersuite,vertexai,mistralai,custom,cohere,perplexity,groq,siliconflow,electronhub,chutes,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,zai">
|
||||
<div class="range-block" data-source="openai,claude,aimlapi,openrouter,ai21,makersuite,vertexai,mistralai,custom,cohere,perplexity,groq,siliconflow,electronhub,chutes,nanogpt,deepseek,xai,pollinations,moonshot,fireworks,cometapi,azure_openai,zai,workers_ai">
|
||||
<div class="range-block-title" data-i18n="Top P">
|
||||
Top P
|
||||
</div>
|
||||
@@ -762,7 +762,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openrouter,nanogpt,chutes">
|
||||
<div class="range-block" data-source="openrouter,nanogpt,chutes,workers_ai">
|
||||
<div class="range-block-title" data-i18n="Repetition Penalty">
|
||||
Repetition Penalty
|
||||
</div>
|
||||
@@ -986,7 +986,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,openrouter,mistralai,custom,cohere,groq,electronhub,chutes,nanogpt,xai,pollinations,aimlapi,makersuite,vertexai,azure_openai">
|
||||
<div class="range-block" data-source="openai,openrouter,mistralai,custom,cohere,groq,electronhub,chutes,nanogpt,xai,pollinations,aimlapi,makersuite,vertexai,azure_openai,workers_ai">
|
||||
<div class="range-block-title justifyLeft" data-i18n="Seed">
|
||||
Seed
|
||||
</div>
|
||||
@@ -1996,7 +1996,7 @@
|
||||
</b>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,cohere,mistralai,custom,claude,aimlapi,openrouter,groq,siliconflow,deepseek,makersuite,vertexai,ai21,xai,pollinations,moonshot,fireworks,cometapi,electronhub,chutes,azure_openai,zai,nanogpt">
|
||||
<div class="range-block" data-source="openai,cohere,mistralai,custom,claude,aimlapi,openrouter,groq,siliconflow,deepseek,makersuite,vertexai,ai21,xai,pollinations,moonshot,fireworks,cometapi,electronhub,chutes,azure_openai,zai,nanogpt,workers_ai">
|
||||
<label for="openai_function_calling" class="checkbox_label flexWrap widthFreeExpand">
|
||||
<input id="openai_function_calling" type="checkbox" />
|
||||
<span data-i18n="Enable function calling">Enable function calling</span>
|
||||
@@ -2035,7 +2035,7 @@
|
||||
</em>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="openai,aimlapi,openrouter,mistralai,makersuite,vertexai,claude,custom,xai,pollinations,moonshot,cohere,cometapi,nanogpt,electronhub,azure_openai,zai,siliconflow,chutes">
|
||||
<div class="range-block" data-source="openai,aimlapi,openrouter,mistralai,makersuite,vertexai,claude,custom,xai,pollinations,moonshot,cohere,cometapi,nanogpt,electronhub,azure_openai,zai,siliconflow,chutes,workers_ai">
|
||||
<label for="openai_media_inlining" class="checkbox_label flexWrap widthFreeExpand">
|
||||
<input id="openai_media_inlining" type="checkbox" />
|
||||
<span data-i18n="Send inline media">Send inline media</span>
|
||||
@@ -2059,7 +2059,7 @@
|
||||
<strong data-source="makersuite,vertexai" data-i18n="video_inlining_hint_4">Videos must be less than 20 MB and under 1 minute long.</strong>
|
||||
<strong data-source="makersuite,vertexai" data-i18n="audio_inlining_hint_2">Audio must be less than 20 MB.</strong>
|
||||
</div>
|
||||
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,xai,pollinations,cohere,cometapi,nanogpt,moonshot,aimlapi,openrouter,mistralai,electronhub,azure_openai,zai,siliconflow,chutes,makersuite,vertexai">
|
||||
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,xai,pollinations,cohere,cometapi,nanogpt,moonshot,aimlapi,openrouter,mistralai,electronhub,azure_openai,zai,siliconflow,chutes,makersuite,vertexai,workers_ai">
|
||||
<div class="flex-container oneline-dropdown">
|
||||
<label for="openai_inline_image_quality" data-i18n="Inline Image Quality">
|
||||
Inline Image Quality
|
||||
@@ -2120,7 +2120,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block" data-source="deepseek,aimlapi,openrouter,custom,claude,xai,makersuite,vertexai,pollinations,moonshot,mistralai,fireworks,cometapi,electronhub,chutes,azure_openai,nanogpt,zai">
|
||||
<div class="range-block" data-source="deepseek,aimlapi,openrouter,custom,claude,xai,makersuite,vertexai,pollinations,moonshot,mistralai,fireworks,cometapi,electronhub,chutes,azure_openai,nanogpt,zai,workers_ai">
|
||||
<label for="openai_show_thoughts" class="checkbox_label widthFreeExpand">
|
||||
<input id="openai_show_thoughts" type="checkbox" />
|
||||
<span data-i18n="Request model reasoning">Request model reasoning</span>
|
||||
@@ -2894,6 +2894,7 @@
|
||||
<option value="azure_openai">Azure OpenAI</option>
|
||||
<option value="chutes">Chutes</option>
|
||||
<option value="claude">Claude</option>
|
||||
<option value="workers_ai">Cloudflare Workers AI</option>
|
||||
<option value="cohere">Cohere</option>
|
||||
<!-- Temporarily disabled. -->
|
||||
<!-- <option value="cometapi">CometAPI</option> -->
|
||||
@@ -3671,6 +3672,26 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div id="workers_ai_form" data-source="workers_ai">
|
||||
<h4><a href="https://dash.cloudflare.com/?to=/:account/ai/workers-ai/api-quick-start" target="_blank" rel="noopener noreferrer" data-i18n="Cloudflare Workers AI API Key">Cloudflare Workers AI API Key</a></h4>
|
||||
<div class="flex-container">
|
||||
<input id="api_key_workers_ai" name="api_key_workers_ai" class="text_pole flex1" value="" 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_workers_ai"></div>
|
||||
</div>
|
||||
<div data-for="api_key_workers_ai" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you click 'Connect'.">
|
||||
For privacy reasons, your API key will be hidden after you click 'Connect'.
|
||||
</div>
|
||||
<h4><a href="https://dash.cloudflare.com/?to=/:account/workers-and-pages" target="_blank" rel="noopener noreferrer" data-i18n="Cloudflare Account ID">Cloudflare Account ID</a></h4>
|
||||
<div class="flex-container">
|
||||
<input id="workers_ai_account_id" class="text_pole flex1" value="" type="text" autocomplete="off" placeholder="e.g. 023e105f4ecef8ad9ca31a8372d0c353" data-i18n="[placeholder]e.g. 023e105f4ecef8ad9ca31a8372d0c353">
|
||||
</div>
|
||||
<div>
|
||||
<h4 data-i18n="Workers AI Model">Workers AI Model</h4>
|
||||
<select id="model_workers_ai_select">
|
||||
<option value="" data-i18n="-- Connect to the API --">-- Connect to the API --</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div id="deepseek_form" data-source="deepseek">
|
||||
<h4 data-i18n="DeepSeek API Key">DeepSeek API Key</h4>
|
||||
<div class="flex-container">
|
||||
@@ -3924,6 +3945,7 @@
|
||||
<h4 data-i18n="Z.AI Model">Z.AI Model</h4>
|
||||
<select id="model_zai_select">
|
||||
<option value="glm-5-turbo">glm-5-turbo</option>
|
||||
<option value="glm-5v-turbo">glm-5v-turbo</option>
|
||||
<option value="glm-5.1">glm-5.1</option>
|
||||
<option value="glm-5">glm-5</option>
|
||||
<option value="glm-4.7">glm-4.7</option>
|
||||
@@ -6733,7 +6755,7 @@
|
||||
<small class="chat_file_size select_chat_block_filename_item"></small>
|
||||
<small class="chat_messages_num select_chat_block_filename_item"></small>
|
||||
</div>
|
||||
<div class="flex-container gap10px">
|
||||
<div class="select_chat_actions flex-container gap10px">
|
||||
<div title="Export JSONL chat file" data-format="jsonl" class="exportRawChatButton opacity50p hoverglow fa-solid fa-file-export" data-i18n="[title]Export JSONL chat file"></div>
|
||||
<div title="Download chat as plain text document" data-format="txt" class="exportChatButton opacity50p hoverglow fa-solid fa-file-lines" data-i18n="[title]Download chat as plain text document"></div>
|
||||
<div title="Delete chat file" file_name="" class="PastChat_cross opacity50p hoverglow fa-solid fa-skull" data-i18n="[title]Delete chat file"></div>
|
||||
|
||||
+18
-7
@@ -741,7 +741,7 @@ async function firstLoadInit() {
|
||||
initKoboldSettings();
|
||||
initNovelAISettings();
|
||||
initSystemPrompts();
|
||||
initExtensions();
|
||||
await initExtensions();
|
||||
initExtensionSlashCommands();
|
||||
ToolManager.initToolSlashCommands();
|
||||
await initPresetManager();
|
||||
@@ -2907,6 +2907,11 @@ export function substituteParamsLegacy(content, _name1, _name2, _original, _grou
|
||||
export function substituteParams(content, options = {}) {
|
||||
if (!content) return '';
|
||||
|
||||
if (typeof content !== 'string') {
|
||||
console.warn('substituteParams: content will be coerced to string', content);
|
||||
content = String(content);
|
||||
}
|
||||
|
||||
// Handle legacy signature calls to substituteParams
|
||||
// We'll simply re-route them to a temporary legacy function. In the future, we'll remove this and cleanly build the options object ourselves.
|
||||
const isOptionsObject = options && typeof options === 'object' && !Array.isArray(options);
|
||||
@@ -3847,9 +3852,7 @@ export function createRawPrompt(prompt, api, instructOverride, quietToLoud, syst
|
||||
|
||||
// If the prompt was given as a string, convert to a message-style object assuming user role
|
||||
if (typeof prompt === 'string') {
|
||||
const message = api === 'openai'
|
||||
? { role: 'user', content: prompt.trim() }
|
||||
: { role: 'system', content: prompt };
|
||||
const message = { role: 'user', content: prompt.trim() };
|
||||
prompt = [message];
|
||||
} else { // checks for message-style object
|
||||
if (prompt.length === 0 && !systemPrompt) throw Error('No messages provided');
|
||||
@@ -3876,7 +3879,12 @@ export function createRawPrompt(prompt, api, instructOverride, quietToLoud, syst
|
||||
// prepend system prompt, if provided
|
||||
if (systemPrompt) {
|
||||
systemPrompt = substituteParams(systemPrompt);
|
||||
systemPrompt = isInstruct ? (formatInstructModeStoryString(systemPrompt) + '\n') : systemPrompt.trim();
|
||||
systemPrompt = isInstruct ? formatInstructModeStoryString(systemPrompt) : systemPrompt.trim();
|
||||
if (isInstruct && systemPrompt.length > 0 && !systemPrompt.endsWith('\n')) {
|
||||
if (power_user.instruct.wrap && !power_user.instruct.story_string_suffix) {
|
||||
systemPrompt += '\n';
|
||||
}
|
||||
}
|
||||
prompt.unshift({ role: 'system', content: systemPrompt });
|
||||
}
|
||||
|
||||
@@ -5823,11 +5831,11 @@ export async function sendMessageAsUser(messageText, messageBias, insertAt = nul
|
||||
await eventSource.emit(event_types.USER_MESSAGE_RENDERED, insertAt);
|
||||
} else {
|
||||
chat.push(message);
|
||||
await saveChatConditional();
|
||||
const chat_id = (chat.length - 1);
|
||||
await eventSource.emit(event_types.MESSAGE_SENT, chat_id);
|
||||
addOneMessage(message);
|
||||
await eventSource.emit(event_types.USER_MESSAGE_RENDERED, chat_id);
|
||||
await saveChatConditional();
|
||||
}
|
||||
|
||||
return message;
|
||||
@@ -6003,7 +6011,7 @@ function setInContextMessages(msgInContextCount, type) {
|
||||
|
||||
if (lastMessageBlock.length === 0) {
|
||||
const firstMessageId = getFirstDisplayedMessageId();
|
||||
chatElement.find(`.mes[mesid="${firstMessageId}"`).addClass('lastInContext');
|
||||
chatElement.find(`.mes[mesid="${firstMessageId}"]`).addClass('lastInContext');
|
||||
}
|
||||
|
||||
// Update last id to chat. No metadata save on purpose, gets hopefully saved via another call
|
||||
@@ -10602,6 +10610,9 @@ export async function renameGroupOrCharacterChat({ characterId, groupId, oldFile
|
||||
if (currentChatId) {
|
||||
await reloadCurrentChat();
|
||||
}
|
||||
|
||||
const eventData = { avatarId: body.avatar_url, groupId, oldFileName: body.original_file, newFileName: body.renamed_file };
|
||||
await eventSource.emit(event_types.CHAT_RENAMED, eventData);
|
||||
} catch {
|
||||
await delay(500);
|
||||
await callGenericPopup('An error has occurred. Chat was not renamed.', POPUP_TYPE.TEXT);
|
||||
|
||||
@@ -407,6 +407,7 @@ function RA_autoconnect(PrevApi) {
|
||||
|| (secret_state[SECRET_KEYS.COMETAPI] && oai_settings.chat_completion_source == chat_completion_sources.COMETAPI)
|
||||
|| (secret_state[SECRET_KEYS.ZAI] && oai_settings.chat_completion_source == chat_completion_sources.ZAI)
|
||||
|| (secret_state[SECRET_KEYS.POLLINATIONS] && oai_settings.chat_completion_source === chat_completion_sources.POLLINATIONS)
|
||||
|| (secret_state[SECRET_KEYS.WORKERS_AI] && oai_settings.chat_completion_source == chat_completion_sources.WORKERS_AI)
|
||||
|| (isValidUrl(oai_settings.custom_url) && oai_settings.chat_completion_source == chat_completion_sources.CUSTOM)
|
||||
|| (secret_state[SECRET_KEYS.AZURE_OPENAI] && oai_settings.chat_completion_source == chat_completion_sources.AZURE_OPENAI)
|
||||
) {
|
||||
|
||||
@@ -505,7 +505,7 @@ export class ChatCompletionService {
|
||||
return async function* streamData() {
|
||||
let text = '';
|
||||
const swipes = [];
|
||||
const state = { reasoning: '', image: '' };
|
||||
const state = { reasoning: '', images: [], signature: '', toolSignatures: {} };
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) return;
|
||||
|
||||
@@ -126,6 +126,12 @@ function applyDynamicFocusStyles(styleSheet, { fromExtension = false } = {}) {
|
||||
// If something like :focus-within or a more specific selector like `.blah:has(:focus-visible)` for elements inside,
|
||||
// it should be manually defined in CSS.
|
||||
const focusSelector = rule.selectorText.replace(/:hover/g, ':focus-visible');
|
||||
|
||||
// Skip pseudo-elements (::before, ::after, ::-webkit-scrollbar, etc.)
|
||||
// as they cannot have :focus-visible appended (invalid CSS syntax)
|
||||
if (focusSelector.includes('::')) {
|
||||
return;
|
||||
}
|
||||
let focusRule = `${focusSelector} { ${rule.style.cssText} }`;
|
||||
|
||||
// Wrap the generated rule into the same @media/@supports/@container chain (if any)
|
||||
|
||||
@@ -50,6 +50,7 @@ export const event_types = {
|
||||
FORCE_SET_BACKGROUND: 'force_set_background',
|
||||
CHAT_DELETED: 'chat_deleted',
|
||||
CHAT_CREATED: 'chat_created',
|
||||
CHAT_RENAMED: 'chat_renamed',
|
||||
GROUP_CHAT_DELETED: 'group_chat_deleted',
|
||||
GROUP_CHAT_CREATED: 'group_chat_created',
|
||||
GENERATE_BEFORE_COMBINE_PROMPTS: 'generate_before_combine_prompts',
|
||||
@@ -97,6 +98,10 @@ export const event_types = {
|
||||
WORLDINFO_SCAN_DONE: 'worldinfo_scan_done',
|
||||
MEDIA_ATTACHMENT_DELETED: 'media_attachment_deleted',
|
||||
PERSONA_CHANGED: 'persona_changed',
|
||||
PERSONA_CREATED: 'persona_created',
|
||||
PERSONA_UPDATED: 'persona_updated',
|
||||
PERSONA_RENAMED: 'persona_renamed',
|
||||
PERSONA_DELETED: 'persona_deleted',
|
||||
TTS_JOB_STARTED: 'tts_job_started',
|
||||
TTS_AUDIO_READY: 'tts_audio_ready',
|
||||
TTS_JOB_COMPLETE: 'tts_job_complete',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DOMPurify, Popper } from '../lib.js';
|
||||
|
||||
import { eventSource, event_types, saveSettings, saveSettingsDebounced, getRequestHeaders, animation_duration, CLIENT_VERSION } from '../script.js';
|
||||
import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
|
||||
import { POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js';
|
||||
import { renderTemplate, renderTemplateAsync } from './templates.js';
|
||||
import { delay, equalsIgnoreCaseAndAccents, isSubsetOf, sanitizeSelector, setValueByPath, versionCompare } from './utils.js';
|
||||
import { getContext } from './st-context.js';
|
||||
@@ -354,12 +354,28 @@ function onToggleAllExtensions(extensionsToToggle, toggleContainer) {
|
||||
return extensionsToToggle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether an extension has a specific hook defined in its manifest.
|
||||
* @param {string} name Extension name (with or without 'third-party' prefix)
|
||||
* @param {'install' | 'update' | 'delete' | 'clean' | 'enable' | 'disable' | 'activate'} hookName The hook to check
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasExtensionHook(name, hookName) {
|
||||
const fullName = name.startsWith('third-party') ? name : `third-party${name}`;
|
||||
const manifest = manifests[fullName];
|
||||
if (!manifest || !manifest.hooks || typeof manifest.hooks !== 'object') {
|
||||
return false;
|
||||
}
|
||||
const hookFunctionName = manifest.hooks[hookName];
|
||||
return typeof hookFunctionName === 'string' && hookFunctionName.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a manifest hook for an extension.
|
||||
* Hooks are optional function names exported from the extension's JS entry point module.
|
||||
* The hook function can optionally return a Promise that will be awaited.
|
||||
* @param {string} name Extension name
|
||||
* @param {'install' | 'update' | 'delete' | 'enable' | 'disable' | 'activate'} hookName The hook to call
|
||||
* @param {'install' | 'update' | 'delete' | 'clean' | 'enable' | 'disable' | 'activate'} hookName The hook to call
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function callExtensionHook(name, hookName) {
|
||||
@@ -473,6 +489,21 @@ export function findExtension(name) {
|
||||
return { name: internalExtensionName, enabled: isEnabled };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a deep clone of the manifest for the given extension name.
|
||||
* Accepts either the short name (e.g. `SillyTavern-MyExtension`) or the full internal key
|
||||
* (e.g. `third-party/SillyTavern-MyExtension`). Returns null if the extension is not found.
|
||||
* @param {string} name - Extension name or internal key
|
||||
* @returns {object|null} Cloned manifest object, or null if not found
|
||||
*/
|
||||
export function getExtensionManifest(name) {
|
||||
const found = extensionNames.find(extName =>
|
||||
equalsIgnoreCaseAndAccents(extName, name) || equalsIgnoreCaseAndAccents(extName, `third-party/${name}`),
|
||||
);
|
||||
const manifest = found ? manifests[found] : null;
|
||||
return manifest ? structuredClone(manifest) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads manifest.json files for extensions.
|
||||
* @param {string[]} names Array of extension names
|
||||
@@ -864,6 +895,7 @@ function generateExtensionHtml(name, manifest, isActive, isDisabled, isExternal,
|
||||
let updateButton = isExternal ? `<button class="btn_update menu_button displayNone" data-name="${externalId}" title="Update available"><i class="fa-solid fa-download fa-fw"></i></button>` : '';
|
||||
let moveButton = isExternal && isUserAdmin ? `<button class="btn_move menu_button" data-name="${externalId}" data-i18n="[title]Move" title="Move"><i class="fa-solid fa-folder-tree fa-fw"></i></button>` : '';
|
||||
let branchButton = isExternal && isUserAdmin ? `<button class="btn_branch menu_button" data-name="${externalId}" data-i18n="[title]Switch branch" title="Switch branch"><i class="fa-solid fa-code-branch fa-fw"></i></button>` : '';
|
||||
let cleanButton = isExternal && hasExtensionHook(externalId, 'clean') ? `<button class="btn_clean menu_button" data-name="${externalId}" data-i18n="[title]Clean extension data" title="Clean extension data"><i class="fa-fw fa-solid fa-broom"></i></button>` : '';
|
||||
let modulesInfo = '';
|
||||
|
||||
if (isActive && Array.isArray(manifest.optional)) {
|
||||
@@ -904,6 +936,7 @@ function generateExtensionHtml(name, manifest, isActive, isDisabled, isExternal,
|
||||
|
||||
<div class="extension_actions flex-container alignItemsCenter">
|
||||
${updateButton}
|
||||
${cleanButton}
|
||||
${branchButton}
|
||||
${moveButton}
|
||||
${deleteButton}
|
||||
@@ -1234,6 +1267,7 @@ async function updateExtension(extensionName, quiet, timeout = null) {
|
||||
* This function makes a POST request to '/api/extensions/delete' with the extension's name.
|
||||
* If the extension is deleted, it displays a success message.
|
||||
* Creates a popup for the user to confirm before delete.
|
||||
* If the extension has a 'clean' hook, an optional checkbox to also run the cleanup is shown.
|
||||
*/
|
||||
async function onDeleteClick() {
|
||||
const extensionName = $(this).data('name');
|
||||
@@ -1244,13 +1278,50 @@ async function onDeleteClick() {
|
||||
return;
|
||||
}
|
||||
|
||||
// use callPopup to create a popup for the user to confirm before delete
|
||||
const confirmation = await callGenericPopup(t`Are you sure you want to delete ${extensionName}?`, POPUP_TYPE.CONFIRM, '', {});
|
||||
const hasCleanHook = hasExtensionHook(extensionName, 'clean');
|
||||
|
||||
/** @type {import('./popup.js').CustomPopupInput[]} */
|
||||
const customInputs = hasCleanHook ? [{ id: 'extension_delete_cleanup', label: t`Also clean up extension data`, defaultState: false }] : null;
|
||||
|
||||
const popup = new Popup(t`Are you sure you want to delete ${extensionName}?`, POPUP_TYPE.CONFIRM, '', { customInputs });
|
||||
const confirmation = await popup.show();
|
||||
if (confirmation === POPUP_RESULT.AFFIRMATIVE) {
|
||||
await deleteExtension(extensionName);
|
||||
const shouldClean = hasCleanHook && Boolean(popup.inputResults?.get('extension_delete_cleanup'));
|
||||
await deleteExtension(extensionName, shouldClean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the click event for the clean button of an extension.
|
||||
* Runs the extension's 'clean' hook after user confirmation, then reloads the page.
|
||||
*/
|
||||
async function onCleanClick() {
|
||||
const extensionName = $(this).data('name');
|
||||
|
||||
const confirmation = await Popup.show.confirm(t`Clean extension data`, t`Are you sure you want to clean up data for ${extensionName}? This action cannot be undone.`);
|
||||
if (!confirmation) {
|
||||
return;
|
||||
}
|
||||
|
||||
await cleanExtension(extensionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the 'clean' hook for an extension and reloads the page.
|
||||
* @param {string} extensionName Extension name (without 'third-party' prefix)
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function cleanExtension(extensionName) {
|
||||
const fullExtensionName = extensionName.startsWith('third-party') ? extensionName : `third-party${extensionName}`;
|
||||
await callExtensionHook(fullExtensionName, 'clean');
|
||||
|
||||
// Clean might have updated settings, which could race with the page reload, so we'll force save here
|
||||
await saveSettings();
|
||||
|
||||
toastr.success(t`Extension ${extensionName} data cleaned`);
|
||||
delay(1000).then(() => location.reload());
|
||||
}
|
||||
|
||||
async function onBranchClick() {
|
||||
const extensionName = $(this).data('name');
|
||||
const isCurrentUserAdmin = isAdmin();
|
||||
@@ -1353,9 +1424,16 @@ async function moveExtension(extensionName, source, destination) {
|
||||
/**
|
||||
* Deletes an extension via the API.
|
||||
* @param {string} extensionName Extension name to delete
|
||||
* @param {boolean} [shouldClean=false] Whether to also run the 'clean' hook before deleting
|
||||
*/
|
||||
export async function deleteExtension(extensionName) {
|
||||
await callExtensionHook(extensionName, 'delete');
|
||||
export async function deleteExtension(extensionName, shouldClean = false) {
|
||||
const fullExtensionName = extensionName.startsWith('third-party') ? extensionName : `third-party${extensionName}`;
|
||||
|
||||
if (shouldClean) {
|
||||
await callExtensionHook(fullExtensionName, 'clean');
|
||||
}
|
||||
|
||||
await callExtensionHook(fullExtensionName, 'delete');
|
||||
|
||||
try {
|
||||
await fetch('/api/extensions/delete', {
|
||||
@@ -1370,6 +1448,9 @@ export async function deleteExtension(extensionName) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
|
||||
// Delete or clean might have updated settings, which could race with the page reload, so we'll force save here
|
||||
await saveSettings();
|
||||
|
||||
toastr.success(t`Extension ${extensionName} deleted`);
|
||||
delay(1000).then(() => location.reload());
|
||||
}
|
||||
@@ -1865,6 +1946,7 @@ export async function initExtensions() {
|
||||
$(document).on('click', '.extensions_info .extension_block .toggle_enable', onEnableExtensionClick);
|
||||
$(document).on('click', '.extensions_info .extension_block .btn_update', onUpdateClick);
|
||||
$(document).on('click', '.extensions_info .extension_block .btn_delete', onDeleteClick);
|
||||
$(document).on('click', '.extensions_info .extension_block .btn_clean', onCleanClick);
|
||||
$(document).on('click', '.extensions_info .extension_block .btn_move', onMoveClick);
|
||||
$(document).on('click', '.extensions_info .extension_block .btn_branch', onBranchClick);
|
||||
|
||||
|
||||
@@ -435,7 +435,7 @@ async function updateCurrentAssets() {
|
||||
//#############################//
|
||||
|
||||
// This function is called when the extension is loaded
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
// This is an example of loading HTML from a file
|
||||
const windowTemplate = await renderExtensionTemplateAsync(MODULE_NAME, 'window', {});
|
||||
const windowHtml = $(windowTemplate);
|
||||
@@ -496,4 +496,4 @@ jQuery(async () => {
|
||||
eventSource.on(event_types.OPEN_CHARACTER_LIBRARY, async (forceDefault) => {
|
||||
openCharacterBrowser(forceDefault);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Keij#6799",
|
||||
"version": "0.1.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ function handleCharacterRename(oldAvatar, newAvatar) {
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
eventSource.on(event_types.APP_READY, cleanUpAttachments);
|
||||
eventSource.on(event_types.CHARACTER_DELETED, cleanUpCharacterAttachments);
|
||||
eventSource.on(event_types.CHARACTER_RENAMED, handleCharacterRename);
|
||||
@@ -407,4 +407,4 @@ jQuery(async () => {
|
||||
}),
|
||||
],
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getContext, getApiUrl, doExtrasFetch, extension_settings, modules, rend
|
||||
import { appendMediaToMessage, chat_metadata, eventSource, event_types, getRequestHeaders, saveChatConditional, saveSettingsDebounced, substituteParamsExtended } from '../../../script.js';
|
||||
import { getMessageTimeStamp } from '../../RossAscends-mods.js';
|
||||
import { SECRET_KEYS, secret_state } from '../../secrets.js';
|
||||
import { oai_settings } from '../../openai.js';
|
||||
import { getMultimodalCaption } from '../shared.js';
|
||||
import { textgen_types, textgenerationwebui_settings } from '../../textgen-settings.js';
|
||||
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
||||
@@ -454,7 +455,7 @@ function isVideoCaptioningAvailable() {
|
||||
return ['google', 'vertexai', 'zai'].includes(extension_settings.caption.multimodal_api);
|
||||
}
|
||||
|
||||
jQuery(async function () {
|
||||
export async function init() {
|
||||
function addSendPictureButton() {
|
||||
const sendButton = $(`
|
||||
<div id="send_picture" class="list-group-item flex-container flexGap5">
|
||||
@@ -504,6 +505,7 @@ jQuery(async function () {
|
||||
'chutes': SECRET_KEYS.CHUTES,
|
||||
'electronhub': SECRET_KEYS.ELECTRONHUB,
|
||||
'pollinations': SECRET_KEYS.POLLINATIONS,
|
||||
'workers_ai': SECRET_KEYS.WORKERS_AI,
|
||||
};
|
||||
|
||||
if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) {
|
||||
@@ -580,7 +582,7 @@ jQuery(async function () {
|
||||
}
|
||||
|
||||
async function addRemoteEndpointModels() {
|
||||
async function processEndpoint(api, url) {
|
||||
async function processEndpoint(api, url, additionalParams = {}) {
|
||||
const dropdown = document.getElementById('caption_multimodal_model');
|
||||
if (!(dropdown instanceof HTMLSelectElement)) {
|
||||
return;
|
||||
@@ -591,7 +593,8 @@ jQuery(async function () {
|
||||
const options = Array.from(dropdown.options);
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders({ omitContentType: true }),
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify(additionalParams),
|
||||
});
|
||||
if (!response.ok) {
|
||||
return;
|
||||
@@ -620,6 +623,7 @@ jQuery(async function () {
|
||||
await processEndpoint('mistral', '/api/backends/chat-completions/multimodal-models/mistral');
|
||||
await processEndpoint('xai', '/api/backends/chat-completions/multimodal-models/xai');
|
||||
await processEndpoint('moonshot', '/api/backends/chat-completions/multimodal-models/moonshot');
|
||||
await processEndpoint('workers_ai', '/api/backends/chat-completions/multimodal-models/workers_ai', { workers_ai_account_id: oai_settings.workers_ai_account_id });
|
||||
}
|
||||
|
||||
await addSettings();
|
||||
@@ -804,4 +808,4 @@ jQuery(async function () {
|
||||
}));
|
||||
|
||||
document.body.classList.add('caption');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<option value="aimlapi">AI/ML API</option>
|
||||
<option value="chutes">Chutes</option>
|
||||
<option value="anthropic">Claude</option>
|
||||
<option value="workers_ai">Cloudflare Workers AI</option>
|
||||
<option value="cohere">Cohere</option>
|
||||
<option value="custom" data-i18n="Custom (OpenAI-compatible)">Custom (OpenAI-compatible)</option>
|
||||
<option value="electronhub">Electron Hub</option>
|
||||
@@ -174,6 +175,7 @@
|
||||
<option data-type="ollama" value="mistral-small3.2">mistral-small3.2</option>
|
||||
<option data-type="ollama" value="llama3.2-vision">llama3.2-vision</option>
|
||||
<option data-type="ollama" value="llama4">llama4</option>
|
||||
<option data-type="zai" value="glm-5v-turbo">glm-5v-turbo</option>
|
||||
<option data-type="zai" value="glm-4.6v">glm-4.6v</option>
|
||||
<option data-type="zai" value="glm-4.6v-flashx">glm-4.6v-flashx</option>
|
||||
<option data-type="zai" value="glm-4.6v-flash">glm-4.6v-flash</option>
|
||||
|
||||
@@ -474,7 +474,7 @@ async function renderDetailsContent(detailsContent) {
|
||||
}
|
||||
}
|
||||
|
||||
(async function () {
|
||||
export async function init() {
|
||||
extension_settings.connectionManager = extension_settings.connectionManager || structuredClone(DEFAULT_SETTINGS);
|
||||
|
||||
for (const key of Object.keys(DEFAULT_SETTINGS)) {
|
||||
@@ -824,4 +824,4 @@ async function renderDetailsContent(detailsContent) {
|
||||
return JSON.stringify(profile);
|
||||
},
|
||||
}));
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2140,7 +2140,7 @@ function migrateSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
(async function () {
|
||||
export async function init() {
|
||||
function addExpressionImage() {
|
||||
const html = `
|
||||
<div id="expression-wrapper">
|
||||
@@ -2511,4 +2511,4 @@ function migrateSettings() {
|
||||
</div>
|
||||
`,
|
||||
}));
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,7 +818,7 @@ function addGalleryWandButton() {
|
||||
}
|
||||
|
||||
// On extension load, ensure the settings are initialized
|
||||
(function () {
|
||||
export async function init() {
|
||||
initSettings();
|
||||
eventSource.on(event_types.CHARACTER_RENAMED, (oldAvatar, newAvatar) => {
|
||||
const context = SillyTavern.getContext();
|
||||
@@ -850,4 +850,4 @@ function addGalleryWandButton() {
|
||||
}),
|
||||
);
|
||||
addGalleryWandButton();
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -8,5 +8,8 @@
|
||||
"css": "style.css",
|
||||
"author": "City-Unit",
|
||||
"version": "1.5.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,7 +1063,7 @@ function setupListeners() {
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(async function () {
|
||||
export async function init() {
|
||||
async function addExtensionControls() {
|
||||
const settingsHtml = await renderExtensionTemplateAsync('memory', 'settings', { defaultSettings });
|
||||
$('#summarize_container').append(settingsHtml);
|
||||
@@ -1128,4 +1128,4 @@ jQuery(async function () {
|
||||
() => summaryMacroHandler(),
|
||||
'Returns the latest memory/summary from the current chat.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ const handleCharChange = () => {
|
||||
settings.charConfig = charConfig;
|
||||
};
|
||||
|
||||
const init = async () => {
|
||||
export async function init() {
|
||||
await loadSets();
|
||||
await loadSettings();
|
||||
log('settings: ', settings);
|
||||
@@ -214,7 +214,8 @@ const init = async () => {
|
||||
eventSource.on(event_types.APP_READY, async () => await finalizeInit());
|
||||
|
||||
globalThis.quickReplyApi = quickReplyApi;
|
||||
};
|
||||
}
|
||||
|
||||
const finalizeInit = async () => {
|
||||
debug('executing startup');
|
||||
await autoExec.handleStartup();
|
||||
@@ -229,7 +230,7 @@ const finalizeInit = async () => {
|
||||
isReady = true;
|
||||
debug('READY');
|
||||
};
|
||||
await init();
|
||||
|
||||
|
||||
const purgeCharacterQuickReplySets = ({ character }) => {
|
||||
// Remove the character's Quick Reply Sets from the settings.
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "RossAscends#1779",
|
||||
"version": "2.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1709,7 +1709,7 @@ function onPresetRenamed({ apiId, oldName, newName }) {
|
||||
|
||||
// Workaround for loading in sequence with other extensions
|
||||
// NOTE: Always puts extension at the top of the list, but this is fine since it's static
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
if (!Array.isArray(extension_settings.regex)) {
|
||||
extension_settings.regex = [];
|
||||
}
|
||||
@@ -2068,6 +2068,37 @@ jQuery(async () => {
|
||||
],
|
||||
helpString: 'Runs a Regex extension script by name on the provided string. The script must be enabled.',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'regex-state',
|
||||
/** @param {object} _ @param {string} name */
|
||||
callback: (_, name) => {
|
||||
if (!name) {
|
||||
toastr.warning('No regex script name provided.');
|
||||
return '';
|
||||
}
|
||||
|
||||
const scripts = getRegexScripts();
|
||||
const script = scripts.find(s => equalsIgnoreCaseAndAccents(s.scriptName, name));
|
||||
|
||||
if (!script) {
|
||||
toastr.warning(`Regex script "${name}" not found.`);
|
||||
return '';
|
||||
}
|
||||
|
||||
return script.disabled ? 'false' : 'true';
|
||||
},
|
||||
returns: 'true (for enabled) or false (for disabled)',
|
||||
unnamedArgumentList: [
|
||||
SlashCommandArgument.fromProps({
|
||||
description: 'script name',
|
||||
typeList: [ARGUMENT_TYPE.STRING],
|
||||
isRequired: true,
|
||||
enumProvider: localEnumProviders.regexScripts,
|
||||
}),
|
||||
],
|
||||
helpString: 'Returns the current state of a regex script.',
|
||||
}));
|
||||
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'regex-toggle',
|
||||
callback: toggleRegexCallback,
|
||||
@@ -2123,4 +2154,4 @@ jQuery(async () => {
|
||||
|
||||
presetManager.setupEventListeners();
|
||||
presetManager.registerSlashCommands();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "kingbri",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,10 @@ export async function getMultimodalCaption(base64Img, prompt) {
|
||||
requestBody.zai_endpoint = oai_settings.zai_endpoint || ZAI_ENDPOINT.COMMON;
|
||||
}
|
||||
|
||||
if (extension_settings.caption.multimodal_api === 'workers_ai') {
|
||||
requestBody.workers_ai_account_id = oai_settings.workers_ai_account_id;
|
||||
}
|
||||
|
||||
function getEndpointUrl() {
|
||||
switch (extension_settings.caption.multimodal_api) {
|
||||
case 'google':
|
||||
@@ -283,6 +287,10 @@ function throwIfInvalidModel(useReverseProxy) {
|
||||
if (multimodalApi === 'pollinations' && !secret_state[SECRET_KEYS.POLLINATIONS]) {
|
||||
throw new Error('Pollinations API key is not set.');
|
||||
}
|
||||
|
||||
if (multimodalApi === 'workers_ai' && (!secret_state[SECRET_KEYS.WORKERS_AI] || !oai_settings.workers_ai_account_id)) {
|
||||
throw new Error('Workers AI API key or account ID is not set.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,6 +443,7 @@ export class ConnectionManagerRequestService {
|
||||
max_tokens: maxTokens,
|
||||
model: profile.model,
|
||||
chat_completion_source: selectedApiMap.source,
|
||||
secret_id: profile['secret-id'],
|
||||
custom_url: profile['api-url'],
|
||||
vertexai_region: profile['api-url'],
|
||||
zai_endpoint: profile['api-url'],
|
||||
@@ -459,6 +468,7 @@ export class ConnectionManagerRequestService {
|
||||
model: profile.model,
|
||||
api_type: selectedApiMap.type,
|
||||
api_server: profile['api-url'],
|
||||
secret_id: profile['secret-id'],
|
||||
...overridePayload,
|
||||
}, {
|
||||
instructName: includeInstruct ? profile.instruct : undefined,
|
||||
|
||||
@@ -1815,6 +1815,34 @@ async function loadAutoSamplers() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSdcppModels() {
|
||||
if (!extension_settings.sd.sdcpp_url) {
|
||||
return [{ value: '', text: 'N/A' }];
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await fetch('/api/sd/sdcpp/models', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({ url: extension_settings.sd.sdcpp_url }),
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
return [{ value: '', text: 'N/A' }];
|
||||
}
|
||||
|
||||
const data = await result.json();
|
||||
|
||||
if (data?.data?.length > 0) {
|
||||
return data.data.map(model => ({ value: model.id, text: model.name || model.id }));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load sd.cpp models:', error);
|
||||
}
|
||||
|
||||
return [{ value: '', text: 'N/A' }];
|
||||
}
|
||||
|
||||
async function loadSdcppSamplers() {
|
||||
// The sdcpp server does not provide an API for samplers, so we return the known list.
|
||||
return ['euler', 'euler_a', 'heun', 'dpm2', 'dpm++2s_a', 'dpm++2m', 'dpm++2mv2', 'ipndm', 'ipndm_v', 'lcm', 'ddim_trailing', 'tcd'];
|
||||
@@ -1910,7 +1938,7 @@ async function loadModels() {
|
||||
models = await loadAutoModels();
|
||||
break;
|
||||
case sources.sdcpp:
|
||||
models = [{ value: '', text: 'N/A' }];
|
||||
models = await loadSdcppModels();
|
||||
break;
|
||||
case sources.drawthings:
|
||||
models = await loadDrawthingsModels();
|
||||
@@ -3858,6 +3886,7 @@ async function generateAutoImage(prompt, negativePrompt, signal) {
|
||||
async function generateSdcppImage(prompt, negativePrompt, signal) {
|
||||
const payload = {
|
||||
url: extension_settings.sd.sdcpp_url,
|
||||
model: extension_settings.sd.model || undefined,
|
||||
prompt: prompt,
|
||||
negative_prompt: negativePrompt,
|
||||
steps: extension_settings.sd.steps,
|
||||
@@ -5441,7 +5470,7 @@ function registerFunctionTool() {
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
await addSDGenButtons();
|
||||
|
||||
const getSelectEnumProvider = (id, text) => () => Array.from(document.querySelectorAll(`#${id} > [value]`)).map(x => new SlashCommandEnumValue(x.getAttribute('value'), text ? x.textContent : null));
|
||||
@@ -5948,4 +5977,4 @@ jQuery(async () => {
|
||||
t`Character's negative Image Generation prompt prefix`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ async function doCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
jQuery(() => {
|
||||
export function init() {
|
||||
const buttonHtml = `
|
||||
<div id="token_counter" class="list-group-item flex-container flexGap5">
|
||||
<div class="fa-solid fa-1 extensionsMenuExtensionButton" /></div>` +
|
||||
@@ -115,4 +115,4 @@ jQuery(() => {
|
||||
returns: 'number of tokens',
|
||||
helpString: 'Counts the number of tokens in the current chat.',
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,7 +707,7 @@ const handleMessageReasoningDelete = createEventHandler(removeReasoningDisplayTe
|
||||
|
||||
globalThis.translate = translate;
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
const html = await renderExtensionTemplateAsync('translate', 'index');
|
||||
const buttonHtml = await renderExtensionTemplateAsync('translate', 'buttons');
|
||||
|
||||
@@ -801,4 +801,4 @@ jQuery(async () => {
|
||||
},
|
||||
returns: ARGUMENT_TYPE.STRING,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { cancelTtsPlay, eventSource, event_types, getCurrentChatId, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js';
|
||||
import { ModuleWorkerWrapper, extension_settings, getContext, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||
import { delay, escapeRegex, getBase64Async, getStringHash, onlyUnique, regexFromString } from '../../utils.js';
|
||||
import { accountStorage } from '../../util/AccountStorage.js';
|
||||
import { EdgeTtsProvider } from './edge.js';
|
||||
import { ElevenLabsTtsProvider } from './elevenlabs.js';
|
||||
import { SileroTtsProvider } from './silerotts.js';
|
||||
@@ -165,7 +166,7 @@ async function onNarrateOneMessage() {
|
||||
}
|
||||
|
||||
resetTtsPlayback();
|
||||
processAndQueueTtsMessage(message, Number(id));
|
||||
processAndQueueTtsMessage(message, Number(id), { manual: true });
|
||||
moduleWorker();
|
||||
}
|
||||
|
||||
@@ -186,13 +187,20 @@ async function onNarrateText(args, text) {
|
||||
? voiceMap[DEFAULT_VOICE_MARKER]
|
||||
: voiceMap[name];
|
||||
|
||||
if (!voiceMapEntry || voiceMapEntry === DISABLED_VOICE_MARKER) {
|
||||
if (voiceMapEntry === DISABLED_VOICE_MARKER) {
|
||||
toastr.info(`TTS voice for ${name} is disabled.`);
|
||||
await initVoiceMap(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!voiceMapEntry) {
|
||||
toastr.info(`Specified voice for ${name} was not found. Check the TTS extension settings.`);
|
||||
await initVoiceMap(false);
|
||||
return;
|
||||
}
|
||||
|
||||
resetTtsPlayback();
|
||||
processAndQueueTtsMessage({ mes: text, name: name });
|
||||
processAndQueueTtsMessage({ mes: text, name: name }, null, { manual: true });
|
||||
await moduleWorker();
|
||||
|
||||
// Return back to the chat voices
|
||||
@@ -245,7 +253,7 @@ function isTtsProcessing() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {ChatMessage & { id?: number }} TtsMessage
|
||||
* @typedef {ChatMessage & { id?: number, manual?: boolean, segmentText?: string, segmentType?: string }} TtsMessage
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -253,12 +261,15 @@ function isTtsProcessing() {
|
||||
* (if enabled) and adds each part to the TTS job queue.
|
||||
* @param {ChatMessage} message - The message object to be processed.
|
||||
* @param {number|null} [messageId=null] - The chat message index to associate with TTS events.
|
||||
* @param {object} [options={}] - Additional options for processing.
|
||||
* @param {boolean} [options.manual=false] - Whether this TTS job was manually triggered (e.g., from the UI) rather than automatically from a new chat message.
|
||||
* @returns {void}
|
||||
*/
|
||||
function processAndQueueTtsMessage(message, messageId = null) {
|
||||
function processAndQueueTtsMessage(message, messageId = null, { manual = false } = {}) {
|
||||
/** @type {TtsMessage} */
|
||||
const clone = structuredClone(message);
|
||||
clone.id = messageId ?? null;
|
||||
clone.manual = manual ?? false;
|
||||
|
||||
if (!extension_settings.tts.narrate_by_paragraphs) {
|
||||
ttsJobQueue.push(clone);
|
||||
@@ -408,9 +419,10 @@ function onAudioControlClicked() {
|
||||
// Not pausing, doing a full stop to anything TTS is doing. Better UX as pause is not as useful
|
||||
if (!audioElement.paused || isTtsProcessing()) {
|
||||
resetTtsPlayback();
|
||||
} else {
|
||||
} else if (context?.chat?.length > 0) {
|
||||
// Default play behavior if not processing or playing is to play the last message.
|
||||
processAndQueueTtsMessage(context.chat[context.chat.length - 1]);
|
||||
const id = context.chat.length - 1;
|
||||
processAndQueueTtsMessage(context.chat[id], id, { manual: true });
|
||||
}
|
||||
updateUiAudioPlayState();
|
||||
}
|
||||
@@ -481,8 +493,10 @@ async function processAudioJobQueue() {
|
||||
// TTS Control //
|
||||
//################//
|
||||
|
||||
/** @type {TtsMessage[]} */
|
||||
const ttsJobQueue = [];
|
||||
let currentTtsJob; // Null if nothing is currently being processed
|
||||
/** @type {TtsMessage|null} */
|
||||
let currentTtsJob = null; // Null if nothing is currently being processed
|
||||
|
||||
function completeTtsJob() {
|
||||
console.info(`Current TTS job for ${currentTtsJob?.name} completed.`);
|
||||
@@ -621,7 +635,18 @@ async function processTtsQueue() {
|
||||
|
||||
const voiceMapEntry = voiceMap[voiceMapKey] === DEFAULT_VOICE_MARKER ? voiceMap[DEFAULT_VOICE_MARKER] : voiceMap[voiceMapKey];
|
||||
|
||||
if (!voiceMapEntry || voiceMapEntry === DISABLED_VOICE_MARKER) {
|
||||
if (voiceMapEntry === DISABLED_VOICE_MARKER) {
|
||||
const storageKey = `tts_disabled_warned_${char}`;
|
||||
if (!accountStorage.getItem(storageKey) || currentTtsJob.manual) {
|
||||
accountStorage.setItem(storageKey, 'true');
|
||||
toastr.info(`TTS voice for ${char} is disabled.`);
|
||||
}
|
||||
currentTtsJob = null;
|
||||
setTimeout(() => wrapper.update(), 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!voiceMapEntry) {
|
||||
throw `${char} not in voicemap. Configure character in extension settings voice map`;
|
||||
}
|
||||
|
||||
@@ -649,7 +674,6 @@ async function processTtsQueue() {
|
||||
text = substituteParams(text);
|
||||
|
||||
if (extension_settings.tts.skip_codeblocks) {
|
||||
text = text.replace(/^\s{4}.*$/gm, '').trim();
|
||||
text = text.replace(/```.*?```/gs, '').trim();
|
||||
text = text.replace(/~~~.*?~~~/gs, '').trim();
|
||||
}
|
||||
@@ -724,6 +748,7 @@ async function processTtsQueue() {
|
||||
mes: currentTtsJob.mes,
|
||||
extra: currentTtsJob.extra,
|
||||
id: currentTtsJob.id,
|
||||
manual: currentTtsJob.manual,
|
||||
};
|
||||
ttsJobQueue.unshift(segmentJob);
|
||||
}
|
||||
@@ -824,7 +849,7 @@ async function playFullConversation() {
|
||||
|
||||
context.chat.forEach((msg, i) => {
|
||||
if (!msg.is_system && msg.mes !== '...' && msg.mes !== '') {
|
||||
processAndQueueTtsMessage(msg, i);
|
||||
processAndQueueTtsMessage(msg, i, { manual: false });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1164,7 +1189,7 @@ async function onMessageEvent(messageId, lastCharIndex) {
|
||||
message.id = messageId;
|
||||
ttsJobQueue.push(message);
|
||||
} else {
|
||||
processAndQueueTtsMessage(message, messageId);
|
||||
processAndQueueTtsMessage(message, messageId, { manual: false });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1506,7 +1531,7 @@ async function initVoiceMapInternal(unrestricted) {
|
||||
updateVoiceMap();
|
||||
}
|
||||
|
||||
jQuery(async function () {
|
||||
export async function init() {
|
||||
async function addExtensionControls() {
|
||||
const settingsHtml = $(await renderExtensionTemplateAsync('tts', 'settings'));
|
||||
$('#tts_container').append(settingsHtml);
|
||||
@@ -1594,4 +1619,4 @@ jQuery(async function () {
|
||||
}));
|
||||
|
||||
document.body.appendChild(audioElement);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,5 +11,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Ouoertheo#7264",
|
||||
"version": "1.0.0",
|
||||
"homePage": "None"
|
||||
"homePage": "None",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ const settings = {
|
||||
|
||||
// For chats
|
||||
enabled_chats: false,
|
||||
keep_hidden: false,
|
||||
template: 'Past events:\n{{text}}',
|
||||
depth: 2,
|
||||
position: extension_prompt_types.IN_PROMPT,
|
||||
@@ -120,6 +121,59 @@ const webllmProvider = new WebLlmVectorProvider();
|
||||
const cachedSummaries = new Map();
|
||||
const vectorApiRequiresUrl = ['llamacpp', 'vllm', 'ollama', 'koboldcpp'];
|
||||
|
||||
/**
|
||||
* @typedef {object} RemoteEmbeddingEndpointConfig
|
||||
* @property {string} url - The API endpoint URL
|
||||
* @property {string} settingsKey - The key in settings for the selected model
|
||||
* @property {string} selectId - The ID of the select element (without #)
|
||||
* @property {string} [valueProperty='id'] - Property name for the option value
|
||||
* @property {string} [textProperty] - Property name for the option text. Falls back to valueProperty
|
||||
* @property {() => object} [getBody] - Function returning the request body
|
||||
* @property {(models: any[]) => any[]} [filter] - Optional post-fetch filter for models
|
||||
*/
|
||||
|
||||
/** @type {Record<string, RemoteEmbeddingEndpointConfig>} */
|
||||
const remoteEmbeddingEndpoints = {
|
||||
chutes: {
|
||||
url: '/api/openai/chutes/models/embedding',
|
||||
settingsKey: 'chutes_model',
|
||||
selectId: 'vectors_chutes_model',
|
||||
valueProperty: 'slug',
|
||||
textProperty: 'name',
|
||||
},
|
||||
nanogpt: {
|
||||
url: '/api/openai/nanogpt/models/embedding',
|
||||
settingsKey: 'nanogpt_model',
|
||||
selectId: 'vectors_nanogpt_model',
|
||||
textProperty: 'name',
|
||||
},
|
||||
electronhub: {
|
||||
url: '/api/openai/electronhub/models',
|
||||
settingsKey: 'electronhub_model',
|
||||
selectId: 'vectors_electronhub_model',
|
||||
textProperty: 'name',
|
||||
filter: models => models.filter(m => Array.isArray(m?.endpoints) && m.endpoints.includes('/v1/embeddings')),
|
||||
},
|
||||
openrouter: {
|
||||
url: '/api/openrouter/models/embedding',
|
||||
settingsKey: 'openrouter_model',
|
||||
selectId: 'vectors_openrouter_model',
|
||||
textProperty: 'name',
|
||||
},
|
||||
siliconflow: {
|
||||
url: '/api/openai/siliconflow/models/embedding',
|
||||
settingsKey: 'siliconflow_model',
|
||||
selectId: 'vectors_siliconflow_model',
|
||||
getBody: () => ({ siliconflow_endpoint: oai_settings.siliconflow_endpoint }),
|
||||
},
|
||||
workers_ai: {
|
||||
url: '/api/openai/workers-ai/models/embedding',
|
||||
settingsKey: 'workers_ai_model',
|
||||
selectId: 'vectors_workers_ai_model',
|
||||
getBody: () => ({ workers_ai_account_id: oai_settings.workers_ai_account_id }),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the Collection ID for a file embedded in the chat.
|
||||
* @param {string} fileUrl URL of the file
|
||||
@@ -347,7 +401,7 @@ async function synchronizeChat(batchSize = 5) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const hashedMessages = context.chat.filter(x => !x.is_system).map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)), index: context.chat.indexOf(x) }));
|
||||
const hashedMessages = context.chat.filter(x => settings.keep_hidden || !x.is_system).map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)), index: context.chat.indexOf(x) }));
|
||||
const hashesInCollection = await getSavedHashes(chatId);
|
||||
|
||||
let newVectorItems = hashedMessages.filter(x => !hashesInCollection.includes(x.hash));
|
||||
@@ -388,6 +442,8 @@ async function synchronizeChat(batchSize = 5) {
|
||||
return 'Extras API must provide an "embeddings" module.';
|
||||
case 'webllm_not_supported':
|
||||
return 'WebLLM extension is not installed or the model is not set.';
|
||||
case 'account_id_missing':
|
||||
return 'Workers AI account ID is required. Save it in the "API Connections" panel.';
|
||||
default:
|
||||
return 'Check server console for more details';
|
||||
}
|
||||
@@ -842,6 +898,10 @@ function getVectorsRequestBody(args = {}) {
|
||||
body.model = extension_settings.vectors.siliconflow_model;
|
||||
body.siliconflow_endpoint = oai_settings.siliconflow_endpoint;
|
||||
break;
|
||||
case 'workers_ai':
|
||||
body.model = extension_settings.vectors.workers_ai_model || '@cf/baai/bge-m3';
|
||||
body.workers_ai_account_id = oai_settings.workers_ai_account_id;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -935,6 +995,7 @@ function throwIfSourceInvalid() {
|
||||
settings.source === 'togetherai' && !secret_state[SECRET_KEYS.TOGETHERAI] ||
|
||||
settings.source === 'nomicai' && !secret_state[SECRET_KEYS.NOMICAI] ||
|
||||
settings.source === 'cohere' && !secret_state[SECRET_KEYS.COHERE] ||
|
||||
settings.source === 'workers_ai' && !secret_state[SECRET_KEYS.WORKERS_AI] ||
|
||||
settings.source === 'siliconflow' && !secret_state[SECRET_KEYS.SILICONFLOW]) {
|
||||
throw new Error('Vectors: API key missing', { cause: 'api_key_missing' });
|
||||
}
|
||||
@@ -963,6 +1024,10 @@ function throwIfSourceInvalid() {
|
||||
if (settings.source === 'webllm' && (!isWebLlmSupported() || !settings.webllm_model)) {
|
||||
throw new Error('Vectors: WebLLM is not supported', { cause: 'webllm_not_supported' });
|
||||
}
|
||||
|
||||
if (settings.source === 'workers_ai' && !oai_settings.workers_ai_account_id) {
|
||||
throw new Error('Vectors: Workers AI account ID missing', { cause: 'account_id_missing' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1154,211 +1219,77 @@ function toggleSettings() {
|
||||
$('#koboldcpp_vectorsModel').toggle(settings.source === 'koboldcpp');
|
||||
$('#google_vectorsModel').toggle(settings.source === 'palm' || settings.source === 'vertexai');
|
||||
$('#siliconflow_vectorsModel').toggle(settings.source === 'siliconflow');
|
||||
$('#workers_ai_vectorsModel').toggle(settings.source === 'workers_ai');
|
||||
$('#vector_altEndpointUrl').toggle(vectorApiRequiresUrl.includes(settings.source));
|
||||
switch (settings.source) {
|
||||
case 'webllm':
|
||||
loadWebLlmModels();
|
||||
break;
|
||||
case 'electronhub':
|
||||
loadElectronHubModels();
|
||||
break;
|
||||
case 'openrouter':
|
||||
loadOpenRouterModels();
|
||||
break;
|
||||
case 'chutes':
|
||||
loadChutesModels();
|
||||
break;
|
||||
case 'nanogpt':
|
||||
loadNanoGPTModels();
|
||||
break;
|
||||
case 'siliconflow':
|
||||
loadSiliconFlowModels();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadChutesModels() {
|
||||
try {
|
||||
const response = await fetch('/api/openai/chutes/models/embedding', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders({ omitContentType: true }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
/** @type {Array<any>} */
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data) ? data : [];
|
||||
populateChutesModelSelect(models);
|
||||
} catch (err) {
|
||||
console.warn('Chutes models fetch failed', err);
|
||||
populateChutesModelSelect([]);
|
||||
}
|
||||
}
|
||||
|
||||
function populateChutesModelSelect(models) {
|
||||
const select = $('#vectors_chutes_model');
|
||||
select.empty();
|
||||
for (const m of models) {
|
||||
const option = document.createElement('option');
|
||||
option.value = m.slug;
|
||||
option.text = m.name;
|
||||
select.append(option);
|
||||
}
|
||||
if (!settings.chutes_model && models.length) {
|
||||
settings.chutes_model = models[0].slug;
|
||||
}
|
||||
$('#vectors_chutes_model').val(settings.chutes_model);
|
||||
}
|
||||
|
||||
async function loadNanoGPTModels() {
|
||||
try {
|
||||
const response = await fetch('/api/openai/nanogpt/models/embedding', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders({ omitContentType: true }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
/** @type {Array<any>} */
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data) ? data : [];
|
||||
populateNanoGPTModelSelect(models);
|
||||
} catch (err) {
|
||||
console.warn('NanoGPT models fetch failed', err);
|
||||
populateNanoGPTModelSelect([]);
|
||||
}
|
||||
}
|
||||
|
||||
function populateNanoGPTModelSelect(models) {
|
||||
const select = $('#vectors_nanogpt_model');
|
||||
select.empty();
|
||||
for (const m of models) {
|
||||
const option = document.createElement('option');
|
||||
option.value = m.id;
|
||||
option.text = m.name || m.id;
|
||||
select.append(option);
|
||||
}
|
||||
if (!settings.nanogpt_model && models.length) {
|
||||
settings.nanogpt_model = models[0].id;
|
||||
}
|
||||
$('#vectors_nanogpt_model').val(settings.nanogpt_model);
|
||||
}
|
||||
|
||||
async function loadElectronHubModels() {
|
||||
try {
|
||||
const response = await fetch('/api/openai/electronhub/models', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders({ omitContentType: true }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
/** @type {Array<any>} */
|
||||
const data = await response.json();
|
||||
// filter by embeddings endpoint
|
||||
const models = Array.isArray(data) ? data.filter(m => Array.isArray(m?.endpoints) && m.endpoints.includes('/v1/embeddings')) : [];
|
||||
populateElectronHubModelSelect(models);
|
||||
} catch (err) {
|
||||
console.warn('Electron Hub models fetch failed', err);
|
||||
populateElectronHubModelSelect([]);
|
||||
if (settings.source === 'webllm') {
|
||||
loadWebLlmModels();
|
||||
} else if (settings.source in remoteEmbeddingEndpoints) {
|
||||
loadRemoteEmbeddingModels(settings.source);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the Electron Hub model select element.
|
||||
* @param {{ id: string, name: string }[]} models Electron Hub models
|
||||
* Loads models from a remote embedding endpoint and populates the corresponding select element.
|
||||
* @param {string} source - The source key matching a remoteEmbeddingEndpoints entry
|
||||
*/
|
||||
function populateElectronHubModelSelect(models) {
|
||||
const select = $('#vectors_electronhub_model');
|
||||
select.empty();
|
||||
for (const m of models) {
|
||||
const option = document.createElement('option');
|
||||
option.value = m.id;
|
||||
option.text = m.name || m.id;
|
||||
select.append(option);
|
||||
async function loadRemoteEmbeddingModels(source) {
|
||||
const config = remoteEmbeddingEndpoints[source];
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
if (!settings.electronhub_model && models.length) {
|
||||
settings.electronhub_model = models[0].id;
|
||||
}
|
||||
$('#vectors_electronhub_model').val(settings.electronhub_model);
|
||||
}
|
||||
|
||||
async function loadOpenRouterModels() {
|
||||
try {
|
||||
const response = await fetch('/api/openrouter/models/embedding', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders({ omitContentType: true }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
const { url, settingsKey, selectId, getBody, filter } = config;
|
||||
const valueProperty = config.valueProperty || 'id';
|
||||
const textProperty = config.textProperty;
|
||||
|
||||
/**
|
||||
* Populates the select element with the given models.
|
||||
* @param {any[]} models - Array of model objects
|
||||
*/
|
||||
function populateSelect(models) {
|
||||
const select = $(`#${selectId}`);
|
||||
select.empty();
|
||||
for (const m of models) {
|
||||
const option = document.createElement('option');
|
||||
option.value = m[valueProperty];
|
||||
option.text = textProperty ? (m[textProperty] || m[valueProperty]) : m[valueProperty];
|
||||
select.append(option);
|
||||
}
|
||||
/** @type {Array<any>} */
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data) ? data : [];
|
||||
populateOpenRouterModelSelect(models);
|
||||
} catch (err) {
|
||||
console.warn('OpenRouter models fetch failed', err);
|
||||
populateOpenRouterModelSelect([]);
|
||||
if (!settings[settingsKey] && models.length) {
|
||||
settings[settingsKey] = models[0][valueProperty];
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
select.val(settings[settingsKey]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the OpenRouter model select element.
|
||||
* @param {{ id: string, name: string }[]} models OpenRouter models
|
||||
*/
|
||||
function populateOpenRouterModelSelect(models) {
|
||||
const select = $('#vectors_openrouter_model');
|
||||
select.empty();
|
||||
for (const m of models) {
|
||||
const option = document.createElement('option');
|
||||
option.value = m.id;
|
||||
option.text = m.name || m.id;
|
||||
select.append(option);
|
||||
}
|
||||
if (!settings.openrouter_model && models.length) {
|
||||
settings.openrouter_model = models[0].id;
|
||||
}
|
||||
$('#vectors_openrouter_model').val(settings.openrouter_model);
|
||||
}
|
||||
|
||||
async function loadSiliconFlowModels() {
|
||||
try {
|
||||
const response = await fetch('/api/openai/siliconflow/models/embedding', {
|
||||
const body = typeof getBody === 'function' ? getBody() : {};
|
||||
|
||||
/** @type {RequestInit} */
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
siliconflow_endpoint: oai_settings.siliconflow_endpoint,
|
||||
}),
|
||||
});
|
||||
body: JSON.stringify(body || {}),
|
||||
};
|
||||
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
/** @type {Array<any>} */
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data) ? data : [];
|
||||
populateSiliconFlowModelSelect(models);
|
||||
} catch (err) {
|
||||
console.warn('SiliconFlow models fetch failed', err);
|
||||
populateSiliconFlowModelSelect([]);
|
||||
}
|
||||
}
|
||||
let models = Array.isArray(data) ? data : [];
|
||||
if (filter) {
|
||||
models = filter(models);
|
||||
}
|
||||
|
||||
function populateSiliconFlowModelSelect(models) {
|
||||
const select = $('#vectors_siliconflow_model');
|
||||
select.empty();
|
||||
for (const m of models) {
|
||||
const option = document.createElement('option');
|
||||
option.value = m.id;
|
||||
option.text = m.id;
|
||||
select.append(option);
|
||||
populateSelect(models);
|
||||
} catch (err) {
|
||||
console.warn(`${source} models fetch failed`, err);
|
||||
populateSelect([]);
|
||||
}
|
||||
if (!settings.siliconflow_model && models.length) {
|
||||
settings.siliconflow_model = models[0].id;
|
||||
}
|
||||
$('#vectors_siliconflow_model').val(settings.siliconflow_model);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1496,10 +1427,11 @@ async function onViewStatsClick() {
|
||||
{ timeOut: 10000, escapeHtml: false },
|
||||
);
|
||||
|
||||
$('#chat .mes.vectorized').removeClass('vectorized');
|
||||
const chat = getContext().chat;
|
||||
for (const message of chat) {
|
||||
if (hashesInCollection.includes(getStringHash(substituteParams(message.mes)))) {
|
||||
const messageElement = $(`.mes[mesid="${chat.indexOf(message)}"]`);
|
||||
const messageElement = $(`#chat .mes[mesid="${chat.indexOf(message)}"]`);
|
||||
messageElement.addClass('vectorized');
|
||||
}
|
||||
}
|
||||
@@ -1704,7 +1636,7 @@ async function activateWorldInfo(chat) {
|
||||
await eventSource.emit(event_types.WORLDINFO_FORCE_ACTIVATE, activatedEntries);
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
if (!extension_settings.vectors) {
|
||||
extension_settings.vectors = settings;
|
||||
}
|
||||
@@ -1726,6 +1658,11 @@ jQuery(async () => {
|
||||
saveSettingsDebounced();
|
||||
toggleSettings();
|
||||
});
|
||||
$('#vectors_keep_hidden').prop('checked', settings.keep_hidden).on('input', () => {
|
||||
settings.keep_hidden = !!$('#vectors_keep_hidden').prop('checked');
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
$('#vectors_enabled_files').prop('checked', settings.enabled_files).on('input', () => {
|
||||
settings.enabled_files = $('#vectors_enabled_files').prop('checked');
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
@@ -1778,6 +1715,11 @@ jQuery(async () => {
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
$('#vectors_workers_ai_model').val(settings.workers_ai_model).on('change', () => {
|
||||
settings.workers_ai_model = String($('#vectors_workers_ai_model').val());
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
$('#vectors_openrouter_model').val(settings.openrouter_model).on('change', () => {
|
||||
settings.openrouter_model = String($('#vectors_openrouter_model').val());
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
@@ -2310,4 +2252,4 @@ jQuery(async () => {
|
||||
}
|
||||
await purgeAllVectorIndexes();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
</label>
|
||||
<select id="vectors_source" class="text_pole">
|
||||
<option value="chutes">Chutes</option>
|
||||
<option value="workers_ai">Cloudflare Workers AI</option>
|
||||
<option value="cohere">Cohere</option>
|
||||
<option value="electronhub">Electron Hub</option>
|
||||
<option value="extras">Extras (deprecated)</option>
|
||||
@@ -205,6 +206,16 @@
|
||||
</i>
|
||||
</div>
|
||||
|
||||
<div class="flex-container flexFlowColumn" id="workers_ai_vectorsModel">
|
||||
<label for="vectors_workers_ai_model" data-i18n="Vectorization Model">
|
||||
Vectorization Model
|
||||
</label>
|
||||
<select id="vectors_workers_ai_model" class="text_pole"></select>
|
||||
<i data-i18n="Hint: Set your Workers AI API key and Account ID in API Connections.">
|
||||
Hint: Set your Workers AI API key and Account ID in API Connections.
|
||||
</i>
|
||||
</div>
|
||||
|
||||
<div class="flex-container marginTopBot5">
|
||||
<div class="flex-container flex1 flexFlowColumn" title="How many last messages will be matched for relevance.">
|
||||
<label for="vectors_query">
|
||||
@@ -408,6 +419,10 @@
|
||||
<hr>
|
||||
|
||||
<div id="vectors_chats_settings">
|
||||
<label class="checkbox_label expander" for="vectors_keep_hidden" title="Keep hidden (system) messages in the vector index and include them in query results.">
|
||||
<input id="vectors_keep_hidden" type="checkbox" class="checkbox">
|
||||
<span data-i18n="Include hidden messages">Include hidden messages</span>
|
||||
</label>
|
||||
<div id="vectors_advanced_settings">
|
||||
<label for="vectors_template" data-i18n="Injection Template">
|
||||
Injection Template
|
||||
|
||||
@@ -139,7 +139,8 @@ async function getLocaleData(language) {
|
||||
function findLang(language) {
|
||||
const supportedLang = langs.find(x => x.lang === language);
|
||||
|
||||
if (!supportedLang && language !== 'en') {
|
||||
const isEn = language.startsWith('en'); // includes 'en', and more specific locales like 'en-us', 'en-au', etc
|
||||
if (!supportedLang && !isEn) {
|
||||
console.warn(`Unsupported language: ${language}`);
|
||||
}
|
||||
return supportedLang;
|
||||
|
||||
@@ -202,6 +202,7 @@ export function getKoboldGenerationData(finalPrompt, settings, maxLength, maxCon
|
||||
mirostat_eta: (kai_flags.can_use_mirostat || isHorde) ? kai_settings.mirostat_eta : undefined,
|
||||
use_default_badwordsids: (kai_flags.can_use_default_badwordsids || isHorde) ? kai_settings.use_default_badwordsids : undefined,
|
||||
grammar: (kai_flags.can_use_grammar || isHorde) ? substituteParams(kai_settings.grammar) : undefined,
|
||||
grammar_retain_state: (kai_flags.can_use_grammar && !!isContinue) ? true : undefined,
|
||||
sampler_seed: kai_settings.seed >= 0 ? kai_settings.seed : undefined,
|
||||
api_server: kai_settings.api_server,
|
||||
};
|
||||
|
||||
@@ -58,10 +58,11 @@ export class MacrosParser {
|
||||
*
|
||||
* @param {string} method
|
||||
* @param {string} replacement
|
||||
* @param {IArguments} [methodArgs=null]
|
||||
* @returns {void}
|
||||
*/
|
||||
static #logDeprecated(method, replacement) {
|
||||
console.warn(`[DEPRECATED] MacrosParser.${method} is deprecated and will be removed in a future version. Use ${replacement} instead.`);
|
||||
static #logDeprecated(method, replacement, methodArgs = null) {
|
||||
console.warn(`[DEPRECATED] MacrosParser.${method} is deprecated and will be removed in a future version. Use ${replacement} instead. Arguments:`, (methodArgs ?? 'none'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +156,7 @@ export class MacrosParser {
|
||||
* @returns {string|MacroFunction|undefined} The macro value
|
||||
*/
|
||||
static get(key) {
|
||||
MacrosParser.#logDeprecated('get', 'macros.registry.getMacro (from scripts/macros/macro-system.js)');
|
||||
MacrosParser.#logDeprecated('get', 'macros.registry.getMacro (from scripts/macros/macro-system.js)', arguments);
|
||||
return MacrosParser.#macros.get(key);
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ export class MacrosParser {
|
||||
* @returns {boolean} True if the macro is registered, false otherwise
|
||||
*/
|
||||
static has(key) {
|
||||
MacrosParser.#logDeprecated('has', 'macros.registry.hasMacro (from scripts/macros/macro-system.js)');
|
||||
MacrosParser.#logDeprecated('has', 'macros.registry.hasMacro (from scripts/macros/macro-system.js)', arguments);
|
||||
if (power_user.experimental_macro_engine) {
|
||||
return macroSystem.registry.hasMacro(key);
|
||||
}
|
||||
@@ -180,7 +181,7 @@ export class MacrosParser {
|
||||
* @param {string} [description] Optional description of the macro
|
||||
*/
|
||||
static registerMacro(key, value, description = '') {
|
||||
MacrosParser.#logDeprecated('registerMacro', 'macros.registry.registerMacro (from scripts/macros/macro-system.js) or substituteParams({ dynamicMacros })');
|
||||
MacrosParser.#logDeprecated('registerMacro', 'macros.registry.registerMacro (from scripts/macros/macro-system.js) or substituteParams({ dynamicMacros })', arguments);
|
||||
if (typeof key !== 'string') {
|
||||
throw new Error('Macro key must be a string');
|
||||
}
|
||||
@@ -223,7 +224,7 @@ export class MacrosParser {
|
||||
* @param {string} key Macro name (key)
|
||||
*/
|
||||
static unregisterMacro(key) {
|
||||
MacrosParser.#logDeprecated('unregisterMacro', 'macros.registry.unregisterMacro (from scripts/macros/macro-system.js)');
|
||||
MacrosParser.#logDeprecated('unregisterMacro', 'macros.registry.unregisterMacro (from scripts/macros/macro-system.js)', arguments);
|
||||
if (typeof key !== 'string') {
|
||||
throw new Error('Macro key must be a string');
|
||||
}
|
||||
|
||||
@@ -196,6 +196,7 @@ export const chat_completion_sources = {
|
||||
AZURE_OPENAI: 'azure_openai',
|
||||
ZAI: 'zai',
|
||||
SILICONFLOW: 'siliconflow',
|
||||
WORKERS_AI: 'workers_ai',
|
||||
};
|
||||
|
||||
const character_names_behavior = {
|
||||
@@ -279,6 +280,7 @@ const sensitiveFields = [
|
||||
'vertexai_express_project_id',
|
||||
'azure_base_url',
|
||||
'azure_deployment_name',
|
||||
'workers_ai_account_id',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -337,6 +339,8 @@ export const settingsToUpdate = {
|
||||
vertexai_model: ['#model_vertexai_select', 'vertexai_model', false, true],
|
||||
zai_model: ['#model_zai_select', 'zai_model', false, true],
|
||||
zai_endpoint: ['#zai_endpoint', 'zai_endpoint', false, true],
|
||||
workers_ai_model: ['#model_workers_ai_select', 'workers_ai_model', false, true],
|
||||
workers_ai_account_id: ['#workers_ai_account_id', 'workers_ai_account_id', false, true],
|
||||
openai_max_context: ['#openai_max_context', 'openai_max_context', false, false],
|
||||
openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false, false],
|
||||
names_behavior: ['#names_behavior', 'names_behavior', false, false],
|
||||
@@ -439,6 +443,8 @@ const default_settings = {
|
||||
fireworks_model: 'accounts/fireworks/models/kimi-k2-instruct',
|
||||
zai_model: 'glm-4.6',
|
||||
zai_endpoint: ZAI_ENDPOINT.COMMON,
|
||||
workers_ai_model: '@cf/meta/llama-3.3-70b-instruct-fp8-fast',
|
||||
workers_ai_account_id: '',
|
||||
azure_base_url: '',
|
||||
azure_deployment_name: '',
|
||||
azure_api_version: '2024-02-15-preview',
|
||||
@@ -1727,6 +1733,8 @@ export function getChatCompletionModel(settings = null) {
|
||||
return settings.azure_openai_model;
|
||||
case chat_completion_sources.ZAI:
|
||||
return settings.zai_model;
|
||||
case chat_completion_sources.WORKERS_AI:
|
||||
return settings.workers_ai_model;
|
||||
default:
|
||||
console.error(`Unknown chat completion source: ${source}`);
|
||||
return '';
|
||||
@@ -2193,6 +2201,24 @@ function saveModelList(data) {
|
||||
$('#model_fireworks_select').val(oai_settings.fireworks_model).trigger('change');
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.WORKERS_AI) {
|
||||
$('#model_workers_ai_select').empty();
|
||||
model_list.forEach((model) => {
|
||||
$('#model_workers_ai_select').append(
|
||||
$('<option>', {
|
||||
value: model.id,
|
||||
text: model.id,
|
||||
}));
|
||||
});
|
||||
|
||||
const selectedModel = model_list.find(model => model.id === oai_settings.workers_ai_model);
|
||||
if (model_list.length > 0 && (!selectedModel || !oai_settings.workers_ai_model)) {
|
||||
oai_settings.workers_ai_model = model_list[0].id;
|
||||
}
|
||||
|
||||
$('#model_workers_ai_select').val(oai_settings.workers_ai_model).trigger('change');
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.COMETAPI) {
|
||||
$('#model_cometapi_select').empty();
|
||||
|
||||
@@ -2604,7 +2630,8 @@ export async function createGenerationParameters(settings, model, type, messages
|
||||
];
|
||||
|
||||
const isO1 = gptSources.includes(settings.chat_completion_source) && ['o1-2024-12-17', 'o1'].includes(model);
|
||||
const stream = settings.stream_openai && type !== 'quiet' && !isO1;
|
||||
const isWorkersAIJsonMode = settings.chat_completion_source === chat_completion_sources.WORKERS_AI && jsonSchema;
|
||||
const stream = settings.stream_openai && type !== 'quiet' && !isO1 && !isWorkersAIJsonMode;
|
||||
|
||||
const noMultiSwipeTypes = ['quiet', 'impersonate', 'continue'];
|
||||
const canMultiSwipe = settings.n > 1 && !noMultiSwipeTypes.includes(type) && multiswipeSources.includes(settings.chat_completion_source);
|
||||
@@ -2815,6 +2842,16 @@ export async function createGenerationParameters(settings, model, type, messages
|
||||
generate_data.siliconflow_endpoint = settings.siliconflow_endpoint || SILICONFLOW_ENDPOINT.GLOBAL;
|
||||
}
|
||||
|
||||
if (settings.chat_completion_source === chat_completion_sources.WORKERS_AI) {
|
||||
generate_data.workers_ai_account_id = settings.workers_ai_account_id;
|
||||
generate_data.top_k = settings.top_k_openai > 0 ? Math.min(Number(settings.top_k_openai), 50) : undefined;
|
||||
generate_data.repetition_penalty = Number(settings.repetition_penalty_openai);
|
||||
generate_data.seed = settings.seed >= 1 ? Number(settings.seed) : undefined;
|
||||
generate_data.top_p = Math.max(Number(settings.top_p_openai), 0.001);
|
||||
delete generate_data.n;
|
||||
delete generate_data.logit_bias;
|
||||
}
|
||||
|
||||
// https://docs.nano-gpt.com/api-reference/endpoint/chat-completion#temperature-&-nucleus
|
||||
if (settings.chat_completion_source === chat_completion_sources.NANOGPT) {
|
||||
generate_data.top_k = Number(settings.top_k_openai);
|
||||
@@ -3052,7 +3089,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].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].includes(chat_completion_source)) {
|
||||
if (show_thoughts) {
|
||||
state.reasoning +=
|
||||
data.choices?.filter(x => x?.delta?.reasoning_content)?.[0]?.delta?.reasoning_content ??
|
||||
@@ -4272,6 +4309,10 @@ async function getStatusOpen() {
|
||||
data.siliconflow_endpoint = oai_settings.siliconflow_endpoint;
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.WORKERS_AI) {
|
||||
data.workers_ai_account_id = oai_settings.workers_ai_account_id;
|
||||
}
|
||||
|
||||
const canBypass = (oai_settings.chat_completion_source === chat_completion_sources.OPENAI && oai_settings.bypass_status_check) || oai_settings.chat_completion_source === chat_completion_sources.CUSTOM;
|
||||
if (canBypass) {
|
||||
setOnlineStatus(t`Status check bypassed`);
|
||||
@@ -4921,6 +4962,7 @@ function getZaiMaxContext(model, isUnlocked) {
|
||||
const contextMap = {
|
||||
'glm-5.1': max_200k,
|
||||
'glm-5-turbo': max_200k,
|
||||
'glm-5v-turbo': max_200k,
|
||||
'glm-5': max_200k,
|
||||
'glm-4.7': max_200k,
|
||||
'glm-4.7-flash': max_200k,
|
||||
@@ -5328,6 +5370,15 @@ async function onModelChange() {
|
||||
oai_settings.zai_model = value;
|
||||
}
|
||||
|
||||
if ($(this).is('#model_workers_ai_select')) {
|
||||
if (!value || !hasModelsLoaded) {
|
||||
console.debug('Null Workers AI model selected. Ignoring.');
|
||||
return;
|
||||
}
|
||||
console.log('Workers AI model changed to', value);
|
||||
oai_settings.workers_ai_model = value;
|
||||
}
|
||||
|
||||
if ([chat_completion_sources.MAKERSUITE, chat_completion_sources.VERTEXAI].includes(oai_settings.chat_completion_source)) {
|
||||
if (oai_settings.max_context_unlocked) {
|
||||
$('#openai_max_context').attr('max', max_2mil);
|
||||
@@ -5548,6 +5599,22 @@ async function onModelChange() {
|
||||
$('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.WORKERS_AI) {
|
||||
if (oai_settings.max_context_unlocked) {
|
||||
$('#openai_max_context').attr('max', unlocked_max);
|
||||
} else {
|
||||
const model = model_list.find(m => m.id === oai_settings.workers_ai_model);
|
||||
const ctxProp = Array.isArray(model?.properties) && model.properties.find(p => p.property_id === 'context_window');
|
||||
const contextLength = ctxProp ? Number(ctxProp.value) : max_8k;
|
||||
$('#openai_max_context').attr('max', contextLength || max_8k);
|
||||
}
|
||||
oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context);
|
||||
$('#openai_max_context').val(oai_settings.openai_max_context).trigger('input');
|
||||
const workersAiMaxTemp = 5.0;
|
||||
oai_settings.temp_openai = Math.min(workersAiMaxTemp, oai_settings.temp_openai);
|
||||
$('#temp_openai').attr('max', workersAiMaxTemp).val(oai_settings.temp_openai).trigger('input');
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.COMETAPI) {
|
||||
$('#openai_max_context').attr('max', oai_settings.max_context_unlocked ? unlocked_max : max_128k);
|
||||
oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context);
|
||||
@@ -5709,6 +5776,7 @@ async function onConnectButtonClick(e) {
|
||||
[chat_completion_sources.ZAI]: { key: SECRET_KEYS.ZAI, selector: '#api_key_zai', proxy: true },
|
||||
[chat_completion_sources.CHUTES]: { key: SECRET_KEYS.CHUTES, selector: '#api_key_chutes', proxy: false },
|
||||
[chat_completion_sources.POLLINATIONS]: { key: SECRET_KEYS.POLLINATIONS, selector: '#api_key_pollinations', proxy: false },
|
||||
[chat_completion_sources.WORKERS_AI]: { key: SECRET_KEYS.WORKERS_AI, selector: '#api_key_workers_ai', proxy: false },
|
||||
};
|
||||
|
||||
// Vertex AI Express version - use API key
|
||||
@@ -5798,6 +5866,8 @@ function toggleChatCompletionForms() {
|
||||
$('#azure_openai_model').trigger('change');
|
||||
} else if (oai_settings.chat_completion_source == chat_completion_sources.ZAI) {
|
||||
$('#model_zai_select').trigger('change');
|
||||
} else if (oai_settings.chat_completion_source == chat_completion_sources.WORKERS_AI) {
|
||||
$('#model_workers_ai_select').trigger('change');
|
||||
}
|
||||
|
||||
$('[data-source]').each(function () {
|
||||
@@ -5923,6 +5993,7 @@ export function isImageInliningSupported() {
|
||||
// Z.AI (GLM)
|
||||
'glm-4.5v',
|
||||
'glm-4.6v',
|
||||
'glm-5v-turbo',
|
||||
'autoglm-phone',
|
||||
// SiliconFlow
|
||||
'Qwen/Qwen3-VL-32B-Instruct',
|
||||
@@ -5978,6 +6049,10 @@ 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.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'));
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -6005,6 +6080,7 @@ export function isVideoInliningSupported() {
|
||||
// Z.AI (GLM)
|
||||
'glm-4.5v',
|
||||
'glm-4.6v',
|
||||
'glm-5v-turbo',
|
||||
];
|
||||
|
||||
switch (oai_settings.chat_completion_source) {
|
||||
@@ -6949,6 +7025,10 @@ export function initOpenAI() {
|
||||
oai_settings.siliconflow_endpoint = String($(this).val());
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
$('#workers_ai_account_id').on('input', function () {
|
||||
oai_settings.workers_ai_account_id = String($(this).val());
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
$('#vertexai_service_account_json').on('input', onVertexAIServiceAccountJsonChange);
|
||||
$('#vertexai_validate_service_account').on('click', onVertexAIValidateServiceAccount);
|
||||
$('#vertexai_clear_service_account').on('click', onVertexAIClearServiceAccount);
|
||||
@@ -6977,6 +7057,7 @@ export function initOpenAI() {
|
||||
$('#model_fireworks_select').on('change', onModelChange);
|
||||
$('#azure_openai_model').on('change', onModelChange);
|
||||
$('#model_zai_select').on('change', onModelChange);
|
||||
$('#model_workers_ai_select').on('change', onModelChange);
|
||||
$('#settings_preset_openai').on('change', onSettingsPresetChange);
|
||||
$('#new_oai_preset').on('click', onNewPresetClick);
|
||||
$('#delete_oai_preset').on('click', onDeletePresetClick);
|
||||
|
||||
+59
-17
@@ -24,7 +24,7 @@ import {
|
||||
} from '../script.js';
|
||||
import { persona_description_positions, power_user } from './power-user.js';
|
||||
import { getTokenCountAsync } from './tokenizers.js';
|
||||
import { PAGINATION_TEMPLATE, clearInfoBlock, debounce, delay, download, ensureImageFormatSupported, flashHighlight, getBase64Async, getCharIndex, isFalseBoolean, isTrueBoolean, onlyUnique, parseJsonFile, setInfoBlock, localizePagination, renderPaginationDropdown, paginationDropdownChangeHandler, addLongPressEvent } from './utils.js';
|
||||
import { PAGINATION_TEMPLATE, clearInfoBlock, debounce, delay, download, ensureImageFormatSupported, flashHighlight, getBase64Async, getCharIndex, isFalseBoolean, isTrueBoolean, onlyUnique, parseJsonFile, setInfoBlock, localizePagination, renderPaginationDropdown, paginationDropdownChangeHandler, addLongPressEvent, uuidv4 } from './utils.js';
|
||||
import { debounce_timeout } from './constants.js';
|
||||
import { FILTER_TYPES, FilterHelper } from './filters.js';
|
||||
import { groups, selected_group } from './group-chats.js';
|
||||
@@ -217,11 +217,12 @@ function getUserAvatarBlock(avatarId) {
|
||||
/**
|
||||
* Initialize missing personas in the power user settings.
|
||||
* @param {string[]} avatarsList List of avatar file names
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function addMissingPersonas(avatarsList) {
|
||||
async function addMissingPersonas(avatarsList) {
|
||||
for (const persona of avatarsList) {
|
||||
if (!power_user.personas[persona]) {
|
||||
initPersona(persona, '[Unnamed Persona]', '', '');
|
||||
await initPersona(persona, '[Unnamed Persona]', '', '', { silent: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -249,7 +250,7 @@ export async function getUserAvatars(doRender = true, openPageAt = '') {
|
||||
}
|
||||
|
||||
// If any persona is missing from the power user settings, we add it
|
||||
addMissingPersonas(allEntities);
|
||||
await addMissingPersonas(allEntities);
|
||||
// Before printing the personas, we check if we should enable/disable search sorting
|
||||
verifyPersonaSearchSortRule();
|
||||
|
||||
@@ -429,7 +430,7 @@ export async function createPersona(avatarId) {
|
||||
|
||||
const personaDescription = await Popup.show.input(t`Enter a description for this persona:`, t`You can always add or change it later.`, '', { rows: 4 });
|
||||
|
||||
initPersona(avatarId, personaName, personaDescription, '');
|
||||
await initPersona(avatarId, personaName, personaDescription, '');
|
||||
if (power_user.persona_show_notifications) {
|
||||
toastr.success(t`You can now pick ${personaName} as a persona in the Persona Management menu.`, t`Persona Created`);
|
||||
}
|
||||
@@ -454,7 +455,7 @@ async function createDummyPersona() {
|
||||
|
||||
// Date + name (only ASCII) to make it unique
|
||||
const avatarId = `${Date.now()}-${personaName.replace(/[^a-zA-Z0-9]/g, '')}.png`;
|
||||
initPersona(avatarId, personaName, '', personaTitle);
|
||||
await initPersona(avatarId, personaName, '', personaTitle);
|
||||
await uploadUserAvatar(default_user_avatar, avatarId);
|
||||
}
|
||||
|
||||
@@ -464,9 +465,11 @@ async function createDummyPersona() {
|
||||
* @param {string} personaName Name for the persona
|
||||
* @param {string} personaDescription Optional description for the persona
|
||||
* @param {string} personaTitle Optional title for the persona
|
||||
* @returns {void}
|
||||
* @param {object} [options] Optional settings
|
||||
* @param {boolean} [options.silent=false] If true, no PERSONA_CREATED event is emitted (used for background migrations)
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export function initPersona(avatarId, personaName, personaDescription, personaTitle) {
|
||||
export async function initPersona(avatarId, personaName, personaDescription, personaTitle, { silent = false } = {}) {
|
||||
power_user.personas[avatarId] = personaName;
|
||||
power_user.persona_descriptions[avatarId] = {
|
||||
description: personaDescription || '',
|
||||
@@ -478,6 +481,10 @@ export function initPersona(avatarId, personaName, personaDescription, personaTi
|
||||
};
|
||||
|
||||
saveSettingsDebounced();
|
||||
|
||||
if (!silent) {
|
||||
await eventSource.emit(event_types.PERSONA_CREATED, { avatarId, name: personaName, description: personaDescription || '', title: personaTitle || '' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,6 +547,7 @@ export async function convertCharacterToPersona(characterId = null) {
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_CREATED, { avatarId: overwriteName, name, description, title: '' });
|
||||
|
||||
console.log('Persona for character created');
|
||||
toastr.success(t`You can now pick ${name} as a persona in the Persona Management menu.`, t`Persona Created`);
|
||||
@@ -778,6 +786,7 @@ async function editPersonaTitle(popup, avatarId, currentTitle) {
|
||||
delete power_user.persona_descriptions[avatarId].title;
|
||||
await getUserAvatars(true, avatarId);
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_UPDATED, avatarId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -786,6 +795,7 @@ async function editPersonaTitle(popup, avatarId, currentTitle) {
|
||||
console.log(`Updated persona title for ${avatarId} to ${newTitle}`);
|
||||
await getUserAvatars(true, avatarId);
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_UPDATED, avatarId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -821,6 +831,7 @@ async function renamePersona(avatarId) {
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_RENAMED, { avatarId, oldName: currentName, newName });
|
||||
await getUserAvatars(true, avatarId);
|
||||
updatePersonaUIStates();
|
||||
setPersonaDescription();
|
||||
@@ -1013,6 +1024,7 @@ async function lockPersona(type = 'chat') {
|
||||
connections: [],
|
||||
title: '',
|
||||
};
|
||||
await eventSource.emit(event_types.PERSONA_CREATED, { avatarId: user_avatar, name: name1, description: '', title: '' });
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
@@ -1113,13 +1125,15 @@ async function deleteUserAvatar() {
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_DELETED, { avatarId, name });
|
||||
|
||||
// Use the existing mechanism to re-render the persona list and choose the next persona here
|
||||
personaLastLoadedChatId = uuidv4(); // Force reload by making a dummy chat id
|
||||
await loadPersonaForCurrentChat({ doRender: true });
|
||||
}
|
||||
}
|
||||
|
||||
function onPersonaDescriptionInput() {
|
||||
async function onPersonaDescriptionInput() {
|
||||
power_user.persona_description = String($('#persona_description').val());
|
||||
countPersonaDescriptionTokens();
|
||||
|
||||
@@ -1145,25 +1159,35 @@ function onPersonaDescriptionInput() {
|
||||
.text(power_user.persona_description || $('#user_avatar_block').attr('no_desc_text'))
|
||||
.toggleClass('text_muted', !power_user.persona_description);
|
||||
saveSettingsDebounced();
|
||||
|
||||
if (power_user.personas[user_avatar]) {
|
||||
await eventSource.emit(event_types.PERSONA_UPDATED, user_avatar);
|
||||
}
|
||||
}
|
||||
|
||||
function onPersonaDescriptionDepthValueInput() {
|
||||
async function onPersonaDescriptionDepthValueInput() {
|
||||
power_user.persona_description_depth = Number($('#persona_depth_value').val());
|
||||
|
||||
if (power_user.personas[user_avatar]) {
|
||||
const object = getOrCreatePersonaDescriptor();
|
||||
object.depth = power_user.persona_description_depth;
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_UPDATED, user_avatar);
|
||||
return;
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function onPersonaDescriptionDepthRoleInput() {
|
||||
async function onPersonaDescriptionDepthRoleInput() {
|
||||
power_user.persona_description_role = Number($('#persona_depth_role').find(':selected').val());
|
||||
|
||||
if (power_user.personas[user_avatar]) {
|
||||
const object = getOrCreatePersonaDescriptor();
|
||||
object.role = power_user.persona_description_role;
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_UPDATED, user_avatar);
|
||||
return;
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
@@ -1171,9 +1195,9 @@ function onPersonaDescriptionDepthRoleInput() {
|
||||
|
||||
/**
|
||||
* Opens a popup to set the lorebook for the current persona.
|
||||
* @param {JQuery.ClickEvent} event Click event
|
||||
* @param {Pick<JQuery.ClickEvent, 'shiftKey' | 'altKey'>} event Click event
|
||||
*/
|
||||
async function onPersonaLoreButtonClick(event) {
|
||||
async function onPersonaLoreButtonClick({ shiftKey, altKey }) {
|
||||
const personaName = power_user.personas[user_avatar];
|
||||
const selectedLorebook = power_user.persona_description_lorebook;
|
||||
|
||||
@@ -1182,7 +1206,7 @@ async function onPersonaLoreButtonClick(event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedLorebook && !event.shiftKey && !event.altKey) {
|
||||
if (selectedLorebook && !shiftKey && !altKey) {
|
||||
openWorldInfoEditor(selectedLorebook);
|
||||
return;
|
||||
}
|
||||
@@ -1200,7 +1224,7 @@ async function onPersonaLoreButtonClick(event) {
|
||||
worldSelect.append(option);
|
||||
}
|
||||
|
||||
worldSelect.on('change', function () {
|
||||
worldSelect.on('change', async function () {
|
||||
power_user.persona_description_lorebook = String($(this).val());
|
||||
|
||||
if (power_user.personas[user_avatar]) {
|
||||
@@ -1210,12 +1234,16 @@ async function onPersonaLoreButtonClick(event) {
|
||||
|
||||
$('#persona_lore_button').toggleClass('world_set', !!power_user.persona_description_lorebook);
|
||||
saveSettingsDebounced();
|
||||
|
||||
if (power_user.personas[user_avatar]) {
|
||||
await eventSource.emit(event_types.PERSONA_UPDATED, user_avatar);
|
||||
}
|
||||
});
|
||||
|
||||
await callGenericPopup(template, POPUP_TYPE.TEXT);
|
||||
}
|
||||
|
||||
function onPersonaDescriptionPositionInput() {
|
||||
async function onPersonaDescriptionPositionInput() {
|
||||
power_user.persona_description_position = Number(
|
||||
$('#persona_description_position').find(':selected').val(),
|
||||
);
|
||||
@@ -1223,6 +1251,10 @@ function onPersonaDescriptionPositionInput() {
|
||||
if (power_user.personas[user_avatar]) {
|
||||
const object = getOrCreatePersonaDescriptor();
|
||||
object.position = power_user.persona_description_position;
|
||||
saveSettingsDebounced();
|
||||
await eventSource.emit(event_types.PERSONA_UPDATED, user_avatar);
|
||||
$('#persona_depth_position_settings').toggle(power_user.persona_description_position === persona_description_positions.AT_DEPTH);
|
||||
return;
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
@@ -1795,6 +1827,16 @@ async function duplicatePersona(avatarId) {
|
||||
};
|
||||
|
||||
await uploadUserAvatar(getUserAvatar(avatarId), newAvatarId);
|
||||
|
||||
const eventData = {
|
||||
avatarId: newAvatarId,
|
||||
name: personaName,
|
||||
description: descriptor?.description ?? '',
|
||||
title: descriptor?.title ?? '',
|
||||
duplicatedFromAvatarId: avatarId,
|
||||
};
|
||||
await eventSource.emit(event_types.PERSONA_CREATED, eventData);
|
||||
|
||||
await getUserAvatars(true, newAvatarId);
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
@@ -1807,7 +1849,7 @@ async function migrateNonPersonaUser() {
|
||||
return;
|
||||
}
|
||||
|
||||
initPersona(user_avatar, name1, '', '');
|
||||
await initPersona(user_avatar, name1, '', '', { silent: true });
|
||||
setPersonaDescription();
|
||||
await getUserAvatars(true, user_avatar);
|
||||
}
|
||||
|
||||
+50
-4
@@ -2,7 +2,7 @@ import dialogPolyfill from '../lib/dialog-polyfill.esm.js';
|
||||
import { shouldSendOnEnter } from './RossAscends-mods.js';
|
||||
import { t } from './i18n.js';
|
||||
import { power_user, toastPositionClasses } from './power-user.js';
|
||||
import { removeFromArray, runAfterAnimation, uuidv4 } from './utils.js';
|
||||
import { clamp, removeFromArray, runAfterAnimation, uuidv4 } from './utils.js';
|
||||
|
||||
/** @readonly */
|
||||
/** @enum {Number} */
|
||||
@@ -79,8 +79,12 @@ export const POPUP_RESULT = {
|
||||
* @property {string} label - The label text for the input
|
||||
* @property {string?} [tooltip=null] - Optional tooltip to be displayed. Default placeholder in input controls, tooltip icon behind the checkbox for those.
|
||||
* @property {boolean|string|undefined} [defaultState=false] - The default state when opening the popup (false if not set)
|
||||
* @property {('checkbox'|'text'|'textarea')?} [type='checkbox'] - The type of the input (default is checkbox)
|
||||
* @property {('checkbox'|'text'|'textarea'|'number')?} [type='checkbox'] - The type of the input (default is checkbox)
|
||||
* @property {number?} [rows=1] - The number of rows for the input field, if the input is 'textarea'
|
||||
* @property {number?} [min] - The minimum value for number inputs
|
||||
* @property {number?} [max] - The maximum value for number inputs
|
||||
* @property {number?} [step] - The step value for number inputs
|
||||
* @property {boolean?} [disabled=false] - Whether the input should be disabled
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -331,6 +335,7 @@ export class Popup {
|
||||
inputElement.type = 'checkbox';
|
||||
inputElement.id = input.id;
|
||||
inputElement.checked = Boolean(input.defaultState ?? false);
|
||||
inputElement.disabled = Boolean(input.disabled ?? false);
|
||||
label.appendChild(inputElement);
|
||||
const labelText = document.createElement('span');
|
||||
labelText.innerText = input.label;
|
||||
@@ -356,6 +361,7 @@ export class Popup {
|
||||
inputElement.id = input.id;
|
||||
inputElement.value = String(input.defaultState ?? '');
|
||||
inputElement.placeholder = input.tooltip ?? '';
|
||||
inputElement.disabled = Boolean(input.disabled ?? false);
|
||||
setTitleFromTooltip(inputElement, input.tooltip);
|
||||
|
||||
const labelText = document.createElement('span');
|
||||
@@ -377,6 +383,7 @@ export class Popup {
|
||||
inputElement.value = String(input.defaultState ?? '');
|
||||
inputElement.rows = input.rows ?? 1;
|
||||
inputElement.placeholder = input.tooltip ?? '';
|
||||
inputElement.disabled = Boolean(input.disabled ?? false);
|
||||
setTitleFromTooltip(inputElement, input.tooltip);
|
||||
|
||||
const labelText = document.createElement('span');
|
||||
@@ -386,9 +393,48 @@ export class Popup {
|
||||
label.appendChild(labelText);
|
||||
label.appendChild(inputElement);
|
||||
|
||||
this.inputControls.appendChild(label);
|
||||
} else if (input.type === 'number') {
|
||||
const label = document.createElement('label');
|
||||
label.classList.add('text_label', 'justifyCenter');
|
||||
label.setAttribute('for', input.id);
|
||||
|
||||
const inputElement = document.createElement('input');
|
||||
inputElement.classList.add('text_pole', 'result-control');
|
||||
inputElement.type = 'number';
|
||||
inputElement.id = input.id;
|
||||
inputElement.value = String(input.defaultState ?? '');
|
||||
inputElement.placeholder = input.tooltip ?? '';
|
||||
inputElement.min = String(input.min ?? '');
|
||||
inputElement.max = String(input.max ?? '');
|
||||
inputElement.step = String(input.step ?? '');
|
||||
inputElement.disabled = Boolean(input.disabled ?? false);
|
||||
setTitleFromTooltip(inputElement, input.tooltip);
|
||||
|
||||
inputElement.addEventListener('change', () => {
|
||||
const value = parseFloat(inputElement.value);
|
||||
if (isNaN(value)) return;
|
||||
|
||||
const min = Number.isFinite(input.min) ? input.min : -Infinity;
|
||||
const max = Number.isFinite(input.max) ? input.max : Infinity;
|
||||
const clamped = clamp(value, min, max);
|
||||
|
||||
if (clamped !== value) {
|
||||
inputElement.value = String(clamped);
|
||||
toastr.warning(t`Value must be between ${min} and ${max}. Clamped to ${clamped}.`);
|
||||
}
|
||||
});
|
||||
|
||||
const labelText = document.createElement('span');
|
||||
labelText.innerText = input.label;
|
||||
labelText.dataset.i18n = input.label;
|
||||
|
||||
label.appendChild(labelText);
|
||||
label.appendChild(inputElement);
|
||||
|
||||
this.inputControls.appendChild(label);
|
||||
} else {
|
||||
console.warn('Unknown custom input type. Only checkbox, text and textarea are supported.', input);
|
||||
console.warn('Unknown custom input type. Only checkbox, text, number and textarea are supported.', input);
|
||||
return;
|
||||
}
|
||||
});
|
||||
@@ -720,7 +766,7 @@ export class Popup {
|
||||
this.inputResults = new Map(this.customInputs.map(input => {
|
||||
/** @type {HTMLInputElement} */
|
||||
const inputControl = this.dlg.querySelector(`#${input.id}`);
|
||||
const value = ['text', 'textarea'].includes(input.type) ? inputControl.value : inputControl.checked;
|
||||
const value = ['text', 'textarea', 'number'].includes(input.type) ? inputControl.value : inputControl.checked;
|
||||
return [inputControl.id, value];
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ export function extractReasoningFromData(data, {
|
||||
case chat_completion_sources.NANOGPT:
|
||||
case chat_completion_sources.SILICONFLOW:
|
||||
case chat_completion_sources.ZAI:
|
||||
case chat_completion_sources.WORKERS_AI:
|
||||
case chat_completion_sources.CUSTOM: {
|
||||
return data?.choices?.[0]?.message?.reasoning_content
|
||||
?? data?.choices?.[0]?.message?.reasoning
|
||||
@@ -1082,7 +1083,7 @@ function registerReasoningSlashCommands() {
|
||||
helpString: t`Collapse the reasoning block of a message or range of messages.`,
|
||||
unnamedArgumentList: reasoningVisibilityArgs,
|
||||
callback: (_args, value) => {
|
||||
const details = getReasoningDetailsElements(value);
|
||||
const details = getReasoningDetailsElements(value.toString());
|
||||
if (details) details.removeAttr('open');
|
||||
return '';
|
||||
},
|
||||
@@ -1094,7 +1095,7 @@ function registerReasoningSlashCommands() {
|
||||
helpString: t`Expand the reasoning block of a message or range of messages.`,
|
||||
unnamedArgumentList: reasoningVisibilityArgs,
|
||||
callback: (_args, value) => {
|
||||
const details = getReasoningDetailsElements(value);
|
||||
const details = getReasoningDetailsElements(value.toString());
|
||||
if (details) details.attr('open', '');
|
||||
return '';
|
||||
},
|
||||
@@ -1106,7 +1107,7 @@ function registerReasoningSlashCommands() {
|
||||
helpString: t`Toggle the reasoning block of a message or range of messages. Expanded blocks will be collapsed, and collapsed blocks will be expanded.`,
|
||||
unnamedArgumentList: reasoningVisibilityArgs,
|
||||
callback: (_args, value) => {
|
||||
const details = getReasoningDetailsElements(value);
|
||||
const details = getReasoningDetailsElements(value.toString());
|
||||
if (!details) return '';
|
||||
details.each(function () {
|
||||
const $el = $(this);
|
||||
|
||||
@@ -76,6 +76,7 @@ export const SECRET_KEYS = {
|
||||
POLLINATIONS: 'api_key_pollinations',
|
||||
VOLCENGINE_APP_ID: 'volcengine_app_id',
|
||||
VOLCENGINE_ACCESS_KEY: 'volcengine_access_key',
|
||||
WORKERS_AI: 'api_key_workers_ai',
|
||||
};
|
||||
|
||||
const FRIENDLY_NAMES = {
|
||||
@@ -140,6 +141,7 @@ const FRIENDLY_NAMES = {
|
||||
[SECRET_KEYS.POLLINATIONS]: 'Pollinations',
|
||||
[SECRET_KEYS.VOLCENGINE_APP_ID]: 'Volcengine App ID',
|
||||
[SECRET_KEYS.VOLCENGINE_ACCESS_KEY]: 'Volcengine Access Key',
|
||||
[SECRET_KEYS.WORKERS_AI]: 'Cloudflare Workers AI',
|
||||
};
|
||||
|
||||
const INPUT_MAP = {
|
||||
@@ -182,8 +184,8 @@ const INPUT_MAP = {
|
||||
[SECRET_KEYS.AZURE_OPENAI]: '#api_key_azure_openai',
|
||||
[SECRET_KEYS.ZAI]: '#api_key_zai',
|
||||
[SECRET_KEYS.SILICONFLOW]: '#api_key_siliconflow',
|
||||
[SECRET_KEYS.COMFY_RUNPOD]: '#api_key_comfy_runpod',
|
||||
[SECRET_KEYS.POLLINATIONS]: '#api_key_pollinations',
|
||||
[SECRET_KEYS.WORKERS_AI]: '#api_key_workers_ai',
|
||||
};
|
||||
|
||||
const getLabel = () => moment().format('L LT');
|
||||
|
||||
@@ -6386,6 +6386,7 @@ function getModelOptions(quiet) {
|
||||
{ id: 'model_fireworks_select', api: 'openai', type: chat_completion_sources.FIREWORKS },
|
||||
{ id: 'model_cometapi_select', api: 'openai', type: chat_completion_sources.COMETAPI },
|
||||
{ id: 'model_zai_select', api: 'openai', type: chat_completion_sources.ZAI },
|
||||
{ id: 'model_workers_ai_select', api: 'openai', type: chat_completion_sources.WORKERS_AI },
|
||||
{ id: 'model_novel_select', api: 'novel', type: null },
|
||||
{ id: 'horde_model', api: 'koboldhorde', type: null },
|
||||
];
|
||||
|
||||
@@ -71,6 +71,7 @@ import {
|
||||
} from '../script.js';
|
||||
import {
|
||||
extension_settings,
|
||||
getExtensionManifest,
|
||||
ModuleWorkerWrapper,
|
||||
openThirdPartyExtensionMenu,
|
||||
renderExtensionTemplate,
|
||||
@@ -290,6 +291,7 @@ export function getContext() {
|
||||
getReasoningTemplateByName,
|
||||
unshallowCharacter,
|
||||
unshallowGroupMembers,
|
||||
getExtensionManifest,
|
||||
openThirdPartyExtensionMenu,
|
||||
symbols: {
|
||||
ignore: IGNORE_SYMBOL,
|
||||
|
||||
@@ -3,8 +3,9 @@ import { SWIPE_DIRECTION, SWIPE_SOURCE } from './constants.js';
|
||||
import { t } from './i18n.js';
|
||||
import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';
|
||||
import { power_user } from './power-user.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { getTokenCountAsync } from './tokenizers.js';
|
||||
import { clamp, timestampToMoment } from './utils.js';
|
||||
import { addLongPressEvent, clamp, copyText, timestampToMoment } from './utils.js';
|
||||
import { chat, deleteSwipe, ensureSwipes, isMessageSwipeable, isSwipingAllowed, swipe, syncMesToSwipe } from '/script.js';
|
||||
|
||||
/**
|
||||
@@ -132,6 +133,7 @@ async function openSwipePicker(messageId) {
|
||||
const template = $('#past_chat_template .select_chat_block_wrapper').clone();
|
||||
const block = template.find('.select_chat_block');
|
||||
block.removeClass('select_chat_block').addClass('swipe_picker_block');
|
||||
block.find('.select_chat_actions').removeClass('gap10px');
|
||||
const branchButton = template.find('.exportRawChatButton');
|
||||
const deleteButton = template.find('.PastChat_cross');
|
||||
const swipeInfo = Array.isArray(message.swipe_info) ? message.swipe_info[index] : null;
|
||||
@@ -162,7 +164,7 @@ async function openSwipePicker(messageId) {
|
||||
'data-i18n': '[title]Create Branch',
|
||||
})
|
||||
.removeClass('exportRawChatButton fa-solid fa-file-export')
|
||||
.addClass('swipe_picker_branch mes_button fa-regular fa-code-branch')
|
||||
.addClass('swipe_picker_branch mes_button fa-fw fa-regular fa-code-branch')
|
||||
.on('click', async (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
@@ -174,7 +176,7 @@ async function openSwipePicker(messageId) {
|
||||
.removeAttr('file_name')
|
||||
.attr('aria-disabled', String(!canDeleteSwipe))
|
||||
.removeClass('fa-skull')
|
||||
.addClass('swipe_picker_delete fa-trash-can')
|
||||
.addClass('swipe_picker_delete fa-fw fa-trash-can')
|
||||
.toggleClass('hoverglow', canDeleteSwipe)
|
||||
.toggleClass('disabled', !canDeleteSwipe)
|
||||
.each(function () {
|
||||
@@ -229,11 +231,42 @@ async function openSwipePicker(messageId) {
|
||||
|
||||
await renderSwipeList();
|
||||
});
|
||||
|
||||
// Add expand/collapse toggle
|
||||
const expandCheckboxId = `swipe_picker_expand_${messageId}_${index}`;
|
||||
const expandCheckbox = document.createElement('input');
|
||||
expandCheckbox.type = 'checkbox';
|
||||
expandCheckbox.id = expandCheckboxId;
|
||||
expandCheckbox.classList.add('swipe_picker_expand_toggle');
|
||||
block[0].prepend(expandCheckbox);
|
||||
|
||||
const expandLabel = document.createElement('label');
|
||||
expandLabel.htmlFor = expandCheckboxId;
|
||||
expandLabel.classList.add('swipe_picker_expand_label', 'fa-solid', 'fa-fw', 'fa-chevron-down');
|
||||
expandLabel.title = t`Expand/Collapse`;
|
||||
expandLabel.setAttribute('data-i18n', '[title]Expand/Collapse');
|
||||
expandLabel.addEventListener('click', (event) => event.stopPropagation());
|
||||
|
||||
// Add copy button
|
||||
const copyButton = document.createElement('div');
|
||||
copyButton.classList.add('swipe_picker_copy', 'fa-solid', 'fa-fw', 'fa-copy');
|
||||
copyButton.title = t`Copy`;
|
||||
copyButton.setAttribute('data-i18n', '[title]Copy');
|
||||
copyButton.addEventListener('click', async (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
await copyText(swipeText);
|
||||
toastr.info(t`Copied!`, '', { timeOut: 2000 });
|
||||
});
|
||||
|
||||
// Insert new buttons before the branch button
|
||||
branchButton.before(expandLabel, copyButton);
|
||||
|
||||
template.find('.select_chat_block_filename').text(`#${index + 1}${index === Number(message.swipe_id ?? 0) ? ` ${t`[Current]`}` : ''}`);
|
||||
template.find('.chat_messages_date').text(sendDate);
|
||||
template.find('.chat_file_size').text(swipeDetails.length ? `(${swipeDetails[0]}${swipeDetails.length > 1 ? ',' : ')'}` : '');
|
||||
template.find('.chat_messages_num').text(swipeDetails.length > 1 ? `${swipeDetails.slice(1).join(', ')})` : '');
|
||||
template.find('.select_chat_block_mes').text(previewText || t`(empty swipe)`);
|
||||
template.find('.select_chat_block_mes').text(previewText ? swipeText : t`(empty swipe)`);
|
||||
|
||||
block.on('click', () => setSelectedSwipe(index));
|
||||
block.on('dblclick', async () => {
|
||||
@@ -269,6 +302,7 @@ async function openSwipePicker(messageId) {
|
||||
defaultState: String(selectedSwipeId + 1),
|
||||
tooltip: `1-${message.swipes.length}`,
|
||||
}],
|
||||
large: true,
|
||||
wider: true,
|
||||
allowVerticalScrolling: true,
|
||||
onOpen: function () {
|
||||
@@ -376,22 +410,29 @@ async function openSwipePicker(messageId) {
|
||||
}
|
||||
|
||||
export function initSwipePicker() {
|
||||
$(document).on('click', '.swipes-counter.swipe-picker-enabled', async function (e) {
|
||||
/**
|
||||
* Click handler for opening the swipe picker when clicking on the swipe counter.
|
||||
* @param {JQuery.Event | Event} e Event object
|
||||
*/
|
||||
async function onSwipeCounterClick(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const mesId = Number($(this).closest('.mes').attr('mesid'));
|
||||
await openSwipePicker(mesId);
|
||||
});
|
||||
}
|
||||
|
||||
if (isMobile()) {
|
||||
addLongPressEvent('.swipes-counter.swipe-picker-enabled', onSwipeCounterClick);
|
||||
} else {
|
||||
$(document).on('click', '.swipes-counter.swipe-picker-enabled', onSwipeCounterClick);
|
||||
}
|
||||
$(document).on('keydown', '.swipes-counter.swipe-picker-enabled', async function (e) {
|
||||
if (e.key !== ' ') {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const mesId = Number($(this).closest('.mes').attr('mesid'));
|
||||
await openSwipePicker(mesId);
|
||||
onSwipeCounterClick.call(this, e);
|
||||
});
|
||||
$(document).on('click', '.mes_swipe_picker', async function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<div class="mes_button showRecentChats" title="Show recent chats" data-i18n="[title]Show recent chats">
|
||||
<i class="fa-solid fa-circle-chevron-down fa-fw fa-lg"></i>
|
||||
</div>
|
||||
<div class="mes_button recentChatsSettings" title="Recent chats settings" data-i18n="[title]Recent chats settings">
|
||||
<i class="fa-solid fa-gear fa-fw fa-lg"></i>
|
||||
</div>
|
||||
<div class="mes_button hideRecentChats" title="Hide recent chats" data-i18n="[title]Hide recent chats">
|
||||
<i class="fa-solid fa-circle-xmark fa-fw fa-lg"></i>
|
||||
</div>
|
||||
|
||||
@@ -1756,6 +1756,7 @@ export function createTextGenGenerationData(settings, model, finalPrompt = null,
|
||||
|
||||
if (settings.type === KOBOLDCPP) {
|
||||
params.grammar = settings.grammar_string || undefined;
|
||||
params.grammar_retain_state = (settings.grammar_string && !!isContinue) ? true : undefined;
|
||||
params.trim_stop = true;
|
||||
params.dry_sequence_breakers = params.parseSequenceBreakers();
|
||||
}
|
||||
|
||||
@@ -694,6 +694,28 @@ export function getTokenizerModel() {
|
||||
}
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.WORKERS_AI && oai_settings.workers_ai_model) {
|
||||
const model = oai_settings.workers_ai_model.toLowerCase();
|
||||
|
||||
if (model.includes('deepseek')) {
|
||||
return deepseekTokenizer;
|
||||
} else if (model.includes('qwen') || model.includes('qwq') || model.includes('kimi')) {
|
||||
return qwen2Tokenizer;
|
||||
} else if (model.includes('llama-3') || model.includes('llama-4')) {
|
||||
return llama3Tokenizer;
|
||||
} else if (model.includes('llama')) {
|
||||
return llamaTokenizer;
|
||||
} else if (model.includes('gemma')) {
|
||||
return gemmaTokenizer;
|
||||
} else if (model.includes('mistral')) {
|
||||
return mistralTokenizer;
|
||||
} else if (model.includes('phi')) {
|
||||
return turboTokenizer;
|
||||
} else if (model.includes('gpt-oss')) {
|
||||
return gpt4oTokenizer;
|
||||
}
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.COHERE) {
|
||||
if (oai_settings.cohere_model.includes('command-a')) {
|
||||
return commandATokenizer;
|
||||
|
||||
@@ -21,11 +21,12 @@ import { isTrueBoolean } from './utils.js';
|
||||
* @property {string} result - The result of the tool invocation.
|
||||
* @property {string?} signature - The thought signature associated with the tool invocation.
|
||||
* @property {string?} reasoning - The plaintext reasoning associated with this tool call turn.
|
||||
* @property {boolean} [error] - Whether the tool invocation failed.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} ToolInvocationResult
|
||||
* @property {ToolInvocation[]} invocations Successful tool invocations
|
||||
* @property {ToolInvocation[]} invocations Tool invocations (both successful and failed)
|
||||
* @property {Error[]} errors Errors that occurred during tool invocation
|
||||
* @property {string[]} stealthCalls Names of stealth tools that were invoked
|
||||
*/
|
||||
@@ -336,10 +337,10 @@ export class ToolManager {
|
||||
|
||||
if (error instanceof Error) {
|
||||
error.cause = name;
|
||||
return error.toString();
|
||||
return error;
|
||||
}
|
||||
|
||||
return new Error('Unknown error occurred while invoking the tool.', { cause: name }).toString();
|
||||
return new Error('Unknown error occurred while invoking the tool.', { cause: name });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -636,6 +637,8 @@ export class ToolManager {
|
||||
return currentModel.supported_features?.includes('tools');
|
||||
case chat_completion_sources.ELECTRONHUB:
|
||||
return currentModel.metadata?.function_call;
|
||||
case chat_completion_sources.WORKERS_AI:
|
||||
return Array.isArray(currentModel.properties) && currentModel.properties.some(p => p.property_id === 'function_calling' && p.value === 'true');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,6 +666,7 @@ export class ToolManager {
|
||||
chat_completion_sources.ZAI,
|
||||
chat_completion_sources.SILICONFLOW,
|
||||
chat_completion_sources.NANOGPT,
|
||||
chat_completion_sources.WORKERS_AI,
|
||||
];
|
||||
return supportedSources.includes(settings.chat_completion_source);
|
||||
}
|
||||
@@ -796,9 +800,23 @@ export class ToolManager {
|
||||
toastr.clear(toast);
|
||||
console.log('[ToolManager] Function tool result:', result);
|
||||
|
||||
// Save a successful invocation
|
||||
// Handle tool errors — still create an invocation so the LLM sees the failure
|
||||
if (toolResult instanceof Error) {
|
||||
result.errors.push(toolResult);
|
||||
if (isStealth) {
|
||||
result.stealthCalls.push(name);
|
||||
} else {
|
||||
result.invocations.push({
|
||||
id,
|
||||
displayName,
|
||||
name,
|
||||
parameters: stringify(parameters),
|
||||
result: toolResult.toString(),
|
||||
error: true,
|
||||
signature: toolCall.signature || null,
|
||||
reasoning: reasoningText || null,
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -814,6 +832,7 @@ export class ToolManager {
|
||||
name,
|
||||
parameters: stringify(parameters),
|
||||
result: toolResult,
|
||||
error: false,
|
||||
signature: toolCall.signature || null,
|
||||
reasoning: reasoningText || null,
|
||||
};
|
||||
|
||||
@@ -2955,7 +2955,7 @@ export function createTimeout(ms, errorMessage = '') {
|
||||
* Registers a long-press (touch hold) event as an alternative to modifier+click.
|
||||
* Supports event delegation for dynamically created elements.
|
||||
* @param {string} selector CSS selector for target elements
|
||||
* @param {function} callback Callback to invoke on long-press, `this` is the matched element
|
||||
* @param {(e: TouchEvent) => void} callback Callback to invoke on long-press, `this` is the matched element
|
||||
* @param {number} [delay=500] Long-press duration in ms
|
||||
*/
|
||||
export function addLongPressEvent(selector, callback, delay = 500) {
|
||||
@@ -2964,6 +2964,7 @@ export function addLongPressEvent(selector, callback, delay = 500) {
|
||||
let target = null;
|
||||
|
||||
document.addEventListener('touchstart', function (event) {
|
||||
if (!(event.target instanceof Element)) return;
|
||||
const el = event.target.closest(selector);
|
||||
if (!el) return;
|
||||
target = el;
|
||||
|
||||
@@ -35,14 +35,43 @@ import { callGenericPopup, POPUP_TYPE } from './popup.js';
|
||||
import { getMessageTimeStamp } from './RossAscends-mods.js';
|
||||
import { renderTemplateAsync } from './templates.js';
|
||||
import { accountStorage } from './util/AccountStorage.js';
|
||||
import { flashHighlight, isElementInViewport, sortMoments, timestampToMoment } from './utils.js';
|
||||
import { clamp, flashHighlight, isElementInViewport, sortMoments, timestampToMoment } from './utils.js';
|
||||
|
||||
const assistantAvatarKey = 'assistant';
|
||||
const pinnedChatsKey = 'pinnedChats';
|
||||
const recentChatsSettingsKey = 'recentChatsSettings';
|
||||
const defaultAssistantAvatar = 'default_Assistant.png';
|
||||
|
||||
const DEFAULT_DISPLAYED = 3;
|
||||
const MAX_DISPLAYED = 15;
|
||||
const DEFAULT_MAX_DISPLAYED = 15;
|
||||
const DEFAULT_COLLAPSED_DISPLAYED = 3;
|
||||
|
||||
/**
|
||||
* Gets the current recent chats settings from account storage.
|
||||
* @returns {{ maxDisplayed: number, collapsedDisplayed: number }}
|
||||
*/
|
||||
function getRecentChatsSettings() {
|
||||
const value = accountStorage.getItem(recentChatsSettingsKey);
|
||||
if (value) {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return {
|
||||
maxDisplayed: Math.max(1, parseInt(parsed.maxDisplayed) || DEFAULT_MAX_DISPLAYED),
|
||||
collapsedDisplayed: Math.max(1, parseInt(parsed.collapsedDisplayed) || DEFAULT_COLLAPSED_DISPLAYED),
|
||||
};
|
||||
} catch {
|
||||
// Ignore parse errors
|
||||
}
|
||||
}
|
||||
return { maxDisplayed: DEFAULT_MAX_DISPLAYED, collapsedDisplayed: DEFAULT_COLLAPSED_DISPLAYED };
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves recent chats settings to account storage.
|
||||
* @param {{ maxDisplayed: number, collapsedDisplayed: number }} settings
|
||||
*/
|
||||
function saveRecentChatsSettings(settings) {
|
||||
accountStorage.setItem(recentChatsSettingsKey, JSON.stringify(settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Pick<RecentChat, 'group' | 'avatar' | 'file_name'>} PinnedChat
|
||||
@@ -82,7 +111,7 @@ class PinnedChatsManager {
|
||||
|
||||
/**
|
||||
* Generates a key for pinned chat storage.
|
||||
* @param {RecentChat} recentChat Recent chat data
|
||||
* @param {Partial<RecentChat>} recentChat Recent chat data
|
||||
* @returns {string} Key for pinned chat storage
|
||||
*/
|
||||
static getKey(recentChat) {
|
||||
@@ -140,6 +169,28 @@ class PinnedChatsManager {
|
||||
this.#saveState(pinState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates pinned state when a chat is renamed.
|
||||
* @param {Partial<RecentChat>} recentChat Recent chat data (with original file_name)
|
||||
* @param {string} newFileName New file name after rename
|
||||
*/
|
||||
static rename(recentChat, newFileName) {
|
||||
const oldKey = this.getKey(recentChat);
|
||||
const pinState = { ...this.getState() };
|
||||
if (!(oldKey in pinState)) {
|
||||
return;
|
||||
}
|
||||
const updatedChat = { ...recentChat, file_name: newFileName };
|
||||
const newKey = this.getKey(updatedChat);
|
||||
pinState[newKey] = {
|
||||
group: recentChat.group,
|
||||
avatar: recentChat.avatar,
|
||||
file_name: newFileName,
|
||||
};
|
||||
delete pinState[oldKey];
|
||||
this.#saveState(pinState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all pinned chats.
|
||||
* @returns {PinnedChat[]}
|
||||
@@ -295,6 +346,12 @@ async function sendWelcomePanel(chats, expand = false) {
|
||||
accountStorage.setItem(recentHiddenKey, 'true');
|
||||
});
|
||||
});
|
||||
root.querySelectorAll('.recentChatsSettings').forEach((button) => {
|
||||
button.addEventListener('click', async (event) => {
|
||||
event.stopPropagation();
|
||||
await openRecentChatsSettingsPopup();
|
||||
});
|
||||
});
|
||||
});
|
||||
fragment.querySelectorAll('.recentChat').forEach((item) => {
|
||||
item.addEventListener('click', () => {
|
||||
@@ -627,6 +684,61 @@ async function refreshWelcomeScreen({ flashChat = null } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a popup to configure recent chats settings.
|
||||
*/
|
||||
async function openRecentChatsSettingsPopup() {
|
||||
const settings = getRecentChatsSettings();
|
||||
|
||||
const MIN_CHATS = 1;
|
||||
const MAX_CHATS = 1000;
|
||||
|
||||
/** @type {import('./popup.js').CustomPopupInput} */
|
||||
const maxRecentChatsInput = {
|
||||
id: 'maxRecentChats',
|
||||
type: 'number',
|
||||
label: t`Max recent chats`,
|
||||
tooltip: t`${MIN_CHATS} - ${MAX_CHATS}`,
|
||||
defaultState: String(settings.maxDisplayed),
|
||||
min: MIN_CHATS,
|
||||
max: MAX_CHATS,
|
||||
step: 1,
|
||||
};
|
||||
|
||||
/** @type {import('./popup.js').CustomPopupInput} */
|
||||
const collapsedRecentChatsInput = {
|
||||
id: 'collapsedRecentChats',
|
||||
type: 'number',
|
||||
label: t`Collapsed recent chats`,
|
||||
tooltip: t`${MIN_CHATS} - ${MAX_CHATS}`,
|
||||
defaultState: String(settings.collapsedDisplayed),
|
||||
min: MIN_CHATS,
|
||||
max: MAX_CHATS,
|
||||
step: 1,
|
||||
};
|
||||
|
||||
await callGenericPopup(t`Recent Chats Settings`, POPUP_TYPE.CONFIRM, null, {
|
||||
okButton: t`Save`,
|
||||
cancelButton: t`Cancel`,
|
||||
customInputs: [maxRecentChatsInput, collapsedRecentChatsInput],
|
||||
onClose: (popup) => {
|
||||
if (!popup.result) {
|
||||
return;
|
||||
}
|
||||
|
||||
const maxInputValue = popup.inputResults.get(maxRecentChatsInput.id)?.toString() ?? String(DEFAULT_MAX_DISPLAYED);
|
||||
const collapsedInputValue = popup.inputResults.get(collapsedRecentChatsInput.id)?.toString() ?? String(DEFAULT_COLLAPSED_DISPLAYED);
|
||||
|
||||
const newMax = clamp(parseInt(maxInputValue) || DEFAULT_MAX_DISPLAYED, maxRecentChatsInput.min, maxRecentChatsInput.max);
|
||||
const newCollapsed = clamp(parseInt(collapsedInputValue) || DEFAULT_COLLAPSED_DISPLAYED, collapsedRecentChatsInput.min, newMax);
|
||||
|
||||
saveRecentChatsSettings({ maxDisplayed: newMax, collapsedDisplayed: newCollapsed });
|
||||
},
|
||||
});
|
||||
|
||||
await refreshWelcomeScreen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of recent chats from the server.
|
||||
* @returns {Promise<RecentChat[]>} List of recent chats
|
||||
@@ -649,10 +761,11 @@ async function refreshWelcomeScreen({ flashChat = null } = {}) {
|
||||
* @property {boolean} pinned Indicates if the chat is pinned
|
||||
*/
|
||||
async function getRecentChats() {
|
||||
const settings = getRecentChatsSettings();
|
||||
const response = await fetch('/api/chats/recent', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({ max: MAX_DISPLAYED, pinned: PinnedChatsManager.getAll() }),
|
||||
body: JSON.stringify({ max: settings.maxDisplayed, pinned: PinnedChatsManager.getAll() }),
|
||||
cache: 'no-cache',
|
||||
});
|
||||
|
||||
@@ -694,7 +807,7 @@ async function getRecentChats() {
|
||||
chat.chat_name = chat.file_name.replace('.jsonl', '');
|
||||
chat.char_thumbnail = character ? getThumbnailUrl('avatar', character.avatar) : system_avatar;
|
||||
chat.is_group = !!group;
|
||||
chat.hidden = index >= DEFAULT_DISPLAYED;
|
||||
chat.hidden = index >= settings.collapsedDisplayed;
|
||||
chat.avatar = chat.avatar || '';
|
||||
chat.group = chat.group || '';
|
||||
chat.pinned = PinnedChatsManager.isPinned(chat);
|
||||
@@ -829,4 +942,8 @@ export function initWelcomeScreen() {
|
||||
accountStorage.setItem(assistantAvatarKey, newAvatar);
|
||||
}
|
||||
});
|
||||
|
||||
eventSource.on(event_types.CHAT_RENAMED, async ({ avatarId, groupId, oldFileName, newFileName }) => {
|
||||
PinnedChatsManager.rename({ avatar: avatarId, group: groupId, file_name: oldFileName }, newFileName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Fuse } from '../lib.js';
|
||||
|
||||
import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles, create_save, createOrEditCharacter, name1, getOneCharacter, select_selected_character } from '../script.js';
|
||||
import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique, equalsIgnoreCaseAndAccents, uuidv4, normalizeArray, getUniqueName, logSlashCommandWarn, addLongPressEvent } from './utils.js';
|
||||
import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique, equalsIgnoreCaseAndAccents, uuidv4, normalizeArray, getUniqueName, logSlashCommandWarn, addLongPressEvent, escapeHtml } from './utils.js';
|
||||
import { extension_settings, getContext } from './extensions.js';
|
||||
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
@@ -3965,7 +3965,25 @@ export async function deleteWorldInfoEntry(data, uid, { silent = false } = {}) {
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmation = silent || await Popup.show.confirm(t`Delete the entry with UID: ${uid}?`, t`This action is irreversible!`);
|
||||
const entry = data.entries[uid];
|
||||
if (!entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let previewText = '';
|
||||
if (entry.comment && entry.comment.trim()) {
|
||||
previewText = entry.comment.trim();
|
||||
} else if (entry.content) {
|
||||
const lines = entry.content.split(/\r?\n/).filter(line => line.trim());
|
||||
previewText = lines.slice(0, 2).join('\n');
|
||||
}
|
||||
|
||||
const popupHeader = t`Delete world info entry with UID: ${uid}?`;
|
||||
const popupText = previewText
|
||||
? `<strong>${t`Entry`}:</strong><br>${escapeHtml(previewText).replace(/\n/g, '<br>')}<br><br>${t`This action is irreversible!`}`
|
||||
: t`This action is irreversible!`;
|
||||
|
||||
const confirmation = silent || await Popup.show.confirm(popupHeader, popupText);
|
||||
if (!confirmation) {
|
||||
return false;
|
||||
}
|
||||
@@ -5808,9 +5826,7 @@ export function openWorldInfoEditor(worldName) {
|
||||
|
||||
/**
|
||||
* Assigns a lorebook to the current chat.
|
||||
* @param {Object} options - The options for assigning the lorebook.
|
||||
* @param {boolean} options.shiftKey - Whether the Shift key is pressed.
|
||||
* @param {boolean} options.altKey - Whether the Alt key is pressed.
|
||||
* @param {Pick<JQuery.ClickEvent, 'shiftKey' | 'altKey'>} event Click event
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function assignLorebookToChat({ shiftKey, altKey }) {
|
||||
|
||||
@@ -4788,6 +4788,48 @@ h5 {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.swipe_picker_block .select_chat_block_mes {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.swipe_picker_block .select_chat_actions {
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.swipe_picker_expand_toggle {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.swipe_picker_block:has(.swipe_picker_expand_toggle:checked) .select_chat_block_mes {
|
||||
display: block;
|
||||
-webkit-line-clamp: unset;
|
||||
line-clamp: unset;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.swipe_picker_expand_label {
|
||||
cursor: pointer;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.swipe_picker_expand_label:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.swipe_picker_copy {
|
||||
cursor: pointer;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.swipe_picker_copy:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.swipe_picker_block:has(.swipe_picker_expand_toggle:checked) .swipe_picker_expand_label {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.select_chat_block .avatar {
|
||||
grid-row: span 2;
|
||||
}
|
||||
|
||||
+47
-32
@@ -5,10 +5,11 @@ import { getConfigValue } from './util.js';
|
||||
/**
|
||||
* Gets the headers for the Mancer API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getMancerHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.MANCER);
|
||||
function getMancerHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.MANCER, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'X-API-KEY': apiKey,
|
||||
@@ -19,10 +20,11 @@ function getMancerHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the TogetherAI API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getTogetherAIHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.TOGETHERAI);
|
||||
function getTogetherAIHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.TOGETHERAI, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -32,10 +34,11 @@ function getTogetherAIHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the InfermaticAI API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getInfermaticAIHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.INFERMATICAI);
|
||||
function getInfermaticAIHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.INFERMATICAI, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -45,10 +48,11 @@ function getInfermaticAIHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the DreamGen API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getDreamGenHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.DREAMGEN);
|
||||
function getDreamGenHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.DREAMGEN, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -58,10 +62,11 @@ function getDreamGenHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the OpenRouter API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getOpenRouterHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.OPENROUTER);
|
||||
function getOpenRouterHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.OPENROUTER, secretId);
|
||||
const baseHeaders = { ...OPENROUTER_HEADERS };
|
||||
|
||||
return apiKey ? Object.assign(baseHeaders, { 'Authorization': `Bearer ${apiKey}` }) : baseHeaders;
|
||||
@@ -70,10 +75,11 @@ function getOpenRouterHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the vLLM API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getVllmHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.VLLM);
|
||||
function getVllmHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.VLLM, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -83,10 +89,11 @@ function getVllmHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the Aphrodite API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getAphroditeHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.APHRODITE);
|
||||
function getAphroditeHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.APHRODITE, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'X-API-KEY': apiKey,
|
||||
@@ -97,10 +104,11 @@ function getAphroditeHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the Tabby API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getTabbyHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.TABBY);
|
||||
function getTabbyHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.TABBY, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'x-api-key': apiKey,
|
||||
@@ -111,10 +119,11 @@ function getTabbyHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the LlamaCPP API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getLlamaCppHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.LLAMACPP);
|
||||
function getLlamaCppHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.LLAMACPP, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -123,11 +132,12 @@ function getLlamaCppHeaders(directories) {
|
||||
|
||||
/**
|
||||
* Gets the headers for the Ooba API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getOobaHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.OOBA);
|
||||
function getOobaHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.OOBA, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -137,10 +147,11 @@ function getOobaHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the KoboldCpp API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getKoboldCppHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.KOBOLDCPP);
|
||||
function getKoboldCppHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.KOBOLDCPP, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -150,10 +161,11 @@ function getKoboldCppHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the Featherless API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getFeatherlessHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.FEATHERLESS);
|
||||
function getFeatherlessHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.FEATHERLESS, secretId);
|
||||
const baseHeaders = { ...FEATHERLESS_HEADERS };
|
||||
|
||||
return apiKey ? Object.assign(baseHeaders, { 'Authorization': `Bearer ${apiKey}` }) : baseHeaders;
|
||||
@@ -162,10 +174,11 @@ function getFeatherlessHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the HuggingFace API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getHuggingFaceHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.HUGGINGFACE);
|
||||
function getHuggingFaceHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.HUGGINGFACE, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -175,10 +188,11 @@ function getHuggingFaceHeaders(directories) {
|
||||
/**
|
||||
* Gets the headers for the Generic text completion API.
|
||||
* @param {import('./users.js').UserDirectoryList} directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used to determine which secret to use)
|
||||
* @returns {object} Headers for the request
|
||||
*/
|
||||
function getGenericHeaders(directories) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.GENERIC);
|
||||
function getGenericHeaders(directories, secretId = null) {
|
||||
const apiKey = readSecret(directories, SECRET_KEYS.GENERIC, secretId);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
@@ -202,7 +216,7 @@ export function getOverrideHeaders(urlHost) {
|
||||
* @param {string|null} server API server for new request
|
||||
*/
|
||||
export function setAdditionalHeaders(request, args, server) {
|
||||
setAdditionalHeadersByType(args.headers, request.body.api_type, server, request.user.directories);
|
||||
setAdditionalHeadersByType(args.headers, request.body.api_type, server, request.user.directories, request.body.secret_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,8 +225,9 @@ export function setAdditionalHeaders(request, args, server) {
|
||||
* @param {string} type API type
|
||||
* @param {string|null} server API server for new request
|
||||
* @param {import('./users.js').UserDirectoryList} directories User directories
|
||||
* @param {string|null} secretId Secret ID for the request (optional, used for some API types to determine which secret to use)
|
||||
*/
|
||||
export function setAdditionalHeadersByType(requestHeaders, type, server, directories) {
|
||||
export function setAdditionalHeadersByType(requestHeaders, type, server, directories, secretId = null) {
|
||||
const headerGetters = {
|
||||
[TEXTGEN_TYPES.MANCER]: getMancerHeaders,
|
||||
[TEXTGEN_TYPES.VLLM]: getVllmHeaders,
|
||||
@@ -231,7 +246,7 @@ export function setAdditionalHeadersByType(requestHeaders, type, server, directo
|
||||
};
|
||||
|
||||
const getHeaders = headerGetters[type];
|
||||
const headers = getHeaders ? getHeaders(directories) : {};
|
||||
const headers = getHeaders ? getHeaders(directories, secretId) : {};
|
||||
|
||||
if (typeof server === 'string' && server.length > 0) {
|
||||
try {
|
||||
|
||||
@@ -209,6 +209,7 @@ export const CHAT_COMPLETION_SOURCES = {
|
||||
AZURE_OPENAI: 'azure_openai',
|
||||
ZAI: 'zai',
|
||||
SILICONFLOW: 'siliconflow',
|
||||
WORKERS_AI: 'workers_ai',
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@echo off
|
||||
pushd %~dp0
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev
|
||||
call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
|
||||
npm run start server.js %*
|
||||
pause
|
||||
popd
|
||||
|
||||
Generated
+12
-12
@@ -9,7 +9,7 @@
|
||||
"version": "1.0.0",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"electron": "^35.0.0"
|
||||
"electron": "^41.1.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@electron/get": {
|
||||
@@ -85,12 +85,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.13.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.9.tgz",
|
||||
"integrity": "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw==",
|
||||
"version": "24.12.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.12.2.tgz",
|
||||
"integrity": "sha512-A1sre26ke7HDIuY/M23nd9gfB+nrmhtYyMINbjI1zHJxYteKR6qSMX56FsmjMcDb3SMcjJg5BiRRgOCC/yBD0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.20.0"
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/responselike": {
|
||||
@@ -265,14 +265,14 @@
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/electron": {
|
||||
"version": "35.7.5",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-35.7.5.tgz",
|
||||
"integrity": "sha512-dnL+JvLraKZl7iusXTVTGYs10TKfzUi30uEDTqsmTm0guN9V2tbOjTzyIZbh9n3ygUjgEYyo+igAwMRXIi3IPw==",
|
||||
"version": "41.1.1",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-41.1.1.tgz",
|
||||
"integrity": "sha512-8bgvDhBjli+3Z2YCKgzzoBPh6391pr7Xv2h/tTJG4ETgvPvUxZomObbZLs31mUzYb6VrlcDDd9cyWyNKtPm3tA==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@electron/get": "^2.0.0",
|
||||
"@types/node": "^22.7.7",
|
||||
"@types/node": "^24.9.0",
|
||||
"extract-zip": "^2.0.1"
|
||||
},
|
||||
"bin": {
|
||||
@@ -768,9 +768,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "6.20.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
|
||||
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
|
||||
"version": "7.16.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
"start": "electron ."
|
||||
},
|
||||
"dependencies": {
|
||||
"electron": "^35.0.0"
|
||||
"electron": "^41.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ const API_ZAI_CODING = 'https://api.z.ai/api/coding/paas/v4';
|
||||
const API_SILICONFLOW = 'https://api.siliconflow.com/v1';
|
||||
const API_SILICONFLOW_CN = 'https://api.siliconflow.cn/v1';
|
||||
const API_OPENROUTER = 'https://openrouter.ai/api/v1';
|
||||
const API_WORKERS_AI = 'https://api.cloudflare.com/client/v4/accounts';
|
||||
|
||||
/**
|
||||
* Module-scoped Claude caching configuration values.
|
||||
@@ -208,7 +209,7 @@ function setJsonObjectFormat(bodyParams, messages, jsonSchema) {
|
||||
*/
|
||||
async function sendClaudeRequest(request, response) {
|
||||
const apiUrl = new URL(request.body.reverse_proxy || API_CLAUDE).toString();
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE);
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE, request.body.secret_id);
|
||||
const divider = '-'.repeat(process.stdout.columns);
|
||||
|
||||
if (!apiKey) {
|
||||
@@ -372,7 +373,7 @@ async function sendClaudeRequest(request, response) {
|
||||
|
||||
if (request.body.stream) {
|
||||
// Pipe remote SSE stream to Express response
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const generateResponseText = await generateResponse.text();
|
||||
@@ -425,7 +426,7 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
}
|
||||
} else {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_MAKERSUITE);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MAKERSUITE);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MAKERSUITE, request.body.secret_id);
|
||||
|
||||
if (!request.body.reverse_proxy && !apiKey) {
|
||||
console.warn(`${apiName} API key is missing.`);
|
||||
@@ -641,7 +642,7 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
} else if (authType === 'full') {
|
||||
// For Full mode (service account authentication), use project-specific URL
|
||||
// Get project ID from Service Account JSON
|
||||
const serviceAccountJson = readSecret(request.user.directories, SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT);
|
||||
const serviceAccountJson = readSecret(request.user.directories, SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT, request.body.secret_id);
|
||||
if (!serviceAccountJson) {
|
||||
console.warn('Vertex AI Service Account JSON is missing.');
|
||||
return response.status(400).send({ error: true });
|
||||
@@ -682,7 +683,7 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
if (stream) {
|
||||
try {
|
||||
// Pipe remote SSE stream to Express response
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} catch (error) {
|
||||
console.error('Error forwarding streaming response:', error);
|
||||
if (!response.headersSent) {
|
||||
@@ -742,7 +743,7 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
async function sendAI21Request(request, response) {
|
||||
if (!request.body) return response.sendStatus(400);
|
||||
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AI21);
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AI21, request.body.secret_id);
|
||||
if (!apiKey) {
|
||||
console.warn('AI21 API key is missing.');
|
||||
return response.status(400).send({ error: true });
|
||||
@@ -793,7 +794,7 @@ async function sendAI21Request(request, response) {
|
||||
try {
|
||||
const generateResponse = await fetch(API_AI21 + '/chat/completions', options);
|
||||
if (request.body.stream) {
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const errorText = await generateResponse.text();
|
||||
@@ -822,7 +823,7 @@ async function sendAI21Request(request, response) {
|
||||
*/
|
||||
async function sendMistralAIRequest(request, response) {
|
||||
const apiUrl = new URL(request.body.reverse_proxy || API_MISTRAL).toString();
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MISTRALAI);
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MISTRALAI, request.body.secret_id);
|
||||
|
||||
if (!apiKey) {
|
||||
console.warn('MistralAI API key is missing.');
|
||||
@@ -883,7 +884,7 @@ async function sendMistralAIRequest(request, response) {
|
||||
|
||||
const generateResponse = await fetch(apiUrl + '/chat/completions', config);
|
||||
if (request.body.stream) {
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const errorText = await generateResponse.text();
|
||||
@@ -911,7 +912,7 @@ async function sendMistralAIRequest(request, response) {
|
||||
* @param {express.Response} response Express response
|
||||
*/
|
||||
async function sendCohereRequest(request, response) {
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.COHERE);
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.COHERE, request.body.secret_id);
|
||||
const controller = new AbortController();
|
||||
request.socket.removeAllListeners('close');
|
||||
request.socket.on('close', function () {
|
||||
@@ -982,7 +983,7 @@ async function sendCohereRequest(request, response) {
|
||||
|
||||
if (request.body.stream) {
|
||||
const stream = await fetch(apiUrl, config);
|
||||
forwardFetchResponse(stream, response);
|
||||
await forwardFetchResponse(stream, response);
|
||||
} else {
|
||||
const generateResponse = await fetch(apiUrl, config);
|
||||
if (!generateResponse.ok) {
|
||||
@@ -1012,7 +1013,7 @@ async function sendCohereRequest(request, response) {
|
||||
*/
|
||||
async function sendDeepSeekRequest(request, response) {
|
||||
const apiUrl = new URL(request.body.reverse_proxy || API_DEEPSEEK).toString();
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.DEEPSEEK);
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.DEEPSEEK, request.body.secret_id);
|
||||
|
||||
if (!apiKey && !request.body.reverse_proxy) {
|
||||
console.warn('DeepSeek API key is missing.');
|
||||
@@ -1093,7 +1094,7 @@ async function sendDeepSeekRequest(request, response) {
|
||||
const generateResponse = await fetch(apiUrl + '/chat/completions', config);
|
||||
|
||||
if (request.body.stream) {
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const errorText = await generateResponse.text();
|
||||
@@ -1122,7 +1123,7 @@ async function sendDeepSeekRequest(request, response) {
|
||||
*/
|
||||
async function sendXaiRequest(request, response) {
|
||||
const apiUrl = new URL(request.body.reverse_proxy || API_XAI).toString();
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.XAI);
|
||||
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.XAI, request.body.secret_id);
|
||||
|
||||
if (!apiKey && !request.body.reverse_proxy) {
|
||||
console.warn('xAI API key is missing.');
|
||||
@@ -1199,7 +1200,7 @@ async function sendXaiRequest(request, response) {
|
||||
const generateResponse = await fetch(apiUrl + '/chat/completions', config);
|
||||
|
||||
if (request.body.stream) {
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const errorText = await generateResponse.text();
|
||||
@@ -1228,7 +1229,7 @@ async function sendXaiRequest(request, response) {
|
||||
*/
|
||||
async function sendAimlapiRequest(request, response) {
|
||||
const apiUrl = API_AIMLAPI;
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AIMLAPI);
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AIMLAPI, request.body.secret_id);
|
||||
|
||||
if (!apiKey) {
|
||||
console.warn('AI/ML API key is missing.');
|
||||
@@ -1304,7 +1305,7 @@ async function sendAimlapiRequest(request, response) {
|
||||
const generateResponse = await fetch(apiUrl + '/chat/completions', config);
|
||||
|
||||
if (request.body.stream) {
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const errorText = await generateResponse.text();
|
||||
@@ -1333,7 +1334,7 @@ async function sendAimlapiRequest(request, response) {
|
||||
*/
|
||||
async function sendElectronHubRequest(request, response) {
|
||||
const apiUrl = API_ELECTRONHUB;
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.ELECTRONHUB);
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.ELECTRONHUB, request.body.secret_id);
|
||||
|
||||
if (!apiKey) {
|
||||
console.warn('Electron Hub key is missing.');
|
||||
@@ -1416,7 +1417,7 @@ async function sendElectronHubRequest(request, response) {
|
||||
const generateResponse = await fetch(apiUrl + '/chat/completions', config);
|
||||
|
||||
if (request.body.stream) {
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const errorText = await generateResponse.text();
|
||||
@@ -1445,7 +1446,7 @@ async function sendElectronHubRequest(request, response) {
|
||||
*/
|
||||
async function sendChutesRequest(request, response) {
|
||||
const apiUrl = API_CHUTES;
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.CHUTES);
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.CHUTES, request.body.secret_id);
|
||||
|
||||
if (!apiKey) {
|
||||
console.warn('Chutes key is missing.');
|
||||
@@ -1517,7 +1518,7 @@ async function sendChutesRequest(request, response) {
|
||||
const generateResponse = await fetch(apiUrl + '/chat/completions', config);
|
||||
|
||||
if (request.body.stream) {
|
||||
forwardFetchResponse(generateResponse, response);
|
||||
await forwardFetchResponse(generateResponse, response);
|
||||
} else {
|
||||
if (!generateResponse.ok) {
|
||||
const errorText = await generateResponse.text();
|
||||
@@ -1547,7 +1548,7 @@ async function sendChutesRequest(request, response) {
|
||||
async function sendAzureOpenAIRequest(request, response) {
|
||||
// 1. GATHER & VALIDATE SETTINGS
|
||||
const { azure_base_url, azure_deployment_name, azure_api_version } = request.body;
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AZURE_OPENAI);
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AZURE_OPENAI, request.body.secret_id);
|
||||
if (!azure_base_url || !azure_deployment_name || !azure_api_version || !apiKey) {
|
||||
return response.status(400).send({
|
||||
error: {
|
||||
@@ -1612,7 +1613,7 @@ async function sendAzureOpenAIRequest(request, response) {
|
||||
const fetchResponse = await fetch(endpointUrl, config);
|
||||
|
||||
if (request.body.stream) {
|
||||
return forwardFetchResponse(fetchResponse, response);
|
||||
return await forwardFetchResponse(fetchResponse, response);
|
||||
}
|
||||
|
||||
if (fetchResponse.ok) {
|
||||
@@ -1646,74 +1647,74 @@ router.post('/status', async function (request, statusResponse) {
|
||||
|
||||
if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENAI) {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_OPENAI).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENROUTER) {
|
||||
apiUrl = 'https://openrouter.ai/api/v1';
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER, request.body.secret_id);
|
||||
// OpenRouter needs to pass the Referer and X-Title: https://openrouter.ai/docs#requests
|
||||
headers = { ...OPENROUTER_HEADERS };
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MISTRALAI) {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_MISTRAL).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MISTRALAI);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MISTRALAI, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.CUSTOM) {
|
||||
apiUrl = request.body.custom_url;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.CUSTOM);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.CUSTOM, request.body.secret_id);
|
||||
headers = {};
|
||||
mergeObjectWithYaml(headers, request.body.custom_include_headers);
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.COHERE) {
|
||||
apiUrl = API_COHERE_V1;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.COHERE);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.COHERE, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.CHUTES) {
|
||||
apiUrl = API_CHUTES;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.CHUTES);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.CHUTES, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.ELECTRONHUB) {
|
||||
apiUrl = API_ELECTRONHUB;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.ELECTRONHUB);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.ELECTRONHUB, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.NANOGPT) {
|
||||
apiUrl = API_NANOGPT;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.NANOGPT);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.NANOGPT, request.body.secret_id);
|
||||
headers = {};
|
||||
queryParams = { detailed: true };
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.DEEPSEEK) {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_DEEPSEEK.replace('/beta', '')).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.DEEPSEEK);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.DEEPSEEK, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.XAI) {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_XAI).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.XAI);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.XAI, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.AIMLAPI) {
|
||||
apiUrl = API_AIMLAPI;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.AIMLAPI);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.AIMLAPI, request.body.secret_id);
|
||||
headers = { ...AIMLAPI_HEADERS };
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.POLLINATIONS) {
|
||||
apiUrl = 'https://gen.pollinations.ai/text';
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.GROQ) {
|
||||
apiUrl = API_GROQ;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.GROQ);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.GROQ, request.body.secret_id);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.COMETAPI) {
|
||||
apiUrl = API_COMETAPI;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.COMETAPI);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.COMETAPI, request.body.secret_id);
|
||||
headers = {};
|
||||
throw new Error('This provider is temporarily disabled.');
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MOONSHOT) {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_MOONSHOT).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT);
|
||||
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);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.FIREWORKS, request.body.secret_id);
|
||||
headers = {};
|
||||
} 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);
|
||||
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);
|
||||
const apiVersion = getConfigValue('gemini.apiVersion', 'v1beta');
|
||||
const modelsUrl = !apiKey && request.body.reverse_proxy
|
||||
@@ -1750,7 +1751,7 @@ router.post('/status', async function (request, statusResponse) {
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.AZURE_OPENAI) {
|
||||
const { azure_base_url, azure_deployment_name, azure_api_version } = request.body;
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AZURE_OPENAI);
|
||||
const apiKey = readSecret(request.user.directories, SECRET_KEYS.AZURE_OPENAI, request.body.secret_id);
|
||||
|
||||
// 1) Validate configuration from the frontend
|
||||
if (!apiKey || !azure_base_url || !azure_deployment_name || !azure_api_version) {
|
||||
@@ -1830,9 +1831,52 @@ router.post('/status', async function (request, statusResponse) {
|
||||
const defaultApiUrl = request.body.siliconflow_endpoint === SILICONFLOW_ENDPOINT.CN
|
||||
? API_SILICONFLOW_CN : API_SILICONFLOW;
|
||||
apiUrl = defaultApiUrl;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.SILICONFLOW);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.SILICONFLOW, request.body.secret_id);
|
||||
headers = {};
|
||||
queryParams = { type: 'text', sub_type: 'chat' };
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.WORKERS_AI) {
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.WORKERS_AI, request.body.secret_id);
|
||||
|
||||
if (!apiKey) {
|
||||
console.warn('Cloudflare Workers AI API key is missing.');
|
||||
return statusResponse.status(400).send({ error: true });
|
||||
}
|
||||
|
||||
try {
|
||||
const accountId = String(request.body.workers_ai_account_id || '').trim();
|
||||
if (!accountId) {
|
||||
console.warn('Cloudflare Workers AI Account ID is missing.');
|
||||
return statusResponse.status(400).send({ error: true });
|
||||
}
|
||||
|
||||
const modelsUrl = new URL(`${API_WORKERS_AI}/${encodeURIComponent(accountId)}/ai/models/search`);
|
||||
modelsUrl.searchParams.set('task', 'Text Generation');
|
||||
modelsUrl.searchParams.set('per_page', '1000');
|
||||
|
||||
const response = await fetch(modelsUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + apiKey,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data?.result)
|
||||
? data.result.map(model => ({ ...model, id: model.name }))
|
||||
: [];
|
||||
|
||||
console.debug('Available Cloudflare Workers AI models:', models.map(m => m.id));
|
||||
return statusResponse.send({ data: models });
|
||||
} else {
|
||||
console.warn('Cloudflare Workers AI models endpoint failed:', response.status, response.statusText);
|
||||
return statusResponse.status(response.status).send({ error: true });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching Cloudflare Workers AI models:', error);
|
||||
return statusResponse.status(500).send({ error: true });
|
||||
}
|
||||
} else {
|
||||
console.warn('This chat completion source is not supported yet.');
|
||||
return statusResponse.status(400).send({ error: true });
|
||||
@@ -2053,7 +2097,7 @@ router.post('/generate', async function (request, response) {
|
||||
|
||||
if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENAI) {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_OPENAI).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {
|
||||
logprobs: request.body.logprobs,
|
||||
@@ -2073,7 +2117,7 @@ router.post('/generate', async function (request, response) {
|
||||
embedOpenRouterMedia(request.body.messages, { audio: true, video: false });
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENROUTER) {
|
||||
apiUrl = 'https://openrouter.ai/api/v1';
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER, request.body.secret_id);
|
||||
// OpenRouter needs to pass the Referer and X-Title: https://openrouter.ai/docs#requests
|
||||
headers = { ...OPENROUTER_HEADERS };
|
||||
const includeReasoning = Boolean(request.body.include_reasoning);
|
||||
@@ -2161,7 +2205,7 @@ router.post('/generate', async function (request, response) {
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.CUSTOM) {
|
||||
apiUrl = request.body.custom_url;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.CUSTOM);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.CUSTOM, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {
|
||||
logprobs: request.body.logprobs,
|
||||
@@ -2179,7 +2223,7 @@ router.post('/generate', async function (request, response) {
|
||||
embedOpenRouterMedia(request.body.messages, { audio: true, video: false });
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {
|
||||
apiUrl = API_PERPLEXITY;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {
|
||||
reasoning_effort: request.body.reasoning_effort,
|
||||
@@ -2195,7 +2239,7 @@ router.post('/generate', async function (request, response) {
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.GROQ) {
|
||||
apiUrl = API_GROQ;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.GROQ);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.GROQ, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
if (request.body.json_schema) {
|
||||
@@ -2211,7 +2255,7 @@ router.post('/generate', async function (request, response) {
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.FIREWORKS) {
|
||||
apiUrl = API_FIREWORKS;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.FIREWORKS);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.FIREWORKS, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
if (request.body.json_schema) {
|
||||
@@ -2227,7 +2271,7 @@ router.post('/generate', async function (request, response) {
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.NANOGPT) {
|
||||
apiUrl = API_NANOGPT;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.NANOGPT);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.NANOGPT, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
if (request.body.enable_web_search && !/:online$/.test(request.body.model)) {
|
||||
@@ -2256,7 +2300,7 @@ router.post('/generate', async function (request, response) {
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.POLLINATIONS) {
|
||||
apiUrl = API_POLLINATIONS;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {
|
||||
reasoning_effort: request.body.reasoning_effort,
|
||||
@@ -2272,7 +2316,7 @@ router.post('/generate', async function (request, response) {
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MOONSHOT) {
|
||||
apiUrl = new URL(request.body.reverse_proxy || API_MOONSHOT).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {
|
||||
thinking: {
|
||||
@@ -2284,7 +2328,7 @@ router.post('/generate', async function (request, response) {
|
||||
: addAssistantPrefix(request.body.messages, [], 'partial');
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.COMETAPI) {
|
||||
apiUrl = API_COMETAPI;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.COMETAPI);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.COMETAPI, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {
|
||||
reasoning_effort: request.body.reasoning_effort,
|
||||
@@ -2293,7 +2337,7 @@ router.post('/generate', async function (request, response) {
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.ZAI) {
|
||||
const defaultApiUrl = request.body.zai_endpoint === ZAI_ENDPOINT.CODING ? API_ZAI_CODING : API_ZAI_COMMON;
|
||||
apiUrl = new URL(request.body.reverse_proxy || defaultApiUrl).toString();
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.ZAI);
|
||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.ZAI, request.body.secret_id);
|
||||
headers = {
|
||||
'Accept-Language': 'en-US,en',
|
||||
};
|
||||
@@ -2309,12 +2353,30 @@ router.post('/generate', async function (request, response) {
|
||||
const defaultApiUrl = request.body.siliconflow_endpoint === SILICONFLOW_ENDPOINT.CN
|
||||
? API_SILICONFLOW_CN : API_SILICONFLOW;
|
||||
apiUrl = defaultApiUrl;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.SILICONFLOW);
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.SILICONFLOW, request.body.secret_id);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
if (request.body.json_schema) {
|
||||
setJsonObjectFormat(bodyParams, request.body.messages, request.body.json_schema);
|
||||
}
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.WORKERS_AI) {
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.WORKERS_AI, request.body.secret_id);
|
||||
const accountId = String(request.body.workers_ai_account_id || '').trim();
|
||||
if (!accountId) {
|
||||
console.warn('Cloudflare Workers AI Account ID is missing.');
|
||||
return response.status(400).send({ error: true });
|
||||
}
|
||||
apiUrl = `${API_WORKERS_AI}/${encodeURIComponent(accountId)}/ai/v1`;
|
||||
headers = {};
|
||||
bodyParams = {
|
||||
repetition_penalty: request.body.repetition_penalty,
|
||||
};
|
||||
if (request.body.json_schema) {
|
||||
bodyParams['response_format'] = {
|
||||
type: 'json_schema',
|
||||
json_schema: request.body.json_schema.value,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
console.warn('This chat completion source is not supported yet.');
|
||||
return response.status(400).send({ error: true });
|
||||
@@ -2411,7 +2473,7 @@ router.post('/generate', async function (request, response) {
|
||||
|
||||
if (request.body.stream) {
|
||||
console.info('Streaming request in progress');
|
||||
return forwardFetchResponse(fetchResponse, response);
|
||||
return await forwardFetchResponse(fetchResponse, response);
|
||||
}
|
||||
|
||||
if (fetchResponse.ok) {
|
||||
@@ -2662,6 +2724,39 @@ multimodalModels.post('/moonshot', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
multimodalModels.post('/workers_ai', async (req, res) => {
|
||||
try {
|
||||
const key = readSecret(req.user.directories, SECRET_KEYS.WORKERS_AI);
|
||||
const accountId = String(req.body.workers_ai_account_id || '').trim();
|
||||
|
||||
if (!key || !accountId) {
|
||||
return res.json([]);
|
||||
}
|
||||
|
||||
const apiUrl = `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(accountId)}/ai/models/search?task=Text+Generation&per_page=1000`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: { 'Authorization': 'Bearer ' + key },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return res.json([]);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data?.result)
|
||||
? data.result
|
||||
.filter(m => Array.isArray(m.properties) && m.properties.some(p => p.property_id === 'vision' && p.value === 'true'))
|
||||
.map(m => m.name)
|
||||
: [];
|
||||
return res.json(models);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
router.use('/multimodal-models', multimodalModels);
|
||||
|
||||
router.post('/process', async function (request, response) {
|
||||
|
||||
@@ -99,7 +99,7 @@ router.post('/generate', async function (request, response_generate) {
|
||||
|
||||
if (request.body.streaming) {
|
||||
// Pipe remote SSE stream to Express response
|
||||
forwardFetchResponse(response, response_generate);
|
||||
await forwardFetchResponse(response, response_generate);
|
||||
return;
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -404,7 +404,7 @@ router.post('/generate', async function (request, response) {
|
||||
} else if (request.body.stream) {
|
||||
const completionsStream = await fetch(url, args);
|
||||
// Pipe remote SSE stream to Express response
|
||||
forwardFetchResponse(completionsStream, response);
|
||||
await forwardFetchResponse(completionsStream, response);
|
||||
} else {
|
||||
const completionsReply = await fetch(url, args);
|
||||
|
||||
|
||||
+15
-1
@@ -321,10 +321,24 @@ async function checkChatIntegrity(filePath, integritySlug) {
|
||||
|
||||
// Parse the first line of the chat file as JSON
|
||||
const firstLine = await readFirstLine(filePath);
|
||||
|
||||
// If the file is empty, allow the save
|
||||
if (!firstLine) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const jsonData = tryParse(firstLine);
|
||||
|
||||
// If the first line exists but can't be parsed, the file may be corrupted.
|
||||
// Refuse the save to prevent silent data loss and let the user decide.
|
||||
if (!jsonData) {
|
||||
console.warn(`File "${filePath}" first line could not be parsed as JSON. Integrity check failed for slug "${integritySlug}".`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const chatIntegrity = jsonData?.chat_metadata?.integrity;
|
||||
|
||||
// If the chat has no integrity metadata, assume it's intact
|
||||
// If the chat has no integrity metadata, assume it's an old format file being upgraded
|
||||
if (!chatIntegrity) {
|
||||
console.debug(`File "${filePath}" does not have integrity metadata matching "${integritySlug}". The integrity validation has been skipped.`);
|
||||
return true;
|
||||
|
||||
@@ -53,8 +53,31 @@ export const CONTENT_TYPES = {
|
||||
QUICK_REPLIES: 'quick_replies',
|
||||
SYSPROMPT: 'sysprompt',
|
||||
REASONING: 'reasoning',
|
||||
ERROR_PAGE: 'error_page',
|
||||
STYLESHEET: 'stylesheet',
|
||||
};
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
export const CONTENT_SCOPE = {
|
||||
USER: 'user',
|
||||
GLOBAL: 'global',
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the scope of a content type.
|
||||
* @param {CONTENT_TYPES} type Content type
|
||||
* @returns {CONTENT_SCOPE} Resolved content scope
|
||||
*/
|
||||
function getScopeByType(type) {
|
||||
const globalTypes = [
|
||||
CONTENT_TYPES.ERROR_PAGE,
|
||||
CONTENT_TYPES.STYLESHEET,
|
||||
];
|
||||
return globalTypes.includes(type) ? CONTENT_SCOPE.GLOBAL : CONTENT_SCOPE.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default presets from the content directory.
|
||||
* @param {import('../users.js').UserDirectoryList} directories User directories
|
||||
@@ -62,13 +85,13 @@ export const CONTENT_TYPES = {
|
||||
*/
|
||||
export function getDefaultPresets(directories) {
|
||||
try {
|
||||
const contentIndex = getContentIndex();
|
||||
const contentIndex = getContentIndex(CONTENT_SCOPE.USER);
|
||||
const presets = [];
|
||||
|
||||
for (const contentItem of contentIndex) {
|
||||
if (contentItem.type.endsWith('_preset') || ['instruct', 'context', 'sysprompt', 'reasoning'].includes(contentItem.type)) {
|
||||
contentItem.name = path.parse(contentItem.filename).name;
|
||||
contentItem.folder = getTargetByType(contentItem.type, directories);
|
||||
contentItem.folder = getUserTargetByType(contentItem.type, directories);
|
||||
presets.push(contentItem);
|
||||
}
|
||||
}
|
||||
@@ -102,24 +125,18 @@ export function getDefaultPresetFile(filename) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeds content for a user.
|
||||
* Seeds content from a content index into a target location.
|
||||
* @param {ContentItem[]} contentIndex Content index
|
||||
* @param {import('../users.js').UserDirectoryList} directories User directories
|
||||
* @param {string[]} forceCategories List of categories to force check (even if content check is skipped)
|
||||
* @returns {Promise<boolean>} Whether any content was added
|
||||
* @param {string} contentLogPath Path to the content log file
|
||||
* @param {(type: string) => string | null} resolveTarget Function to resolve the target directory for a content type
|
||||
* @param {string[]} [forceCategories] List of categories to force check (even if content check is skipped)
|
||||
* @returns {boolean} Whether any content was added
|
||||
*/
|
||||
async function seedContentForUser(contentIndex, directories, forceCategories) {
|
||||
function seedContent(contentIndex, contentLogPath, resolveTarget, forceCategories) {
|
||||
let anyContentAdded = false;
|
||||
|
||||
if (!fs.existsSync(directories.root)) {
|
||||
fs.mkdirSync(directories.root, { recursive: true });
|
||||
}
|
||||
|
||||
const contentLogPath = path.join(directories.root, 'content.log');
|
||||
const contentLog = getContentLog(contentLogPath);
|
||||
|
||||
for (const contentItem of contentIndex) {
|
||||
// If the content item is already in the log, skip it
|
||||
if (contentLog.includes(contentItem.filename) && !forceCategories?.includes(contentItem.type)) {
|
||||
continue;
|
||||
}
|
||||
@@ -136,7 +153,7 @@ async function seedContentForUser(contentIndex, directories, forceCategories) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const contentTarget = getTargetByType(contentItem.type, directories);
|
||||
const contentTarget = resolveTarget(contentItem.type);
|
||||
|
||||
if (!contentTarget) {
|
||||
console.warn(`Content file ${contentItem.filename} has unknown type ${contentItem.type}`);
|
||||
@@ -152,6 +169,7 @@ async function seedContentForUser(contentIndex, directories, forceCategories) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fs.mkdirSync(contentTarget, { recursive: true });
|
||||
fs.cpSync(contentPath, targetPath, { recursive: true, force: false });
|
||||
setPermissionsSync(targetPath);
|
||||
console.info(`Content file ${contentItem.filename} copied to ${contentTarget}`);
|
||||
@@ -162,6 +180,32 @@ async function seedContentForUser(contentIndex, directories, forceCategories) {
|
||||
return anyContentAdded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeds content for a user.
|
||||
* @param {ContentItem[]} contentIndex Content index
|
||||
* @param {import('../users.js').UserDirectoryList} directories User directories
|
||||
* @param {string[]} forceCategories List of categories to force check (even if content check is skipped)
|
||||
* @returns {Promise<boolean>} Whether any content was added
|
||||
*/
|
||||
async function seedContentForUser(contentIndex, directories, forceCategories) {
|
||||
if (!fs.existsSync(directories.root)) {
|
||||
fs.mkdirSync(directories.root, { recursive: true });
|
||||
}
|
||||
|
||||
const contentLogPath = path.join(directories.root, 'content.log');
|
||||
return seedContent(contentIndex, contentLogPath, (type) => getUserTargetByType(type, directories), forceCategories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeds global content that is not user-specific, such as error pages.
|
||||
* @param {ContentItem[]} contentIndex Content index
|
||||
* @returns {Promise<boolean>} Whether any content was added
|
||||
*/
|
||||
async function seedGlobalContent(contentIndex) {
|
||||
const contentLogPath = path.join(globalThis.DATA_ROOT, 'content.log');
|
||||
return seedContent(contentIndex, contentLogPath, getGlobalTargetByType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for new content and seeds it for all users.
|
||||
* @param {import('../users.js').UserDirectoryList[]} directoriesList List of user directories
|
||||
@@ -175,13 +219,19 @@ export async function checkForNewContent(directoriesList, forceCategories = [])
|
||||
return;
|
||||
}
|
||||
|
||||
const contentIndex = getContentIndex();
|
||||
const userContentIndex = getContentIndex(CONTENT_SCOPE.USER);
|
||||
const globalContentIndex = getContentIndex(CONTENT_SCOPE.GLOBAL);
|
||||
let anyContentAdded = false;
|
||||
|
||||
for (const directories of directoriesList) {
|
||||
const seedResult = await seedContentForUser(contentIndex, directories, forceCategories);
|
||||
const globalSeedResult = await seedGlobalContent(globalContentIndex);
|
||||
if (globalSeedResult) {
|
||||
anyContentAdded = true;
|
||||
}
|
||||
|
||||
if (seedResult) {
|
||||
for (const directories of directoriesList) {
|
||||
const userSeedResult = await seedContentForUser(userContentIndex, directories, forceCategories);
|
||||
|
||||
if (userSeedResult) {
|
||||
anyContentAdded = true;
|
||||
}
|
||||
}
|
||||
@@ -198,9 +248,10 @@ export async function checkForNewContent(directoriesList, forceCategories = [])
|
||||
|
||||
/**
|
||||
* Gets combined content index from the content and scaffold directories.
|
||||
* @param {CONTENT_SCOPE} scope Scope of content to get
|
||||
* @returns {ContentItem[]} Array of content index
|
||||
*/
|
||||
function getContentIndex() {
|
||||
function getContentIndex(scope = CONTENT_SCOPE.USER) {
|
||||
const result = [];
|
||||
|
||||
if (fs.existsSync(scaffoldIndexPath)) {
|
||||
@@ -209,6 +260,7 @@ function getContentIndex() {
|
||||
if (Array.isArray(scaffoldIndex)) {
|
||||
scaffoldIndex.forEach((item) => {
|
||||
item.folder = scaffoldDirectory;
|
||||
item.scope = getScopeByType(item.type);
|
||||
});
|
||||
result.push(...scaffoldIndex);
|
||||
}
|
||||
@@ -220,22 +272,24 @@ function getContentIndex() {
|
||||
if (Array.isArray(contentIndex)) {
|
||||
contentIndex.forEach((item) => {
|
||||
item.folder = contentDirectory;
|
||||
item.scope = getScopeByType(item.type);
|
||||
});
|
||||
result.push(...contentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result.filter((item) => item.scope === scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets content by type and format.
|
||||
* @param {string} type Type of content
|
||||
* @param {'json'|'string'|'raw'} format Format of content
|
||||
* @param {CONTENT_SCOPE} scope Scope of content to get
|
||||
* @returns {string[]|Buffer[]} Array of content
|
||||
*/
|
||||
export function getContentOfType(type, format) {
|
||||
const contentIndex = getContentIndex();
|
||||
export function getContentOfType(type, format, scope = CONTENT_SCOPE.USER) {
|
||||
const contentIndex = getContentIndex(scope);
|
||||
const indexItems = contentIndex.filter((item) => item.type === type && item.folder);
|
||||
const files = [];
|
||||
for (const item of indexItems) {
|
||||
@@ -269,7 +323,7 @@ export function getContentOfType(type, format) {
|
||||
* @param {import('../users.js').UserDirectoryList} directories User directories
|
||||
* @returns {string | null} Target directory
|
||||
*/
|
||||
function getTargetByType(type, directories) {
|
||||
export function getUserTargetByType(type, directories) {
|
||||
switch (type) {
|
||||
case CONTENT_TYPES.SETTINGS:
|
||||
return directories.root;
|
||||
@@ -312,6 +366,22 @@ function getTargetByType(type, directories) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target directory for global content types.
|
||||
* @param {CONTENT_TYPES} type Content type
|
||||
* @returns {string | null} Target directory
|
||||
*/
|
||||
export function getGlobalTargetByType(type) {
|
||||
switch (type) {
|
||||
case CONTENT_TYPES.ERROR_PAGE:
|
||||
return path.join(globalThis.DATA_ROOT, '_errors');
|
||||
case CONTENT_TYPES.STYLESHEET:
|
||||
return path.join(globalThis.DATA_ROOT, '_css');
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content log from the content log file.
|
||||
* @param {string} contentLogPath Path to the content log file
|
||||
|
||||
@@ -270,7 +270,7 @@ router.post('/generate', async function (req, res) {
|
||||
|
||||
if (req.body.streaming) {
|
||||
// Pipe remote SSE stream to Express response
|
||||
forwardFetchResponse(response, res);
|
||||
await forwardFetchResponse(response, res);
|
||||
} else {
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
|
||||
@@ -102,6 +102,10 @@ router.post('/caption-image', async (request, response) => {
|
||||
bodyParams.seed = Math.floor(Math.random() * Math.pow(2, 32));
|
||||
}
|
||||
|
||||
if (request.body.api === 'workers_ai') {
|
||||
key = readSecret(request.user.directories, SECRET_KEYS.WORKERS_AI);
|
||||
}
|
||||
|
||||
const noKeyTypes = ['custom', 'ooba', 'koboldcpp', 'vllm', 'llamacpp'];
|
||||
if (!key && !request.body.reverse_proxy && !noKeyTypes.includes(request.body.api)) {
|
||||
console.warn('No key found for API', request.body.api);
|
||||
@@ -216,6 +220,14 @@ router.post('/caption-image', async (request, response) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (request.body.api === 'workers_ai') {
|
||||
const accountId = String(request.body.workers_ai_account_id || '').trim();
|
||||
if (!accountId) {
|
||||
return response.status(400).send({ error: 'Cloudflare Workers AI Account ID is required' });
|
||||
}
|
||||
apiUrl = `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(accountId)}/ai/v1/chat/completions`;
|
||||
}
|
||||
|
||||
if (['koboldcpp', 'vllm', 'llamacpp', 'ooba'].includes(request.body.api)) {
|
||||
apiUrl = `${trimV1(request.body.server_url)}/v1/chat/completions`;
|
||||
}
|
||||
@@ -570,6 +582,50 @@ router.post('/siliconflow/models/embedding', async (request, response) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/workers-ai/models/embedding', async (request, response) => {
|
||||
try {
|
||||
const key = readSecret(request.user.directories, SECRET_KEYS.WORKERS_AI);
|
||||
|
||||
if (!key) {
|
||||
console.warn('No Workers AI key found');
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const accountId = String(request.body.workers_ai_account_id || '').trim();
|
||||
if (!accountId) {
|
||||
console.warn('No Workers AI account ID found');
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const apiUrl = `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(accountId)}/ai/models/search?task=Text+Embeddings&per_page=100`;
|
||||
const result = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${key}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
const text = await result.text();
|
||||
console.warn('Workers AI embedding models request failed', result.statusText, text);
|
||||
return response.status(500).send(text);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
|
||||
if (!Array.isArray(data?.result)) {
|
||||
console.warn('Workers AI embedding models response invalid', data);
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
|
||||
return response.json(data.result.map(m => ({ ...m, id: m.name })));
|
||||
} catch (error) {
|
||||
console.error('Workers AI embedding models fetch failed', error);
|
||||
response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/generate-image', async (request, response) => {
|
||||
try {
|
||||
const key = readSecret(request.user.directories, SECRET_KEYS.OPENAI);
|
||||
|
||||
@@ -69,6 +69,7 @@ export const SECRET_KEYS = {
|
||||
POLLINATIONS: 'api_key_pollinations',
|
||||
VOLCENGINE_APP_ID: 'volcengine_app_id',
|
||||
VOLCENGINE_ACCESS_KEY: 'volcengine_access_key',
|
||||
WORKERS_AI: 'api_key_workers_ai',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -441,10 +442,11 @@ export function deleteSecret(directories, key) {
|
||||
* Reads a secret from the secrets file
|
||||
* @param {import('../users.js').UserDirectoryList} directories User directories
|
||||
* @param {string} key Secret key
|
||||
* @param {string?} id Secret ID (optional)
|
||||
* @returns {string} Secret value
|
||||
*/
|
||||
export function readSecret(directories, key) {
|
||||
return new SecretManager(directories).readSecret(key, null);
|
||||
export function readSecret(directories, key, id = null) {
|
||||
return new SecretManager(directories).readSecret(key, id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -264,7 +264,7 @@ elevenlabs.post('/synthesize', async (req, res) => {
|
||||
}
|
||||
|
||||
res.set('Content-Type', 'audio/mpeg');
|
||||
forwardFetchResponse(response, res);
|
||||
await forwardFetchResponse(response, res);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
@@ -328,7 +328,7 @@ elevenlabs.post('/history-audio', async (req, res) => {
|
||||
}
|
||||
|
||||
res.set('Content-Type', 'audio/mpeg');
|
||||
forwardFetchResponse(response, res);
|
||||
await forwardFetchResponse(response, res);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
|
||||
@@ -833,8 +833,7 @@ const sdcpp = express.Router();
|
||||
|
||||
sdcpp.post('/ping', async (request, response) => {
|
||||
try {
|
||||
const url = new URL(request.body.url);
|
||||
url.pathname = '/v1/images/generations';
|
||||
const url = new URL(urlJoin(request.body.url, '/v1/images/generations'));
|
||||
|
||||
const result = await fetch(url, { method: 'OPTIONS' });
|
||||
if (!result.ok) {
|
||||
@@ -848,12 +847,29 @@ sdcpp.post('/ping', async (request, response) => {
|
||||
}
|
||||
});
|
||||
|
||||
sdcpp.post('/models', async (request, response) => {
|
||||
try {
|
||||
const url = new URL(urlJoin(request.body.url, '/v1/models'));
|
||||
|
||||
const result = await fetch(url);
|
||||
if (!result.ok) {
|
||||
throw new Error('stable-diffusion.cpp server returned an error.');
|
||||
}
|
||||
|
||||
const data = await result.json();
|
||||
return response.send(data);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
sdcpp.post('/generate', async (request, response) => {
|
||||
try {
|
||||
const url = new URL(request.body.url);
|
||||
url.pathname = '/sdapi/v1/txt2img';
|
||||
const url = new URL(urlJoin(request.body.url, '/sdapi/v1/txt2img'));
|
||||
|
||||
const payload = {
|
||||
model: request.body.model,
|
||||
prompt: request.body.prompt,
|
||||
negative_prompt: request.body.negative_prompt,
|
||||
width: request.body.width,
|
||||
@@ -864,7 +880,9 @@ sdcpp.post('/generate', async (request, response) => {
|
||||
batch_size: request.body.batch_size,
|
||||
sampler_name: request.body.sampler_name,
|
||||
scheduler: request.body.scheduler,
|
||||
clip_skip: request.body.clip_skip,
|
||||
// sd.cpp produces blank images when clip_skip is 1, which is the
|
||||
// default (no skipping). Only send clip_skip when it's > 1.
|
||||
clip_skip: request.body.clip_skip > 1 ? request.body.clip_skip : undefined,
|
||||
};
|
||||
|
||||
for (const [key, value] of Object.entries(payload)) {
|
||||
|
||||
@@ -39,6 +39,7 @@ const SOURCES = [
|
||||
'chutes',
|
||||
'nanogpt',
|
||||
'siliconflow',
|
||||
'workers_ai',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -88,6 +89,8 @@ async function getVector(source, sourceSettings, text, isQuery, directories) {
|
||||
return getOpenAIVector(text, source, directories, sourceSettings.model);
|
||||
case 'siliconflow':
|
||||
return getOpenAIVector(text, source, directories, sourceSettings.model, sourceSettings.urlOverride);
|
||||
case 'workers_ai':
|
||||
return getOpenAIVector(text, source, directories, sourceSettings.model, sourceSettings.urlOverride);
|
||||
}
|
||||
|
||||
throw new Error(`Unknown vector source ${source}`);
|
||||
@@ -162,6 +165,9 @@ async function getBatchVector(source, sourceSettings, texts, isQuery, directorie
|
||||
case 'siliconflow':
|
||||
results.push(...await getOpenAIBatchVector(batch, source, directories, sourceSettings.model, sourceSettings.urlOverride));
|
||||
break;
|
||||
case 'workers_ai':
|
||||
results.push(...await getOpenAIBatchVector(batch, source, directories, sourceSettings.model, sourceSettings.urlOverride));
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown vector source ${source}`);
|
||||
}
|
||||
@@ -260,6 +266,15 @@ function getSourceSettings(source, request) {
|
||||
urlOverride: request.body.siliconflow_endpoint === 'cn'
|
||||
? 'https://api.siliconflow.cn/v1' : null,
|
||||
};
|
||||
case 'workers_ai': {
|
||||
const accountId = String(request.body.workers_ai_account_id || '').trim();
|
||||
return {
|
||||
model: String(request.body.model || '@cf/baai/bge-m3'),
|
||||
urlOverride: accountId
|
||||
? `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(accountId)}/ai/v1`
|
||||
: null,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import ipaddr from 'ipaddr.js';
|
||||
import ipMatching from 'ip-matching';
|
||||
|
||||
const noopMiddleware = (_req, _res, next) => next();
|
||||
/** @deprecated Do not use. A global middleware is provided at the application level. */
|
||||
@@ -50,3 +51,31 @@ export function isFirefox(req) {
|
||||
const userAgent = req.headers['user-agent'] || '';
|
||||
return /firefox/i.test(userAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters and validates IP patterns.
|
||||
* @param {string[]} entries - The list of IP patterns to validate
|
||||
* @param {(entry: string, message: string) => string} formatLog - The function to format the warning message for invalid entries
|
||||
* @returns {string[]} The list of valid IP patterns
|
||||
*/
|
||||
export function filterValidIpPatterns(entries, formatLog) {
|
||||
const validEntries = [];
|
||||
|
||||
if (!Array.isArray(entries)) {
|
||||
return validEntries;
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
try {
|
||||
// This will throw if the entry is not a valid IP or CIDR
|
||||
ipMatching.getMatch(entry);
|
||||
validEntries.push(entry);
|
||||
} catch (e) {
|
||||
if (typeof formatLog === 'function') {
|
||||
console.warn(formatLog(entry, e?.message || 'Unknown error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return validEntries;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* allow access to the endpoint after successful authentication.
|
||||
*/
|
||||
import { Buffer } from 'node:buffer';
|
||||
import path from 'node:path';
|
||||
import storage from 'node-persist';
|
||||
import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';
|
||||
import { getConfigValue, safeReadFileSync } from '../util.js';
|
||||
@@ -11,7 +12,7 @@ const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false, 'boolean')
|
||||
const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false, 'boolean');
|
||||
|
||||
const basicAuthMiddleware = async function (request, response, callback) {
|
||||
const unauthorizedWebpage = safeReadFileSync('./public/error/unauthorized.html') ?? '';
|
||||
const unauthorizedWebpage = safeReadFileSync(path.join(globalThis.DATA_ROOT, '_errors', 'unauthorized.html')) ?? '';
|
||||
const unauthorizedResponse = (res) => {
|
||||
res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');
|
||||
return res.status(401).send(unauthorizedWebpage);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user