feat: 2026-04-15~05-02 累积变更基线 — AI 重构 + Runtime Context + DWS 修复
涵盖(每条对应已存的审计记录): - AI 模块拆分:apps/backend/app/ai/apps -> prompts/(8 个 APP + app2a 派生) audit: 2026-04-20__ai-module-complete.md - admin-web AI 管理套件:AIDashboard / AIOperations / AIRunLogs / AITriggers / TriggerManager audit: 2026-04-21__admin-web-ai-management-suite.md - App2 财务洞察 prompt v3 -> v5.1 + 小程序 AI 接入(chat / board-finance) audit: 2026-04-22__app2_prompt_v5_1_and_miniprogram_ai_insight.md - App2 prewarm 全过滤器 + AI 触发器 cron reschedule audit: 2026-04-21__app2-finance-prewarm-all-filters.md migration: 20260420_ai_trigger_jobs_and_app2_prewarm.sql / 20260421_app2_prewarm_cron_reschedule.sql - AppType 联合类型对齐 + adminAiAppTypes.test.ts audit: 2026-04-30__admin_web_ai_app_type_alignment.md - DashScope tokens_used 提取修复 audit: 2026-04-30__backend_dashscope_tokens_used_extraction.md - App3 线索完整详情 prompt audit: 2026-05-01__backend_app3_full_detail_prompt.md - Runtime Context 沙箱(5-1~5-2 主线): - 后端 schema/service + admin_runtime_context / xcx_runtime_clock 两个 router - admin-web RuntimeContext.tsx + miniprogram runtime-clock.ts - migration: 20260501__runtime_context_sandbox.sql - tools/db/verify_admin_web_sandbox.py + verify_sandbox_end_to_end.py - database/changes: 7 份 sandbox_* 验证报告 - 飞球 DWS 修复:finance_area_daily 区域汇总 + task_engine 调整 + RLS 视图业务日上界(migration 20260502 + scripts/ops/gen_rls_business_date_migration.py) 合规: - .gitignore 启用 tmp/ 排除 - 不入仓:apps/etl/connectors/feiqiu/.env(API_TOKEN secret,本地修改保留) 待验证清单: - docs/audit/changes/2026-05-04__cumulative_baseline_pending_verification.md 每个主题的功能完整性 / 上线验证几乎都未收口,按优先级 P0~P3 逐一处理
This commit is contained in:
@@ -14,12 +14,17 @@ from typing import Callable
|
||||
|
||||
import psycopg2.extensions
|
||||
|
||||
from app.services.runtime_context import LIVE_INSTANCE_ID, MODE_LIVE, MODE_SANDBOX, get_runtime_context
|
||||
|
||||
# prompt 最大存储长度
|
||||
_MAX_PROMPT_LENGTH = 2000
|
||||
# 2026-04-22:2000→8000。app2_finance 真实 prompt 约 4-8KB(72 组合财务看板 + 中文 key 膨胀),
|
||||
# 2000 字符截断会丢掉 optimization-critical 字段(如 discount_items 含团购折扣明细),
|
||||
# admin-web 调用详情页无法完整审阅 → 提高到 8000 覆盖绝大部分场景
|
||||
_MAX_PROMPT_LENGTH = 8000
|
||||
|
||||
|
||||
def _truncate_prompt(prompt: str | None) -> str | None:
|
||||
"""截断 prompt 为前 2000 字符。None 原样返回。"""
|
||||
"""截断 prompt 为 _MAX_PROMPT_LENGTH 字符上限。None 原样返回。"""
|
||||
if prompt is None:
|
||||
return None
|
||||
return prompt[:_MAX_PROMPT_LENGTH]
|
||||
@@ -54,17 +59,21 @@ class AIRunLogService:
|
||||
truncated = _truncate_prompt(request_prompt)
|
||||
conn = self._get_conn()
|
||||
try:
|
||||
ctx = get_runtime_context(site_id, conn=conn)
|
||||
runtime_mode = MODE_SANDBOX if ctx.is_sandbox else MODE_LIVE
|
||||
sandbox_instance_id = ctx.sandbox_instance_id if ctx.is_sandbox else LIVE_INSTANCE_ID
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO biz.ai_run_logs
|
||||
(site_id, app_type, trigger_type, member_id,
|
||||
request_prompt, session_id, status)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, 'pending')
|
||||
request_prompt, session_id, status,
|
||||
runtime_mode, sandbox_instance_id)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, 'pending', %s, %s)
|
||||
RETURNING id
|
||||
""",
|
||||
(site_id, app_type, trigger_type, member_id,
|
||||
truncated, session_id),
|
||||
truncated, session_id, runtime_mode, sandbox_instance_id),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
assert row is not None, "INSERT RETURNING 应返回 id"
|
||||
|
||||
Reference in New Issue
Block a user