Compare commits

...
95 Commits
Author SHA1 Message Date
Wolfsblvt ad29cbda62 docs: route new provider contributions before implementation (#6099)
* docs: route new provider contributions before implementation

* docs: point provider PR authors to integration guide
2026-10-03 00:05:27 +02:00
EmandWolfsblvt bc81b9f7e3 Change API button warning from credit to charge (#6049)
* Change API button warning from credit to charge

Updated the warning message for the test API button to indicate a charge instead of a credit. (you are using tokens to send the message, the provider is not giving you tokens because you sent a test)

* fix: clarify test message usage charges

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-09-23 23:19:13 +02:00
EmandWolfsblvt 8901f28b01 Fix typos in property descriptions in char-data.js (#6054)
* Fix typos in property descriptions in char-data.js

Wether → Whether x6

* docs: correct character description property text

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-09-23 23:16:59 +02:00
Em 9758a6cd5e Fix typo in readme regarding open source status (#6047)
Corrected 'open sourced' to 'open source' for consistency.
2026-09-23 23:08:52 +02:00
Em ca7330f1af Fix typo in comment for tool calls (#6052)
assistent → assistant
2026-09-23 23:08:18 +02:00
Em a1c7f19bac Fix typo in comment (#6053)
posible  →  possible
2026-09-23 23:07:45 +02:00
Wolfsblvt e9860754ad feat: add GPT-6 Sol and Luna, Opus 5.5, and Gemini 3.8 Flash (#6070) 2026-09-23 21:59:01 +02:00
Wolfsblvt 7c39941963 Merge pull request #6038 from SillyTavern/release
Sync npm publishing workflow to staging.
2026-09-14 21:16:18 +02:00
Wolfsblvt 06bde939fb Fix npm release publishing workflow (#6037)
Allow npm releases to be retried from an existing release tag through the trusted publishing workflow, and scope the `allow-directory` workaround to the publish command.
2026-09-14 21:01:34 +02:00
Wolfsblvt 7e8663cd9c Merge pull request #6036 from SillyTavern/staging
1.19.0
2026-09-14 19:55:46 +02:00
Wolfsblvt 61139aa9b6 Update release version number (#6035) 2026-09-14 19:44:18 +02:00
Wolfsblvt 5e8d463ed4 feat: add Claude Fable 5.1 and GPT-6 Astra (#6015) 2026-09-14 19:03:39 +02:00
F.B. c0a417b240 Add image embed for DeepSeek V4 Flash Vision Exp (#5964) (#5996)
Add deepseek-v4-flash-vision-exp to image embed whitelist.
Block image embed in non `user` msg as DS doesn't allow this.
2026-09-07 23:09:17 +02:00
X00LAandClaude Sonnet 5 cc053e8356 Fix CORS proxy forwarding raw zstd-compressed bytes to the client (#6007)
undici (Node's fetch) transparently decompresses gzip, deflate, and br,
but not zstd. When a browser's full Accept-Encoding header is forwarded
as-is to the target origin, a Cloudflare-fronted server may respond
with zstd, and corsProxyMiddleware pipes those still-compressed bytes
straight through — the client receives garbage instead of the expected
body (e.g. "SyntaxError: Unexpected token" when parsing JSON).

Cap the outgoing Accept-Encoding to the encodings undici can actually
decode, so the target always responds with something we can forward
correctly.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-07 23:07:13 +02:00
Siyuan ChenandWolfsblvt d6b244cd25 Fix: Avoid cpSync crash when renaming characters (#6012)
* Fix: Avoid cpSync crash when renaming characters

Add a no-op filter to fs.cpSync during character renaming.

This avoids Node.js's native copyDir fast path, which can terminate
the process on Windows with affected Node.js versions instead of
throwing a catchable filesystem error.

Refs: https://github.com/nodejs/node/issues/63970

* docs: explain character rename copy workaround

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-09-07 23:05:18 +02:00
voodoohop e7c4f8ee98 fix: resolve Pollinations TTS model aliases (#6010) 2026-09-07 23:03:43 +02:00
QiuLGandQiuLG a8f7e0d900 Fix Quick Reply overwrite cancellation (#6005)
Co-authored-by: QiuLG <195722592+QiuLsG@users.noreply.github.com>
2026-09-07 23:00:44 +02:00
saitewasreset 4613abc26e Google AI Studio: Fetch all model pages (#5954)
Paginate the Gemini models endpoint before returning available
generateContent models, and reject incomplete model lists.
2026-09-01 00:58:51 +02:00
Jeremy SchoemakerandWolfsblvt dd326d244f Return a degraded preview instead of dropping a chat whose last line is unparseable (#5969)
* fix: return a degraded preview instead of {} when a chat's last line is unparseable

getChatInfo resolved an empty object when the last line of a chat .jsonl
failed to parse or lacked known fields (truncated write, external edit).
All three consumers (chat list, search, recents) drop entries without a
file_name, so an otherwise intact chat silently disappeared from the UI
while still occupying its name for uniqueness checks (#5940).

Resolve the already-built chatData instead: file_id, file_name, file_size
and mtime-based last_mes are known good from stat(), chat_items comes from
the line count, and mes falls back to the existing placeholder. Matcher
results from the intact lines are preserved for search.

Fixes #5940

* fix: exclude unreadable chat line from message count

Keep degraded previews aligned with the messages that can actually be loaded by excluding both the metadata line and broken trailing line.

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-09-01 00:38:40 +02:00
Zhewen Tan ccd8287833 fix: preserve zero NovelAI Math1 temperature (#5965) 2026-08-31 23:36:06 +02:00
Em 30eaf26a43 Update TavernAI link in README (#5987)
Update TavernAI link in README
2026-08-27 01:33:51 +02:00
PeterGriffin 98af17a8a4 fix(chat): delete associated tool calls with messages (#5949) 2026-08-21 06:35:50 +02:00
primorLee 0a9ba91852 fix: parse boolean values in env migrations (#5950) 2026-08-21 06:33:08 +02:00
Christoph 814734d4af Fix duplicate tool call IDs if provider repeats id, type, name (#5948)
Before this fix, tool call IDs were duplicated repeatedly with streaming requests if the provider repeats the "id" field in each streaming chunk:

```
{
    role: 'tool',
    content: 'content',
    tool_call_id: 'chatcmpl-tool-aa62chatcmpl-tool-aa62chatcmpl-tool-aa62chatcmpl-tool-aa62'
},
```

After this fix:

```
{
    role: 'tool',
    content: 'content',
    tool_call_id: 'chatcmpl-tool-aa62'
},
```

Example of raw streaming chunks received from Fireworks AI exhibiting this behavior of repeating "id", "type", "name":

```json
{
  "id": "chatcmpl-b7de",
  "object": "chat.completion.chunk",
  "created": 1783459695,
  "model": "accounts/fireworks/models/glm-5p2",
  "choices": [
    {
      "index": 0,
      "delta": {
        "tool_calls": [
          {
            "index": 0,
            "id": "chatcmpl-tool-aa62",
            "type": "function",
            "function": {
              "name": "debug_tool",
              "arguments": ""
            },
            "name": null
          }
        ]
      },
      "finish_reason": null,
      "raw_output": null
    }
  ],
  "usage": null
}
{
  "id": "chatcmpl-b7de",
  "object": "chat.completion.chunk",
  "created": 1783459695,
  "model": "accounts/fireworks/models/glm-5p2",
  "choices": [
    {
      "index": 0,
      "delta": {
        "tool_calls": [
          {
            "index": 0,
            "id": "chatcmpl-tool-aa62",
            "type": "function",
            "function": {
              "name": null,
              "arguments": "{\"input\": \""
            },
            "name": null
          }
        ]
      },
      "finish_reason": null,
      "raw_output": null
    }
  ],
  "usage": null
}
{
  "id": "chatcmpl-b7de",
  "object": "chat.completion.chunk",
  "created": 1783459695,
  "model": "accounts/fireworks/models/glm-5p2",
  "choices": [
    {
      "index": 0,
      "delta": {
        "tool_calls": [
          {
            "index": 0,
            "id": "chatcmpl-tool-aa62",
            "type": "function",
            "function": {
              "name": null,
              "arguments": "First"
            },
            "name": null
          }
        ]
      },
      "finish_reason": null,
      "raw_output": null
    }
  ],
  "usage": null
}
```
2026-08-21 06:16:41 +02:00
Christoph 8992872765 Fireworks: Request and process reasoning (#5947)
This change enables reasoning effort selection for the Fireworks provider as documented at https://docs.fireworks.ai/guides/reasoning#using-reasoning_effort.
2026-08-19 23:47:16 +02:00
Christoph 558d72dde2 Fireworks AI: Set session affinity header for improved caching (#5826)
This change adds a chat-specific "x-session-affinity" HTTP header to requests to Fireworks that use the full prompt. Quiet requests like summarization requests that don't use the same prompt prefix are excluded.

This improves prompt caching by
1. Adding a stable "x-session-affinity" header, which Fireworks AI recommends to route requests to the same replica
2. Separating different chats into different sessions
3. Separating main LLM calls from quiet calls which have a completely different prompt prefix

See https://docs.fireworks.ai/guides/prompt-caching.

This uses an HMAC with the cookie secret instead of simply hashing the chat title to avoid leaking chat titles. Session affinity headers may not fall under zero-data retention in Fireworks or could be cached by proxies on the way. Chat titles are tiny, so the HMAC computation is instant.
2026-08-19 23:25:15 +02:00
WolfsblvtandClaude Fable 5 4ad7af3c06 fix: use provider error fields instead of statusText for HTTP 200 errors (#5945)
Providers can return an HTTP 200 response whose body carries an error
object without a message field, or the error as a plain string. The
error message fell back to response.statusText, which is 'OK' for any
200 response, producing the opaque 'Error: OK'. Error messages now fall
back to the error's code or type field, then the string form, and only
use statusText for non-2xx responses where it carries meaning. Applies
to the non-streaming request path and both streaming error toasts.

Fixes #5647

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-19 21:05:04 +02:00
WolfsblvtandClaude Fable 5 bcc42de2e9 Give non-ASCII chat names distinct backup keys and throttles (#5944)
* fix: give non-ASCII chat names distinct backup keys and throttles

Backup filenames replace all non-alphanumeric characters with
underscores, so names such as equal-length CJK ones collapsed to the
same key and shared a single backup quota: busy chats evicted the
backups of unrelated quiet ones. The backup key now appends a short
hash of the raw name whenever the name contains non-ASCII characters,
keeping keys distinct and stable while ASCII names keep their exact
current keys and retention.

The backup throttle was also keyed per user only, so rapid saves in
one chat deferred or swallowed the backup of another chat saved in the
same window. It is now keyed per user and chat.

Fixes #5780

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix: replace stray NUL byte in backup throttle key separator

A literal 0x00 byte slipped into the template string separator, which
made Git treat the whole file as binary.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* chore: reunite backupChat docblock with its function

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-19 20:49:43 +02:00
WolfsblvtandClaude Fable 5 b4e162324b fix: mint a fresh integrity slug for new branches and checkpoints (#5943)
Branches and checkpoints inherited the parent chat's integrity UUID
through the chat_metadata spread in saveChat and saveGroupBookmarkChat,
so every member of a branch family shared one slug and the integrity
guard could not tell them apart. A save aimed at the wrong file within
the family would pass validation. New branches and checkpoints now get
their own slug at creation. Existing files are unaffected.

Fixes #5942

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-19 20:30:01 +02:00
Marcela Petra Ferraz de Novaes 2c61f3be1e fix: never resize avatars option does not work for group chat avatar (#5936)
* Check the never_resize_avatars setting to request or not cropping for group avatars.

* Change max width of thumbnail to 300px so square images are allowed.
2026-08-19 20:17:30 +02:00
48e7d605df fix(expressions): guard against null/undefined default-expression labels (#5938)
* fix(expressions): guard against null/undefined default-expression labels

Classifiers can return a falsy or literal "null"/"undefined" expression
label, and setDefaultEmojiForImage then requested the nonexistent
/img/default-expressions/null.png, producing a 404.

Fall back to DEFAULT_FALLBACK_EXPRESSION (joy) when the label is falsy,
a literal "null"/"undefined", or a custom expression without a default
asset. This is the only place the default-expressions URL is built, so the
guard covers all 404 paths.

Fixes #5863

* fix(expressions): fall back for any label without a default asset

Generalize the guard to a whitelist check against DEFAULT_EXPRESSIONS.
Every entry in that list has a matching default-expressions asset, so
any other label (falsy, literal null/undefined strings, custom
expressions, or unexpected classifier output) falls back to the
default expression instead of requesting a missing image.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-19 20:13:23 +02:00
WolfsblvtandClaude Fable 5 12b4fc50aa tests: set extensions enabled override for discover suite
PR #5571 added an extensionsEnabledFeatureGuard middleware that reads
extensions.enabled via getConfigValue. The test environment has no
config.yaml, so getConfig() exits the process and kills the Jest
worker, failing the extensions-discover suite. Set the env var
override so the guard resolves without touching the config file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-19 20:06:43 +02:00
Yongjie Guan 742d5601be Prevent proxy access keys from triggering password-manager prompts in Chromium-based browsers (#5913)
* fix: prevent proxy keys from triggering password manager

Render reverse proxy credentials as visually masked text fields with password-neutral DOM identifiers while preserving existing settings, preset, and request field names. Align the Azure OpenAI key input and add regression coverage.

* fix: preserve masked secret clipboard protection
2026-08-19 20:05:15 +02:00
4ed1372411 fix: correct malformed multimodal caption request for oobabooga (#5915)
Closes #4448

The 'ooba' special case in the caption-image route split the correctly
structured message (a single user message with a content array
containing text + image_url) into two separate messages, moving
image_url to a top-level property with an empty content array.

oobabooga's own multimodal image handling (modules/image_utils.py)
only looks for images inside content array items with
type: 'image_url', so this transformation caused the image to be
silently dropped, producing hallucinated or "I can't see an image"
captions - even though the request appeared to contain valid image
data.

Removing the special case lets 'ooba' use the same, already-correct
message structure as every other multimodal-capable API.

Verified against a local oobabooga (llama.cpp/GGUF loader) with a
vision-capable GGUF + mmproj pair: before the fix, captions ignored
the attached image; after the fix, captions accurately describe real
photos.

Co-authored-by: bbastex <bbastex@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-17 03:33:13 +02:00
Christoph 86b55c8696 Fireworks: Update model fetching because /v1/models is broken (#5831)
* Fireworks AI: Fetch model list from custom URL

Fireworks provides the model list on a custom URL in a custom format, see https://docs.fireworks.ai/api-reference/list-models. The standard /v1/models endpoint no longer works correctly and returns a wrong list of models:

```
Available models: [
  'accounts/fireworks/models/deepseek-v4-pro',
  'accounts/fireworks/models/flux-1-schnell-fp8',
  'accounts/fireworks/models/glm-5p1',
  'accounts/fireworks/models/glm-5p2',
  'accounts/fireworks/models/gpt-oss-120b',
  'accounts/fireworks/models/kimi-k2p5',
  'accounts/fireworks/models/kimi-k2p6'
]
```

Many new models like Deepseek V4 Pro, Kimi K2.7 Code are missing.

* Fireworks AI: Add "fast" models

Some models have a "fast" variant. The model list endpoint does not return this information, so for now the available fast versions are listed explicitly.

Fast models have the same parameters (max context etc.) as the regular ones. They are only faster and cost more.
2026-08-17 03:30:30 +02:00
Martin TibkeandMartin Tibke 1a7f88861d fix(tags): drop filters for tags with no assigned entities (#5911)
Filter lists only print tags that are assigned to at least one entity, so a
persisted filter on an unassigned tag has no element to toggle. "Clear all
filters" cannot reset it either, since it works by clicking the printed
elements. The result is a character list that stays empty on every app start,
showing only an "N characters hidden" notice with no visible cause.

removeMissingTagFilters() already dropped filters for deleted tags and for
empty open bogus folders (#5225). Generalize that check to any tag without
assigned entities, which covers plain tags as well, and clear the matching
account storage entry so the filter does not come back on the next reload.

Co-authored-by: Martin Tibke <martin@tibke.net>
2026-08-17 03:01:40 +02:00
WolfsblvtandClaude Fable 5 800caeb9e0 fix: skip extension folders without a manifest during discovery (#5934)
A manually deleted extension often leaves a folder husk on disk, for
example when Windows fails to remove locked .git files. The discover
endpoint listed any directory, so the husk kept reporting as an
installed extension: /extension-exists and /extension-state returned
true after a fresh load and the manifest fetch produced a 404 in the
console on every load. Discovery now skips folders without a
manifest.json and logs a warning naming the exact path, and the
client drops any discovered name whose manifest could not be loaded
so state queries cannot report ghost extensions.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 02:47:08 +02:00
f91050136c fix: show full Generic textgen model list in a select (#5897)
Browsers filter datalist suggestions to the current input value, so
Generic OpenAI-compatible text completion looked like a single model
while Chat Custom's select showed the full /v1/models list. Add an
Available Models select (select2 + reconnect) matching other textgen
backends, and keep the optional free-text Model ID field.

Co-authored-by: trahloc <trahloc@proton.me>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-17 02:21:11 +02:00
f199580102 fix: remove GroupId requirement from MiniMax TTS (#5920)
* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension (#5778)

* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension

Added New versions and new Default model

* Add glm-5.2 option to model selection dropdown

* fix: remove GroupId requirement from MiniMax TTS

MiniMax's current API (sk-cp- keys) uses Bearer auth only. GroupId
is a legacy parameter from the pre-2025 API that the current API
tolerates/ignores. Requiring it blocks new users from setting up
MiniMax TTS.

- Backend: drop groupId from required params and URL
- Frontend: remove Group ID input field and all validation checks

Fixes #5909

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Co-authored-by: Samueras <Samueras@jackoedv.de>
Co-authored-by: chen-jiying <chen-jiying@users.noreply.github.com>
2026-08-17 01:36:56 +02:00
eaf2858e43 fix: use exact ArrayBuffer slices for BYAF imports (#5917)
* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension (#5778)

* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension

Added New versions and new Default model

* Add glm-5.2 option to model selection dropdown

* Refactor file reading to use getArrayBufferSlice

* Update util.js

* Update util-pure.test.js

* test: add real-archive regression for BYAF pooled buffer handling

Builds an actual BYAF zip in memory, embeds it at an offset inside a
larger backing buffer to simulate Node's buffer pooling, and proves
through the real parser that the exact ArrayBuffer slice parses
correctly while the raw oversized backing buffer does not.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Co-authored-by: Samueras <Samueras@jackoedv.de>
Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 01:28:15 +02:00
1cfdcd82e1 fix: skip non-image ComfyUI outputs (#5910)
* fix: skip non-image ComfyUI outputs

* test: cover ComfyUI gif fallback and no-output error paths

Extends the skip-non-image regression with the gifs fallback that
animated workflows rely on and the error path when no output node
carries images or gifs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: CaoBochun <caobochun@bytedance.com>
Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 01:19:49 +02:00
7228502f0b Add Claude Opus 5 / Sonnet 5 and Gemini 3.7 Flash / 3.6 Flash / 3.5 Flash-Lite (#5883)
* feature: add Claude Opus 5, Sonnet 5, and Gemini 3.6 Flash / 3.5 Flash-Lite

Enable adaptive thinking and strip rejected sampling/prefill fields so the new models work with Chat Completions and Image Captioning.

* feature: add Gemini 3.7 Flash

Strip rejected sampling/prefill fields and map min thinking to low so the model works with Chat Completions and Image Captioning.

* feat: refresh Claude and Gemini model lists on top of Claude 5 support

Builds on the Claude 5 and Gemini wiring in this branch: removes
retired models from the Claude and Gemini dropdowns and captioning
lists (claude-opus-4-1 verified retired with a live 404; Gemini 2.0
experimental models, 2.5 preview snapshots, and gemini-3-pro-preview
are shut down per Google's model docs), labels deprecated models
without touching option values so saved selections keep working, adds
claude-fable-5 to the captioning list, and moves new-install defaults
to claude-sonnet-5 and gemini-3.7-flash. Claude 5 generation, vision,
web search, and effort mapping verified live against the API; the
trailing-prefill test now uses a plain loop so the tests lint passes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 01:10:28 +02:00
WolfsblvtandClaude Fable 5 4f6977b779 feat: verify GPT-5.6 support and refresh OpenAI model list (#5932)
Verifies Sol, Terra, and Luna live against the API: generation,
vision, effort values (none/low/xhigh), the unlisted gpt-5.6 alias,
and the sampler contract (temperature and top_p are rejected even
with reasoning off, so the strict stripping stays). Removes models
OpenAI has shut down from the model dropdowns, labels announced
deprecations without touching option values, orders groups newest
first, and moves the new-install and captioning defaults off
gpt-4-turbo, which shuts down on October 23, 2026.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 00:37:46 +02:00
6fea520309 Don't do a full chat reload from /addswipe (#5903)
* Don't reload chat from addswipe

* test: add /addswipe regression and harden e2e login helper

Covers both /addswipe modes through the real command pipeline:
swipe data, counters, visible text, and message element identity,
which a full chat reload would break. The login helper now tries
accounts from last to first so password-protected accounts don't
break local e2e runs, and the test waits out fresh-account
onboarding before measuring.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 00:13:30 +02:00
aca0684c0b Fix crash when a chat is deleted during a search/recent scan (#5871)
* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension (#5778)

* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension

Added New versions and new Default model

* Add glm-5.2 option to model selection dropdown

* Fix crash when a chat file is deleted mid-scan

getChatInfo() stats a chat file without handling ENOENT. If the file
is deleted (e.g. from the UI) while a search or the recent-chats list
is scanning the same directory, the stat throws, and since it's inside
new Promise(async (res) => {...}) with no reject wired up, it becomes
an unhandled rejection that kills the whole server process.

This catches ENOENT and resolves with { match: false } instead, same
as the fallback already used elsewhere in this function/its callers
for corrupted or unmatched entries.

* fix: handle all mid-scan chat deletion races in getChatInfo

The stat guard alone left the function unsound: it lived inside an
async promise executor, so a non-ENOENT error became an unhandled
rejection and the promise never settled. A file deleted between the
stat and the stream opening still crashed via an unhandled stream
error, which readline re-emits, and a file truncated to empty mid-scan
hung the request because the close handler never resolved.

getChatInfo now uses plain async/await up to the streaming part,
resolves a no-match sentinel when the file vanishes at either point,
resolves an empty object on truncation, and properly rejects
everything else. Comes with deterministic regression tests for each
race window.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Co-authored-by: Samueras <Samueras@jackoedv.de>
Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-16 23:51:08 +02:00
0x4kgi 54aedc8797 Add/enable low reasoning effort for Deepseek (#5924)
Also mapping min/minimum as low as it makes sense here.
2026-08-16 23:45:06 +02:00
b5cc683074 Update BFL generation and polling endpoints to api.bfl.ai (#5681)
* Fix BFL API endpoint and polling URL handling

* fix: send authentication header when polling BFL results

The bfl.ai API requires the x-key header on the polling request as
well; the retired bfl.ml API tolerated unauthenticated polling. Without
the header every poll returns 403 and generation never completes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-16 23:41:48 +02:00
WolfsblvtandClaude Fable 5 cd2c65c9d4 fix: await chat completion preset application when switching presets (#5930)
Applying a CC preset deferred the actual settings update behind an
unawaitable event continuation, so /preset resolved before the preset
was applied. A connection profile switch runs /api, /preset, /api in
sequence, and the preset's stored chat_completion_source would land
after the final /api check, reverting the source to the previous
provider. Requests then silently went to the wrong endpoint.

The preset application chain is now captured in a promise that
selectPreset awaits, so /preset resolves only when the preset is fully
applied and follow-up commands sequence correctly. The UI dropdown
path is unchanged, and callers that do not await selectPreset keep
the exact previous behavior.

Fixes #5926
Fixes #5147

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-16 23:21:01 +02:00
ed563cb7d8 fix: reject localhost and .localhost domains in /api/search/visit to prevent SSRF bypass (#5749)
* fix: reject localhost and .localhost domains in /api/search/visit to prevent SSRF bypass

The hostname check in /api/search/visit only validated IP addresses using
ipRegex, but did not block 'localhost' or subdomains ending in '.localhost'.
This allowed SSRF bypasses to internal services via localhost URLs.

Changes:
- Add explicit rejection of 'localhost' hostname
- Add rejection of any hostname ending in '.localhost' (RFC 6761 reserved)

Closes GHSA-wm7j-m6jm-8797

* fix: enforce SSRF boundary for /api/search/visit at connection time

The URL string checks only guard the literal input. Hostnames resolving
to private addresses, redirects into internal services, and DNS
rebinding all bypassed them. The visit endpoint now routes its outbound
request through a strict PrivateRequestAgent even when the private
request filter is disabled: the resolved IP is validated at connection
time on every hop and the connection is pinned to the validated IP.
When the private request filter is enabled its configured whitelist
keeps applying, and an enabled request proxy keeps owning routing.
Also rejects bracketed IPv6 literals, which kept their brackets and
slipped past the hostname check.

Fixes GHSA-wm7j-m6jm-8797

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-16 22:56:44 +02:00
WolfsblvtandClaude Fable 5 32e1966757 fix: require confirmation before overwriting chats with unparseable headers (#5928)
An existing non-empty chat file whose first line could not be parsed as a
JSON object passed the integrity check as if it were a legacy chat, so a
save silently replaced the file and only the replacement got backed up.
The check now fails closed for unparseable, truncated, or non-object
headers, routing the client into the existing overwrite confirmation
dialog. A UTF-8 BOM in front of an otherwise valid header is stripped
before parsing. Empty files, valid legacy headers, and force saves behave
as before.

Fixes #5454

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-16 22:23:29 +02:00
Frank Schubert 380e31e8c5 fix: fetch only current prompt from ComfyUI history endpoint (#5790)
The ComfyUI polling loop fetches /history every 100ms to check if the
current prompt has completed. This returns the entire history, which
grows unboundedly. After ~170 generations, the JSON response exceeds
Node.js's 512MB string length limit, crashing the server with:

  RangeError: Invalid string length

Fix by requesting /history/{id} instead, which returns only the single
prompt entry needed. This is a supported ComfyUI API endpoint that
returns the same data structure.
2026-07-12 00:43:10 +02:00
Tony Gies 46bd341ec1 perf(plugins): list plugin dirs without per-entry statSync (#5690)
updatePlugins called fs.statSync on every entry returned by readdirSync
just to test isDirectory(). Pass withFileTypes to readdirSync and filter
on the Dirent type instead. Symlinks are still treated as directories.
2026-07-12 00:31:20 +02:00
Tony Gies aaf12b4925 perf(util): read each file's mtime once when getImages sorts by date (#5689)
The previous date sort read file modification times while comparing
items, which meant stat'ing the same files over and over for one
listing. mtimes are now read once per file before sorting. Files that
disappear during the call (e.g. concurrent deletion) sort to the start
instead of crashing.
2026-07-12 00:25:22 +02:00
DeathStalker471andWolfsblvt c4672e953e chore: Sync NanoGPT providers: UOMI and Wafer (#5707)
* Sync Nanogpt providers again

* Sort providers alphabetically

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-07-12 00:21:37 +02:00
cloak1505 4259eb7220 Sync OpenRouter providers list (#5686) 2026-07-12 00:04:43 +02:00
DragonFSKY 0168803f41 Fix whitespace-only reasoning block controls (#5636)
* Fix whitespace-only reasoning block controls

* Fix duplicate hidden reasoning editor

* Fix hidden reasoning open state cleanup

* Add reasoning message edit regression tests
2026-07-11 23:54:25 +02:00
Wolfsblvt 2463e83966 Fix: remove trailing whitespace from variable macros (#5848)
- Restore root lint compliance for the variable macro registry.
2026-07-11 23:23:19 +02:00
Wolfsblvt 0a1a746bfd Fix: ignore local third-party extensions during linting (#5847)
- Keep root lint focused on core sources.
- Ignore local .windsurf IDE settings.
2026-07-11 23:22:56 +02:00
Jason WuandWolfsblvt 902bd10382 Add Claude Opus 4.8, GPT-5.6 models, and migrate Gemini 3.1 Flash Lite and Gemini image models to stable (#5845)
* feature: support Claude Opus 4.8 model

* feature: support OpenAI GPT 5.6 models

* fix: replace deprecated Gemini preview model with stable gemini-3.1-flash-lite

* Fix GPT-5.6 Chat Completions effort mapping

- Map Maximum reasoning effort to xhigh because max is Responses-only
- Clarify model-specific OpenAI and adaptive Claude effort guidance
- Cover stable Gemini 3.1 Flash-Lite thinking-level routing

Tests:
- npm run test:unit -- --runInBand
- ESLint on all changed JavaScript files

* Fix: migrate Gemini image models to stable IDs

- Replace shut-down Gemini image preview selectors for Google AI and Vertex AI
- Migrate saved chat and caption model settings to the stable replacements
- Enable image generation for the stable model IDs
- Correct the Gemini 3.1 Flash Image context fallback to 128K
- Add regression coverage for stable Gemini 3 image thinking levels

Tests:
- npm run test:unit -- --runInBand
- ESLint on all changed JavaScript files

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-07-11 16:22:04 +02:00
maxime-fleury 29ed34939c Fix translation for 'Persona Description' in French (#5830)
Fix translation in french
2026-07-08 20:34:58 +02:00
Noahandransxd 37943ea4b1 Optimize World Info entry sorting to avoid O(n^2) lookups (#5809)
* Optimize World Info entry sorting to avoid O(n^2) lookups

The comparator in checkWorldInfo called sortedEntries.indexOf() twice per
comparison, making the sort O(n^2 log n). Build an index Map once and use
it for lookups instead. Sort order is unchanged.

* Address review: build index map before sort, use -1 for unknown entries

Move sortedEntriesIndex creation to immediately before the activatedNow
sort so indices match the current sortedEntries array. Use ?? -1 so
externally force-activated (cloned) entries behave like indexOf(-1).

* Skip index map when at most one entry needs sorting

Build sortedEntriesIndex only when activatedNow.size > 1, since the
comparator is not used for zero or one activated entries.

---------

Co-authored-by: ransxd <ransxd@users.noreply.github.com>
2026-07-08 20:21:46 +02:00
Lukas Straub 29e0df4886 Openrouter: Enable logprobs if requested by user (#5804) 2026-07-07 20:24:53 +02:00
6b49e9e7d0 Add claude-fable-5 support to Claude and OpenAI-compatible request builders (#5757)
* Add claude-fable-5 support to Claude and OpenAI-compatible request builders

* Fix: request Fable thinking summaries on auto

- Request summarized adaptive thinking for claude-fable auto effort when reasoning display is enabled

- Preserve existing effort mapping and sampler stripping behavior

Verification:

- node --check src/endpoints/backends/chat-completions.js

- git diff --check

---------

Co-authored-by: TheLonelyDevil9 <TheLonelyDevil9@users.noreply.github.com>
Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-07-07 20:22:32 +02:00
WolfsblvtandSamueras bba96c6fbe Update TTS model from Gemini 2.5 to 3.1 in TTS Extension (#5778) (#5824)
* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension

Added New versions and new Default model

* Add glm-5.2 option to model selection dropdown

Co-authored-by: Samueras <Samueras@jackoedv.de>
2026-07-07 19:52:38 +02:00
Samueras 8172dcd0ee Update TTS model from Gemini 2.5 to 3.1 in TTS Extension (#5778)
* Update TTS model from Gemini 2.5 to 3.1 in TTS Extension

Added New versions and new Default model

* Add glm-5.2 option to model selection dropdown
2026-07-07 19:36:20 +02:00
Samueras 10ae84fb62 Add glm-5.2 to contextMap (#5770)
* Add glm-5.2 to contextMap

Add glm-5.2 to contextMap

* Update contextMap for glm-5.2 max value
2026-07-07 19:29:45 +02:00
RossAscends bf6f0b0c46 Merge pull request #5814 from underscorex86/patch-5
change novelai user information to be called from image.novelai.net
confirmed via Anlatan discord announcement.
2026-07-04 13:51:32 +09:00
underscore_x 3594fe224a change user information to be called from image.novelai.net
"for 3rd party API customers: GET /user/information, GET /user/data, GET /user/subscription should now be called from https://image.novelai.net. The old URL will be non-functional in a couple of hours. The old URL is currently non-functional."

from NAI devs, this change has already been implemented from NAI side, no backward compat.
2026-07-04 05:43:04 +01:00
Tosd 1ca70787f9 Add gemini-3.5-flash to Google AI Studio and Vertex model lists (#5675) 2026-05-20 13:06:50 +03:00
Cohee 691f0ce604 Temporarily comment out allow-remote setting in .npmrc due to npm bug (#5668)
https://github.com/npm/cli/issues/9347
2026-05-19 21:04:48 +03:00
Cohee fe048f6bdc Improve remote tokenizer encode validation (#5665)
* fix: handle unsupported text generation types in encode endpoint

* fix: simplify URL handling in encode endpoint by using trimV1 utility
2026-05-19 00:45:56 +03:00
Blueberry 93bd9e217e Macros: Access array and object elements (#4383) (#5649)
* Macros: Access array items by index (#4383)

* Macros: Access array and object elements (#4383)

* fix spacing

* setvarkey setvarindex

* setglobalvarindex getglobalvarindex
2026-05-19 00:13:47 +03:00
Cohee fd582be5ca Add rate limit to account reset (#5603) 2026-05-18 23:25:50 +03:00
Cohee 3a453d4cfa Enforce stricter npm source restrictions in .npmrc (#5663) 2026-05-18 22:51:39 +03:00
40ca51f4f1 Pollinations: Add API endpoint selection (#5625)
* Split Pollinations into two separate API providers: (Key) and (No Key)

- Replaces the single "Pollinations" source with two distinct entries:
  - "Pollinations (Key)": uses gen.pollinations.ai/v1 with Bearer token auth,
    supports BYOP OAuth flow with app key pk_Gu8Ta8q6QhS67hSg and manual key entry
  - "Pollinations (No Key)": uses text.pollinations.ai/v1, no authentication required
- Renames CHAT_COMPLETION_SOURCES.POLLINATIONS to POLLINATIONS_KEY/POLLINATIONS_NOKEY
  throughout the codebase (constants, endpoints, frontend scripts)
- Adds BYOP authorize button and OAuth callback handler for key-based source
- Updates all data-source attributes, secret key mappings, model selectors,
  tool-calling, reasoning, slash-commands, caption, and SD extension references

https://claude.ai/code/session_01T57Cm84cv2GiSL4DPCccBj

* Fix POLLINATIONS_NOKEY: exempt from API key check, fix placeholder text

- Add POLLINATIONS_NOKEY to the keyless providers exemption in the
  /generate endpoint's API key guard (was hitting the 400 check)
- Remove 'pk_...' from the key input placeholder since pk_ is the
  app key used in the BYOP auth link, not the user's secret key

https://claude.ai/code/session_01T57Cm84cv2GiSL4DPCccBj

* Add Pollinations anonymous/authenticated endpoint selector

Implements reviewer feedback to use a single Pollinations provider with
an endpoint dropdown (similar to Z.AI) rather than two separate sources.

- Add POLLINATIONS_ENDPOINT enum (anonymous / authenticated)
- Anonymous uses text.pollinations.ai/v1, no API key required
- Authenticated uses gen.pollinations.ai/v1, requires sk_... key with BYOP OAuth support
- Key input and BYOP button are hidden when anonymous endpoint is selected
- Backend skips key guard for anonymous requests
- Reasoning effort and JSON schema only sent for authenticated mode
- Connection status check passes for anonymous without a saved key

https://claude.ai/code/session_01T57Cm84cv2GiSL4DPCccBj

* Fix broken Pollinations references after resolving merge conflicts

- Replace POLLINATIONS_KEY/NOKEY in CHAT_COMPLETION_SOURCES with POLLINATIONS
- Fix SECRET_KEYS.POLLINATIONS → SECRET_KEYS.POLLINATIONS_KEY in backend
- Update all chat_completion_sources references in openai.js to use unified POLLINATIONS
- Consolidate duplicate model select/change handlers into single pollinations_model
- Keep backward compat in caption-image handler for pollinations_key/nokey multimodal API
- Fix openai.js inline handler to route pollinations to correct endpoint based on endpoint field

https://claude.ai/code/session_01T57Cm84cv2GiSL4DPCccBj

* Complete Pollinations unification: remove all pollinations_key/nokey splits

- Fix committed merge conflict in openai.js (Wolfsblvt review)
- Replace POLLINATIONS_KEY/NOKEY in chat_completion_source dropdown with single POLLINATIONS option
- Replace pollinations_key,pollinations_nokey in all data-source attributes with pollinations
- Merge duplicate /pollinations_key and /pollinations_nokey multimodal routes into single /pollinations
- Update caption extension: single "Pollinations" option using pollinations_endpoint from oai_settings
- Update slash-commands.js model selector to single pollinations entry
- Clean up caption-image handler (openai.js) to use only 'pollinations' api type
- Pass pollinations_endpoint in caption request body (shared.js)
- Add settings migration: pollinations_key → pollinations, pollinations_nokey → pollinations (anonymous)

https://claude.ai/code/session_01T57Cm84cv2GiSL4DPCccBj

* Address Cohee review: named constants, mock key, revert POLLINATIONS_KEY rename, default to authenticated

- Use POLLINATIONS_ENDPOINT named constants throughout (no magic 'anonymous' strings)
- Use mock key pattern (set key to POLLINATIONS_ENDPOINT.ANONYMOUS value) so no guard exception needed
- Revert POLLINATIONS_KEY rename back to POLLINATIONS in secrets.js files
- Default pollinations_endpoint to AUTHENTICATED so saved keys aren't bypassed
- Remove redundant isPollinationsAnon check from getReasoningEffort() (backend handles it)
- Unify tool-calling.js, caption, shared, stable-diffusion to single POLLINATIONS source

https://claude.ai/code/session_01T57Cm84cv2GiSL4DPCccBj

* Fix ESLint padded-blocks error in BYOP OAuth callback

https://claude.ai/code/session_01T57Cm84cv2GiSL4DPCccBj

* fix: regression in caption API validation

* fix: remove unneeded migration

* fix: remove duplicate keyless check in apiSourceConfig

* fix: regression in extractReasoningFromData

* refactor: simplify UI unhide logic

* fix: remove BYOP flow due to security concerns

* fix: use a string instead of a constant reference for placeholder key

* fix: reconnect when switching endpoints

* feat: support pollinations in /api-url command

* fix: remove endpoint check from image generation (it always uses authenticated)

* fix: default to authenticated

* fix: use a named constant in auto-connect logic

* fix: filter by modality in anon models list

* fix: remove bespoke model loading logic for anon endpoint

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-05-18 22:45:53 +03:00
Wolfsblvt 060f224f28 Add MessageFormatter: a structured hook system for extensions to transform message content pre-DOM (#5652)
* feat(core): add MessageFormatter pipeline for extension message hooks

Introduces a new MessageFormatter singleton class (public/scripts/message-formatter.js)
that allows extensions to transform message text at well-defined stages of the
messageFormatting() pipeline, before the result reaches the DOM.

The pipeline exposes three hook stages (all before DOMPurify sanitization):
- BEFORE_REGEX  -- raw Markdown, before custom regex rules
- AFTER_REGEX   -- plain Markdown, after regex, before showdown conversion
- AFTER_MARKDOWN -- rendered HTML, after showdown, before sanitization (default)

There is intentionally no post-sanitize stage to prevent XSS vectors.

Extensions register hooks via getContext().messageFormatter.addHook(fn, { stage, order }).
Stage and order enums (formatting_stage, hook_order) are re-exported on the
singleton instance itself so extensions need no additional imports beyond getContext().

The formatter also exposes a .format() shim over messageFormatting() for
convenience. messageFormatting() itself gains full JSDoc documentation.

* feat(core): add pipeline documentation to MessageFormatter.format()

Adds detailed JSDoc documentation to the MessageFormatter.format() method
describing the complete 11-step message formatting pipeline, from prompt-bias
stripping through DOMPurify sanitization. Clarifies that all extension hooks
(beforeRegex, afterRegex, afterMarkdown) run before sanitization to ensure
their output is always sanitised.

* feat(core): add async detection and non-string return guards to MessageFormatter

Adds runtime and registration-time safety checks to the MessageFormatter hook system:
- Throws TypeError at registration if an async function is passed to addHook()
- Emits console warning and ignores return value if a hook returns non-string at runtime
- Detects Promise returns and includes helpful hint that hook may be async
- Updates JSDoc to clarify synchronous string return requirement and error conditions

* test(frontend): add comprehensive e2e tests for MessageFormatter

Adds full test coverage for the MessageFormatter singleton class including:
- Module exports validation (formatting_stage, hook_order enums)
- Singleton instance constant re-exports
- Registration validation (rejects non-functions, async functions, unknown stages)
- Hook execution pipeline (stage isolation, order sorting, context freezing)
- Error handling (continues on throw, warns on non-string/Promise returns)
- Stage injection

* refactor(core): rename ch_name parameter to characterName in MessageFormatter

Renames the `ch_name` parameter to `characterName` throughout MessageFormatter for improved code clarity and consistency with modern naming conventions. Updates JSDoc typedef and method signatures.
2026-05-18 21:51:16 +03:00
Wolfsblvt aec9754b31 Fix: Scoped comment macro {{//}}...{{///}} not removing its content (#5643)
* fix: handle scoped comment macro closing tag tokenization edge case

The lexer greedily tokenizes '//' before '/', causing {{///}} to parse as {{// /}} instead of {{/ //}}. Added special case detection in MacroCstWalker to check if the comment macro's first argument starts with '/' and treat it as a closing block. Removed list/strictArgs flags from comment macro definition and added comprehensive e2e tests for scoped comment blocks.

* refactor: DRY, remove unneccessarily duplicated private extractMacroInfo
2026-05-18 21:48:49 +03:00
Wolfsblvt 9f8c3e156a Lorebook "Apply Current Sorting" — Order control, ascending mode, step size, and live validation feedback (#5653)
* feat: enhance world info sorting with ascending/descending modes and animation

- Add autoFocus property to popup inputs with autofocus attribute and tabIndex
- Add slide animation to setInfoBlock/clearInfoBlock with configurable animate option
- Replace simple input prompt with detailed popup for applying current sorting
- Add ascending/descending order toggle for world info entry sorting
- Add configurable step value between order assignments
- Add real-time warning when starting value is below

* fix: improve world info sorting warning to account for step value

- Update warning calculation to consider step size when detecting order collisions
- Add step input parameter to updateWarning function
- Attach input listener to step field for real-time warning updates
- Display more detailed warning message showing the calculated final order value
2026-05-18 20:14:45 +03:00
Wolfsblvt 355598bb30 fix: disable pipe/filter feature to prevent breaking macros with pipe characters in arguments (#5644)
Temporarily commented out Filter.Pipe and Filter.EscapedPipe token handling in MacroLexer to fix issue where pipe characters in argument values (e.g., {{setvar::foo::|bar}}) were incorrectly parsed as filter operators. Added regression tests for pipe handling in argument values and skipped existing output modifier tests until filter flag (>) logic is properly implemented.

Resolves: #5618
2026-05-18 19:56:38 +03:00
mekineerandCohee 45d166ff6a fix(autocomplete): guard MutationObserver against detached textarea (#5660)
When a textarea is removed from the DOM before the autocomplete
clone-positioning logic runs, parentElement is null and
MutationObserver.observe throws. This can happen when extensions
abort generation early (via generate_interceptor) and the textarea
is torn down before autocomplete finishes setup.

Add a null check so the observer is only attached when the parent
still exists.

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-05-18 19:35:36 +03:00
realyxl 69cf5571ba Update outdated readme-zh_cn.md and readme-ja_jp.md (#5659) 2026-05-18 19:33:36 +03:00
加乘 81be2c51a2 Update outdated readme-zh_tw.md (#5639) 2026-05-18 19:32:19 +03:00
DeathStalker471 a900958bef chore: Sync NanoGPT providers: Tensorix, and Xiaomi (#5646)
* Sync NanoGPT providers, Tensorix, and Xiaomi

* fix lint
2026-05-18 19:31:18 +03:00
underscore_x 56061f793c fix mislabelled popup for "Replace existing Quick Reply set" (#5662)
* fix mislabelled popup for "Replace existing Quick Reply Set"

it currently provides a popup asking for confirmation "Replace existing World Info" when user tries to create a new QR Set with an existing name.

Checked that it does not conflict/reuse anything from the actual world info screen.

* capitalisation
2026-05-18 19:30:26 +03:00
FeldherrenandCohee 77ba2c21a5 Add message indicating that the 'Request mode reasoning' checkbox controls whether reasoning is generated at the source, for Deepseek API (#5633)
* Add message indicating that the 'Request mode reasoning' checkbox
controls whether reasoning is generated at the source, for Deepseek API.

* Added zai and moonshot to conditions for showing message indicating reasoning is enabled/disabled by 'request model reasoning' toggle..

* Added new message indicating openrouter's behaviour when 'request model reasoning' setting is disabled.

* fix: grammar

* fix: duplication for openrouter

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-05-13 22:43:37 +03:00
Leandro Jofré 597517730b Feat/New features for character expressions (#5574)
* update: improve fetching of selected default expression
It includes the fallback values #emoji and #none.

* update: allow expression-list to filter custom expressions
It can allow, filter out, or only include custom expressions in the result.

* update: separate getLastExpression from the slash command to use on macros

* feat: register defaultExpression macro
It will fetch the label of the currently selected global fallback expression.

* feat: register lastExpression macro
It will return the last expression used by the selected character.

* feat: register availableExpressions macro
Returns a list of all expressions provided by the Classifier API.

* update: fix macros labels

* update: normalize return label for defaultExpression macro

* Fix - Typos

* Update - Add compatibility with old macro engine

* Fix - Remove redundant structuredClone

* Update - Consider sprite folders to fetch the last expression used

* Update - Improve last message handling when name is provided

* Fix - Update description of getLastCharacterMessage

* Update - Bring back using active character as fallback for groups
Just weighted that if no name is provided, doing fallback to the active character generating prompt is more useful for groups than grabbing the expression used by another character, after randomly removing that prev commit.
2026-05-13 22:35:45 +03:00
44af6bc169 Update persona lore on WI rename (#5637)
* Fix personal lore stale update on rename (#5628)

* Add test for rename persona lore

Co-authored-by: Copilot <copilot@github.com>

* Fix stale update on personal lore rename

Co-authored-by: Copilot <copilot@github.com>

Given the recent work to fix #5610, this is a continuation to fix a
similiar bug in the persona lore.

* Add newline for linter check

---------

Co-authored-by: Copilot <copilot@github.com>

* feat: update links for other personas

---------

Co-authored-by: Unnatural Developer <40277404+unnaturaldeveloper@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
2026-05-13 22:04:03 +03:00
RojikkuandCohee 3913dfffb9 fix(content-manager) parseChubUrl should clean URL before relying on length (#5604)
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-05-13 22:03:26 +03:00
Tantoofaaz777 d08bbb1096 Skip inactive autocomplete repositioning (#5635) 2026-05-13 20:53:50 +03:00
Manthan AwganandCohee b1f5c29921 Refactor custom header and body handling in OpenAI scripts to use substituteParams function for improved parameter substitution. (#5627)
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-05-13 20:43:58 +03:00
Cohee bfff81bbf9 fix: event type in note-position command (#5624) 2026-05-12 00:54:26 +03:00
Unnatural DeveloperandCohee d5b6b7924b Fix stale chat bound lore name after rename (#5610)
* Add test to reproduce chat lore bug

Co-authored-by: Copilot <copilot@github.com>

Given that I wanted to reliably reproduce the bug, I created a playwright Docker container as part of this commit, along with the applicable unit test. The included docker-compose includes an environment variable that is passed for use by the frontend test harness, default to the host that the playwright and the ST instance containers are running on.

* Fix stale chat bound lore name after rename

Co-authored-by: Copilot <copilot@github.com>

Given the function renameWorldInfo and the resulting call to updateWorldInfoLinks, this fix ensures that if the world_info key in the chat_metadata is still set to the old name, it will be updated to the name

Resolves: #5608

* Start to separate test runner from branch

Given the bug fix for #5608 should be separate from the test runner
compose file, this commit removes the file from the branch associated
with the bug fix.

* Fix frontend test setup to check for login page

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

* Make change to eslint configuration

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

Given the updates to the setup of frontend-utils, configure eslint to
recognize browser and jquery specific globals

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-05-12 00:27:11 +03:00
CasualAutopsyandCohee e0c1dbad8f Add expand editor button to CC quick prompts (#5607)
* Add expand editor button to quick prompts

* fix: clean-up html

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-05-12 00:25:37 +03:00
ReithanandCohee 37b3e9e461 fix /tokens command returning inflated count for OpenAI API (#5601)
* fix /tokens command returning inflated count for OpenAI API

* Apply repo owner's patch to improve token counting fix

- Remove artificial 'role: system' wrapper that caused inflated counts
- Initialize token_count to 0 instead of -1
- Simplify web tokenizer to join message content directly
- Maintains caching functionality while fixing the overhead issue

* lint

* Revert to using cached implementation

* lint 2: revenge

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-05-12 00:19:48 +03:00
Wolfsblvt 29a18ce0c6 Refactor getUniqueName utility for allowBaseName option (#5602)
* feat: add allowBaseName option to getUniqueName utility function

* feat: simplify getUniqueName by removing allowBaseName option and changing default startIndex to 0
2026-05-05 22:33:04 +03:00
121 changed files with 5196 additions and 656 deletions
+1
View File
@@ -70,6 +70,7 @@ module.exports = {
'**/dist/**',
'**/.git/**',
'public/lib/**',
'public/scripts/extensions/third-party/**',
'backups/**',
'data/**',
'cache/**',
+6
View File
@@ -1,5 +1,11 @@
<!-- Put X in the box below to confirm -->
<!--
Adding a new named external provider or service?
Read https://docs.sillytavern.app/for-contributors/provider-integrations/
before implementing or submitting it, and link the prior issue when the guide requires one.
-->
## Checklist:
- [ ] I have read the [Contribution guidelines](https://github.com/SillyTavern/SillyTavern/blob/release/CONTRIBUTING.md).
+2 -1
View File
@@ -26,7 +26,7 @@ SillyTavernは、多くのLLM API(KoboldAI/CPP、Horde、NovelAI、Ooba、Tabb
SillyTavern(略してST)は、テキスト生成LLM、画像生成エンジン、TTS音声モデルと対話するための、ローカルにインストールされるユーザーインターフェースです。
2023年2月にTavernAI 1.2.8のフォークとして始まり、SillyTavernは現在200人以上の貢献者と2年間の独立した開発を経て、知識豊富なAI愛好家のための主要なソフトウェアとして機能し続けています。
2023年2月にTavernAI 1.2.8のフォークとして始まり、SillyTavernは現在300人以上の貢献者と3年間の独立した開発を経て、知識豊富なAI愛好家のための主要なソフトウェアとして機能し続けています。
## 私たちのビジョン
@@ -79,6 +79,7 @@ SillyTavern(略してST)は、テキスト生成LLM、画像生成エンジ
* CncAnonのTavernAITurbo modの一部を許可を得て使用
* PepperTacoの作品に触発されたビジュアルノベルモード (<https://github.com/peppertaco/Tavern/>)
* GoogleによるNoto Sansフォント (OFLライセンス)
* Chevrotainによるレキサー/パーサー (Apache-2.0ライセンス) <https://github.com/chevrotain/chevrotain>
* Font Awesomeによるアイコンテーマ <https://fontawesome.com> (アイコン: CC BY 4.0, フォント: SIL OFL 1.1, コード: MITライセンス)
* @OtisAlejandroによるデフォルトコンテンツ(Seraphinaキャラクターと伝承本)と@kallmefloccによる10K Discordユーザー記念背景
* [@mrguymiah](https://github.com/mrguymiah)と[@Bronya-Rand](https://github.com/Bronya-Rand)によるDockerガイド
+2 -1
View File
@@ -26,7 +26,7 @@ SillyTavern 为众多 LLM API(KoboldAI/CPP、Horde、NovelAI、Ooba、Tabby、
SillyTavern(简称 ST)是一个本地安装的用户界面,允许您与文本生成 LLM、图像生成引擎和 TTS 语音模型进行交互。
SillyTavern 于 2023 年 2 月作为 TavernAI 1.2.8 的一个分支开始,如今已拥有超过 200 名贡献者和 2 年的独立开发经验,并继续作为资深 AI 爱好者领先的软件。
SillyTavern 于 2023 年 2 月作为 TavernAI 1.2.8 的一个分支开始,如今已拥有超过 300 名贡献者和 3 年的独立开发经验,并继续作为资深 AI 爱好者领先的软件。
## 我们的愿景
@@ -79,6 +79,7 @@ SillyTavern 于 2023 年 2 月作为 TavernAI 1.2.8 的一个分支开始,如
* CncAnon 的 TavernAITurbo mod 的部分内容经许可使用
* 视觉小说模式的灵感来自 PepperTaco 的工作 (<https://github.com/peppertaco/Tavern/>)
* Noto Sans 字体 by Google (OFL 许可证)
* Lexer/Parser 由 Chevrotain 提供 (Apache-2.0 许可证) <https://github.com/chevrotain/chevrotain>
* 图标主题 by Font Awesome <https://fontawesome.com> (图标: CC BY 4.0, 字体: SIL OFL 1.1, 代码: MIT 许可证)
* 默认内容由 @OtisAlejandro (Seraphina 角色和世界书) 和 @kallmeflocc (10K Discord 用户庆祝背景) 提供
* Docker 指南由 [@mrguymiah](https://github.com/mrguymiah) 和 [@Bronya-Rand](https://github.com/Bronya-Rand) 提供
+3 -2
View File
@@ -26,7 +26,7 @@ SillyTavern 提供一個統一的前端介面,整合多種大型語言模型
SillyTavern(簡稱 ST)是一款本地安裝的使用者介面,讓您能與大型語言模型(LLM)、影像生成引擎以及語音合成模型互動的前端。
SillyTavern 起源於 2023 年 2 月,作為 TavernAI 1.2.8 的分支版本發展至今。目前已有超過 200 位貢獻者,並擁有超過兩年的獨立開發歷史。如今,它已成為 AI 愛好者中備受推崇的軟體之一。
SillyTavern 起源於 2023 年 2 月,作為 TavernAI 1.2.8 的分支版本發展至今。目前已有超過 300 位貢獻者,並擁有超過三年的獨立開發歷史。如今,它已成為 AI 愛好者中備受推崇的軟體之一。
## 我們的願景
@@ -42,7 +42,7 @@ SillyTavern 的硬體需求相當低。任何能夠運行 NodeJS 20 或更高版
### 歡迎加入我們的 Discord 伺服器
| [![][discord-shield-badge]][discord-link] | [加入我們的 Disocrd 伺服器](https://discord.gg/sillytavern) 以獲得技術支援、分享您喜愛的角色與提示詞。 |
| [![][discord-shield-badge]][discord-link] | [加入我們的 Discord 伺服器](https://discord.gg/sillytavern) 以獲得技術支援、分享您喜愛的角色與提示詞。 |
| :---------------------------------------- | :----------------------------------------------------------------------------------------------------------------- |
或直接聯繫開發者:
@@ -79,6 +79,7 @@ SillyTavern 的硬體需求相當低。任何能夠運行 NodeJS 20 或更高版
* 經授權使用部分來自 CncAnon 的 TavernAITurbo 模組
* 視覺小說模式(Visual Novel Mode)的靈感,來源於 PepperTaco 的貢獻(<https://github.com/peppertaco/Tavern/>)
* Noto Sans 字體由 Google 提供(OFL 許可)
* Lexer/Parser 由 Chevrotain 提供 (Apache-2.0 許可) <https://github.com/chevrotain/chevrotain>
* 主題圖示由 Font Awesome <https://fontawesome.com> 提供(圖示:CC BY 4.0,字體:SIL OFL 1.1,程式碼:MIT 許可)
* 預設資源來源於 @OtisAlejandro(包含角色 Seraphina 與知識書)與 @kallmeflocc(SillyTavern 官方 Discord 伺服器成員突破 10K 的慶祝背景)
* Docker 安裝指南由 [@mrguymiah](https://github.com/mrguymiah) 和 [@Bronya-Rand](https://github.com/Bronya-Rand) 編寫
+2 -2
View File
@@ -29,7 +29,7 @@ Beginning in February 2023 as a fork of TavernAI 1.2.8, SillyTavern now has over
1. We aim to empower users with as much utility and control over their LLM prompts as possible. The steep learning curve is part of the fun!
2. We do not provide any online or hosted services, nor programmatically track any user data.
3. SillyTavern is a passion project brought to you by a dedicated community of LLM enthusiasts, and will always be free and open sourced.
3. SillyTavern is a passion project brought to you by a dedicated community of LLM enthusiasts, and will always be free and open source.
## Do I need a powerful PC to run SillyTavern?
@@ -75,7 +75,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.**
* [TavernAI](https://github.com/TavernAI/TavernAI) 1.2.8 by Humi: MIT License
* [TavernAI](https://github.com/TavernAI/TavernAI-v1) 1.2.8 by Humi: MIT License
* Portions of CncAnon's TavernAITurbo mod used with permission
* Visual Novel Mode inspired by the work of PepperTaco (<https://github.com/peppertaco/Tavern/>)
* Noto Sans font by Google (OFL license)
+19 -2
View File
@@ -1,4 +1,4 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# Publish to npm for a new release or explicitly retry an existing release tag.
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Node.js Package
@@ -6,6 +6,16 @@ name: Node.js Package
on:
release:
types: [created]
workflow_dispatch:
inputs:
tag:
description: Existing release tag to publish
required: true
type: string
env:
PUBLISH_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.event.release.tag_name }}
PUBLISH_REF: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.tag) || github.ref }}
permissions:
id-token: write # Required for OIDC
@@ -16,9 +26,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
ref: ${{ env.PUBLISH_REF }}
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3
with:
node-version: 24
- name: Verify release tag matches package version
run: test "$(node -p "require('./package.json').version")" = "$PUBLISH_TAG"
- run: npm ci --omit=dev --ignore-scripts
publish-npm:
@@ -26,9 +40,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
ref: ${{ env.PUBLISH_REF }}
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3
with:
node-version: 24
registry-url: https://registry.npmjs.org/
- run: npm ci --omit=dev --ignore-scripts
- run: npm publish
# https://github.com/npm/cli/issues/9755
- run: npm publish --allow-directory=all
+1
View File
@@ -34,6 +34,7 @@ whitelist.txt
.vscode/**
!.vscode/extensions.json
.idea/
.windsurf/
secrets.json
/dist
/backups/
+6
View File
@@ -1,2 +1,8 @@
ignore-scripts=true
min-release-age=7
allow-directory=none
allow-file=none
allow-git=none
# Temporarily disabled due to an npm bug:
# https://github.com/npm/cli/issues/9347
# allow-remote=none
+13 -2
View File
@@ -62,6 +62,16 @@ Write at least somewhat meaningful PR descriptions and commit messages. There's
- What did you do to achieve this?
- How would a reviewer test the change?
### Discuss new provider integrations before implementing them
Do not use a completed pull request as the first product discussion for a new named external provider or service.
- Model routers, resellers, rerouters, gateways, and aggregators should use **Custom (OpenAI-compatible)** and publish provider-owned setup instructions. Provider-specific convenience may be implemented as a third-party UI extension or server plugin.
- New first-party model, TTS, speech, web search, image, vectorization, embedding, reranking, and similar integrations are exceptional and should begin with a public issue and maintainer discussion before implementation.
- Existing-provider maintenance and provider-neutral improvements to generic compatibility remain welcome.
Read [Integrating an External Provider](https://docs.sillytavern.app/for-contributors/provider-integrations/) before starting implementation.
### We (likely) don't speak your language
English is the primary language of communication in this project. Please use only English when writing commit messages, PR descriptions, comments and other text. This does not apply to contributions to localization files.
@@ -81,5 +91,6 @@ We do not prohibit nor encourage the use of AI tools for coding assistance to he
## Further reading
1. [How to write UI extensions](https://docs.sillytavern.app/for-contributors/writing-extensions/)
2. [How to write server plugins](https://docs.sillytavern.app/for-contributors/server-plugins)
1. [How to integrate an external provider](https://docs.sillytavern.app/for-contributors/provider-integrations/)
2. [How to write UI extensions](https://docs.sillytavern.app/for-contributors/writing-extensions/)
3. [How to write server plugins](https://docs.sillytavern.app/for-contributors/server-plugins)
+2
View File
@@ -198,6 +198,8 @@ rateLimiting:
accountsLoginMaxAttempts: 5
# Set the maximum number of allowed failed account recovery attempts before rate limiting is applied. Set to 0 to disable rate limiting for account recovery.
accountsRecoverMaxAttempts: 5
# Set the maximum number of allowed failed account reset attempts before rate limiting is applied. Set to 0 to disable rate limiting for account resets.
accountsResetMaxAttempts: 5
# Set to true to enable support for real IPs in certain request headers for features like IP whitelisting, rate limiting and access logging.
# Only change if you are sure that you use a correctly configured reverse proxy, otherwise this may lead to IP spoofing.
forwardedHeaders:
+4 -4
View File
@@ -1,7 +1,7 @@
{
"chat_completion_source": "openai",
"openai_model": "gpt-4-turbo",
"claude_model": "claude-sonnet-4-5",
"openai_model": "gpt-5.6-terra",
"claude_model": "claude-sonnet-5",
"openrouter_model": "OR_Website",
"openrouter_use_fallback": false,
"openrouter_group_models": false,
@@ -20,8 +20,8 @@
"custom_include_body": "",
"custom_exclude_body": "",
"custom_include_headers": "",
"google_model": "gemini-2.5-pro",
"vertexai_model": "gemini-2.5-pro",
"google_model": "gemini-3.7-flash",
"vertexai_model": "gemini-3.7-flash",
"temperature": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
+1 -1
View File
@@ -622,7 +622,7 @@
},
"wi_format": "{0}",
"openai_model": "gpt-4-turbo",
"claude_model": "claude-sonnet-4-5",
"claude_model": "claude-sonnet-5",
"ai21_model": "jamba-large",
"openrouter_model": "OR_Website",
"reverse_proxy": "",
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "sillytavern",
"version": "1.18.0",
"version": "1.19.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sillytavern",
"version": "1.18.0",
"version": "1.19.0",
"license": "AGPL-3.0",
"dependencies": {
"@adobe/css-tools": "^4.4.4",
+1 -1
View File
@@ -115,7 +115,7 @@
"type": "git",
"url": "https://github.com/SillyTavern/SillyTavern.git"
},
"version": "1.18.0",
"version": "1.19.0",
"scripts": {
"init": "node src/server-init.js",
"start": "node server.js",
+4 -3
View File
@@ -39,9 +39,10 @@ if (command === 'install') {
}
async function updatePlugins() {
const directories = fs.readdirSync(pluginsPath)
.filter(file => !file.startsWith('.'))
.filter(file => fs.statSync(path.join(pluginsPath, file)).isDirectory());
const directories = fs.readdirSync(pluginsPath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory() || dirent.isSymbolicLink())
.filter(dirent => !dirent.name.startsWith('.'))
.map(dirent => dirent.name);
console.log(`Found ${color.cyan(directories.length)} directories in ./plugins`);
+148 -125
View File
@@ -809,18 +809,21 @@
<div class="inline-drawer-content">
<div class="range-block m-t-1">
<div class="justifyLeft" data-i18n="Main">Main</div>
<i class="editor_maximize fa-solid fa-maximize right_menu_button" data-for="main_prompt_quick_edit_textarea" data-i18n="[title]Expand the editor"></i>
<div class="wide100p">
<textarea id="main_prompt_quick_edit_textarea" class="text_pole textarea_compact autoSetHeight" rows="6" placeholder="&mdash;" data-pm-prompt="main"></textarea>
</div>
</div>
<div class="range-block m-t-1">
<div class="justifyLeft" data-i18n="Auxiliary">Auxiliary</div>
<i class="editor_maximize fa-solid fa-maximize right_menu_button" data-for="nsfw_prompt_quick_edit_textarea" data-i18n="[title]Expand the editor"></i>
<div class="wide100p">
<textarea id="nsfw_prompt_quick_edit_textarea" class="text_pole textarea_compact autoSetHeight" rows="6" placeholder="&mdash;" data-pm-prompt="nsfw"></textarea>
</div>
</div>
<div class="range-block m-t-1">
<div class="justifyLeft" data-i18n="Post-History Instructions">Post-History Instructions</div>
<i class="editor_maximize fa-solid fa-maximize right_menu_button" data-for="jailbreak_prompt_quick_edit_textarea" data-i18n="[title]Expand the editor"></i>
<div class="wide100p">
<textarea id="jailbreak_prompt_quick_edit_textarea" class="text_pole textarea_compact autoSetHeight" rows="6" placeholder="&mdash;" data-pm-prompt="jailbreak"></textarea>
</div>
@@ -2144,12 +2147,15 @@
<span data-i18n="Allows the model to return its thinking process.">
Allows the model to return its thinking process.
</span>
<strong data-i18n="This setting enables or disables reasoning generation by the model." data-source="deepseek,zai,moonshot">
This setting enables or disables reasoning generation by the model.
</strong>
<strong data-i18n="This setting affects visibility only." data-source-mode="except" data-source="zai,moonshot,openrouter,deepseek">
This setting affects visibility only.
</strong>
</div>
</div>
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,claude,xai,makersuite,vertexai,aimlapi,openrouter,pollinations,perplexity,cometapi,electronhub,azure_openai,chutes,nanogpt,deepseek">
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,claude,xai,makersuite,vertexai,aimlapi,openrouter,pollinations,perplexity,cometapi,electronhub,azure_openai,chutes,nanogpt,deepseek,fireworks">
<div class="flex-container oneline-dropdown" title="Constrains effort on reasoning for reasoning models.&#10;Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response." data-i18n="[title]Constrains effort on reasoning for reasoning models.">
<label for="openai_reasoning_effort">
<span data-i18n="Reasoning Effort">Reasoning Effort</span>
@@ -2163,14 +2169,17 @@
<option data-i18n="openai_reasoning_effort_high" value="high">High</option>
<option data-i18n="openai_reasoning_effort_maximum" value="max">Maximum</option>
</select>
<div class="toggle-description justifyLeft marginBot5" data-source="openai,custom,xai,aimlapi,openrouter,pollinations,perplexity,cometapi,electronhub,azure_openai,chutes" data-i18n="OpenAI-style options: low, medium, high. Minimum and maximum are aliased to low and high. Auto does not send an effort level.">
OpenAI-style options: low, medium, high. Minimum and maximum are aliased to low and high. Auto does not send an effort level.
<div class="toggle-description justifyLeft marginBot5" data-source="openai,custom,xai,aimlapi,openrouter,pollinations,perplexity,cometapi,electronhub,azure_openai,chutes" data-i18n="OpenAI-compatible effort levels vary by model. Minimum and maximum may use model-specific aliases. Auto does not send an effort level.">
OpenAI-compatible effort levels vary by model. Minimum and maximum may use model-specific aliases. Auto does not send an effort level.
</div>
<div class="toggle-description justifyLeft marginBot5" data-source="fireworks" data-i18n="Fireworks supports low, medium, high, and max as distinct effort levels. Minimum is aliased to low. Auto does not send an effort level.">
Fireworks supports low, medium, high, and max as distinct effort levels. Minimum is aliased to low. Auto does not send an effort level.
</div>
<strong class="toggle-description justifyLeft marginBot5" data-source="openrouter">
Request model reasoning = Off with Reasoning Effort = Minimum disables reasoning entirely on models that support that, but can cause errors with some models.
</strong>
<div class="toggle-description justifyLeft marginBot5" data-source="claude" data-i18n="Allocates a portion of the response length for thinking (min: 1024 tokens, low: 10%, medium: 25%, high: 50%, max: 95%), but minimum 1024 tokens. Auto does not request thinking.">
Allocates a portion of the response length for thinking (min: 1024 tokens, low: 10%, medium: 25%, high: 50%, max: 95%), but minimum 1024 tokens. Auto does not request thinking.
<div class="toggle-description justifyLeft marginBot5" data-source="claude" data-i18n="Selects an effort level on adaptive-thinking models. On older Claude models, it allocates a portion of the response length to thinking. Auto does not request thinking.">
Selects an effort level on adaptive-thinking models. On older Claude models, it allocates a portion of the response length to thinking. Auto does not request thinking.
</div>
<div class="toggle-description justifyLeft marginBot5" data-source="makersuite,vertexai">
<span data-i18n="Sets a dynamic reasoning depth level for thinking (Flash 3/Pro 3). High and low are supported by both, minimal and medium are Flash 3 only. Auto lets the model decide.">
@@ -2198,7 +2207,7 @@
Constrains the verbosity of the model's response.
</div>
<strong class="toggle-description justifyLeft marginBot5" data-source="claude">
On Opus 4.6 / Sonnet 4.6, a non-automatic Reasoning Effort takes precedence over Verbosity.
On adaptive-thinking Claude models, a non-automatic Reasoning Effort takes precedence over Verbosity.
</strong>
</div>
</div>
@@ -2587,8 +2596,19 @@
<small data-i18n="Example: http://127.0.0.1:5000">Example: http://127.0.0.1:5000</small>
<input id="generic_api_url_text" name="generic_api_url" class="text_pole wide100p" value="" autocomplete="off" data-server-history="generic">
</div>
<datalist id="generic_model_fill"></datalist>
<input id="generic_model_textgenerationwebui" list="generic_model_fill" class="text_pole wide100p" placeholder="Model ID (optional)" data-i18n="[placeholder]Model ID (optional)" type="text">
<h4 data-i18n="Enter a Model ID">Enter a Model ID</h4>
<div class="flex-container">
<input list="generic_model_fill" id="generic_model_textgenerationwebui" class="text_pole wide100p" placeholder="Model ID (optional)" data-i18n="[placeholder]Model ID (optional)" type="text" autocomplete="off">
<datalist id="generic_model_fill"></datalist>
</div>
<h4 data-i18n="Available Models">Available Models</h4>
<div class="flex-container">
<select id="generic_model_select" class="text_pole wide100p">
<option value="" data-i18n="-- Connect to the API --">
-- Connect to the API --
</option>
</select>
</div>
</div>
<div data-tg-type="ooba" class="flex-container flexFlowColumn">
<div class="flex-container flexFlowColumn">
@@ -2991,8 +3011,8 @@
<br>
</div>
<div class="flex-container width100p">
<input id="openai_proxy_password" type="password" class="text_pole flex1" placeholder="" form="openai_form" autocomplete="off" />
<div id="openai_proxy_password_show" title="Peek a password" data-i18n="[title]Peek a password" class="menu_button fa-solid fa-eye-slash fa-fw"></div>
<input id="openai_proxy_access_key" type="text" class="text_pole flex1 masked-secret" placeholder="" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false" />
<div id="openai_proxy_access_key_show" title="Peek a password" data-i18n="[title]Peek a password" class="menu_button fa-solid fa-eye-slash fa-fw"></div>
</div>
</div>
</div>
@@ -3046,6 +3066,17 @@
<div>
<h4 data-i18n="OpenAI Model">OpenAI Model</h4>
<select id="model_openai_select">
<optgroup label="GPT-6">
<option value="gpt-6-astra">gpt-6-astra</option>
<option value="gpt-6-sol">gpt-6-sol</option>
<option value="gpt-6-luna">gpt-6-luna</option>
</optgroup>
<optgroup label="GPT-5.6">
<option value="gpt-5.6">gpt-5.6</option>
<option value="gpt-5.6-sol">gpt-5.6-sol</option>
<option value="gpt-5.6-terra">gpt-5.6-terra</option>
<option value="gpt-5.6-luna">gpt-5.6-luna</option>
</optgroup>
<optgroup label="GPT-5.5">
<option value="gpt-5.5">gpt-5.5</option>
<option value="gpt-5.5-2026-04-23">gpt-5.5-2026-04-23</option>
@@ -3059,87 +3090,74 @@
<option value="gpt-5.4-nano-2026-03-17">gpt-5.4-nano-2026-03-17</option>
</optgroup>
<optgroup label="GPT-5.3">
<option value="gpt-5.3-chat-latest">gpt-5.3-chat-latest</option>
<option value="gpt-5.3-chat-latest">gpt-5.3-chat-latest (deprecated)</option>
</optgroup>
<optgroup label="GPT-5.2">
<option value="gpt-5.2">gpt-5.2</option>
<option value="gpt-5.2-2025-12-11">gpt-5.2-2025-12-11</option>
<option value="gpt-5.2-chat-latest">gpt-5.2-chat-latest</option>
<option value="gpt-5.2-chat-latest">gpt-5.2-chat-latest (deprecated)</option>
</optgroup>
<optgroup label="GPT-5.1">
<option value="gpt-5.1">gpt-5.1</option>
<option value="gpt-5.1-2025-11-13">gpt-5.1-2025-11-13</option>
<option value="gpt-5.1-chat-latest">gpt-5.1-chat-latest</option>
<option value="gpt-5.1-chat-latest">gpt-5.1-chat-latest (deprecated)</option>
</optgroup>
<optgroup label="GPT-5">
<option value="gpt-5">gpt-5</option>
<option value="gpt-5-2025-08-07">gpt-5-2025-08-07</option>
<option value="gpt-5-chat-latest">gpt-5-chat-latest</option>
<option value="gpt-5-2025-08-07">gpt-5-2025-08-07 (deprecated)</option>
<option value="gpt-5-chat-latest">gpt-5-chat-latest (deprecated)</option>
<option value="gpt-5-mini">gpt-5-mini</option>
<option value="gpt-5-mini-2025-08-07">gpt-5-mini-2025-08-07</option>
<option value="gpt-5-mini-2025-08-07">gpt-5-mini-2025-08-07 (deprecated)</option>
<option value="gpt-5-nano">gpt-5-nano</option>
<option value="gpt-5-nano-2025-08-07">gpt-5-nano-2025-08-07</option>
</optgroup>
<optgroup label="GPT-4o">
<option value="gpt-4o">gpt-4o</option>
<option value="gpt-4o-2024-11-20">gpt-4o-2024-11-20</option>
<option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option>
<option value="gpt-4o-2024-05-13">gpt-4o-2024-05-13</option>
<option value="chatgpt-4o-latest">chatgpt-4o-latest</option>
</optgroup>
<optgroup label="GPT-4o mini">
<option value="gpt-4o-mini">gpt-4o-mini</option>
<option value="gpt-4o-mini-2024-07-18">gpt-4o-mini-2024-07-18</option>
<option value="gpt-5-nano-2025-08-07">gpt-5-nano-2025-08-07 (deprecated)</option>
</optgroup>
<optgroup label="GPT-4.1">
<option value="gpt-4.1">gpt-4.1</option>
<option value="gpt-4.1-2025-04-14">gpt-4.1-2025-04-14</option>
<option value="gpt-4.1-mini">gpt-4.1-mini</option>
<option value="gpt-4.1-mini-2025-04-14">gpt-4.1-mini-2025-04-14</option>
<option value="gpt-4.1-nano">gpt-4.1-nano</option>
<option value="gpt-4.1-nano-2025-04-14">gpt-4.1-nano-2025-04-14</option>
<option value="gpt-4.1-nano">gpt-4.1-nano (deprecated)</option>
<option value="gpt-4.1-nano-2025-04-14">gpt-4.1-nano-2025-04-14 (deprecated)</option>
</optgroup>
<optgroup label="o1">
<option value="o1">o1</option>
<option value="o1-2024-12-17">o1-2024-12-17</option>
<option value="o1-mini">o1-mini</option>
<option value="o1-mini-2024-09-12">o1-mini-2024-09-12</option>
<option value="o1-preview">o1-preview</option>
<option value="o1-preview-2024-09-12">o1-preview-2024-09-12</option>
<optgroup label="o4">
<option value="o4-mini">o4-mini (deprecated)</option>
<option value="o4-mini-2025-04-16">o4-mini-2025-04-16 (deprecated)</option>
</optgroup>
<optgroup label="o3">
<option value="o3">o3</option>
<option value="o3-2025-04-16">o3-2025-04-16</option>
<option value="o3-mini">o3-mini</option>
<option value="o3-mini-2025-01-31">o3-mini-2025-01-31</option>
<option value="o3-2025-04-16">o3-2025-04-16 (deprecated)</option>
<option value="o3-mini">o3-mini (deprecated)</option>
<option value="o3-mini-2025-01-31">o3-mini-2025-01-31 (deprecated)</option>
</optgroup>
<optgroup label="o4">
<option value="o4-mini">o4-mini</option>
<option value="o4-mini-2025-04-16">o4-mini-2025-04-16</option>
<optgroup label="o1">
<option value="o1">o1 (deprecated)</option>
<option value="o1-2024-12-17">o1-2024-12-17 (deprecated)</option>
</optgroup>
<optgroup label="GPT-4.5">
<option value="gpt-4.5-preview">gpt-4.5-preview</option>
<option value="gpt-4.5-preview-2025-02-27">gpt-4.5-preview-2025-02-27</option>
<optgroup label="GPT-4o">
<option value="gpt-4o">gpt-4o</option>
<option value="gpt-4o-2024-11-20">gpt-4o-2024-11-20</option>
<option value="gpt-4o-2024-08-06">gpt-4o-2024-08-06</option>
<option value="gpt-4o-2024-05-13">gpt-4o-2024-05-13</option>
</optgroup>
<optgroup label="GPT-4o mini">
<option value="gpt-4o-mini">gpt-4o-mini</option>
<option value="gpt-4o-mini-2024-07-18">gpt-4o-mini-2024-07-18</option>
</optgroup>
<optgroup label="GPT-4 Turbo and GPT-4">
<option value="gpt-4-turbo">gpt-4-turbo</option>
<option value="gpt-4-turbo-2024-04-09">gpt-4-turbo-2024-04-09</option>
<option value="gpt-4-turbo-preview">gpt-4-turbo-preview</option>
<option value="gpt-4-0125-preview">gpt-4-0125-preview (2024)</option>
<option value="gpt-4-1106-preview">gpt-4-1106-preview (2023)</option>
<option value="gpt-4">gpt-4</option>
<option value="gpt-4-0613">gpt-4-0613 (2023)</option>
<option value="gpt-4-0314">gpt-4-0314 (2023)</option>
<option value="gpt-4-turbo">gpt-4-turbo (deprecated)</option>
<option value="gpt-4-turbo-2024-04-09">gpt-4-turbo-2024-04-09 (deprecated)</option>
<option value="gpt-4">gpt-4 (deprecated)</option>
<option value="gpt-4-0613">gpt-4-0613 (2023, deprecated)</option>
</optgroup>
<optgroup label="GPT-3.5 Turbo">
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>
<option value="gpt-3.5-turbo-0125">gpt-3.5-turbo-0125 (2024)</option>
<option value="gpt-3.5-turbo-1106">gpt-3.5-turbo-1106 (2023)</option>
<option value="gpt-3.5-turbo-instruct">gpt-3.5-turbo-instruct</option>
<option value="gpt-3.5-turbo">gpt-3.5-turbo (deprecated)</option>
<option value="gpt-3.5-turbo-0125">gpt-3.5-turbo-0125 (2024, deprecated)</option>
<option value="gpt-3.5-turbo-1106">gpt-3.5-turbo-1106 (2023, deprecated)</option>
<option value="gpt-3.5-turbo-instruct">gpt-3.5-turbo-instruct (deprecated)</option>
</optgroup>
<optgroup label="Other">
<option value="babbage-002">babbage-002</option>
<option value="davinci-002">davinci-002</option>
<option value="babbage-002">babbage-002 (deprecated)</option>
<option value="davinci-002">davinci-002 (deprecated)</option>
</optgroup>
<optgroup id="openai_external_category" label="External">
</optgroup>
@@ -3170,6 +3188,12 @@
<h4 data-i18n="Claude Model">Claude Model</h4>
<select id="model_claude_select">
<optgroup label="Versions">
<option value="claude-fable-5-1">claude-fable-5-1</option>
<option value="claude-fable-5">claude-fable-5</option>
<option value="claude-opus-5-5">claude-opus-5-5</option>
<option value="claude-opus-5">claude-opus-5</option>
<option value="claude-sonnet-5">claude-sonnet-5</option>
<option value="claude-opus-4-8">claude-opus-4-8</option>
<option value="claude-opus-4-7">claude-opus-4-7</option>
<option value="claude-opus-4-6">claude-opus-4-6</option>
<option value="claude-opus-4-5">claude-opus-4-5</option>
@@ -3179,21 +3203,10 @@
<option value="claude-sonnet-4-5-20250929">claude-sonnet-4-5-20250929</option>
<option value="claude-haiku-4-5">claude-haiku-4-5</option>
<option value="claude-haiku-4-5-20251001">claude-haiku-4-5-20251001</option>
<option value="claude-opus-4-1">claude-opus-4-1</option>
<option value="claude-opus-4-1-20250805">claude-opus-4-1-20250805</option>
<option value="claude-opus-4-0">claude-opus-4-0</option>
<option value="claude-opus-4-20250514">claude-opus-4-20250514</option>
<option value="claude-sonnet-4-0">claude-sonnet-4-0</option>
<option value="claude-sonnet-4-20250514">claude-sonnet-4-20250514</option>
<option value="claude-3-7-sonnet-latest">claude-3-7-sonnet-latest</option>
<option value="claude-3-7-sonnet-20250219">claude-3-7-sonnet-20250219</option>
<option value="claude-3-5-sonnet-latest">claude-3-5-sonnet-latest</option>
<option value="claude-3-5-sonnet-20241022">claude-3-5-sonnet-20241022</option>
<option value="claude-3-5-sonnet-20240620">claude-3-5-sonnet-20240620</option>
<option value="claude-3-5-haiku-latest">claude-3-5-haiku-latest</option>
<option value="claude-3-5-haiku-20241022">claude-3-5-haiku-20241022</option>
<option value="claude-3-opus-20240229">claude-3-opus-20240229</option>
<option value="claude-3-haiku-20240307">claude-3-haiku-20240307</option>
<option value="claude-opus-4-0">claude-opus-4-0 (deprecated)</option>
<option value="claude-opus-4-20250514">claude-opus-4-20250514 (deprecated)</option>
<option value="claude-sonnet-4-0">claude-sonnet-4-0 (deprecated)</option>
<option value="claude-sonnet-4-20250514">claude-sonnet-4-20250514 (deprecated)</option>
</optgroup>
</select>
</div>
@@ -3301,46 +3314,39 @@
<div>
<h4 data-i18n="Google Model">Google Model</h4>
<select id="model_google_select">
<optgroup label="Gemini 3.8">
<option value="gemini-3.8-flash">gemini-3.8-flash</option>
</optgroup>
<optgroup label="Gemini 3.7">
<option value="gemini-3.7-flash">gemini-3.7-flash</option>
</optgroup>
<optgroup label="Gemini 3.6">
<option value="gemini-3.6-flash">gemini-3.6-flash</option>
</optgroup>
<optgroup label="Gemini 3.5">
<option value="gemini-3.5-flash">gemini-3.5-flash</option>
<option value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
</optgroup>
<optgroup label="Gemini 3.1">
<option value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
<option value="gemini-3.1-flash-lite-preview">gemini-3.1-flash-lite-preview</option>
<option value="gemini-3.1-flash-image-preview">gemini-3.1-flash-image-preview</option>
<option value="gemini-3.1-flash-lite">gemini-3.1-flash-lite</option>
<option value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
</optgroup>
<optgroup label="Gemini 3.0">
<option value="gemini-3-pro-preview">gemini-3-pro-preview</option>
<option value="gemini-3-pro-image-preview">gemini-3-pro-image-preview</option>
<option value="gemini-3-pro-image">gemini-3-pro-image</option>
<option value="gemini-3-flash-preview">gemini-3-flash-preview</option>
</optgroup>
<optgroup label="Gemini 2.5">
<option value="gemini-2.5-pro">gemini-2.5-pro</option>
<option value="gemini-2.5-pro-preview-06-05">gemini-2.5-pro-preview-06-05</option>
<option value="gemini-2.5-pro-preview-05-06">gemini-2.5-pro-preview-05-06</option>
<option value="gemini-2.5-pro-preview-03-25">gemini-2.5-pro-preview-03-25</option>
<option value="gemini-2.5-flash">gemini-2.5-flash</option>
<option value="gemini-2.5-flash-preview-09-2025">gemini-2.5-flash-preview-09-2025</option>
<option value="gemini-2.5-flash-preview-05-20">gemini-2.5-flash-preview-05-20</option>
<option value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
<option value="gemini-2.5-flash-lite-preview-09-2025">gemini-2.5-flash-lite-preview-09-2025</option>
<option value="gemini-2.5-flash-lite-preview-06-17">gemini-2.5-flash-lite-preview-06-17</option>
<option value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
<option value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
</optgroup>
<optgroup label="Gemini 2.0">
<option value="gemini-2.0-pro-exp-02-05">gemini-2.0-pro-exp-02-05 → 2.5-exp-03-25</option>
<option value="gemini-2.0-pro-exp">gemini-2.0-pro-exp → 2.5-exp-03-25</option>
<option value="gemini-exp-1206">gemini-exp-1206 → 2.5-exp-03-25</option>
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
<option value="gemini-2.0-flash-exp-image-generation">gemini-2.0-flash-exp-image-generation</option>
<option value="gemini-2.0-flash-preview-image-generation">gemini-2.0-flash-preview-image-generation</option>
<option value="gemini-2.0-flash-exp">gemini-2.0-flash-exp</option>
<option value="gemini-2.0-flash">gemini-2.0-flash</option>
<option value="gemini-2.0-flash-thinking-exp-01-21">gemini-2.0-flash-thinking-exp-01-21 → 2.5-flash-preview-05-20</option>
<option value="gemini-2.0-flash-thinking-exp-1219">gemini-2.0-flash-thinking-exp-1219 → 2.5-flash-preview-05-20</option>
<option value="gemini-2.0-flash-thinking-exp">gemini-2.0-flash-thinking-exp → 2.5-flash-preview-05-20</option>
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
<option value="gemini-2.0-flash-lite-preview-02-05">gemini-2.0-flash-lite-preview-02-05</option>
<option value="gemini-2.0-flash-lite-preview">gemini-2.0-flash-lite-preview</option>
<option value="gemini-2.0-flash-lite">gemini-2.0-flash-lite</option>
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
<option value="gemini-2.0-flash">gemini-2.0-flash (deprecated)</option>
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
<option value="gemini-2.0-flash-lite">gemini-2.0-flash-lite (deprecated)</option>
</optgroup>
<optgroup label="Gemma">
<option value="gemma-4-31b-it">gemma-4-31b-it</option>
@@ -3481,14 +3487,26 @@
<h4 data-i18n="Google Model">Google Model</h4>
<select id="model_vertexai_select">
<!-- data-mode="full" is for models that require a service account -->
<optgroup label="Gemini 3.8">
<option value="gemini-3.8-flash">gemini-3.8-flash</option>
</optgroup>
<optgroup label="Gemini 3.7">
<option value="gemini-3.7-flash">gemini-3.7-flash</option>
</optgroup>
<optgroup label="Gemini 3.6">
<option value="gemini-3.6-flash">gemini-3.6-flash</option>
</optgroup>
<optgroup label="Gemini 3.5">
<option value="gemini-3.5-flash">gemini-3.5-flash</option>
<option value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
</optgroup>
<optgroup label="Gemini 3.1">
<option value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
<option value="gemini-3.1-flash-lite-preview">gemini-3.1-flash-lite-preview</option>
<option value="gemini-3.1-flash-image-preview">gemini-3.1-flash-image-preview</option>
<option value="gemini-3.1-flash-lite">gemini-3.1-flash-lite</option>
<option value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
</optgroup>
<optgroup label="Gemini 3.0">
<option value="gemini-3-pro-preview">gemini-3-pro-preview</option>
<option value="gemini-3-pro-image-preview">gemini-3-pro-image-preview</option>
<option value="gemini-3-pro-image">gemini-3-pro-image</option>
<option value="gemini-3-flash-preview">gemini-3-flash-preview</option>
</optgroup>
<optgroup label="Gemini 2.5">
@@ -3496,14 +3514,11 @@
<option value="gemini-2.5-flash">gemini-2.5-flash</option>
<option value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
<option value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
<option value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
</optgroup>
<optgroup label="Gemini 2.0">
<option value="gemini-2.0-flash-exp" data-mode="full">gemini-2.0-flash-exp</option>
<option value="gemini-2.0-flash-preview-image-generation" data-mode="full">gemini-2.0-flash-preview-image-generation</option>
<option value="gemini-2.0-flash">gemini-2.0-flash</option>
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
<option value="gemini-2.0-flash">gemini-2.0-flash (deprecated)</option>
<option value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
<option value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
</optgroup>
</select>
</div>
@@ -3868,17 +3883,24 @@
</select>
</div>
<div id="pollinations_form" data-source="pollinations">
<h4>
<a href="https://enter.pollinations.ai/" target="_blank" rel="noopener noreferrer" data-i18n="Pollinations API Key">
Pollinations API Key
</a>
</h4>
<div class="flex-container">
<input id="api_key_pollinations" name="api_key_pollinations" 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_pollinations"></div>
</div>
<div data-for="api_key_pollinations" 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'.
<h4 data-i18n="Pollinations Endpoint">Pollinations Endpoint</h4>
<select id="pollinations_endpoint">
<option value="anonymous" data-i18n="Anonymous (No Key)">Anonymous (No Key)</option>
<option value="authenticated" data-i18n="Authenticated (API Key)">Authenticated (API Key)</option>
</select>
<div id="pollinations_key_section">
<h4>
<a href="https://enter.pollinations.ai/" target="_blank" rel="noopener noreferrer" data-i18n="Pollinations API Key">
Pollinations API Key
</a>
</h4>
<div class="flex-container">
<input id="api_key_pollinations" name="api_key_pollinations" class="text_pole flex1" value="" type="text" placeholder="sk_..." 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_pollinations"></div>
</div>
<div data-for="api_key_pollinations" 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>
</div>
<h4 data-i18n="Pollinations Model">Pollinations Model</h4>
<select id="model_pollinations_select">
@@ -3932,6 +3954,7 @@
</select>
<h4 data-i18n="Z.AI Model">Z.AI Model</h4>
<select id="model_zai_select">
<option value="glm-5.2">glm-5.2</option>
<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>
@@ -3978,7 +4001,7 @@
<!-- Azure API Key -->
<h4><span data-i18n="Azure API Key">Azure API Key</span></h4>
<div class="flex-container">
<input id="api_key_azure_openai" data-setting="api_key_azure_openai" class="text_pole flex1" type="password" autocomplete="off">
<input id="api_key_azure_openai" data-setting="api_key_azure_openai" class="text_pole flex1" type="text" autocomplete="off">
<div title="Manage API keys" data-i18n="[title]Manage API keys" class="menu_button fa-solid fa-key fa-fw manage-api-keys" data-key="api_key_azure_openai"></div>
</div>
<div class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you click 'Connect'." data-for="api_key_azure_openai">
@@ -4056,7 +4079,7 @@
<div class="api_loading menu_button menu_button_icon" data-i18n="Cancel">Cancel</div>
<div data-source="custom" id="customize_additional_parameters" class="menu_button menu_button_icon" data-i18n="Additional Parameters">Additional Parameters</div>
<div data-source="openrouter" class="menu_button menu_button_icon openrouter_authorize" title="Get your OpenRouter API token using OAuth flow. You will be redirected to openrouter.ai" data-i18n="Authorize;[title]Get your OpenRouter API token using OAuth flow. You will be redirected to openrouter.ai">Authorize</div>
<div id="test_api_button" class="menu_button menu_button_icon" title="Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!" data-i18n="Test Message;[title]Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!">Test Message</div>
<div id="test_api_button" class="menu_button menu_button_icon" title="Verifies your API connection by sending a short test message. This may incur usage charges." data-i18n="Test Message;[title]Verifies your API connection by sending a short test message. This may incur usage charges.">Test Message</div>
</div>
<div class="online_status">
<div class="online_status_indicator"></div>
+1 -1
View File
@@ -396,7 +396,7 @@
"Available Models": "النماذج المتاحة",
"Prompt Post-Processing": "موجه بعد المعالجة",
"Applies additional processing to the prompt before sending it to the API.": "يطبق معالجة إضافية على الموجه قبل إرساله إلى واجهة برمجة التطبيقات.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "تتحقق من اتصالك بواجهة برمجة التطبيقات من خلال إرسال رسالة اختبار قصيرة. كن على علم بأنك ستحصل على الفضل في ذلك!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "يتحقق من اتصال API الخاص بك عن طريق إرسال رسالة اختبار قصيرة. قد يؤدي ذلك إلى فرض رسوم استخدام.",
"Test Message": "رسالة اختبار",
"Auto-connect to Last Server": "الاتصال التلقائي بآخر خادم",
"Missing key": "❌المفتاح مفقود",
+1 -1
View File
@@ -396,7 +396,7 @@
"Available Models": "Verfügbare Modelle",
"Prompt Post-Processing": "Zeitnahe Nachbearbeitung",
"Applies additional processing to the prompt before sending it to the API.": "Wendet zusätzliche Verarbeitungsvorgänge auf die Eingabeaufforderung an, bevor sie an die API gesendet wird.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Überprüft deine API-Verbindung durch Senden einer kurzen Testnachricht. Sei dir bewusst, dass du dafür gutgeschrieben wirst!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Überprüft deine API-Verbindung durch Senden einer kurzen Testnachricht. Dabei können Nutzungsgebühren anfallen.",
"Test Message": "Testnachricht",
"Auto-connect to Last Server": "Automatisch mit dem letzten Server verbinden",
"Missing key": "❌ Fehlender Schlüssel",
+1 -1
View File
@@ -396,7 +396,7 @@
"Available Models": "Modelos disponibles",
"Prompt Post-Processing": "Postprocesamiento rápido",
"Applies additional processing to the prompt before sending it to the API.": "Aplica procesamiento adicional al mensaje antes de enviarlo a la API.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Verifica su conexión de API enviando un breve mensaje de prueba. ¡Tenga en cuenta que se le cobrará por ello!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Verifica su conexión API enviando un breve mensaje de prueba. Esto puede generar cargos de uso.",
"Test Message": "Mensaje de prueba",
"Auto-connect to Last Server": "Conexión automática al último servidor",
"Missing key": "❌ Llave faltante",
+2 -2
View File
@@ -376,7 +376,7 @@
"Available Models": "Modèles disponibles",
"Prompt Post-Processing": "Post-traitement de prompt",
"Applies additional processing to the prompt before sending it to the API.": "Applique un traitement supplémentaire au prompt avant de l'envoyer à l'API.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Vérifie votre connexion API en envoyant un court message de test. Soyez conscient que vous serez crédité pour cela !",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Vérifie votre connexion API en envoyant un court message de test. Cela peut entraîner des frais d'utilisation.",
"Test Message": "Message de test",
"Auto-connect to Last Server": "Connexion automatique au dernier serveur",
"Missing key": "❌ Clé manquante",
@@ -717,7 +717,7 @@
"Click to set a new User Name": "Cliquez pour définir un nouveau nom d'utilisateur",
"Click to lock your selected persona to the current chat. Click again to remove the lock.": "Cliquez pour verrouiller votre persona sélectionnée sur la discussion actuelle. Cliquez à nouveau pour supprimer le verrou.",
"Click to set user name for all messages": "Cliquez pour définir le nom d'utilisateur pour tous les messages",
"Persona Description": "Description de la persona",
"Persona Description": "Description du persona",
"Example: [{{user}} is a 28-year-old Romanian cat girl.]": "Exemple : [{{user}} est une fille chat roumaine de 28 ans.]",
"Tokens persona description": "Description des tokens",
"Position:": "Position :",
+1 -1
View File
@@ -394,7 +394,7 @@
"Available Models": "Módel í boði",
"Prompt Post-Processing": "Skjót eftirvinnsla",
"Applies additional processing to the prompt before sending it to the API.": "Beitir viðbótarvinnslu á boðunina áður en hún er send í API.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Sannreynir API tengingu þína með því að senda stutt skilaboð til að prófa. Vertu meðvituð(ur/ur) um að þú færð fyrir það!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Staðfestir API tenginguna þína með því að senda stutt prufuskilaboð. Þetta gæti haft afnotagjöld í för með sér.",
"Test Message": "Prufu skilaboð",
"Auto-connect to Last Server": "Tengjast sjálfkrafa við síðustu framendurnar",
"Missing key": "❌ Vantar lykil",
+1 -1
View File
@@ -396,7 +396,7 @@
"Available Models": "Modelli disponibili",
"Prompt Post-Processing": "Post-elaborazione rapida",
"Applies additional processing to the prompt before sending it to the API.": "Applica un'ulteriore elaborazione al prompt prima di inviarlo all'API.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Verifica la tua connessione API inviando un breve messaggio di prova. Tieni presente che verrai accreditato per questo!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Verifica la tua connessione API inviando un breve messaggio di prova. Ciò potrebbe comportare costi di utilizzo.",
"Test Message": "Messaggio di prova",
"Auto-connect to Last Server": "Connetti automaticamente all'ultimo server",
"Missing key": "❌ Chiave mancante",
+1 -1
View File
@@ -396,7 +396,7 @@
"Available Models": "利用可能なモデル",
"Prompt Post-Processing": "迅速な後処理",
"Applies additional processing to the prompt before sending it to the API.": "プロンプトを API に送信する前に追加の処理を適用します。",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "短いテストメッセージを送信してAPI接続を検証します。それに対してクレジットが与えられることに注意してください!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "短いテストメッセージを送信してAPI接続を検証します。これにより利用料金が発生する場合があります。",
"Test Message": "テストメッセージ",
"Auto-connect to Last Server": "前回のサーバーに自動接続",
"Missing key": "❌ キーがありません",
+1 -1
View File
@@ -404,7 +404,7 @@
"Prompt Post-Processing": "신속한 후처리",
"api_no_connection": "연결이 되지 않았습니다...",
"Applies additional processing to the prompt before sending it to the API.": "API로 보내기 전에 프롬프트에 추가 처리를 적용합니다.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "짧은 테스트 메시지를 보내어 API 연결을 확인합니다. 이에 대해 유료 크레딧이 지불될 수 있음을 인식하세요!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "짧은 테스트 메시지를 보내 API 연결을 확인합니다. 이로 인해 사용 요금이 부과될 수 있습니다.",
"Test Message": "테스트 메시지",
"Auto-connect to Last Server": "마지막 서버에 자동으로 연결",
"Missing key": "❌ 현재 저장된 키가 존재하지 않습니다.",
+1 -1
View File
@@ -392,7 +392,7 @@
"Available Models": "Beschikbare modellen",
"Prompt Post-Processing": "Snelle naverwerking",
"Applies additional processing to the prompt before sending it to the API.": "Past extra verwerking toe op de prompt voordat deze naar de API wordt verzonden.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Verifieert uw API-verbinding door een kort testbericht te verzenden. Wees ervan bewust dat u hiervoor wordt gecrediteerd!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Verifieert uw API-verbinding door een kort testbericht te verzenden. Hiervoor kunnen gebruikskosten in rekening worden gebracht.",
"Test Message": "Testbericht",
"Auto-connect to Last Server": "Automatisch verbinden met de laatste server",
"Missing key": "❌ Ontbrekende sleutel",
+1 -1
View File
@@ -394,7 +394,7 @@
"Available Models": "Modelos Disponíveis",
"Prompt Post-Processing": "Pós-processamento imediato",
"Applies additional processing to the prompt before sending it to the API.": "Aplica processamento adicional ao prompt antes de enviá-lo para a API.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Verifica sua conexão com a API enviando uma mensagem de teste curta. Esteja ciente de que você será creditado por isso!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Verifica a ligação à API ao enviar uma mensagem de teste curta. Isto pode implicar custos de utilização.",
"Test Message": "Mensagem de Teste",
"Auto-connect to Last Server": "Conectar-se automaticamente ao último servidor",
"Missing key": "❌ Chave faltando",
+1 -1
View File
@@ -514,7 +514,7 @@
"Clear your API key": "Стереть ключ от API",
"Refresh models": "Обновить модели",
"Get your OpenRouter API token using OAuth flow. You will be redirected to openrouter.ai": "Получите свой OpenRouter API токен используя OAuth. У вас будет открыта вкладка openrouter.ai",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Проверка работоспособности вашего соединения с API путём отправки короткого тестового сообщения. Внимание: оно будет отправлено от вашего имени.",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Проверяет соединение с API, отправляя короткое тестовое сообщение. Это может повлечь плату за использование.",
"Edit": "Редактировать",
"Locked = World Editor will stay open": "Закреплено = Редактор мира останется открытым",
"Entries can activate other entries by mentioning their keywords": "Записи могут активировать другие записи, если в них содержатся ключевые слова",
+1 -1
View File
@@ -401,7 +401,7 @@
"Available Models": "โมเดลที่สามารถใช้ได้",
"Prompt Post-Processing": "การประมวลผลพรอมต์หลังการส่ง",
"Applies additional processing to the prompt before sending it to the API.": "ใช้การประมวลผลเพิ่มเติมกับพรอมต์ก่อนส่งไปยัง API",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "ตรวจสอบการเชื่อมต่อ API โดยส่งข้อความทดสอบสั้นๆ โปรดทราบว่าคุณจะถูกเรียกเก็บเงินสำหรับการทดสอบนี้!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "ตรวจสอบการเชื่อมต่อ API โดยส่งข้อความทดสอบสั้นๆ ซึ่งอาจมีค่าใช้จ่ายในการใช้งาน",
"Test Message": "ทดสอบการส่งข้อความ",
"Auto-connect to Last Server": "เชื่อมต่อเซิฟเวอร์อัตโนมัติ",
"Missing key": "โปรดใส่ API Key",
+1 -1
View File
@@ -394,7 +394,7 @@
"Available Models": "Доступні моделі",
"Prompt Post-Processing": "Швидка постобробка",
"Applies additional processing to the prompt before sending it to the API.": "Застосовує додаткову обробку запиту перед надсиланням його в API.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Підтверджує ваше підключення до API, надсилаючи коротке тестове повідомлення. Пам'ятайте, що ви будете платити за це!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Перевіряє підключення до API, надсилаючи коротке тестове повідомлення. За це може стягуватися плата за використання.",
"Test Message": "Тестове повідомлення",
"Auto-connect to Last Server": "Автоматичне підключення до останнього сервера",
"Missing key": "❌ Відсутній ключ",
+1 -1
View File
@@ -394,7 +394,7 @@
"Available Models": "Các Model hiện có",
"Prompt Post-Processing": "Xử lý hậu kỳ Prompt",
"Applies additional processing to the prompt before sending it to the API.": "Áp dụng xử lý bổ sung cho Prompt trước khi gửi nó tới API.",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "Xác minh kết nối API của bạn bằng cách gửi một tin nhắn kiểm tra ngắn. Hãy nhớ rằng bạn sẽ được ghi nhận về điều đó!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "Xác minh kết nối API của bạn bằng cách gửi tin nhắn kiểm tra ngắn. Việc này có thể phát sinh phí sử dụng.",
"Test Message": "Test tin nhắn",
"Auto-connect to Last Server": "Tự động kết nối với link trước đó",
"Missing key": "❌ Thiếu Key",
+1 -1
View File
@@ -556,7 +556,7 @@
"prompt_post_processing_single": "单一用户消息(无工具)",
"Additional Parameters": "附加参数",
"Test Message": "发送测试消息",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "通过发送简短的测试消息验证您的API连接。请注意,您将因此消耗额度!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "通过发送简短的测试消息验证您的 API 连接。这可能会产生使用费用。",
"Auto-connect to Last Server": "自动连接到上次的服务器",
"Missing key": "❌ 缺少密钥",
"Key saved": "密钥已保存",
+1 -1
View File
@@ -393,7 +393,7 @@
"Available Models": "可用模型",
"Prompt Post-Processing": "提示詞後處理",
"Applies additional processing to the prompt before sending it to the API.": "這個選項會在將提示詞送往 API 之前,對它進行額外的處理。",
"Verifies your API connection by sending a short test message. Be aware that you'll be credited for it!": "透過傳送簡短的測試訊息來驗證您的 API 連線。請注意,您將因此獲得榮譽!",
"Verifies your API connection by sending a short test message. This may incur usage charges.": "透過傳送簡短的測試訊息來驗證您的 API 連線。這可能會產生使用費用。",
"Test Message": "測試訊息",
"Auto-connect to Last Server": "自動連線至上次使用的伺服器",
"Missing key": "❌ 鑰匙遺失",
+79 -17
View File
@@ -282,6 +282,7 @@ import { initDomHandlers } from './scripts/dom-handlers.js';
import { SimpleMutex } from './scripts/util/SimpleMutex.js';
import { AudioPlayer } from './scripts/audio-player.js';
import { MacroEnvBuilder } from './scripts/macros/engine/MacroEnvBuilder.js';
import { MessageFormatter } from './scripts/message-formatter.js';
import { MacroEngine } from './scripts/macros/engine/MacroEngine.js';
import { addChatBackupsBrowser } from './scripts/chat-backups.js';
import { onboardingExperimentalMacroEngine } from './scripts/macros/engine/MacroDiagnostics.js';
@@ -603,6 +604,7 @@ export let is_send_press = false; //Send generation
export const isGenerating = () => (is_send_press || is_group_generating);
let this_del_mes = -1;
let deleteToolCallsInDeleteMode = true;
/** @type {string} */
let this_edit_mes_chname = '';
@@ -1609,13 +1611,32 @@ export async function deleteLastMessage() {
await eventSource.emit(event_types.MESSAGE_DELETED, chat.length);
}
function getMessageDeletionStartId(id, deleteToolCalls = true) {
const message = chat[id];
if (!deleteToolCalls || message?.is_user || message?.is_system) {
return id;
}
let startId = id;
while (startId > 0) {
const previousMessage = chat[startId - 1];
if (!previousMessage?.is_system || !Array.isArray(previousMessage.extra?.tool_invocations)) {
break;
}
startId--;
}
return startId;
}
/**
* Deletes a message from the chat by its ID, optionally asking for confirmation.
* @param {number} id The ID of the message to delete.
* @param {number} [swipeDeletionIndex] Deletes the swipe with that index.
* @param {boolean} [askConfirmation=false] Whether to ask for confirmation before deleting.
* @param {boolean} [deleteToolCalls=true] Whether to delete preceding tool-call messages.
*/
export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfirmation = false) {
export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfirmation = false, deleteToolCalls = true) {
const canDeleteSwipe = swipeDeletionIndex !== undefined && swipeDeletionIndex !== null;
if (canDeleteSwipe) {
if (swipeDeletionIndex < 0) {
@@ -1653,13 +1674,19 @@ export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfi
return;
}
chat.splice(id, 1);
messageElement.remove();
const firstMessageId = getMessageDeletionStartId(id, deleteToolCalls);
const messageIds = Array.from({ length: id - firstMessageId + 1 }, (_, index) => id - index);
// Delete from the end so earlier indices remain stable.
for (const messageId of messageIds) {
chat.splice(messageId, 1);
chatElement.find(`.mes[mesid="${messageId}"]`).remove();
deleteItemizedPromptForMessage(messageId);
}
chat_metadata.tainted = true;
const startIndex = [0, minId].includes(id) ? id : null;
deleteItemizedPromptForMessage(id);
const startIndex = firstMessageId <= minId ? firstMessageId : null;
updateViewMessageIds(startIndex);
saveChatDebounced();
@@ -1740,15 +1767,35 @@ export async function sendTextareaMessage() {
}
/**
* Formats the message text into an HTML string using Markdown and other formatting.
* @param {string} mes Message text
* @param {string} ch_name Character name
* @param {boolean} isSystem If the message was sent by the system
* @param {boolean} isUser If the message was sent by the user
* @param {number} messageId Message index in chat array
* @param {Partial<DOMPurify.Config>} [sanitizerOverrides] DOMPurify sanitizer option overrides
* @param {boolean} [isReasoning] If the message is reasoning output
* @returns {string} HTML string
* Formats raw message text into an HTML string ready for DOM insertion.
*
* The pipeline is, in order:
* 1. Prompt-bias stripping (message 0 only)
* 2. Comment / hidden-message normalisation
* 3. `beforeRegex` extension hooks (see {@link MessageFormatter})
* 4. Custom regex rules (`getRegexedString`)
* 5. `afterRegex` extension hooks
* 6. Markdown auto-fix (`fixMarkdown`)
* 7. HTML tag encoding (`encode_tags`)
* 8. Showdown Markdown → HTML conversion
* 9. `afterMarkdown` extension hooks
* 10. Name-prefix stripping (`allow_name2_display`)
* 11. DOMPurify sanitization
*
* All extension hooks run **before** DOMPurify (steps 3, 5, 9) so their
* output is always sanitised.
*
* @param {string} mes - Raw message text.
* @param {string} ch_name - Character name associated with the message.
* @param {boolean} isSystem - Whether the message is a system message.
* @param {boolean} isUser - Whether the message was sent by the user.
* @param {number} messageId - Index of the message in the chat array, or -1
* for transient messages (e.g. streaming previews).
* @param {Partial<DOMPurify.Config>} [sanitizerOverrides] - DOMPurify option
* overrides. Merged on top of the default config.
* @param {boolean} [isReasoning=false] - Whether the message is reasoning/thinking
* output (affects regex placement and some display rules).
* @returns {string} Sanitized HTML string ready to assign to `innerHTML`.
*/
export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, sanitizerOverrides = {}, isReasoning = false) {
if (!mes) {
@@ -1805,12 +1852,20 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
const indexOf = usableMessages.findIndex(x => x.index === Number(messageId));
const depth = messageId >= 0 && indexOf !== -1 ? (usableMessages.length - indexOf - 1) : undefined;
mes = MessageFormatter.runStage(MessageFormatter.stage.BEFORE_REGEX, mes,
{ ch_name, isSystem, isUser, messageId, isReasoning },
);
// Always override the character name
mes = getRegexedString(mes, regexPlacement, {
characterOverride: ch_name,
isMarkdown: true,
depth: depth,
});
mes = MessageFormatter.runStage(MessageFormatter.stage.AFTER_REGEX, mes,
{ ch_name, isSystem, isUser, messageId, isReasoning },
);
}
if (power_user.auto_fix_generated_markdown) {
@@ -1889,6 +1944,10 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
mes = mes.replace(/<code(.*)>[\s\S]*?<\/code>/g, function (match) {
return match.replace(/&amp;/g, '&');
});
mes = MessageFormatter.runStage(MessageFormatter.stage.AFTER_MARKDOWN, mes,
{ ch_name, isSystem, isUser, messageId, isReasoning },
);
}
if (!power_user.allow_name2_display && ch_name && !isUser && !isSystem) {
@@ -8133,7 +8192,7 @@ function updateMessage(div) {
return { mesBlock, text, mes, bias };
}
function openMessageDelete(fromSlashCommand) {
function openMessageDelete(fromSlashCommand, deleteToolCalls = true) {
closeMessageEditor();
hideSwipeButtons();
if (fromSlashCommand || (!is_send_press) || (selected_group && !is_group_generating)) {
@@ -8152,6 +8211,7 @@ function openMessageDelete(fromSlashCommand) {
is_group_generating: ${is_group_generating}`);
}
this_del_mes = -1;
deleteToolCallsInDeleteMode = deleteToolCalls;
is_delete_mode = true;
}
@@ -9714,7 +9774,7 @@ export async function createOrEditCharacter(e) {
return;
}
try {
//if the character name text area isn't empty (only posible when creating a new character)
//if the character name text area isn't empty (only possible when creating a new character)
let url = '/api/characters/create';
if (crop_data != undefined) {
@@ -11196,6 +11256,7 @@ jQuery(async function () {
});
$(this).addClass('selected'); //sets the bg of the mes selected for deletion
var i = Number($(this).attr('mesid')); //checks the message ID in the chat
i = getMessageDeletionStartId(i, deleteToolCallsInDeleteMode);
this_del_mes = i;
//as long as the current message ID is less than the total chat length
while (i < chat.length) {
@@ -11520,6 +11581,7 @@ jQuery(async function () {
///////////// OPTIMIZED LISTENERS FOR LEFT SIDE OPTIONS POPUP MENU //////////////////////
$('#options [id]').on('click', async function (event, customData) {
const fromSlashCommand = customData?.fromSlashCommand || false;
const deleteToolCalls = customData?.deleteToolCalls ?? true;
var id = $(this).attr('id');
// Check whether a custom prompt was provided via custom data (for example through a slash command)
@@ -11598,7 +11660,7 @@ jQuery(async function () {
Generate('continue', buildOrFillAdditionalArgs());
}
} else if (id == 'option_delete_mes') {
setTimeout(() => openMessageDelete(fromSlashCommand), animation_duration);
setTimeout(() => openMessageDelete(fromSlashCommand, deleteToolCalls), animation_duration);
} else if (id == 'option_close_chat') {
await closeCurrentChat();
} else if (id === 'option_settings') {
+2 -2
View File
@@ -34,7 +34,7 @@ import {
secret_state,
} from './secrets.js';
import { debounce, getStringHash, isValidUrl } from './utils.js';
import { chat_completion_sources, oai_settings } from './openai.js';
import { chat_completion_sources, oai_settings, POLLINATIONS_ENDPOINT } from './openai.js';
import { getTokenCountAsync } from './tokenizers.js';
import { textgen_types, textgenerationwebui_settings as textgen_settings, getTextGenServer } from './textgen-settings.js';
import { debounce_timeout, SWIPE_SOURCE } from './constants.js';
@@ -406,7 +406,7 @@ function RA_autoconnect(PrevApi) {
|| (secret_state[SECRET_KEYS.FIREWORKS] && oai_settings.chat_completion_source == chat_completion_sources.FIREWORKS)
|| (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.POLLINATIONS] || oai_settings.pollinations_endpoint === POLLINATIONS_ENDPOINT.ANONYMOUS) && 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)
|| (secret_state[SECRET_KEYS.MINIMAX] && oai_settings.chat_completion_source == chat_completion_sources.MINIMAX)
|| (isValidUrl(oai_settings.custom_url) && oai_settings.chat_completion_source == chat_completion_sources.CUSTOM)
+1 -1
View File
@@ -96,7 +96,7 @@ function setNotePositionCommand(_, text) {
return;
}
$(`input[name="extension_floating_position"][value="${position}"]`).prop('checked', true).trigger('input');
$(`input[name="extension_floating_position"][value="${position}"]`).prop('checked', true).trigger('input').trigger('change');
toastr.info(t`Author's Note position updated`);
}
return Object.keys(validPositions).find(key => validPositions[key] == chat_metadata[metadata_keys.position]);
+13 -3
View File
@@ -126,9 +126,17 @@ export class AutoComplete {
});
textarea.addEventListener('blur', () => this.hide());
if (isFloating) {
textarea.addEventListener('scroll', () => this.updateFloatingPositionDebounced());
textarea.addEventListener('scroll', () => {
if (this.isActive) {
this.updateFloatingPositionDebounced();
}
});
}
window.addEventListener('resize', () => this.updatePositionDebounced());
window.addEventListener('resize', () => {
if (this.isActive) {
this.updatePositionDebounced();
}
});
}
/**
@@ -666,7 +674,9 @@ export class AutoComplete {
this.clone.remove();
}
});
mo.observe(this.textarea.parentElement, { childList: true });
if (this.textarea.parentElement) {
mo.observe(this.textarea.parentElement, { childList: true });
}
}
this.clone.style.height = `${inputRect.height}px`;
this.clone.style.left = `${inputRect.left}px`;
+7 -4
View File
@@ -41,6 +41,7 @@ import { t } from './i18n.js';
import {
getUniqueName,
isTrueBoolean,
uuidv4,
} from './utils.js';
const bookmarkNameToken = 'Checkpoint #';
@@ -94,7 +95,7 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) {
return `${cleanName} - ${bookmarkNameToken}${i}`;
}
const existingChats = await getExistingChatNames();
const suggestedName = getUniqueName(mainChatName, (x) => existingChats.includes(x), { nameBuilder: buildCheckpointName });
const suggestedName = getUniqueName(mainChatName, (x) => existingChats.includes(x), { nameBuilder: buildCheckpointName, startIndex: 1 });
const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace, suggestedName: suggestedName });
let name = forceName ?? await Popup.show.input('Create Checkpoint', body, suggestedName);
@@ -196,7 +197,8 @@ export async function createBranch(mesId, { swipeId = null } = {}) {
const lastMes = chat[mesId];
const mainChatName = (getCurrentChatDetails()).sessionName;
const newMetadata = { main_chat: mainChatName };
// Mint a fresh integrity slug so the branch is distinguishable from its parent (#5942)
const newMetadata = { main_chat: mainChatName, integrity: uuidv4() };
const selectedSwipeId = swipeId === null ? null : Number(swipeId);
if (selectedSwipeId !== null && (!Number.isInteger(selectedSwipeId) || selectedSwipeId < 0 || selectedSwipeId >= (lastMes?.swipes?.length ?? 0))) {
@@ -212,7 +214,7 @@ export async function createBranch(mesId, { swipeId = null } = {}) {
return `${cleanName} - Branch #${i}`;
}
const existingChats = await getExistingChatNames();
const name = getUniqueName(mainChatName, (x) => existingChats.includes(x), { nameBuilder: buildBranchName });
const name = getUniqueName(mainChatName, (x) => existingChats.includes(x), { nameBuilder: buildBranchName, startIndex: 1 });
if (!name) {
console.error('Could not generate a unique branch name.');
toastr.error('Could not generate a unique branch name.', 'Branch creation failed');
@@ -278,7 +280,8 @@ export async function createNewBookmark(mesId, { forceName = null } = {}) {
}
const mainChat = selected_group ? groups?.find(x => x.id == selected_group)?.chat_id : characters[this_chid].chat;
const newMetadata = { main_chat: mainChat };
// Mint a fresh integrity slug so the checkpoint is distinguishable from its parent (#5942)
const newMetadata = { main_chat: mainChat, integrity: uuidv4() };
await saveItemizedPrompts(name);
if (selected_group) {
+6 -6
View File
@@ -33,12 +33,12 @@
* @property {number} role - The specific function or purpose of the extension.
* @property {boolean} vectorized - Indicates if the extension is optimized for vectorized processing.
* @property {number} display_index - The order in which the extension should be displayed for user interfaces.
* @property {boolean} match_persona_description - Wether to match against the persona description.
* @property {boolean} match_character_description - Wether to match against the persona description.
* @property {boolean} match_character_personality - Wether to match against the character personality.
* @property {boolean} match_character_depth_prompt - Wether to match against the character depth prompt.
* @property {boolean} match_scenario - Wether to match against the character scenario.
* @property {boolean} match_creator_notes - Wether to match against the character creator notes.
* @property {boolean} match_persona_description - Whether to match against the persona description.
* @property {boolean} match_character_description - Whether to match against the character description.
* @property {boolean} match_character_personality - Whether to match against the character personality.
* @property {boolean} match_character_depth_prompt - Whether to match against the character depth prompt.
* @property {boolean} match_scenario - Whether to match against the character scenario.
* @property {boolean} match_creator_notes - Whether to match against the character creator notes.
*/
/**
+1 -1
View File
@@ -592,7 +592,7 @@ export class ChatCompletionService {
}
// Ensure api-url is properly applied for all sources that accept it
['custom_url', 'vertexai_region', 'zai_endpoint', 'siliconflow_endpoint', 'minimax_endpoint'].forEach(field => {
['custom_url', 'vertexai_region', 'zai_endpoint', 'siliconflow_endpoint', 'minimax_endpoint', 'pollinations_endpoint'].forEach(field => {
// The order is: connection profile => CC preset => CC settings
overridePayload[field] = overridePayload[field] || settings[field] || oai_settings[field];
});
+9
View File
@@ -1797,6 +1797,15 @@ export async function loadExtensionSettings(settings, versionChanged, enableAuto
extensionTypes = Object.fromEntries(extensions.map(x => [x.name, x.type]));
manifests = await getManifests(extensionNames);
// An extension without a loadable manifest cannot be used: drop it so state queries
// and the extensions list do not report a ghost entry (e.g. leftover folder on disk)
const namesWithoutManifest = extensionNames.filter(name => !Object.hasOwn(manifests, name));
if (namesWithoutManifest.length) {
console.warn('Ignoring extensions without a loadable manifest.json:', namesWithoutManifest);
extensionNames = extensionNames.filter(name => Object.hasOwn(manifests, name));
namesWithoutManifest.forEach(name => delete extensionTypes[name]);
}
if (versionChanged && enableAutoUpdate) {
await autoUpdateExtensions(false);
}
+15 -5
View File
@@ -3,7 +3,7 @@ import { getContext, getApiUrl, doExtrasFetch, extension_settings, modules, rend
import { appendMediaToMessage, chat_metadata, eventSource, event_types, getRequestHeaders, saveChatConditional, saveSettingsDebounced, substituteParams } from '../../../script.js';
import { getMessageTimeStamp } from '../../RossAscends-mods.js';
import { SECRET_KEYS, secret_state } from '../../secrets.js';
import { oai_settings } from '../../openai.js';
import { oai_settings, POLLINATIONS_ENDPOINT } from '../../openai.js';
import { getMultimodalCaption } from '../shared.js';
import { textgen_types, textgenerationwebui_settings } from '../../textgen-settings.js';
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
@@ -18,6 +18,11 @@ const MODULE_NAME = 'caption';
const PROMPT_DEFAULT = 'What\'s in this image?';
const TEMPLATE_DEFAULT = '[{{user}} sends {{char}} a picture that contains: {{caption}}]';
const GOOGLE_MODEL_MIGRATIONS = new Map([
['gemini-3.1-flash-lite-preview', 'gemini-3.1-flash-lite'],
['gemini-3.1-flash-image-preview', 'gemini-3.1-flash-image'],
['gemini-3-pro-image-preview', 'gemini-3-pro-image'],
]);
/**
* Migrates old extension settings to the new format.
@@ -37,7 +42,12 @@ function migrateSettings() {
if (extension_settings.caption.source === 'openai') {
extension_settings.caption.source = 'multimodal';
extension_settings.caption.multimodal_api = 'openai';
extension_settings.caption.multimodal_model = 'gpt-4-turbo';
extension_settings.caption.multimodal_model = 'gpt-5.6-luna';
}
if (['google', 'vertexai'].includes(extension_settings.caption.multimodal_api)) {
extension_settings.caption.multimodal_model = GOOGLE_MODEL_MIGRATIONS.get(extension_settings.caption.multimodal_model)
?? extension_settings.caption.multimodal_model;
}
if (!extension_settings.caption.multimodal_api) {
@@ -45,7 +55,7 @@ function migrateSettings() {
}
if (!extension_settings.caption.multimodal_model) {
extension_settings.caption.multimodal_model = 'gpt-4-turbo';
extension_settings.caption.multimodal_model = 'gpt-6-luna';
}
if (!extension_settings.caption.prompt) {
@@ -530,8 +540,8 @@ export async function init() {
return true;
}
// Custom API doesn't need additional checks
if (api === 'custom') {
// Custom API and anonymous Pollinations don't need additional checks
if (api === 'custom' || (api === 'pollinations' && oai_settings.pollinations_endpoint === POLLINATIONS_ENDPOINT.ANONYMOUS)) {
return true;
}
}
+34 -47
View File
@@ -54,6 +54,13 @@
<option data-type="cohere" value="c4ai-aya-vision-8b">c4ai-aya-vision-8b</option>
<option data-type="cohere" value="c4ai-aya-vision-32b">c4ai-aya-vision-32b</option>
<option data-type="cohere" value="command-a-vision-07-2025">command-a-vision-07-2025</option>
<option data-type="openai" value="gpt-6-astra">gpt-6-astra</option>
<option data-type="openai" value="gpt-6-sol">gpt-6-sol</option>
<option data-type="openai" value="gpt-6-luna">gpt-6-luna</option>
<option data-type="openai" value="gpt-5.6">gpt-5.6</option>
<option data-type="openai" value="gpt-5.6-sol">gpt-5.6-sol</option>
<option data-type="openai" value="gpt-5.6-terra">gpt-5.6-terra</option>
<option data-type="openai" value="gpt-5.6-luna">gpt-5.6-luna</option>
<option data-type="openai" value="gpt-5.5">gpt-5.5</option>
<option data-type="openai" value="gpt-5.5-2026-04-23">gpt-5.5-2026-04-23</option>
<option data-type="openai" value="gpt-5.4">gpt-5.4</option>
@@ -82,20 +89,22 @@
<option data-type="openai" value="gpt-4.1-mini-2025-04-14">gpt-4.1-mini-2025-04-14</option>
<option data-type="openai" value="gpt-4.1-nano">gpt-4.1-nano</option>
<option data-type="openai" value="gpt-4.1-nano-2025-04-14">gpt-4.1-nano-2025-04-14</option>
<option data-type="openai" value="gpt-4-vision-preview">gpt-4-vision-preview</option>
<option data-type="openai" value="gpt-4-turbo">gpt-4-turbo</option>
<option data-type="openai" value="gpt-4o">gpt-4o</option>
<option data-type="openai" value="gpt-4o-mini">gpt-4o-mini</option>
<option data-type="openai" value="gpt-4o-mini-2024-07-18">gpt-4o-mini-2024-07-18</option>
<option data-type="openai" value="chatgpt-4o-latest">chatgpt-4o-latest</option>
<option data-type="openai" value="o1">o1</option>
<option data-type="openai" value="o1-2024-12-17">o1-2024-12-17</option>
<option data-type="openai" value="o3">o3</option>
<option data-type="openai" value="o3-2025-04-16">o3-2025-04-16</option>
<option data-type="openai" value="o4-mini">o4-mini</option>
<option data-type="openai" value="o4-mini-2025-04-16">o4-mini-2025-04-16</option>
<option data-type="openai" value="gpt-4.5-preview">gpt-4.5-preview</option>
<option data-type="openai" value="gpt-4.5-preview-2025-02-27">gpt-4.5-preview-2025-02-27</option>
<option data-type="anthropic" value="claude-fable-5-1">claude-fable-5-1</option>
<option data-type="anthropic" value="claude-fable-5">claude-fable-5</option>
<option data-type="anthropic" value="claude-opus-5-5">claude-opus-5-5</option>
<option data-type="anthropic" value="claude-opus-5">claude-opus-5</option>
<option data-type="anthropic" value="claude-sonnet-5">claude-sonnet-5</option>
<option data-type="anthropic" value="claude-opus-4-8">claude-opus-4-8</option>
<option data-type="anthropic" value="claude-opus-4-7">claude-opus-4-7</option>
<option data-type="anthropic" value="claude-opus-4-6">claude-opus-4-6</option>
<option data-type="anthropic" value="claude-opus-4-5">claude-opus-4-5</option>
@@ -105,52 +114,27 @@
<option data-type="anthropic" value="claude-sonnet-4-5-20250929">claude-sonnet-4-5-20250929</option>
<option data-type="anthropic" value="claude-haiku-4-5">claude-haiku-4-5</option>
<option data-type="anthropic" value="claude-haiku-4-5-20251001">claude-haiku-4-5-20251001</option>
<option data-type="anthropic" value="claude-opus-4-1">claude-opus-4-1</option>
<option data-type="anthropic" value="claude-opus-4-1-20250805">claude-opus-4-1-20250805</option>
<option data-type="anthropic" value="claude-opus-4-0">claude-opus-4-0</option>
<option data-type="anthropic" value="claude-opus-4-20250514">claude-opus-4-20250514</option>
<option data-type="anthropic" value="claude-sonnet-4-0">claude-sonnet-4-0</option>
<option data-type="anthropic" value="claude-sonnet-4-20250514">claude-sonnet-4-20250514</option>
<option data-type="anthropic" value="claude-3-7-sonnet-latest">claude-3-7-sonnet-latest</option>
<option data-type="anthropic" value="claude-3-7-sonnet-20250219">claude-3-7-sonnet-20250219</option>
<option data-type="anthropic" value="claude-3-5-sonnet-latest">claude-3-5-sonnet-latest</option>
<option data-type="anthropic" value="claude-3-5-sonnet-20241022">claude-3-5-sonnet-20241022</option>
<option data-type="anthropic" value="claude-3-5-sonnet-20240620">claude-3-5-sonnet-20240620</option>
<option data-type="anthropic" value="claude-3-5-haiku-latest">claude-3-5-haiku-latest</option>
<option data-type="anthropic" value="claude-3-5-haiku-20241022">claude-3-5-haiku-20241022</option>
<option data-type="anthropic" value="claude-3-opus-20240229">claude-3-opus-20240229</option>
<option data-type="anthropic" value="claude-3-haiku-20240307">claude-3-haiku-20240307</option>
<option data-type="google" value="gemini-3.8-flash">gemini-3.8-flash</option>
<option data-type="google" value="gemini-3.7-flash">gemini-3.7-flash</option>
<option data-type="google" value="gemini-3.6-flash">gemini-3.6-flash</option>
<option data-type="google" value="gemini-3.5-flash">gemini-3.5-flash</option>
<option data-type="google" value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
<option data-type="google" value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
<option data-type="google" value="gemini-3.1-flash-lite-preview">gemini-3.1-flash-lite-preview</option>
<option data-type="google" value="gemini-3.1-flash-image-preview">gemini-3.1-flash-image-preview</option>
<option data-type="google" value="gemini-3-pro-preview">gemini-3-pro-preview</option>
<option data-type="google" value="gemini-3-pro-image-preview">gemini-3-pro-image-preview</option>
<option data-type="google" value="gemini-3.1-flash-lite">gemini-3.1-flash-lite</option>
<option data-type="google" value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
<option data-type="google" value="gemini-3-pro-image">gemini-3-pro-image</option>
<option data-type="google" value="gemini-3-flash-preview">gemini-3-flash-preview</option>
<option data-type="google" value="gemini-2.5-pro">gemini-2.5-pro</option>
<option data-type="google" value="gemini-2.5-pro-preview-06-05">gemini-2.5-pro-preview-06-05</option>
<option data-type="google" value="gemini-2.5-pro-preview-05-06">gemini-2.5-pro-preview-05-06</option>
<option data-type="google" value="gemini-2.5-pro-preview-03-25">gemini-2.5-pro-preview-03-25</option>
<option data-type="google" value="gemini-2.5-flash">gemini-2.5-flash</option>
<option data-type="google" value="gemini-2.5-flash-preview-09-2025">gemini-2.5-flash-preview-09-2025</option>
<option data-type="google" value="gemini-2.5-flash-preview-05-20">gemini-2.5-flash-preview-05-20</option>
<option data-type="google" value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
<option data-type="google" value="gemini-2.5-flash-lite-preview-09-2025">gemini-2.5-flash-lite-preview-09-2025</option>
<option data-type="google" value="gemini-2.5-flash-lite-preview-06-17">gemini-2.5-flash-lite-preview-06-17</option>
<option data-type="google" value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
<option data-type="google" value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
<option data-type="google" value="gemini-2.0-pro-exp-02-05">gemini-2.0-pro-exp-02-05 → 2.5-exp-03-25</option>
<option data-type="google" value="gemini-2.0-pro-exp">gemini-2.0-pro-exp → 2.5-exp-03-25</option>
<option data-type="google" value="gemini-exp-1206">gemini-exp-1206 → 2.5-exp-03-25</option>
<option data-type="google" value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
<option data-type="google" value="gemini-2.0-flash-exp-image-generation">gemini-2.0-flash-exp-image-generation</option>
<option data-type="google" value="gemini-2.0-flash-exp">gemini-2.0-flash-exp</option>
<option data-type="google" value="gemini-2.0-flash">gemini-2.0-flash</option>
<option data-type="google" value="gemini-2.0-flash-thinking-exp-01-21">gemini-2.0-flash-thinking-exp-01-21 → 2.5-flash-preview-5-20</option>
<option data-type="google" value="gemini-2.0-flash-thinking-exp-1219">gemini-2.0-flash-thinking-exp-1219 → 2.5-flash-preview-05-20</option>
<option data-type="google" value="gemini-2.0-flash-thinking-exp">gemini-2.0-flash-thinking-exp → 2.5-flash-preview-05-20</option>
<option data-type="google" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
<option data-type="google" value="gemini-2.0-flash-lite-preview-02-05">gemini-2.0-flash-lite-preview-02-05</option>
<option data-type="google" value="gemini-2.0-flash-lite-preview">gemini-2.0-flash-lite-preview</option>
<option data-type="google" value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
<option data-type="google" value="gemini-2.0-flash">gemini-2.0-flash (deprecated)</option>
<option data-type="google" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
<option data-type="google" value="learnlm-2.0-flash-experimental">learnlm-2.0-flash-experimental</option>
<option data-type="google" value="gemini-robotics-er-1.5-preview">gemini-robotics-er-1.5-preview</option>
<option data-type="google" value="gemma-4-31b-it">gemma-4-31b-it</option>
@@ -158,19 +142,22 @@
<option data-type="google" value="gemma-3-27b-it">gemma-3-27b-it</option>
<option data-type="google" value="gemma-3-12b-it">gemma-3-12b-it</option>
<option data-type="google" value="gemma-3-4b-it">gemma-3-4b-it</option>
<option data-type="vertexai" value="gemini-3.8-flash">gemini-3.8-flash</option>
<option data-type="vertexai" value="gemini-3.7-flash">gemini-3.7-flash</option>
<option data-type="vertexai" value="gemini-3.6-flash">gemini-3.6-flash</option>
<option data-type="vertexai" value="gemini-3.5-flash">gemini-3.5-flash</option>
<option data-type="vertexai" value="gemini-3.5-flash-lite">gemini-3.5-flash-lite</option>
<option data-type="vertexai" value="gemini-3.1-pro-preview">gemini-3.1-pro-preview</option>
<option data-type="vertexai" value="gemini-3.1-flash-lite-preview">gemini-3.1-flash-lite-preview</option>
<option data-type="vertexai" value="gemini-3.1-flash-image-preview">gemini-3.1-flash-image-preview</option>
<option data-type="vertexai" value="gemini-3-pro-preview">gemini-3-pro-preview</option>
<option data-type="vertexai" value="gemini-3-pro-image-preview">gemini-3-pro-image-preview</option>
<option data-type="vertexai" value="gemini-3.1-flash-lite">gemini-3.1-flash-lite</option>
<option data-type="vertexai" value="gemini-3.1-flash-image">gemini-3.1-flash-image</option>
<option data-type="vertexai" value="gemini-3-pro-image">gemini-3-pro-image</option>
<option data-type="vertexai" value="gemini-3-flash-preview">gemini-3-flash-preview</option>
<option data-type="vertexai" value="gemini-2.5-pro">gemini-2.5-pro</option>
<option data-type="vertexai" value="gemini-2.5-flash">gemini-2.5-flash</option>
<option data-type="vertexai" value="gemini-2.5-flash-lite">gemini-2.5-flash-lite</option>
<option data-type="vertexai" value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
<option data-type="vertexai" value="gemini-2.5-flash-image-preview">gemini-2.5-flash-image-preview</option>
<option data-type="vertexai" value="gemini-2.0-flash-001">gemini-2.0-flash-001</option>
<option data-type="vertexai" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001</option>
<option data-type="vertexai" value="gemini-2.0-flash-001">gemini-2.0-flash-001 (deprecated)</option>
<option data-type="vertexai" value="gemini-2.0-flash-lite-001">gemini-2.0-flash-lite-001 (deprecated)</option>
<option data-type="groq" value="meta-llama/llama-4-scout-17b-16e-instruct">meta-llama/llama-4-scout-17b-16e-instruct</option>
<option data-type="groq" value="meta-llama/llama-4-maverick-17b-128e-instruct">meta-llama/llama-4-maverick-17b-128e-instruct</option>
<option data-type="ollama" value="ollama_current" data-i18n="currently_selected">[Currently selected]</option>
+180 -35
View File
@@ -18,6 +18,8 @@ import { generateWebLlmChatPrompt, isWebLlmSupported } from '../shared.js';
import { Popup, POPUP_RESULT } from '../../popup.js';
import { t } from '../../i18n.js';
import { removeReasoningFromString } from '../../reasoning.js';
import { macros } from '../../macros/macro-system.js';
import { MacrosParser } from '/scripts/macros.js';
export { MODULE_NAME };
/**
@@ -103,6 +105,19 @@ let lastServerResponseTime = 0;
/** @type {{[characterName: string]: string}} */
export let lastExpression = {};
/**
* Gets the current fallback expression, including the labels for when it is not set
* @returns {string|null}
*/
function getCurrentFallbackExpression() {
const expression = extension_settings?.expressions.fallback_expression;
const showEmojis = extension_settings?.expressions?.showDefault;
if (!expression && showEmojis) return OPTION_EMOJI_FALLBACK;
if (!expression) return OPTION_NO_FALLBACK;
return expression;
}
/**
* Returns a placeholder image object for a given expression
* @param {string} expression - The expression label
@@ -786,13 +801,48 @@ async function setSpriteSlashCommand({ type }, searchTerm) {
return label;
}
/**
* Get all the currently set expression labels.
* @param {Object} args
* @param {'true'|'false'|'only'} [args.custom] - Whether to filter out or return only custom expressions
* @param {'true'|'false'} [args.filter] - Filter the list to only include expressions that have available sprites for the current character
* @param {import('../../slash-commands/SlashCommandReturnHelper.js').SlashCommandReturnType} [args.return] - In which format must the expressions be returned
* @param {string} characterName
* @returns {Promise<string>}
*/
async function getExpressionListSlashCommand(args, characterName) {
const { custom, filter = 'true', return: returnType = 'pipe' } = args;
const expressions = await getExpressionsList({ filterAvailable: !isFalseBoolean(filter) });
const customExpressions = extension_settings?.expressions?.custom || [];
const expressionsMap = {
default: expressions.filter(expression => !customExpressions.includes(expression)),
custom: customExpressions,
all: expressions,
};
let expressionIndex = 'all';
if (custom === 'false') expressionIndex = 'default';
if (custom === 'only') expressionIndex = 'custom';
try {
return await slashCommandReturnHelper.doReturn(returnType, expressionsMap[expressionIndex], {
objectToStringFunc: list => list.join(', '),
});
} catch (err) {
console.error(err);
return '';
}
}
/**
* @param {string} expressionName - Label of the expression to set as fallback
*/
function setFallBackExpressionSlashCommand(args, expressionName) {
expressionName = expressionName.trim().toLowerCase();
if (!expressionName) return extension_settings?.expressions?.fallback_expression || '';
if (!expressionName) return getCurrentFallbackExpression();
const select = /** @type {HTMLSelectElement} */(document.getElementById('expression_fallback'));
const fallbackExpressions = Array
@@ -1151,15 +1201,24 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
}
}
function getLastCharacterMessage() {
/**
* @param {Object} [options]
* @param {string} [options.characterName] Filters last message to the one of the target character
*/
function getLastCharacterMessage({ characterName = '' } = {}) {
const context = getContext();
const reversedChat = context.chat.slice().reverse();
const ignoreCharName = !characterName;
for (let mes of reversedChat) {
if (mes.is_user || mes.is_system || mes.extra?.type === system_message_types.NARRATOR) {
continue;
}
if (!ignoreCharName && mes.name !== characterName) {
continue;
}
return { mes: mes.mes, name: mes.name, original_avatar: mes.original_avatar, force_avatar: mes.force_avatar };
}
@@ -1463,6 +1522,30 @@ export async function getExpressionsList({ filterAvailable = false } = {}) {
}
}
/**
* Gets the last expression used in the chat by the active character.
* @param {Object} [options]
* @param {string} [options.characterName] Filters last expression to the one of the target character instead
* @returns {string}
*/
function getLastExpression({ characterName = '' } = {}) {
if (typeof characterName !== 'string') throw new Error('Character name must be a string');
if (!characterName) {
characterName = characters[this_chid]?.avatar || '';
}
const char = findChar({ name: characterName, quiet: true });
const currentLastMessage = getLastCharacterMessage({ characterName });
const finalCharacterName = currentLastMessage?.name ?? char?.name ?? characterName;
const spriteFolderName = getSpriteFolderName(currentLastMessage, finalCharacterName);
const sprite = lastExpression[spriteFolderName.split('/')[0]] ?? '';
return sprite;
}
/**
* Selects a sprite from the given sprite folder for the given expression.
*
@@ -1634,8 +1717,10 @@ async function setExpression(spriteFolderName, expression, { force = false, over
* @param {string} expression - The expression label to use for the default image
*/
function setDefaultEmojiForImage(img, expression) {
if (extension_settings.expressions.custom?.includes(expression)) {
console.debug(`Can't set default emoji for a custom expression (${expression}). setting to ${DEFAULT_FALLBACK_EXPRESSION} instead.`);
// Classifiers can return a falsy, literal "null"/"undefined", or otherwise unknown label,
// and custom expressions have no default assets; only known labels have an image (#5863).
if (!DEFAULT_EXPRESSIONS.includes(expression)) {
console.debug(`Can't set default emoji for expression (${expression}). setting to ${DEFAULT_FALLBACK_EXPRESSION} instead.`);
expression = DEFAULT_FALLBACK_EXPRESSION;
}
@@ -2351,15 +2436,15 @@ export async function init() {
typeList: [ARGUMENT_TYPE.STRING],
isRequired: false,
enumProvider: () => [
new SlashCommandEnumValue('#none', 'Sets the fallback expression to no image'),
new SlashCommandEnumValue('#emoji', 'Sets the fallback expression to emojis'),
new SlashCommandEnumValue(OPTION_NO_FALLBACK, 'Sets the fallback expression to no image'),
new SlashCommandEnumValue(OPTION_EMOJI_FALLBACK, 'Sets the fallback expression to emojis'),
...localEnumProviders.expressions(),
],
}),
],
helpString: `
<div>
Gets the currently selected expression fallback for all characters.<br />
Gets the currently selected global fallback expression.<br />
If a valid expression label is sent, it will be set as the new fallback.
</div>
<div>
@@ -2410,23 +2495,8 @@ export async function init() {
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'expression-last',
aliases: ['lastsprite'],
/** @type {(args: object, name: string) => Promise<string>} */
callback: async (_, name) => {
if (typeof name !== 'string') throw new Error('name must be a string');
if (!name) {
if (selected_group) {
toastr.error(t`In group chats, you must specify a character name.`, t`No character name specified`);
return '';
}
name = characters[this_chid]?.avatar;
}
const char = findChar({ name: name });
if (!char) toastr.warning(t`Couldn't find character ${name}.`, t`Character not found`);
const sprite = lastExpression[char?.name ?? name] ?? '';
return sprite;
},
/** @type {(args: object, name: string) => string} */
callback: (_, name) => getLastExpression({ characterName: (name || '') }),
returns: 'the last set expression for the named character.',
unnamedArgumentList: [
SlashCommandArgument.fromProps({
@@ -2440,23 +2510,14 @@ export async function init() {
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'expression-list',
aliases: ['expressions'],
/** @type {(args: {return: string, filter: string}) => Promise<string>} */
callback: async (args) => {
let returnType =
/** @type {import('../../slash-commands/SlashCommandReturnHelper.js').SlashCommandReturnType} */
(args.return);
const list = await getExpressionsList({ filterAvailable: !isFalseBoolean(args.filter) });
return await slashCommandReturnHelper.doReturn(returnType ?? 'pipe', list, { objectToStringFunc: list => list.join(', ') });
},
callback: getExpressionListSlashCommand,
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'return',
description: 'The way how you want the return value to be provided',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: 'pipe',
enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
enumList: slashCommandReturnHelper.enumList({ allowObject: true, allowPopup: true }),
forceEnum: true,
}),
SlashCommandNamedArgument.fromProps({
@@ -2466,6 +2527,21 @@ export async function init() {
enumList: commonEnumProviders.boolean('trueFalse')(),
defaultValue: 'true',
}),
SlashCommandNamedArgument.fromProps({
name: 'custom',
description: t`Whether to include, filter out or return only custom expressions`,
typeList: [
ARGUMENT_TYPE.STRING,
ARGUMENT_TYPE.BOOLEAN,
],
isRequired: false,
defaultValue: 'true',
enumList: [
new SlashCommandEnumValue('true', '(default) Custom expressions will be included in the result'),
new SlashCommandEnumValue('false', 'Custom expressions will not be included in the result'),
new SlashCommandEnumValue('only', 'Only custom expressions will be included in the result'),
],
}),
],
returns: 'The comma-separated list of available expressions, including custom expressions.',
helpString: 'Returns a list of available expressions, including custom expressions.',
@@ -2573,4 +2649,73 @@ export async function init() {
</div>
`,
}));
if (power_user.experimental_macro_engine) {
macros.register('defaultExpression', {
handler: getCurrentFallbackExpression,
category: macros.category.MISC,
description: 'Returns the global fallback expression.',
returns: 'Expression label',
exampleUsage: '{{defaultExpression}}',
});
macros.register('lastExpression', {
handler: function ({ args: [name = '{{char}}'], resolve }) {
try {
return getLastExpression({ characterName: resolve(name || '') });
} catch (error) {
console.error(error);
return '';
}
},
unnamedArgs: [{
name: 'name',
description: 'The name of the target character',
defaultValue: '{{char}}',
optional: true,
type: macros.valueType.STRING,
}],
delayArgResolution: true,
category: macros.category.MISC,
description: 'Returns the last expression used by the selected character. The currently active character is used if no character name is provided.',
returns: 'Expression label',
exampleUsage: [
'{{lastExpression}}',
'{{lastExpression::John}}',
'{{lastExpression::{{char}}}}',
],
});
macros.register('availableExpressions', {
handler: function () {
return getCachedExpressions().join(', ');
},
category: macros.category.MISC,
description: 'Returns a list with all the available expressions provided by the Classifier API.',
returns: 'Expression label list',
exampleUsage: '{{availableExpressions}}',
});
} else {
MacrosParser.registerMacro('defaultExpression',
getCurrentFallbackExpression,
t`Returns the global fallback expression.`,
);
MacrosParser.registerMacro('lastExpression',
() => {
try {
return getLastExpression();
} catch (error) {
console.error(error);
return '';
}
},
t`Returns the last expression used.`,
);
MacrosParser.registerMacro('availableExpressions',
() => getCachedExpressions().join(', '),
t`Returns a list with all the available expressions provided by the Classifier API.`,
);
}
}
@@ -381,7 +381,7 @@ export class SettingsUi {
if (name && name.length > 0) {
const oldQrs = QuickReplySet.get(name);
if (oldQrs) {
const replace = Popup.show.confirm('Replace existing World Info', `A Quick Reply Set named "${name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
const replace = await Popup.show.confirm('Replace existing Quick Reply set', `A Quick Reply Set named "${name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
if (replace) {
const idx = QuickReplySet.list.indexOf(oldQrs);
await this.doDeleteQrSet(oldQrs);
@@ -444,7 +444,7 @@ export class SettingsUi {
qrs.init();
const oldQrs = QuickReplySet.get(props.name);
if (oldQrs) {
const replace = Popup.show.confirm('Replace existing World Info', `A Quick Reply Set named "${name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
const replace = await Popup.show.confirm('Replace existing Quick Reply set', `A Quick Reply Set named "${props.name}" already exists.<br>Do you want to overwrite the existing Quick Reply Set?<br>The existing set will be deleted. This cannot be undone.`);
if (replace) {
const idx = QuickReplySet.list.indexOf(oldQrs);
await this.doDeleteQrSet(oldQrs);
+11 -6
View File
@@ -1,7 +1,7 @@
import { CONNECT_API_MAP, createModelIcon, getRequestHeaders } from '../../script.js';
import { CONNECT_API_MAP, createModelIcon, getRequestHeaders, substituteParams } from '../../script.js';
import { extension_settings, openThirdPartyExtensionMenu } from '../extensions.js';
import { t } from '../i18n.js';
import { oai_settings, proxies, ZAI_ENDPOINT } from '../openai.js';
import { oai_settings, proxies, ZAI_ENDPOINT, POLLINATIONS_ENDPOINT } from '../openai.js';
import { SECRET_KEYS, secret_state } from '../secrets.js';
import { textgen_types, textgenerationwebui_settings } from '../textgen-settings.js';
import { getTokenCountAsync } from '../tokenizers.js';
@@ -117,15 +117,19 @@ export async function getMultimodalCaption(base64Img, prompt) {
}
requestBody.server_url = oai_settings.custom_url;
requestBody.custom_include_headers = oai_settings.custom_include_headers;
requestBody.custom_include_body = oai_settings.custom_include_body;
requestBody.custom_exclude_body = oai_settings.custom_exclude_body;
requestBody.custom_include_headers = substituteParams(oai_settings.custom_include_headers);
requestBody.custom_include_body = substituteParams(oai_settings.custom_include_body);
requestBody.custom_exclude_body = substituteParams(oai_settings.custom_exclude_body);
}
if (extension_settings.caption.multimodal_api === 'zai') {
requestBody.zai_endpoint = oai_settings.zai_endpoint || ZAI_ENDPOINT.COMMON;
}
if (extension_settings.caption.multimodal_api === 'pollinations') {
requestBody.pollinations_endpoint = oai_settings.pollinations_endpoint || POLLINATIONS_ENDPOINT.AUTHENTICATED;
}
if (extension_settings.caption.multimodal_api === 'workers_ai') {
requestBody.workers_ai_account_id = oai_settings.workers_ai_account_id;
}
@@ -284,7 +288,7 @@ function throwIfInvalidModel(useReverseProxy) {
throw new Error('Z.AI API key is not set.');
}
if (multimodalApi === 'pollinations' && !secret_state[SECRET_KEYS.POLLINATIONS]) {
if (multimodalApi === 'pollinations' && oai_settings.pollinations_endpoint !== POLLINATIONS_ENDPOINT.ANONYMOUS && !secret_state[SECRET_KEYS.POLLINATIONS]) {
throw new Error('Pollinations API key is not set.');
}
@@ -449,6 +453,7 @@ export class ConnectionManagerRequestService {
zai_endpoint: profile['api-url'],
siliconflow_endpoint: profile['api-url'],
minimax_endpoint: profile['api-url'],
pollinations_endpoint: profile['api-url'],
reverse_proxy: proxyPreset?.url,
proxy_password: proxyPreset?.password,
custom_prompt_post_processing: profile['prompt-post-processing'],
@@ -344,7 +344,7 @@
<div data-sd-source="bfl">
<div class="flex-container flexnowrap alignItemsBaseline marginBot5">
<a href="https://api.bfl.ml/" target="_blank" rel="noopener noreferrer">
<a href="https://api.bfl.ai/" target="_blank" rel="noopener noreferrer">
<strong data-i18n="API Key">API Key</strong>
<i class="fa-solid fa-share-from-square"></i>
</a>
@@ -12,7 +12,7 @@ export class GoogleNativeTtsProvider {
defaultSettings = {
voiceMap: {},
model: 'gemini-2.5-flash-preview-tts',
model: 'gemini-3.1-flash-tts-preview',
apiType: 'makersuite',
};
@@ -32,6 +32,7 @@ export class GoogleNativeTtsProvider {
<select id="google-tts-model">
<option value="gemini-2.5-flash-preview-tts">Gemini 2.5 Flash Preview TTS</option>
<option value="gemini-2.5-pro-preview-tts">Gemini 2.5 Pro Preview TTS</option>
<option value="gemini-3.1-flash-tts-preview">Gemini 3.1 Flash TTS Preview</option>
</select>
</div>
</div>`;
+8 -14
View File
@@ -55,10 +55,6 @@ class MiniMaxTtsProvider {
<i class="fa-solid fa-key"></i>
<span>Click to set API Key</span>
</div>
<div id="minimax_group_id" class="menu_button menu_button_icon manage-api-keys" data-key="minimax_group_id">
<i class="fa-solid fa-key"></i>
<span>Click to set Group ID</span>
</div>
</div>
<div class="tts_block">
<label for="minimax_tts_api_host">API Host</label>
@@ -173,9 +169,8 @@ class MiniMaxTtsProvider {
constructor() {
this.handler = async function (/** @type {string} */ key) {
if (![SECRET_KEYS.MINIMAX, SECRET_KEYS.MINIMAX_GROUP_ID].includes(key)) return;
if (key !== SECRET_KEYS.MINIMAX) return;
$('#api_key_minimax').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX]);
$('#minimax_group_id').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]);
await this.onRefreshClick();
}.bind(this);
}
@@ -588,13 +583,12 @@ class MiniMaxTtsProvider {
}
$('#api_key_minimax').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX]);
$('#minimax_group_id').toggleClass('success', !!secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]);
[event_types.SECRET_WRITTEN, event_types.SECRET_DELETED, event_types.SECRET_ROTATED].forEach(event => {
eventSource.on(event, this.handler);
});
// Only check ready status when API credentials are available
if (secret_state[SECRET_KEYS.MINIMAX] && secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
if (secret_state[SECRET_KEYS.MINIMAX]) {
try {
await this.checkReady();
console.debug('MiniMax TTS: Settings loaded and ready');
@@ -608,8 +602,8 @@ class MiniMaxTtsProvider {
// Perform a simple readiness check
async checkReady() {
if (!secret_state[SECRET_KEYS.MINIMAX] || !secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
const error = new Error('API Key and Group ID are required');
if (!secret_state[SECRET_KEYS.MINIMAX]) {
const error = new Error('API Key is required');
console.error('MiniMax TTS checkReady error:', error.message);
throw error;
}
@@ -709,8 +703,8 @@ class MiniMaxTtsProvider {
async fetchTtsVoiceObjects() {
try {
if (!secret_state[SECRET_KEYS.MINIMAX] || !secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
console.warn('MiniMax TTS: API Key and Group ID required for fetching voices');
if (!secret_state[SECRET_KEYS.MINIMAX]) {
console.warn('MiniMax TTS: API Key required for fetching voices');
console.warn('Using all available voices (default + custom). Please check your API credentials');
return this.getAllVoices();
}
@@ -775,8 +769,8 @@ class MiniMaxTtsProvider {
async fetchTtsGeneration(inputText, voiceId, language = null) {
console.info(`Generating new MiniMax TTS for voice_id ${voiceId}`);
if (!secret_state[SECRET_KEYS.MINIMAX] || !secret_state[SECRET_KEYS.MINIMAX_GROUP_ID]) {
const error = new Error('API Key and Group ID are required');
if (!secret_state[SECRET_KEYS.MINIMAX]) {
const error = new Error('API Key is required');
console.error('MiniMax TTS fetchTtsGeneration error:', error.message);
throw error;
}
+3 -2
View File
@@ -1908,13 +1908,14 @@ async function uploadGroupAvatar(event) {
$('#dialogue_popup').addClass('large_dialogue_popup wide_dialogue_popup');
const croppedImage = await callGenericPopup('Set the crop position of the avatar image', POPUP_TYPE.CROP, '', { cropImage: result });
const croppedImage = power_user.never_resize_avatars ? result :
await callGenericPopup('Set the crop position of the avatar image', POPUP_TYPE.CROP, '', { cropImage: result });
if (!croppedImage) {
return;
}
let thumbnail = await createThumbnail(String(croppedImage), 200, 300);
let thumbnail = await createThumbnail(String(croppedImage), 300, 300);
//remove data:image/whatever;base64
thumbnail = thumbnail.replace(/^data:image\/[a-z]+;base64,/, '');
let _thisGroup = groups.find((x) => x.id == openGroupId);
@@ -289,8 +289,8 @@ export function registerCoreMacros() {
description: 'Any kind of text as comment. If you want multiline comments, consider using a scoped macro like {{//}}First\nSecond{{///}}.',
},
],
list: true, // We consume any arguments as if this is a list, but we'll ignore them in the handler anyway
strictArgs: false, // and we also always remove it, even if the parsing might say it's invalid
// list: true, // We consume any arguments as if this is a list, but we'll ignore them in the handler anyway
// strictArgs: false, // and we also always remove it, even if the parsing might say it's invalid
description: 'Comment macro that produces an empty string. Can be used for writing into prompt definitions, without being passed to the context.',
returns: '',
displayOverride: '{{// ...}}',
@@ -155,6 +155,62 @@ export function registerVariableMacros() {
},
});
// {{setvarkey::name::key::value}} -> ''
MacroRegistry.registerMacro('setvarkey', {
aliases: [{ alias: 'setvarindex' }],
category: MacroCategory.VARIABLE,
unnamedArgs: [
{
name: 'name',
type: MacroValueType.STRING,
description: 'The name of the local object or array.',
},
{
name: 'key',
type: [MacroValueType.STRING, MacroValueType.NUMBER],
description: 'The key of an object or the index of an array.',
},
{
name: 'value',
type: [MacroValueType.STRING, MacroValueType.NUMBER],
description: 'The value to set at the specified key or index.',
},
],
description: 'Sets a value at a specific key or index in a local object or array. If the variable does not exist, it will be created based on the type of the key.',
returns: '',
exampleUsage: ['{{setvarkey::myarray::0::foo}}', '{{setvarkey::myobj::uniquekey::somevalue}}'],
handler: ({ unnamedArgs: [name, key, value] }) => {
ctx.variables.local.set(name, value, { index: key });
return '';
},
});
// {{getvarkey::name::key}} -> returns value at key
MacroRegistry.registerMacro('getvarkey', {
aliases: [{ alias: 'getvarindex' }],
category: MacroCategory.VARIABLE,
unnamedArgs: [
{
name: 'name',
type: MacroValueType.STRING,
description: 'The name of the local object or array variable to get from.',
},
{
name: 'key',
type: [MacroValueType.STRING, MacroValueType.NUMBER],
description: 'The key of an object or the index of an array.',
},
],
description: 'Gets a value at a specific key or index in a local object or array variable.',
returns: 'The value at the specified key or index in the local object or array variable.',
returnType: [MacroValueType.STRING, MacroValueType.NUMBER],
exampleUsage: ['{{getvarkey::myarray::0}}', '{{getvarkey::myobj::uniquekey}}'],
handler: ({ unnamedArgs: [name, key], normalize }) => {
const result = ctx.variables.local.get(name, { index: key });
return normalize(result);
},
});
// {{setglobalvar::name::value}} -> ''
MacroRegistry.registerMacro('setglobalvar', {
category: MacroCategory.VARIABLE,
@@ -302,4 +358,60 @@ export function registerVariableMacros() {
return '';
},
});
// {{setglobalvarkey::name::key::value}} -> ''
MacroRegistry.registerMacro('setglobalvarkey', {
aliases: [{ alias: 'setglobalvarindex' }],
category: MacroCategory.VARIABLE,
unnamedArgs: [
{
name: 'name',
type: MacroValueType.STRING,
description: 'The name of the global object or array variable.',
},
{
name: 'key',
type: [MacroValueType.STRING, MacroValueType.NUMBER],
description: 'The key of an object or the index of an array element to set.',
},
{
name: 'value',
type: [MacroValueType.STRING, MacroValueType.NUMBER],
description: 'The value to set at the specified key or index.',
},
],
description: 'Sets a value at a specific key or index in a global object or array variable. If the variable does not exist, it will be created based on the type of the key.',
returns: '',
exampleUsage: ['{{setglobalvarkey::myarray::0::foo}}', '{{setglobalvarkey::myobj::uniquekey::bar}}'],
handler: ({ unnamedArgs: [name, key, value] }) => {
ctx.variables.global.set(name, value, { index: key });
return '';
},
});
// {{getglobalvarkey::name::key}} -> returns value at key
MacroRegistry.registerMacro('getglobalvarkey', {
aliases: [{ alias: 'getglobalvarindex' }],
category: MacroCategory.VARIABLE,
unnamedArgs: [
{
name: 'name',
type: MacroValueType.STRING,
description: 'The name of the global object or array variable to get from.',
},
{
name: 'key',
type: [MacroValueType.STRING, MacroValueType.NUMBER],
description: 'The key of an object or the index of an array element to get.',
},
],
description: 'Gets a value at a specific key or index in a global object or array variable.',
returns: 'The value at the specified key or index in the global object or array variable.',
returnType: [MacroValueType.STRING, MacroValueType.NUMBER],
exampleUsage: ['{{getglobalvarkey::myarray::0}}', '{{getglobalvarkey::myobj::uniquekey}}'],
handler: ({ unnamedArgs: [name, key], normalize }) => {
const result = ctx.variables.global.get(name, { index: key });
return normalize(result);
},
});
}
+45 -33
View File
@@ -189,7 +189,21 @@ class MacroCstWalker {
// Check for closing block flag
const flagTokens = /** @type {IToken[]} */ (children.flags || []);
const isClosing = flagTokens.some(token => token.image === MacroFlagType.CLOSING_BLOCK);
let isClosing = flagTokens.some(token => token.image === MacroFlagType.CLOSING_BLOCK);
// Special case for the comment macro (//):
// The lexer always greedily tokenizes '//' before a single '/', so {{///}} is parsed as
// {{// /}} (comment with arg '/') rather than {{/ //}} (closing block for //).
// We detect this by checking if the '//' macro's positionally-first argument token starts with '/'.
if (!isClosing && name === '//') {
const firstArgNode = /** @type {CstNode?} */ ((argumentNodes || [])[0]);
if (firstArgNode) {
const firstToken = this.#getFirstTokenInNode(firstArgNode);
if (firstToken?.image?.startsWith('/')) {
isClosing = true;
}
}
}
return {
name,
@@ -227,7 +241,7 @@ class MacroCstWalker {
for (const item of items) {
if (item.type !== 'macro') continue;
const info = this.#extractMacroInfo(item.node);
const info = this.extractMacroInfo(item.node);
if (!info) continue;
if (info.isClosing) {
@@ -1098,6 +1112,34 @@ class MacroCstWalker {
return !!value && typeof value === 'object' && 'name' in value && 'children' in value;
}
/**
* Returns the positionally-first leaf token (by startOffset) across all children of a CST node.
* Chevrotain groups tokens by type in the children object, so we must scan all type arrays
* and pick the token with the smallest startOffset rather than assuming any one array is ordered first.
*
* @param {CstNode} node
* @returns {IToken|null}
*/
#getFirstTokenInNode(node) {
const children = node?.children || {};
/** @type {IToken|null} */
let first = null;
for (const key of Object.keys(children)) {
for (const element of children[key] || []) {
// Skip CST nodes (nested rules) — we only want leaf tokens
if (this.#isCstNode(element)) continue;
const token = /** @type {IToken} */ (element);
if (typeof token.startOffset !== 'number' || isNaN(token.startOffset)) continue;
if (first === null || token.startOffset < first.startOffset) {
first = token;
}
}
}
return first;
}
/**
* Evaluates scoped content between an opening and closing macro tag.
* This resolves any nested macros within the scoped content.
@@ -1146,7 +1188,7 @@ class MacroCstWalker {
const item = items[i];
if (item.type !== 'macro') continue;
const info = this.#extractMacroInfo(item.node);
const info = this.extractMacroInfo(item.node);
if (!info) continue;
macroInfos.push({
@@ -1254,36 +1296,6 @@ class MacroCstWalker {
return items.filter((_, index) => !itemsToRemove.has(index));
}
/**
* Extracts macro name and closing flag status from a macro node.
*
* @param {CstNode} macroNode
* @returns {{ name: string, isClosing: boolean } | null}
*/
#extractMacroInfo(macroNode) {
const children = macroNode.children || {};
// Check if this is a variable expression - they can't be scoped
const variableExprNode = (children.variableExpr || [])[0];
if (variableExprNode) {
return null; // Variable expressions don't support scoped content
}
// Regular macro - get info from macroBody
const macroBodyNode = /** @type {CstNode?} */ ((children.macroBody || [])[0]);
const bodyChildren = macroBodyNode?.children || {};
const identifierTokens = /** @type {IToken[]} */ (bodyChildren['Macro.identifier'] || []);
const name = identifierTokens[0]?.image || '';
if (!name) return null;
// Check for closing block flag (inside macroBody)
const flagTokens = /** @type {IToken[]} */ (children.flags || []);
const isClosing = flagTokens.some(token => token.image === MacroFlagType.CLOSING_BLOCK);
return { name, isClosing };
}
/**
* Checks if a macro can accept scoped content as an additional argument.
+7 -2
View File
@@ -214,11 +214,16 @@ const Def = {
// Macro args allow nested macros
enter(Tokens.Macro.Start, modes.macro_def),
// PIPE/FILTER FEATURE DISABLED: Lines below commented out until pipe/filter feature is fully implemented.
// Currently, having these active breaks macros that use | as a regular character in argument values (e.g., {{setvar::foo::|bar}})
// See: https://github.com/SillyTavern/SillyTavern/issues/5618
// TODO: Re-enable when filter flag (>) logic is properly implemented to conditionally enable pipe parsing
// We allow escaped pipes to not start output modifiers. We need to capture this first, before the pipe
using(Tokens.Filter.EscapedPipe),
// using(Tokens.Filter.EscapedPipe),
// If at any place during args writing there is a pipe, we lex it as an output identifier, and then continue with lex its args
enter(Tokens.Filter.Pipe, modes.macro_filter_modifer),
// enter(Tokens.Filter.Pipe, modes.macro_filter_modifer),
using(Tokens.Args.DoubleColon),
using(Tokens.Args.Colon),
+1
View File
@@ -52,6 +52,7 @@ export const macros = {
// enums
category: MacroCategory,
valueType: MacroValueType,
// shorthand functions
register: MacroRegistry.registerMacro.bind(MacroRegistry),
+259
View File
@@ -0,0 +1,259 @@
import { messageFormatting } from '../script.js';
/**
* Pipeline stages at which extension hooks may run.
* All stages occur **before** DOMPurify sanitization so output is always safe.
*
* - `BEFORE_REGEX` – Raw message text, after prompt-bias stripping but before
* custom regex rules are applied. Suitable for transforms
* that should be invisible to regex rules.
* - `AFTER_REGEX` – After custom regex rules, before Markdown conversion.
* The text is still plain Markdown at this point.
* - `AFTER_MARKDOWN` – After Markdown-to-HTML conversion (showdown), before
* DOMPurify. The value is an HTML string. This is the
* **default** stage and the most common insertion point
* for extensions that want to annotate rendered HTML (e.g.
* adding ruby tags, tooltips, highlights).
*
* > There is intentionally no post-sanitize stage.
* > All hooks run before DOMPurify so their output is always sanitized along
* > with the rest of the message. If your hook inserts HTML, make sure it is
* > safe to pass through DOMPurify (i.e. avoid `<script>` tags and inline
* > event handlers — they will be stripped anyway, but it is still bad
* > practice to produce them).
*
* @enum {string}
*/
export const formatting_stage = {
BEFORE_REGEX: 'beforeRegex',
AFTER_REGEX: 'afterRegex',
AFTER_MARKDOWN: 'afterMarkdown',
};
/**
* @typedef {formatting_stage[keyof formatting_stage]} MessageFormattingStage
*/
/**
* Message metadata supplied by {@link messageFormatting} to {@link MessageFormatter#runStage}.
* Does not include `stage` — that is injected by `runStage` itself.
*
* @typedef {Object} MessageFormattingBase
* @property {string} characterName - Character name associated with the message.
* @property {boolean} isSystem - Whether the message is a system message.
* @property {boolean} isUser - Whether the message was sent by the user.
* @property {number} messageId - Index of the message in the chat array, or -1 for transient messages (e.g. streaming previews).
* @property {boolean} isReasoning - Whether the message is reasoning/thinking output.
*/
/**
* Immutable context object passed to every formatting hook.
* Built from {@link MessageFormattingBase} with `stage` added and the whole
* object frozen by {@link MessageFormatter#runStage}.
*
* @typedef {Readonly<MessageFormattingBase & { stage: MessageFormattingStage }>} MessageFormattingContext
*/
/**
* A formatting hook function.
* Receives the current message text (plain Markdown or HTML, depending on
* the stage) and an immutable context object. Must return the (possibly
* modified) message text **synchronously** as a `string`. Passing an async
* function to {@link MessageFormatter#addHook} will throw a `TypeError` at
* registration time. If a hook returns a non-string at runtime, a console
* warning is emitted and the return value is ignored (the pipeline continues
* with the previous text unchanged).
*
* @callback MessageFormattingHook
* @param {string} mes - Current message text at this pipeline stage.
* @param {MessageFormattingContext} ctx - Immutable metadata about the message.
* @returns {string} The (possibly transformed) message text.
*/
/**
* Options accepted by {@link MessageFormatter#addHook}.
*
* @typedef {Object} AddHookOptions
* @property {hook_order|number} [order=hook_order.NORMAL] - Numeric priority within the stage.
* Lower numbers run first. Use the exported {@link hook_order} constants for readable values.
*/
/**
* Ordering buckets for formatting hooks.
* Use these when calling {@link MessageFormatter#addHook} to express
* intent rather than bare numbers.
*
* @enum {number}
*/
export const hook_order = {
EARLIEST: 0,
EARLY: 10,
NORMAL: 50,
LATE: 90,
LATEST: 100,
};
/** @type {MessageFormatter} */
let instance;
/**
* Singleton instance of {@link MessageFormatter}.
* Exported under the class name so callers can write
* `import { MessageFormatter } from './message-formatter.js'`
* and use it directly.
*
* @type {MessageFormatter}
*/
export { instance as MessageFormatter };
/**
* Manages the message-formatting pipeline and exposes registration points
* for extensions that need to transform message text before it reaches the
* DOM.
*
* Extensions should obtain the singleton via `getContext().messageFormatter`
* and call {@link MessageFormatter#addHook} once during their init phase.
*
* @example
* // In your extension's init function:
* const { messageFormatter } = getContext();
* messageFormatter.addHook((mes, ctx) => {
* if (ctx.isUser) return mes;
* return addFurigana(mes);
* });
*
* // With an explicit stage and order (using the enum accessors on the singleton):
* const { messageFormatter } = getContext();
* messageFormatter.addHook((mes, ctx) => transform(mes), {
* stage: messageFormatter.stage.AFTER_REGEX,
* order: messageFormatter.order.EARLY,
* });
*/
class MessageFormatter {
/** @type {MessageFormatter} */
static #instance;
/** @returns {MessageFormatter} */
static get instance() {
return MessageFormatter.#instance ?? (MessageFormatter.#instance = new MessageFormatter());
}
/**
* Internal storage: one sorted bucket per stage.
*
* @type {Map<MessageFormattingStage, { fn: MessageFormattingHook, order: number }[]>}
*/
#hooks = new Map();
/**
* Exposes {@link formatting_stage} on the instance so extensions can
* access stage constants without a separate import.
* @type {typeof formatting_stage}
* @readonly
*/
stage = formatting_stage;
/**
* Exposes {@link hook_order} on the instance so extensions can
* access order constants without a separate import.
* @type {typeof hook_order}
* @readonly
*/
order = hook_order;
constructor() {
this.#hooks.set(formatting_stage.BEFORE_REGEX, []);
this.#hooks.set(formatting_stage.AFTER_REGEX, []);
this.#hooks.set(formatting_stage.AFTER_MARKDOWN, []);
}
/**
* Registers a hook function to run at a specific pipeline stage.
*
* Should be called once during the extension's init/setup phase.
* Hooks are applied in ascending `order` within each stage.
*
* @param {MessageFormattingHook} fn - The hook function.
* @param {AddHookOptions & { stage?: MessageFormattingStage }} [options={}]
* Options object. `stage` defaults to `'afterMarkdown'`; `order` defaults to `50`.
* @returns {void}
*
* @throws {TypeError} If `fn` is not a function or is an async function.
* @throws {RangeError} If `stage` is not a known {@link formatting_stage} value.
*/
addHook(fn, { stage = formatting_stage.AFTER_MARKDOWN, order = hook_order.NORMAL } = {}) {
if (typeof fn !== 'function') throw new TypeError('MessageFormatter: hook must be a function');
if (fn.constructor?.name === 'AsyncFunction') throw new TypeError(`MessageFormatter: hook registered for stage '${stage}' must be synchronous — async functions are not supported`);
if (!this.#hooks.has(stage)) throw new RangeError(`MessageFormatter: unknown stage '${stage}'`);
this.#hooks.get(stage).push({ fn, order });
}
/**
* Runs all hooks registered for the given stage in order.
* Called internally by {@link messageFormatting} at each pipeline point.
* Extensions do not need to call this directly.
*
* @param {MessageFormattingStage} stage - The pipeline stage to execute.
* @param {string} mes - Current message text.
* @param {MessageFormattingBase} base - Message metadata. `stage` is injected automatically.
* @returns {string} The message text after all hooks have been applied.
*/
runStage(stage, mes, base) {
const bucket = this.#hooks.get(stage);
if (!bucket?.length) return mes;
const ctx = Object.freeze({ ...base, stage });
const sorted = bucket.slice().sort((a, b) => a.order - b.order);
for (const { fn } of sorted) {
try {
const result = fn(mes, ctx);
if (typeof result !== 'string') {
console.warn(`[MessageFormatter] Hook at stage '${stage}' returned ${/** @type {unknown} */ (result) instanceof Promise ? 'a Promise (hook may be async)' : typeof result} instead of a string. The hook's return value has been ignored.`);
} else {
mes = result;
}
} catch (e) {
console.error(`[MessageFormatter] Hook error at stage '${stage}':`, e);
}
}
return mes;
}
/**
* Formats a message using the full pipeline (including all registered
* hooks). This is a convenience shim over the top-level
* {@link messageFormatting} function and accepts the same arguments.
*
* Extensions that already import `getContext()` can use this instead of
* importing `messageFormatting` directly from `script.js`.
*
* The pipeline is, in order:
* 1. Prompt-bias stripping (message 0 only)
* 2. Comment / hidden-message normalisation
* 3. `beforeRegex` extension hooks (see {@link MessageFormatter})
* 4. Custom regex rules (`getRegexedString`)
* 5. `afterRegex` extension hooks
* 6. Markdown auto-fix (`fixMarkdown`)
* 7. HTML tag encoding (`encode_tags`)
* 8. Showdown Markdown → HTML conversion
* 9. `afterMarkdown` extension hooks
* 10. Name-prefix stripping (`allow_name2_display`)
* 11. DOMPurify sanitization
*
* All extension hooks run **before** DOMPurify (steps 3, 5, 9) so their
* output is always sanitised.
*
* @param {string} mes - Raw message text.
* @param {string} characterName - Character name.
* @param {boolean} isSystem - Whether this is a system message.
* @param {boolean} isUser - Whether this was sent by the user.
* @param {number} messageId - Message index in the chat array.
* @param {Partial<import('dompurify').Config>} [sanitizerOverrides={}] - DOMPurify option overrides.
* @param {boolean} [isReasoning=false] - Whether this is reasoning output.
* @returns {string} Formatted HTML string ready for DOM insertion.
*/
format(mes, characterName, isSystem, isUser, messageId, sanitizerOverrides = {}, isReasoning = false) {
return messageFormatting(mes, characterName, isSystem, isUser, messageId, sanitizerOverrides, isReasoning);
}
}
instance = MessageFormatter.instance;
+2 -2
View File
@@ -205,7 +205,7 @@ export function loadNovelPreset(preset) {
nai_settings.logit_bias = preset.logit_bias || [];
nai_settings.preamble = preset.preamble || default_preamble;
nai_settings.min_p = preset.min_p || 0;
nai_settings.math1_temp = preset.math1_temp || 1;
nai_settings.math1_temp = preset.math1_temp ?? 1;
nai_settings.math1_quad = preset.math1_quad || 0;
nai_settings.math1_quad_entropy_scale = preset.math1_quad_entropy_scale || 0;
nai_settings.extensions = preset.extensions || {};
@@ -259,7 +259,7 @@ export function loadNovelSettings(data, settings) {
nai_settings.order = settings.order || default_order;
nai_settings.logit_bias = settings.logit_bias || [];
nai_settings.min_p = settings.min_p || 0;
nai_settings.math1_temp = settings.math1_temp || 1;
nai_settings.math1_temp = settings.math1_temp ?? 1;
nai_settings.math1_quad = settings.math1_quad || 0;
nai_settings.math1_quad_entropy_scale = settings.math1_quad_entropy_scale || 0;
nai_settings.extensions = settings.extensions || {};
+181 -30
View File
@@ -14,6 +14,7 @@ import {
extension_prompt_roles,
extension_prompt_types,
Generate,
getCurrentChatId,
getExtensionPrompt,
getExtensionPromptMaxDepth,
getMediaDisplay,
@@ -133,6 +134,7 @@ const max_200k = 200 * 1000;
const max_256k = 256 * 1000;
const max_400k = 400 * 1000;
const max_1mil = 1000 * 1000;
const max_1050k = 1050 * 1000;
const max_2mil = 2000 * 1000;
const unlocked_max = max_2mil;
const oai_max_temp = 2.0;
@@ -267,6 +269,11 @@ export const ZAI_ENDPOINT = {
CODING: 'coding',
};
export const POLLINATIONS_ENDPOINT = {
AUTHENTICATED: 'authenticated',
ANONYMOUS: 'anonymous',
};
export const SILICONFLOW_ENDPOINT = {
GLOBAL: 'global',
CN: 'cn',
@@ -335,6 +342,7 @@ export const settingsToUpdate = {
aimlapi_model: ['#model_aimlapi_select', 'aimlapi_model', false, true],
xai_model: ['#model_xai_select', 'xai_model', false, true],
pollinations_model: ['#model_pollinations_select', 'pollinations_model', false, true],
pollinations_endpoint: ['#pollinations_endpoint', 'pollinations_endpoint', false, true],
moonshot_model: ['#model_moonshot_select', 'moonshot_model', false, true],
fireworks_model: ['#model_fireworks_select', 'fireworks_model', false, true],
cometapi_model: ['#model_cometapi_select', 'cometapi_model', false, true],
@@ -369,7 +377,7 @@ export const settingsToUpdate = {
prompts: ['', 'prompts', false, false],
prompt_order: ['', 'prompt_order', false, false],
show_external_models: ['#openai_show_external_models', 'show_external_models', true, true],
proxy_password: ['#openai_proxy_password', 'proxy_password', false, true],
proxy_password: ['#openai_proxy_access_key', 'proxy_password', false, true],
assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false, false],
assistant_impersonation: ['#claude_assistant_impersonation', 'assistant_impersonation', false, false],
use_sysprompt: ['#use_sysprompt', 'use_sysprompt', true, false],
@@ -429,10 +437,10 @@ const default_settings = {
personality_format: default_personality_format,
sort_models: 'alphabetically',
group_models: false,
openai_model: 'gpt-4-turbo',
claude_model: 'claude-sonnet-4-5',
google_model: 'gemini-2.5-pro',
vertexai_model: 'gemini-2.5-pro',
openai_model: 'gpt-6-sol',
claude_model: 'claude-sonnet-5',
google_model: 'gemini-3.8-flash',
vertexai_model: 'gemini-3.8-flash',
ai21_model: 'jamba-large',
mistralai_model: 'mistral-large-latest',
cohere_model: 'command-r-plus',
@@ -451,6 +459,7 @@ const default_settings = {
aimlapi_model: 'chatgpt-4o-latest',
xai_model: 'grok-3-beta',
pollinations_model: 'openai',
pollinations_endpoint: POLLINATIONS_ENDPOINT.AUTHENTICATED,
cometapi_model: 'gpt-4o',
moonshot_model: 'kimi-latest',
fireworks_model: 'accounts/fireworks/models/kimi-k2-instruct',
@@ -1614,6 +1623,21 @@ export async function prepareOpenAIMessages({
return [chat, promptManager.tokenHandler.counts];
}
/**
* Extracts a human-readable message from a Chat Completion error response.
* Providers can return an error object without a message field, or the error as
* a plain string. statusText is only used for non-2xx responses, since for an
* HTTP 200 carrying an error payload it is just "OK" (#5647).
* @param {object} data Parsed response body
* @param {Response} response Fetch response
* @returns {string} Error message to display and throw
*/
function getChatCompletionErrorMessage(data, response) {
const error = data?.error ?? data?.detail?.error;
const message = typeof error === 'string' ? error : (error?.message || error?.code || error?.type);
return String(message || (!response.ok && response.statusText) || t`Unknown error`);
}
/**
* Handles errors during streaming requests.
* @param {Response} response
@@ -1636,7 +1660,7 @@ export function tryParseStreamingError(response, decoded, { quiet = false } = {}
// if trying to fix "[object Object]" displayed to users, start here
if (data.error) {
!quiet && toastr.error(data.error.message || response.statusText, 'Chat Completion API');
!quiet && toastr.error(getChatCompletionErrorMessage(data, response), 'Chat Completion API');
throw new Error(data);
}
@@ -1646,7 +1670,7 @@ export function tryParseStreamingError(response, decoded, { quiet = false } = {}
}
if (data.detail) {
!quiet && toastr.error(data.detail?.error?.message || response.statusText, 'Chat Completion API');
!quiet && toastr.error(getChatCompletionErrorMessage(data, response), 'Chat Completion API');
throw new Error(data);
}
} catch {
@@ -2281,14 +2305,12 @@ function saveModelList(data) {
if (oai_settings.chat_completion_source === chat_completion_sources.FIREWORKS) {
$('#model_fireworks_select').empty();
model_list.sort((a, b) => (a?.name || a?.id || '').localeCompare(b?.name || b?.id || ''));
model_list.forEach((model) => {
if (!model?.supports_chat) {
return;
}
$('#model_fireworks_select').append(
$('<option>', {
value: model.id,
text: model.id,
text: model.name || model.id,
}));
});
@@ -2538,6 +2560,7 @@ function getReasoningEffort(settings = null, model = null) {
chat_completion_sources.ELECTRONHUB,
chat_completion_sources.CHUTES,
chat_completion_sources.DEEPSEEK,
chat_completion_sources.FIREWORKS,
];
if (!reasoningEffortSources.includes(settings.chat_completion_source)) {
@@ -2549,6 +2572,9 @@ function getReasoningEffort(settings = null, model = null) {
switch (settings.reasoning_effort) {
case reasoning_effort_types.auto:
return undefined;
case reasoning_effort_types.min:
case reasoning_effort_types.low:
return reasoning_effort_types.low;
case reasoning_effort_types.max:
return reasoning_effort_types.max;
default:
@@ -2556,6 +2582,17 @@ function getReasoningEffort(settings = null, model = null) {
}
}
if (settings.chat_completion_source === chat_completion_sources.FIREWORKS) {
switch (settings.reasoning_effort) {
case reasoning_effort_types.auto:
return undefined;
case reasoning_effort_types.min:
return reasoning_effort_types.low;
default:
return settings.reasoning_effort;
}
}
if (settings.chat_completion_source === chat_completion_sources.CUSTOM && /^koboldcpp\/(.+)$/.test(model)) {
switch (settings.reasoning_effort) {
case reasoning_effort_types.auto:
@@ -2584,7 +2621,7 @@ function getReasoningEffort(settings = null, model = null) {
}
if ([chat_completion_sources.OPENAI, chat_completion_sources.AZURE_OPENAI].includes(settings.chat_completion_source)) {
if (/^gpt-5\.(4|5)/.test(model)) {
if (/^(?:gpt-5\.(?:4|5|6)|gpt-6-(?:sol|luna))/.test(model)) {
return 'none';
}
if (/^gpt-5/.test(model)) {
@@ -2594,6 +2631,15 @@ function getReasoningEffort(settings = null, model = null) {
return reasoning_effort_types.low;
case reasoning_effort_types.max:
if ([chat_completion_sources.OPENAI, chat_completion_sources.AZURE_OPENAI].includes(settings.chat_completion_source)
&& /^gpt-6-/.test(model)) {
return reasoning_effort_types.max;
}
if ([chat_completion_sources.OPENAI, chat_completion_sources.AZURE_OPENAI].includes(settings.chat_completion_source)
&& /^gpt-5\.6/.test(model)) {
// GPT-5.6 reserves "max" effort for the Responses API.
return 'xhigh';
}
return reasoning_effort_types.high;
default:
return settings.reasoning_effort;
@@ -2649,6 +2695,20 @@ export async function createGenerationParameters(settings, model, type, messages
}
messages = messages.filter(msg => msg && typeof msg === 'object');
// DeepSeek only accepts image blocks in user messages. Media can also be
// attached to system and assistant messages by the shared inlining path.
const isDeepSeekVisionModel = typeof model === 'string' && model.toLowerCase().includes('deepseek-v4-flash-vision-exp');
if (isDeepSeekVisionModel) {
messages = messages.flatMap((message) => {
if (!['system', 'assistant'].includes(message.role) || !Array.isArray(message.content)) {
return [message];
}
const content = message.content.filter(block => block?.type !== 'image_url');
return content.length > 0 ? [{ ...message, content }] : [];
});
}
// "OpenAI-like" sources
const gptSources = [
chat_completion_sources.OPENAI,
@@ -2692,6 +2752,7 @@ export async function createGenerationParameters(settings, model, type, messages
const logprobsSupportedSources = [
chat_completion_sources.OPENAI,
chat_completion_sources.AZURE_OPENAI,
chat_completion_sources.OPENROUTER,
chat_completion_sources.CUSTOM,
chat_completion_sources.DEEPSEEK,
chat_completion_sources.XAI,
@@ -2837,6 +2898,10 @@ export async function createGenerationParameters(settings, model, type, messages
generate_data.nanogpt_payg_override = settings.nanogpt_payg_override;
}
if (settings.chat_completion_source === chat_completion_sources.FIREWORKS && type !== 'quiet') {
generate_data.chat_id = getCurrentChatId();
}
if ([chat_completion_sources.MAKERSUITE, chat_completion_sources.VERTEXAI].includes(settings.chat_completion_source)) {
const stopStringsLimit = 5;
generate_data.top_k = Number(settings.top_k_openai);
@@ -2856,9 +2921,9 @@ export async function createGenerationParameters(settings, model, type, messages
if (settings.chat_completion_source === chat_completion_sources.CUSTOM) {
generate_data.custom_url = settings.custom_url;
generate_data.custom_include_body = settings.custom_include_body;
generate_data.custom_exclude_body = settings.custom_exclude_body;
generate_data.custom_include_headers = settings.custom_include_headers;
generate_data.custom_include_body = substituteParams(settings.custom_include_body);
generate_data.custom_exclude_body = substituteParams(settings.custom_exclude_body);
generate_data.custom_include_headers = substituteParams(settings.custom_include_headers);
}
if (settings.chat_completion_source === chat_completion_sources.COHERE) {
@@ -2933,6 +2998,10 @@ export async function createGenerationParameters(settings, model, type, messages
delete generate_data.frequency_penalty;
}
if (settings.chat_completion_source === chat_completion_sources.POLLINATIONS) {
generate_data.pollinations_endpoint = settings.pollinations_endpoint || POLLINATIONS_ENDPOINT.AUTHENTICATED;
}
if (settings.chat_completion_source === chat_completion_sources.SILICONFLOW) {
generate_data.siliconflow_endpoint = settings.siliconflow_endpoint || SILICONFLOW_ENDPOINT.GLOBAL;
}
@@ -3025,6 +3094,33 @@ export async function createGenerationParameters(settings, model, type, messages
}
}
if (gptSources.includes(settings.chat_completion_source) && /gpt-6-/.test(model)) {
generate_data.max_completion_tokens = generate_data.max_tokens;
delete generate_data.max_tokens;
if (model.includes('gpt-6-astra') || generate_data.reasoning_effort !== 'none') {
delete generate_data.temperature;
delete generate_data.top_p;
delete generate_data.logprobs;
delete generate_data.top_logprobs;
}
}
// Claude Fable / Claude 5 models removed sampling parameters and reject them with HTTP 400,
// including via OpenAI-compatible proxies. Unanchored to also match prefixed ids
// like 'anthropic/claude-fable-5' or 'anthropic/claude-opus-5'.
if (/claude-(fable|opus-5|sonnet-5)/.test(model)) {
delete generate_data.temperature;
delete generate_data.top_p;
delete generate_data.top_k;
delete generate_data.frequency_penalty;
delete generate_data.presence_penalty;
// Keep reasoning_effort for the native Claude source, where the backend maps it to
// adaptive thinking; proxies may translate it into a thinking budget that these models reject.
if (settings.chat_completion_source !== chat_completion_sources.CLAUDE) {
delete generate_data.reasoning_effort;
}
}
if (jsonSchema) {
generate_data.json_schema = jsonSchema;
}
@@ -3100,7 +3196,7 @@ async function sendOpenAIRequest(type, messages, signal, { jsonSchema = null } =
checkModerationError(data);
if (data.error) {
const message = data.error.message || response.statusText || t`Unknown error`;
const message = getChatCompletionErrorMessage(data, response);
toastr.error(message, t`API returned an error`);
throw new Error(message);
}
@@ -3192,7 +3288,7 @@ export function getStreamingReply(data, state, { chatCompletionSource = null, ov
}
});
return data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? '';
} else if ([chat_completion_sources.CUSTOM, chat_completion_sources.POLLINATIONS, chat_completion_sources.AIMLAPI, chat_completion_sources.MOONSHOT, chat_completion_sources.COMETAPI, chat_completion_sources.ELECTRONHUB, chat_completion_sources.NANOGPT, chat_completion_sources.ZAI, chat_completion_sources.SILICONFLOW, chat_completion_sources.CHUTES, chat_completion_sources.WORKERS_AI].includes(chat_completion_source)) {
} else if ([chat_completion_sources.CUSTOM, chat_completion_sources.POLLINATIONS, chat_completion_sources.AIMLAPI, chat_completion_sources.MOONSHOT, chat_completion_sources.COMETAPI, chat_completion_sources.ELECTRONHUB, chat_completion_sources.NANOGPT, chat_completion_sources.ZAI, chat_completion_sources.SILICONFLOW, chat_completion_sources.CHUTES, chat_completion_sources.WORKERS_AI, chat_completion_sources.FIREWORKS].includes(chat_completion_source)) {
if (show_thoughts) {
state.reasoning +=
data.choices?.filter(x => x?.delta?.reasoning_content)?.[0]?.delta?.reasoning_content ??
@@ -3229,6 +3325,7 @@ function parseChatCompletionLogprobs(data) {
: parseOpenAITextLogprobs(data.choices[0]?.logprobs);
case chat_completion_sources.OPENAI:
case chat_completion_sources.AZURE_OPENAI:
case chat_completion_sources.OPENROUTER:
case chat_completion_sources.DEEPSEEK:
case chat_completion_sources.XAI:
case chat_completion_sources.CUSTOM:
@@ -4182,6 +4279,12 @@ function migrateChatCompletionSettings(settings) {
{ oldKey: 'chat_completion_source', oldValue: 'palm', newKey: 'chat_completion_source', newValue: chat_completion_sources.MAKERSUITE },
{ oldKey: 'custom_prompt_post_processing', oldValue: custom_prompt_post_processing_types.CLAUDE, newKey: 'custom_prompt_post_processing', newValue: custom_prompt_post_processing_types.MERGE },
{ oldKey: 'ai21_model', oldValue: /^j2-/, newKey: 'ai21_model', newValue: 'jamba-large' },
{ oldKey: 'google_model', oldValue: 'gemini-3.1-flash-lite-preview', newKey: 'google_model', newValue: 'gemini-3.1-flash-lite' },
{ oldKey: 'vertexai_model', oldValue: 'gemini-3.1-flash-lite-preview', newKey: 'vertexai_model', newValue: 'gemini-3.1-flash-lite' },
{ oldKey: 'google_model', oldValue: 'gemini-3.1-flash-image-preview', newKey: 'google_model', newValue: 'gemini-3.1-flash-image' },
{ oldKey: 'vertexai_model', oldValue: 'gemini-3.1-flash-image-preview', newKey: 'vertexai_model', newValue: 'gemini-3.1-flash-image' },
{ oldKey: 'google_model', oldValue: 'gemini-3-pro-image-preview', newKey: 'google_model', newValue: 'gemini-3-pro-image' },
{ oldKey: 'vertexai_model', oldValue: 'gemini-3-pro-image-preview', newKey: 'vertexai_model', newValue: 'gemini-3-pro-image' },
{ oldKey: 'image_inlining', oldValue: false, newKey: 'media_inlining', newValue: false },
{ oldKey: 'image_inlining', oldValue: true, newKey: 'media_inlining', newValue: true },
{ oldKey: 'video_inlining', oldValue: true, newKey: 'media_inlining', newValue: true },
@@ -4407,7 +4510,7 @@ async function getStatusOpen() {
if (oai_settings.chat_completion_source === chat_completion_sources.CUSTOM) {
$('.model_custom_select').empty();
data.custom_url = oai_settings.custom_url;
data.custom_include_headers = oai_settings.custom_include_headers;
data.custom_include_headers = substituteParams(oai_settings.custom_include_headers);
}
if (oai_settings.chat_completion_source === chat_completion_sources.AZURE_OPENAI) {
@@ -4428,6 +4531,10 @@ async function getStatusOpen() {
data.workers_ai_account_id = oai_settings.workers_ai_account_id;
}
if (oai_settings.chat_completion_source === chat_completion_sources.POLLINATIONS) {
data.pollinations_endpoint = oai_settings.pollinations_endpoint || POLLINATIONS_ENDPOINT.AUTHENTICATED;
}
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`);
@@ -4894,6 +5001,23 @@ async function onLogitBiasPresetDeleteClick() {
saveSettingsDebounced();
}
/**
* Promise that resolves when the most recently started preset application has fully completed.
* The change handler defers the actual apply behind an event emission, so programmatic preset
* switches (e.g. /preset, connection profiles) must await this to sequence follow-up commands
* such as /api and /model correctly.
* @type {Promise<void>}
*/
let presetApplicationPromise = Promise.resolve();
/**
* Gets a promise that resolves when the currently pending preset application completes.
* @returns {Promise<void>} Promise that resolves when the preset is fully applied.
*/
export function getPresetApplicationPromise() {
return presetApplicationPromise;
}
// Load OpenAI preset settings
function onSettingsPresetChange() {
const presetNameBefore = oai_settings.preset_settings_openai;
@@ -4909,7 +5033,7 @@ function onSettingsPresetChange() {
const updateCheckbox = (selector, value) => $(selector).prop('checked', value).trigger('input', { source: 'preset' });
// Allow subscribers to alter the preset before applying deltas
eventSource.emit(event_types.OAI_PRESET_CHANGED_BEFORE, {
presetApplicationPromise = eventSource.emit(event_types.OAI_PRESET_CHANGED_BEFORE, {
preset: preset,
presetName: presetName,
settingsToUpdate: settingsToUpdate,
@@ -4970,6 +5094,8 @@ function getMaxContextOpenAI(value) {
/** @type {[RegExp, number][]} */
const contextMap = [
[/^gpt-6-/, max_1050k],
[/^gpt-5\.6/, max_1050k],
[/^gpt-5\.[45]/, max_1mil],
[/^gpt-5/, max_400k],
[/gpt-4\.1/, max_1mil],
@@ -5018,6 +5144,7 @@ function getGeminiMaxContext(model, isUnlocked) {
/** @type {[RegExp, number][]} */
const contextMap = [
[/gemini-2\.5-flash-image/, max_32k],
[/gemini-3\.1-flash-image/, max_128k],
[/gemini-3-pro-image/, max_64k],
[/gemini-(?:3[.\d]*|2\.(?:5|0))-(pro|flash)/, max_1mil],
[/(gemini-exp|learnlm-2\.0-flash|gemini-robotics)/, max_1mil],
@@ -5137,6 +5264,7 @@ function getZaiMaxContext(model, isUnlocked) {
}
const contextMap = {
'glm-5.2': max_1mil,
'glm-5.1': max_200k,
'glm-5-turbo': max_200k,
'glm-5v-turbo': max_200k,
@@ -5604,7 +5732,7 @@ async function onModelChange() {
if (oai_settings.chat_completion_source == chat_completion_sources.CLAUDE) {
if (oai_settings.max_context_unlocked) {
$('#openai_max_context').attr('max', unlocked_max);
} else if (/^claude-(sonnet-4-5|sonnet-4-6|opus-4-6|opus-4-7)/.test(value)) {
} else if (/^claude-(sonnet-4-5|sonnet-4-6|sonnet-5|opus-4-6|opus-4-7|opus-4-8|opus-5|fable)/.test(value)) {
$('#openai_max_context').attr('max', max_1mil);
} else if (/^claude-(3|opus|haiku|sonnet)/.test(value)) {
$('#openai_max_context').attr('max', max_200k);
@@ -5934,7 +6062,7 @@ async function onConnectButtonClick(e) {
[chat_completion_sources.AZURE_OPENAI]: { key: SECRET_KEYS.AZURE_OPENAI, selector: '#api_key_azure_openai', proxy: false },
[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.POLLINATIONS]: { key: SECRET_KEYS.POLLINATIONS, selector: '#api_key_pollinations', proxy: false, keyless: oai_settings.pollinations_endpoint === POLLINATIONS_ENDPOINT.ANONYMOUS },
[chat_completion_sources.WORKERS_AI]: { key: SECRET_KEYS.WORKERS_AI, selector: '#api_key_workers_ai', proxy: false },
[chat_completion_sources.MINIMAX]: { key: SECRET_KEYS.MINIMAX, selector: '#api_key_minimax', proxy: false },
};
@@ -6017,6 +6145,7 @@ function toggleChatCompletionForms() {
} else if (oai_settings.chat_completion_source == chat_completion_sources.XAI) {
$('#model_xai_select').trigger('change');
} else if (oai_settings.chat_completion_source == chat_completion_sources.POLLINATIONS) {
$('#pollinations_key_section').toggle(oai_settings.pollinations_endpoint === POLLINATIONS_ENDPOINT.AUTHENTICATED);
$('#model_pollinations_select').trigger('change');
} else if (oai_settings.chat_completion_source == chat_completion_sources.MOONSHOT) {
$('#model_moonshot_select').trigger('change');
@@ -6066,10 +6195,8 @@ function reconnectOpenAi() {
}
}
function onProxyPasswordShowClick() {
const $input = $('#openai_proxy_password');
const type = $input.attr('type') === 'password' ? 'text' : 'password';
$input.attr('type', type);
function onProxyAccessKeyShowClick() {
$('#openai_proxy_access_key').toggleClass('masked-secret');
$(this).toggleClass('fa-eye-slash fa-eye');
}
@@ -6116,14 +6243,20 @@ export function isImageInliningSupported() {
'gpt-4.1',
'gpt-4.5-preview',
'gpt-4o',
'gpt-6-astra',
'gpt-6-sol',
'gpt-6-luna',
'gpt-5',
'o1',
'o3',
'o4-mini',
// Claude
'claude-3',
'claude-fable',
'claude-opus-4',
'claude-opus-5',
'claude-sonnet-4',
'claude-sonnet-5',
'claude-haiku-4',
// Cohere
'c4ai-aya-vision',
@@ -6156,6 +6289,8 @@ export function isImageInliningSupported() {
'moonshot-v1-128k-vision-preview',
'kimi-k2.5',
'kimi-latest',
// DeepSeek
'deepseek-v4-flash-vision-exp',
// Z.AI (GLM)
'glm-4.5v',
'glm-4.6v',
@@ -6215,10 +6350,14 @@ export function isImageInliningSupported() {
return visionSupportedModels.some(model => oai_settings.zai_model.includes(model));
case chat_completion_sources.SILICONFLOW:
return visionSupportedModels.some(model => oai_settings.siliconflow_model.includes(model));
case chat_completion_sources.DEEPSEEK:
return visionSupportedModels.some(model => oai_settings.deepseek_model.includes(model));
case chat_completion_sources.WORKERS_AI: {
const waiModel = Array.isArray(model_list) && model_list.find(m => m.id === oai_settings.workers_ai_model);
return Boolean(waiModel && Array.isArray(waiModel.properties) && waiModel.properties.some(p => p.property_id === 'vision' && p.value === 'true'));
}
case chat_completion_sources.FIREWORKS:
return (Array.isArray(model_list) && model_list.find(m => m.id === oai_settings.fireworks_model)?.supports_image_input);
default:
return false;
}
@@ -6387,7 +6526,7 @@ function setProxyPreset(name, url, password) {
oai_settings.reverse_proxy = url;
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
oai_settings.proxy_password = password;
$('#openai_proxy_password').val(oai_settings.proxy_password);
$('#openai_proxy_access_key').val(oai_settings.proxy_password);
reconnectOpenAi();
}
@@ -6406,7 +6545,7 @@ function onProxyPresetChange() {
$('#save_proxy').on('click', async function () {
const presetName = $('#openai_reverse_proxy_name').val();
const reverseProxy = $('#openai_reverse_proxy').val();
const proxyPassword = $('#openai_proxy_password').val();
const proxyPassword = $('#openai_proxy_access_key').val();
setProxyPreset(presetName, reverseProxy, proxyPassword);
saveSettingsDebounced();
@@ -6440,7 +6579,7 @@ $('#delete_proxy').on('click', async function () {
oai_settings.reverse_proxy = selected_proxy.url;
$('#openai_reverse_proxy').val(selected_proxy.url);
oai_settings.proxy_password = selected_proxy.password;
$('#openai_proxy_password').val(selected_proxy.password);
$('#openai_proxy_access_key').val(selected_proxy.password);
saveSettingsDebounced();
$('#openai_proxy_preset').val(selected_proxy.name);
@@ -6855,11 +6994,17 @@ export function initOpenAI() {
saveSettingsDebounced();
});
$('#openai_proxy_password').on('input', function () {
$('#openai_proxy_access_key').on('input', function () {
oai_settings.proxy_password = String($(this).val());
saveSettingsDebounced();
});
$('#openai_proxy_access_key').on('copy cut', function (event) {
if ($(this).hasClass('masked-secret')) {
event.preventDefault();
}
});
$('#claude_assistant_prefill').on('input', function () {
oai_settings.assistant_prefill = String($(this).val());
saveSettingsDebounced();
@@ -7193,6 +7338,12 @@ export function initOpenAI() {
oai_settings.zai_endpoint = String($(this).val());
saveSettingsDebounced();
});
$('#pollinations_endpoint').on('input', function () {
oai_settings.pollinations_endpoint = String($(this).val());
$('#pollinations_key_section').toggle(oai_settings.pollinations_endpoint === POLLINATIONS_ENDPOINT.AUTHENTICATED);
reconnectOpenAi();
saveSettingsDebounced();
});
$('#siliconflow_endpoint').on('input', function () {
oai_settings.siliconflow_endpoint = String($(this).val());
saveSettingsDebounced();
@@ -7243,7 +7394,7 @@ export function initOpenAI() {
$('#openai_logit_bias_export_preset').on('click', onLogitBiasPresetExportClick);
$('#openai_logit_bias_delete_preset').on('click', onLogitBiasPresetDeleteClick);
$('#import_oai_preset').on('click', onImportPresetClick);
$('#openai_proxy_password_show').on('click', onProxyPasswordShowClick);
$('#openai_proxy_access_key_show').on('click', onProxyAccessKeyShowClick);
$('#customize_additional_parameters').on('click', onCustomizeParametersClick);
$('#openai_proxy_preset').on('change', onProxyPresetChange);
}
+5
View File
@@ -85,6 +85,7 @@ export const POPUP_RESULT = {
* @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
* @property {boolean?} [autoFocus=false] - Whether this input should be auto-focused when the popup opens
*/
/**
@@ -336,6 +337,7 @@ export class Popup {
inputElement.id = input.id;
inputElement.checked = Boolean(input.defaultState ?? false);
inputElement.disabled = Boolean(input.disabled ?? false);
if (input.autoFocus) { inputElement.setAttribute('autofocus', ''); inputElement.tabIndex = 0; }
label.appendChild(inputElement);
const labelText = document.createElement('span');
labelText.innerText = input.label;
@@ -362,6 +364,7 @@ export class Popup {
inputElement.value = String(input.defaultState ?? '');
inputElement.placeholder = input.tooltip ?? '';
inputElement.disabled = Boolean(input.disabled ?? false);
if (input.autoFocus) { inputElement.setAttribute('autofocus', ''); inputElement.tabIndex = 0; }
setTitleFromTooltip(inputElement, input.tooltip);
const labelText = document.createElement('span');
@@ -384,6 +387,7 @@ export class Popup {
inputElement.rows = input.rows ?? 1;
inputElement.placeholder = input.tooltip ?? '';
inputElement.disabled = Boolean(input.disabled ?? false);
if (input.autoFocus) { inputElement.setAttribute('autofocus', ''); inputElement.tabIndex = 0; }
setTitleFromTooltip(inputElement, input.tooltip);
const labelText = document.createElement('span');
@@ -409,6 +413,7 @@ export class Popup {
inputElement.max = String(input.max ?? '');
inputElement.step = String(input.step ?? '');
inputElement.disabled = Boolean(input.disabled ?? false);
if (input.autoFocus) { inputElement.setAttribute('autofocus', ''); inputElement.tabIndex = 0; }
setTitleFromTooltip(inputElement, input.tooltip);
inputElement.addEventListener('change', () => {
+33 -9
View File
@@ -2818,9 +2818,10 @@ async function loadUntilMesId(mesId) {
return target;
}
async function doMesCut(_, text) {
async function doMesCut(args, text) {
console.debug(`was asked to cut message id #${text}`);
const range = stringToRange(text, 0, chat.length - 1);
const deleteToolCalls = args?.toolcalls === undefined || isTrueBoolean(args.toolcalls);
//reject invalid args or no args
if (!range) {
@@ -2828,12 +2829,16 @@ async function doMesCut(_, text) {
return;
}
let totalMesToCut = (range.end - range.start) + 1;
let mesIDToCut = range.start;
const messagesToCut = chat.slice(range.start, range.end + 1);
let cutText = '';
for (let i = 0; i < totalMesToCut; i++) {
cutText += (chat[mesIDToCut]?.mes || '') + '\n';
for (const message of messagesToCut) {
const mesIDToCut = chat.indexOf(message);
if (mesIDToCut === -1) {
continue;
}
cutText += (message?.mes || '') + '\n';
let mesToCut = $('#chat').find(`.mes[mesid=${mesIDToCut}]`);
if (!mesToCut.length) {
@@ -2845,7 +2850,7 @@ async function doMesCut(_, text) {
}
setEditedMessageId(mesIDToCut);
await deleteMessage(mesIDToCut, null, false);
await deleteMessage(mesIDToCut, null, false, deleteToolCalls);
}
await saveChatConditional();
@@ -2853,7 +2858,7 @@ async function doMesCut(_, text) {
return cutText;
}
async function doDelMode(_, text) {
async function doDelMode(args, text) {
//reject invalid args
if (text && isNaN(text)) {
toastr.warning('Must enter a number or nothing.');
@@ -2862,7 +2867,8 @@ async function doDelMode(_, text) {
// Just enter the delete mode.
if (!text) {
$('#option_delete_mes').trigger('click', { fromSlashCommand: true });
const deleteToolCalls = args?.toolcalls === undefined || isTrueBoolean(args.toolcalls);
$('#option_delete_mes').trigger('click', { fromSlashCommand: true, deleteToolCalls });
return '';
}
@@ -2879,7 +2885,7 @@ async function doDelMode(_, text) {
}
const range = `${chat.length - count}-${chat.length - 1}`;
return doMesCut(_, range);
return doMesCut(args, range);
}
function doResetPanels() {
@@ -4145,6 +4151,15 @@ jQuery(() => {
name: 'del',
callback: doDelMode,
aliases: ['delete', 'delmode'],
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'toolcalls',
description: 'also delete associated tool-call messages',
typeList: [ARGUMENT_TYPE.BOOLEAN],
defaultValue: 'true',
enumList: commonEnumProviders.boolean('trueFalse')(),
}),
],
unnamedArgumentList: [
new SlashCommandArgument(
'optional number', [ARGUMENT_TYPE.NUMBER], false,
@@ -4157,6 +4172,15 @@ jQuery(() => {
name: 'cut',
callback: doMesCut,
returns: 'the text of cut messages separated by a newline',
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'toolcalls',
description: 'also delete associated tool-call messages',
typeList: [ARGUMENT_TYPE.BOOLEAN],
defaultValue: 'true',
enumList: commonEnumProviders.boolean('trueFalse')(),
}),
],
unnamedArgumentList: [
SlashCommandArgument.fromProps({
description: 'number or range',
+11 -4
View File
@@ -23,7 +23,7 @@ import { t } from './i18n.js';
import { instruct_presets } from './instruct-mode.js';
import { kai_settings } from './kai-settings.js';
import { convertNovelPreset } from './nai-settings.js';
import { oai_settings, openai_setting_names, openai_settings } from './openai.js';
import { getPresetApplicationPromise, oai_settings, openai_setting_names, openai_settings } from './openai.js';
import { POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js';
import { context_presets, getContextSettings, power_user } from './power-user.js';
import { reasoning_templates } from './reasoning.js';
@@ -406,14 +406,21 @@ class PresetManager {
/**
* Selects a preset by option value.
* The returned promise resolves when the preset is fully applied. Chat Completion presets
* apply asynchronously after the change event, so callers that run follow-up commands
* (e.g. /preset followed by /api) must await it to avoid overriding their own changes.
* @param {string} value Preset option value
* @returns {Promise<void>}
*/
selectPreset(value) {
async selectPreset(value) {
const option = $(this.select).filter(function () {
return $(this).val() === value;
});
option.prop('selected', true);
$(this.select).val(value).trigger('change');
if (this.apiId === 'openai') {
await getPresetApplicationPromise();
}
}
/**
@@ -938,7 +945,7 @@ async function presetCommandCallback(_, name) {
const presetValue = presetManager.findPreset(exactMatch);
if (presetValue) {
presetManager.selectPreset(presetValue);
await presetManager.selectPreset(presetValue);
shouldReconnect && await waitForConnection();
}
}
@@ -961,7 +968,7 @@ async function presetCommandCallback(_, name) {
console.log('Found fuzzy preset match', fuzzyPresetName);
if (currentPreset !== fuzzyPresetName) {
presetManager.selectPreset(fuzzyPresetValue);
await presetManager.selectPreset(fuzzyPresetValue);
shouldReconnect && await waitForConnection();
}
}
+52 -12
View File
@@ -73,6 +73,25 @@ function getMessageFromJquery(element) {
return { messageId: messageId, message, messageBlock };
}
/**
* Collapses reasoning blocks that cannot be closed by their header.
* @param {JQuery<HTMLElement>} messageBlock Message block
*/
function closeReasoningDetailsWithoutContent(messageBlock) {
const details = messageBlock.find('.mes_reasoning_details');
if (details.attr('data-has-content') !== 'true') {
details.removeAttr('open');
}
}
/**
* Opens reasoning blocks only when they have visible content.
* @param {JQuery<HTMLElement>} details Reasoning details elements
*/
function openReasoningDetailsWithContent(details) {
details.filter('[data-has-content="true"]').attr('open', '');
}
/**
* Toggles the auto-expand state of reasoning blocks.
*/
@@ -80,7 +99,7 @@ function toggleReasoningAutoExpand() {
const reasoningBlocks = document.querySelectorAll('details.mes_reasoning_details');
reasoningBlocks.forEach((block) => {
if (block instanceof HTMLDetailsElement) {
block.open = power_user.reasoning.auto_expand;
block.open = power_user.reasoning.auto_expand && block.dataset.hasContent === 'true';
}
});
}
@@ -135,6 +154,7 @@ export function extractReasoningFromData(data, {
case chat_completion_sources.SILICONFLOW:
case chat_completion_sources.ZAI:
case chat_completion_sources.WORKERS_AI:
case chat_completion_sources.FIREWORKS:
case chat_completion_sources.CUSTOM: {
return data?.choices?.[0]?.message?.reasoning_content
?? data?.choices?.[0]?.message?.reasoning
@@ -364,7 +384,7 @@ export class ReasoningHandler {
this.updateDom(messageId);
if (power_user.reasoning.auto_expand && this.state !== ReasoningState.Hidden) {
if (power_user.reasoning.auto_expand && this.messageReasoningDetailsDom.dataset.hasContent === 'true') {
this.messageReasoningDetailsDom.open = true;
}
}
@@ -551,7 +571,12 @@ export class ReasoningHandler {
setDatasetProperty(this.messageReasoningDetailsDom, 'type', this.type);
// Update the reasoning message
const reasoning = trimSpaces(this.reasoningDisplayText ?? this.reasoning);
const rawReasoning = this.reasoningDisplayText ?? this.reasoning;
const reasoning = trimSpaces(rawReasoning);
// Keep whitespace-only saved reasoning editable without showing it as visible content.
const hasStoredReasoning = Boolean(this.reasoningDisplayText || this.reasoning);
const hasReasoningContent = Boolean(String(rawReasoning ?? '').trim());
setDatasetProperty(this.messageReasoningDetailsDom, 'hasContent', hasReasoningContent ? 'true' : null);
const displayReasoning = messageFormatting(reasoning, '', false, false, messageId, {}, true);
if (power_user.stream_fade_in) {
@@ -563,7 +588,8 @@ export class ReasoningHandler {
// Update tooltip for hidden reasoning edit
/** @type {HTMLElement} */
const button = this.messageDom.querySelector('.mes_edit_add_reasoning');
button.title = this.state === ReasoningState.Hidden ? t`Hidden reasoning - Add reasoning block` : t`Add reasoning block`;
const isHiddenLikeReasoning = this.state === ReasoningState.Hidden || (hasStoredReasoning && !hasReasoningContent);
button.title = isHiddenLikeReasoning ? t`Hidden reasoning - Add reasoning block` : t`Add reasoning block`;
// Make sure that hidden reasoning headers are collapsed by default, to not show a useless edit button
if (this.state === ReasoningState.Hidden) {
@@ -934,8 +960,9 @@ function registerReasoningSlashCommands() {
closeMessageEditor('reasoning');
updateMessageBlock(messageId, message);
if (isTrueBoolean(String(args.collapse))) $(`#chat [mesid="${messageId}"] .mes_reasoning_details`).removeAttr('open');
if (isFalseBoolean(String(args.collapse))) $(`#chat [mesid="${messageId}"] .mes_reasoning_details`).attr('open', '');
const details = $(`#chat [mesid="${messageId}"] .mes_reasoning_details`);
if (isTrueBoolean(String(args.collapse))) details.removeAttr('open');
if (isFalseBoolean(String(args.collapse))) openReasoningDetailsWithContent(details);
return message.extra.reasoning;
},
}));
@@ -1134,7 +1161,7 @@ function registerReasoningSlashCommands() {
unnamedArgumentList: reasoningVisibilityArgs,
callback: (_args, value) => {
const details = getReasoningDetailsElements(value.toString());
if (details) details.attr('open', '');
if (details) openReasoningDetailsWithContent(details);
return '';
},
}));
@@ -1151,7 +1178,7 @@ function registerReasoningSlashCommands() {
const $el = $(this);
if ($el.attr('open') !== undefined) {
$el.removeAttr('open');
} else {
} else if ($el.attr('data-has-content') === 'true') {
$el.attr('open', '');
}
});
@@ -1198,8 +1225,8 @@ function setReasoningEventHandlers() {
$(document).on('click', '.mes_reasoning_header', function (e) {
const details = $(this).closest('.mes_reasoning_details');
// Along with the CSS rules to mark blocks not toggle-able when they are empty, prevent them from actually being toggled, or being edited
if (details.find('.mes_reasoning').is(':empty')) {
// Keep click behavior aligned with CSS: only blocks with backing content can toggle or enter edit mode.
if (details.attr('data-has-content') !== 'true') {
e.preventDefault();
return;
}
@@ -1228,6 +1255,10 @@ function setReasoningEventHandlers() {
return;
}
if (messageBlock.find('.reasoning_edit_textarea').length > 0) {
return;
}
const reasoning = String(message?.extra?.reasoning ?? '');
const chatElement = document.getElementById('chat');
const textarea = document.createElement('textarea');
@@ -1265,6 +1296,7 @@ function setReasoningEventHandlers() {
e.stopPropagation();
e.preventDefault();
$('.mes_reasoning_details[open]:not([data-has-content="true"])').removeAttr('open');
$('.mes_reasoning_details[open] .mes_reasoning_header').trigger('click');
});
@@ -1281,11 +1313,13 @@ function setReasoningEventHandlers() {
newReasoning = substituteParams(newReasoning);
textarea.remove();
if (newReasoning === message.extra.reasoning) {
closeReasoningDetailsWithoutContent(messageBlock);
return;
}
updateReasoningFromValue(message, newReasoning);
await saveChatConditional();
updateMessageBlock(messageId, message);
closeReasoningDetailsWithoutContent(messageBlock);
messageBlock.find('.mes_edit_done:visible').trigger('click');
await eventSource.emit(event_types.MESSAGE_REASONING_EDITED, messageId);
@@ -1302,6 +1336,7 @@ function setReasoningEventHandlers() {
messageBlock.find('.mes_reasoning_edit_cancel:visible').trigger('click');
updateReasoningUI(messageBlock);
closeReasoningDetailsWithoutContent(messageBlock);
});
$(document).on('click', '.mes_edit_add_reasoning', async function () {
@@ -1310,7 +1345,12 @@ function setReasoningEventHandlers() {
return;
}
if (message.extra.reasoning) {
const details = messageBlock.find('.mes_reasoning_details');
if (details.find('.reasoning_edit_textarea').length > 0) {
return;
}
if (message.extra.reasoning && details.attr('data-has-content') === 'true') {
toastr.info(t`Reasoning already exists.`, t`Edit Message`);
return;
}
@@ -1324,7 +1364,7 @@ function setReasoningEventHandlers() {
}
// Open the reasoning area so we can actually edit it
messageBlock.find('.mes_reasoning_details').attr('open', '');
details.attr('open', '');
messageBlock.find('.mes_reasoning_edit').trigger('click');
await saveChatConditional();
});
+38 -11
View File
@@ -38,6 +38,7 @@ import {
newAssistantChat,
online_status,
reloadCurrentChat,
refreshSwipeButtons,
removeMacros,
renameCharacter,
renameChat,
@@ -57,11 +58,11 @@ import {
swipe,
stopGeneration,
substituteParams,
syncMesToSwipe,
system_avatar,
system_message_types,
this_chid,
updateMessageElement,
updateSwipeCounter,
} from '../script.js';
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
import { SlashCommandParserError } from './slash-commands/SlashCommandParserError.js';
@@ -70,7 +71,7 @@ import { hideChatMessageRange } from './chats.js';
import { getContext, saveMetadataDebounced } from './extensions.js';
import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
import { findGroupMemberId, groups, is_group_generating, openGroupById, regenerateGroup, resetSelectedGroup, saveGroupChat, selected_group, getGroupMembers } from './group-chats.js';
import { chat_completion_sources, MINIMAX_ENDPOINT, oai_settings, promptManager, SILICONFLOW_ENDPOINT, ZAI_ENDPOINT } from './openai.js';
import { chat_completion_sources, MINIMAX_ENDPOINT, oai_settings, POLLINATIONS_ENDPOINT, promptManager, SILICONFLOW_ENDPOINT, ZAI_ENDPOINT } from './openai.js';
import { user_avatar } from './personas.js';
import { addEphemeralStoppingString, chat_styles, context_presets, flushEphemeralStoppingStrings, playMessageSound, power_user } from './power-user.js';
import { SERVER_INPUTS, textgen_types, textgenerationwebui_settings } from './textgen-settings.js';
@@ -2970,9 +2971,9 @@ export function initDefaultSlashCommands() {
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'tokens',
callback: (_, text) => {
callback: async (_, text) => {
if (text instanceof SlashCommandClosure || Array.isArray(text)) throw new Error(t`Unnamed argument cannot be a closure for command /tokens`);
return getTokenCountAsync(text).then(count => String(count));
return String(await getTokenCountAsync(text));
},
returns: t`number of tokens`,
unnamedArgumentList: [
@@ -3135,6 +3136,7 @@ export function initDefaultSlashCommands() {
new SlashCommandEnumValue('vertexai', 'Google Vertex AI', enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'vertexai')), 'V'),
new SlashCommandEnumValue('siliconflow', 'SiliconFlow', enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'siliconflow')), 'S'),
new SlashCommandEnumValue('minimax', 'MiniMax', enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'minimax')), 'M'),
new SlashCommandEnumValue('pollinations', 'Pollinations', enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'pollinations')), 'P'),
new SlashCommandEnumValue('kobold', 'KoboldAI Classic', enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'kobold')), 'K'),
...Object.values(textgen_types).filter(api => Object.keys(SERVER_INPUTS).includes(api)).map(api => new SlashCommandEnumValue(api, null, enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'textgenerationwebui')), 'T')),
],
@@ -3168,7 +3170,7 @@ export function initDefaultSlashCommands() {
${t`If a manual API is provided to <b>set</b> the URL, make sure to set <code>connect=false</code>, as auto-connect only works for the currently selected API, or consider switching to it with <code>/api</code> first.`}
</div>
<div>
${t`This slash command works for most of the Text Completion sources, KoboldAI Classic, and also Custom OpenAI compatible, Z.AI, SiliconFlow, MiniMax, and Google Vertex AI for the Chat Completion sources. If unsure which APIs are supported, check the auto-completion of the optional <code>api</code> argument of this command.`}
${t`This slash command works for most of the Text Completion sources, KoboldAI Classic, and also Custom OpenAI compatible, Z.AI, SiliconFlow, MiniMax, Pollinations, and Google Vertex AI for the Chat Completion sources. If unsure which APIs are supported, check the auto-completion of the optional <code>api</code> argument of this command.`}
</div>
`,
}));
@@ -4615,6 +4617,7 @@ async function echoCallback(args, value) {
* @param {string} value - The swipe text to add (unnamed argument)
*/
async function addSwipeCallback(args, value) {
const lastMessageId = chat.length - 1;
const lastMessage = chat[chat.length - 1];
if (!lastMessage) {
@@ -4662,15 +4665,13 @@ async function addSwipeCallback(args, value) {
const newSwipeId = lastMessage.swipes.length - 1;
if (isTrueBoolean(args.switch)) {
// Make sure ad-hoc changes to extras are saved before swiping away
syncMesToSwipe();
lastMessage.swipe_id = newSwipeId;
lastMessage.mes = lastMessage.swipes[newSwipeId];
lastMessage.extra = structuredClone(lastMessage.swipe_info?.[newSwipeId]?.extra ?? lastMessage.extra ?? {});
await swipe(null, SWIPE_DIRECTION.RIGHT, { source: SWIPE_SOURCE.SLASH_COMMAND, repeated: false, forceMesId: lastMessageId, forceSwipeId: newSwipeId });
} else {
await updateSwipeCounter(lastMessageId, { message: lastMessage });
refreshSwipeButtons();
}
await saveChatConditional();
await reloadCurrentChat();
return String(newSwipeId);
}
@@ -6686,6 +6687,32 @@ async function setApiUrlCallback({ api = null, connect = 'true', quiet = 'false'
return oai_settings.vertexai_region || defaultRegion;
}
const isCurrentlyPollinations = main_api === 'openai' && oai_settings.chat_completion_source === chat_completion_sources.POLLINATIONS;
if (api === chat_completion_sources.POLLINATIONS || (!api && isCurrentlyPollinations)) {
if (!url) {
return oai_settings.pollinations_endpoint || POLLINATIONS_ENDPOINT.AUTHENTICATED;
}
const permittedValues = Object.values(POLLINATIONS_ENDPOINT);
if (!permittedValues.includes(url)) {
!isQuiet && toastr.warning(t`Valid options are: ${permittedValues.join(', ')}`, t`Pollinations endpoint '${url}' is not a valid option.`);
return '';
}
if (!isCurrentlyPollinations && autoConnect) {
toastr.warning(t`Pollinations API is not the currently selected API, so we cannot do an auto-connect. Consider switching to it via /api beforehand.`);
return '';
}
$('#pollinations_endpoint').val(url).trigger('input');
if (autoConnect) {
$('#api_button_openai').trigger('click');
}
return oai_settings.pollinations_endpoint || POLLINATIONS_ENDPOINT.AUTHENTICATED;
}
// Special handling for Kobold Classic API
const isCurrentlyKoboldClassic = main_api === 'kobold';
if (api === 'kobold' || (!api && isCurrentlyKoboldClassic)) {
+2
View File
@@ -110,6 +110,7 @@ import { ConnectionManagerRequestService } from './extensions/shared.js';
import { updateReasoningUI, parseReasoningFromString, getReasoningTemplateByName } from './reasoning.js';
import { IGNORE_SYMBOL } from './constants.js';
import { macros } from './macros/macro-system.js';
import { MessageFormatter } from './message-formatter.js';
export function getContext() {
return {
@@ -242,6 +243,7 @@ export function getContext() {
scrollChatToBottom,
scrollOnMediaLoad,
macros,
messageFormatter: MessageFormatter,
loader,
swipe: {
left: swipe_left,
+18 -14
View File
@@ -2289,28 +2289,32 @@ function printViewTagList(tagContainer, empty = true) {
function removeMissingTagFilters() {
const tagIds = new Set(tags.map(tag => tag.id));
const assignedTagIds = new Set(Object.values(tag_map).flat());
const openBogusFolderIds = new Set(getOpenBogusFolders().map(tag => tag.id));
const isEmptyOpenBogusFolder = (tagId) => openBogusFolderIds.has(tagId) && !assignedTagIds.has(tagId);
// Filter lists only print tags that are assigned to at least one entity. A filter on an unassigned
// tag therefore has no element to toggle, and "Clear all filters" can't reset it either, because it
// works by clicking the printed elements. Drop those filters instead of leaving them stuck.
const isUnclearable = (tagId) => !tagIds.has(tagId) || !assignedTagIds.has(tagId);
for (const helper of [groupCandidatesFilter, groupMembersFilter, entitiesFilter]) {
const { selected, excluded } = helper.getFilterData(FILTER_TYPES.TAG);
const storagePrefix = getFilterStorageKey(helper);
let anyRemoved = false;
if (Array.isArray(selected)) {
for (let i = selected.length - 1; i >= 0; i--) {
if (!tagIds.has(selected[i]) || isEmptyOpenBogusFolder(selected[i])) {
selected.splice(i, 1);
anyRemoved = true;
}
for (const tagIdList of [selected, excluded]) {
if (!Array.isArray(tagIdList)) {
continue;
}
}
if (Array.isArray(excluded)) {
for (let i = excluded.length - 1; i >= 0; i--) {
if (!tagIds.has(excluded[i]) || isEmptyOpenBogusFolder(excluded[i])) {
excluded.splice(i, 1);
anyRemoved = true;
for (let i = tagIdList.length - 1; i >= 0; i--) {
if (!isUnclearable(tagIdList[i])) {
continue;
}
if (storagePrefix) {
accountStorage.removeItem(`${storagePrefix}_tag_${tagIdList[i]}`);
}
tagIdList.splice(i, 1);
anyRemoved = true;
}
}
+1 -1
View File
@@ -14,6 +14,6 @@
</div>
<div class="resetCodeBlock">
<label data-i18n="Reset Code:" for="password">Reset Code:</label>
<input type="text" name="code" class="text_pole" placeholder="XXXX">
<input type="text" name="code" class="text_pole" placeholder="XXXXXX">
</div>
</form>
+61 -4
View File
@@ -49,6 +49,7 @@ const OPENROUTER_PROVIDERS = [
'Clarifai',
'Cloudflare',
'Cohere',
'Crucible',
'Crusoe',
'DeepInfra',
'DeepSeek',
@@ -80,14 +81,17 @@ const OPENROUTER_PROVIDERS = [
'Morph',
'NCompass',
'Nebius',
'Nex AGI',
'NextBit',
'Novita',
'Nvidia',
'OpenAI',
'OpenInference',
'Parasail',
'Perceptron',
'Perplexity',
'Phala',
'Poolside',
'Recraft',
'Reka',
'Relace',
@@ -212,7 +216,7 @@ const NANOGPT_PROVIDERS = [
},
{
'id': 'ionet',
'label': 'Io Net',
'label': 'io.net',
},
{
'id': 'inceptron',
@@ -256,7 +260,11 @@ const NANOGPT_PROVIDERS = [
},
{
'id': 'neuralwatt',
'label': 'Neuralwatt',
'label': 'NeuralWatt',
},
{
'id': 'tensorix',
'label': 'Tensorix',
},
{
'id': 'nextbit',
@@ -302,14 +310,26 @@ const NANOGPT_PROVIDERS = [
'id': 'together',
'label': 'Together',
},
{
'id': 'uomi',
'label': 'UOMI',
},
{
'id': 'venice',
'label': 'Venice',
},
{
'id': 'wafer',
'label': 'Wafer',
},
{
'id': 'wandb',
'label': 'Weights & Biases',
},
{
'id': 'xiaomi',
'label': 'Xiaomi',
},
{
'id': 'zai',
'label': 'Z.AI',
@@ -590,15 +610,37 @@ export function loadGenericModels(data) {
return;
}
data.sort((a, b) => a.id.localeCompare(b.id));
const models = data
.filter(model => model && typeof model.id === 'string' && model.id.length > 0)
.sort((a, b) => a.id.localeCompare(b.id));
const dataList = $('#generic_model_fill');
dataList.empty();
for (const model of data) {
const modelSelect = $('#generic_model_select');
modelSelect.empty();
modelSelect.append($('<option>', { value: '' }));
for (const model of models) {
const option = document.createElement('option');
option.value = model.id;
option.text = model.id;
dataList.append(option);
const selectOption = document.createElement('option');
selectOption.value = model.id;
selectOption.text = model.id;
selectOption.selected = model.id === textgen_settings.generic_model;
modelSelect.append(selectOption);
}
// Keep free-text entry for IDs that are not in the /v1/models list
if (textgen_settings.generic_model && !models.find(x => x.id === textgen_settings.generic_model)) {
modelSelect.append($('<option>', {
value: textgen_settings.generic_model,
text: textgen_settings.generic_model,
selected: true,
}));
}
}
@@ -1031,6 +1073,13 @@ function onLlamaCppModelSelect() {
$('#api_button_textgenerationwebui').trigger('click');
}
function onGenericModelSelect() {
const modelId = String($('#generic_model_select').val() ?? '');
textgen_settings.generic_model = modelId;
$('#generic_model_textgenerationwebui').val(modelId);
$('#api_button_textgenerationwebui').trigger('click');
}
function onOpenRouterModelSelect() {
const modelId = String($('#openrouter_model').val());
textgen_settings.openrouter_model = modelId;
@@ -1348,6 +1397,7 @@ export function initTextGenModels() {
$('#tabby_download_model').on('click', downloadTabbyModel);
$('#tabby_model').on('change', onTabbyModelSelect);
$('#llamacpp_model').on('change', onLlamaCppModelSelect);
$('#generic_model_select').on('change', onGenericModelSelect);
$('#featherless_model').on('change', () => onFeatherlessModelSelect(String($('#featherless_model').val())));
const providersSelect = $('.openrouter_providers');
@@ -1401,6 +1451,13 @@ export function initTextGenModels() {
width: '100%',
allowClear: true,
});
$('#generic_model_select').select2({
placeholder: t`Select a model`,
searchInputPlaceholder: t`Search models...`,
searchInputCssClass: 'text_pole',
width: '100%',
allowClear: true,
});
$('#model_infermaticai_select').select2({
placeholder: t`Select a model`,
searchInputPlaceholder: t`Search models...`,
+5 -5
View File
@@ -552,7 +552,7 @@ export function getTokenCount(str, padding = undefined) {
* @deprecated Use counterWrapperOpenAIAsync instead.
*/
function counterWrapperOpenAI(text) {
const message = { role: 'system', content: text };
const message = { content: text };
return countTokensOpenAI(message, true);
}
@@ -562,7 +562,7 @@ function counterWrapperOpenAI(text) {
* @returns {Promise<number>} Token count.
*/
function counterWrapperOpenAIAsync(text) {
const message = { role: 'system', content: text };
const message = { content: text };
return countTokensOpenAIAsync(message, true);
}
@@ -639,7 +639,7 @@ export function getTokenizerModel() {
}
if (oai_settings.chat_completion_source == chat_completion_sources.ELECTRONHUB && oai_settings.electronhub_model) {
if (oai_settings.electronhub_model.includes('gpt-4o') || oai_settings.electronhub_model.includes('gpt-5')) {
if (oai_settings.electronhub_model.includes('gpt-4o') || oai_settings.electronhub_model.includes('gpt-5') || oai_settings.electronhub_model.includes('gpt-6-')) {
return gpt4oTokenizer;
} else if (oai_settings.electronhub_model.includes('gpt-4.1') || oai_settings.electronhub_model.includes('gpt-4.5')) {
return gpt4oTokenizer;
@@ -801,7 +801,7 @@ export function countTokensOpenAI(messages, full = false) {
messages = [messages];
}
let token_count = -1;
let token_count = 0;
for (const message of messages) {
const model = getTokenizerModel();
@@ -851,7 +851,7 @@ export async function countTokensOpenAIAsync(messages, full = false) {
messages = [messages];
}
let token_count = -1;
let token_count = 0;
for (const message of messages) {
const model = getTokenizerModel();
+13 -1
View File
@@ -580,7 +580,13 @@ export class ToolManager {
}
if (typeof deltaValue === 'string') {
if (typeof targetValue === 'string') {
// `id`, `name`, `type` are sent in full by some providers on every
// streaming chunk; concatenating them would duplicate the value.
if (key === 'id' || key === 'name' || key === 'type') {
if (!targetValue) {
target[key] = deltaValue;
}
} else if (typeof targetValue === 'string') {
// Concatenate strings
target[key] = targetValue + deltaValue;
} else {
@@ -613,6 +619,12 @@ export class ToolManager {
return false;
}
// GPT-6 Astra requires Responses for tools. Sol and Luna allow Chat Completions tools only without reasoning.
if ([chat_completion_sources.OPENAI, chat_completion_sources.AZURE_OPENAI].includes(settings.chat_completion_source)
&& (/^gpt-6-astra/.test(model) || (/^gpt-6-(sol|luna)/.test(model) && settings.reasoning_effort !== 'min'))) {
return false;
}
// Post-processing will forcefully remove past tool calls from the prompt, making them useless
const { NONE, MERGE_TOOLS, SEMI_TOOLS, STRICT_TOOLS } = custom_prompt_post_processing_types;
const allowedPromptPostProcessing = [NONE, MERGE_TOOLS, SEMI_TOOLS, STRICT_TOOLS];
+37 -16
View File
@@ -7,7 +7,7 @@ import {
} from '../lib.js';
import { getContext } from './extensions.js';
import { characters, getRequestHeaders, processDroppedFiles, this_chid, user_avatar } from '../script.js';
import { animation_duration, characters, getRequestHeaders, processDroppedFiles, this_chid, user_avatar } from '../script.js';
import { isMobile } from './RossAscends-mods.js';
import { collapseNewlines, power_user } from './power-user.js';
import { debounce_timeout } from './constants.js';
@@ -692,13 +692,12 @@ export function isElementInViewport(el) {
* @param {{ (name: string): boolean; }} exists Function to check if name exists.
* @param {Object} [options] The options.
* @param {((baseName: string, i: number) => string)|null} [options.nameBuilder=null] Function to build the name.
* Starts with the index provided by `startIndex` (default is 1). If not provided, uses "${baseName} (${i})".
* Starts with the index provided by `startIndex` (default is 0). If not provided, uses `baseName` for index 0 and "${baseName} (${i})" for higher indices.
* @param {number} [options.maxTries=1000] The maximum number of tries to find a unique name. Default is 1000.
* @param {number} [options.startIndex=1] The index to start with when building the name. Default is 1.
* When set to 0, the intention is to also check if the basename (without applied index) is free.
* @param {number} [options.startIndex=0] The index to start with when building the name. Default is 0.
* @returns {string|null} A unique name. Null if no unique name could be found in `maxTries`.
*/
export function getUniqueName(baseName, exists, { nameBuilder = null, maxTries = 1000, startIndex = 1 } = {}) {
export function getUniqueName(baseName, exists, { nameBuilder = null, maxTries = 1000, startIndex = 0 } = {}) {
nameBuilder ??= (baseName, i) => i === 0 ? baseName : `${baseName} (${i})`;
let i = startIndex;
let name;
@@ -2787,32 +2786,54 @@ export function arraysEqual(a, b) {
* @param {string | HTMLElement} target - The CSS selector or the HTML element of the information block
* @param {string | HTMLElement?} content - The message to display inside the information block (supports HTML) or an HTML element
* @param {'hint' | 'info' | 'warning' | 'error'} [type='info'] - The type of message, which determines the styling of the information block
* @param {object} [options={}] - Optional settings
* @param {boolean} [options.animate=true] - Whether to animate the block sliding in when first shown
*/
export function setInfoBlock(target, content, type = 'info') {
export function setInfoBlock(target, content, type = 'info', { animate = true } = {}) {
if (!content) {
clearInfoBlock(target);
return;
}
const infoBlock = typeof target === 'string' ? document.querySelector(target) : target;
if (infoBlock) {
infoBlock.className = `info-block ${type}`;
if (typeof content === 'string') {
infoBlock.innerHTML = content;
} else {
infoBlock.innerHTML = '';
infoBlock.appendChild(content);
}
if (!infoBlock) return;
const wasVisible = infoBlock.classList.contains('info-block');
if (!wasVisible && animate) {
$(infoBlock).hide();
}
infoBlock.className = `info-block ${type}`;
if (typeof content === 'string') {
infoBlock.innerHTML = content;
} else {
infoBlock.innerHTML = '';
infoBlock.appendChild(content);
}
if (!wasVisible && animate) {
$(infoBlock).slideDown(animation_duration * 1.5);
}
}
/**
* Clears the content and style of an information block.
* @param {string | HTMLElement} target - The CSS selector or the HTML element of the information block
* @param {object} [options={}] - Optional settings
* @param {boolean} [options.animate=true] - Whether to animate the block fading out before clearing
*/
export function clearInfoBlock(target) {
export function clearInfoBlock(target, { animate = true } = {}) {
const infoBlock = typeof target === 'string' ? document.querySelector(target) : target;
if (infoBlock && infoBlock.classList.contains('info-block')) {
if (!infoBlock || !infoBlock.classList.contains('info-block')) return;
if (animate) {
$(infoBlock).slideUp(animation_duration * 1.5, () => {
infoBlock.className = '';
infoBlock.innerHTML = '';
$(infoBlock).css('display', '');
});
} else {
infoBlock.className = '';
infoBlock.innerHTML = '';
}
+147 -28
View File
@@ -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, escapeHtml } 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, setInfoBlock, clearInfoBlock } 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';
@@ -2495,45 +2495,125 @@ async function displayWorldEntries(name, data, navigation = navigation_option.no
$('#world_apply_current_sorting').off('click').on('click', async () => {
const entryCount = Object.keys(data.entries).length;
const moreThan100 = entryCount > 100;
let content = '<span>' + t`Apply your current sorting to the "Order" field. The Order values will go down from the chosen number.` + '</span>';
if (moreThan100) {
content += '<div class="m-t-1"><i class="fa-solid fa-triangle-exclamation" style="color: #FFD43B;"></i> ' + t`More than 100 entries in this world. If you don't choose a number higher than that, the lower entries will default to 0.<br />(Usual default: 100)<br />Minimum: ${entryCount}` + '</div>';
}
const contentEl = document.createElement('div');
const result = await Popup.show.input(t`Apply Current Sorting`, content, '100', { okButton: t`Apply`, cancelButton: 'Cancel' });
if (!result) return;
const heading = document.createElement('h3');
heading.textContent = t`Apply Current Sorting`;
contentEl.appendChild(heading);
const description = document.createElement('span');
const descriptionText = document.createElement('p');
descriptionText.innerHTML = t`Assigns Order values to all entries based on their current sort position.`;
contentEl.appendChild(descriptionText);
const descriptionDetail = document.createElement('p');
descriptionDetail.innerHTML = t`Entries are ordered <b>descending</b> by default — the first entry in the list gets the highest value and will be inserted first into the prompt.`;
contentEl.appendChild(descriptionDetail);
const entryCountText = document.createElement('small');
entryCountText.textContent = t`(${entryCount} entries total)`;
contentEl.appendChild(entryCountText);
contentEl.appendChild(description);
const warningEl = document.createElement('div');
contentEl.appendChild(warningEl);
/** @type {(startInput: HTMLInputElement, stepInput: HTMLInputElement, ascendingInput: HTMLInputElement) => void} */
const updateWarning = (startInput, stepInput, ascendingInput) => {
const startVal = Number(startInput.value);
const stepVal = Number(stepInput.value);
const isAscending = ascendingInput.checked;
if (!isAscending && !isNaN(startVal) && !isNaN(stepVal) && startVal - (entryCount - 1) * stepVal < 0) {
setInfoBlock(warningEl, t`Some entries will be clamped to Order 0, causing collisions at the bottom. The last entry would reach ${startVal - (entryCount - 1) * stepVal} (${entryCount} entries, step ${stepVal}).`, 'warning');
} else {
clearInfoBlock(warningEl);
}
};
/** @type {import('./popup.js').CustomPopupInput[]} */
const customInputs = [
{
id: 'wi_sort_start',
label: t`Starting value`,
tooltip: t`The Order value assigned to the first entry. In descending mode, values count down from here; in ascending mode, values count up from here.` + ' ' + t`(${entryCount} entries total)`,
type: 'number',
defaultState: '100',
min: 0,
step: 1,
autoFocus: true,
},
{
id: 'wi_sort_step',
label: t`Step`,
tooltip: t`The gap between each Order value. For example, a step of 5 produces values like 100, 95, 90... (descending) or 0, 5, 10... (ascending).`,
type: 'number',
defaultState: '1',
min: 1,
step: 1,
},
{
id: 'wi_sort_ascending',
label: t`Ascending order`,
tooltip: t`When checked, Order values count upward from the starting value (first sorted entry gets the lowest Order). When unchecked, values count downward (first sorted entry gets the highest Order).`,
type: 'checkbox',
defaultState: false,
},
];
const popup = new Popup(contentEl, POPUP_TYPE.TEXT, null, {
okButton: t`Apply`,
cancelButton: t`Cancel`,
customInputs,
});
const startInput = /** @type {HTMLInputElement} */ (popup.dlg.querySelector('#wi_sort_start'));
const stepInput = /** @type {HTMLInputElement} */ (popup.dlg.querySelector('#wi_sort_step'));
const ascendingInput = /** @type {HTMLInputElement} */ (popup.dlg.querySelector('#wi_sort_ascending'));
startInput.addEventListener('input', () => updateWarning(startInput, stepInput, ascendingInput));
stepInput.addEventListener('input', () => updateWarning(startInput, stepInput, ascendingInput));
ascendingInput.addEventListener('change', () => updateWarning(startInput, stepInput, ascendingInput));
updateWarning(startInput, stepInput, ascendingInput);
const result = await popup.show();
if (result !== POPUP_RESULT.AFFIRMATIVE) return;
const start = Number(popup.inputResults.get('wi_sort_start') ?? '100');
const step = Number(popup.inputResults.get('wi_sort_step') ?? '1');
const ascending = Boolean(popup.inputResults.get('wi_sort_ascending'));
const start = Number(result);
if (isNaN(start) || start < 0) {
toastr.error(t`Invalid number: ${result}`, t`Apply Current Sorting`);
toastr.error(t`Invalid starting value: ${start}`, t`Apply Current Sorting`);
return;
}
if (start < entryCount) {
toastr.warning(t`A number lower than the entry count has been chosen. All entries below that will default to 0.`, t`Apply Current Sorting`);
if (isNaN(step) || step < 1) {
toastr.error(t`Invalid step value: ${step}`, t`Apply Current Sorting`);
return;
}
if (!ascending && start < entryCount) {
toastr.warning(t`A starting value lower than the entry count has been chosen. All entries below that will default to 0.`, t`Apply Current Sorting`);
}
// We need to sort the entries here, as the data source isn't sorted
const entries = Object.values(data.entries);
sortWorldInfoEntries(entries);
let updated = 0, current = start;
for (const entry of entries) {
const newOrder = Math.max(current--, 0);
if (entry.order === newOrder) continue;
let updated = 0;
entries.forEach((entry, index) => {
const newOrder = ascending
? start + index * step
: Math.max(start - index * step, 0);
if (entry.order === newOrder) return;
entry.order = newOrder;
setWIOriginalDataValue(data, entry.order, 'order', entry.order);
setWIOriginalDataValue(data, entry.uid, 'order', entry.order);
updated++;
}
});
if (updated > 0) {
toastr.info(`Updated ${updated} Order values`, 'Apply Custom Sorting');
toastr.info(t`Updated ${updated} Order values`, t`Apply Current Sorting`);
await saveWorldInfo(name, data, true);
updateEditor(navigation_option.previous);
} else {
toastr.info('All values up to date', 'Apply Custom Sorting');
toastr.info(t`All values up to date`, t`Apply Current Sorting`);
}
});
@@ -4123,11 +4203,12 @@ async function renameWorldInfo(name, data) {
}
const entryPreviouslySelected = selected_world_info.findIndex((e) => e === oldName);
const retargetPersonaLore = power_user.persona_description_lorebook === oldName;
await saveWorldInfo(newName, data, true);
await deleteWorldInfo(oldName);
await updateWorldInfoLinks(oldName, newName);
await updateWorldInfoLinks(oldName, newName, { retargetPersonaLore });
if (entryPreviouslySelected !== -1) {
const wiElement = getWIElement(newName);
@@ -4145,9 +4226,10 @@ async function renameWorldInfo(name, data) {
* Retargets all character lore links from an old world info name to a new one, with an optional confirmation for primary lorebook links
* @param {string} oldName Previous WI file name
* @param {string} newName New WI file name
* @param {{ retargetPersonaLore?: boolean }} [options] Additional relink options
* @returns {Promise<void>}
*/
async function updateWorldInfoLinks(oldName, newName) {
async function updateWorldInfoLinks(oldName, newName, { retargetPersonaLore } = {}) {
const existingCharLores = world_info.charLore?.filter((e) => e.extraBooks.includes(oldName));
if (existingCharLores && existingCharLores.length > 0) {
existingCharLores.forEach((charLore) => {
@@ -4158,6 +4240,36 @@ async function updateWorldInfoLinks(oldName, newName) {
saveSettingsDebounced();
}
// Update link for active persona
if (retargetPersonaLore) {
power_user.persona_description_lorebook = newName;
const object = getOrCreatePersonaDescriptor();
object.lorebook = newName;
setPersonaDescription();
saveSettingsDebounced();
}
// Update links for other personas
Object.keys(power_user.personas).forEach((persona) => {
if (user_avatar === persona) {
return;
}
const descriptor = power_user.persona_descriptions[persona];
if (!descriptor) {
return;
}
if (descriptor.lorebook === oldName) {
descriptor.lorebook = newName;
saveSettingsDebounced();
}
});
// update the world info key to the new name if it's still set to the old one
if (chat_metadata[METADATA_KEY] === oldName) {
chat_metadata[METADATA_KEY] = newName;
await saveMetadata();
}
// find all characters using the old lorebook name as their primary world
const linkedChIDs = [];
characters.forEach((character, chid) => {
@@ -4879,12 +4991,19 @@ export async function checkWorldInfo(chat, maxContext, isDryRun, globalScanData
console.debug(`[WI] Search done. Found ${activatedNow.size} possible entries.`);
// Sort the entries for the probability and the budget limit checks
const newEntries = [...activatedNow]
.sort((a, b) => {
const isASticky = timedEffects.isEffectActive('sticky', a) ? 1 : 0;
const isBSticky = timedEffects.isEffectActive('sticky', b) ? 1 : 0;
return isBSticky - isASticky || sortedEntries.indexOf(a) - sortedEntries.indexOf(b);
});
let newEntries;
if (activatedNow.size > 1) {
const sortedEntriesIndex = new Map(sortedEntries.map((entry, index) => [entry, index]));
newEntries = [...activatedNow]
.sort((a, b) => {
const isASticky = timedEffects.isEffectActive('sticky', a) ? 1 : 0;
const isBSticky = timedEffects.isEffectActive('sticky', b) ? 1 : 0;
return isBSticky - isASticky
|| (sortedEntriesIndex.get(a) ?? -1) - (sortedEntriesIndex.get(b) ?? -1);
});
} else {
newEntries = [...activatedNow];
}
let newContent = '';
+15 -7
View File
@@ -466,7 +466,7 @@ input[type='checkbox']:focus-visible {
align-items: baseline;
}
.mes:has(.mes_reasoning:empty) .mes_reasoning_header {
.mes_reasoning_details:not([data-has-content="true"]) .mes_reasoning_header {
cursor: default;
}
@@ -489,10 +489,11 @@ input[type='checkbox']:focus-visible {
.mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning_actions .mes_button:not(.edit_button),
.mes_reasoning_details:not(:has(.reasoning_edit_textarea)) .mes_reasoning_actions .edit_button,
.mes_block:has(.edit_textarea):has(.reasoning_edit_textarea) .mes_reasoning_actions,
.mes.reasoning:not([data-reasoning-state="hidden"]) .mes_edit_add_reasoning,
.mes:has(.mes_reasoning:empty) .mes_reasoning_arrow,
.mes:has(.mes_reasoning:empty) .mes_reasoning,
.mes:has(.mes_reasoning:empty) .mes_reasoning_copy {
.mes.reasoning:has(.mes_reasoning_details[data-has-content="true"]) .mes_edit_add_reasoning,
.mes:has(.mes_reasoning_details .reasoning_edit_textarea) .mes_edit_add_reasoning,
.mes_reasoning_details:not([data-has-content="true"]) .mes_reasoning_arrow,
.mes_reasoning_details:not([data-has-content="true"]) .mes_reasoning,
.mes_reasoning_details:not([data-has-content="true"]) .mes_reasoning_copy {
display: none;
}
@@ -500,8 +501,10 @@ input[type='checkbox']:focus-visible {
background-color: color-mix(in srgb, var(--SmartThemeQuoteColor) 33%, var(--SmartThemeBlurTintColor) 66%);
}
/** If hidden reasoning should not be shown, we hide all blocks that don't have content */
#chat:not([data-show-hidden-reasoning="true"]):not(:has(.reasoning_edit_textarea)) .mes:has(.mes_reasoning:empty) .mes_reasoning_details {
/** If hidden reasoning should not be shown, we hide all blocks that don't have content,
* except the one currently being edited.
*/
#chat:not([data-show-hidden-reasoning="true"]) .mes_reasoning_details:not([data-has-content="true"]):not(:has(.reasoning_edit_textarea)) {
display: none;
}
@@ -2678,6 +2681,11 @@ textarea::placeholder {
height: fit-content;
}
/* Keep non-login secrets visually masked without using password input semantics. */
.masked-secret {
-webkit-text-security: disc;
}
select.text_pole {
padding-right: 20px;
}
+2 -2
View File
@@ -4,7 +4,7 @@ import yaml from 'yaml';
import color from 'chalk';
import _ from 'lodash';
import { serverDirectory } from './server-directory.js';
import { keyToEnv, setConfigFilePath } from './util.js';
import { keyToEnv, setConfigFilePath, stringToBool } from './util.js';
const keyMigrationMap = [
{
@@ -181,7 +181,7 @@ export function addMissingConfigValues(configPath) {
const newEnvKey = keyToEnv(newKey);
if (process.env[oldEnvKey] && !process.env[newEnvKey]) {
const oldValue = process.env[oldEnvKey];
const newValue = migrate(oldValue);
const newValue = migrate(stringToBool(oldValue));
process.env[newEnvKey] = newValue;
delete process.env[oldEnvKey];
console.warn(color.yellow(`Warning: Using a deprecated environment variable: ${oldEnvKey}. Please use ${newEnvKey} instead.`));
+13 -1
View File
@@ -456,7 +456,7 @@ export const AZURE_OPENAI_KEYS = [
'reasoning_effort',
];
export const OPENAI_VERBOSITY_MODELS = /^gpt-5/;
export const OPENAI_VERBOSITY_MODELS = /^(?:gpt-5|gpt-6-)/;
export const OPENAI_REASONING_EFFORT_MODELS = [
'o1',
@@ -487,6 +487,13 @@ export const OPENAI_REASONING_EFFORT_MODELS = [
'gpt-5.4-nano-2026-03-17',
'gpt-5.5',
'gpt-5.5-2026-04-23',
'gpt-5.6',
'gpt-5.6-sol',
'gpt-5.6-terra',
'gpt-5.6-luna',
'gpt-6-astra',
'gpt-6-sol',
'gpt-6-luna',
];
export const OPENAI_REASONING_EFFORT_MAP = {
@@ -561,6 +568,11 @@ export const ZAI_ENDPOINT = {
CODING: 'coding',
};
export const POLLINATIONS_ENDPOINT = {
AUTHENTICATED: 'authenticated',
ANONYMOUS: 'anonymous',
};
export const SILICONFLOW_ENDPOINT = {
GLOBAL: 'global',
CN: 'cn',
+147 -48
View File
@@ -1,4 +1,5 @@
/* eslint-disable dot-notation */
import { createHmac } from 'node:crypto';
import process from 'node:process';
import util from 'node:util';
import express from 'express';
@@ -20,6 +21,7 @@ import {
SILICONFLOW_ENDPOINT,
MINIMAX_ENDPOINT,
ZAI_ENDPOINT,
POLLINATIONS_ENDPOINT,
} from '../../constants.js';
import {
forwardFetchResponse,
@@ -65,6 +67,8 @@ import {
getWebTokenizer,
} from '../tokenizers.js';
import { getVertexAIAuth, getProjectIdFromServiceAccount } from '../google.js';
import { getCookieSecret } from '../../users.js';
import { fetchGoogleModels, GoogleModelsHttpError } from './google-models.js';
const API_OPENAI = 'https://api.openai.com/v1';
const API_CLAUDE = 'https://api.anthropic.com/v1';
@@ -83,6 +87,7 @@ const API_DEEPSEEK = 'https://api.deepseek.com/beta';
const API_XAI = 'https://api.x.ai/v1';
const API_AIMLAPI = 'https://api.aimlapi.com/v1';
const API_POLLINATIONS = 'https://gen.pollinations.ai/v1';
const API_POLLINATIONS_ANON = 'https://text.pollinations.ai/v1';
const API_MOONSHOT = 'https://api.moonshot.ai/v1';
const API_FIREWORKS = 'https://api.fireworks.ai/inference/v1';
const API_COMETAPI = 'https://api.cometapi.com/v1';
@@ -106,6 +111,18 @@ const cachingAtDepth = (() => {
})();
const enableAdaptiveThinking = getConfigValue('claude.enableAdaptiveThinking', true, 'boolean');
/**
* Lazily-cached HMAC key (instance cookie secret) for session-affinity hashing.
* @type {string|undefined}
*/
let affinityKey;
function getAffinityKey() {
if (affinityKey === undefined) {
affinityKey = getCookieSecret(globalThis.DATA_ROOT);
}
return affinityKey;
}
/**
* Cache for cacheable (writing) OpenRouter model IDs.
* @type {string[]}
@@ -231,13 +248,17 @@ async function sendClaudeRequest(request, response) {
const useTools = Array.isArray(request.body.tools) && request.body.tools.length > 0;
const useSystemPrompt = Boolean(request.body.use_sysprompt);
const convertedPrompt = convertClaudeMessages(request.body.messages, request.body.assistant_prefill, useSystemPrompt, useTools, getPromptNames(request));
const useThinking = /^claude-(3-7|opus-4|sonnet-4|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model);
const useWebSearch = /^claude-(3-5|3-7|opus-4|sonnet-4|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model) && Boolean(request.body.enable_web_search);
// Unanchored to also match prefixed ids passed through proxies, e.g. 'anthropic/claude-fable-5'
const isFableModel = /claude-fable/.test(request.body.model);
const useNativeJsonOutput = /claude-(fable-5-1|opus-5-5)/.test(request.body.model);
const isClaude5Model = /claude-(opus-5|sonnet-5)/.test(request.body.model);
const useThinking = /^claude-(3-7|opus-4|sonnet-4|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model) || isFableModel || isClaude5Model;
const useWebSearch = (/^claude-(3-5|3-7|opus-4|sonnet-4|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model) || isFableModel || isClaude5Model) && Boolean(request.body.enable_web_search);
const isLimitedSampling = /^claude-(opus-4-1|sonnet-4-5|haiku-4-5|opus-4-5|opus-4-6|sonnet-4-6)/.test(request.body.model);
const useVerbosity = /^claude-(opus-4-5|opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model);
const noPrefillModel = /^claude-(opus-4-6|sonnet-4-6|opus-4-7)/.test(request.body.model);
const isAdaptiveModel = /^claude-(opus-4-7)/.test(request.body.model) || (enableAdaptiveThinking && /^claude-(opus-4-6|sonnet-4-6)/.test(request.body.model));
const noSamplingModel = /^claude-(opus-4-7)/.test(request.body.model);
const useVerbosity = /^claude-(opus-4-5|opus-4-6|sonnet-4-6|opus-4-7|opus-4-8)/.test(request.body.model) || isFableModel || isClaude5Model;
const noPrefillModel = /^claude-(opus-4-6|sonnet-4-6|opus-4-7|opus-4-8)/.test(request.body.model) || isFableModel || isClaude5Model;
const isAdaptiveModel = /^claude-(opus-4-7|opus-4-8)/.test(request.body.model) || isFableModel || isClaude5Model || (enableAdaptiveThinking && /^claude-(opus-4-6|sonnet-4-6)/.test(request.body.model));
const noSamplingModel = /^claude-(opus-4-7|opus-4-8)/.test(request.body.model) || isFableModel || isClaude5Model;
let fixThinkingPrefill = false;
// Add custom stop sequences
const stopSequences = [];
@@ -278,15 +299,24 @@ async function sendClaudeRequest(request, response) {
}
}
// Structured output is a forced tool
// Fable 5.1 and Opus 5.5 reject forced tools, but support native JSON outputs.
if (request.body.json_schema) {
const jsonTool = {
name: request.body.json_schema.name,
description: request.body.json_schema.description || 'Well-formed JSON object',
input_schema: request.body.json_schema.value,
};
requestBody.tools = [...(requestBody.tools || []), jsonTool];
requestBody.tool_choice = { type: 'tool', name: request.body.json_schema.name };
if (useNativeJsonOutput) {
requestBody.output_config = {
format: {
type: 'json_schema',
schema: request.body.json_schema.value,
},
};
} else {
const jsonTool = {
name: request.body.json_schema.name,
description: request.body.json_schema.description || 'Well-formed JSON object',
input_schema: request.body.json_schema.value,
};
requestBody.tools = [...(requestBody.tools || []), jsonTool];
requestBody.tool_choice = { type: 'tool', name: request.body.json_schema.name };
}
}
if (useWebSearch) {
@@ -321,13 +351,13 @@ async function sendClaudeRequest(request, response) {
}
const reasoningEffort = request.body.reasoning_effort;
const includeReasoning = Boolean(request.body.include_reasoning);
const budgetTokens = calculateClaudeBudgetTokens(requestBody.max_tokens, reasoningEffort, requestBody.stream, isAdaptiveModel);
// Adaptive thinking: returns a string effort level (like Gemini 3)
if (useThinking && typeof budgetTokens === 'string') {
fixThinkingPrefill = true;
requestBody.thinking = { type: 'adaptive' };
const includeReasoning = Boolean(request.body.include_reasoning);
if (noSamplingModel && includeReasoning) {
requestBody.thinking.display = 'summarized';
}
@@ -335,6 +365,10 @@ async function sendClaudeRequest(request, response) {
requestBody.output_config.effort = budgetTokens;
// top_k is not allowed in adaptive mode
delete requestBody.top_k;
} else if (useThinking && (isFableModel || isClaude5Model) && reasoningEffort === 'auto' && includeReasoning) {
// Fable/Claude 5 auto thinking is already enabled, but readable summaries require an explicit display request.
fixThinkingPrefill = true;
requestBody.thinking = { type: 'adaptive', display: 'summarized' };
} else if (useThinking && Number.isInteger(budgetTokens)) {
// Traditional thinking: returns a numeric budget
fixThinkingPrefill = true;
@@ -485,12 +519,14 @@ async function sendMakerSuiteRequest(request, response) {
'gemini-2.0-flash-preview-image-generation',
'gemini-2.5-flash-image-preview',
'gemini-2.5-flash-image',
'gemini-3-pro-image-preview',
'gemini-3.1-flash-image-preview',
'gemini-3-pro-image',
'gemini-3.1-flash-image',
];
const isThinkingConfigModel = m => (/^gemini-2.5-(flash|pro)/.test(m) && !/-image(-preview)?$/.test(m)) || (/^gemini-3[.\d]*-(flash|pro)/.test(m));
const isImageSizeModel = m => /^gemini-3/.test(m);
// https://ai.google.dev/gemini-api/docs/latest-model#api-changes-and-parameter-updates
const noSamplingModel = /gemini-3\.[678]-flash|gemini-3\.5-flash-lite/.test(model);
const noSearchModels = [
'gemini-2.0-flash-lite',
@@ -504,6 +540,13 @@ async function sendMakerSuiteRequest(request, response) {
delete generationConfig.stopSequences;
}
if (noSamplingModel) {
delete generationConfig.temperature;
delete generationConfig.topP;
delete generationConfig.topK;
delete generationConfig.candidateCount;
}
const enableImageModality = requestImages && imageGenerationModels.includes(model);
const enableImageConfig = enableImageModality && (aspectRatio || imageSize);
if (enableImageModality) {
@@ -1789,8 +1832,9 @@ router.post('/status', async function (request, statusResponse) {
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) {
const isAnonymous = request.body.pollinations_endpoint === POLLINATIONS_ENDPOINT.ANONYMOUS;
apiUrl = 'https://gen.pollinations.ai/text';
apiKey = readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS, request.body.secret_id);
apiKey = isAnonymous ? 'anonymous' : 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;
@@ -1806,9 +1850,61 @@ router.post('/status', async function (request, statusResponse) {
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT, request.body.secret_id);
headers = {};
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.FIREWORKS) {
apiUrl = API_FIREWORKS;
apiKey = readSecret(request.user.directories, SECRET_KEYS.FIREWORKS, request.body.secret_id);
headers = {};
const modelsUrl = 'https://api.fireworks.ai/v1/accounts/fireworks/models?filter=supports_serverless%3Dtrue&pageSize=200';
try {
const response = await fetch(modelsUrl, {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + apiKey,
...headers,
},
});
if (response.ok) {
/** @type {any} */
const data = await response.json();
const models = Array.isArray(data?.models)
? data.models
.filter(m => m?.contextLength > 0 && m?.kind !== 'EMBEDDING_MODEL')
.map(m => ({
id: m.name,
name: m.displayName,
context_length: m.contextLength,
supports_tools: m.supportsTools,
supports_image_input: m.supportsImageInput,
}))
: [];
// Add fast router versions for models that have them
const fastRouters = {
'accounts/fireworks/models/glm-5p2': 'accounts/fireworks/routers/glm-5p2-fast',
'accounts/fireworks/models/kimi-k2p6': 'accounts/fireworks/routers/kimi-k2p6-fast',
'accounts/fireworks/models/kimi-k2p7-code': 'accounts/fireworks/routers/kimi-k2p7-code-fast',
'accounts/fireworks/models/kimi-k3': 'accounts/fireworks/routers/kimi-k3-fast',
};
for (const [standardId, fastId] of Object.entries(fastRouters)) {
const standard = models.find(m => m.id === standardId);
if (standard) {
models.push({
...standard,
id: fastId,
name: standard.name + ' (fast)',
});
}
}
console.debug('Available Fireworks models:', models.map(m => m.id));
return statusResponse.send({ data: models });
} else {
console.warn('Fireworks models endpoint failed:', response.status, response.statusText);
return statusResponse.send({ error: true, data: { data: [] } });
}
} catch (error) {
console.error('Error fetching Fireworks models:', error);
return statusResponse.send({ error: true, data: { data: [] } });
}
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MAKERSUITE) {
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MAKERSUITE, request.body.secret_id);
apiUrl = trimTrailingSlash(request.body.reverse_proxy || API_MAKERSUITE);
@@ -1823,26 +1919,15 @@ router.post('/status', async function (request, statusResponse) {
}
try {
const response = await fetch(modelsUrl);
if (response.ok) {
/** @type {any} */
const data = await response.json();
// Transform Google AI Studio models to OpenAI format
const models = data.models
?.filter(model => model.supportedGenerationMethods?.includes('generateContent'))
?.map(model => ({
...model,
id: model.name.replace('models/', ''),
})) || [];
console.info('Available Google AI Studio models:', models.map(m => m.id));
return statusResponse.send({ data: models });
} else {
console.warn('Google AI Studio models endpoint failed:', response.status, response.statusText);
const models = await fetchGoogleModels(modelsUrl);
console.info('Available Google AI Studio models:', models.map(m => m.id));
return statusResponse.send({ data: models });
} catch (error) {
if (error instanceof GoogleModelsHttpError) {
console.warn('Google AI Studio models endpoint failed:', error.status, error.statusText);
return statusResponse.send({ error: true, bypass: true, data: { data: [] } });
}
} catch (error) {
console.error('Error fetching Google AI Studio models:', error);
return statusResponse.send({ error: true, bypass: true, data: { data: [] } });
}
@@ -2227,6 +2312,11 @@ router.post('/generate', async function (request, response) {
},
};
if (request.body.logprobs > 0) {
bodyParams['top_logprobs'] = request.body.logprobs;
bodyParams['logprobs'] = true;
}
if (request.body.min_p !== undefined) {
bodyParams['min_p'] = request.body.min_p;
}
@@ -2366,6 +2456,9 @@ router.post('/generate', async function (request, response) {
apiKey = readSecret(request.user.directories, SECRET_KEYS.FIREWORKS, request.body.secret_id);
headers = {};
bodyParams = {};
if (request.body.reasoning_effort) {
bodyParams['reasoning_effort'] = request.body.reasoning_effort;
}
if (request.body.json_schema) {
bodyParams['response_format'] = {
type: 'json_schema',
@@ -2377,6 +2470,9 @@ router.post('/generate', async function (request, response) {
},
};
}
if (request.body.chat_id) {
headers['x-session-affinity'] = createHmac('sha256', getAffinityKey()).update(request.body.chat_id).digest('hex').slice(0, 16);
}
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.NANOGPT) {
apiUrl = API_NANOGPT;
apiKey = readSecret(request.user.directories, SECRET_KEYS.NANOGPT, request.body.secret_id);
@@ -2414,20 +2510,23 @@ 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, request.body.secret_id);
const isAnonymous = request.body.pollinations_endpoint === POLLINATIONS_ENDPOINT.ANONYMOUS;
apiUrl = isAnonymous ? API_POLLINATIONS_ANON : API_POLLINATIONS;
apiKey = isAnonymous ? 'anonymous' : readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS, request.body.secret_id);
headers = {};
bodyParams = {
reasoning_effort: request.body.reasoning_effort,
seed: request.body.seed ?? Math.floor(Math.random() * 99999999),
};
if (request.body.json_schema) {
bodyParams['response_format'] = {
type: 'json_schema',
json_schema: {
schema: request.body.json_schema.value,
},
};
if (!isAnonymous) {
bodyParams['reasoning_effort'] = request.body.reasoning_effort;
if (request.body.json_schema) {
bodyParams['response_format'] = {
type: 'json_schema',
json_schema: {
schema: request.body.json_schema.value,
},
};
}
}
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MOONSHOT) {
apiUrl = new URL(request.body.reverse_proxy || API_MOONSHOT).toString();
+99
View File
@@ -0,0 +1,99 @@
import fetch from 'node-fetch';
const GOOGLE_MODELS_PAGE_SIZE = 1000;
export class GoogleModelsHttpError extends Error {
/**
* @param {number} status HTTP status code
* @param {string} statusText HTTP status text
*/
constructor(status, statusText) {
super(`Google AI Studio models endpoint returned ${status} ${statusText}`.trim());
this.name = 'GoogleModelsHttpError';
this.status = status;
this.statusText = statusText;
}
}
export class GoogleModelsResponseError extends Error {
/**
* @param {string} message Error message
* @param {ErrorOptions} [options] Error options
*/
constructor(message, options) {
super(message, options);
this.name = 'GoogleModelsResponseError';
}
}
/**
* Fetches every page of Google AI Studio models and converts supported models.
*
* @param {string | URL} modelsUrl Google AI Studio models endpoint
* @param {typeof fetch} [fetchImpl] Fetch implementation
* @returns {Promise<object[]>} Models that support content generation
*/
export async function fetchGoogleModels(modelsUrl, fetchImpl = fetch) {
const requestUrl = new URL(modelsUrl);
requestUrl.searchParams.set('pageSize', String(GOOGLE_MODELS_PAGE_SIZE));
requestUrl.searchParams.delete('pageToken');
const models = [];
const pageTokens = new Set();
let pageNumber = 1;
while (true) {
let response;
try {
response = await fetchImpl(requestUrl.toString());
} catch (cause) {
throw new GoogleModelsResponseError(`Failed to fetch Google AI Studio models page ${pageNumber}.`, { cause });
}
if (!response.ok) {
throw new GoogleModelsHttpError(response.status, response.statusText);
}
let data;
try {
data = await response.json();
} catch (cause) {
throw new GoogleModelsResponseError(`Failed to parse Google AI Studio models page ${pageNumber}.`, { cause });
}
if (!data || !Array.isArray(data.models)) {
throw new GoogleModelsResponseError(`Google AI Studio models page ${pageNumber} has an invalid models field.`);
}
models.push(...data.models);
const nextPageToken = data.nextPageToken;
if (nextPageToken === undefined || nextPageToken === '') {
break;
}
if (typeof nextPageToken !== 'string') {
throw new GoogleModelsResponseError(`Google AI Studio models page ${pageNumber} has an invalid nextPageToken.`);
}
if (pageTokens.has(nextPageToken)) {
throw new GoogleModelsResponseError(`Google AI Studio models pagination repeated token on page ${pageNumber}.`);
}
pageTokens.add(nextPageToken);
requestUrl.searchParams.set('pageToken', nextPageToken);
pageNumber++;
}
return models
.filter(model => model?.supportedGenerationMethods?.includes('generateContent'))
.map((model, index) => {
if (typeof model.name !== 'string') {
throw new GoogleModelsResponseError(`Google AI Studio model at index ${index} has an invalid name.`);
}
return {
...model,
id: model.name.replace('models/', ''),
};
});
}
+6 -4
View File
@@ -14,7 +14,7 @@ import storage from 'node-persist';
import { AVATAR_WIDTH, AVATAR_HEIGHT, DEFAULT_AVATAR_PATH } from '../constants.js';
import { default as validateAvatarUrlMiddleware, getFileNameValidationFunction, forbiddenRegExp } from '../middleware/validateFileName.js';
import { deepMerge, humanizedDateTime, tryParse, MemoryLimitedMap, getConfigValue, mutateJsonString, clientRelativePath, getUniqueName, sanitizeSafeCharacterReplacements } from '../util.js';
import { deepMerge, humanizedDateTime, tryParse, MemoryLimitedMap, getConfigValue, mutateJsonString, clientRelativePath, getUniqueName, sanitizeSafeCharacterReplacements, getArrayBufferSlice } from '../util.js';
import { TavernCardValidator } from '../validator/TavernCardValidator.js';
import { parse, read, write } from '../character-card-parser.js';
import { readWorldInfoFile } from './worldinfo.js';
@@ -765,7 +765,7 @@ async function importFromYaml(uploadPath, context, preservedFileName) {
async function importFromCharX(uploadPath, { request }, preservedFileName) {
const fileBuffer = fs.readFileSync(uploadPath);
// Create a properly-sized ArrayBuffer (Node's buffer pool can cause oversized .buffer)
const data = fileBuffer.buffer.slice(fileBuffer.byteOffset, fileBuffer.byteOffset + fileBuffer.byteLength);
const data = getArrayBufferSlice(fileBuffer);
fs.unlinkSync(uploadPath);
const parser = new CharXParser(data);
@@ -801,7 +801,7 @@ async function importFromCharX(uploadPath, { request }, preservedFileName) {
}
async function importFromByaf(uploadPath, { request }, preservedFileName) {
const data = (await fsPromises.readFile(uploadPath)).buffer;
const data = getArrayBufferSlice(await fsPromises.readFile(uploadPath));
await fsPromises.unlink(uploadPath);
console.info('Importing from BYAF');
@@ -1081,7 +1081,9 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res
// Rename chats folder
if (fs.existsSync(oldChatsPath) && !fs.existsSync(newChatsPath)) {
fs.cpSync(oldChatsPath, newChatsPath, { recursive: true });
// Supplying a filter avoids a Node.js Windows copyDir crash while preserving all entries.
// https://github.com/nodejs/node/issues/63970
fs.cpSync(oldChatsPath, newChatsPath, { recursive: true, filter: () => true });
fs.rmSync(oldChatsPath, { recursive: true, force: true });
}
+107 -32
View File
@@ -1,3 +1,4 @@
import crypto from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
import readline from 'node:readline';
@@ -30,6 +31,23 @@ const checkIntegrity = !!getConfigValue('backups.chat.checkIntegrity', true, 'bo
export const CHAT_BACKUPS_PREFIX = 'chat_';
/**
* Builds a stable filename key for a chat's backups.
* Non-ASCII characters are replaced with underscores, so names such as CJK ones
* would all collapse to the same key and share one backup quota. A short hash of
* the raw name keeps those keys distinct while ASCII names stay unchanged (#5780).
* @param {string} name The name of the chat.
* @returns {string} Sanitized filename key for the backup files.
*/
export function getBackupKey(name) {
const sanitized = sanitize(name).replace(/[^a-z0-9]/gi, '_').toLowerCase();
if (/[^\x20-\x7E]/.test(name)) {
const hash = crypto.createHash('sha256').update(name).digest('hex').slice(0, 8);
return `${sanitized}_${hash}`;
}
return sanitized;
}
/**
* Saves a chat to the backups directory.
* @param {string} directory The user's backup directory.
@@ -44,8 +62,7 @@ function backupChat(directory, name, data, backupPrefix = CHAT_BACKUPS_PREFIX) {
if (!fs.existsSync(directory)) {
console.error(`The chat couldn't be backed up because no directory exists at ${directory}!`);
}
// replace non-alphanumeric characters with underscores
name = sanitize(name).replace(/[^a-z0-9]/gi, '_').toLowerCase();
name = getBackupKey(name);
const backupFile = path.join(directory, `${backupPrefix}${name}_${generateTimestamp()}.jsonl`);
@@ -66,15 +83,19 @@ function backupChat(directory, name, data, backupPrefix = CHAT_BACKUPS_PREFIX) {
const backupFunctions = new Map();
/**
* Gets a backup function for a user.
* Gets a backup function for a user and chat.
* Throttling is keyed per user and chat so that rapid saves in one chat cannot
* swallow the throttled backup of another chat saved in the same window.
* @param {string} handle User handle
* @param {string} name The name of the chat, as passed to backupChat
* @returns {typeof backupChat} Backup function
*/
function getBackupFunction(handle) {
if (!backupFunctions.has(handle)) {
backupFunctions.set(handle, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true }));
function getBackupFunction(handle, name) {
const key = `${handle} ${name}`;
if (!backupFunctions.has(key)) {
backupFunctions.set(key, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true }));
}
return backupFunctions.get(handle) || (() => { });
return backupFunctions.get(key) || (() => { });
}
/**
@@ -319,12 +340,25 @@ async function checkChatIntegrity(filePath, integritySlug) {
return true;
}
// Parse the first line of the chat file as JSON
// If the chat file is empty, there is nothing that could be lost by overwriting it
if (fs.statSync(filePath).size === 0) {
return true;
}
// Parse the first line of the chat file as JSON. Strip a UTF-8 BOM an external editor may have added.
const firstLine = await readFirstLine(filePath);
const jsonData = tryParse(firstLine);
const jsonData = tryParse(String(firstLine ?? '').replace(/^\uFEFF/, ''));
// If the first line of a non-empty file is not a JSON object, the file may be corrupted or truncated.
// Fail the check so the client asks for an explicit overwrite confirmation instead of silently losing data.
if (typeof jsonData !== 'object' || jsonData === null || Array.isArray(jsonData)) {
console.warn(`File "${filePath}" is not empty, but its first line could not be parsed as a chat header. Overwriting it requires an explicit confirmation.`);
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 intact (legacy chats created before integrity checks existed)
if (!chatIntegrity) {
console.debug(`File "${filePath}" does not have integrity metadata matching "${integritySlug}". The integrity validation has been skipped.`);
return true;
@@ -357,33 +391,66 @@ async function checkChatIntegrity(filePath, integritySlug) {
* @typedef {(textArray: string[]) => boolean} ChatMatchFunction
*/
export async function getChatInfo(pathToFile, additionalData = {}, withMetadata = false, matcher = null) {
return new Promise(async (res) => {
const parsedPath = path.parse(pathToFile);
const stats = await fs.promises.stat(pathToFile);
const hasMatcher = (typeof matcher === 'function');
const parsedPath = path.parse(pathToFile);
const hasMatcher = (typeof matcher === 'function');
const chatData = {
match: false,
file_id: parsedPath.name,
file_name: parsedPath.base,
file_size: formatBytes(stats.size),
chat_items: 0,
mes: '[The chat is empty]',
last_mes: stats.mtimeMs,
...additionalData,
};
// A chat that is deleted while a scan is running is not an error: treat it like a corrupted chat and move on.
const chatVanished = () => {
console.warn('Chat file was deleted while it was being scanned:', pathToFile);
return { match: false };
};
if (stats.size === 0) {
res(chatData);
return;
let stats;
try {
stats = await fs.promises.stat(pathToFile);
} catch (error) {
if (error.code === 'ENOENT') {
return chatVanished();
}
throw error;
}
const chatData = {
match: false,
file_id: parsedPath.name,
file_name: parsedPath.base,
file_size: formatBytes(stats.size),
chat_items: 0,
mes: '[The chat is empty]',
last_mes: stats.mtimeMs,
...additionalData,
};
if (stats.size === 0) {
return chatData;
}
return new Promise((res, rej) => {
const fileStream = fs.createReadStream(pathToFile);
// The file can still disappear between the stat above and the stream opening
fileStream.on('error', (error) => {
if (error.code === 'ENOENT') {
res(chatVanished());
return;
}
rej(error);
});
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
});
// readline re-emits input stream errors; without a listener the emit throws
rl.on('error', (error) => {
if (error.code === 'ENOENT') {
res(chatVanished());
return;
}
rej(error);
});
let lastLine;
let itemCounter = 0;
let hasAnyMatch = false;
@@ -410,8 +477,6 @@ export async function getChatInfo(pathToFile, additionalData = {}, withMetadata
lastLine = line;
});
rl.on('close', () => {
rl.close();
if (lastLine) {
const jsonData = tryParse(lastLine);
if (jsonData && (jsonData.name || jsonData.character_name || jsonData.chat_metadata)) {
@@ -422,9 +487,19 @@ export async function getChatInfo(pathToFile, additionalData = {}, withMetadata
res(chatData);
} else {
console.warn('Found an invalid or corrupted chat file:', pathToFile);
res({});
// The last line is unparseable or lacks known fields (e.g. a truncated write or an external edit).
// Resolve a degraded preview from the stat data instead of hiding an otherwise intact chat
// from the chat list, search and recents.
console.warn('Found an invalid or corrupted last line in a chat file:', pathToFile);
// Exclude both the metadata line and the unreadable trailing line.
chatData.chat_items = Math.max(itemCounter - 2, 0);
chatData.mes = '[The message is empty]';
chatData.match = hasMatcher ? hasAnyMatch : true;
res(chatData);
}
} else {
// The file was truncated after the stat reported a non-zero size; treat it like an empty chat
res(chatData);
}
});
});
@@ -464,7 +539,7 @@ export async function trySaveChat(chatData, filePath, skipIntegrityCheck = false
throw new IntegrityMismatchError(`Chat integrity check failed for "${filePath}". The expected integrity slug was "${chatIntegritySlug}".`);
}
tryWriteFileSync(filePath, jsonlData);
getBackupFunction(handle)(backupDirectory, cardName, jsonlData);
getBackupFunction(handle, cardName)(backupDirectory, cardName, jsonlData);
}
router.post('/save', validateAvatarUrlMiddleware, async function (request, response) {
+9 -9
View File
@@ -556,11 +556,6 @@ async function downloadPygmalionCharacter(id) {
*/
function parseChubUrl(str) {
const splitStr = str.split('/');
const length = splitStr.length;
if (length < 2) {
return null;
}
let domainIndex = -1;
@@ -570,20 +565,25 @@ function parseChubUrl(str) {
}
});
const lastTwo = domainIndex !== -1 ? splitStr.slice(domainIndex + 1) : splitStr;
const cleanUrl = domainIndex !== -1 ? splitStr.slice(domainIndex + 1) : splitStr;
const length = cleanUrl.length;
const firstPart = lastTwo[0].toLowerCase();
if (length < 2) {
return null;
}
const firstPart = cleanUrl[0].toLowerCase();
if (firstPart === 'characters' || firstPart === 'lorebooks') {
const type = firstPart === 'characters' ? 'character' : 'lorebook';
const id = type === 'character' ? lastTwo.slice(1).join('/') : lastTwo.join('/');
const id = type === 'character' ? cleanUrl.slice(1).join('/') : cleanUrl.join('/');
return {
id: id,
type: type,
};
} else if (length === 2) {
return {
id: lastTwo.join('/'),
id: cleanUrl.join('/'),
type: 'character',
};
}
+20 -1
View File
@@ -6,7 +6,7 @@ import sanitize from 'sanitize-filename';
import { CheckRepoActions, default as simpleGit } from 'simple-git';
import { PUBLIC_DIRECTORIES } from '../constants.js';
import { getConfigValue, isValidUrl } from '../util.js';
import { color, getConfigValue, isValidUrl } from '../util.js';
import { createGitClient } from '../git/client.js';
const gitBackend = getConfigValue('git.backend', 'auto');
@@ -486,17 +486,35 @@ router.get('/discover', function (request, response) {
fs.mkdirSync(PUBLIC_DIRECTORIES.globalExtensions);
}
/**
* A directory without a manifest.json is not a usable extension: typically a leftover
* from a manual deletion (e.g. a locked .git directory on Windows). Listing it would
* make the client report a ghost extension and request its manifest in vain on every load.
* @param {string} parentDirectory Directory containing extension folders
* @param {string} folder Extension folder name
* @returns {boolean} Whether the folder contains a manifest
*/
const hasManifest = (parentDirectory, folder) => {
const manifestExists = fs.existsSync(path.join(parentDirectory, folder, 'manifest.json'));
if (!manifestExists) {
console.warn(color.yellow(`Extension folder "${path.join(parentDirectory, folder)}" has no manifest.json and was skipped. Remove the folder to get rid of this warning.`));
}
return manifestExists;
};
// Get all folders in system extensions folder, excluding third-party
const builtInExtensions = fs
.readdirSync(PUBLIC_DIRECTORIES.extensions)
.filter(f => fs.statSync(path.join(PUBLIC_DIRECTORIES.extensions, f)).isDirectory())
.filter(f => f !== 'third-party')
.filter(f => hasManifest(PUBLIC_DIRECTORIES.extensions, f))
.map(f => ({ type: 'system', name: f }));
// Get all folders in local extensions folder
const userExtensions = fs
.readdirSync(path.join(request.user.directories.extensions))
.filter(f => fs.statSync(path.join(request.user.directories.extensions, f)).isDirectory())
.filter(f => hasManifest(request.user.directories.extensions, f))
.map(f => ({ type: 'local', name: `third-party/${f}` }));
// Get all folders in global extensions folder
@@ -504,6 +522,7 @@ router.get('/discover', function (request, response) {
const globalExtensions = fs
.readdirSync(PUBLIC_DIRECTORIES.globalExtensions)
.filter(f => fs.statSync(path.join(PUBLIC_DIRECTORIES.globalExtensions, f)).isDirectory())
.filter(f => hasManifest(PUBLIC_DIRECTORIES.globalExtensions, f))
.map(f => ({ type: 'global', name: `third-party/${f}` }))
.filter(f => !userExtensions.some(e => e.name === f.name));
+3 -4
View File
@@ -33,12 +33,11 @@ router.post('/generate-voice', async (request, response) => {
} = request.body;
const apiKey = readSecret(request.user.directories, SECRET_KEYS.MINIMAX);
const groupId = readSecret(request.user.directories, SECRET_KEYS.MINIMAX_GROUP_ID);
// Validate required parameters
if (!text || !voiceId || !apiKey || !groupId) {
if (!text || !voiceId || !apiKey) {
console.warn('MiniMax TTS: Missing required parameters');
return response.status(400).json({ error: 'Missing required parameters: text, voiceId, apiKey, and groupId are required' });
return response.status(400).json({ error: 'Missing required parameters: text, voiceId, and apiKey are required' });
}
const requestBody = {
@@ -64,7 +63,7 @@ router.post('/generate-voice', async (request, response) => {
requestBody.lang = language;
}
const apiUrl = `${apiHost}/v1/t2a_v2?GroupId=${groupId}`;
const apiUrl = `${apiHost}/v1/t2a_v2`;
console.debug('MiniMax TTS Request:', {
url: apiUrl,
+1 -1
View File
@@ -140,7 +140,7 @@ router.post('/status', async function (req, res) {
}
try {
const response = await fetch(API_NOVELAI + '/user/subscription', {
const response = await fetch(IMAGE_NOVELAI + '/user/subscription', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
+5 -15
View File
@@ -8,6 +8,7 @@ import express from 'express';
import { getConfigValue, mergeObjectWithYaml, excludeKeysByYaml, trimV1, delay } from '../util.js';
import { setAdditionalHeaders } from '../additional-headers.js';
import { readSecret, SECRET_KEYS } from './secrets.js';
import { POLLINATIONS_ENDPOINT } from '../constants.js';
import { AIMLAPI_HEADERS, OPENROUTER_HEADERS, SILICONFLOW_ENDPOINT, ZAI_ENDPOINT } from '../constants.js';
export const router = express.Router();
@@ -98,7 +99,8 @@ router.post('/caption-image', async (request, response) => {
}
if (request.body.api === 'pollinations') {
key = readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS);
const isAnonymous = request.body.pollinations_endpoint === POLLINATIONS_ENDPOINT.ANONYMOUS;
key = isAnonymous ? 'anonymous' : readSecret(request.user.directories, SECRET_KEYS.POLLINATIONS);
bodyParams.seed = Math.floor(Math.random() * Math.pow(2, 32));
}
@@ -182,7 +184,8 @@ router.post('/caption-image', async (request, response) => {
}
if (request.body.api === 'pollinations') {
apiUrl = 'https://gen.pollinations.ai/v1/chat/completions';
const isAnonymous = request.body.pollinations_endpoint === POLLINATIONS_ENDPOINT.ANONYMOUS;
apiUrl = isAnonymous ? 'https://text.pollinations.ai/v1/chat/completions' : 'https://gen.pollinations.ai/v1/chat/completions';
}
if (request.body.api === 'moonshot' && !request.body.reverse_proxy) {
@@ -232,19 +235,6 @@ router.post('/caption-image', async (request, response) => {
apiUrl = `${trimV1(request.body.server_url)}/v1/chat/completions`;
}
if (request.body.api === 'ooba') {
const imgMessage = body.messages.pop();
body.messages.push({
role: 'user',
content: imgMessage?.content?.[0]?.text,
});
body.messages.push({
role: 'user',
content: [],
image_url: imgMessage?.content?.[1]?.image_url?.url,
});
}
setAdditionalHeaders(request, { headers }, apiUrl);
console.debug('Multimodal captioning request', body);
+13 -3
View File
@@ -6,6 +6,7 @@ import { decode } from 'html-entities';
import { readSecret, SECRET_KEYS } from './secrets.js';
import { trimV1 } from '../util.js';
import { setAdditionalHeaders } from '../additional-headers.js';
import { getUntrustedRequestAgent } from '../private-request-filter.js';
export const router = express.Router();
@@ -416,8 +417,14 @@ router.post('/visit', async (request, response) => {
throw new Error('Invalid port');
}
// Reject IP addresses
if (ipRegex.v4({ exact: true }).test(urlObj.hostname) || ipRegex.v6({ exact: true }).test(urlObj.hostname)) {
// Reject IP addresses. A bracketed IPv6 literal keeps its brackets in URL.hostname.
const bareHostname = urlObj.hostname.replace(/^\[|\]$/g, '');
if (ipRegex.v4({ exact: true }).test(bareHostname) || ipRegex.v6({ exact: true }).test(bareHostname)) {
throw new Error('Invalid hostname');
}
// Reject localhost and .localhost domains to prevent SSRF bypass
if (urlObj.hostname === 'localhost' || urlObj.hostname.endsWith('.localhost')) {
throw new Error('Invalid hostname');
}
} catch (error) {
@@ -427,7 +434,10 @@ router.post('/visit', async (request, response) => {
console.info('Visiting web URL', url);
const result = await fetch(url, { headers: visitHeaders });
// The URL checks above only guard the literal input. The agent enforces the actual network
// boundary: it blocks connections to private addresses after DNS resolution, on every redirect
// hop, and pins the connection to the validated IP to prevent DNS rebinding.
const result = await fetch(url, { headers: visitHeaders, agent: getUntrustedRequestAgent() });
if (!result.ok) {
console.error(`Visit failed ${result.status} ${result.statusText}`);
+1 -1
View File
@@ -101,7 +101,7 @@ pollinations.post('/voices', async (req, res) => {
throw new Error('Invalid data format received from Pollinations');
}
const audioModelData = data.find(m => m.name === model);
const audioModelData = data.find(m => m.name === model || m.aliases?.includes(model));
if (!audioModelData || !Array.isArray(audioModelData.voices)) {
throw new Error('No voices found for the specified model');
}
+11 -4
View File
@@ -586,7 +586,7 @@ comfy.post('/generate', async (request, response) => {
/** @type {any} */
const data = await promptResult.json();
const id = data.prompt_id;
const historyUrl = new URL(urlJoin(request.body.url, '/history'));
const historyUrl = new URL(urlJoin(request.body.url, `/history/${id}`));
while (true) {
const result = await fetch(historyUrl);
if (!result.ok) {
@@ -611,7 +611,8 @@ comfy.post('/generate', async (request, response) => {
}
const outputs = Object.keys(item.outputs).map(it => item.outputs[it]);
console.debug('ComfyUI outputs:', outputs);
const imgInfo = outputs.map(it => it.images).flat()[0] ?? outputs.map(it => it.gifs).flat()[0];
const imgInfo = outputs.map(it => it.images).filter(Array.isArray).flat()[0]
?? outputs.map(it => it.gifs).filter(Array.isArray).flat()[0];
if (!imgInfo) {
throw new Error('ComfyUI did not return any recognizable outputs.');
}
@@ -1528,7 +1529,7 @@ bfl.post('/generate', async (request, response) => {
console.debug('BFL request:', requestBody);
const result = await fetch(`https://api.bfl.ml/v1/${request.body.model}`, {
const result = await fetch(`https://api.bfl.ai/v1/${request.body.model}`, {
method: 'POST',
body: JSON.stringify(requestBody),
headers: {
@@ -1545,12 +1546,18 @@ bfl.post('/generate', async (request, response) => {
/** @type {any} */
const taskData = await result.json();
const { id } = taskData;
const pollingUrl = taskData.polling_url ?? `https://api.bfl.ai/v1/get_result?id=${id}`;
const MAX_ATTEMPTS = 100;
for (let i = 0; i < MAX_ATTEMPTS; i++) {
await delay(2500);
const statusResult = await fetch(`https://api.bfl.ml/v1/get_result?id=${id}`);
// The bfl.ai API requires authentication on the polling request as well
const statusResult = await fetch(pollingUrl, {
headers: {
'x-key': key,
},
});
if (!statusResult.ok) {
const text = await statusResult.text();
+9 -9
View File
@@ -12,10 +12,9 @@ import { Tokenizer } from '@agnai/web-tokenizers';
import { SentencePieceProcessor } from '@agnai/sentencepiece-js';
import tiktoken from 'tiktoken';
import { convertClaudePrompt } from '../prompt-converters.js';
import { TEXTGEN_TYPES } from '../constants.js';
import { setAdditionalHeaders } from '../additional-headers.js';
import { getConfigValue, isValidUrl } from '../util.js';
import { getConfigValue, isValidUrl, trimV1 } from '../util.js';
/**
* @typedef { (req: import('express').Request, res: import('express').Response) => Promise<any> } TokenizationHandler
@@ -443,7 +442,7 @@ export function getTokenizerModel(requestModel) {
return 'o1';
}
if (requestModel.includes('gpt-5') || requestModel.includes('o3') || requestModel.includes('o4-mini')) {
if (requestModel.includes('gpt-5') || requestModel.includes('gpt-6-') || requestModel.includes('o3') || requestModel.includes('o4-mini')) {
return 'o1';
}
@@ -545,15 +544,14 @@ export function getTiktokenTokenizer(model) {
* @returns {number} Number of tokens
*/
export function countWebTokenizerTokens(tokenizer, messages) {
// Should be fine if we use the old conversion method instead of the messages API one i think?
const convertedPrompt = convertClaudePrompt(messages, false, '', false, false, '', false);
const jsonBody = messages.flatMap(x => Object.values(x)).join('\n\n');
// Fallback to strlen estimation
if (!tokenizer) {
return guesstimate(convertedPrompt);
return guesstimate(jsonBody);
}
const count = tokenizer.encode(convertedPrompt).length;
const count = tokenizer.encode(jsonBody).length;
return count;
}
@@ -1088,7 +1086,7 @@ router.post('/remote/textgenerationwebui/encode', async function (request, respo
setAdditionalHeaders(request, args, baseUrl);
// Convert to string + remove trailing slash + /v1 suffix
let url = String(baseUrl).replace(/\/$/, '').replace(/\/v1$/, '');
let url = trimV1(baseUrl);
switch (request.body.api_type) {
case TEXTGEN_TYPES.TABBY:
@@ -1111,10 +1109,12 @@ router.post('/remote/textgenerationwebui/encode', async function (request, respo
url += '/v1/tokenize';
args.body = JSON.stringify({ 'model': model, 'prompt': text });
break;
default:
case TEXTGEN_TYPES.OOBA:
url += '/v1/internal/encode';
args.body = JSON.stringify({ 'text': text });
break;
default:
return response.sendStatus(400);
}
const result = await fetch(url, args);
+43 -6
View File
@@ -4,15 +4,25 @@ import crypto from 'node:crypto';
import storage from 'node-persist';
import express from 'express';
import { RateLimiterMemory, RateLimiterRes } from 'rate-limiter-flexible';
import { getUserAvatar, toKey, getPasswordHash, getPasswordSalt, createBackupArchive, ensurePublicDirectoriesExist, toAvatarKey, getAccountVersion } from '../users.js';
import { SETTINGS_FILE } from '../constants.js';
import { checkForNewContent, CONTENT_TYPES } from './content-manager.js';
import { color, Cache, getConfigValue } from '../util.js';
import { getIpAddress, retryAfter } from '../express-common.js';
const RESET_POINTS = getConfigValue('rateLimiting.accountsResetMaxAttempts', 5, 'number');
const PREFER_REAL_IP_HEADER = getConfigValue('rateLimiting.preferRealIpHeader', false, 'boolean');
const RESET_CACHE = new Cache(5 * 60 * 1000);
const generateResetCode = () => Array.from({ length: 6 }, () => crypto.randomInt(0, 10)).join('');
export const router = express.Router();
const resetLimiter = new RateLimiterMemory({
points: RESET_POINTS > 0 ? RESET_POINTS : Number.MAX_SAFE_INTEGER,
duration: 300,
});
router.post('/logout', async (request, response) => {
try {
@@ -223,14 +233,27 @@ router.post('/change-name', async (request, response) => {
router.post('/reset-step1', async (request, response) => {
try {
const resetCode = String(crypto.randomInt(1000, 9999));
const ip = getIpAddress(request, PREFER_REAL_IP_HEADER);
const rateLimit = await resetLimiter.get(ip);
// Check for existing rate limits, but allow requesting a new code unless locked out
if (rateLimit !== null && rateLimit.consumedPoints > resetLimiter.points) {
throw rateLimit;
}
const resetCode = generateResetCode();
console.log();
console.log(color.magenta(`${request.user.profile.name}, your account reset code is: `) + color.red(resetCode));
console.log();
RESET_CACHE.set(request.user.profile.handle, resetCode);
return response.sendStatus(204);
} catch (error) {
console.error('Recover step 1 failed:', error);
if (error instanceof RateLimiterRes) {
console.error('Reset step 1 failed: Rate limited from', getIpAddress(request, PREFER_REAL_IP_HEADER));
return retryAfter(response, error).status(429).send({ error: 'Too many attempts. Try again later or contact your admin.' });
}
console.error('Reset step 1 failed:', error);
return response.sendStatus(500);
}
});
@@ -238,19 +261,27 @@ router.post('/reset-step1', async (request, response) => {
router.post('/reset-step2', async (request, response) => {
try {
if (!request.body.code) {
console.warn('Recover step 2 failed: Missing required fields');
console.warn('Reset step 2 failed: Missing required fields');
return response.status(400).json({ error: 'Missing required fields' });
}
if (request.user.profile.password && request.user.profile.password !== getPasswordHash(request.body.password, request.user.profile.salt)) {
console.warn('Recover step 2 failed: Incorrect password');
console.warn('Reset step 2 failed: Incorrect password');
return response.status(400).json({ error: 'Incorrect password' });
}
const ip = getIpAddress(request, PREFER_REAL_IP_HEADER);
const rateLimit = await resetLimiter.get(ip);
if (rateLimit !== null && rateLimit.consumedPoints > resetLimiter.points) {
throw rateLimit;
}
const code = RESET_CACHE.get(request.user.profile.handle);
if (!code || code !== request.body.code) {
console.warn('Recover step 2 failed: Incorrect code');
await resetLimiter.consume(ip);
console.warn('Reset step 2 failed: Incorrect code');
return response.status(400).json({ error: 'Incorrect code' });
}
@@ -260,10 +291,16 @@ router.post('/reset-step2', async (request, response) => {
await ensurePublicDirectoriesExist();
await checkForNewContent([request.user.directories]);
await resetLimiter.delete(ip);
RESET_CACHE.remove(request.user.profile.handle);
return response.sendStatus(204);
} catch (error) {
console.error('Recover step 2 failed:', error);
if (error instanceof RateLimiterRes) {
console.error('Reset step 2 failed: Rate limited from', getIpAddress(request, PREFER_REAL_IP_HEADER));
return retryAfter(response, error).status(429).send({ error: 'Too many attempts. Try again later or contact your admin.' });
}
console.error('Reset step 2 failed:', error);
return response.sendStatus(500);
}
});
+6
View File
@@ -26,6 +26,12 @@ export default async function corsProxyMiddleware(req, res) {
headersToRemove.forEach(header => delete headers[header]);
// Force a set of encodings that node-fetch/undici can transparently decompress.
// Some origins (e.g. Cloudflare-fronted sites) will respond with zstd when a browser's
// full Accept-Encoding list is forwarded as-is; undici does not decode zstd, so the raw
// compressed bytes would otherwise be piped straight through to the client as garbage.
headers['accept-encoding'] = 'gzip, deflate, br';
const bodyMethods = ['POST', 'PUT', 'PATCH'];
const response = await fetch(url, {
+33 -1
View File
@@ -196,6 +196,35 @@ class PrivateRequestAgent extends Agent {
}
}
/**
* Whether requests to untrusted URLs should follow the global agent chain instead of the strict agent:
* either the private request filter is enabled (the global agents filter with the user's configured
* whitelist), or a request proxy owns outbound routing and a direct connection would bypass it.
* @type {boolean}
*/
let untrustedFilteringDelegated = false;
/** @type {PrivateRequestAgent|null} */
let strictAgent = null;
/**
* Get the agent to use for outbound requests to untrusted, user-supplied URLs (e.g. /api/search/visit).
* Returns a strict agent that blocks all private addresses at connection time, including on redirect hops,
* regardless of whether the private request filter is enabled. Returns undefined when the global agent
* chain already handles these requests (private request filter enabled, or request proxy owns routing),
* so the default agent selection applies.
* @returns {PrivateRequestAgent|undefined} The agent to pass to the outbound request, or undefined.
*/
export function getUntrustedRequestAgent() {
if (untrustedFilteringDelegated) {
return undefined;
}
if (!strictAgent) {
strictAgent = new PrivateRequestAgent({ privateAddressWhitelist: [], logBlocked: true, logAllowed: false, allowUnresolvedHosts: false, enableKeepAlive: false });
}
return strictAgent;
}
/**
* Initialize the private request filter by replacing the global HTTP and HTTPS agents with an instance of PrivateRequestAgent.
* @param {object} options Options for initializing the private request filter.
@@ -206,8 +235,11 @@ class PrivateRequestAgent extends Agent {
* @param {boolean} options.logAllowed Whether to log allowed requests to the console.
* @param {boolean} options.allowUnresolvedHosts Whether to allow requests to hosts that cannot be resolved.
* @param {boolean} options.enableKeepAlive Whether to enable HTTP/HTTPS keep-alive.
* @param {boolean} [options.requestProxyEnabled] Whether a request proxy is enabled and owns outbound routing.
*/
export default function initPrivateRequestFilter({ listen, enabled, privateAddressWhitelist, logBlocked, logAllowed, allowUnresolvedHosts, enableKeepAlive }) {
export default function initPrivateRequestFilter({ listen, enabled, privateAddressWhitelist, logBlocked, logAllowed, allowUnresolvedHosts, enableKeepAlive, requestProxyEnabled }) {
untrustedFilteringDelegated = !!enabled || !!requestProxyEnabled;
if (!enabled) {
if (listen) {
console.warn();
+9 -3
View File
@@ -390,7 +390,7 @@ export function convertCohereMessages(messages, names) {
}
messages.forEach((msg, index) => {
// Tool calls require an assistent primer
// Tool calls require an assistant primer
if (Array.isArray(msg.tool_calls)) {
if (index > 0 && messages[index - 1].role === 'assistant') {
msg.content = messages[index - 1].content;
@@ -453,13 +453,17 @@ export function convertGooglePrompt(messages, model, useSysPrompt, names) {
const system_instruction = { parts: sysPrompt.map(text => ({ text })) };
const toolNameMap = {};
// https://ai.google.dev/gemini-api/docs/latest-model#prefilled-model-turn-validation
const noPrefillModel = /gemini-3\.[678]-flash|gemini-3\.5-flash-lite/.test(model);
const contents = [];
messages.forEach((message, index) => {
// fix the roles
if (message.role === 'system' || message.role === 'tool') {
message.role = 'user';
} else if (message.role === 'assistant') {
message.role = 'model';
// A trailing model turn is a prefill, which is rejected by the newest models
message.role = noPrefillModel && index === messages.length - 1 ? 'user' : 'model';
}
// Convert the content to an array of parts
@@ -1259,11 +1263,13 @@ export function calculateGoogleBudgetTokens(maxTokens, reasoningEffort, model) {
}
function getGemini3FlashBudget() {
// https://ai.google.dev/gemini-api/docs/models/gemini-3.7-flash
const noMinimalThinking = /gemini-3\.[78]-flash/.test(model);
switch (reasoningEffort) {
case REASONING_EFFORT.auto:
return null;
case REASONING_EFFORT.min:
return 'minimal';
return noMinimalThinking ? 'low' : 'minimal';
case REASONING_EFFORT.low:
return 'low';
case REASONING_EFFORT.medium:
+1
View File
@@ -343,6 +343,7 @@ async function preSetupTasks() {
logAllowed: !!getConfigValue('privateAddressWhitelist.log.allowedRequests', false, 'boolean'),
allowUnresolvedHosts: !!getConfigValue('privateAddressWhitelist.allowUnresolvedHosts', false, 'boolean'),
enableKeepAlive: cliArgs.enableKeepAlive,
requestProxyEnabled: !!cliArgs.requestProxyEnabled,
};
initPrivateRequestFilter(requestFilterOptions);
+37 -14
View File
@@ -486,6 +486,20 @@ export async function readAllChunks(readableStream) {
});
}
/**
* Creates a precisely-sized ArrayBuffer from a Uint8Array view such as a Node Buffer.
* This avoids leaking unrelated bytes from the underlying backing store.
* @param {Uint8Array} view Source byte view
* @returns {ArrayBuffer} Exact ArrayBuffer slice for the provided view
*/
export function getArrayBufferSlice(view) {
if (!(view instanceof Uint8Array)) {
throw new TypeError('Expected Uint8Array');
}
return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
}
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
@@ -666,18 +680,7 @@ export function removeOldBackups(directory, prefix, limit = null) {
* @returns {string[]} List of image file names
*/
export function getImages(directoryPath, sortBy = 'name', type = MEDIA_REQUEST_TYPE.IMAGE) {
function getSortFunction() {
switch (sortBy) {
case 'name':
return Intl.Collator().compare;
case 'date':
return (a, b) => fs.statSync(path.join(directoryPath, a)).mtimeMs - fs.statSync(path.join(directoryPath, b)).mtimeMs;
default:
return (_a, _b) => 0;
}
}
return fs
const files = fs
.readdirSync(directoryPath, { withFileTypes: true })
.filter(dirent => dirent.isFile())
.map(dirent => dirent.name)
@@ -696,8 +699,28 @@ export function getImages(directoryPath, sortBy = 'name', type = MEDIA_REQUEST_T
return true;
}
return false;
})
.sort(getSortFunction());
});
switch (sortBy) {
case 'name':
return files.sort(Intl.Collator().compare);
case 'date': {
const mtimes = new Map();
for (const file of files) {
try {
mtimes.set(file, fs.statSync(path.join(directoryPath, file)).mtimeMs);
} catch (err) {
if (err?.code !== 'ENOENT') {
throw err;
}
mtimes.set(file, 0);
}
}
return files.sort((a, b) => mtimes.get(a) - mtimes.get(b));
}
default:
return files;
}
}
/**
+2
View File
@@ -12,6 +12,8 @@ module.exports = {
env: {
es6: true,
node: true,
browser: true,
jquery: true,
'jest/globals': true,
},
parserOptions: {
+73
View File
@@ -0,0 +1,73 @@
import path from 'node:path';
import process from 'node:process';
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals';
import archiver from 'archiver';
import { ByafParser } from '../src/byaf.js';
import { getArrayBufferSlice } from '../src/util.js';
// The parser reads the default avatar from a repo-root-relative path
const originalCwd = process.cwd();
beforeAll(() => process.chdir(path.resolve(originalCwd, '..')));
afterAll(() => process.chdir(originalCwd));
/**
* Builds a minimal valid BYAF archive in memory.
* @returns {Promise<Buffer>} Zipped BYAF bytes
*/
function buildByafArchive() {
return new Promise((resolve, reject) => {
const archive = archiver('zip', { zlib: { level: 9 } });
const chunks = [];
archive.on('data', chunk => chunks.push(chunk));
archive.on('error', reject);
archive.on('end', () => resolve(Buffer.concat(chunks)));
archive.append(JSON.stringify({
characters: ['characters/character.json'],
scenarios: ['scenarios/scenario.json'],
}), { name: 'manifest.json' });
archive.append(JSON.stringify({
name: 'Byaf Test Character',
persona: 'A test persona.',
images: [{ path: 'images/icon.png', label: '' }],
}), { name: 'characters/character.json' });
const pngPixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==', 'base64');
archive.append(pngPixel, { name: 'characters/images/icon.png' });
archive.append(JSON.stringify({
name: 'Test Scenario',
messages: [],
}), { name: 'scenarios/scenario.json' });
archive.finalize();
});
}
describe('BYAF import buffer handling', () => {
/** @type {Buffer} */
let zipBuffer;
/** @type {Buffer} */
let pooledView;
beforeAll(async () => {
zipBuffer = await buildByafArchive();
// Simulate Node's buffer pooling: the archive bytes sit at an offset inside
// a larger backing buffer surrounded by unrelated bytes.
const backing = Buffer.alloc(zipBuffer.length + 8192, 0xFF);
zipBuffer.copy(backing, 4096);
pooledView = backing.subarray(4096, 4096 + zipBuffer.length);
});
test('parses a real BYAF archive from an exact ArrayBuffer slice of a pooled view', async () => {
const exact = getArrayBufferSlice(pooledView);
expect(exact.byteLength).toBe(zipBuffer.length);
const parser = new ByafParser(exact);
const result = await parser.parse();
expect(result.card?.data?.name).toBe('Byaf Test Character');
});
test('the raw oversized backing buffer is not parseable, which is why callers must slice', async () => {
const parser = new ByafParser(pooledView.buffer);
await expect(parser.parse()).rejects.toThrow();
});
});
+78
View File
@@ -0,0 +1,78 @@
import { beforeAll, afterAll, describe, test, expect } from '@jest/globals';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
// chats.js reads these config values at module load. Environment variables take
// precedence over config.yaml, so setting them here lets the module import
// without a config file present. The short throttle interval keeps lodash
// timers from delaying the Jest process while still being long enough that a
// per-user (rather than per-chat) throttle would defer the second chat's backup.
process.env.SILLYTAVERN_BACKUPS_CHAT_ENABLED = 'true';
process.env.SILLYTAVERN_BACKUPS_CHAT_MAXTOTALBACKUPS = '-1';
process.env.SILLYTAVERN_BACKUPS_CHAT_THROTTLEINTERVAL = '200';
process.env.SILLYTAVERN_BACKUPS_CHAT_CHECKINTEGRITY = 'false';
process.env.SILLYTAVERN_BACKUPS_COMMON_NUMBEROFBACKUPS = '1';
/** @type {import('../src/endpoints/chats.js')} */
let chats;
let workDir;
beforeAll(async () => {
chats = await import('../src/endpoints/chats.js');
workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'st-backups-'));
});
afterAll(() => {
fs.rmSync(workDir, { recursive: true, force: true });
});
/**
* Builds a minimal chat array like the client sends it.
* @param {string} message Message text
* @returns {object[]} Chat array
*/
function makeChat(message) {
return [
{ user_name: 'User', character_name: 'Char', chat_metadata: {} },
{ name: 'Char', is_user: false, mes: message },
];
}
describe('getBackupKey', () => {
test('keeps plain ASCII names unchanged', () => {
expect(chats.getBackupKey('Seraphina')).toBe('seraphina');
expect(chats.getBackupKey('Some Test')).toBe('some_test');
});
test('produces distinct stable keys for names that sanitize identically', () => {
const keyA = chats.getBackupKey('雷电将军');
const keyB = chats.getBackupKey('测试角色');
expect(keyA).not.toBe(keyB);
expect(chats.getBackupKey('雷电将军')).toBe(keyA);
});
});
describe('chat backups', () => {
test('chats with equal-length CJK names get independent backups and quotas', async () => {
const backupsDir = path.join(workDir, 'backups');
const chatsDir = path.join(workDir, 'chats');
fs.mkdirSync(backupsDir, { recursive: true });
fs.mkdirSync(chatsDir, { recursive: true });
// numberOfBackups is 1: with a shared backup key, the second chat's
// backup would evict the first; with a shared throttle, it would not be
// written at the leading edge at all
await chats.trySaveChat(makeChat('first'), path.join(chatsDir, 'a.jsonl'), true, 'test-user', '雷电将军', backupsDir);
await chats.trySaveChat(makeChat('second'), path.join(chatsDir, 'b.jsonl'), true, 'test-user', '测试角色', backupsDir);
const backupFiles = fs.readdirSync(backupsDir);
expect(backupFiles).toHaveLength(2);
const keyA = chats.getBackupKey('雷电将军');
const keyB = chats.getBackupKey('测试角色');
expect(backupFiles.some(f => f.startsWith(`chat_${keyA}_`))).toBe(true);
expect(backupFiles.some(f => f.startsWith(`chat_${keyB}_`))).toBe(true);
});
});
+130
View File
@@ -0,0 +1,130 @@
import { beforeAll, beforeEach, afterEach, describe, test, expect, jest } from '@jest/globals';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
// chats.js reads these config values at module load. Environment variables take
// precedence over config.yaml, so the module imports without a config file.
process.env.SILLYTAVERN_BACKUPS_CHAT_ENABLED = 'false';
process.env.SILLYTAVERN_BACKUPS_CHAT_MAXTOTALBACKUPS = '-1';
process.env.SILLYTAVERN_BACKUPS_CHAT_THROTTLEINTERVAL = '0';
process.env.SILLYTAVERN_BACKUPS_CHAT_CHECKINTEGRITY = 'true';
/** @type {import('../src/endpoints/chats.js')} */
let chats;
beforeAll(async () => {
chats = await import('../src/endpoints/chats.js');
});
function makeChatJsonl() {
return [
JSON.stringify({ user_name: 'User', character_name: 'Char', chat_metadata: { note: 'meta' } }),
JSON.stringify({ name: 'Char', is_user: false, mes: 'First message', send_date: '2026-01-01T00:00:00.000Z' }),
JSON.stringify({ name: 'User', is_user: true, mes: 'Second message', send_date: '2026-01-02T00:00:00.000Z' }),
].join('\n');
}
describe('getChatInfo', () => {
let tmpDir;
let chatFile;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'st-chat-info-'));
chatFile = path.join(tmpDir, 'chat.jsonl');
});
afterEach(() => {
jest.restoreAllMocks();
fs.rmSync(tmpDir, { recursive: true, force: true });
});
test('reads info from a normal chat file', async () => {
fs.writeFileSync(chatFile, makeChatJsonl());
const info = await chats.getChatInfo(chatFile, {}, true);
expect(info.file_id).toBe('chat');
expect(info.file_name).toBe('chat.jsonl');
expect(info.chat_items).toBe(2);
expect(info.mes).toBe('Second message');
expect(info.last_mes).toBe('2026-01-02T00:00:00.000Z');
expect(info.match).toBe(true);
expect(info.chat_metadata).toEqual({ note: 'meta' });
});
test('returns defaults for an empty chat file', async () => {
fs.writeFileSync(chatFile, '');
const info = await chats.getChatInfo(chatFile);
expect(info.file_name).toBe('chat.jsonl');
expect(info.chat_items).toBe(0);
expect(info.mes).toBe('[The chat is empty]');
expect(info.match).toBe(false);
});
test('applies the matcher against message content', async () => {
fs.writeFileSync(chatFile, makeChatJsonl());
const matching = await chats.getChatInfo(chatFile, {}, false, lines => lines.some(l => l.includes('Second')));
expect(matching.match).toBe(true);
const nonMatching = await chats.getChatInfo(chatFile, {}, false, lines => lines.some(l => l.includes('nope')));
expect(nonMatching.match).toBe(false);
});
test('resolves without match when the file was already deleted', async () => {
const info = await chats.getChatInfo(path.join(tmpDir, 'gone.jsonl'));
expect(info).toEqual({ match: false });
});
test('resolves without match when the file is deleted between stat and read', async () => {
// Simulate the race: stat succeeds, but the file is gone when the stream opens
jest.spyOn(fs.promises, 'stat').mockResolvedValue(/** @type {any} */({ size: 100, mtimeMs: 1_000_000 }));
const info = await chats.getChatInfo(path.join(tmpDir, 'ghost.jsonl'));
expect(info).toEqual({ match: false });
});
test('resolves instead of hanging when the file is truncated between stat and read', async () => {
// Simulate the race: stat reports content, but the file is empty when read
fs.writeFileSync(chatFile, '');
jest.spyOn(fs.promises, 'stat').mockResolvedValue(/** @type {any} */({ size: 100, mtimeMs: 1_000_000 }));
const info = await chats.getChatInfo(chatFile);
expect(info.file_name).toBe('chat.jsonl');
expect(info.chat_items).toBe(0);
expect(info.mes).toBe('[The chat is empty]');
expect(info.match).toBe(false);
});
test('rejects with the original error for non-ENOENT stat failures', async () => {
const eacces = Object.assign(new Error('EACCES: permission denied'), { code: 'EACCES' });
jest.spyOn(fs.promises, 'stat').mockRejectedValue(eacces);
await expect(chats.getChatInfo(chatFile)).rejects.toThrow('EACCES');
});
test('resolves a degraded preview for a fully corrupted chat file', async () => {
fs.writeFileSync(chatFile, 'not json at all\nstill not json');
const info = await chats.getChatInfo(chatFile);
expect(info.file_id).toBe('chat');
expect(info.file_name).toBe('chat.jsonl');
expect(info.chat_items).toBe(0);
expect(info.mes).toBe('[The message is empty]');
expect(info.match).toBe(true);
});
test('resolves a degraded preview when only the last line is unparseable', async () => {
// e.g. a partially flushed write or an external edit truncated the final line
fs.writeFileSync(chatFile, makeChatJsonl() + '\n' + '{"name": "User", "is_user": true, "mes": "Trunc');
const info = await chats.getChatInfo(chatFile);
expect(info.file_id).toBe('chat');
expect(info.file_name).toBe('chat.jsonl');
expect(info.chat_items).toBe(2);
expect(info.mes).toBe('[The message is empty]');
expect(info.match).toBe(true);
});
test('matcher still applies to intact messages when the last line is unparseable', async () => {
fs.writeFileSync(chatFile, makeChatJsonl() + '\n' + '{"broken');
const matching = await chats.getChatInfo(chatFile, {}, false, lines => lines.some(l => l.includes('Second')));
expect(matching.match).toBe(true);
expect(matching.file_name).toBe('chat.jsonl');
const nonMatching = await chats.getChatInfo(chatFile, {}, false, lines => lines.some(l => l.includes('nope')));
expect(nonMatching.match).toBe(false);
expect(nonMatching.file_name).toBe('chat.jsonl');
});
});
+167
View File
@@ -0,0 +1,167 @@
import { beforeAll, beforeEach, afterEach, describe, test, expect } from '@jest/globals';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
// chats.js reads these config values at module load. Environment variables take
// precedence over config.yaml, so setting them here lets the module import
// without a config file present. The throttle interval is zeroed so lodash
// throttle timers don't keep the Jest process alive.
process.env.SILLYTAVERN_BACKUPS_CHAT_ENABLED = 'false';
process.env.SILLYTAVERN_BACKUPS_CHAT_MAXTOTALBACKUPS = '-1';
process.env.SILLYTAVERN_BACKUPS_CHAT_THROTTLEINTERVAL = '0';
process.env.SILLYTAVERN_BACKUPS_CHAT_CHECKINTEGRITY = 'true';
/** @type {import('../src/endpoints/chats.js')} */
let chats;
beforeAll(async () => {
chats = await import('../src/endpoints/chats.js');
});
const BOM = String.fromCharCode(0xFEFF);
const SLUG = '1e6905db-bab6-4901-913b-06d18cab5a8f';
const OTHER_SLUG = 'f1c1d103-464a-418a-a643-f9dab81589b9';
/**
* Builds a chat array like the client sends it.
* @param {string|null} slug Integrity slug for the header, or null for none
* @returns {object[]} Chat array
*/
function makeChat(slug) {
const metadata = slug ? { integrity: slug } : {};
return [
{ user_name: 'User', character_name: 'Char', chat_metadata: metadata },
{ name: 'Char', is_user: false, mes: 'Hello' },
];
}
/**
* Serializes a chat array the same way trySaveChat does.
* @param {object[]} chatData Chat array
* @returns {string} JSONL string
*/
function toJsonl(chatData) {
return chatData.map(m => JSON.stringify(m)).join('\n');
}
describe('trySaveChat integrity check', () => {
let tmpDir;
let chatFile;
let backupDir;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'st-chat-integrity-'));
chatFile = path.join(tmpDir, 'chat.jsonl');
backupDir = path.join(tmpDir, 'backups');
fs.mkdirSync(backupDir);
});
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
function save(chatData, { force = false } = {}) {
return chats.trySaveChat(chatData, chatFile, force, 'default-user', 'Char', backupDir);
}
test('writes a new file when none exists', async () => {
const chatData = makeChat(SLUG);
await save(chatData);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(chatData));
});
test('overwrites when the integrity slug matches', async () => {
fs.writeFileSync(chatFile, toJsonl(makeChat(SLUG)));
const newChat = makeChat(SLUG);
newChat[1].mes = 'Updated';
await save(newChat);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(newChat));
});
test('refuses to overwrite when the integrity slug mismatches and keeps the original bytes', async () => {
const originalBytes = toJsonl(makeChat(SLUG));
fs.writeFileSync(chatFile, originalBytes);
await expect(save(makeChat(OTHER_SLUG))).rejects.toThrow(/integrity check failed/i);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(originalBytes);
});
test('overwrites a legacy chat whose header has no integrity metadata', async () => {
const legacyHeader = JSON.stringify({ user_name: 'User', character_name: 'Char', create_date: '2023-01-01' });
fs.writeFileSync(chatFile, legacyHeader + '\n' + JSON.stringify({ name: 'Char', mes: 'Old' }));
const newChat = makeChat(SLUG);
await save(newChat);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(newChat));
});
test('overwrites an empty file', async () => {
fs.writeFileSync(chatFile, '');
const newChat = makeChat(SLUG);
await save(newChat);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(newChat));
});
test('refuses to overwrite a non-empty file with an unparseable first line and keeps the original bytes', async () => {
const originalBytes = 'this is not json{{{';
fs.writeFileSync(chatFile, originalBytes);
await expect(save(makeChat(SLUG))).rejects.toThrow(/integrity check failed/i);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(originalBytes);
});
test('refuses to overwrite a truncated header and keeps the original bytes', async () => {
const originalBytes = toJsonl(makeChat(SLUG)).slice(0, 25);
fs.writeFileSync(chatFile, originalBytes);
await expect(save(makeChat(SLUG))).rejects.toThrow(/integrity check failed/i);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(originalBytes);
});
test('refuses to overwrite when the first line parses to a non-object', async () => {
const originalBytes = '42\n' + JSON.stringify({ name: 'Char', mes: 'Orphan' });
fs.writeFileSync(chatFile, originalBytes);
await expect(save(makeChat(SLUG))).rejects.toThrow(/integrity check failed/i);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(originalBytes);
});
test('refuses to overwrite when the file starts with a blank line but has content below', async () => {
const originalBytes = '\n' + toJsonl(makeChat(SLUG));
fs.writeFileSync(chatFile, originalBytes);
await expect(save(makeChat(SLUG))).rejects.toThrow(/integrity check failed/i);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(originalBytes);
});
test('ignores a UTF-8 BOM in front of a valid matching header', async () => {
fs.writeFileSync(chatFile, BOM + toJsonl(makeChat(SLUG)));
const newChat = makeChat(SLUG);
newChat[1].mes = 'Updated';
await save(newChat);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(newChat));
});
test('still checks the integrity slug behind a UTF-8 BOM', async () => {
const originalBytes = BOM + toJsonl(makeChat(SLUG));
fs.writeFileSync(chatFile, originalBytes);
await expect(save(makeChat(OTHER_SLUG))).rejects.toThrow(/integrity check failed/i);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(originalBytes);
});
test('force overwrites a corrupted file when the user confirmed', async () => {
fs.writeFileSync(chatFile, 'this is not json{{{');
const newChat = makeChat(SLUG);
await save(newChat, { force: true });
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(newChat));
});
test('force overwrites a mismatching file when the user confirmed', async () => {
fs.writeFileSync(chatFile, toJsonl(makeChat(SLUG)));
const newChat = makeChat(OTHER_SLUG);
await save(newChat, { force: true });
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(newChat));
});
test('skips the check when the incoming chat has no integrity slug (existing behavior)', async () => {
fs.writeFileSync(chatFile, toJsonl(makeChat(SLUG)));
const newChat = makeChat(null);
await save(newChat);
expect(fs.readFileSync(chatFile, 'utf8')).toBe(toJsonl(newChat));
});
});
+42
View File
@@ -0,0 +1,42 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { afterEach, beforeEach, describe, expect, jest, test } from '@jest/globals';
import { addMissingConfigValues } from '../src/config-init.js';
const oldEnvKey = 'SILLYTAVERN_DISABLETHUMBNAILS';
const newEnvKey = 'SILLYTAVERN_THUMBNAILS_ENABLED';
describe('addMissingConfigValues', () => {
let tempDirectory;
let configPath;
beforeEach(() => {
tempDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'sillytavern-config-'));
configPath = path.join(tempDirectory, 'config.yaml');
fs.writeFileSync(configPath, '{}\n');
delete process.env[oldEnvKey];
delete process.env[newEnvKey];
jest.spyOn(console, 'log').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {});
});
afterEach(() => {
delete process.env[oldEnvKey];
delete process.env[newEnvKey];
fs.rmSync(tempDirectory, { recursive: true, force: true });
jest.restoreAllMocks();
});
test.each([
['false', 'true'],
['true', 'false'],
])('migrates the boolean environment value %s to %s', (oldValue, newValue) => {
process.env[oldEnvKey] = oldValue;
addMissingConfigValues(configPath);
expect(process.env[newEnvKey]).toBe(newValue);
expect(process.env[oldEnvKey]).toBeUndefined();
});
});
+63
View File
@@ -0,0 +1,63 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import process from 'node:process';
import { afterAll, beforeAll, describe, expect, test } from '@jest/globals';
// extensions.js reads these config values at module load or per request; the env var
// overrides avoid needing a config.yaml in the test environment
process.env.SILLYTAVERN_GIT_BACKEND = 'auto';
process.env.SILLYTAVERN_EXTENSIONS_ENABLED = 'true';
// The extensions endpoint resolves the built-in extensions folder relative to the repo root
const originalCwd = process.cwd();
beforeAll(() => process.chdir(path.resolve(originalCwd, '..')));
afterAll(() => process.chdir(originalCwd));
describe('extensions discover', () => {
/** @type {import('node:http').Server} */
let server;
let baseUrl;
let userExtensionsDir;
beforeAll(async () => {
userExtensionsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'st-extensions-'));
// A valid extension with a manifest
fs.mkdirSync(path.join(userExtensionsDir, 'Valid-Extension'));
fs.writeFileSync(path.join(userExtensionsDir, 'Valid-Extension', 'manifest.json'), JSON.stringify({ display_name: 'Valid' }));
// A leftover folder without a manifest (e.g. locked .git remnant after manual deletion)
fs.mkdirSync(path.join(userExtensionsDir, 'Deleted-Husk'));
fs.mkdirSync(path.join(userExtensionsDir, 'Deleted-Husk', '.git'));
const { default: express } = await import('express');
const { router } = await import('../src/endpoints/extensions.js');
const app = express();
app.use((req, _res, next) => {
req.user = {
profile: { handle: 'test-user' },
directories: { extensions: userExtensionsDir },
};
next();
});
app.use(router);
server = app.listen(0, '127.0.0.1');
await new Promise(resolve => server.once('listening', resolve));
baseUrl = `http://127.0.0.1:${server.address().port}`;
});
afterAll(async () => {
await new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
fs.rmSync(userExtensionsDir, { recursive: true, force: true });
});
test('lists folders with a manifest and skips folders without one', async () => {
const response = await fetch(`${baseUrl}/discover`);
expect(response.status).toBe(200);
const extensions = await response.json();
const names = extensions.map(x => x.name);
expect(names).toContain('third-party/Valid-Extension');
expect(names).not.toContain('third-party/Deleted-Husk');
});
});

Some files were not shown because too many files have changed in this diff Show More