fix:修复qq号为int的问题,修复部分多行配置问题,修复多语言prompt问题
This commit is contained in:
@@ -32,8 +32,7 @@
|
||||
|
||||
# 运行/调试/构建/测试/依赖
|
||||
优先使用uv
|
||||
依赖项以 pyproject.toml 为准
|
||||
|
||||
依赖项以 pyproject.toml 为准,要同步更新requirements.txt
|
||||
|
||||
# 语言规范
|
||||
项目的首选语言为简体中文,无论是注释语言,日志展示语言,还是 WebUI 展示语言都首要以简体中文为首要实现目标
|
||||
@@ -52,3 +51,6 @@
|
||||
|
||||
# maibot插件开发文档
|
||||
https://github.com/Mai-with-u/maibot-plugin-sdk/blob/main/docs/guide.md
|
||||
|
||||
# 如何提交maibot插件
|
||||
https://github.com/Mai-with-u/plugin-repo/blob/main/CONTRIBUTING.md
|
||||
@@ -215,12 +215,50 @@ export const DynamicConfigForm: React.FC<DynamicConfigFormProps> = ({
|
||||
? [...normalFields, ...advancedFields]
|
||||
: normalFields
|
||||
|
||||
const groupFieldsByRow = (fields: FieldSchema[]) => {
|
||||
const rows: FieldSchema[][] = []
|
||||
let currentRow: FieldSchema[] = []
|
||||
let currentRowKey: string | undefined
|
||||
|
||||
for (const field of fields) {
|
||||
const rowKey = field['x-row']
|
||||
if (rowKey && rowKey === currentRowKey) {
|
||||
currentRow.push(field)
|
||||
continue
|
||||
}
|
||||
|
||||
if (currentRow.length > 0) {
|
||||
rows.push(currentRow)
|
||||
}
|
||||
|
||||
currentRow = [field]
|
||||
currentRowKey = rowKey
|
||||
}
|
||||
|
||||
if (currentRow.length > 0) {
|
||||
rows.push(currentRow)
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
const renderFieldList = (fields: FieldSchema[]) => (
|
||||
<>
|
||||
{fields.map((field, index) => (
|
||||
<React.Fragment key={field.name}>
|
||||
{groupFieldsByRow(fields).map((row, index) => (
|
||||
<React.Fragment key={row.map((field) => field.name).join('|')}>
|
||||
{index > 0 && <Separator className="my-2 bg-border/50" />}
|
||||
<div className="py-1">{renderField(field)}</div>
|
||||
{row.length > 1 ? (
|
||||
<div
|
||||
className="grid gap-4 py-1 md:grid-cols-[repeat(var(--field-row-count),minmax(0,1fr))]"
|
||||
style={{ '--field-row-count': row.length } as React.CSSProperties}
|
||||
>
|
||||
{row.map((field) => (
|
||||
<div key={field.name}>{renderField(field)}</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="py-1">{renderField(row[0])}</div>
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</>
|
||||
|
||||
@@ -8,6 +8,12 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Slider } from "@/components/ui/slider"
|
||||
import { Switch } from "@/components/ui/switch"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { FieldSchema } from "@/types/config-schema"
|
||||
|
||||
@@ -115,11 +121,9 @@ export const DynamicField: React.FC<DynamicFieldProps> = ({
|
||||
return <IconComponent className="h-4 w-4" />
|
||||
}
|
||||
|
||||
const isRuleTypeSelect =
|
||||
schema.name === 'rule_type' &&
|
||||
(schema.type === 'select' || schema['x-widget'] === 'select')
|
||||
const inlineDescription = isRuleTypeSelect ? '' : schema.description
|
||||
const selectHoverDescription = isRuleTypeSelect ? schema.description : undefined
|
||||
const optionDescriptions = schema['x-option-descriptions'] ?? {}
|
||||
const hasOptionDescriptions = Object.keys(optionDescriptions).length > 0
|
||||
const inlineDescription = hasOptionDescriptions ? '' : schema.description
|
||||
|
||||
const renderFieldHeader = () => (
|
||||
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
|
||||
@@ -352,15 +356,43 @@ export const DynamicField: React.FC<DynamicFieldProps> = ({
|
||||
|
||||
return (
|
||||
<Select value={strValue} onValueChange={(val) => onChange(val)}>
|
||||
<SelectTrigger title={selectHoverDescription}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={`Select ${schema.label}`} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options.map((option) => (
|
||||
<SelectItem key={option} value={option}>
|
||||
{option}
|
||||
</SelectItem>
|
||||
))}
|
||||
{hasOptionDescriptions ? (
|
||||
<TooltipProvider delayDuration={150}>
|
||||
{options.map((option) => {
|
||||
const description = optionDescriptions[option]
|
||||
return description ? (
|
||||
<Tooltip key={option}>
|
||||
<TooltipTrigger asChild>
|
||||
<SelectItem value={option} title={description}>
|
||||
{option}
|
||||
</SelectItem>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
align="center"
|
||||
className="max-w-72 bg-background text-foreground border shadow-lg"
|
||||
>
|
||||
{description}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<SelectItem key={option} value={option}>
|
||||
{option}
|
||||
</SelectItem>
|
||||
)
|
||||
})}
|
||||
</TooltipProvider>
|
||||
) : (
|
||||
options.map((option) => (
|
||||
<SelectItem key={option} value={option}>
|
||||
{option}
|
||||
</SelectItem>
|
||||
))
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)
|
||||
|
||||
@@ -490,10 +490,20 @@ function BotConfigPageContent() {
|
||||
const saveSourceCode = async () => {
|
||||
try {
|
||||
setSaving(true)
|
||||
// 编辑器展示时会把 basic string 内的 \n 展开成真实换行;保存前先转回 TOML 转义序列。
|
||||
const escapedSourceCode = sourceCode.replace(/"([^"]*)"/g, (_match, content) => {
|
||||
const encoded = content
|
||||
.replace(/\\/g, '\\\\') // 反斜杠必须先转义,避免 \s 等序列被 TOML 当作非法转义
|
||||
.replace(/"/g, '\\"')
|
||||
.replace(/\n/g, '\\n')
|
||||
.replace(/\t/g, '\\t')
|
||||
.replace(/\r/g, '\\r')
|
||||
return `"${encoded}"`
|
||||
})
|
||||
|
||||
// 前端验证 TOML 格式
|
||||
try {
|
||||
parseToml(sourceCode)
|
||||
parseToml(escapedSourceCode)
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : 'TOML 格式错误'
|
||||
const translatedMsg = translateTomlError(errorMsg)
|
||||
@@ -508,18 +518,7 @@ function BotConfigPageContent() {
|
||||
return
|
||||
}
|
||||
|
||||
// 将双引号字符串中的实际字符转换回 TOML 转义序列
|
||||
// 使用正则表达式只处理双引号字符串内的内容,不影响单引号字符串
|
||||
const escaped = sourceCode.replace(/"([^"]*)"/g, (_match, content) => {
|
||||
const encoded = content
|
||||
.replace(/\\/g, '\\\\') // 反斜杠(必须放在最前)
|
||||
.replace(/"/g, '\\"') // 双引号
|
||||
.replace(/\n/g, '\\n') // 换行符
|
||||
.replace(/\t/g, '\\t') // 制表符
|
||||
.replace(/\r/g, '\\r') // 回车符
|
||||
return `"${encoded}"`
|
||||
})
|
||||
const result = await updateBotConfigRaw(escaped)
|
||||
const result = await updateBotConfigRaw(escapedSourceCode)
|
||||
if (!result.success) {
|
||||
setHasTomlError(true)
|
||||
const errorMsg = result.error
|
||||
|
||||
@@ -889,7 +889,7 @@ function ModelConfigPageContent() {
|
||||
开始引导
|
||||
</Button>
|
||||
<Button type="button" variant="ghost" size="sm" onClick={dismissTourEntry}>
|
||||
鍏抽棴
|
||||
关闭
|
||||
</Button>
|
||||
</div>
|
||||
</AlertDescription>
|
||||
|
||||
@@ -63,7 +63,7 @@ export function EmojiManagementPage() {
|
||||
const [page, setPage] = useState(1)
|
||||
const [total, setTotal] = useState(0)
|
||||
const [pageSize, setPageSize] = useState(20)
|
||||
const [registeredFilter, setRegisteredFilter] = useState<string>('all')
|
||||
const [registeredFilter, setRegisteredFilter] = useState<string>('registered')
|
||||
const [bannedFilter, setBannedFilter] = useState<string>('all')
|
||||
const [formatFilter, setFormatFilter] = useState<string>('all')
|
||||
const [sortBy, setSortBy] = useState<string>('usage_count')
|
||||
|
||||
@@ -44,7 +44,7 @@ function normalizePlatform(raw: string): string {
|
||||
function deriveSelectedPlatform(config: BotBasicConfig): { selected: string; customName: string } {
|
||||
const platform = config.platform
|
||||
// Legacy: no platform set but has QQ account
|
||||
if (!platform && config.qq_account > 0) {
|
||||
if (!platform && config.qq_account.trim()) {
|
||||
return { selected: 'qq', customName: '' }
|
||||
}
|
||||
if (!platform) {
|
||||
@@ -96,9 +96,7 @@ export function BotBasicForm({ config, onChange }: BotBasicFormProps) {
|
||||
const customPlatformName = customPlatformNameOverride ?? derived.customName
|
||||
const primaryAccount =
|
||||
selectedPlatform === 'qq'
|
||||
? config.qq_account > 0
|
||||
? String(config.qq_account)
|
||||
: ''
|
||||
? config.qq_account.trim()
|
||||
: config.platform
|
||||
? getPrimaryAccount(config.platforms, config.platform)
|
||||
: ''
|
||||
@@ -141,7 +139,7 @@ export function BotBasicForm({ config, onChange }: BotBasicFormProps) {
|
||||
if (normalized === 'qq') {
|
||||
onChange({
|
||||
...config,
|
||||
qq_account: Number(accountId) || 0,
|
||||
qq_account: accountId.trim(),
|
||||
platform: 'qq',
|
||||
})
|
||||
} else {
|
||||
|
||||
@@ -61,10 +61,11 @@ export async function loadBotBasicConfig(): Promise<BotBasicConfig> {
|
||||
)
|
||||
const data = throwIfError(result)
|
||||
const botConfig = (data.config.bot || {}) as Partial<BotBasicConfig>
|
||||
const qqAccount = String(botConfig.qq_account ?? '').trim()
|
||||
|
||||
return {
|
||||
platform: botConfig.platform || (botConfig.qq_account ? 'qq' : ''),
|
||||
qq_account: botConfig.qq_account || 0,
|
||||
platform: botConfig.platform || (qqAccount ? 'qq' : ''),
|
||||
qq_account: qqAccount,
|
||||
platforms: botConfig.platforms || [],
|
||||
nickname: botConfig.nickname || '',
|
||||
alias_names: botConfig.alias_names || [],
|
||||
|
||||
@@ -106,7 +106,7 @@ function SetupPageContent() {
|
||||
// 步骤1:Bot基础信息
|
||||
const [botBasic, setBotBasic] = useState<BotBasicConfig>({
|
||||
platform: '',
|
||||
qq_account: 0,
|
||||
qq_account: '',
|
||||
platforms: [],
|
||||
nickname: '',
|
||||
alias_names: [],
|
||||
@@ -239,7 +239,7 @@ function SetupPageContent() {
|
||||
if (!config.platform) return t('setupPage.validation.selectPlatform')
|
||||
if (!config.nickname.trim()) return t('setupPage.validation.enterNickname')
|
||||
if (config.platform === 'qq') {
|
||||
if (!config.qq_account || config.qq_account <= 0) {
|
||||
if (!config.qq_account.trim()) {
|
||||
return t('setupPage.validation.enterQqAccount')
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface SetupStep {
|
||||
// 步骤1:Bot基础信息
|
||||
export interface BotBasicConfig {
|
||||
platform: string // Primary platform name (normalized, lowercase)
|
||||
qq_account: number // QQ account (preserved always for webui compat)
|
||||
qq_account: string // QQ account (preserved always for webui compat)
|
||||
platforms: string[] // Other platform accounts "platform:account"
|
||||
nickname: string
|
||||
alias_names: string[]
|
||||
|
||||
@@ -40,6 +40,8 @@ export interface FieldSchema {
|
||||
'x-icon'?: string
|
||||
'x-layout'?: 'inline-right'
|
||||
'x-input-width'?: string
|
||||
'x-option-descriptions'?: Record<string, string>
|
||||
'x-row'?: string
|
||||
'x-textarea-min-height'?: number
|
||||
'x-textarea-rows'?: number
|
||||
advanced?: boolean
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
You are chatting in a QQ group. Below is the content currently being discussed in the group, including chat records and images in the chat.
|
||||
Messages marked with {bot_name} (you) are your own messages, so please distinguish them carefully:
|
||||
|
||||
{time_block}
|
||||
Messages marked as your own messages should be distinguished carefully:
|
||||
|
||||
{identity}
|
||||
You are chatting in the group now. Please read the previous chat records, grasp the current topic, and then give a natural, colloquial reply.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
あなたは QQ グループで会話しています。以下はグループ内で現在話されている内容で、チャット記録とチャット中の画像が含まれます。
|
||||
{bot_name}(あなた) と記された発言はあなた自身の発言です。区別に注意してください:
|
||||
|
||||
{time_block}
|
||||
あなた自身の発言として記された発言は、区別に注意してください:
|
||||
|
||||
{identity}
|
||||
今あなたはグループ内で会話しています。これまでのチャット記録を読み、現在の話題を把握したうえで、日常的で口語的な返信をしてください。
|
||||
|
||||
@@ -56,7 +56,7 @@ BOT_CONFIG_PATH: Path = (CONFIG_DIR / "bot_config.toml").resolve().absolute()
|
||||
MODEL_CONFIG_PATH: Path = (CONFIG_DIR / "model_config.toml").resolve().absolute()
|
||||
LEGACY_ENV_PATH: Path = (PROJECT_ROOT / ".env").resolve().absolute()
|
||||
A_MEMORIX_LEGACY_CONFIG_PATH: Path = (CONFIG_DIR / "a_memorix.toml").resolve().absolute()
|
||||
MMC_VERSION: str = "1.0.0-pre.10"
|
||||
MMC_VERSION: str = "1.0.0-pre.11"
|
||||
CONFIG_VERSION: str = "8.10.6"
|
||||
MODEL_CONFIG_VERSION: str = "1.15.3"
|
||||
|
||||
|
||||
@@ -343,10 +343,10 @@ def try_migrate_legacy_bot_config_dict(data: dict[str, Any]) -> MigrationResult:
|
||||
reasons: list[str] = []
|
||||
|
||||
bot = _as_dict(data.get("bot"))
|
||||
if bot is not None and isinstance(bot.get("qq_account"), str) and not bot["qq_account"].strip():
|
||||
bot["qq_account"] = 0
|
||||
if bot is not None and isinstance(bot.get("qq_account"), int):
|
||||
bot["qq_account"] = str(bot["qq_account"]) if bot["qq_account"] > 0 else ""
|
||||
migrated_any = True
|
||||
reasons.append("bot.qq_account_empty")
|
||||
reasons.append("bot.qq_account_int_to_string")
|
||||
|
||||
chat = _as_dict(data.get("chat"))
|
||||
if chat is not None and _migrate_chat_talk_value_rules(chat):
|
||||
|
||||
@@ -4,6 +4,17 @@ import re
|
||||
|
||||
from .config_base import ConfigBase, Field
|
||||
|
||||
RULE_TYPE_OPTION_DESCRIPTIONS = {
|
||||
"group": "群聊聊天流,item_id 填群号或群聊 ID",
|
||||
"private": "私聊聊天流,item_id 填用户 ID",
|
||||
}
|
||||
|
||||
VISUAL_MODE_OPTION_DESCRIPTIONS = {
|
||||
"auto": "根据模型信息自动选择文本或多模态模式",
|
||||
"text": "纯文本模式,不向模型发送视觉输入",
|
||||
"multimodal": "多模态模式,会向模型发送视觉输入",
|
||||
}
|
||||
|
||||
"""
|
||||
须知:
|
||||
1. 本文件中记录了所有的配置项
|
||||
@@ -33,8 +44,8 @@ class BotConfig(ConfigBase):
|
||||
)
|
||||
"""平台"""
|
||||
|
||||
qq_account: int = Field(
|
||||
default=0,
|
||||
qq_account: str = Field(
|
||||
default="",
|
||||
json_schema_extra={
|
||||
"x-widget": "input",
|
||||
"x-icon": "user",
|
||||
@@ -141,6 +152,8 @@ class VisualConfig(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "select",
|
||||
"x-icon": "git-branch",
|
||||
"x-option-descriptions": VISUAL_MODE_OPTION_DESCRIPTIONS,
|
||||
"x-row": "visual-modes",
|
||||
},
|
||||
)
|
||||
"""规划器模式,auto根据模型信息自动选择,text为纯文本模式,multimodal为多模态模式"""
|
||||
@@ -150,6 +163,8 @@ class VisualConfig(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "select",
|
||||
"x-icon": "git-branch",
|
||||
"x-option-descriptions": VISUAL_MODE_OPTION_DESCRIPTIONS,
|
||||
"x-row": "visual-modes",
|
||||
},
|
||||
)
|
||||
"""回复器模式,auto根据模型信息自动选择,text为纯文本模式,multimodal为多模态模式"""
|
||||
@@ -162,7 +177,13 @@ class TalkRulesItem(ConfigBase):
|
||||
item_id: str = ""
|
||||
"""用户ID,与平台一起留空表示全局"""
|
||||
|
||||
rule_type: Literal["group", "private"] = "group"
|
||||
rule_type: Literal["group", "private"] = Field(
|
||||
default="group",
|
||||
json_schema_extra={
|
||||
"x-widget": "select",
|
||||
"x-option-descriptions": RULE_TYPE_OPTION_DESCRIPTIONS,
|
||||
},
|
||||
)
|
||||
"""聊天流类型,group(群聊)或private(私聊)"""
|
||||
|
||||
time: str = ""
|
||||
@@ -185,6 +206,7 @@ class ChatConfig(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "slider",
|
||||
"x-icon": "message-circle",
|
||||
"x-row": "talk-values",
|
||||
"step": 0.1,
|
||||
},
|
||||
)
|
||||
@@ -197,6 +219,7 @@ class ChatConfig(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "slider",
|
||||
"x-icon": "message-circle",
|
||||
"x-row": "talk-values",
|
||||
"step": 0.1,
|
||||
},
|
||||
)
|
||||
@@ -207,11 +230,19 @@ class ChatConfig(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "switch",
|
||||
"x-icon": "at-sign",
|
||||
"x-row": "reply-switches",
|
||||
},
|
||||
)
|
||||
"""是否启用提及必回复"""
|
||||
|
||||
inevitable_at_reply: bool = Field(default=True)
|
||||
inevitable_at_reply: bool = Field(
|
||||
default=True,
|
||||
json_schema_extra={
|
||||
"x-widget": "switch",
|
||||
"x-icon": "at-sign",
|
||||
"x-row": "reply-switches",
|
||||
},
|
||||
)
|
||||
"""是否启用at必回复"""
|
||||
|
||||
enable_at: bool = Field(
|
||||
@@ -241,6 +272,7 @@ class ChatConfig(ConfigBase):
|
||||
"x-icon": "layers",
|
||||
"x-layout": "inline-right",
|
||||
"x-input-width": "12rem",
|
||||
"x-row": "context-sizes",
|
||||
},
|
||||
)
|
||||
"""上下文长度"""
|
||||
@@ -252,6 +284,7 @@ class ChatConfig(ConfigBase):
|
||||
"x-icon": "layers",
|
||||
"x-layout": "inline-right",
|
||||
"x-input-width": "12rem",
|
||||
"x-row": "context-sizes",
|
||||
},
|
||||
)
|
||||
"""私聊上下文长度"""
|
||||
@@ -395,6 +428,7 @@ class TargetItem(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "select",
|
||||
"x-icon": "users",
|
||||
"x-option-descriptions": RULE_TYPE_OPTION_DESCRIPTIONS,
|
||||
},
|
||||
)
|
||||
"""聊天流类型,group(群聊)或private(私聊)"""
|
||||
@@ -1049,6 +1083,7 @@ class LearningItem(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "select",
|
||||
"x-icon": "users",
|
||||
"x-option-descriptions": RULE_TYPE_OPTION_DESCRIPTIONS,
|
||||
},
|
||||
)
|
||||
"""聊天流类型,group(群聊)或private(私聊)"""
|
||||
@@ -1751,6 +1786,7 @@ class ExtraPromptItem(ConfigBase):
|
||||
json_schema_extra={
|
||||
"x-widget": "select",
|
||||
"x-icon": "users",
|
||||
"x-option-descriptions": RULE_TYPE_OPTION_DESCRIPTIONS,
|
||||
},
|
||||
)
|
||||
"""聊天流类型,group(群聊)或private(私聊)"""
|
||||
|
||||
@@ -132,6 +132,11 @@ def _toml_to_plain_dict(obj: Any) -> Any:
|
||||
|
||||
def _coerce_numeric_value(value: Any, target_type: Any) -> Any:
|
||||
"""根据配置字段类型,把旧 WebUI 可能写入的数字字符串还原为数字。"""
|
||||
if target_type is str:
|
||||
if isinstance(value, (int, float)):
|
||||
return str(value)
|
||||
return value
|
||||
|
||||
if target_type is int:
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user