-- AI 助手消息执行步骤表(思考过程 + 分步结论,docs/design/chat-process-timeline-plan.md) -- 追加型明细,物理删除,不设 del_flag;仅承接开关启用后新产生的对话,存量历史会话不回填。 -- 幂等:create table / index if not exists,可重复执行。 create table if not exists ai_message_step ( id bigint not null, session_id bigint not null, message_id bigint not null, seq integer not null, step_key varchar(128) not null, kind varchar(20) not null, speaker varchar(10) default 'entry', expert_name varchar(100), agent_id bigint, title varchar(200), status varchar(20) not null, conclusion varchar(500), detail_json text, duration_ms bigint, remark varchar(500), create_by bigint, create_time timestamp, update_by bigint, update_time timestamp, constraint pk_ai_message_step primary key (id) ); -- HITL 恢复段按 (message_id, step_key) upsert:暂停段 waiting → 恢复段终态,seq 保留原值 create unique index if not exists uk_ai_message_step_key on ai_message_step (message_id, step_key); -- 会话级回放:按消息分组、轮内序号排序 create index if not exists idx_ai_message_step_session on ai_message_step (session_id, message_id, seq); comment on table ai_message_step is 'AI 助手消息执行步骤表(思考/路由/工具/专家/确认/整合,物理追加+按步键幂等更新,仅新数据写入)'; comment on column ai_message_step.id is '主键(雪花)'; comment on column ai_message_step.session_id is '所属会话(ai_session.id)'; comment on column ai_message_step.message_id is '所属助手消息(ai_message.id)'; comment on column ai_message_step.seq is '轮内步骤序号(恢复段续接 maxSeq+n)'; comment on column ai_message_step.step_key is '步骤键(轮内唯一,HITL 恢复段 upsert 依据)'; comment on column ai_message_step.kind is '步骤类型 thinking/route/tool/expert/confirm/integration'; comment on column ai_message_step.speaker is '说话人 entry/expert'; comment on column ai_message_step.expert_name is '专家名(speaker=expert 时)'; comment on column ai_message_step.agent_id is '关联智能体主键(专家步/确认步)'; comment on column ai_message_step.title is '步骤标题(后端拼好)'; comment on column ai_message_step.status is '状态 running/success/error/skipped/waiting/approved/rejected/expired/aborted'; comment on column ai_message_step.conclusion is '一行结论(≤80 字)'; comment on column ai_message_step.detail_json is '详情 JSON(思考全文/工具入参出参/专家原文+子工具/路由理由/确认处置,已脱敏)'; comment on column ai_message_step.duration_ms is '步骤耗时(毫秒)'; comment on column ai_message_step.remark is '备注'; comment on column ai_message_step.create_by is '创建者'; comment on column ai_message_step.create_time is '创建时间'; comment on column ai_message_step.update_by is '更新者'; comment on column ai_message_step.update_time is '更新时间';