refactor(ai): 助手按 AI-AGENT 开发指南对齐(Ask 模式)
对照指南逐条评估后落地 4 项真实差距(MCP/Agent Loop/白名单等重型章节不适用,明确排除): - 上下文预算(指南 07 TrimMessages):历史按 24k 字符预算从最旧裁剪,system 标注 「更早的对话已省略」;抽 trimHistory 独立函数+单测(超预算丢最旧/小历史不裁) - 配额超限诚实终态(指南 05.3/06 禁止伪装 completed):不再 400 报错,返回提示 文案;前端渲染为 warning 提示条样式,对话上下文保留 - 回复脱敏(指南 08):assistant 回复同样过 RedactTextOnly,堵住模型复述样本 带回敏感串的通道 - 退避重试(指南 05.2):429/5xx/网络错误指数退避 1s→2s 最多 2 次(计入总超时), 鉴权/参数错不重试
This commit is contained in:
1 parent
448f695c28
commit
550d8f4967
3 files changed
+106
-13
No files matched your search
@@ -85,17 +85,22 @@ export const AiAssistant = memo(function AiAssistant() {
|
||||
{messages.length === 0 && (
|
||||
<p className="py-8 text-center text-xs text-muted-foreground">{t('assistant.emptyHint')}</p>
|
||||
)}
|
||||
{messages.map((m, i) => (
|
||||
<div key={i} className={m.role === 'user' ? 'flex justify-end' : 'flex justify-start'}>
|
||||
<div className={
|
||||
m.role === 'user'
|
||||
? 'max-w-[85%] rounded-lg bg-primary px-3 py-2 text-primary-foreground'
|
||||
: 'max-w-[85%] whitespace-pre-wrap rounded-lg bg-muted px-3 py-2'
|
||||
}>
|
||||
{m.content}
|
||||
{messages.map((m, i) => {
|
||||
const isQuota = m.role === 'assistant' && m.content.includes('今日 AI 配额已用完')
|
||||
return (
|
||||
<div key={i} className={m.role === 'user' ? 'flex justify-end' : 'flex justify-start'}>
|
||||
<div className={
|
||||
isQuota
|
||||
? 'max-w-[85%] whitespace-pre-wrap rounded-lg border border-warning/40 bg-warning/10 px-3 py-2 text-warning'
|
||||
: m.role === 'user'
|
||||
? 'max-w-[85%] rounded-lg bg-primary px-3 py-2 text-primary-foreground'
|
||||
: 'max-w-[85%] whitespace-pre-wrap rounded-lg bg-muted px-3 py-2'
|
||||
}>
|
||||
{m.content}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
{sending && (
|
||||
<div className="flex justify-start">
|
||||
<div className="flex items-center gap-2 rounded-lg bg-muted px-3 py-2 text-xs text-muted-foreground">
|
||||
|
||||
Reference in new issue
Block a user