18 Commits
Author SHA1 Message Date
qihu-bot 9cf4378bf5 #973 微信Bot文本回复慢+间歇空修复
CI / gate (push) Has been cancelled
根因: 多轮对话时图片URL(含AWS token)存进历史+104技能清单注入prompt, 导致推理模型响应慢(72s)且间歇返回空content。修复: 1.IM侧精简prompt(db=None只注入静态文档) 2.空content重试(同模型最多3轮) 3.图片回复存[图片]占位符不存URL 4.历史每条截断500字符。验证: 你好15s/1+1=4s可正常回复。
2026-08-18 11:15:50 +08:00
QihuAI Design 04a0641202 feat(otel #876): 双 Claw 强制标签 + 入口接线 + Grafana 双 Claw 对比看板
#876 OpenTelemetry 可观测(双 Claw 标签):
- app/core/otel.py: 新增 set_otel_ctx/get_otel_ctx(ContextVar 三元组 tenant_id+claw_type+
  trace_id);current_span_cm 自动注入双 Claw 强制标签,全部 13 个 span 调用点零签名侵入带维度;
  record_span_metrics 指标维度补 tenant_id+claw_type(trace_id 因高基数不计入指标标签)。
- app/core/llm_router.py: set_route_ctx 桥接转调 set_otel_ctx(单次入口注入双端共享:
  路由上下文 + OTel 标签),失败安全。
- app/api/chat.py: send_message 与 send_message_stream 入口注入 set_route_ctx(web),
  stream 经 asyncio.create_task 子协程自动传播 contextvars,使 _send_message_core 内
  所有 span 均带 tenant_id+claw_type。
- app/api/im_llm.py: _call_real_llm 入口最早注入 set_route_ctx(im_wechat),并显式开启
  im.send_message span(此前 IM Claw 完全无 span,Grafana 无 IM 数据点),finally 关闭。
- tests/test_dual_claw.py: R-DUAL-6 由 skip 转为确定性断言(Web/IM 双 Claw span 必带
  tenant_id+claw_type),作为持续哨兵。
- 交付 Grafana 双 Claw 对比看板 JSON(aiflow_span_* / aiflow_llm_route_total 按 claw_type
  分组:P50/P95 延迟、成功率、QPS、租户健康 Top10)。Alloy OTLP 仅桥接 metrics→Prometheus,
  trace 无 pipeline(#800 已压制 UNIMPLEMENTED 噪声),看板基于 metrics 出图。

safe-align: 仅复制 5 个 git-tracked 文件,未触碰 secrets/venv/node_modules/caches。本地提交不 push。
2026-08-04 13:49:34 +08:00
QihuAI Design 180409d317 feat(#875): LLM Router shadow mode + consolidate litellm master key 2026-08-04 13:16:30 +08:00
QihuAI Design 037c965c26 feat(engine): #873 dual-Claw event contract + SseAdapter/BufferAdapter + chat.py SSE delegate + im_llm EngineCore thin-shell (gray-gated)
- app/core/engine_event.py (#880): EngineEvent dataclass + make_* factories, single construction entry, byte-compatible wire with legacy ChatPage.tsx
- app/core/claw_adapters.py (#884): SseAdapter (hot frames zero-metadata, terminal keeps trace_id) + BufferAdapter (assemble() preserves __media__)
- app/api/chat.py (#881): /messages/stream now delegates to SseAdapter; wire bytes unchanged (46B delta / done+message_id)
- app/api/im_llm.py (#883): IM_USE_ENGINE_CORE gray gate; _call_engine_core reuses EngineCore via BufferAdapter (default OFF, preserves media fast-path)
- app/api/chat_service.py: capture 3 container-ahead fixes (stray import asyncio removed, logger.info format, LiteLLM master key)
2026-08-04 12:25:12 +08:00
QihuAI Design 29a1ce2e54 fix: 双Claw能力对齐 + MCP/LLM代理绕过(P0止血)
- 新增 app/core/capability_discovery.py:统一能力发现层,Web/IM 双Claw共用单一实现
  (三级降级:用户安装 → 平台published → 相关性裁剪;MCP 自动挂载已启用服务)
- im_llm.py:IM Bot Claw 改用统一发现层,恢复 skills(12) + MCP(26工具) 能力,
  修复 #866 部署回退导致的 agents=[]/mcp=[] 回归;mcp__ 前缀分流到 call_mcp_tool
- mcp_client.py:注入 httpx_client_factory(trust_env=False) 绕过容器 HTTP_PROXY,
  修复外部 MCP(xiaobenyang.com / anysearch.com) tools/list 全部静默失败(mcp_tools 0→26)
- llm_client.py / im_bot_user.py:2026-07-31 代理劫持内部请求 + 媒体断连修复(随镜像已上线)
2026-08-04 10:21:19 +08:00
QihuAI Design 9a43ee244d fix(im_llm): 代理绕过Docker内部hostname 2026-07-31 08:51:15 +08:00
QihuAI Design 771c8456b8 chore: normalize line endings to LF via .gitattributes
Root-cause fix for mixed CRLF/LF in the repo (no .gitattributes previously).
Adds '* text=auto eol=lf' and explicit binary rules so all future checkouts
are LF. Renormalizes all tracked text files (no logical content change).
Backup tags: image qihuaiflow:backup-lineend-20260725-121632, git backup-lineend-pre-20260725-121632.
2026-07-25 12:16:39 +08:00
QihuAI Design e8a1791c9f chore(align): sync Git with running container as authoritative source
Standards alignment (STANDARDS_AUDIT_2026-07-24): Phase 1 标准化核心 +
Phase 2 质量层 landed in the running container and captured in Git so the
three sources (container := image := Git) agree.

Backend (Phase 1 标准化核心):
- mcp_client.py: replaced hand-rolled JSON-RPC with official `mcp` SDK
  (ClientSession, streamable_http/sse transports, protocol auto-negotiation)
- core/otel.py + core/observability.py: standard OpenTelemetry SDK bridge
  (OTLP gRPC), wired to Grafana Alloy (qihu-aiflow-alloy:4317) which forwards
  metrics to Prometheus; emits aiflow_span_duration_ms / aiflow_span_count
- deployments: Grafana Alloy container + Prometheus remote-write receiver

Backend (Phase 2 质量层):
- core/rag_pipeline.py: standardized RAG (recursive overlap chunking +
  rerank hook) reusing pgvector_search
- core/llm_client.py: SDK-ified LLM + embeddings (aembed/embed) collapsing
  hand-rolled httpx calls; trust_env=False to bypass container proxy

Migrations:
- 018_normalize_marketapp_scene.sql: fixed capability allowlist
  (prevents capability wipe on restart)

Alignment performed 2026-07-24 12:18:51. No deletions; secrets/venv/node_modules/
caches were not touched (tracked-source-only copy).
2026-07-24 12:18:52 +08:00
QihuAI Design 26075272d6 chore(align): sync Git with running container as authoritative source
One-time alignment to close drift between the running container
(qihu-aiflow / image qihuaiflow:with-deps) and this Git repository.
Container hotfixes previously persisted only via `docker commit` are now
captured in Git so Git becomes the single source of truth.

Backend:
- chat_service.py: accumulated fixes incl. EigenFlux README guidance
- chat_context.py / chat_media.py: URL/web-repo context injection
- api/url_reader.py: NEW SSRF-safe web/README reader (Issue #725)
- skills_admin.py & Skills.tsx: 14-scene capability unification
- pgvector_search.py, orchestrator.py, platform_knowledge.py,
  market.py, admin/models.py: drift sync

Frontend:
- ChatPage.tsx: collapsible AI think/act block (Issue #724)
- MarketPage / EvolutionDashboard / TokenDashboard styling sync

Migrations:
- 018_normalize_marketapp_scene.sql: fixed capability allowlist
  (prevents capability wipe on restart)

Alignment performed 2026-07-23 22:42:43. No deletions; secrets/venv/node_modules/
caches were not touched (tracked-source-only copy).
2026-07-23 22:42:46 +08:00
QihuAI Design 2969544d54 feat(observability): Phase2.3 媒体/LLM 可观测面板(后端归因聚合+前端页) 并修复 token_usage_logs trace_id 写入(chat_service/im_llm) [v2026.07.19.5]
CI / gate (push) Has been cancelled
2026-07-19 10:18:14 +08:00
QihuAI Design ce81297159 fix: 修复技能市场分页、后台Skills管理、微信Bot图片生成超时
1. MarketPage.tsx: getApps 加 page_size=100,修复只显示20条
2. skills_admin.py: list_skills 同时查询 market_apps(type=skill)
   解决前台导入50个技能后台看不到(前后台用不同表)
3. im_llm.py: _run_async 加 timeout 参数,_call_real_llm 媒体生成
   5分钟超时保护,解决微信Bot图片生成无限期挂住的问题
2026-07-16 15:10:50 +08:00
QihuAI Design da89a27bca fix(wechat-bot): ①对话时间统一北京时间 ②媒体内联发送(微信直看图片/视频) ③媒体生成计入Token驾驶舱 ④清空技能市场 2026-07-15 23:37:30 +08:00
QihuAI Design 7739f17594 fix(wechat-bot): 修复 AGNES 媒体生成失败——优化步骤相对导入路径错误(从未生效)+ 国内模型直连 + 内容策略重试 2026-07-15 22:04:22 +08:00
QihuAI Design fd2011b93e fix: AGNES 三个模型改走香港代理(实测延迟更低、更稳定) 2026-07-15 20:17:44 +08:00
deploy ccc5f799e1 fix(media): AGNES 图像/视频生成加韧性层——指数退避重试+友好错误翻译+Bot解析加固
根因(实测复现): AGNES 外部服务不稳定, 非平台代码问题:
- 视频创建常返 500 publish_video_queue_failed / context deadline exceeded
- 连接偶发重置 Server disconnected
- 视频硬限频 每分钟 1 次 (429 rate limit)

改动:
1. chat.py 新增 _agnes_post_json(): 对 5xx/连接中断做 3 次指数退避重试(2/4s);
   4xx(参数错误)不重试直接返回
2. 新增 _friendly_media_err(): 把 AGNES 原始 HTTP/JSON 错误
   转译为对用户友好的中文(限频/连接失败/队列繁忙), 不再透传原始报错
3. _generate_media 图像/视频分支改用上述重试+友好错误
4. im_llm.py Bot 媒体结果解析加固: strip 后判 <img>/<video>,
   成功返回干净链接; 失败透传友好中文, 绝不把原始提示词/标签甩给用户

验证(容器内实测):
- WEB_IMG OK / WEB_VID OK / BOT_IMG OK (均返回真实 png/mp4)
- 429/断开/队列三类错误均正确转译为友好中文
2026-07-15 19:58:06 +08:00
deploy 148e4a21c2 fix: 全面修复6项问题——Auto模型路由/媒体提示词优化/微信Bot/Token驾驶舱/技能市场清空
1. resolve_auto_model: image/video/audio无显式默认时自动发现启用模型(原返回None→文本模型回退→AI说无法生成)
2. 新增_optimize_media_prompt: 调用文本LLM精炼用户原始输入为AGNES高质量提示词(去除对话噪音+英文优化)
3. detect_media_intent: 扩展关键词覆盖多轮对话模式(做图片/生成个图/画一下/制作视频等)
4. chat.py+im_llm.py: 所有httpx调用补trust_env=False+_proxy_for_url, 规避容器坏代理
5. token_usage.py: 模型名回退链(model表→日志自带的model_name→auto标签), 不再显示unknown
6. skills_admin.py: 新增POST /batch-delete批量删除API(ids空则删全部)
7. 技能市场数据已清空, 用户可重新导入技能
2026-07-15 17:05:00 +08:00
QihuAI Design 996d5413da fix: 修复AI聊天/IM多项问题(媒体直连+技能自动发现+agent/mcp上下文)
- Issue4/7: 图像/视频生成对AGNES国内域名强制直连(trust_env=False),修复Server disconnected(代理172.18.0.1:7890返回502)

- Issue8: 修复_parse_skill_content缺失def导致的NameError;新增_discover_installed_skills默认技能自动发现

- Issue2/3: system prompt注入agent资料与mcp描述/endpoint

- Issue7: IM Bot制作图片走Auto路由媒体模型
2026-07-15 12:23:56 +08:00
QihuAI Design ab54d7344c refactor: 移除通用频道管理(LangBot)模块,IM Bot 改为直接对接;迁移 _call_real_llm 至 im_llm 2026-07-14 08:21:56 +08:00