This commit is contained in:
Classic298 2026-11-07 00:50:47 +09:00 • committed by GitHub
commit 94261c384f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 0 deletions

View file

@ -2077,6 +2077,10 @@ SKILL_PREVIEW_MAX_CHARS = int(os.environ['SKILL_PREVIEW_MAX_CHARS']) if os.geten
if SKILL_PREVIEW_MAX_CHARS is not None and SKILL_PREVIEW_MAX_CHARS <= 0:
raise ValueError('SKILL_PREVIEW_MAX_CHARS must be a positive integer or unset')
VIEW_CHAT_MAX_CHARS = int(os.environ['VIEW_CHAT_MAX_CHARS']) if os.getenv('VIEW_CHAT_MAX_CHARS') else None
if VIEW_CHAT_MAX_CHARS is not None and VIEW_CHAT_MAX_CHARS <= 0:
raise ValueError('VIEW_CHAT_MAX_CHARS must be a positive integer or unset')
ENABLE_CHANNELS = os.getenv('ENABLE_CHANNELS', 'False').lower() == 'true'
ENABLE_ENCRYPTED_CHANNELS = os.getenv('ENABLE_ENCRYPTED_CHANNELS', 'False').lower() == 'true'
@ -2953,6 +2957,7 @@ DEFAULT_CONFIG = {
'skills.lazy_loading.enable': ENABLE_SKILL_LAZY_LOADING,
'skills.content_max_chars': SKILL_CONTENT_MAX_CHARS,
'skills.preview_max_chars': SKILL_PREVIEW_MAX_CHARS,
'chats.view_max_chars': VIEW_CHAT_MAX_CHARS,
'direct.enable': ENABLE_DIRECT_CONNECTIONS,
'direct.integrations.enable': ENABLE_DIRECT_INTEGRATIONS,
'ollama.enable': ENABLE_OLLAMA_API,

View file

@ -143,6 +143,7 @@ ADMIN_CONFIG_KEYS = {
'ENABLE_SKILL_LAZY_LOADING': 'skills.lazy_loading.enable',
'SKILL_CONTENT_MAX_CHARS': 'skills.content_max_chars',
'SKILL_PREVIEW_MAX_CHARS': 'skills.preview_max_chars',
'VIEW_CHAT_MAX_CHARS': 'chats.view_max_chars',
'ENABLE_NOTES': 'notes.enable',
'ENABLE_USER_WEBHOOKS': 'ui.enable_user_webhooks',
'ENABLE_USER_STATUS': 'users.enable_status',
@ -1188,6 +1189,7 @@ class AdminConfig(MfaConfigForm):
ENABLE_SKILL_LAZY_LOADING: bool = False
SKILL_CONTENT_MAX_CHARS: int | None = Field(default=None, gt=0, strict=True)
SKILL_PREVIEW_MAX_CHARS: int | None = Field(default=None, gt=0, strict=True)
VIEW_CHAT_MAX_CHARS: int | None = Field(default=None, gt=0, strict=True)
ENABLE_NOTES: bool
ENABLE_USER_WEBHOOKS: bool
ENABLE_USER_STATUS: bool
@ -1246,6 +1248,8 @@ async def update_admin_config(request: Request, form_data: AdminConfig, user=Dep
updates.pop('skills.content_max_chars', None)
if 'SKILL_PREVIEW_MAX_CHARS' not in form_data.model_fields_set:
updates.pop('skills.preview_max_chars', None)
if 'VIEW_CHAT_MAX_CHARS' not in form_data.model_fields_set:
updates.pop('chats.view_max_chars', None)
updates['ui.default_interface_settings'] = form_data.DEFAULT_INTERFACE_SETTINGS or {}
updates['folders.max_file_count'] = int(form_data.FOLDER_MAX_FILE_COUNT) if form_data.FOLDER_MAX_FILE_COUNT else ''
updates['automations.max_count'] = int(form_data.AUTOMATION_MAX_COUNT) if form_data.AUTOMATION_MAX_COUNT else ''

View file

@ -1750,6 +1750,24 @@ async def view_chat(
)
current_id = msg.get('parentId') if msg else None
truncation = {}
max_chars = await Config.get('chats.view_max_chars')
if max_chars and sum(len(str(message['content'] or '')) for message in messages) > max_chars:
remaining_chars = max_chars
kept_messages = []
for message in messages:
if remaining_chars <= 0:
break
content = str(message['content'] or '')[:remaining_chars]
kept_messages.append({**message, 'content': content})
remaining_chars -= len(content)
truncation = {
'truncated': True,
'total_messages': len(messages),
'returned_messages': len(kept_messages),
}
messages = kept_messages
# Reverse to get chronological order
messages.reverse()
@ -1760,6 +1778,7 @@ async def view_chat(
'messages': messages,
'updated_at': chat.updated_at,
'created_at': chat.created_at,
**truncation,
},
ensure_ascii=False,
)

View file

@ -86,6 +86,7 @@
...adminConfig,
SKILL_CONTENT_MAX_CHARS: adminConfig.SKILL_CONTENT_MAX_CHARS ?? null,
SKILL_PREVIEW_MAX_CHARS: adminConfig.SKILL_PREVIEW_MAX_CHARS ?? null,
VIEW_CHAT_MAX_CHARS: adminConfig.VIEW_CHAT_MAX_CHARS ?? null,
DEFAULT_INTERFACE_SETTINGS: defaultInterfaceSettings,
I18N: cleaned
});
@ -378,6 +379,21 @@
bind:value={adminConfig.SKILL_PREVIEW_MAX_CHARS}
/>
</AdminSettingField>
<AdminSettingField
forId="view-chat-max-chars"
label={$i18n.t('settings.admin.general.viewChatMaxChars.label')}
description={$i18n.t('settings.admin.general.viewChatMaxChars.description')}
>
<input
id="view-chat-max-chars"
class={inputClass}
type="number"
min="1"
step="1"
placeholder={$i18n.t('No limit')}
bind:value={adminConfig.VIEW_CHAT_MAX_CHARS}
/>
</AdminSettingField>
<AdminSettingRow
label={$i18n.t('settings.admin.general.notes.label')}
description={$i18n.t('settings.admin.general.notes.description')}

View file

@ -3181,6 +3181,8 @@
"settings.admin.general.userWebhooks.description": "Allow users to configure webhooks from their account.",
"settings.admin.general.userWebhooks.label": "User Webhooks",
"settings.admin.general.version.label": "Version",
"settings.admin.general.viewChatMaxChars.description": "Maximum characters returned when a model reads a previous chat. The newest messages are kept. Leave empty for no limit.",
"settings.admin.general.viewChatMaxChars.label": "Chat Read Limit",
"settings.admin.general.webuiUrl.description": "Enter the public URL of your WebUI. This URL will be used to generate links in the notifications.",
"settings.admin.general.webuiUrl.label": "WebUI URL",
"settings.admin.images.apiAuthString.description": "Provide the --api-auth username and password when required.",