Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71a6403e5b | ||
|
|
5def2697de | ||
|
|
612ce37518 |
No files matched your search
@@ -1430,7 +1430,7 @@ async def _generate_media_task(ai_msg_id: str, ai_model_id: str, prompt: str, us
|
||||
logger.info(f"[_generate_media_task] 启动 media 生成 msg={ai_msg_id} model={ai_model_id} prompt={prompt[:60]!r}")
|
||||
caps = [c.lower() for c in (ai_model.capabilities or [])]
|
||||
is_video = "video" in caps
|
||||
timeout_seconds = 300 if is_video else 90
|
||||
timeout_seconds = 300 if is_video else 180
|
||||
try:
|
||||
result = await asyncio.wait_for(
|
||||
_generate_media(db, ai_model, prompt, user_id),
|
||||
|
||||
@@ -1657,6 +1657,16 @@ async def _send_message_core(
|
||||
|
||||
|
||||
|
||||
# 媒体分支直接返回,不会进入 LLM 工具调用;提前初始化避免未绑定
|
||||
|
||||
called_skill_names = []
|
||||
|
||||
|
||||
|
||||
called_mcp_names = []
|
||||
|
||||
|
||||
|
||||
if effective_skill_ids:
|
||||
|
||||
|
||||
|
||||
@@ -128,7 +128,15 @@ def setup_file_logging():
|
||||
root_logger.setLevel(logging.INFO)
|
||||
root_logger.addHandler(app_handler)
|
||||
root_logger.addHandler(error_handler)
|
||||
root_logger.addFilter(TraceIdFilter())
|
||||
|
||||
# TraceIdFilter 必须挂在 handler 上,而非 root logger。
|
||||
# logger 级 filter 只对「直接经该 logger 发射」的记录生效;子 logger 的记录向上冒泡
|
||||
# 到 root 的 handler 时不会经过 root 的 logger 级 filter,导致 %(trace_id)s 缺失并抛
|
||||
# KeyError('trace_id')。handler 级 filter 对经它格式化的每条记录都生效。
|
||||
_tid_filter = TraceIdFilter()
|
||||
app_handler.addFilter(_tid_filter)
|
||||
error_handler.addFilter(_tid_filter)
|
||||
access_handler.addFilter(_tid_filter)
|
||||
|
||||
# 配置访问日志专用logger
|
||||
access_logger = logging.getLogger("aiflow.access")
|
||||
|
||||
@@ -945,7 +945,7 @@ class SkillTrajectoryLink(Base):
|
||||
skill_name = Column(String(200), nullable=False, index=True, comment="关联的技能名称")
|
||||
user_id = Column(String(36), ForeignKey("users.id"), nullable=False, index=True)
|
||||
trajectory_id = Column(String(36), nullable=True, comment="关联的轨迹ID")
|
||||
atom_id = Column(String(36), nullable=True, comment="原子任务ID")
|
||||
atom_id = Column(String(128), nullable=True, comment="原子任务ID(形如 trajectory_id_atom_N,需容纳 UUID+后缀)")
|
||||
weightscore = Column(Integer, default=0, comment="关联权重分")
|
||||
created_at = Column(DateTime, default=datetime.now)
|
||||
|
||||
|
||||
@@ -96,10 +96,24 @@ class PipelineScheduler:
|
||||
self._process_trajectory(db, traj)
|
||||
except Exception as e:
|
||||
logger.error(f"处理轨迹 {traj.id} 失败: {e}")
|
||||
# 先回滚失效事务(_process_trajectory 内 commit 失败会让 session
|
||||
# 进入 rolled-back 状态,不回滚直接再 commit 会抛 PendingRollbackError
|
||||
# 并级联到外层日志),再写错误状态。
|
||||
try:
|
||||
db.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
traj.error_msg = str(e)[:500]
|
||||
traj.retry_count = (traj.retry_count or 0) + 1
|
||||
traj.status = "error"
|
||||
db.commit()
|
||||
except Exception as ce:
|
||||
logger.error(f"更新轨迹 {traj.id} 错误状态失败: {ce}")
|
||||
try:
|
||||
db.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
db.close()
|
||||
except Exception as e:
|
||||
|
||||
@@ -1121,7 +1121,7 @@ const Achievement: React.FC = () => {
|
||||
|
||||
<td style={{ color: 'rgba(0,0,0,0.4)' }}>
|
||||
|
||||
{entry.last_completed ? new Date(entry.last_completed).toLocaleDateString('zh-CN') : '-'}
|
||||
{entry.last_completed ? formatBjDate(entry.last_completed) : '-'}
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { adminAPI, marketAPI } from '@/api';
|
||||
import type { AdBanner, MarketApp } from '@/types';
|
||||
import { formatBjDate } from '@/utils/datetime';
|
||||
import './Ads.css';
|
||||
|
||||
const SVGIcon: React.FC<{ children: React.ReactNode; size?: number }> = ({ children, size = 16 }) => (
|
||||
@@ -281,7 +282,7 @@ const Ads: React.FC = () => {
|
||||
</span>
|
||||
</td>
|
||||
<td style={{ fontSize: 'var(--text-xs)', color: 'var(--color-text-tertiary)' }}>
|
||||
{new Date(banner.createdAt).toLocaleDateString()}
|
||||
{formatBjDate(banner.createdAt)}
|
||||
</td>
|
||||
<td>
|
||||
<div style={{ display: 'flex', gap: 'var(--space-xs)' }}>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { adminAPI } from '@/api';
|
||||
import './Apps.css';
|
||||
import { formatBjTime } from '@/utils/datetime';
|
||||
import { formatBjTime, formatBjDate } from '@/utils/datetime';
|
||||
|
||||
interface AIApp {
|
||||
id: string;
|
||||
@@ -224,11 +224,7 @@ export default function AdminApps() {
|
||||
};
|
||||
|
||||
const formatDate = (dt: string | null) => {
|
||||
if (!dt) return '-';
|
||||
try {
|
||||
const d = new Date(dt);
|
||||
return d.toLocaleDateString('zh-CN') + ' ' + d.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
|
||||
} catch { return dt; }
|
||||
return formatBjTime(dt);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -738,7 +734,7 @@ function AppDetailDrawer({ app, analytics, onClose, onAction }: {
|
||||
<div key={v.id} className="version-item">
|
||||
<span className="version-num">v{v.version}</span>
|
||||
<span className="version-log">{v.changelog}</span>
|
||||
<span className="version-date">{v.created_at ? new Date(v.created_at).toLocaleDateString('zh-CN') : '-'}</span>
|
||||
<span className="version-date">{v.created_at ? formatBjDate(v.created_at) : '-'}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { imUserAPI } from '@/api';
|
||||
import { formatBjDate } from '@/utils/datetime';
|
||||
|
||||
const PRIMARY = '#5B5FED';
|
||||
|
||||
@@ -106,7 +107,7 @@ const AppServices: React.FC = () => {
|
||||
</div>
|
||||
<p style={{ fontSize: '13px', color: '#6B7280', lineHeight: 1.7, flex: 1, margin: '0 0 14px 0' }}>{app.description || '暂无描述'}</p>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<span style={{ fontSize: '12px', color: '#9CA3AF' }}>{app.published_at ? '上架于 ' + new Date(app.published_at).toLocaleDateString('zh-CN') : ''}</span>
|
||||
<span style={{ fontSize: '12px', color: '#9CA3AF' }}>{app.published_at ? '上架于 ' + formatBjDate(app.published_at) : ''}</span>
|
||||
<button onClick={() => showToast('已加入「我的应用」,可在 AI 聊天中调用')} style={{ padding: '7px 16px', background: PRIMARY, border: 'none', borderRadius: '8px', color: '#fff', fontSize: '13px', fontWeight: 500, cursor: 'pointer' }}>使用</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { Asset, AssetCategory, AssetCategoryDef, AssetFileType } from '@/types';
|
||||
import { assetsAPI } from '@/api';
|
||||
import { formatBjTime } from '@/utils/datetime';
|
||||
import './AssetsPage.css';
|
||||
|
||||
const fileTypeLabels: Record<string, { label: string; bg: string; color: string }> = {
|
||||
@@ -46,7 +47,7 @@ function formatSize(bytes?: number): string {
|
||||
}
|
||||
|
||||
function formatDate(dateStr: string): string {
|
||||
return new Date(dateStr).toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });
|
||||
return formatBjTime(dateStr);
|
||||
}
|
||||
|
||||
// 将文件扩展名或API返回的file_type映射到前端fileType标签
|
||||
|
||||
@@ -471,10 +471,15 @@
|
||||
}
|
||||
|
||||
.md-table td {
|
||||
padding: 10px 14px;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid #EEF0F4;
|
||||
color: var(--color-text-primary);
|
||||
vertical-align: top;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.md-table td br {
|
||||
line-height: 0.8;
|
||||
}
|
||||
|
||||
.md-table tbody tr:last-child td {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { chatAPI, knowledgeAPI, marketAPI, evolutionAPI } from '@/api';
|
||||
import { formatChatTime } from '@/utils/datetime';
|
||||
import type { Conversation, Message } from '@/types';
|
||||
import './ChatPage.css';
|
||||
|
||||
@@ -188,41 +189,8 @@ const MarkdownContent: React.FC<{ content: string }> = ({ content }) => {
|
||||
return '\x00MEDIA' + (mediaBlocks.length - 1) + '\x00';
|
||||
});
|
||||
|
||||
// 2.7 Extract Markdown tables: | h1 | h2 |\n|---|---| ... |
|
||||
// 把整段表格替换为占位符,表格内容(已转义)放入 tableBlocks 数组
|
||||
const tableBlocks: string[] = [];
|
||||
text = text.replace(
|
||||
/((?:^\|.+\|\r?\n)+^\|[\s\-:|]+\|\r?\n(?:^\|.+\|\r?\n?)+)/gm,
|
||||
(_m: string, block: string) => {
|
||||
const lines = block.trim().split(/\r?\n/).filter((l: string) => l.trim());
|
||||
if (lines.length < 2) return block;
|
||||
const headerCells = lines[0].split('|').slice(1, -1).map((c: string) => c.trim());
|
||||
const alignCells = lines[1].split('|').slice(1, -1).map((c: string) => {
|
||||
const t = c.trim();
|
||||
const left = t.startsWith(':');
|
||||
const right = t.endsWith(':');
|
||||
if (left && right) return 'center';
|
||||
if (right) return 'right';
|
||||
if (left) return 'left';
|
||||
return 'left';
|
||||
});
|
||||
const bodyRows = lines.slice(2).map((row: string) =>
|
||||
row.split('|').slice(1, -1).map((c: string) => c.trim())
|
||||
);
|
||||
const thead = headerCells.map((c: string, i: number) =>
|
||||
`<th style="text-align:${alignCells[i] || 'left'}">${c}</th>`
|
||||
).join('');
|
||||
const tbody = bodyRows.map((r: string[]) =>
|
||||
'<tr>' + r.map((c: string, i: number) =>
|
||||
`<td style="text-align:${alignCells[i] || 'left'}">${c}</td>`
|
||||
).join('') + '</tr>'
|
||||
).join('');
|
||||
const html = `<table class="md-table"><thead><tr>${thead}</tr></thead><tbody>${tbody}</tbody></table>`;
|
||||
const idx = tableBlocks.length;
|
||||
tableBlocks.push(html);
|
||||
return '\x00TABLE' + idx + '\x00';
|
||||
}
|
||||
);
|
||||
// 2.6 Normalize excessive blank lines in prose (code blocks already extracted)
|
||||
text = text.replace(/\n{3,}/g, '\n\n').trim();
|
||||
|
||||
// 2.8 LaTeX 数学公式:$$...$$(块级)和 $...$(行内)
|
||||
// 提取为占位符,渲染后用 KaTeX 处理
|
||||
@@ -272,15 +240,58 @@ const MarkdownContent: React.FC<{ content: string }> = ({ content }) => {
|
||||
text = text.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
||||
text = text.replace(/(?<!\w)\*(?!\*)(.+?)(?<!\*)\*(?!\w)/g, '<em>$1</em>');
|
||||
|
||||
// 7.5 Extract Markdown tables after inline formatting so cells support bold/italic/links.
|
||||
// 表格提取放在加粗/链接之后,避免单元格内 **xxx** 原样显示;同时压缩单元格内多余 <br>。
|
||||
const tableBlocks: string[] = [];
|
||||
text = text.replace(
|
||||
/((?:^\|.+\|\r?\n)+^\|[\s\-:|]+\|\r?\n(?:^\|.+\|\r?\n?)+)/gm,
|
||||
(_m: string, block: string) => {
|
||||
const lines = block.trim().split(/\r?\n/).filter((l: string) => l.trim());
|
||||
if (lines.length < 2) return block;
|
||||
const headerCells = lines[0].split('|').slice(1, -1).map((c: string) => c.trim());
|
||||
const alignCells = lines[1].split('|').slice(1, -1).map((c: string) => {
|
||||
const t = c.trim();
|
||||
const left = t.startsWith(':');
|
||||
const right = t.endsWith(':');
|
||||
if (left && right) return 'center';
|
||||
if (right) return 'right';
|
||||
if (left) return 'left';
|
||||
return 'left';
|
||||
});
|
||||
const normalizeCell = (cell: string) => {
|
||||
return cell
|
||||
.replace(/<br\s*\/?>\s*/gi, '<br/>')
|
||||
.replace(/\n/g, '<br/>')
|
||||
.replace(/(<br\/>){2,}/g, '<br/>')
|
||||
.replace(/^(<br\/>)+|(<br\/>)+$/g, '');
|
||||
};
|
||||
const bodyRows = lines.slice(2).map((row: string) =>
|
||||
row.split('|').slice(1, -1).map((c: string) => normalizeCell(c.trim()))
|
||||
);
|
||||
const thead = headerCells.map((c: string, i: number) =>
|
||||
`<th style="text-align:${alignCells[i] || 'left'}">${normalizeCell(c)}</th>`
|
||||
).join('');
|
||||
const tbody = bodyRows.map((r: string[]) =>
|
||||
'<tr>' + r.map((c: string, i: number) =>
|
||||
`<td style="text-align:${alignCells[i] || 'left'}">${c}</td>`
|
||||
).join('') + '</tr>'
|
||||
).join('');
|
||||
const html = `<table class="md-table"><thead><tr>${thead}</tr></thead><tbody>${tbody}</tbody></table>`;
|
||||
const idx = tableBlocks.length;
|
||||
tableBlocks.push(html);
|
||||
return '\x00TABLE' + idx + '\x00';
|
||||
}
|
||||
);
|
||||
|
||||
// 8. Lists
|
||||
text = text.replace(/^\s*[-*] (.+)$/gm, '<li class="md-li">$1</li>');
|
||||
text = text.replace(/^\s*\d+\. (.+)$/gm, '<li class="md-li">$1</li>');
|
||||
// Wrap consecutive <li> in <ul>
|
||||
text = text.replace(/((?:<li class="md-li">[\s\S]*?<\/li>\n?)+)/g, '<ul class="md-ul">$1</ul>');
|
||||
|
||||
// 9. Convert double newlines to paragraph breaks, single to <br/>
|
||||
// 9. Convert double newlines to paragraph breaks, single newlines to spaces
|
||||
text = text.replace(/\n\n/g, '</p><p class="md-p">');
|
||||
text = text.replace(/\n/g, '<br/>');
|
||||
text = text.replace(/\n/g, ' ');
|
||||
|
||||
// 10. Restore code blocks and inline codes
|
||||
text = text.replace(/\x00CODEBLOCK(\d+)\x00/g, (_m: string, idx: string) => codeBlocks[parseInt(idx)] || '');
|
||||
@@ -396,21 +407,7 @@ function escapeHtml(text: string): string {
|
||||
|
||||
// ===== Time Formatting =====
|
||||
function formatTime(iso: string): string {
|
||||
const date = new Date(iso);
|
||||
const now = new Date();
|
||||
const diff = now.getTime() - date.getTime();
|
||||
const oneDay = 24 * 60 * 60 * 1000;
|
||||
|
||||
if (diff < oneDay) {
|
||||
return date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
|
||||
} else if (diff < 7 * oneDay) {
|
||||
const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||
return days[date.getDay()];
|
||||
} else if (date.getFullYear() === now.getFullYear()) {
|
||||
return `${date.getMonth() + 1}/${date.getDate()}`;
|
||||
} else {
|
||||
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
|
||||
}
|
||||
return formatChatTime(iso);
|
||||
}
|
||||
|
||||
// ===== Helpers: normalize API responses =====
|
||||
|
||||
@@ -1596,6 +1596,7 @@ const MarketPage: React.FC = () => {
|
||||
const [localApps, setLocalApps] = useState<MarketApp[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const searchTimerRef = useRef<number | null>(null);
|
||||
const [capabilityFilter, setCapabilityFilter] = useState<string | null>(null);
|
||||
const [installToast, setInstallToast] = useState<string | null>(null);
|
||||
|
||||
@@ -1893,7 +1894,7 @@ const MarketPage: React.FC = () => {
|
||||
className="form-input"
|
||||
placeholder="搜索应用名称或描述..."
|
||||
value={searchQuery}
|
||||
onChange={e => { setSearchQuery(e.target.value); loadApps(e.target.value); }}
|
||||
onChange={e => { const v = e.target.value; setSearchQuery(v); if (searchTimerRef.current) clearTimeout(searchTimerRef.current); searchTimerRef.current = window.setTimeout(() => loadApps(v), 350); }}
|
||||
style={{ paddingLeft: 32, flex: 1, maxWidth: 400 }}
|
||||
/>
|
||||
{searchQuery && (
|
||||
|
||||
@@ -7,3 +7,34 @@ export function formatBjTime(t?: string | null): string {
|
||||
if (isNaN(d.getTime())) return t;
|
||||
return d.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false });
|
||||
}
|
||||
|
||||
// 仅日期(北京时间)
|
||||
export function formatBjDate(t?: string | null): string {
|
||||
if (!t) return '-';
|
||||
const iso = /[Z+]/.test(t) ? t : t + '+08:00';
|
||||
const d = new Date(iso);
|
||||
if (isNaN(d.getTime())) return t;
|
||||
return d.toLocaleDateString('zh-CN', { timeZone: 'Asia/Shanghai' });
|
||||
}
|
||||
|
||||
// 将任意 Date 换算为「北京墙钟」对应的 UTC 视图,便于按北京日历日比较
|
||||
function toBjView(d: Date): Date {
|
||||
return new Date(d.getTime() + (d.getTimezoneOffset() + 480) * 60000);
|
||||
}
|
||||
|
||||
// 聊天消息时间:今天 HH:MM / 昨天 HH:MM / MM-DD HH:MM / YYYY-MM-DD HH:MM(北京时间)
|
||||
export function formatChatTime(iso?: string | null): string {
|
||||
if (!iso) return '';
|
||||
const s = /[Z+]/.test(iso) ? iso : iso + '+08:00';
|
||||
const d = new Date(s);
|
||||
if (isNaN(d.getTime())) return '';
|
||||
const bj = toBjView(d);
|
||||
const nowBj = toBjView(new Date());
|
||||
const dayDiff = Math.floor(nowBj.getTime() / 86400000) - Math.floor(bj.getTime() / 86400000);
|
||||
const hhmm = d.toLocaleTimeString('zh-CN', { timeZone: 'Asia/Shanghai', hour: '2-digit', minute: '2-digit' });
|
||||
if (dayDiff <= 0) return hhmm;
|
||||
if (dayDiff === 1) return '昨天 ' + hhmm;
|
||||
const md = d.toLocaleDateString('zh-CN', { timeZone: 'Asia/Shanghai', month: '2-digit', day: '2-digit' });
|
||||
if (bj.getUTCFullYear() === nowBj.getUTCFullYear()) return md + ' ' + hhmm;
|
||||
return d.toLocaleDateString('zh-CN', { timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit' }) + ' ' + hhmm;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS `skill_trajectory_links` (
|
||||
`skill_name` VARCHAR(200) NOT NULL,
|
||||
`user_id` VARCHAR(36) NOT NULL,
|
||||
`trajectory_id` VARCHAR(36),
|
||||
`atom_id` VARCHAR(36),
|
||||
`atom_id` VARCHAR(128),
|
||||
`weightscore` INT DEFAULT 0,
|
||||
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX `idx_stl_user_skill` (`user_id`, `skill_name`),
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- 021: 加宽 skill_trajectory_links.atom_id 列
|
||||
-- 背景:atom_id 实际值形如 "{trajectory_id}_atom_{i}"(UUID 36 + "_atom_" + 序号 ≈ 45 字符),
|
||||
-- 原 VARCHAR(36) 过短导致写入时 DataError(1406) Data too long,并使会话进入 rolled-back 状态,
|
||||
-- 级联触发 PendingRollbackError 与日志 trace_id KeyError 刷屏。
|
||||
-- 本迁移幂等:重复执行 MODIFY 到相同类型为无害 no-op。
|
||||
|
||||
ALTER TABLE `skill_trajectory_links` MODIFY COLUMN `atom_id` VARCHAR(128) NULL;
|
||||
Reference in new issue
Block a user