Compare commits
17
Commits
cb23061088
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0317873a5b | ||
|
|
eec5978fa7 | ||
|
|
25ec9cf69a | ||
|
|
302c4bcf52 | ||
|
|
05d0f89c16 | ||
|
|
a273a86a7d | ||
|
|
45f0560f85 | ||
|
|
f74d51b905 | ||
|
|
e08b0f4311 | ||
|
|
3bb662f092 | ||
|
|
a644e93604 | ||
|
|
795935bf6a | ||
|
|
7548896f6d | ||
|
|
5faaa88302 | ||
|
|
8c4aa5dc5b | ||
|
|
9142e30714 | ||
|
|
9e26d6b19c |
Generated
+1
-1
@@ -1039,7 +1039,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "devflow"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
||||
@@ -310,6 +310,7 @@ mod tests {
|
||||
role: MessageRole::User,
|
||||
content: "字面量构造".into(),
|
||||
parts: None,
|
||||
source: None,
|
||||
tool_call_id: None,
|
||||
tool_calls: None,
|
||||
model: None,
|
||||
@@ -368,6 +369,7 @@ mod tests {
|
||||
role: MessageRole::Assistant,
|
||||
content: "answer".to_string(),
|
||||
parts: None,
|
||||
source: None,
|
||||
tool_call_id: None,
|
||||
tool_calls: None,
|
||||
model: None,
|
||||
@@ -429,6 +431,7 @@ mod tests {
|
||||
role: MessageRole::Assistant,
|
||||
content: "answer".to_string(),
|
||||
parts: None,
|
||||
source: None,
|
||||
tool_call_id: None,
|
||||
tool_calls: None,
|
||||
model: None,
|
||||
|
||||
@@ -68,7 +68,9 @@ fn non_read_file_large_result_also_gets_handle() {
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
tool_offload::init_base(base.clone());
|
||||
|
||||
let body: String = (1..=1200).map(|i| format!("match {i}: src/foo.rs:{i}\n")).collect();
|
||||
// 中性行夹具:不得含 error/panic/.rs: 等错误行信号——错误行保留策略会全量保留
|
||||
// 命中行,用信号行做夹具会让「应被压缩」断言先天不成立(测的是普通大结果外置)
|
||||
let body: String = (1..=1200).map(|i| format!("match {i}: src/foo.txt:{i}\n")).collect();
|
||||
assert!(body.len() >= 8 * 1024, "夹具须 ≥8KB(句柄追加下限)");
|
||||
let out = extract_key_info(&body, "grep");
|
||||
assert!(out.len() < body.len(), "应被压缩");
|
||||
|
||||
@@ -1178,6 +1178,74 @@ impl KnowledgeRepo {
|
||||
.await
|
||||
.map_err(storage_err)?
|
||||
}
|
||||
|
||||
/// 知识路标读侧(devflow.md 投影通道):已发布且(人工验证 或 复用达标)的条目选摘。
|
||||
///
|
||||
/// 与检索族(search/search_keywords)的差别:路标无查询词,是「库里有什么」的静态选摘,
|
||||
/// 供 system prompt 路标段铺开让 agent 知晓库藏、想起检索。入选门槛 = published 且
|
||||
/// (verified = 1 OR reuse_count >= 3);排序 = 复用降序(唯一客观信号,对齐 search/top_used),
|
||||
/// 同复用按 created_at 降序定稳定次序。verified 只作入选不作排序(复用是更强的实战信号)。
|
||||
///
|
||||
/// 两档拼接:项目档(source_project = project_id,上限 project_limit)在前——会话归属
|
||||
/// 项目的知识最相关;跨项目补充档(非本项目含无归属条目,上限 global_limit)在后。
|
||||
/// 两档 WHERE 互斥(= pid vs IS NULL/≠ pid),结果天然无重复。
|
||||
/// project_id = None → 仅补充档(会话未解析出归属项目,项目档无从谈起)。
|
||||
pub async fn list_waymark(
|
||||
&self,
|
||||
project_id: Option<&str>,
|
||||
project_limit: usize,
|
||||
global_limit: usize,
|
||||
) -> Result<Vec<KnowledgeRecord>> {
|
||||
let conn = self.conn.clone();
|
||||
let project_id = project_id.map(|s| s.to_owned());
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let guard = conn.blocking_lock();
|
||||
// 入选门槛与排序两档共用(verified 在 SQLite 存 0/1;复用达标压线 3 即入选)
|
||||
let qualify = "status = 'published' AND (verified = 1 OR reuse_count >= 3)";
|
||||
let order = " ORDER BY reuse_count DESC, created_at DESC LIMIT ";
|
||||
let mut results = Vec::new();
|
||||
|
||||
// 项目档:会话归属项目内的合格条目(复用降序,上限 project_limit)
|
||||
if let Some(pid) = &project_id {
|
||||
let sql = format!(
|
||||
"SELECT {KNOWLEDGE_COLS} FROM knowledges WHERE {qualify} AND source_project = ?1{order}?2"
|
||||
);
|
||||
let mut stmt = guard.prepare(&sql).map_err(storage_err)?;
|
||||
let rows = stmt
|
||||
.query_map(params![pid, project_limit as i64], knowledge_from_row)
|
||||
.map_err(storage_err)?;
|
||||
for r in rows {
|
||||
results.push(r.map_err(storage_err)?);
|
||||
}
|
||||
}
|
||||
|
||||
// 跨项目补充档:非本项目(含无归属全局条目)按复用降序补足 global_limit;
|
||||
// WHERE 与项目档互斥 → 天然去重。project_id = None 时无排他条件,即全量合格条目。
|
||||
// LIMIT 占位符编号随排他条件有无而变(?1 空档排他时归 LIMIT,有排他时排他占 ?1、LIMIT 占 ?2)
|
||||
let exclude = if project_id.is_some() {
|
||||
" AND (source_project IS NULL OR source_project != ?1)"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let lim_n = if project_id.is_some() { 2 } else { 1 };
|
||||
let sql = format!("SELECT {KNOWLEDGE_COLS} FROM knowledges WHERE {qualify}{exclude}{order}?{lim_n}");
|
||||
let mut stmt = guard.prepare(&sql).map_err(storage_err)?;
|
||||
let rows = match &project_id {
|
||||
Some(pid) => stmt
|
||||
.query_map(params![pid, global_limit as i64], knowledge_from_row)
|
||||
.map_err(storage_err)?,
|
||||
None => stmt
|
||||
.query_map(params![global_limit as i64], knowledge_from_row)
|
||||
.map_err(storage_err)?,
|
||||
};
|
||||
for r in rows {
|
||||
results.push(r.map_err(storage_err)?);
|
||||
}
|
||||
Ok(results)
|
||||
})
|
||||
.await
|
||||
.map_err(storage_err)?
|
||||
}
|
||||
}
|
||||
|
||||
impl_repo!(
|
||||
@@ -1715,6 +1783,107 @@ mod tests {
|
||||
assert_eq!(hits[0].id, "k1");
|
||||
}
|
||||
|
||||
// ---------- 知识路标读侧(list_waymark,devflow.md 投影通道) ----------
|
||||
|
||||
/// 入选门槛:published 且(verified 或 复用达标);candidate/archived/复用不足均淘汰
|
||||
#[tokio::test]
|
||||
async fn waymark_qualifies_verified_or_reused_published_only() {
|
||||
let repo = setup_repo().await;
|
||||
// verified=true 复用 0 → 入选(验证豁免复用门槛)
|
||||
let mut v = krec("v", "已验证条目", "...", "lesson", "published", None, 0);
|
||||
v.verified = true;
|
||||
repo.insert(v).await.unwrap();
|
||||
// 未验证复用 3 → 入选(压线达标)
|
||||
repo.insert(krec("r3", "复用达标条目", "...", "lesson", "published", None, 3))
|
||||
.await
|
||||
.unwrap();
|
||||
// 未验证复用 2 → 淘汰
|
||||
repo.insert(krec("r2", "复用不足条目", "...", "lesson", "published", None, 2))
|
||||
.await
|
||||
.unwrap();
|
||||
// 复用再高,状态非 published(candidate)→ 淘汰
|
||||
repo.insert(krec("cand", "候选未发布", "...", "lesson", "candidate", None, 99))
|
||||
.await
|
||||
.unwrap();
|
||||
// archived → 淘汰
|
||||
repo.insert(krec("arch", "已归档", "...", "lesson", "archived", None, 99))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let hits = repo.list_waymark(None, 20, 10).await.unwrap();
|
||||
let ids: Vec<_> = hits.iter().map(|h| h.id.as_str()).collect();
|
||||
assert_eq!(ids.len(), 2, "只应入选 已验证 + 复用达标 两条");
|
||||
assert!(ids.contains(&"v") && ids.contains(&"r3"));
|
||||
}
|
||||
|
||||
/// 两档序:项目档在前(复用降序,verified 豁免复用但仍按复用参与排序),
|
||||
/// 跨项目补充档在后(复用降序);异项目高复用压不过同项目低复用(档位优先于复用)
|
||||
#[tokio::test]
|
||||
async fn waymark_project_tier_first_global_supplement_after() {
|
||||
let repo = setup_repo().await;
|
||||
repo.insert(krec("p9", "同项目复用9", "...", "lesson", "published", None, 9))
|
||||
.await
|
||||
.unwrap();
|
||||
repo.insert(krec("p5", "同项目复用5", "...", "lesson", "published", None, 5))
|
||||
.await
|
||||
.unwrap();
|
||||
// 同项目 verified 但零复用:入选项目档,排序落在复用条目之后
|
||||
let mut pv = krec("pv", "同项目已验证零复用", "...", "lesson", "published", None, 0);
|
||||
pv.verified = true;
|
||||
repo.insert(pv).await.unwrap();
|
||||
// 异项目高复用 → 补充档
|
||||
let mut f = krec("f99", "异项目复用99", "...", "lesson", "published", None, 99);
|
||||
f.source_project = Some("proj-2".to_string());
|
||||
repo.insert(f).await.unwrap();
|
||||
// 无归属全局条目 → 补充档
|
||||
let mut g = krec("g10", "全局复用10", "...", "lesson", "published", None, 10);
|
||||
g.source_project = None;
|
||||
repo.insert(g).await.unwrap();
|
||||
|
||||
let hits = repo.list_waymark(Some("proj-1"), 20, 10).await.unwrap();
|
||||
let ids: Vec<_> = hits.iter().map(|h| h.id.as_str()).collect();
|
||||
assert_eq!(
|
||||
ids,
|
||||
vec!["p9", "p5", "pv", "f99", "g10"],
|
||||
"项目档在前(复用降序),补充档在后(复用降序:异项目99 > 全局10)"
|
||||
);
|
||||
// 两档 WHERE 互斥的去重属性:任一条目恰好出现一次
|
||||
assert_eq!(ids.iter().filter(|i| **i == "p9").count(), 1, "同项目条目不得因两档重复出现");
|
||||
}
|
||||
|
||||
/// 各档上限独立生效:项目档取复用最高的 project_limit 条,补充档另计 global_limit 条
|
||||
/// (条目复用全部压线达标,确保裁剪只来自 LIMIT 而非入选门槛)
|
||||
#[tokio::test]
|
||||
async fn waymark_limits_cap_tiers_independently() {
|
||||
let repo = setup_repo().await;
|
||||
for reuse in 3..=5 {
|
||||
repo.insert(krec(&format!("p{reuse}"), "同项目", "...", "lesson", "published", None, reuse))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
for reuse in 3..=5 {
|
||||
let mut g = krec(&format!("g{reuse}"), "全局", "...", "lesson", "published", None, reuse);
|
||||
g.source_project = None;
|
||||
repo.insert(g).await.unwrap();
|
||||
}
|
||||
|
||||
let hits = repo.list_waymark(Some("proj-1"), 2, 2).await.unwrap();
|
||||
let ids: Vec<_> = hits.iter().map(|h| h.id.as_str()).collect();
|
||||
assert_eq!(
|
||||
ids,
|
||||
vec!["p5", "p4", "g5", "g4"],
|
||||
"项目档取复用最高的 2 条,补充档独立取全局最高的 2 条"
|
||||
);
|
||||
}
|
||||
|
||||
/// 空库 → 空结果(路标子块整体缺席的前提,投影侧据此零追加)
|
||||
#[tokio::test]
|
||||
async fn waymark_empty_db_returns_empty() {
|
||||
let repo = setup_repo().await;
|
||||
assert!(repo.list_waymark(Some("proj-1"), 20, 10).await.unwrap().is_empty());
|
||||
assert!(repo.list_waymark(None, 20, 10).await.unwrap().is_empty());
|
||||
}
|
||||
|
||||
// ---------- 复用即信任(auto_publish_if_reused) ----------
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -265,6 +265,12 @@ impl AiMessageRepo {
|
||||
/// 全量重写语义——以入参 records 为该对话的**唯一真相**,先删该 conv 全部旧行再批量插。
|
||||
/// 单事务保证「删 + 插」原子,无中间空窗(reload 不会读到半删半插的中间态)。
|
||||
///
|
||||
/// created_at 保出生时间(2026-10-17 修复批量污染):created_at 语义 = 消息首次入库时间,
|
||||
/// 全量重写只该变内容不变出生时间。调用方(save_conversation)对整批 records 统一盖
|
||||
/// 对话级 created_at(老对话 None 时 now 兜底),直插会把全对话消息 created_at 抹成同一秒。
|
||||
/// 故 DELETE 前先取存量 `id → created_at` 映射,重插时同 id 行回填原值;新 id(真新消息)
|
||||
/// 保留入参值。ai_messages 表无 updated_at 列,内容变更无单独时间戳(不在此列语义内)。
|
||||
///
|
||||
/// 设计权衡(非 dirty 增量,留 P2.1 优化):
|
||||
/// - 内存 ContextManager 是运行时真相源,save 是同步点,每轮 save 全量回写简单可靠;
|
||||
/// - INSERT OR IGNORE 幂等:records 内 id 重复或与残留行(理论不应有,事务已 DELETE)冲突跳过;
|
||||
@@ -274,7 +280,7 @@ impl AiMessageRepo {
|
||||
pub async fn replace_conversation(
|
||||
&self,
|
||||
conv_id: &str,
|
||||
records: Vec<AiMessageRecord>,
|
||||
mut records: Vec<AiMessageRecord>,
|
||||
) -> Result<()> {
|
||||
let conn = self.conn.clone();
|
||||
let conv_id = conv_id.to_owned();
|
||||
@@ -282,7 +288,29 @@ impl AiMessageRepo {
|
||||
let mut guard = conn.blocking_lock();
|
||||
let tx = guard.transaction().map_err(storage_err)?;
|
||||
{
|
||||
// 先删该 conv 全部旧行(全量重写语义)
|
||||
// 先取存量 id → created_at 映射(DELETE 前留证,重插回填保出生时间)
|
||||
{
|
||||
let mut stmt = tx
|
||||
.prepare("SELECT id, created_at FROM ai_messages WHERE conversation_id = ?1")
|
||||
.map_err(storage_err)?;
|
||||
let rows = stmt
|
||||
.query_map(params![conv_id], |r| {
|
||||
Ok((r.get::<_, String>("id")?, r.get::<_, String>("created_at")?))
|
||||
})
|
||||
.map_err(storage_err)?;
|
||||
let mut original: std::collections::HashMap<String, String> =
|
||||
std::collections::HashMap::new();
|
||||
for r in rows {
|
||||
let (id, created_at) = r.map_err(storage_err)?;
|
||||
original.insert(id, created_at);
|
||||
}
|
||||
for rec in &mut records {
|
||||
if let Some(orig) = original.get(&rec.id) {
|
||||
rec.created_at = orig.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
// 再删该 conv 全部旧行(全量重写语义)
|
||||
tx.execute(
|
||||
"DELETE FROM ai_messages WHERE conversation_id = ?1",
|
||||
params![conv_id],
|
||||
@@ -693,6 +721,62 @@ mod tests {
|
||||
assert_eq!(got.len(), 1, "重复 replace 不应叠加");
|
||||
}
|
||||
|
||||
/// replace_conversation 保 created_at 出生时间(2026-10-17 批量污染回归):
|
||||
/// 调用方对整批统一盖一个 created_at(如对话级时间或 now),重写后既有 id 行
|
||||
/// 的 created_at 必须逐行保留原入库值,不得被统一时间抹平;新 id 行保留入参值。
|
||||
#[tokio::test]
|
||||
async fn replace_conversation_preserves_created_at() {
|
||||
let db = Database::open_in_memory().await.expect("open_in_memory");
|
||||
let repo = AiMessageRepo::new(&db);
|
||||
|
||||
// 预置两行,created_at 各异(模拟真实逐条入库的出生时间)
|
||||
let mut m0 = mk_msg("m0", "c", 0, "user", "v1");
|
||||
m0.created_at = "2026-10-01T10:00:00.000".into();
|
||||
let mut m1 = mk_msg("m1", "c", 1, "assistant", "v1");
|
||||
m1.created_at = "2026-10-02T11:30:00.000".into();
|
||||
repo.insert_batch(vec![m0, m1]).await.expect("insert");
|
||||
|
||||
// 重写:既有 id 内容变了、created_at 被调用方统一盖成同一时间;
|
||||
// 另带一条新 id 消息(真新消息,该保留入参时间)。
|
||||
let uniform_ts = "2026-10-17T21:25:01.000";
|
||||
let rewrite = |id: &str, seq: i64, role: &str, content: &str| {
|
||||
let mut m = mk_msg(id, "c", seq, role, content);
|
||||
m.created_at = uniform_ts.into();
|
||||
m
|
||||
};
|
||||
repo.replace_conversation(
|
||||
"c",
|
||||
vec![
|
||||
rewrite("m0", 0, "user", "v2-改写内容"),
|
||||
rewrite("m1", 1, "assistant", "v2-改写内容"),
|
||||
rewrite("m2_new", 2, "user", "新消息"),
|
||||
],
|
||||
)
|
||||
.await
|
||||
.expect("replace");
|
||||
|
||||
let got = repo.list_by_conversation("c").await.expect("list");
|
||||
assert_eq!(got.len(), 3);
|
||||
// 逐行断言:既有 id 的 created_at 保持原值,内容确实变了
|
||||
assert_eq!(got[0].id, "m0");
|
||||
assert_eq!(got[0].created_at, "2026-10-01T10:00:00.000", "既有行 created_at 不得被重写抹平");
|
||||
assert_eq!(got[0].content, "v2-改写内容");
|
||||
assert_eq!(got[1].id, "m1");
|
||||
assert_eq!(got[1].created_at, "2026-10-02T11:30:00.000", "既有行 created_at 不得被重写抹平");
|
||||
assert_eq!(got[1].content, "v2-改写内容");
|
||||
// 新 id(首次入库)保留入参 created_at
|
||||
assert_eq!(got[2].id, "m2_new");
|
||||
assert_eq!(got[2].created_at, uniform_ts, "新消息保留入参 created_at");
|
||||
|
||||
// 二次重写再验:出生时间已固化,连续重写不漂移
|
||||
repo.replace_conversation("c", vec![rewrite("m0", 0, "user", "v3")])
|
||||
.await
|
||||
.expect("replace again");
|
||||
let got = repo.list_by_conversation("c").await.expect("list");
|
||||
assert_eq!(got.len(), 1);
|
||||
assert_eq!(got[0].created_at, "2026-10-01T10:00:00.000", "连续重写 created_at 不漂移");
|
||||
}
|
||||
|
||||
/// limit=0 契约:返空集(直传 SQLite LIMIT 0),不再旧版 max(1) 钳成 1 条。
|
||||
/// 锁死语义防回归:请求 0 条却回 1 条会让调用方误判页内有数据。
|
||||
#[tokio::test]
|
||||
|
||||
@@ -87,9 +87,9 @@ fn build_order_clause(order_by: Option<&str>) -> Result<String> {
|
||||
|
||||
/// 带「最近活跃时间」的项目记录(list_active_with_activity 专用返回结构)。
|
||||
///
|
||||
/// `last_active_at` = COALESCE(project_events 最新事件 created_at, projects.updated_at):
|
||||
/// 反映业务活跃(任务/灵感/状态推进等事件),无事件项目回退 updated_at。供前端「最近活跃排序」
|
||||
/// 展示,语义比 projects.updated_at(随元信息修改如改 description 也会刷新)更准确。
|
||||
/// `last_active_at` = MAX(tasks.updated_at 最新值, project_events 最新 created_at,
|
||||
/// projects.updated_at):任务活跃为主信号(任务面是真实工作发生地),事件表已停写仅保留维度,
|
||||
/// updated_at 兜底。供前端「最近活跃排序」展示与 system prompt 项目清单排序。
|
||||
///
|
||||
/// Serialize 供 IPC 层直接序列化回前端(serde 字段名 snake_case,对齐 ProjectRecord)。
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
@@ -243,29 +243,35 @@ impl ProjectRepo {
|
||||
.map_err(storage_err)?
|
||||
}
|
||||
|
||||
/// 列出未删除项目,**按「最近活跃」排序**(LEFT JOIN project_events 取最新事件时间,
|
||||
/// COALESCE 回退 updated_at)。
|
||||
/// 列出未删除项目,**按「最近活跃」排序**(三源取大:任务活跃为主信号)。
|
||||
///
|
||||
/// 业务语义:项目「最近活跃」应反映业务事件(任务/灵感/状态推进),而非 projects.updated_at
|
||||
/// (后者随元信息修改如改 description/path 也会刷新,不反映真实业务活跃)。本方法通过子查询
|
||||
/// 取每个项目 project_events 最新 created_at,无事件项目回退 updated_at,排序列统一可比。
|
||||
/// 业务语义:last_active_at = MAX(tasks.updated_at 最新值, project_events 最新 created_at,
|
||||
/// projects.updated_at)。**任务活跃为主信号**——ai-chat 会话/任务面是真实工作发生地,
|
||||
/// 任务停更即项目停更;project_events 已停写(现网空表,保留维度向后兼容);
|
||||
/// projects.updated_at 仅元信息修改(改 description/path 也会刷新,不反映真实业务活跃),
|
||||
/// 仅作兜底。无任务无事件的项目回退 updated_at,排序列统一可比。
|
||||
///
|
||||
/// 子查询而非 JOIN:project_events 每项目可能 0..N 条,JOIN 会展开需 DISTINCT,子查询
|
||||
/// `(SELECT MAX(created_at) FROM project_events WHERE project_id = projects.id)` 每行一次
|
||||
/// 聚合,语义清晰无笛卡尔积风险。单用户桌面应用项目数小,无性能压力。
|
||||
/// 子查询而非 JOIN:tasks/project_events 每项目可能 0..N 条,JOIN 会展开需 DISTINCT,
|
||||
/// 标量子查询每行一次聚合,语义清晰无笛卡尔积风险(SQLite 多参 MAX 为标量取大,
|
||||
/// IFNULL 兜空子查询 NULL)。单用户桌面应用项目数小,无性能压力。
|
||||
///
|
||||
/// 返回 `ProjectActivityRecord`(ProjectRecord + last_active_at 字段),供前端排序展示。
|
||||
/// 返回 `ProjectActivityRecord`(ProjectRecord + last_active_at 字段),供前端排序展示
|
||||
/// 与 system prompt「当前项目」清单(build_context_lists)按活跃度排序。
|
||||
pub async fn list_active_with_activity(&self) -> Result<Vec<ProjectActivityRecord>> {
|
||||
let conn = self.conn.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let guard = conn.blocking_lock();
|
||||
// COALESCE(子查询最新事件, projects.updated_at):无事件项目回退 updated_at,
|
||||
// 保证所有项目有可比活跃时间。ORDER BY 该列 DESC,同时间 created_at DESC 兜底稳定。
|
||||
// 三源取大(SQLite 多参 MAX=标量取大,IFNULL 兜空子查询):任务活跃为主信号,
|
||||
// 事件表已停写仅保留维度,updated_at 兜底。ORDER BY 该列 DESC,同时间 created_at DESC
|
||||
// 兜底稳定。
|
||||
let mut stmt = guard
|
||||
.prepare(
|
||||
"SELECT id, name, description, status, idea_id, path, stack, archived, created_at, updated_at, \
|
||||
COALESCE((SELECT MAX(created_at) FROM project_events WHERE project_id = projects.id), \
|
||||
updated_at) AS last_active_at \
|
||||
MAX(\
|
||||
IFNULL((SELECT MAX(updated_at) FROM tasks WHERE project_id = projects.id AND deleted_at IS NULL), 0), \
|
||||
IFNULL((SELECT MAX(created_at) FROM project_events WHERE project_id = projects.id), 0), \
|
||||
updated_at\
|
||||
) AS last_active_at \
|
||||
FROM projects WHERE deleted_at IS NULL AND archived = 0 \
|
||||
ORDER BY last_active_at DESC, created_at DESC",
|
||||
)
|
||||
@@ -840,4 +846,62 @@ mod tests {
|
||||
assert_eq!(after.name, "原项目", "回收站项目内容不应被改写");
|
||||
assert_eq!(after.updated_at, current.updated_at, "updated_at 不应抖动");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_active_with_activity_orders_by_task_activity_over_created_at() {
|
||||
// 回归(事故形状):项目 A created_at 较晚(创建序排前)但无任务/停更;项目 B
|
||||
// created_at 较早但有一条 tasks.updated_at 最新 → 活跃序 B 排 A 前
|
||||
// (任务活跃为主信号,治创建序误导 AI 把停摆项目当最高优先锚点)。
|
||||
use crate::crud::task_repo::TaskRepo;
|
||||
use crate::models::TaskRecord;
|
||||
use df_types::types::TaskStatus;
|
||||
|
||||
let db = Database::open_in_memory().await.expect("open_in_memory");
|
||||
let projects = ProjectRepo::new(&db);
|
||||
let tasks = TaskRepo::new(&db);
|
||||
|
||||
// B 先建(早),A 后建(晚)——创建序会排 A 前
|
||||
let mut early = prec("pb", "早建但活跃");
|
||||
early.created_at = "1700000000000".to_string();
|
||||
early.updated_at = "1700000000000".to_string();
|
||||
let mut late = prec("pa", "晚建但停更");
|
||||
late.created_at = "1700000010000".to_string();
|
||||
late.updated_at = "1700000010000".to_string();
|
||||
projects.insert(early).await.unwrap();
|
||||
projects.insert(late).await.unwrap();
|
||||
|
||||
// B 挂一条最新任务;A 无任务 → B 活跃时间取任务 updated_at,A 回退自身 updated_at
|
||||
let task = TaskRecord {
|
||||
id: "tb".to_string(),
|
||||
project_id: "pb".to_string(),
|
||||
title: "B 的任务".to_string(),
|
||||
description: String::new(),
|
||||
status: TaskStatus::InProgress,
|
||||
priority: 0,
|
||||
branch_name: None,
|
||||
assignee: None,
|
||||
workflow_def_id: None,
|
||||
base_branch: None,
|
||||
review_rounds: 0,
|
||||
output_json: None,
|
||||
idea_id: None,
|
||||
queue: "todo".to_string(),
|
||||
parent_id: None,
|
||||
content_json: None,
|
||||
module_id: None,
|
||||
archived: false,
|
||||
created_at: "1700000000000".to_string(),
|
||||
updated_at: "1790000000000".to_string(),
|
||||
};
|
||||
tasks.insert(task).await.unwrap();
|
||||
|
||||
let listed = projects.list_active_with_activity().await.unwrap();
|
||||
assert_eq!(listed.len(), 2);
|
||||
assert_eq!(listed[0].record.id, "pb", "任务活跃最新的早建项目应排前");
|
||||
assert_eq!(listed[1].record.id, "pa", "无任务的晚建项目应排后");
|
||||
assert_eq!(
|
||||
listed[0].last_active_at, "1790000000000",
|
||||
"活跃时间应取该项目任务 updated_at 最新值"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# ai-chat 上下文管理与信息组织·完善设计(2026-10-18)
|
||||
|
||||
> 用户令:ai-chat agent 上下文管理/信息组织开发完善;回复别太口水话(2026-10-18)。
|
||||
> 证据输入(问题全量论证在彼,此处只引编号不重复):`temp/深查-aichat对话质量复测-2026-10-17.md`(E1-E13)、`temp/深查-aichat信息UX-2026-10-17.md`(F1-F6)。
|
||||
> 现状判定:10-04 三大病(上下文失控/反复压缩/终局缺失)基本治愈;残量集中在**恢复链污染、终局态半闭环、存量脏数据、信息可达性、输出纪律**五个结构性面。
|
||||
|
||||
## 一、信息流模型与缺口定位
|
||||
|
||||
链路:`发起(直发/inject) → 目标提取(pinned_goals) → 上下文组装(system+摘要+近期) → 执行循环 → 压缩(view/cache) → 恢复(recovery) → 投影(轮桶/轨迹卡) → 呈现(桌面/飞书)`
|
||||
|
||||
| 缺口 | 根因(结构性,非散点) | 归并的散点 |
|
||||
|---|---|---|
|
||||
| **G-A 恢复链身份未建模** | 恢复消息无类型标记,兼具「系统信号」与「用户输入」双重身份,被目标提取源再次吸收 | E1 套娃、E3 二次恢复、看板 649 行恢复目标完整性守卫 |
|
||||
| **G-B 终局态半闭环** | boundary_json/loop_state 字段已建、写入闭环未建(填充率 0) | P2-5、E3 竞态窗口 |
|
||||
| **G-C 写入不保数据语义** | 写入方各自为政,全量重写/双写不保留原义 | E11 created_at 重写污染 1750 条、E5 存量目标不迁移、E12 双写 |
|
||||
| **G-D 信息可达性瓶颈** | 呈现层硬上限+折叠体内不可见 | F4-1 会话 50 上限(实测 115 条已击穿)、F1-3+F3-2 注入降级藏审批、F6-1 |
|
||||
| **G-E 输出纪律缺失** | 聚焦准则管「答什么」,不管「怎么答」——主提示词无回复风格条款 | 用户口水话反馈(本次令);摘要提示词已有该纪律可对齐 |
|
||||
| **G-F 阴性结论无守卫** | 工具 0 命中被当事实断言,无复核引导 | E6 假阴性 3 轮错判链 |
|
||||
|
||||
## 二、修复批次(领单视角,M1 先行)
|
||||
|
||||
### M1 · P1 上下文正确性
|
||||
1. **E1+E3 恢复链治本(G-A)**:恢复消息加 source 标记(与看板 961② inject 标记同基建,复用 V52 source 字段);build_recovery_message 过滤 `[系统恢复]` 前缀目标;目标写入侧拒收同前缀。防二次恢复:快照全部目标=completed 时短路,或恢复后 N 分钟窗口禁重复。
|
||||
2. **E11 created_at 保义(G-C)**:message_repo.rs:285 全量重写保留原 created_at(records 读取带出原值回写)。
|
||||
3. **E6 阴性存疑(G-F)**:search_files/grep 0 命中时结果强制附「阴性存疑,建议复核路径/glob」标记(seq 1549 hint 雏形转正)。
|
||||
4. **E4 跑题换装验证**:三源活跃度排序已在树(第五十三段),换装后重放 6a5a3e04 seq1802 场景验证。
|
||||
|
||||
### M2 · P2 上下文域
|
||||
5. **E5 存量目标一次性迁移(G-C)**:active 目标命中「执行/搜索/查看+工具参数」形态或 `[系统恢复]`/`[补充指令]` 前缀 → 降级为非目标或重取首条任务消息。
|
||||
6. **E2 压缩降级透出**:压缩失败兜底时前端状态条「上下文已降级」,禁静默。
|
||||
7. **E13 超时连败收敛**:同命令超时连败 N 次转「换方案/问用户」分支(与看板 B5d 退避策略同族,合并实施)。
|
||||
8. **P2-5 终局闭环(G-B)**:停靠/终局时填充 boundary_json/loop_state,不只落 status。
|
||||
|
||||
### M3 · P2/P3 信息组织域
|
||||
9. **F4-1 会话可达性(G-D)**:列表 offset 游标分页+侧栏「加载更多」;搜索走后端 LIKE(title+消息内容)。
|
||||
10. **F5-1+F5-2 飞书审批闭环(同根一改双收)**:决议词表归一(trim/剥标点/同义词,复用 normalize_halfwidth)+ 订阅 AiToolCallCompleted 推终态卡;pending 为空时决议回「已失效」提示而非静默放行。
|
||||
11. **F1-3+F3-2 折叠体可达(G-D,同根)**:executing 判定改「桶内存在 running/pending 工具」;scrollToFirstPending 前按 data-trace-key 预展开含 pending 的轨迹卡。
|
||||
|
||||
### M4 · 输出纪律+UX 小批
|
||||
12. **G-E 提示词输出纪律**:system_prompt_parts 行为准则追加「回复风格」段——结论先行直接给动作/结果;省略复述用户问题、客套开场、总结性收尾;要点优先于段落;用户没问的不展开。中英双语同步+测试断言(对齐 prompt.rs 既有测试范式)。注意别过度约束:需要解释时照常解释,反的是空话不是内容。
|
||||
13. **UX 确定性小批**:F1-1 i18n 补键 / F1-2+F3-1 主题 token 化 / F2-1 aria-label / F4-2 loaded 标志 / F6-2+F6-3 Esc 关闭 / 看板尾部队列带图项标记(10-18 残留)。
|
||||
|
||||
## 三、验收口径
|
||||
|
||||
- **复测脚本复跑**(复用 `temp/复测-aichat质量-1017/` 脚本,timestamp 列口径):恢复消息套娃=0、created_at 污染增量=0、boundary_json 填充率>0(新停靠会话 100%)。
|
||||
- **可达性**:115 条活跃会话全量可从侧栏到达;审批卡在任何折叠形态下 scrollToFirstPending 均可见。
|
||||
- **输出纪律**:3 个真实会话抽查,开场复述/空收尾/无信息客套=0;结论仍在首屏。
|
||||
- 每批销账附验收命令输出(G4 惯例)。
|
||||
@@ -0,0 +1,53 @@
|
||||
# 上下文管理对标 u-claw 与大批量并行差距分析(2026-10-19)
|
||||
|
||||
> 用户令(2026-10-18 飞书):①大批量 AI 任务调度/多会话多任务并行是未来常态核心场景;②战略目标=DevFlow 部署 Linux 替代 u-claw+Claude Code(CC 效率不够高、资源消耗太大);③第一门槛=上下文管理三命题:丢记忆、历史信息召回、高效利用 token;④方法=学习 u-claw 历史提交记录补 devflow 场景不足。
|
||||
|
||||
## 一、u-claw 上下文管理能力画像(源自主仓 6 条相关提交,核心是 86e9216)
|
||||
|
||||
| # | 能力 | u-claw 实现 | 要点 |
|
||||
|---|---|---|---|
|
||||
| 1 | **token 水位判据** | 140K≈200K 窗口 70% 主判据(可配),体积判据降兜底 | 治「换代过早」:350KB 体积≈真实水位 20-35%,体积判据致 23 代/日→水位判据 <5/日 |
|
||||
| 2 | **usage 真值采集** | 读流解析 message.usage(input+cache_read+cache_creation),失败静默 0 | 水位判据的数据底座 |
|
||||
| 3 | **大内容外置纪律** | system prompt 处理规则:大结论写盘 out/,回复只给路径+3 行结论 | 治上下文滚雪球(attach/ 86 文件 25MB 实锤) |
|
||||
| 4 | **换代通知推送** | rollover 等会话层事件经渠道真推送(非仅日志) | 用户对会话滚动有感知 |
|
||||
| 5 | **/history 归档检索** | 无参列最近 10 代,关键词 grep summary | 跨代记忆召回入口 |
|
||||
| 6 | **归档检索指引** | sopHint 注明 jsonl 字段与 grep→读 summary 操作路径 | 让 AI 自己会查历史 |
|
||||
|
||||
另:0a4f8dd 重上下文估算(防图片堆积)、a3f28dc 群聊上下文增量注入(按决策价值治理进度卡)。
|
||||
|
||||
## 二、devflow 现状对照(三命题 × 已治/缺口)
|
||||
|
||||
### 命题 1:丢记忆
|
||||
- ✅ 已治:目标语义重构(用户任务原文入 pinned_goals)、恢复链快照([系统恢复]/[补充指令] 产物双侧过滤,10-18 批)、压缩摘要四段式(意图/决策/文件/约束+失败事实保留)、E2 降级透出(10-18)
|
||||
- ❌ 缺口:**boundary/loop_state 填充率 0**(终局态建模半闭环)——「代」的显式语义缺失,会话边界靠消息流推断
|
||||
|
||||
### 命题 2:历史信息召回
|
||||
- ✅ 已治:单会话内压缩可召回(archive jsonl+召回句柄行)、知识路标投影进系统提示词
|
||||
- ❌ 缺口:**跨会话检索无入口**(u-claw /history 等价物缺失)——「上次那个任务怎么弄的」只能靠人翻侧栏;消息全文搜索未做(F4-1 只做了标题+列表分页)
|
||||
|
||||
### 命题 3:高效利用 token
|
||||
- ✅ 已治:压缩 memoization+决策冻结(10-04 病②治愈)、尾部追加摘要保前缀缓存、E13 超时连败收敛
|
||||
- ❌ 缺口:
|
||||
- **usage 真值采集未落地**(6 月 P1 敲定至今暂缓;cache_hit≈0% 说明 cache 口径有列无真值)——水位判据缺数据底座
|
||||
- **压缩触发判据待查**:压缩/请求比 4.8 偏频,疑体积/轮次判据过敏感(对标 u-claw 病灶同型)
|
||||
- **大内容外置纪律缺失**:工具输出有 truncate,但「大结论写盘+回复给路径」没有
|
||||
|
||||
### 大批量并行新命题(u-claw 亦未解,devflow 需原创)
|
||||
- 多会话同时压缩互不感知(各自预算独立,全局 token 消耗无视图)
|
||||
- 并行任务的信息投影(侧栏/仪表盘聚合 N 个会话的进行态)
|
||||
- 调度面:优先级/抢占/停靠恢复已有底座(TaskBoundary/parked),缺**全局调度器**视角
|
||||
|
||||
## 三、补差优先级(P0→P2)
|
||||
|
||||
| 级 | 项 | 移植来源 | 落点 |
|
||||
|---|---|---|---|
|
||||
| **P0** | usage 真值采集(stream_options.include_usage 三口径) | u-claw #2 | 6 月 P1 设计直接复活;先有数据再谈判据 |
|
||||
| **P0** | 压缩触发改 token 水位主判据(≈窗口 70%,体积兜底) | u-claw #1 | maybe_auto_compress 判据重构,依赖上项 |
|
||||
| **P1** | 跨会话归档检索:/history 等价(关键词搜消息全文+摘要) | u-claw #5/#6 | ai_messages 全文索引(FTS5 或 LIKE 起步);检索指令+AI 检索指引 |
|
||||
| **P1** | boundary/loop_state 写入闭环(代语义显式化) | — | 停靠/终局时填充;换代通知推送(u-claw #4 同款) |
|
||||
| **P2** | 大内容外置纪律(system prompt 处理规则+out/ 目录约定) | u-claw #3 | prompt.rs 处理规则段+workspace 目录约定 |
|
||||
| **P2** | 并行资源治理:全局 token 预算视图+多会话压缩协防 | 原创 | 调度器域,与 Linux 化路线(看板 10-18 远程容器方向)合流设计 |
|
||||
|
||||
## 四、与 Linux 化战略的衔接
|
||||
|
||||
上下文管理是第一门槛(用户拍板),Linux 化是最终形态。依赖链:**usage 真值 → 水位判据 → 代语义+归档检索 → 并行调度治理 → server 化无头运行**。前三步在现有 Tauri 架构内即可推进(P0 两项纯 Rust 域),后两步与远程容器/df-tunnel 线合流。建议节奏:P0 两项作下一批(devflow agent 领单),P1 随后,P2 与 Linux 化立项合并设计。
|
||||
@@ -0,0 +1,132 @@
|
||||
# DevFlow 布局样式大重构设计(2026-10-18)
|
||||
|
||||
> 依据:用户令「布局样式大重构,参考 D:\Downloads\u-agent」+「每页样式 DRY 提取统一定义」
|
||||
> 输入:u-agent设计系统勘察-2026-10-18.md · 样式走查-1018/报告-布局全局审计.md · 报告-配色全局审计.md
|
||||
> 原则:DRY 单一真值 · token 化 · 高密度(u-agent 13px 范式)· 双主题保留 · 紫 accent 品牌保留 · 视觉回归可控(dev 模式实时预览)
|
||||
|
||||
## 0. 现状诊断(三份勘察合并)
|
||||
|
||||
| 维度 | 现状 | u-agent 基准 | 差距 |
|
||||
|---|---|---|---|
|
||||
| 基准字号 | html 14px,aichat 已降 9-13,views 仍 11-14 | 13px 全局 | 功能页粗一档,密度断层 |
|
||||
| 页头 | 三套并存(aichat 46px / Dashboard 18px 标题 / 功能页 24px h1 无固定高) | 46px 定高单行 | 全站统一为紧凑单行 |
|
||||
| 侧栏 | 192px | 250-280px | 偏窄,功能页导航拥挤 |
|
||||
| 按钮 | .btn 双基类分叉(global 34px vs settings 30px)+ 图标钮三档 | .cbtn 单基类 | 合一 30px |
|
||||
| 徽章/tag | 圆角 3/4/6/8/10 五档并存;.df-tag 3px 字面量 | 小标签小圆角一档 | 收敛一档入 token |
|
||||
| 圆角 token | 覆盖 75.5%,9 处 var 回退值写错(静默降档) | — | 修回退+字面量 97 处归 token |
|
||||
| 间距 | 76.7% 收敛,7px×8/82px 手算对齐等离群 | 4px 刻度 | 离群归位+魔法数 token 化 |
|
||||
| 字号 | 半像素 24 处(10.5/11.5/12.5)+17px 孤值 | 纯整数谱 | 归整 |
|
||||
| 输入框 | 三档并存(21-22 / 26-27 / 30) | 30px 单档为主 | 行内搜索统一 26px 档 |
|
||||
| 小节头 | 各页自造 | 9-10px uppercase mono 字距 统一范式 | 抽 .df-sec-h |
|
||||
| 公共技法 | 无 | hairline 网格 kv 卡 / 发丝线行 / 染色两档 | 引入公共类 |
|
||||
|
||||
## 1. Token 层扩展(global.css :root,单一真值)
|
||||
|
||||
### 1.1 新增 token
|
||||
|
||||
```css
|
||||
/* 字号谱(纯整数,对齐 u-agent) */
|
||||
--df-fs-micro: 9px; /* 小节头/tag/计数 */
|
||||
--df-fs-meta: 10px; /* 徽章/元数据 */
|
||||
--df-fs-aux: 11px; /* 辅助文字/列表次级 */
|
||||
--df-fs-ctrl: 12px; /* 控件文字/小按钮 */
|
||||
--df-fs-body: 13px; /* 正文基准 */
|
||||
--df-fs-title: 16px; /* 页头标题 */
|
||||
|
||||
/* 控件高度档 */
|
||||
--df-h-btn: 30px; /* 主按钮(.btn 合一目标) */
|
||||
--df-h-input: 26px; /* 行内输入/搜索 */
|
||||
--df-h-modal-input: 30px;
|
||||
--df-h-icon-btn: 26px; /* 图标钮统一档(22/26/28 收敛) */
|
||||
|
||||
/* 微内距暗刻度(chip/badge 族) */
|
||||
--df-pad-chip: 1px 6px;
|
||||
--df-pad-badge: 3px 8px;
|
||||
|
||||
/* 图标槽 */
|
||||
--df-icon-gutter: 42px; /* ToolCard 图标槽(38/42 魔法数归一) */
|
||||
|
||||
/* 染色两档(语义色背景/边框透明度统一,双主题各配) */
|
||||
/* 由 --df-*-bg(12% 底)+ 新增 --df-*-bd(30% 边)承担,消除散落 rgba 字面量 */
|
||||
--df-success-bd / --df-warning-bd / --df-danger-bd / --df-info-bd / --df-accent-bd
|
||||
```
|
||||
|
||||
### 1.2 修正既有错误
|
||||
- 9 处 var 回退值写错(lg 8→10 / md 6→8 / xs 3→2):**删回退值**(token 必注入,回退是静默降档源)
|
||||
- .df-tag 圆角 3px 字面量 → var(--df-radius-xs)
|
||||
- body 基准 14px → 13px(line-height 1.5 保持);aichat 已对齐,功能页随页头波次跟进
|
||||
|
||||
## 2. 公共组件层(global.css/components.css 单一来源)
|
||||
|
||||
| 公共类 | 来源 | 定义去向 |
|
||||
|---|---|---|
|
||||
| `.btn` 族 | global+settings 双基类合一 30px/8px 16px/13px | global.css 唯一定义,settings.css 删副本 |
|
||||
| `.df-sec-h` | u-agent 小节头范式(10px uppercase letter-spacing .5px mono tx3) | global.css 新增 |
|
||||
| `.df-kv` / `.df-kv-i/k/v` | hairline 网格档案卡(gap:1px+bd 背景) | components.css 新增 |
|
||||
| `.df-row` | 发丝线行(border-bottom+last-child none) | components.css 新增 |
|
||||
| `.df-note` | 通知条(info/warning/danger 染色) | components.css 新增 |
|
||||
| `.df-pill` | 状态胶囊(全圆+染色底) | components.css 新增 |
|
||||
| `.df-tab` / `.df-tab--active` | 下划线 tab(2px accent 底线+计数 chip) | components.css 新增 |
|
||||
| 既有 `.df-dot/.df-badge/.df-tag/.df-mono/.df-hstat` | 第五十四段已注入 | 保留,随 1.2 修圆角 |
|
||||
|
||||
## 3. 页面适配波(DRY 提取:各页 scoped 重复样式→公共类)
|
||||
|
||||
- **页头统一**:功能页 8 页 + Dashboard 全部改 `.page-header` 紧凑单行(h1 16px/500 + 定高 46px 等价 padding + header-actions gap 8px),删各页自造页头样式
|
||||
- **侧栏 192→220px**(AppSidebar 一处)
|
||||
- **输入框**:GitChanges/Provider 行内 21-22px → var(--df-h-input)
|
||||
- **列表/详情页**:status-tag/status-* 徽章族(components.css 已有 13 个状态色)染边补齐 + 圆角统一;Details 页 kv 区改 .df-kv;tab 行改 .df-tab
|
||||
- **settings 族**:settings.css .btn 副本删除并轨;面板内重复 card/row 样式提取
|
||||
- **ai 族**(已对齐 workbench):仅扫尾——圆角字面量 9px 气泡入注释锚定、7px 代码块归 token、tag 圆角收敛
|
||||
- **离群修复**:7px 间距→6/8、ProviderPanel 82px 手算对齐改结构、26px 图标位 calc、FilePreview outline-name 补 nowrap(确定 bug)、定宽输入/浮层补 max-width
|
||||
|
||||
## 4. 实施波次(文件零交集,逐波门禁 vue-tsc + 目检)
|
||||
|
||||
| 波 | 内容 | 文件面 |
|
||||
|---|---|---|
|
||||
| R0 底座 | token 扩展+回退修正+公共类新增+.btn 合一+body 13px | styles/global.css + components.css + settings/settings.css |
|
||||
| R1 功能页族 | Projects/Tasks/Ideas/Knowledge/AuditLog 页头+密度+tag 收敛 | views/*.vue(5 页可再拆并行) |
|
||||
| R2 详情页族 | ProjectDetail/TaskDetail/IdeaDetail(kv/tab/徽章/页头) | 3 个 Detail.vue 可并行 |
|
||||
| R3 设置族 | settings.css 并轨+面板 DRY 提取 | components/settings/* |
|
||||
| R4 ai 扫尾+杂项 | 圆角/token 扫尾+离群修复+FilePreview bug | components/ai/* + 杂项 |
|
||||
| R5 配色收口 | 按配色审计报告优先级表 10 项实施(报告 temp/样式走查-1018/报告-配色全局审计.md):①幽灵 token 清零(含 --df-bg-secondary 等 6 处声明失效真 bug)②.status-* 徽章系 token 三件套③白叠层 64 处入 token(--df-hover/--df-zebra 浅色覆写黑叠层)④回退值 111 处全删⑤global.css 边框 rgba 改 color-mix⑥--df-neutral-bg⑦views 族 rgba 清零⑧--df-shadow-sm/md⑨alpha 收敛⑩豁免注释 | 按报告分布;R5 先补 token(叠层/中性/阴影)再批量替换 |
|
||||
|
||||
每波:前台同步代理实施 → 主代理 diff 核查 + vue-tsc → dev 窗口目检(用户可实时看)。R0 先行(其他波依赖新 token/类),R1-R4 在 R0 后并行。
|
||||
|
||||
## 5. 拍板点(按推荐值先行,用户可回改)
|
||||
|
||||
1. **基准字号 13px**(功能页降一档,信息密度对齐 u-agent;若觉偏小回 14 仅改一处 token 层 body 声明)
|
||||
2. **侧栏 220px**(192→220 折中,非 250)
|
||||
3. **页头 16px 标题+紧凑单行**(废 24px 大标题)
|
||||
4. **按钮 30px 主档**(对齐 settings 既有 30px 而非 global 34px)
|
||||
5. tag/badge 圆角统一 xs(2px)/sm(4px) 档
|
||||
|
||||
## 6. 单文件拆分轨([补4],与样式波错峰)
|
||||
|
||||
行数实测(2026-10-18):MessageList 3297 / ProjectDetail 1750 / TopBar 1700 / Tasks 1540 / ChatInput 1503 / IdeaDetail 1228 / ConversationSidebar 1226 / TaskDetail 1160 / AiChat 1145 / FilePreview 1144 / ProviderPanel 964 / FileExplorer 932 / ToolResultBody 895。
|
||||
|
||||
**拆分纪律**:
|
||||
- 纯拆分不改行为——样式/逻辑原样搬迁,验收=vue-tsc 0 + 构建过 + dev 窗口目检无视觉回归
|
||||
- 拆分边界按「区块自治」(模板区块+配套样式+相关逻辑成组),优先抽展示型子组件;共享状态经 props/emits 或既有 composable,不新造 store
|
||||
- **与样式波互斥调度**:同一文件的样式适配与拆分不并行(样式先行,拆分在后——拆完再改样式要重新定位锚点)
|
||||
- 拆分批次(样式波收口后启动,每批文件零交集):
|
||||
- C1 ai 族:MessageList(3297→消息项/工具卡区/折叠条带等子件) → ChatInput(1503) → TopBar(1700)
|
||||
- C2 项目族:ProjectDetail(1750) → FilePreview(1144) → FileExplorer(932)
|
||||
- C3 任务/想法族:Tasks(1540) → TaskDetail(1160) → IdeaDetail(1228)
|
||||
- C4 侧栏+设置族:ConversationSidebar(1226) → AiChat(1145) → ProviderPanel(964) → ToolResultBody(895)
|
||||
- 每文件拆分目标:主文件 ≤600 行,子件单一职责
|
||||
|
||||
## 7. 整洁性轨(用户令 2026-10-18:代码整洁性全量处理+样式代码统一抽取,[补1] 共享的样式才抽取)
|
||||
|
||||
探针实测(dead-style-scan.json / dup-style-scan.json,脚本在 temp/样式走查-1018/):
|
||||
- 死样式候选 368 处 / 56 文件(MessageList 34/ToolCard 25/TopBar 20/ActiveProjectsPanel 19 领衔);**假阳性规则**:Vue transition 生成类(xxx-enter/leave/from/to/active 由 `<transition name="xxx">` 隐式消费,非死)、动态拼接类(`'status-' + s`)、子组件透传类——删前须逐处验证
|
||||
- 跨文件共享重复规则 49 条;典型双轨:`.ai-toast-*`(AiChat/ApprovalPopup)与 `.toast-*`(Knowledge/Settings)同义共存;`.confirm-actions`×3;`@keyframes spin/shimmer` 10/3 文件各写一份
|
||||
|
||||
**底座已落**(主代理亲码 global.css):`.df-toast` 四色族+过渡 / `@keyframes df-spin`/`df-shimmer` / `.df-confirm-actions`+过渡 / `.df-diff-pre` 族。
|
||||
|
||||
**D 批分路**(R5 收口后启动,文件族零交集,每路两件事:本族死样式验证删除 + 本族共享类消费替换):
|
||||
- D-A ai 族+根组件(MessageList/ToolCard/TopBar/ConversationSidebar/ChatInput/ToolResultBody/AiChat/ToolCardList):死样式 100+ 处 + ai-toast 族消费 + spin/shimmer keyframes 消费 + .ai-tool-diff-pre 族并轨 .df-diff-pre
|
||||
- D-B views+project 族(Knowledge/ApprovalPopup/Settings/Projects/ProjectDetail/Tasks/AuditLog/FilePreview/FileExplorer/GitChanges/ProjectCard):死样式 100+ 处 + .toast-* 族消费 + confirm-actions 消费
|
||||
- D-C settings+layout+dashboard+knowledge 族(AdvancedSection/AllowedDirsPanel/UpdateBadge/ActiveProjectsPanel/KnowledgeDetail 等):死样式残余 + 确认弹层消费
|
||||
- D4 TS/模板整洁(随各路顺带):未用 import/变量(vue-tsc noUnusedLocals 级)、console.log 残留、死模板分支——纯删不改语义
|
||||
|
||||
**验收纪律**:每路 vue-tsc 0 + grep 证据(死样式删除数/共享类消费数);transition 类假阳性必须 grep `<transition name=` 确认后再删。
|
||||
@@ -0,0 +1,30 @@
|
||||
# 飞书通道 WS 假活:探活只告警不自愈
|
||||
|
||||
> 登记: AI-Ops 2026-10-11 22:15 · 来源: 用户 @ bot 零回应事故排查 · 实施归 devflow agent
|
||||
|
||||
## 现象
|
||||
|
||||
用户 20:07 后在飞书 @ bot 发消息,零回应。feishu-channel.log 尾部停在 20:07 「打包换装」watcher 终版,其后 2h+ 零「收到消息」事件——消息根本未达应用,非模型/会话层问题。
|
||||
|
||||
## 证据
|
||||
|
||||
- 日志: `~/AppData/Roaming/top.1216.devflow/feishu-channel.log`
|
||||
- 累计 90 条探活告警「660s 无任何事件且无在途会话(疑似假活,持续出现请重启应用重建连接)」,跨 10-05~10-11 多日分布,连接时好时坏
|
||||
- 时间线: 14:00 前持续告警 → 20:04-20:07 恢复(收到 4 条消息正常受理+终版) → 20:07 起再断,至 22:12 仍零入站,进程未重启(devflow.exe PID 14172 同前)
|
||||
- 应用本身健康: trace.log 持续输出, B5 引擎「🟢 健康,空闲」
|
||||
- 对照: u-claw 曾有同款(热重建不关旧连接致僵尸 WS,closeGraceful 须显式 Close),见 u-claw 记忆 uclaw-zombie-ws-connection
|
||||
|
||||
## 根因方向
|
||||
|
||||
WS 长连接假活: 探活任务已检测到「无事件+无在途」但仅打日志,无自动重建连接动作,恢复依赖新消息触发或人工重启。为何 20:04 能自愈一次、20:07 后不能,需读 SDK 连接层确认(是否依赖入站流量触发重连)。
|
||||
|
||||
## 修复建议
|
||||
|
||||
1. 探活告警连续 N 次(如 2 次,约 20 分钟)→ 主动断开并重建 WS 连接(显式 Close 旧连接防僵尸),重建结果写日志
|
||||
2. 重建失败退避重试,持续失败升级通知(桌面通知/卡片)
|
||||
3. 复核 90 条告警的历史分布,确认是否存在更早未被用户察觉的静默窗口
|
||||
|
||||
## 排除项
|
||||
|
||||
- 97「收到消息」vs 47「受理返回」差值: 新旧版本日志口径混杂(受理返回为后加日志),受理守卫拒绝仅 2 条且走旧「AI 正在生成中」路径,无消息丢失
|
||||
- watcher 终版无「回复」行: 新版投递走卡片原地更新(edit_card),非回复消息,属正常
|
||||
+39
-1
@@ -353,6 +353,11 @@
|
||||
### 附:F2 兜底前移(可选)
|
||||
- `ai_chat_stop` 的心跳 60s stale 判死+emit AiCompleted 兜底只在用户点停止时运行;可在 loop spawn 时自带一份,panic 死 loop 无需用户点停止也能收敛。
|
||||
|
||||
### 🔍 工具结果压缩·错误行洪泛缺陷(2026-10-15 发现,未修)
|
||||
- **现象**:`extract_key_info_inner` 的错误行保留策略无上限——结果里每个含 `error`/`panic`/`.rs:`/「失败」的行都全量保留并加 `[行 N]` 前缀,grep/rustc 类输出(恰是压缩的主要对象)错误行占多数时输出≥原文,压缩失效且无落盘句柄(`compressed.len() < content.len()` 门不过)。
|
||||
- **佐证**:`crates/df-ai/tests/context_offload.rs` 的 `non_read_file_large_result_also_gets_handle` 用 `src/foo.rs:N` 做夹具,先天必挂——该集成测试历来未被 `--lib` 门禁覆盖, until 2026-10-15 全量 workspace 门禁才暴露(夹具已改中性行修绿,生产行为未动)。
|
||||
- **修法方向**:错误行保留加封顶(如最多 N 条+「另有 M 条错误行省略」),超限走正常省略段;配套恢复信号行夹具的鉴别力测试。
|
||||
|
||||
# aichat 三路走查增量待办(2026-10-02 深夜)
|
||||
|
||||
> 来源:上下文管理批收口期 rev-backend/rev-frontend/rev-crates 三路走查(历三次会话重启后续跑完成)。**全文与批次归并建议见 `docs/05-代码审查/aichat三路走查报告-2026-10-02.md`**。以下为可执行登记,开工以现场源码为准。
|
||||
@@ -640,6 +645,11 @@
|
||||
|
||||
### B5 无人值守续作引擎(2026-10-06 用户实证"总停下确定性任务"的根治,挂机治理核心缺口)
|
||||
- [ ] **B5a 挂钟闸分任务定级**:确定性任务(看板任务/用户拍板项)挂钟闸放宽(如 120min)或按预估时长配置;闸到点改「检查点+续跑」(存进度不停工),仅非确定性/失控疑似才硬停靠。
|
||||
- [ ] **目标提取质量闸**(2026-10-12 目标丢失事故实锤:用户抱怨句「丢失 会话上下文了 找回目标」被注册成任务目标、「继续」单字成目标、半截命令「ssh-proxy upload --name i」以 active 驱动续跑):写入侧把关——短文本/纯沟通词/疑问句不入 goals,含参数的命令目标须完整形态;恢复侧放行前过同闸
|
||||
- [ ] **恢复消息递归套娃**(2026-10-12 实锤:重启恢复消息整段被当用户输入再提取,目标里嵌套上一次恢复全文,层层放大):恢复消息注入走旁路,不进目标提取源
|
||||
- [ ] **G2 停滞判定叠输出变化维度**(2026-10-12 OSS迁移会话实证:轮询 grep DONE 同参数连发5次被防卡死拦截,但输出 skip 8000→8500 在变=有进展硬证据):样本键叠加输出内容哈希,输出仍在变不算停滞(真死循环输出也不变,非放松防线);stall_detector.rs 签名族
|
||||
- [ ] **恢复目标完整性守卫**(同上实证:残缺目标「ssh-proxy upload --name i」进快照被恢复引导放行,AI 强行续跑):R4 恢复消息对参数明显不完整的目标标注「须先向用户确认参数」;偏产品语义,与快照线同族
|
||||
- [ ] **压缩失败路径召回句柄核查**(同上实证:压缩失败兜底摘要+archive jsonl 归档正常,但截断参数仍丢失):核查④压缩可召回句柄行在压缩失败路径是否注入/AI 是否被引导召回;与知识路标层同族问题
|
||||
- [ ] **B5b 停靠自动续作**:停靠/parked/批收敛后自动回读看板——有 parked 可续任务→自动 resume;有未完批次→自动领单续作;真需决策才停(附决策项)。无人值守的"永动"机制,CLAUDE.md 领单纪律的运行时化。
|
||||
- [ ] **B5c 审批无人值守策略**:挂机中审批拦截按用户预设策略处置(低风险自动批+留痕,高风险停下+通知),策略 yml 可配。验收:挂机 4h 连续推进模拟(确定性批次队列),零人工干预零停顿;超大任务挂钟闸到点走检查点续跑。
|
||||
|
||||
@@ -664,7 +674,7 @@
|
||||
- **推广路线**:devflow v1 验证 → 模板提炼进技能分发站 → u-claw 九实例各挂看板 → 多 bot 协作总线(N²→N+1) → 人-bot 协作(写板即派工)。
|
||||
- **前置约束**:仅异步任务适用;hook 随模板强制安装;多实例并发领单=[→]原子改写+git push 冲突天然仲裁。
|
||||
- [ ] 32 泛化落地:devflow v1 跑通后,模板三件套提炼进技能分发站(skill 形态),九实例试点 2-3 个(先 AI-Ops 自领+devflow,跑一周数据再扩)。
|
||||
33. [ ] **devflow.md MVP(十四节多角色论证定稿)**:①启动读取 devflow.md(规范纪律+领单两分区)+CLAUDE.md 并入 build_runtime_prompt 第七段,内容按相关性裁剪禁全量 ②警示区走 insert 消息范式 ③状态不文件化(DB 直注+H3 git 实测) ④知识投影补相关性元数据。砍除运行中文件刷新。v2+:agent 自主维护/知识投影动态化/跨会话投影。验收:启动双文件并入生效;警示事件下一轮可见;token 零缓存击穿。
|
||||
33. [x] **devflow.md MVP(十四节多角色论证定稿)** ✅已实施(2026-10-12:devflow_md.rs 投影模块+第七段稳定尾追加双路径(主会话 build_runtime_prompt+子代理 spawn_agent 同源)/分区裁剪(纪律4000+领单2000+CLAUDE 4000/总6000)/conv_id 键会话级缓存零缓存击穿/缺失零回归;881 测试绿含 9 新):①启动读取 devflow.md(规范纪律+领单两分区)+CLAUDE.md 并入 build_runtime_prompt 第七段,内容按相关性裁剪禁全量 ②警示区走 insert 消息范式 ③状态不文件化(DB 直注+H3 git 实测) ④知识投影补相关性元数据。砍除运行中文件刷新。v2+:agent 自主维护/知识投影动态化/跨会话投影。验收:启动双文件并入生效;警示事件下一轮可见;token 零缓存击穿。
|
||||
|
||||
### 看板完整性防护(2026-10-06 todo.md 截断事故:文件被重写为 12 行+脱离 git 跟踪,内容经 git HEAD+残版合并零丢失恢复)
|
||||
- [ ] **看板防护三件**:①条目数骤降告警——看板条目数单次变化 >50% 时视为异常(防静默截断),提交/重写前自检 ②看板修改一律原子写(tmp+rename)+保留前版快照(todo-快照-*.md 滚动一份) ③git add 覆盖检查——提交流程确认看板在跟踪列表(防选择性 add 遗漏致脱离跟踪)。根因:agent 提交/整理流程对 todo.md 组合失误(重写+跟踪移除),细节在其 transcript 不可见——机制防护优先于行为归因。
|
||||
@@ -746,3 +756,31 @@
|
||||
961. [~] **桌面轮次交互定位重定义(2026-10-11 用户拍板,补7 三条)**:①轨迹卡片收敛:除主回复气泡外交互收敛到一张「有动态+可折叠」的轨迹卡(现有轮次折叠类型),**修缺陷:正生成时卡片展开不了**;②轮次语义纠正:现「压缩后即新轮次」定位错——正确定义=**一次信息发起=一个任务轮次,中途补充信息(inject)仍属同一轮,全部完成后新发起才是新轮**;③轮次编号稳定化:现编号不稳定(刚是 5 一会下面又出现 1)——应固定为「该对话的第 1 轮/第 2 轮」持久编号(与消息 seq/轮边界锚点绑定,不随视图压缩/折叠漂移)。
|
||||
- ✅ **①已修(2026-10-11)**:执行中 step 卡支持点击展开(复用 expandedTraceIds,key 与完成态 trace 同构,执行中展开→完成转 trace 态不丢;展开区实时渲染该轮过程工具卡)。
|
||||
- **②③设计要点(实施前拍板)**:轮边界判定锚点从「压缩摘要」改为「用户发起消息」——发起=桌面直发/飞书入站的 user 消息,补充=inject_runtime_message 写入的消息(需来源标记,建议复用 V52 source:{channel:"inject"} 与发起区分,归属判定 O(1));轮号=conv 内第 N 条「发起消息」序(数据派生,天然稳定,不随压缩/视图漂移),轨迹卡头/导航条/进度徽标统一取该口径(单一真值来源)。涉及:轮桶分桶逻辑(MessageList genBucketItems 上游)+轮号计算函数收敛+inject 消息 source 标记。
|
||||
|
||||
# 产品方向定位:执行 agent 运行到远程容器(2026-10-18 用户口述,设计先行未实施)
|
||||
- **定位**:DevFlow 未来形态=执行 agent 跑在远程容器(本机只做控制面/交互面),对齐 u-claw 分身实例形态——桌面端发起任务→远程容器内 agent 全权执行→结果回传。收益:长任务不占本机/环境隔离/多实例并行/24h 无人值守天然成立。
|
||||
- **衔接存量**:df-tunnel/u-relay 线(v3 wire 协议+ws 隧道,已在树)正是传输底座;TaskBoundary 无人值守体系(边界内自主)是权限面底座;两者拼合即远程执行骨架。
|
||||
- **待设计问题**(立项时展开):远程执行体的工具面裁剪(本机路径语义如何映射)/媒体与文件存储归属(远程落盘 vs 回传)/审批与边界在远程侧的执行点/凭据注入方式/断线重连与会话恢复/多容器池调度。
|
||||
- **本条为方向登记,实施等用户令。**
|
||||
- [ ] 队列带图项零标记(2026-10-18 走查残留):队列行渲染在 AiChat.vue:81-115,带图队列项无图标记;与 F3-2(ToolCardList scrollToFirstPending 预展开)同批处理。
|
||||
|
||||
### 💡 2026-10-18 ai-chat 上下文管理与信息组织完善(设计已定,按批领单)
|
||||
> 用户令「上下文管理/信息组织开发完善+回复别太口水话」。蓝图:[02-架构设计/专项设计/ai-chat上下文管理与信息组织完善设计-2026-10-18.md](../02-架构设计/专项设计/ai-chat上下文管理与信息组织完善设计-2026-10-18.md);证据:temp/深查-aichat对话质量复测-2026-10-17.md(E系)+temp/深查-aichat信息UX-2026-10-17.md(F系)。M1 为 P1 先行,条目锚点/修法/验收全在设计文档,此处只列索引。
|
||||
- [x] M1-P1① 恢复链治本:恢复消息 source 标记+[系统恢复]目标双侧过滤+防二次恢复(E1/E3;与 961② 同基建,可并 649 行旧条销账)——✅ 验收:cargo test -p devflow --lib recovery **6 passed**(zero_nesting_with_polluted_goals/all_polluted_falls_back/drops_recovery_artifacts_idempotent 等);conversation.rs:415 双侧过滤+单点拦截在位
|
||||
- [x] M1-P1② message_repo 全量重写保留原 created_at(E11;污染存量 1750 条不回刷,止增量即可)——✅ 验收:cargo test -p df-storage **14 passed** 含 replace_conversation_preserves_created_at ok
|
||||
- [x] M1-P1③ search_files/grep 0 命中「阴性存疑」标记转正(E6)——✅ 22:11 AI-Ops 子代理补齐:file.rs negative_hit_hint 共享函数+grep/search_files 两处接入;验收:negative_hit_hint_states_doubt_and_scope ok
|
||||
- [~] M1-P1④ 跑题修复换装验证(E4;修复在树,换装后重放 6a5a3e04 seq1802 验证)——**已在工作区实施待验收**(prompt.rs list_active_with_activity 三源活跃度排序+指纹缓存对齐;验证方式:跑 dev 后重放场景)
|
||||
- [ ] M2 存量目标一次性迁移/压缩降级前端透出/超时连败收敛(并 B5d)/boundary_json+loop_state 写入闭环(E5/E2/E13/P2-5)
|
||||
- [ ] M3 会话 offset 分页+后端搜索/飞书审批决议词归一+终态卡/executing 桶内活性判定+审批预展开(F4-1/F5-1+2/F1-3+F3-2)
|
||||
- [x] M4-a 提示词回复风格纪律(反口水话,中英双语+测试断言)——✅ 22:11 AI-Ops 子代理补齐:prompt.rs 中英两版行为准则各加「回复风格/Response style」条款(结论先行/省客套复述收尾/要点优先/没问不展开/「省的是空话不是内容」);验收:system_prompt_zh/en_has_response_style_clause 2 passed(共 5 passed)
|
||||
- [ ] M4-b UX 小批(i18n 补键/token 化/aria/loaded/Esc/队列带图标记)——未动,留板
|
||||
- [x] **收尾令(用户 2026-10-18 21:41 飞书下达到 AI-Ops,转登记)**:M1 销账后——①按 G3 提交本批改动并 push origin main(推送令已拍板,限本批范围);②启动 dev 模式运行验证(重点验 M4 反口水话与 M1 恢复链);③完成信息经飞书推送用户。若 AI-Ops 监测到 M1 已销账而本条未执行,AI-Ops 代执行。——✅ 23:0x AI-Ops 执行完毕:四笔分组提交(05d0f89 上下文P1批/302c4bc 飞书闭环/25ec9cf 前端令牌批/fb83339 文档)已 push(3bb662f..fb83339);验收 cargo test 2281 passed 0 failed+vue-tsc EXIT 0;dev 已跑(vite:1420 HTTP 200);完成信息已飞书推送。
|
||||
|
||||
### 💡 2026-10-19 上下文管理对标 u-claw·大批量并行差距(AI-Ops 分析,待领单)
|
||||
> 用户战略令(10-18 飞书):DevFlow 上 Linux 替代 u-claw+CC,第一门槛=上下文管理三命题(丢记忆/历史召回/token 高效),大批量多会话并行是常态场景。详情:[02-架构设计/专项设计/上下文管理对标u-claw与大批量并行差距分析-2026-10-19.md](../02-架构设计/专项设计/上下文管理对标u-claw与大批量并行差距分析-2026-10-19.md)
|
||||
- [ ] P0-A usage 真值采集:stream_options.include_usage 三口径(input/cache_read/cache_creation),6 月 P1 设计复活(当时暂缓,结构层已回退干净)
|
||||
- [ ] P0-B 压缩触发改 token 水位主判据(≈窗口 70% 可配,体积兜底;u-claw 86e9216 同款,治压缩/请求比 4.8 偏频),依赖 P0-A
|
||||
- [ ] P1-A 跨会话归档检索(/history 等价):消息全文搜索(FTS5 或 LIKE 起步)+检索指令+AI 检索指引进 sop
|
||||
- [ ] P1-B boundary/loop_state 写入闭环(代语义显式化+换代通知推送)
|
||||
- [ ] P2-A 大内容外置纪律(大结论写盘 out/+回复给路径,system prompt 处理规则)
|
||||
- [ ] P2-B 并行资源治理(全局 token 预算视图/多会话压缩协防)——与 Linux 化/远程容器方向合流设计
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# 探测本机正在运行的 DevFlow 进程及其版本(只读)
|
||||
$p = Get-Process devflow -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty Path
|
||||
if ($p) {
|
||||
$v = (Get-Item $p).VersionInfo
|
||||
Write-Host "PATH=$p"
|
||||
Write-Host "FileVersion=$($v.FileVersion)"
|
||||
Write-Host "ProductVersion=$($v.ProductVersion)"
|
||||
} else {
|
||||
Write-Host "NO_DEVFLOW_PROCESS"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# 校验 updater 验签密钥配对(终版): 比对 keyid(KEYNUM 8字节) —— minisign 格式对齐
|
||||
# conf.pubkey blob(42B): SIGALG"Ed"[0..2] + KEYNUM[2..10] + PUBKEY[10..42]
|
||||
# 私钥文件 blob(116B): SIGALG"Rs"[0..2] + KDFALG[2..4] + CKSUM[4..12] + SALT[12..28] + OPS[28..36] + MEM[36..44] + KEYNUM[44..52] + SIG[52..116]
|
||||
$confPath = "E:\wk-lab\devflow\src-tauri\tauri.conf.json"
|
||||
$keyPath = Join-Path $env:USERPROFILE ".tauri\devflow.key"
|
||||
|
||||
# 1. conf 侧: 提取 pubkey → 解码 → 取 KEYNUM
|
||||
$raw = Get-Content $confPath -Raw
|
||||
if ($raw -match '"pubkey"\s*:\s*"([A-Za-z0-9+/=]{40,400})"') { $confPubB64 = $Matches[1] } else { Write-Host "CONF_PUBKEY_NOT_FOUND"; exit 1 }
|
||||
# conf.pubkey 是 base64(minisign .pub 文件文本),需二次解码取末行
|
||||
$confText = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($confPubB64))
|
||||
$pubLines = @($confText -split "`n" | Where-Object { $_.Trim() -and $_ -notmatch 'comment' } | ForEach-Object { $_.Trim() })
|
||||
if ($pubLines.Count -lt 1) { Write-Host "CONF_PUB_FORMAT_UNEXPECTED"; exit 1 }
|
||||
$confBlob = [Convert]::FromBase64String($pubLines[0])
|
||||
$confKeynum = ($confBlob[2..9] | ForEach-Object { $_.ToString("x2") }) -join ""
|
||||
Write-Host "conf keyid : $confKeynum (blob $($confBlob.Length)B)"
|
||||
|
||||
# 2. key 侧: 私钥文件 = 注释行 + 1 条 b64 blob(KEYNUM 未加密,明文可读)
|
||||
if (-not (Test-Path $keyPath)) { Write-Host "KEY_NOT_FOUND: $keyPath"; exit 1 }
|
||||
$b64Lines = @(Get-Content $keyPath | Where-Object { $_ -and $_ -notmatch 'comment' } | ForEach-Object { $_.Trim() })
|
||||
if ($b64Lines.Count -lt 1) { Write-Host "KEY_FORMAT_UNEXPECTED"; exit 1 }
|
||||
$secBlob = [Convert]::FromBase64String($b64Lines[0])
|
||||
$secKeynum = ($secBlob[44..51] | ForEach-Object { $_.ToString("x2") }) -join ""
|
||||
Write-Host "key keyid : $secKeynum (blob $($secBlob.Length)B)"
|
||||
|
||||
# 3. 配对判定
|
||||
if ($confKeynum -eq $secKeynum) {
|
||||
Write-Host "MATCH - updater 验签密钥配对正确(keyid $confKeynum), B3 安装验签可通过"
|
||||
exit 0
|
||||
} else {
|
||||
Write-Host "MISMATCH - tauri.conf.json 的 pubkey 与签名私钥不配对, B3 安装验签将失败!"
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
# 发布收尾:杀挂起脚本 -> 手动签名 0.1.3 -> latest.json -> 上传 -> 远端验证
|
||||
$ErrorActionPreference = "Stop"
|
||||
$repo = "E:\wk-lab\devflow"
|
||||
$nsis = "$repo\target\release\bundle\nsis"
|
||||
$exe = "$nsis\devflow_0.1.3_x64-setup.exe"
|
||||
$key = "$env:USERPROFILE\.tauri\devflow.key"
|
||||
$site = "suke-dev"
|
||||
$remoteDir = "/var/www/app-site/download/devflow"
|
||||
$baseUrl = "https://app.1216.top/download/devflow"
|
||||
$notes = "版本更新与自动升级全链路上线:设置页新增「关于」,支持应用内检查/下载/安装更新"
|
||||
|
||||
# 1. 杀挂起的发布脚本与构建残留
|
||||
Get-Process -Id 14328,2008,26208,28276,19412 -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Write-Host "[1/5] 挂起进程已清理"
|
||||
|
||||
# 2. 手动签名(key 文件内容经 env 传入——-k/ev 传路径会被当 base64 解码,报 Invalid symbol 58)
|
||||
Set-Location $repo
|
||||
$env:TAURI_SIGNING_PRIVATE_KEY = (Get-Content $key -Raw).Trim()
|
||||
$env:TAURI_SIGNING_PRIVATE_KEY_PASSWORD = ""
|
||||
cmd /c "cargo tauri signer sign -p `"`" --app-version 0.1.3 `"$exe`" < NUL 2>&1"
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host "[失败] 签名"; exit 1 }
|
||||
$sigPath = "$exe.sig"
|
||||
if (-not (Test-Path $sigPath)) { Write-Host "[失败] .sig 未生成"; exit 1 }
|
||||
Write-Host "[2/5] 签名完成: $sigPath"
|
||||
|
||||
# 3. 生成 latest.json(UTF-8 无 BOM,防 PS5.1 BOM 坑)
|
||||
$sig = (Get-Content $sigPath -Raw).Trim()
|
||||
$pubDate = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
||||
$latestJson = [ordered]@{
|
||||
version = "0.1.3"
|
||||
notes = $notes
|
||||
pub_date = $pubDate
|
||||
platforms = [ordered]@{
|
||||
"windows-x86_64" = [ordered]@{
|
||||
signature = $sig
|
||||
url = "$baseUrl/devflow_0.1.3_x64-setup.exe"
|
||||
}
|
||||
}
|
||||
} | ConvertTo-Json -Depth 5
|
||||
$latestPath = "$nsis\latest.json"
|
||||
[System.IO.File]::WriteAllText($latestPath, $latestJson, (New-Object System.Text.UTF8Encoding($false)))
|
||||
Write-Host "[3/5] latest.json 已生成 (version=0.1.3)"
|
||||
|
||||
# 4. 上传三件套
|
||||
$env:MSYS_NO_PATHCONV = "1"
|
||||
ssh-proxy exec -n $site -c "mkdir -p $remoteDir"
|
||||
foreach ($f in @($exe, $sigPath, $latestPath)) {
|
||||
$name = Split-Path $f -Leaf
|
||||
Write-Host "[4/5] 上传 $name ..."
|
||||
ssh-proxy upload --name $site --src $f --dst "$remoteDir/$name"
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host "[失败] 上传 $name"; exit 1 }
|
||||
}
|
||||
|
||||
# 5. 远端验证
|
||||
Write-Host "[5/5] 远端清单验证:"
|
||||
ssh-proxy exec -n $site -c "ls -la $remoteDir | grep 0.1.3; head -c 200 $remoteDir/latest.json"
|
||||
Write-Host ""
|
||||
Write-Host "[发布完成] v0.1.3 清单地址: $baseUrl/latest.json"
|
||||
@@ -0,0 +1,25 @@
|
||||
# 后台启动 publish-release.ps1(tauri build 10 分钟级,run_command 600s 上限装不下)
|
||||
# 用法: run_command 执行本文件 -> 立即返回 pid -> 之后轮询 release-out.log
|
||||
$repo = 'E:\wk-lab\devflow'
|
||||
$log = "$repo\target\release-out.log"
|
||||
$errl = "$repo\target\release-err.log"
|
||||
|
||||
# 清掉上次 600s 超时可能残留的构建进程,防 cargo 构建锁互等
|
||||
$killed = Get-Process cargo,cargo-tauri,rustc -ErrorAction SilentlyContinue
|
||||
if ($killed) {
|
||||
$killed | Stop-Process -Force
|
||||
Write-Host ("清理残留构建进程: " + (($killed | Select-Object -ExpandProperty Id) -join ','))
|
||||
} else {
|
||||
Write-Host "无残留构建进程"
|
||||
}
|
||||
|
||||
Remove-Item $log,$errl -ErrorAction SilentlyContinue
|
||||
$p = Start-Process -FilePath 'powershell.exe' `
|
||||
-ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File',"$repo\scripts\publish-release.ps1") `
|
||||
-WorkingDirectory $repo `
|
||||
-NoNewWindow `
|
||||
-RedirectStandardOutput $log `
|
||||
-RedirectStandardError $errl `
|
||||
-PassThru
|
||||
Set-Content -Path "$repo\target\release-pid.txt" -Value $p.Id -Encoding ascii
|
||||
Write-Host "release started, pid=$($p.Id), log=$log"
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "devflow"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
description = "DevFlow Desktop App"
|
||||
authors = [""]
|
||||
edition = "2021"
|
||||
|
||||
@@ -270,7 +270,7 @@ pub(super) async fn maybe_auto_compress(
|
||||
);
|
||||
// 复位 is_compressing 收口进 keyword_fallback_commit 单锁(909①-补:
|
||||
// 原先此处单独取锁复位,与提交之间留并发二次压缩窗口)。
|
||||
keyword_fallback_commit(
|
||||
let degraded = keyword_fallback_commit(
|
||||
&session_arc,
|
||||
&conv_id,
|
||||
protect_start,
|
||||
@@ -281,6 +281,16 @@ pub(super) async fn maybe_auto_compress(
|
||||
recall_on.then_some(data_dir.as_path()),
|
||||
)
|
||||
.await;
|
||||
// E2:降级不再静默(实证 76730ce8 seq166 用户被迫原句重发)
|
||||
if degraded {
|
||||
emit_ai_chat_event(
|
||||
&app_handle,
|
||||
AiChatEvent::AiContextDegraded {
|
||||
conversation_id: Some(conv_id.to_string()),
|
||||
reason: "压缩 provider 重建失败,已降级为关键词摘要".into(),
|
||||
},
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -384,7 +394,7 @@ pub(super) async fn maybe_auto_compress(
|
||||
"[ai] 自动压缩失败(后台),降级走关键词摘要兜底(KEYWORD_FALLBACK_ENABLED={})",
|
||||
KEYWORD_FALLBACK_ENABLED,
|
||||
);
|
||||
keyword_fallback_commit(
|
||||
let degraded = keyword_fallback_commit(
|
||||
&session_arc,
|
||||
&conv_id,
|
||||
protect_start,
|
||||
@@ -395,6 +405,17 @@ pub(super) async fn maybe_auto_compress(
|
||||
recall_on.then_some(data_dir.as_path()),
|
||||
)
|
||||
.await;
|
||||
// E2:降级不再静默——AiError 语义是生成结束,此处 loop 仍在跑,
|
||||
// 用专用事件让前端透出降级状态条/提示(不打断流)
|
||||
if degraded {
|
||||
emit_ai_chat_event(
|
||||
&app_handle,
|
||||
AiChatEvent::AiContextDegraded {
|
||||
conversation_id: Some(conv_id.to_string()),
|
||||
reason: "LLM 压缩失败,已降级为关键词摘要".into(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}) // 闭 catch_unwind 内 async move
|
||||
@@ -444,11 +465,11 @@ async fn keyword_fallback_commit(
|
||||
log_head: &str,
|
||||
head_id: &Option<String>,
|
||||
recall: Option<&Path>,
|
||||
) {
|
||||
) -> bool {
|
||||
let inserted = {
|
||||
let mut session = session_arc.lock().await;
|
||||
if !session.per_conv.contains_key(conv_id) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
let conv = session.conv(conv_id);
|
||||
// 939⑪ 内容版本守卫:上下文已被整体替换 → 丢弃兜底提交(标志亦不复位)。
|
||||
@@ -458,7 +479,7 @@ async fn keyword_fallback_commit(
|
||||
"[ai] {}兜底提交前上下文版本已变(疑似 clear 重建),丢弃",
|
||||
log_head
|
||||
);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// 复位与提交同锁原子(909①-补):消「锁外复位→再取锁提交」之间的并发二次压缩窗口。
|
||||
conv.messages.set_compressing(false);
|
||||
@@ -495,6 +516,7 @@ async fn keyword_fallback_commit(
|
||||
log_head
|
||||
);
|
||||
}
|
||||
inserted
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -39,7 +39,7 @@ use df_storage::models::AiProviderRecord;
|
||||
// ProviderAcquire 已随 stream_round 迁至 stream_relay.rs。
|
||||
use crate::state::{AppState, LlmConcurrency};
|
||||
|
||||
use super::audit::{process_tool_calls, ToolExecPolicy};
|
||||
use super::audit::{process_tool_calls, take_tool_fail_park, ToolExecPolicy};
|
||||
use super::event_bus::emit_ai_chat_event;
|
||||
// compress_via_llm 已随压缩逻辑迁至 context_lifecycle.rs(maybe_auto_compress 内调用)。
|
||||
use super::conversation::{save_conversation, TokenAccumulator};
|
||||
@@ -527,6 +527,32 @@ pub(crate) async fn run_agentic_loop(
|
||||
// 热改 agent_max_iterations 不影响在跑 loop)+ 清零上 loop 残留的注入顺延余量。
|
||||
conv.loop_max_rounds = max_iterations;
|
||||
conv.round_budget_extra = 0;
|
||||
// 真目标源(2026-10-15 目标语义重构):pinned_goals 从「工具推理流水账」改为「用户任务原文」
|
||||
// ——流水账模式下用户真实意图从不进目标体系,压缩/重启后 AI 即失忆(2026-10-12/15
|
||||
// 两次丢目标事故同根)。首条任务型 user 消息写入首位;已有目标不覆盖(尊重
|
||||
// UPDATE_GOALS 显式修正);[系统恢复] 引导与超短碎片不入(递归套娃教训)。
|
||||
if conv.pinned_goals.is_empty() {
|
||||
let task_text = conv
|
||||
.messages
|
||||
.iter()
|
||||
.find(|m| {
|
||||
matches!(m.role, df_ai::provider::MessageRole::User)
|
||||
&& !m.content.starts_with("[系统恢复]")
|
||||
&& !m.content.starts_with("[补充指令]")
|
||||
&& m.content.chars().count() >= 4
|
||||
})
|
||||
.map(|m| {
|
||||
let mut t: String = m.content.chars().take(GOAL_MAX_CHARS).collect();
|
||||
if m.content.chars().count() > GOAL_MAX_CHARS {
|
||||
t.push('…');
|
||||
}
|
||||
t
|
||||
});
|
||||
if let Some(t) = task_text {
|
||||
conv.pinned_goals.push(super::GoalEntry::new(t));
|
||||
tracing::info!(conv_id = %conv_id, "[ai] 会话目标取首条任务消息(目标语义重构)");
|
||||
}
|
||||
}
|
||||
(
|
||||
conv.stop_flag.clone(),
|
||||
conv.notify.clone(),
|
||||
@@ -969,7 +995,7 @@ pub(crate) async fn run_agentic_loop(
|
||||
// (pinned_goals / working_context / workflow_dag_summary)消除原 G1/T5/T4 三处独立 lock,
|
||||
// 且返回 pinned_goals 复用作 AiCompleted 快照(消除原 L1157 二次读)。拼接顺序+内容逐字节等价。
|
||||
let (system_prompt, pinned_goals_snapshot) = build_runtime_prompt(
|
||||
&session_arc, &conv_id, system_prompt, "",
|
||||
&session_arc, &conv_id, system_prompt, "", h3_watch_dir.as_deref(),
|
||||
).await;
|
||||
|
||||
// ── Plan-driven Phase 1:LLM 规划端(AICHAT_PLAN_ENABLED 门控) ──
|
||||
@@ -2013,6 +2039,9 @@ async fn prepare_round_inputs(
|
||||
// 条目已消失则跳过,防 conv() 惰性创建孤儿状态
|
||||
if session.conv_read(conv_id).is_some() {
|
||||
session.conv(conv_id).messages.set_cache_friendly(cache_friendly);
|
||||
// 本轮请求已含截至此刻的全部消息,注入计数清零(=已消化);此后到收敛前
|
||||
// 再到的注入会计数,收敛出口凭 >0 续一轮消化(见收敛分支守卫)。
|
||||
session.conv(conv_id).pending_injects = 0;
|
||||
}
|
||||
let conv = match session.conv_read(conv_id) {
|
||||
Some(c) => c,
|
||||
@@ -2218,7 +2247,10 @@ async fn finalize_round_output(
|
||||
})
|
||||
.collect();
|
||||
} else {
|
||||
update_pinned_goals(&mut session, conv_id, tool_calls_acc);
|
||||
// 工具推理流水账停写(2026-10-15 目标语义重构):「执行 xxx/查看 xxx」是手段记录
|
||||
// 不是用户目标,入 pinned_goals 挤占真目标且压缩/重启后即失忆;工具轨迹已由
|
||||
// 轨迹卡与审计表完整覆盖。目标来源收敛为:首条任务消息(入口写入)+UPDATE_GOALS
|
||||
// 显式修正(上方分支,LLM 显式目标管理继续有效)。
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2345,19 +2377,49 @@ async fn finalize_round_output(
|
||||
// 正常收敛(loop 主体置 converged 后 break)
|
||||
// P2-1 主会话侧最小修复:收敛文本若被 max_tokens 腰斩,追加系统提示消息
|
||||
// (对齐 MidStream 保文的系统提示机制),用户/下轮请求能看见截断而非当完整回复。
|
||||
if round_truncated_by_max_tokens {
|
||||
// 注入未消化守卫(2026-10-14 实测):本轮组装后到达的补充指令,纯问答轮一轮收敛即
|
||||
// 无人消费(本轮上下文已在生成中定型)。计数>0 → 插提示续一轮,下轮
|
||||
// build_for_request 自然带上补充内容;计数已 take 清零,同批注入不重复触发。
|
||||
let pending_injects = {
|
||||
let mut session = session_arc.lock().await;
|
||||
if session.per_conv.contains_key(conv_id) {
|
||||
std::mem::take(&mut session.conv(conv_id).pending_injects)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
};
|
||||
if pending_injects > 0 {
|
||||
let mut session = session_arc.lock().await;
|
||||
if session.per_conv.contains_key(conv_id) {
|
||||
let conv = session.conv(conv_id);
|
||||
let mut notice = ChatMessage::system(
|
||||
"⚠ 回复因 max_tokens 上限被截断,以上内容可能不完整;可要求模型继续输出。",
|
||||
);
|
||||
notice.model = Some(resolved_model.to_string());
|
||||
conv.messages.push(notice);
|
||||
let mut tip = ChatMessage::system(format!(
|
||||
"用户在回答生成期间补充了 {pending_injects} 条消息(见对话记录中的补充指令);\
|
||||
请结合补充内容继续或修正上面的回答,勿忽略。"
|
||||
));
|
||||
tip.model = Some(resolved_model.to_string());
|
||||
conv.messages.push(tip);
|
||||
}
|
||||
tracing::warn!(conv_id = %conv_id, "[ai] 收敛回复因 max_tokens 截断,已追加系统提示");
|
||||
tracing::info!(
|
||||
conv_id = %conv_id, pending = pending_injects,
|
||||
"[ai] 收敛时检出未消化注入,插提示续一轮消化"
|
||||
);
|
||||
// 不 return Converged:掉到函数尾部 RunTools(本轮无工具空转),
|
||||
// loop 顶部正常续轮,补充指令获得完整消费轮。
|
||||
} else {
|
||||
if round_truncated_by_max_tokens {
|
||||
let mut session = session_arc.lock().await;
|
||||
if session.per_conv.contains_key(conv_id) {
|
||||
let conv = session.conv(conv_id);
|
||||
let mut notice = ChatMessage::system(
|
||||
"⚠ 回复因 max_tokens 上限被截断,以上内容可能不完整;可要求模型继续输出。",
|
||||
);
|
||||
notice.model = Some(resolved_model.to_string());
|
||||
conv.messages.push(notice);
|
||||
}
|
||||
tracing::warn!(conv_id = %conv_id, "[ai] 收敛回复因 max_tokens 截断,已追加系统提示");
|
||||
}
|
||||
return RoundEpilogue::Converged;
|
||||
}
|
||||
return RoundEpilogue::Converged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2417,6 +2479,24 @@ async fn process_round_tools(
|
||||
return ToolsOutcome::Exit;
|
||||
}
|
||||
|
||||
// B5d 工具连败熔断终局:同会话失败记忆拦截连击达阈且期间无成功 → 强制停靠。
|
||||
// 拦截计数在 audit 层(execute_with_heartbeat)累积,停靠在 loop 层执行:guard 复位
|
||||
// 与 emit_task_parked 正典序列只有本层触达,audit 层只判定不执行。停靠即终局,
|
||||
// 不再给模型无视 blocked 提示继续重试的机会(实证:拦截后模型仍原样重试 10+ 次)。
|
||||
if take_tool_fail_park(conv_id) {
|
||||
tracing::warn!(
|
||||
conv_id = %conv_id,
|
||||
"[ai] 工具连续失败熔断:失败记忆拦截连击达阈,任务强制停靠"
|
||||
);
|
||||
guard.reset().await;
|
||||
crate::commands::ai::emit_task_parked(
|
||||
app_handle, conv_id,
|
||||
"工具连续失败熔断(同一调用被失败记忆反复拦截仍重试),任务安全停靠;已完成进度已保存,调整思路后重发消息可继续",
|
||||
"circuit_breaker",
|
||||
);
|
||||
return ToolsOutcome::Exit;
|
||||
}
|
||||
|
||||
// AC-2 ①:单轮工具调用数超限 → 注入软提示(机制化,非静默,弱模型能感知)。
|
||||
// 治单轮并行调用爆炸:LLM 看不到自己发了多少调用,必须在消息流里显式警告。
|
||||
if is_tool_call_over_limit(round_tool_call_count) {
|
||||
@@ -3238,11 +3318,13 @@ fn completed_event(
|
||||
// 做 snapshot,消除原 L1157 第二次 lock 读。
|
||||
//
|
||||
// 注:`_lang` 参数为未来 i18n 行为准则预留(当前 system_prompt 拼接未用 lang),保持调用点签名稳定。
|
||||
// 注:`work_dir` 供项目规则文件投影定位工作区(与被监视工作区同一目录),None=无授权目录。
|
||||
async fn build_runtime_prompt(
|
||||
session_arc: &Arc<Mutex<AiSession>>,
|
||||
conv_id: &str,
|
||||
base_prompt: String,
|
||||
_lang: &str,
|
||||
work_dir: Option<&str>,
|
||||
) -> (String, Vec<super::GoalEntry>) {
|
||||
// 一次锁读四字段(pinned_goals / working_injection / workflow_dag_summary / workflow_id)。
|
||||
// conv 已删(None)→ goals=空 / injection=空 / dag=None,等价原各块 conv_read.unwrap_or_default 短路。
|
||||
@@ -3368,6 +3450,12 @@ async fn build_runtime_prompt(
|
||||
);
|
||||
}
|
||||
|
||||
// 项目规则文件投影(devflow.md/CLAUDE.md):稳定尾段纯追加 —— 拼在全部既有段之后、
|
||||
// 返回之前。内容经 devflow_md 模块按会话缓存(同会话只读一次盘),loop 内为不变量,
|
||||
// 不击穿 provider prompt 缓存前缀;工作目录无规则文件时原样返回(缺失不影响既有组装)。
|
||||
let system_prompt =
|
||||
crate::commands::ai::devflow_md::append_projection(system_prompt, work_dir, conv_id).await;
|
||||
|
||||
(system_prompt, goals)
|
||||
}
|
||||
|
||||
@@ -3576,6 +3664,7 @@ fn push_assistant_message(
|
||||
// ── update_pinned_goals: G1 目标钉扎提取+裁剪(扁平抽自原嵌套块,原 8 层 → 3 层) ──
|
||||
// 从工具调用推理新目标 → 去重 add → 标记旧 active 为 completed → 超上限时淘汰最早 completed。
|
||||
// 入参 session 需外层调用方持锁;纯内存 mutate,无 await。
|
||||
#[allow(dead_code)]
|
||||
fn update_pinned_goals(
|
||||
session: &mut AiSession,
|
||||
conv_id: &str,
|
||||
|
||||
@@ -228,6 +228,76 @@ fn sub_agent_tool_clamped(allowed: Option<&[String]>, tool_name: &str) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
// B5d 工具连败升级(快速放弃+换路引导)。三级全部复用既有失败记忆(tool_failure_memory)
|
||||
// 的连败计数,不另造计数轨道:首败=裸错误原样;第 2 次失败=错误包附软提示(勿原样重试);
|
||||
// 第 3 次起=入口拦截包升级为强制换路通牒(换工具/查知识库/向用户说明)。拦截在本会话
|
||||
// 连续达 PARK_AFTER_BLOCKS 且期间无任何工具成功 → take_tool_fail_park 请求 loop 层停靠
|
||||
// (2026-10-12 实证:拦截后模型仍原样重试 10+ 次,软提示拦不住,须有终局)。
|
||||
|
||||
/// 第 2 次失败附带的软提示:提醒而非禁止,给模型自行调参换路的机会。
|
||||
const HINT_AVOID_RETRY: &str = "已连续失败 2 次,勿盲目重试同命令;考虑调整参数或换路径";
|
||||
|
||||
/// 第 3 次起拦截包附带的强制换路提示(终局通牒,含知识库检索引导)。
|
||||
const HINT_MUST_SWITCH: &str = "连续失败≥3次,禁止重试同命令,必须:①换工具或换路径 ②调 knowledge_search 查既有经验 ③仍无法绕过则向用户说明并停手";
|
||||
|
||||
/// 同会话失败记忆拦截连续达此值(且期间无任何工具成功)→ 请求 loop 层强制停靠。
|
||||
const PARK_AFTER_BLOCKS: u32 = 5;
|
||||
|
||||
/// 同会话失败记忆拦截连击计数:键=conv_id,值=自该会话最近一次成功执行以来的拦截次数。
|
||||
/// 与失败记忆分开记:拦截不触发工具执行,失败记忆的连败数停在阈值不再增长,连击数
|
||||
/// 只能另记;按会话而非按调用键记,参数抖动绕开调用键时连击依旧成立。
|
||||
static BLOCK_STREAKS: std::sync::OnceLock<std::sync::Mutex<HashMap<String, u32>>> =
|
||||
std::sync::OnceLock::new();
|
||||
|
||||
fn bump_block_streak(conv_id: &str) -> u32 {
|
||||
let streaks = BLOCK_STREAKS.get_or_init(|| std::sync::Mutex::new(HashMap::new()));
|
||||
let mut m = streaks.lock().unwrap_or_else(|p| p.into_inner());
|
||||
let n = m.entry(conv_id.to_string()).or_insert(0);
|
||||
*n += 1;
|
||||
*n
|
||||
}
|
||||
|
||||
/// 任一工具成功即打断连击(会话有产出,不再是纯挣扎状态)。
|
||||
fn clear_block_streak(conv_id: &str) {
|
||||
if let Some(m) = BLOCK_STREAKS.get() {
|
||||
m.lock().unwrap_or_else(|p| p.into_inner()).remove(conv_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// loop 层消费停靠请求:连击达 PARK_AFTER_BLOCKS 且未被成功清零 → 取走标志返 true。
|
||||
pub(crate) fn take_tool_fail_park(conv_id: &str) -> bool {
|
||||
let Some(m) = BLOCK_STREAKS.get() else { return false };
|
||||
let mut map = m.lock().unwrap_or_else(|p| p.into_inner());
|
||||
match map.get(conv_id) {
|
||||
Some(&n) if n >= PARK_AFTER_BLOCKS => {
|
||||
map.remove(conv_id);
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// 第 2 次失败的错误包附软提示;首败原样透传。
|
||||
fn with_streak_hint(err: anyhow::Error, streak_hit: bool) -> anyhow::Error {
|
||||
if streak_hit {
|
||||
anyhow::anyhow!("{err}\n{HINT_AVOID_RETRY}")
|
||||
} else {
|
||||
err
|
||||
}
|
||||
}
|
||||
|
||||
/// 拦截包升级:hint 字段换为强制换路通牒,status/tool/consecutive_failures/last_error
|
||||
/// 保留不丢。提示文本跨次恒定(不带递增计数):L1 断路器按错误文本哈希归一 key,
|
||||
/// 变化文本会打散其连败累计;连击数走 tracing 日志与停靠判定,不进模型可见包。
|
||||
fn upgrade_blocked_hint(blocked: &str) -> String {
|
||||
let mut v: serde_json::Value = serde_json::from_str(blocked)
|
||||
.unwrap_or_else(|_| serde_json::json!({ "status": "blocked_by_failure_memory" }));
|
||||
if let Some(obj) = v.as_object_mut() {
|
||||
obj.insert("hint".into(), serde_json::json!(HINT_MUST_SWITCH));
|
||||
}
|
||||
v.to_string()
|
||||
}
|
||||
|
||||
/// 处理流式接收的工具调用:Low 风险并行执行(join_all),Med/High 进审批门控
|
||||
/// 返回待审批的工具数量(0 = 全部自动执行完成)
|
||||
///
|
||||
@@ -261,17 +331,20 @@ pub(crate) async fn execute_with_heartbeat(
|
||||
use tokio::time::Duration;
|
||||
|
||||
// ── B5d 工具失败记忆:执行前拦截「同 (conv,tool,args) 连败 ≥2 次」的重复调用 ──
|
||||
// 治「404 连环十几次无退避换路」:拦截时回填结构化换路提示(改参数/换工具/报告放弃),
|
||||
// 治「404 连环十几次无退避换路」:拦截时回填结构化换路提示(强制换路通牒,升级版),
|
||||
// 引导 LLM 换路而非原样重试。成功即清零(record 侧),防误杀。
|
||||
// 拦截直接返 Err(错误 tool_result),不执行工具——process_tool_calls 侧按既有错误路径处理。
|
||||
// 拦截同时累加会话连击,达 PARK_AFTER_BLOCKS 由 loop 层(process_round_tools)停靠收场。
|
||||
if let Some(blocked) = super::tool_failure_memory::precheck(name, &args) {
|
||||
let blocks = bump_block_streak(conv_id);
|
||||
tracing::warn!(
|
||||
conv_id = %conv_id,
|
||||
tool = %name,
|
||||
tool_call_id = %tool_call_id,
|
||||
"[failure-memory] 同调用连败达标,执行前拦截"
|
||||
blocks,
|
||||
"[failure-memory] 同调用连败达标,执行前拦截(本会话累计第 {blocks} 次)"
|
||||
);
|
||||
return Err(anyhow::anyhow!(blocked));
|
||||
return Err(anyhow::anyhow!(upgrade_blocked_hint(&blocked)));
|
||||
}
|
||||
// record 侧需 args 计算 memory_key,但下方 tools.execute(name, args) 会 move args。
|
||||
// 此处留一份 clone 供执行后 record 使用(仅工具执行路径,非热循环,开销可接受)。
|
||||
@@ -516,13 +589,22 @@ pub(crate) async fn execute_with_heartbeat(
|
||||
exec_result
|
||||
};
|
||||
|
||||
// ── B5d 工具失败记忆:执行后回写(成功清零 / 失败递增并记最近错误) ──
|
||||
// 与入口 precheck 配对:成功即删记忆(知识保鲜,防误杀);失败累加计数,
|
||||
// ── B5d 工具失败记忆:执行后回写 + 连败升级提示 ──
|
||||
// 与入口 precheck 配对:成功即删记忆(知识保鲜,防误杀)并打断拦截连击;失败累加计数,
|
||||
// 达阈值后下次 precheck 拦截。error 摘要取 Err 文案(超时/提前退出/工具自身错误同源)。
|
||||
match &exec_result {
|
||||
Ok(_) => super::tool_failure_memory::record(name, &args_for_memory, true, None),
|
||||
Err(e) => super::tool_failure_memory::record(name, &args_for_memory, false, Some(e.to_string())),
|
||||
}
|
||||
// 失败侧回探 precheck:命中即本次为第 2 次失败,错误包附软提示(第 3 次起由入口拦截包接管)。
|
||||
let exec_result = match exec_result {
|
||||
Ok(v) => {
|
||||
super::tool_failure_memory::record(name, &args_for_memory, true, None);
|
||||
clear_block_streak(conv_id);
|
||||
Ok(v)
|
||||
}
|
||||
Err(e) => {
|
||||
super::tool_failure_memory::record(name, &args_for_memory, false, Some(e.to_string()));
|
||||
let streak_hit = super::tool_failure_memory::precheck(name, &args_for_memory).is_some();
|
||||
Err(with_streak_hint(e, streak_hit))
|
||||
}
|
||||
};
|
||||
|
||||
exec_result
|
||||
}
|
||||
@@ -1726,4 +1808,78 @@ mod tests {
|
||||
let (reason_0, _) = approval_timeout_park_parts(0);
|
||||
assert!(reason_0.contains("0"), "任意分钟数可格式化(0=禁用超时不会到点,防御)");
|
||||
}
|
||||
|
||||
/// B5d 连败升级三级:首败裸错误 / 第 2 次失败附软提示 / 第 3 次起拦截包升级强制换路
|
||||
/// 通牒(含 knowledge_search 引导);成功一次即清零,再败回到首败无提示。
|
||||
/// 走真失败记忆(进程级静态),键取本测试专属路径防并行互踩。
|
||||
#[test]
|
||||
fn failure_streak_hint_escalates_three_levels() {
|
||||
use crate::commands::ai::tool_failure_memory::{precheck, record};
|
||||
let args = serde_json::json!({ "path": "/tmp/b5d-escalation-check.txt" });
|
||||
|
||||
// 首败:未达拦截阈值,无提示
|
||||
record("read_file", &args, false, Some("not found".into()));
|
||||
assert!(!precheck("read_file", &args).is_some(), "首败不拦截");
|
||||
|
||||
// 第 2 次失败:记录后回探预检命中,错误包附软提示
|
||||
record("read_file", &args, false, Some("not found".into()));
|
||||
let streak_hit = precheck("read_file", &args).is_some();
|
||||
assert!(streak_hit, "两连败后回探应命中");
|
||||
let hinted = with_streak_hint(anyhow::anyhow!("工具执行失败"), streak_hit).to_string();
|
||||
assert!(hinted.contains(HINT_AVOID_RETRY), "第 2 次失败附软提示: {hinted}");
|
||||
assert!(hinted.contains("工具执行失败"), "原始错误保留: {hinted}");
|
||||
|
||||
// 第 3 次起:拦截包升级为强制换路通牒,状态字段保留,文本跨次恒定(L1 断路器
|
||||
// 按错误文本哈希归 key,变化文本会打散其累计)
|
||||
let blocked = precheck("read_file", &args).unwrap();
|
||||
let upgraded = upgrade_blocked_hint(&blocked);
|
||||
let upgraded_again = upgrade_blocked_hint(&blocked);
|
||||
assert!(upgraded.contains("blocked_by_failure_memory"), "状态字段保留: {upgraded}");
|
||||
assert!(upgraded.contains(HINT_MUST_SWITCH), "拦截包附强制换路通牒: {upgraded}");
|
||||
assert!(upgraded.contains("knowledge_search"), "通牒含知识库检索引导: {upgraded}");
|
||||
assert_eq!(upgraded, upgraded_again, "升级文本跨次恒定");
|
||||
|
||||
// 成功一次即清零:再败回到首败,无提示
|
||||
record("read_file", &args, true, None);
|
||||
record("read_file", &args, false, Some("not found".into()));
|
||||
assert!(!precheck("read_file", &args).is_some(), "成功清零后首败无提示");
|
||||
assert!(
|
||||
!with_streak_hint(anyhow::anyhow!("x"), precheck("read_file", &args).is_some())
|
||||
.to_string()
|
||||
.contains(HINT_AVOID_RETRY),
|
||||
"首败错误包不附提示"
|
||||
);
|
||||
}
|
||||
|
||||
/// B5d 熔断终局:同会话失败记忆拦截连击达 PARK_AFTER_BLOCKS 触发停靠,取走即消费
|
||||
/// (不重复触发);未达阈不触发。
|
||||
#[test]
|
||||
fn blocked_streak_parks_after_five() {
|
||||
let conv = "conv-b5d-park-check";
|
||||
clear_block_streak(conv);
|
||||
for _ in 0..(PARK_AFTER_BLOCKS - 1) {
|
||||
bump_block_streak(conv);
|
||||
}
|
||||
assert!(!take_tool_fail_park(conv), "未达阈不停靠");
|
||||
bump_block_streak(conv);
|
||||
assert!(take_tool_fail_park(conv), "拦截连击达 5 触发停靠");
|
||||
assert!(!take_tool_fail_park(conv), "停靠取走即消费,不重复触发");
|
||||
}
|
||||
|
||||
/// B5d 成功打断连击:达阈前任一工具成功即清零,连击从头再计(会话有产出不停靠)。
|
||||
#[test]
|
||||
fn tool_success_clears_block_streak() {
|
||||
let conv = "conv-b5d-success-clear";
|
||||
clear_block_streak(conv);
|
||||
for _ in 0..(PARK_AFTER_BLOCKS - 1) {
|
||||
bump_block_streak(conv);
|
||||
}
|
||||
clear_block_streak(conv);
|
||||
assert!(!take_tool_fail_park(conv), "成功打断连击,不停靠");
|
||||
for _ in 0..PARK_AFTER_BLOCKS {
|
||||
bump_block_streak(conv);
|
||||
}
|
||||
assert!(take_tool_fail_park(conv), "清零后重新连击达阈仍停靠");
|
||||
clear_block_streak(conv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1197,6 +1197,9 @@ pub(crate) async fn inject_runtime_message(
|
||||
if extended {
|
||||
conv.round_budget_extra += 1;
|
||||
}
|
||||
// 未消化计数(2026-10-14 实测):纯问答轮一轮收敛无下一轮,末轮扩轮机制(loop_max>0 才生效)
|
||||
// 兜不住;收敛出口凭此计数感知「组装后有注入到达」并续一轮消化。
|
||||
conv.pending_injects = conv.pending_injects.saturating_add(1);
|
||||
drop(session);
|
||||
// 落库(增量 save):与 loop 的 save 走同一 per-conv save 锁串行,幂等无交叉
|
||||
save_conversation(&state.ai_session, &state.db, conv_id, None, None, true).await;
|
||||
@@ -1204,6 +1207,20 @@ pub(crate) async fn inject_runtime_message(
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// 桌面端补充注入入口(桌面 AiChat 运行中发消息的 u-claw 语义:补充并进当前回答,不开新轮)。
|
||||
/// 把 inject_runtime_message 暴露为 Tauri command,与飞书渠道(feishu_channel.rs)同源同一实现,
|
||||
/// 锁纪律/末轮顺延语义收敛在 inject_runtime_message 单一真值,本 command 纯透传零附加逻辑。
|
||||
/// 返回契约:Ok(true)=已注入(前端不入队,提示已并入当前回答);Ok(false)=会话不存在
|
||||
/// (前端按普通新消息入队);Err=非活跃/Stopping(前端零破坏回退常规入队)。
|
||||
#[tauri::command]
|
||||
pub async fn ai_inject_runtime(
|
||||
state: State<'_, AppState>,
|
||||
conversation_id: String,
|
||||
message: String,
|
||||
) -> Result<bool, String> {
|
||||
inject_runtime_message(&state, &conversation_id, &message).await
|
||||
}
|
||||
|
||||
/// 批准/拒绝挂起的工具调用
|
||||
#[tauri::command]
|
||||
pub async fn ai_approve(
|
||||
|
||||
@@ -232,14 +232,24 @@ pub async fn ai_conversation_create(
|
||||
///
|
||||
/// 截断按组独立:活跃/归档各自取 limit,归档项不挤占活跃名额(侧栏归档分组数据源依赖
|
||||
/// include_archived=true,见 useAiConversations.loadConversations)。
|
||||
///
|
||||
/// F4-1(2026-10-17)分页:active_offset/archived_offset 按组跳过前 N 条(默认 0=第一页,
|
||||
/// 旧调用方零改动)。治「会话列表+搜索硬上限 50」——实测 115 条活跃主会话 57% 在桌面
|
||||
/// 端零入口;侧栏首屏仍一页(50/组)保启动性能,「加载更多」按 offset 续拉,搜索前前端
|
||||
/// 逐页拉满(搜索跑在已加载列表上,截断列表=搜索失灵)。offset 超组长度返回该组空页
|
||||
/// (自然收敛,无需显式 has_more 字段:页内某组满额 limit 即可能还有下一页)。
|
||||
#[tauri::command]
|
||||
pub async fn ai_conversation_list(
|
||||
state: State<'_, AppState>,
|
||||
limit: Option<usize>,
|
||||
include_archived: Option<bool>,
|
||||
active_offset: Option<usize>,
|
||||
archived_offset: Option<usize>,
|
||||
) -> Result<Vec<serde_json::Value>, String> {
|
||||
let limit = limit.unwrap_or(50);
|
||||
let include_archived = include_archived.unwrap_or(false);
|
||||
let active_offset = active_offset.unwrap_or(0);
|
||||
let archived_offset = archived_offset.unwrap_or(0);
|
||||
let records = state.ai_conversations.list_all().await.map_err(err_str)?;
|
||||
// list_all 已按 created_at DESC(最新在前);默认排除归档 + 截断 limit。
|
||||
// origin 非空(子代理轨迹,V44)不进侧栏列表——轨迹在库可追溯,展示面只留主会话。
|
||||
@@ -273,20 +283,25 @@ pub async fn ai_conversation_list(
|
||||
"loop_state": r.loop_state,
|
||||
})
|
||||
}).collect();
|
||||
// 分组截断:活跃/归档各自独立取 limit,防归档项挤占活跃名额(前端侧栏活跃列表被截空)。
|
||||
// 原单 take(limit) 在 include_archived=true 时归档项混排会占满 50 名额。
|
||||
let mut active = Vec::with_capacity(limit);
|
||||
let mut archived = Vec::with_capacity(limit);
|
||||
for s in summaries {
|
||||
if s.get("archived").and_then(|v| v.as_bool()) == Some(true) {
|
||||
if archived.len() < limit { archived.push(s); }
|
||||
} else if active.len() < limit {
|
||||
active.push(s);
|
||||
}
|
||||
}
|
||||
// 活跃在前(侧栏主区),归档在后(归档分组);各自保持 created_at DESC 原序。
|
||||
active.extend(archived);
|
||||
Ok(active)
|
||||
Ok(paginate_by_group(summaries, limit, active_offset, archived_offset))
|
||||
}
|
||||
|
||||
/// F4-1:摘要按组独立分页——活跃/归档各自 skip(offset)+take(limit),活跃在前归档在后,
|
||||
/// 组内保持传入原序(created_at DESC)。offset=0 与旧「分组截断」口径逐字节等价
|
||||
/// (回归保护见 paginate_first_page_matches_legacy_grouped_truncation)。
|
||||
/// 抽纯函数供单测:分组正确性/offset 续拉/越界空页/归档不挤占活跃名额。
|
||||
fn paginate_by_group(
|
||||
summaries: Vec<serde_json::Value>,
|
||||
limit: usize,
|
||||
active_offset: usize,
|
||||
archived_offset: usize,
|
||||
) -> Vec<serde_json::Value> {
|
||||
let (active, archived): (Vec<_>, Vec<_>) = summaries
|
||||
.into_iter()
|
||||
.partition(|s| s.get("archived").and_then(|v| v.as_bool()) != Some(true));
|
||||
let mut page: Vec<serde_json::Value> = active.into_iter().skip(active_offset).take(limit).collect();
|
||||
page.extend(archived.into_iter().skip(archived_offset).take(limit));
|
||||
page
|
||||
}
|
||||
|
||||
/// B3(无人值守可靠性专项):列出可恢复会话(loop_state='parked')。
|
||||
@@ -391,11 +406,37 @@ pub(crate) async fn recover_parked_inner(
|
||||
.await
|
||||
}
|
||||
|
||||
/// 恢复产物前缀:恢复链自身生成的引导消息以它开头(恢复产物非用户意图,任何情况下
|
||||
/// 都不该作为有效目标回放——2026-10-15 目标语义重构约定)。递归套娃根因:恢复消息
|
||||
/// 经 begin_turn(chat.rs:950/2461)被记为 WorkingContext Active 目标落库,下次恢复
|
||||
/// 回放时被当有效目标嵌套进新恢复消息,逐层加深(实证 conv 76730ce8 seq 250:
|
||||
/// 目标文本=上一条恢复消息原文截 200 字符)。防线收敛在恢复链单点:
|
||||
/// parse_pinned_goals 反解剔除 + build_recovery_message 回放剔除,同判据。
|
||||
pub(crate) const RECOVERY_ARTIFACT_PREFIX: &str = "[系统恢复]";
|
||||
|
||||
/// 恢复产物判定:目标文本以恢复前缀开头即恢复链自产物,不作为有效目标。
|
||||
fn is_recovery_artifact(text: &str) -> bool {
|
||||
text.starts_with(RECOVERY_ARTIFACT_PREFIX)
|
||||
}
|
||||
|
||||
/// 注入产物判定(E5):[补充指令] 是运行中用户插话的通道标记,非任务意图本身
|
||||
/// (实证 434c8c40 active goal=「[补充指令] 123 hi」占位)。与恢复产物同治:
|
||||
/// 载入侧滤出内存,下轮 save 重写即自愈落库。
|
||||
fn is_injection_artifact(text: &str) -> bool {
|
||||
text.starts_with("[补充指令]")
|
||||
}
|
||||
|
||||
/// 引导产物总判定(恢复+注入),双侧(载入/回放)统一用。
|
||||
fn is_guide_artifact(text: &str) -> bool {
|
||||
is_recovery_artifact(text) || is_injection_artifact(text)
|
||||
}
|
||||
|
||||
/// 目标快照:按最终有效意图生成 parked 恢复引导消息。
|
||||
///
|
||||
/// 「按快照续不重放历史目标流」:取 WorkingContext.goals 与 pinned_goals 中仍 Active 的
|
||||
/// 目标 + unresolved 未解项;中途被调整作废(Cancelled)或已完成(Completed)的目标不复活。
|
||||
/// 快照全空(旧会话无快照)回退 [`PARKED_RECOVERY_MESSAGE`],行为同今日。
|
||||
/// 目标 + unresolved 未解项;中途被调整作废(Cancelled)或已完成(Completed)的目标不复活;
|
||||
/// 恢复产物([系统恢复] 前缀)剔除——回放它即递归套娃,历史污染目标在此单点拦截。
|
||||
/// 快照全空(旧会话无快照/全被过滤)回退 [`PARKED_RECOVERY_MESSAGE`],行为同今日。
|
||||
/// 不另立存储:快照即 working_context_json + pinned_goals 两列的语义化读取(单一真值来源)。
|
||||
pub(crate) fn build_recovery_message(
|
||||
working_context: &df_ai::context_helpers::WorkingContext,
|
||||
@@ -405,12 +446,18 @@ pub(crate) fn build_recovery_message(
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let mut active: Vec<&str> = Vec::new();
|
||||
for g in &working_context.goals {
|
||||
if matches!(g.status, GoalStatus::Active) && seen.insert(g.text.clone()) {
|
||||
if matches!(g.status, GoalStatus::Active)
|
||||
&& !is_guide_artifact(&g.text)
|
||||
&& seen.insert(g.text.clone())
|
||||
{
|
||||
active.push(&g.text);
|
||||
}
|
||||
}
|
||||
for g in pinned_goals {
|
||||
if matches!(g.status, crate::commands::ai::GoalStatus::Active) && seen.insert(g.text.clone()) {
|
||||
if matches!(g.status, crate::commands::ai::GoalStatus::Active)
|
||||
&& !is_guide_artifact(&g.text)
|
||||
&& seen.insert(g.text.clone())
|
||||
{
|
||||
active.push(&g.text);
|
||||
}
|
||||
}
|
||||
@@ -442,7 +489,8 @@ pub(crate) fn build_recovery_message(
|
||||
|
||||
/// pinned_goals 落库反解(新旧格式兼容):新格式 [{text,status}] 保 status,
|
||||
/// 旧格式 ["text"] 转 Active;非数组/坏 JSON 一律空(降级不炸)。switch 恢复与
|
||||
/// parked 恢复共用(DRY,单一事实源)。
|
||||
/// parked 恢复共用(DRY,单一事实源)。恢复产物([系统恢复] 前缀)剔除——存量
|
||||
/// 污染目标不进内存,switch 载入后下轮 save 重写 pinned_goals 即自愈落库。
|
||||
pub(crate) fn parse_pinned_goals(raw: Option<&str>) -> Vec<crate::commands::ai::GoalEntry> {
|
||||
let parsed: Option<serde_json::Value> = raw.and_then(|s| serde_json::from_str(s).ok());
|
||||
match parsed {
|
||||
@@ -468,6 +516,7 @@ pub(crate) fn parse_pinned_goals(raw: Option<&str>) -> Vec<crate::commands::ai::
|
||||
Some(crate::commands::ai::GoalEntry::new(text))
|
||||
}
|
||||
})
|
||||
.filter(|e| !is_guide_artifact(&e.text))
|
||||
.collect(),
|
||||
_ => vec![],
|
||||
}
|
||||
@@ -1477,6 +1526,73 @@ mod tests {
|
||||
assert_eq!(back.timestamp, Some(123));
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// F4-1 会话列表分页(paginate_by_group:活跃/归档各自 offset+limit)
|
||||
// ============================================================
|
||||
|
||||
fn conv_val(id: &str, archived: bool) -> serde_json::Value {
|
||||
serde_json::json!({ "id": id, "archived": archived })
|
||||
}
|
||||
|
||||
/// 首页(offset=0)与旧「分组截断」口径等价:各组前 limit 条,活跃在前归档在后。
|
||||
#[test]
|
||||
fn paginate_first_page_matches_legacy_grouped_truncation() {
|
||||
// 60 活跃 + 60 归档,limit 50:旧口径各取 50(归档不挤占活跃名额)
|
||||
let summaries: Vec<_> = (0..60).map(|i| conv_val(&format!("a{i}"), false))
|
||||
.chain((0..60).map(|i| conv_val(&format!("r{i}"), true)))
|
||||
.collect();
|
||||
let page = paginate_by_group(summaries, 50, 0, 0);
|
||||
assert_eq!(page.len(), 100, "各组独立取满 50");
|
||||
assert!(page.iter().take(50).all(|s| s["archived"] == false), "前 50 全活跃");
|
||||
assert!(page.iter().skip(50).all(|s| s["archived"] == true), "后 50 全归档");
|
||||
assert_eq!(page[0]["id"], "a0");
|
||||
assert_eq!(page[49]["id"], "a49");
|
||||
assert_eq!(page[50]["id"], "r0");
|
||||
assert_eq!(page[99]["id"], "r49");
|
||||
}
|
||||
|
||||
/// offset 续拉:第二页从各组 offset 处继续,两组独立推进互不影响
|
||||
/// (115 活跃场景:第一页 a0..a49,第二页 active_offset=50 拉 a50..a99)。
|
||||
#[test]
|
||||
fn paginate_offset_advances_each_group_independently() {
|
||||
let summaries: Vec<_> = (0..115).map(|i| conv_val(&format!("a{i}"), false))
|
||||
.chain((0..3).map(|i| conv_val(&format!("r{i}"), true)))
|
||||
.collect();
|
||||
// 第二页:活跃 offset 50(满页 50 条),归档 offset 0(仅 3 条全回)
|
||||
let page2 = paginate_by_group(summaries.clone(), 50, 50, 0);
|
||||
assert_eq!(page2.len(), 53);
|
||||
assert_eq!(page2[0]["id"], "a50");
|
||||
assert_eq!(page2[49]["id"], "a99");
|
||||
assert_eq!(page2[50]["id"], "r0", "归档组从 0 起独立分页,不被活跃 offset 影响");
|
||||
// 第三页:活跃 offset 100(尾页 15 条),归档 offset 3(越界空)
|
||||
let page3 = paginate_by_group(summaries, 50, 100, 3);
|
||||
assert_eq!(page3.len(), 15);
|
||||
assert_eq!(page3[0]["id"], "a100");
|
||||
assert_eq!(page3[14]["id"], "a114");
|
||||
assert!(page3.iter().all(|s| s["archived"] == false), "归档越界返回该组空页");
|
||||
}
|
||||
|
||||
/// offset 超组长度的组返回空页(自然收敛);两组同时越界返回空 Vec。
|
||||
#[test]
|
||||
fn paginate_offset_beyond_length_yields_empty() {
|
||||
let summaries = vec![conv_val("a0", false), conv_val("r0", true)];
|
||||
assert!(paginate_by_group(summaries.clone(), 50, 5, 0).iter().all(|s| s["archived"] == true));
|
||||
assert!(paginate_by_group(summaries.clone(), 50, 0, 5).iter().all(|s| s["archived"] == false));
|
||||
assert!(paginate_by_group(summaries, 50, 5, 5).is_empty());
|
||||
}
|
||||
|
||||
/// 输入混排(归档穿插在活跃间,list_all 全量 DESC 实际形态)时 partition 仍按组归位,
|
||||
/// 组内保持传入原序。
|
||||
#[test]
|
||||
fn paginate_partition_from_interleaved_input() {
|
||||
let summaries = vec![
|
||||
conv_val("a0", false), conv_val("r0", true), conv_val("a1", false), conv_val("r1", true),
|
||||
];
|
||||
let page = paginate_by_group(summaries, 50, 0, 0);
|
||||
let ids: Vec<&str> = page.iter().map(|s| s["id"].as_str().unwrap()).collect();
|
||||
assert_eq!(ids, vec!["a0", "a1", "r0", "r1"], "活跃全量在前(原序),归档全量在后(原序)");
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// F-260619-03 批次 B 端到端 round-trip(写路径全链:映射 → replace → list → 还原)
|
||||
// ============================================================
|
||||
@@ -1789,4 +1905,86 @@ mod tests {
|
||||
assert!(parse_pinned_goals(Some("not-json")).is_empty());
|
||||
assert!(parse_pinned_goals(None).is_empty());
|
||||
}
|
||||
|
||||
// ── 恢复产物过滤(递归套娃防线,conv 76730ce8 seq 250 实证) ──
|
||||
|
||||
/// 构造一条上一代恢复消息全文(截 200 字符,复刻 begin_turn 误记目标的现场形态)。
|
||||
fn prev_recovery_text() -> String {
|
||||
let full = format!(
|
||||
"{} 应用重启导致上次任务中断,已完成进度已保留。请按以下目标快照继续完成未竟任务:\n\n有效目标:\n- 检查 各个 u-claw 实例状态\n\n若快照不足以判断进度,先向用户确认已完成步骤再继续。",
|
||||
RECOVERY_ARTIFACT_PREFIX
|
||||
);
|
||||
full.chars().take(200).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recovery_message_zero_nesting_with_polluted_goals() {
|
||||
use df_ai::context_helpers::GoalStatus;
|
||||
// 嵌套恢复现场:WorkingContext.goals 与 pinned_goals 都躺着上一条恢复消息全文,
|
||||
// 两侧 Active——未过滤时它会被当有效目标嵌进新恢复消息(套娃逐层加深)。
|
||||
let wc = wc_with_goals(&[
|
||||
(&prev_recovery_text(), GoalStatus::Active),
|
||||
("交付 v2 登录接口", GoalStatus::Active),
|
||||
]);
|
||||
let pinned = vec![
|
||||
crate::commands::ai::GoalEntry::new(prev_recovery_text()),
|
||||
crate::commands::ai::GoalEntry::new("补齐单测覆盖".to_string()),
|
||||
];
|
||||
let msg = build_recovery_message(&wc, &pinned);
|
||||
// 输出只允许保留消息头一处恢复前缀(零套娃),正常用户目标不受影响
|
||||
assert_eq!(
|
||||
msg.matches(RECOVERY_ARTIFACT_PREFIX).count(),
|
||||
1,
|
||||
"恢复产物目标必须被剔除,输出仅消息头一处前缀: {msg}"
|
||||
);
|
||||
assert!(msg.contains("交付 v2 登录接口"), "正常用户目标须保留: {msg}");
|
||||
assert!(msg.contains("补齐单测覆盖"), "正常钉扎目标须保留: {msg}");
|
||||
assert!(
|
||||
!msg.contains("有效目标:\n- [系统恢复]"),
|
||||
"上一代恢复消息不得作为目标行回放: {msg}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recovery_message_all_polluted_falls_back_to_constant() {
|
||||
use df_ai::context_helpers::GoalStatus;
|
||||
// 快照只剩恢复产物(历史最深套娃态):全部过滤后回退常量,套娃链在此截断
|
||||
let wc = wc_with_goals(&[(&prev_recovery_text(), GoalStatus::Active)]);
|
||||
let pinned = vec![crate::commands::ai::GoalEntry::new(prev_recovery_text())];
|
||||
assert_eq!(
|
||||
build_recovery_message(&wc, &pinned),
|
||||
PARKED_RECOVERY_MESSAGE,
|
||||
"全污染快照过滤后按空快照回退常量"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_pinned_goals_drops_recovery_artifacts_idempotent() {
|
||||
// 存量污染反解剔除:恢复前缀条目不进内存(幂等——清洗后再解析结果不变)
|
||||
let polluted = serde_json::to_string(&vec![
|
||||
crate::commands::ai::GoalEntry::new(prev_recovery_text()),
|
||||
crate::commands::ai::GoalEntry::new("正常目标保留".to_string()),
|
||||
])
|
||||
.unwrap();
|
||||
let parsed = parse_pinned_goals(Some(&polluted));
|
||||
assert_eq!(parsed.len(), 1, "恢复产物条目须剔除: {parsed:?}");
|
||||
assert_eq!(parsed[0].text, "正常目标保留");
|
||||
// 幂等:清洗结果重解析不变
|
||||
let cleaned = serde_json::to_string(&parsed).unwrap();
|
||||
assert_eq!(parse_pinned_goals(Some(&cleaned)).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_pinned_goals_drops_injection_artifacts() {
|
||||
// E5:[补充指令] 是通道标记非任务意图(434c8c40「[补充指令] 123 hi」占位实证),
|
||||
// 与恢复产物同治——载入侧剔除,下轮 save 重写自愈。
|
||||
let polluted = serde_json::to_string(&vec![
|
||||
crate::commands::ai::GoalEntry::new("[补充指令] 123 hi".to_string()),
|
||||
crate::commands::ai::GoalEntry::new("升级工具链到最新版".to_string()),
|
||||
])
|
||||
.unwrap();
|
||||
let parsed = parse_pinned_goals(Some(&polluted));
|
||||
assert_eq!(parsed.len(), 1, "注入产物条目须剔除: {parsed:?}");
|
||||
assert_eq!(parsed[0].text, "升级工具链到最新版");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
use tauri::State;
|
||||
|
||||
use crate::commands::ai::knowledge_inject::resolve_source_project;
|
||||
|
||||
/// 单条脉络摘要(字段前端契约,snake_case)
|
||||
#[derive(serde::Serialize, Clone, Debug)]
|
||||
pub struct ContextBrief {
|
||||
@@ -14,12 +16,19 @@ pub struct ContextBrief {
|
||||
pub source_ref: Option<String>,
|
||||
pub source_project: Option<String>,
|
||||
pub reuse_count: i32,
|
||||
/// 知识条目最近更新时间,原样透供前端展示「这条什么时候定的」
|
||||
pub updated_at: String,
|
||||
/// 可跳转的来源会话 id(自 source_ref 解析,消息级引用经 ai_messages 反查);
|
||||
/// 解析不出(无源/引用失效)为 None,前端降级纯文本标题
|
||||
pub source_conv: Option<String>,
|
||||
}
|
||||
|
||||
/// 项目脉络分组
|
||||
#[derive(serde::Serialize, Clone, Debug)]
|
||||
pub struct ProjectBriefs {
|
||||
pub source_project: String,
|
||||
/// 是否为当前会话归属项目(仅传 focus_conv 且解析命中时为 true,前端做置顶高亮)
|
||||
pub focused: bool,
|
||||
pub briefs: Vec<ContextBrief>,
|
||||
}
|
||||
|
||||
@@ -35,12 +44,91 @@ fn truncate_chars(s: &str, max: usize) -> String {
|
||||
out
|
||||
}
|
||||
|
||||
/// source_ref 溯源引用的三种形态:对话级 `conv:{id}` 直接可跳;
|
||||
/// 消息级 `conv_msg:{msg_id}` 须查 ai_messages 反查会话;其余(空/异形)不可跳。
|
||||
enum SourceConvRef {
|
||||
Conv(String),
|
||||
Msg(String),
|
||||
None,
|
||||
}
|
||||
|
||||
fn parse_source_conv(source_ref: Option<&str>) -> SourceConvRef {
|
||||
let Some(r) = source_ref else {
|
||||
return SourceConvRef::None;
|
||||
};
|
||||
if let Some(id) = r.strip_prefix("conv:") {
|
||||
if id.is_empty() {
|
||||
return SourceConvRef::None;
|
||||
}
|
||||
return SourceConvRef::Conv(id.to_string());
|
||||
}
|
||||
if let Some(id) = r.strip_prefix("conv_msg:") {
|
||||
if id.is_empty() {
|
||||
return SourceConvRef::None;
|
||||
}
|
||||
return SourceConvRef::Msg(id.to_string());
|
||||
}
|
||||
SourceConvRef::None
|
||||
}
|
||||
|
||||
/// 回填 source_conv:对话级引用直接取 id,消息级引用批量反查 ai_messages(一条 IN 查询,
|
||||
/// 引用失效/表查不到保持 None,前端降级纯文本)。
|
||||
async fn fill_source_convs(db: &df_storage::db::Database, groups: &mut [ProjectBriefs]) {
|
||||
for g in groups.iter_mut() {
|
||||
for b in g.briefs.iter_mut() {
|
||||
if let SourceConvRef::Conv(id) = parse_source_conv(b.source_ref.as_deref()) {
|
||||
b.source_conv = Some(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
let msg_ids: Vec<String> = groups
|
||||
.iter()
|
||||
.flat_map(|g| g.briefs.iter())
|
||||
.filter_map(|b| match parse_source_conv(b.source_ref.as_deref()) {
|
||||
SourceConvRef::Msg(id) => Some(id),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<std::collections::HashSet<_>>()
|
||||
.into_iter()
|
||||
.collect();
|
||||
if msg_ids.is_empty() {
|
||||
return;
|
||||
}
|
||||
let conn = db.conn();
|
||||
let guard = conn.lock().await;
|
||||
let Ok(mut stmt) = guard.prepare("SELECT conversation_id FROM ai_messages WHERE id = ?1")
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let mut found: std::collections::HashMap<String, String> = std::collections::HashMap::new();
|
||||
for id in &msg_ids {
|
||||
if let Ok(rows) = stmt.query_map([id], |row| row.get::<_, String>(0)) {
|
||||
for conv_id in rows.flatten() {
|
||||
found.insert(id.clone(), conv_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
drop(stmt);
|
||||
for g in groups.iter_mut() {
|
||||
for b in g.briefs.iter_mut() {
|
||||
if b.source_conv.is_some() {
|
||||
continue;
|
||||
}
|
||||
if let SourceConvRef::Msg(id) = parse_source_conv(b.source_ref.as_deref()) {
|
||||
b.source_conv = found.get(&id).cloned();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 聚合纯函数:published 记录 → 按项目分组脉络。无归属项目(source_project None)的知识
|
||||
/// 不入脉络卡(无分组锚点,注入侧 top-3 已覆盖全局知识);每组按 reuse_count 降序(唯一
|
||||
/// 客观信号),组间按组内最高复用数降序(活跃项目排前)。
|
||||
/// 客观信号),组间按组内最高复用数降序(活跃项目排前);`focus_project` 命中的组置顶
|
||||
/// (当前会话归属项目优先展示),未命中/不传时顺序与置顶逻辑不存在时完全一致。
|
||||
fn aggregate_briefs(
|
||||
records: Vec<df_storage::models::KnowledgeRecord>,
|
||||
per_project: usize,
|
||||
focus_project: Option<&str>,
|
||||
) -> Vec<ProjectBriefs> {
|
||||
use std::collections::HashMap;
|
||||
let mut groups: HashMap<String, Vec<ContextBrief>> = HashMap::new();
|
||||
@@ -54,6 +142,8 @@ fn aggregate_briefs(
|
||||
source_ref: r.source_ref,
|
||||
source_project: Some(proj.clone()),
|
||||
reuse_count: r.reuse_count,
|
||||
updated_at: r.updated_at,
|
||||
source_conv: None,
|
||||
};
|
||||
groups.entry(proj).or_default().push(brief);
|
||||
}
|
||||
@@ -62,29 +152,45 @@ fn aggregate_briefs(
|
||||
.map(|(source_project, mut briefs)| {
|
||||
briefs.sort_by(|a, b| b.reuse_count.cmp(&a.reuse_count));
|
||||
briefs.truncate(per_project);
|
||||
ProjectBriefs { source_project, briefs }
|
||||
let focused = focus_project == Some(source_project.as_str());
|
||||
ProjectBriefs { source_project, focused, briefs }
|
||||
})
|
||||
.collect();
|
||||
out.sort_by(|a, b| {
|
||||
let top = |g: &ProjectBriefs| g.briefs.first().map(|b| b.reuse_count).unwrap_or(0);
|
||||
top(b).cmp(&top(a))
|
||||
});
|
||||
if let Some(focus) = focus_project {
|
||||
if let Some(pos) = out.iter().position(|g| g.source_project == focus) {
|
||||
let focused_group = out.remove(pos);
|
||||
out.insert(0, focused_group);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// 脉络卡数据:published 知识按 source_project 聚合(每项目取复用最高的 `per_project` 条)。
|
||||
/// `focus_conv` 传当前会话 id 时解析其归属项目,命中组置顶并带 `focused` 标记;解析失败/
|
||||
/// 无归属时与不传该参数行为完全一致(软排序只调顺序,不报错不缩面)。
|
||||
/// 纯读侧,无状态无副作用;knowledge 表空/无归属项目时返空(前端不渲染卡)。
|
||||
#[tauri::command]
|
||||
pub async fn ai_context_briefs(
|
||||
state: State<'_, crate::AppState>,
|
||||
per_project: Option<usize>,
|
||||
focus_conv: Option<String>,
|
||||
) -> Result<Vec<ProjectBriefs>, String> {
|
||||
let records = state
|
||||
.knowledge
|
||||
.list_by_status("published")
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(aggregate_briefs(records, per_project.unwrap_or(5)))
|
||||
let focus_project = match focus_conv.as_deref() {
|
||||
Some(conv_id) => resolve_source_project(&state.db, conv_id, &[]).await,
|
||||
None => None,
|
||||
};
|
||||
let mut out = aggregate_briefs(records, per_project.unwrap_or(5), focus_project.as_deref());
|
||||
fill_source_convs(&state.db, &mut out).await;
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -119,10 +225,11 @@ mod tests {
|
||||
rec("乙项目", "c3", Some("proj-b"), 3),
|
||||
rec("无归属不入卡", "c4", None, 99),
|
||||
];
|
||||
let out = aggregate_briefs(recs, 5);
|
||||
let out = aggregate_briefs(recs, 5, None);
|
||||
assert_eq!(out.len(), 2, "两项目分组,无归属剔除: {out:?}");
|
||||
assert_eq!(out[0].source_project, "proj-a", "组间按最高复用降序");
|
||||
assert_eq!(out[0].briefs[0].title, "甲项目高复用", "组内按复用降序");
|
||||
assert!(out.iter().all(|g| !g.focused), "无 focus 时任何组不带置顶标记");
|
||||
assert!(out.iter().all(|g| g.briefs.iter().all(|b| b.source_project.is_some())));
|
||||
}
|
||||
|
||||
@@ -131,8 +238,121 @@ mod tests {
|
||||
let recs: Vec<_> = (0..8)
|
||||
.map(|i| rec(&format!("条{i}"), &"长".repeat(200), Some("proj"), i))
|
||||
.collect();
|
||||
let out = aggregate_briefs(recs, 3);
|
||||
let out = aggregate_briefs(recs, 3, None);
|
||||
assert_eq!(out[0].briefs.len(), 3, "每项目截断到 per_project");
|
||||
assert!(out[0].briefs[0].summary.chars().count() <= BRIEF_SUMMARY_MAX_CHARS + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_project_group_moves_to_front() {
|
||||
let recs = vec![
|
||||
rec("乙高复用", "c1", Some("proj-b"), 9),
|
||||
rec("甲低复用", "c2", Some("proj-a"), 1),
|
||||
];
|
||||
let out = aggregate_briefs(recs, 5, Some("proj-a"));
|
||||
assert_eq!(out[0].source_project, "proj-a", "会话归属项目组置顶(复用更低也排前): {out:?}");
|
||||
assert!(out[0].focused, "命中组带 focused 标记");
|
||||
assert!(!out[1].focused, "非命中组保持 focused=false");
|
||||
}
|
||||
|
||||
fn group_order(groups: &[ProjectBriefs]) -> Vec<&str> {
|
||||
groups.iter().map(|g| g.source_project.as_str()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_unmatched_project_keeps_order() {
|
||||
let recs = vec![
|
||||
rec("乙高复用", "c1", Some("proj-b"), 9),
|
||||
rec("甲低复用", "c2", Some("proj-a"), 1),
|
||||
];
|
||||
let plain = aggregate_briefs(recs.clone(), 5, None);
|
||||
let unmatched = aggregate_briefs(recs, 5, Some("proj-x"));
|
||||
assert_eq!(group_order(&plain), group_order(&unmatched), "解析无归属/未知项目时顺序不变");
|
||||
assert!(unmatched.iter().all(|g| !g.focused), "无命中组不误标记");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brief_carries_updated_at() {
|
||||
let mut r = rec("条目", "c", Some("proj"), 1);
|
||||
r.updated_at = "1777777777".into();
|
||||
let out = aggregate_briefs(vec![r], 5, None);
|
||||
assert_eq!(out[0].briefs[0].updated_at, "1777777777", "updated_at 原样透传");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_ref_parses_to_conv_msg_or_none() {
|
||||
assert!(matches!(
|
||||
parse_source_conv(Some("conv:abc-1")),
|
||||
SourceConvRef::Conv(id) if id == "abc-1"
|
||||
));
|
||||
assert!(matches!(
|
||||
parse_source_conv(Some("conv_msg:msg_123_4")),
|
||||
SourceConvRef::Msg(id) if id == "msg_123_4"
|
||||
));
|
||||
assert!(matches!(parse_source_conv(Some("conv:")), SourceConvRef::None));
|
||||
assert!(matches!(parse_source_conv(Some("weird:x")), SourceConvRef::None));
|
||||
assert!(matches!(parse_source_conv(None), SourceConvRef::None));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn fill_source_convs_resolves_both_ref_kinds() {
|
||||
let db = df_storage::db::Database::open_in_memory()
|
||||
.await
|
||||
.expect("内存库");
|
||||
{
|
||||
let conn = db.conn();
|
||||
let guard = conn.lock().await;
|
||||
guard
|
||||
.execute(
|
||||
"CREATE TABLE IF NOT EXISTS ai_messages (id TEXT PRIMARY KEY, conversation_id TEXT NOT NULL)",
|
||||
[],
|
||||
)
|
||||
.expect("建表");
|
||||
guard
|
||||
.execute(
|
||||
"INSERT INTO ai_messages (id, conversation_id, seq, role, created_at) VALUES \
|
||||
('msg_1_0', 'conv-a', 1, 'assistant', '0'), ('msg_2_0', 'conv-b', 2, 'assistant', '0')",
|
||||
[],
|
||||
)
|
||||
.expect("造数");
|
||||
}
|
||||
let mut groups = vec![ProjectBriefs {
|
||||
source_project: "proj".into(),
|
||||
focused: false,
|
||||
briefs: vec![
|
||||
ContextBrief {
|
||||
title: "对话级".into(),
|
||||
summary: "s".into(),
|
||||
source_ref: Some("conv:conv-a".into()),
|
||||
source_project: Some("proj".into()),
|
||||
reuse_count: 2,
|
||||
updated_at: "1".into(),
|
||||
source_conv: None,
|
||||
},
|
||||
ContextBrief {
|
||||
title: "消息级".into(),
|
||||
summary: "s".into(),
|
||||
source_ref: Some("conv_msg:msg_2_0".into()),
|
||||
source_project: Some("proj".into()),
|
||||
reuse_count: 1,
|
||||
updated_at: "1".into(),
|
||||
source_conv: None,
|
||||
},
|
||||
ContextBrief {
|
||||
title: "失效引用".into(),
|
||||
summary: "s".into(),
|
||||
source_ref: Some("conv_msg:msg_gone".into()),
|
||||
source_project: Some("proj".into()),
|
||||
reuse_count: 0,
|
||||
updated_at: "1".into(),
|
||||
source_conv: None,
|
||||
},
|
||||
],
|
||||
}];
|
||||
fill_source_convs(&db, &mut groups).await;
|
||||
let briefs = &groups[0].briefs;
|
||||
assert_eq!(briefs[0].source_conv.as_deref(), Some("conv-a"), "对话级直接取 id");
|
||||
assert_eq!(briefs[1].source_conv.as_deref(), Some("conv-b"), "消息级反查回填");
|
||||
assert_eq!(briefs[2].source_conv, None, "失效引用降级 None");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,702 @@
|
||||
//! devflow.md / CLAUDE.md 项目认知投影(项目规则文件 + 知识库路标 → system prompt 稳定尾段)。
|
||||
//!
|
||||
//! 定位:对标 CLAUDE.md 的"启动读一遍静态规则文件",本土化为双文件并读——
|
||||
//! - `devflow.md`:agent 生态自己的项目认知文件,v1 取两个分区(规范纪律 / 领单);
|
||||
//! - `CLAUDE.md`:既有通用约定,同目录存在则并入(增强非依赖)。
|
||||
//! 两文件并存时 devflow.md 优先(段内排序在前 + 显式冲突注明)。
|
||||
//!
|
||||
//! 知识路标子段(知识投影 v2):规则文件只说"该怎么做",路标补"库里有啥"——已发布且
|
||||
//! (人工验证或复用达标)的知识条目按「同项目档 + 跨项目补充档」铺开成紧凑行,
|
||||
//! 让 agent 知晓知识库藏、在工具故障/重复失败时想起用 knowledge_search 检索,
|
||||
//! 而不是死磕。读侧走 df-storage [`KnowledgeRepo::list_waymark`],会话项目归属复用
|
||||
//! [`resolve_source_project`] 既有机制,不自写 SQL 不造双轨。
|
||||
//!
|
||||
//! 缓存红线:投影段纯追加在 system prompt 全部既有段之后,内容按会话缓存——
|
||||
//! 同一会话(含其派生的子代理)只在首次组装时读一次盘 + 查一次库,此后复用同一文本,
|
||||
//! 保证段内容会话内逐字节不变,不击穿 provider 的 prompt 缓存前缀。
|
||||
//! 会话粒度取 conv_id 作缓存键:新会话重新组装(拿到文件与库的最新内容),旧会话不受扰动。
|
||||
//!
|
||||
//! 海纳川流:两文件缺失 / 读取失败 / 内容为空,且知识库无合格条目 → 投影段为空,
|
||||
//! prompt 与不接本模块逐字一致(规则文件与路标都是增强输入,缺失不影响内生运作)。
|
||||
//!
|
||||
//! 裁剪纪律:注入的 token 才是成本——规则分区按字符上限截断,路标条目数被查询
|
||||
//! LIMIT 封顶 + 行内标题截断,整体体量有界。超限按 Unicode 字符截断
|
||||
//! (中文一字一符,按字节会截断 UTF-8 序列产生乱码)并注明。
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
use df_storage::crud::KnowledgeRepo;
|
||||
use df_storage::db::Database;
|
||||
use df_storage::models::KnowledgeRecord;
|
||||
|
||||
use crate::state::AllowedDirs;
|
||||
|
||||
// ── 裁剪上限(字符数,中文一字一符) ──
|
||||
//
|
||||
// 分区上限兜住单分区体量,总上限兜住整段体量;取值按"规范纪律最厚、领单次之、
|
||||
// CLAUDE.md 与纪律区同量级"的内容形态分配,叠加后总上限仍可能触发二次截断。
|
||||
/// 规范纪律分区上限
|
||||
const DISCIPLINE_MAX_CHARS: usize = 4000;
|
||||
/// 领单分区上限
|
||||
const CLAIM_MAX_CHARS: usize = 2000;
|
||||
/// CLAUDE.md 并入段上限
|
||||
const CLAUDE_MD_MAX_CHARS: usize = 4000;
|
||||
/// 投影段总上限(各分区叠加后的二次硬闸)
|
||||
const SECTION_MAX_CHARS: usize = 6000;
|
||||
|
||||
/// 投影段缓存上限(条目)。会话粒度缓存,长跑进程防内存膨胀;超限整体清空
|
||||
/// (清空后下次组装重读盘,内容只会更新不会错,正确性不受损)。
|
||||
const SECTION_CACHE_MAX: usize = 64;
|
||||
|
||||
// ── 知识路标子段参数 ──
|
||||
//
|
||||
// 条目数由查询 LIMIT 封顶(项目档 + 补充档),行内标题截断注省略号——双层结构上界
|
||||
// 使路标块体量有界(约 30 行 × 行宽上限),无须再设整块字符闸。
|
||||
/// 会话归属项目档上限(条)
|
||||
const WAYMARK_PROJECT_MAX: usize = 20;
|
||||
/// 跨项目补充档上限(条)
|
||||
const WAYMARK_GLOBAL_MAX: usize = 10;
|
||||
/// 路标行标题上限(字符):超长截断防长标题破坏紧凑行形态
|
||||
const WAYMARK_TITLE_MAX_CHARS: usize = 60;
|
||||
|
||||
/// devflow.md 规范分区识别的标题关键字(领单优先判,防"领单纪律"被纪律关键字截胡)
|
||||
const CLAIM_HEADING_KEY: &str = "领单";
|
||||
const DISCIPLINE_HEADING_KEYS: [&str; 2] = ["纪律", "规范"];
|
||||
|
||||
static SECTION_CACHE: OnceLock<Mutex<HashMap<String, String>>> = OnceLock::new();
|
||||
|
||||
fn section_cache() -> &'static Mutex<HashMap<String, String>> {
|
||||
SECTION_CACHE.get_or_init(|| Mutex::new(HashMap::new()))
|
||||
}
|
||||
|
||||
/// 知识库读侧句柄:进程级 AppHandle → AppState.db(生产装配点,与 spawn_agent 全局
|
||||
/// 同款"注册期无法捕获、运行期读取"形态)。AppHandle 未注入 / AppState 未托管
|
||||
/// (早期启动、单元测试)→ None,路标子块整体缺席,其余组装零扰动。
|
||||
fn knowledge_db() -> Option<Arc<Database>> {
|
||||
use tauri::Manager;
|
||||
let app = crate::commands::ai::tools::spawn_agent::app_handle()?;
|
||||
let state = app.try_state::<crate::state::AppState>()?;
|
||||
Some(state.db.clone())
|
||||
}
|
||||
|
||||
/// 工作目录解析:首个持久授权目录(排序取首稳定)。
|
||||
///
|
||||
/// 与主链被监视工作区取同一约定,保证主会话与子代理对"项目根"的认知一致;
|
||||
/// HashSet 迭代序不定,必须排序后取首才是稳定值。
|
||||
pub(crate) fn work_dir_of(allowed: &AllowedDirs) -> Option<String> {
|
||||
let mut dirs: Vec<PathBuf> = allowed.persistent.iter().cloned().collect();
|
||||
dirs.sort();
|
||||
dirs.first().map(|p| p.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
/// 把投影段纯追加到 system prompt 尾部(两条组装路径的统一入口)。
|
||||
///
|
||||
/// 无投影内容时原样返回(调用方 prompt 逐字不变);有则 `\n\n` 接续,
|
||||
/// 调用方既有段内容不受任何影响(稳定尾段语义)。
|
||||
pub(crate) async fn append_projection(prompt: String, work_dir: Option<&str>, conv_id: &str) -> String {
|
||||
let kb = knowledge_db();
|
||||
match projection_section(work_dir, conv_id, kb).await {
|
||||
Some(seg) => format!("{}\n\n{}", prompt, seg),
|
||||
None => prompt,
|
||||
}
|
||||
}
|
||||
|
||||
/// 取会话的投影段:缓存命中直接复用(同会话零重复读盘查库);未命中组装一次并入缓存。
|
||||
///
|
||||
/// 缓存值空串 = 本会话已知无投影(文件缺失且库无合格条目),同样走缓存避免每轮白查。
|
||||
/// 子代理以父会话 conv_id 作键,天然复用父会话已读内容。
|
||||
/// `kb`:知识库读侧句柄(None = 单元测试/未托管态,路标子块整体缺席)。
|
||||
async fn projection_section(work_dir: Option<&str>, conv_id: &str, kb: Option<Arc<Database>>) -> Option<String> {
|
||||
{
|
||||
let cache = section_cache().lock().unwrap_or_else(|p| p.into_inner());
|
||||
if let Some(hit) = cache.get(conv_id) {
|
||||
return (!hit.is_empty()).then(|| hit.clone());
|
||||
}
|
||||
}
|
||||
let dir = work_dir.map(PathBuf::from);
|
||||
let conv = conv_id.to_string();
|
||||
// 规则文件读盘(阻塞线程池,失败按缺失处理)与知识路标查库相互独立,并发取
|
||||
let (files, waymark) = tokio::join!(
|
||||
tokio::task::spawn_blocking(move || read_pair(dir)),
|
||||
async {
|
||||
match kb {
|
||||
Some(db) => build_waymark(&db, &conv).await,
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
);
|
||||
let (devflow, claude) = files.unwrap_or_else(|_| (None, None));
|
||||
let (discipline, claiming) = devflow
|
||||
.as_deref()
|
||||
.map(extract_partitions)
|
||||
.unwrap_or((String::new(), String::new()));
|
||||
let section = combine_sections(build_section(&discipline, &claiming, claude.as_deref()), waymark);
|
||||
let mut cache = section_cache().lock().unwrap_or_else(|p| p.into_inner());
|
||||
if cache.len() >= SECTION_CACHE_MAX {
|
||||
cache.clear();
|
||||
}
|
||||
cache.insert(conv_id.to_string(), section.clone().unwrap_or_default());
|
||||
section
|
||||
}
|
||||
|
||||
/// 规则文件投影 + 知识路标子块的拼装(纯函数):路标恒居规则投影之后(同一稳定尾段内);
|
||||
/// 双双缺席 → None(调用方零追加,零回归)。仅路标在场 → 路标独占投影段(规则文件头语不出现)。
|
||||
fn combine_sections(rules: Option<String>, waymark: Option<String>) -> Option<String> {
|
||||
match (rules, waymark) {
|
||||
(Some(mut rules), Some(wm)) => {
|
||||
rules.push_str("\n\n");
|
||||
rules.push_str(&wm);
|
||||
Some(rules)
|
||||
}
|
||||
(Some(rules), None) => Some(rules),
|
||||
(None, Some(wm)) => Some(format!("## 项目认知投影\n\n{wm}")),
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// 组装知识路标子块:解析会话归属项目(既有机制) → 两档查询 → 渲染紧凑行。
|
||||
/// 查询失败降级缺席(warn 留痕,不阻断组装:路标是增强输入,故障不该影响 prompt 主链)。
|
||||
async fn build_waymark(db: &Arc<Database>, conv_id: &str) -> Option<String> {
|
||||
let project = crate::commands::ai::knowledge_inject::resolve_source_project(db, conv_id, &[]).await;
|
||||
match KnowledgeRepo::new(db)
|
||||
.list_waymark(project.as_deref(), WAYMARK_PROJECT_MAX, WAYMARK_GLOBAL_MAX)
|
||||
.await
|
||||
{
|
||||
Ok(list) if !list.is_empty() => Some(render_waymark(&list)),
|
||||
Ok(_) => None,
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, conv_id, "[devflow-md] 知识路标查询失败,子块缺席");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 渲染路标子块(纯函数):段首说明 + 紧凑行 + 段尾固定提示。
|
||||
/// 标题压平空白(库内标题可能含换行,直拼会破坏单行形态)并截断注省略号;
|
||||
/// 空白标题条目跳过(渲染不出可读行的脏数据不入段)。
|
||||
fn render_waymark(entries: &[KnowledgeRecord]) -> String {
|
||||
let mut wm = String::from("### 知识库路标\n项目知识库路标(详情用 knowledge_search 按标题关键词检索)");
|
||||
for e in entries {
|
||||
let flat = e.title.split_whitespace().collect::<Vec<_>>().join(" ");
|
||||
if flat.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let count = flat.chars().count();
|
||||
let mut title: String = flat.chars().take(WAYMARK_TITLE_MAX_CHARS).collect();
|
||||
if count > WAYMARK_TITLE_MAX_CHARS {
|
||||
title.push('…');
|
||||
}
|
||||
wm.push_str(&format!("\n- {title} | 复用{}次", e.reuse_count));
|
||||
}
|
||||
wm.push_str("\n上述经验条目可直接复用;遇到工具故障/重复失败先检索路标");
|
||||
wm
|
||||
}
|
||||
|
||||
/// 读工作目录下的两份规则文件,内容 trim 后返回;目录缺失 / 读失败 / 空白内容 → None。
|
||||
fn read_pair(dir: Option<PathBuf>) -> (Option<String>, Option<String>) {
|
||||
let Some(dir) = dir else {
|
||||
return (None, None);
|
||||
};
|
||||
(read_trimmed(&dir.join("devflow.md")), read_trimmed(&dir.join("CLAUDE.md")))
|
||||
}
|
||||
|
||||
fn read_trimmed(path: &Path) -> Option<String> {
|
||||
std::fs::read_to_string(path)
|
||||
.ok()
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
/// 拼装规则文件投影段(纯函数):分区截取、上限截断、优先级注明都在这里定形。
|
||||
/// 三路输入全空 → None(路标子块在场时由 combine_sections 单独成段)。
|
||||
fn build_section(discipline: &str, claiming: &str, claude: Option<&str>) -> Option<String> {
|
||||
let claude = claude.map(str::trim).filter(|c| !c.is_empty());
|
||||
if discipline.is_empty() && claiming.is_empty() && claude.is_none() {
|
||||
return None;
|
||||
}
|
||||
let has_devflow = !discipline.is_empty() || !claiming.is_empty();
|
||||
let mut sec = String::from("## 项目认知投影\n以下规则来自项目仓库文件(会话启动时读取)");
|
||||
// 优先级只在双文件并存时注明,单文件无冲突可注明
|
||||
if has_devflow && claude.is_some() {
|
||||
sec.push_str(",devflow.md 与 CLAUDE.md 并存,冲突以 devflow.md 为准");
|
||||
}
|
||||
sec.push(':');
|
||||
|
||||
if !discipline.is_empty() {
|
||||
sec.push_str("\n\n### 规范纪律(devflow.md)\n");
|
||||
sec.push_str(&cap_chars(discipline, DISCIPLINE_MAX_CHARS));
|
||||
}
|
||||
if !claiming.is_empty() {
|
||||
sec.push_str("\n\n### 领单纪律(devflow.md)\n");
|
||||
sec.push_str(&cap_chars(claiming, CLAIM_MAX_CHARS));
|
||||
}
|
||||
if let Some(cla) = claude {
|
||||
sec.push_str("\n\n### 项目规范(CLAUDE.md)\n");
|
||||
sec.push_str(&cap_chars(cla, CLAUDE_MD_MAX_CHARS));
|
||||
}
|
||||
|
||||
// 总上限二次硬闸:各分区上限叠加后仍可能超,整段再截一次
|
||||
if sec.chars().count() > SECTION_MAX_CHARS {
|
||||
let cut: String = sec.chars().take(SECTION_MAX_CHARS).collect();
|
||||
return Some(format!("{}\n…(投影段超出总上限已截断)", cut));
|
||||
}
|
||||
Some(sec)
|
||||
}
|
||||
|
||||
/// 按字符数截断并注明(纯函数):超 `max` 截断追加标注,否则原样返回。
|
||||
fn cap_chars(s: &str, max: usize) -> String {
|
||||
if s.chars().count() <= max {
|
||||
return s.to_string();
|
||||
}
|
||||
let cut: String = s.chars().take(max).collect();
|
||||
format!("{}\n…(超上限已截断)", cut)
|
||||
}
|
||||
|
||||
// ── devflow.md 分区解析 ──
|
||||
//
|
||||
// v1 取两个分区:规范纪律 / 领单。识别方式 = markdown 标题关键字命中,命中块的
|
||||
// 更深层子标题视为块内子结构一并保留;未命中关键标题的块不注入(状态/警示类
|
||||
// 分区不属 v1 范围,天然被裁掉)。全文无命中分区的扁平写法回退为整文件按
|
||||
// 规范纪律处理——规则文件形态与 CLAUDE.md 同构,不因没写小节标题而失传。
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum Partition {
|
||||
Discipline,
|
||||
Claim,
|
||||
}
|
||||
|
||||
/// 识别 markdown 标题行,返回 (级别, 标题文本);非标题 / 纯装饰线 → None。
|
||||
fn heading_of(line: &str) -> Option<(usize, &str)> {
|
||||
let t = line.trim_start();
|
||||
let level = t.len() - t.trim_start_matches('#').len();
|
||||
if level == 0 || level > 6 {
|
||||
return None;
|
||||
}
|
||||
let text = t[level..].trim();
|
||||
if text.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some((level, text))
|
||||
}
|
||||
|
||||
fn classify_heading(text: &str) -> Option<Partition> {
|
||||
if text.contains(CLAIM_HEADING_KEY) {
|
||||
return Some(Partition::Claim);
|
||||
}
|
||||
if DISCIPLINE_HEADING_KEYS.iter().any(|k| text.contains(k)) {
|
||||
return Some(Partition::Discipline);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// 从 devflow.md 全文提取 (规范纪律, 领单) 两个分区正文(纯函数,未截断)。
|
||||
fn extract_partitions(content: &str) -> (String, String) {
|
||||
let mut discipline: Vec<String> = Vec::new();
|
||||
let mut claiming: Vec<String> = Vec::new();
|
||||
// 当前块:(分区, 起始标题级别, 正文);正文不含起始标题行(投影段会重加小标题)
|
||||
let mut cur: Option<(Partition, usize, String)> = None;
|
||||
|
||||
for line in content.lines() {
|
||||
let heading = heading_of(line);
|
||||
// 块边界:块内遇到不深于起始层级的标题 → 收块,由新标题决定是否开下一块
|
||||
let boundary = matches!((&cur, &heading), (Some((_, lv, _)), Some((h_lv, _))) if h_lv <= lv);
|
||||
if boundary {
|
||||
let (kind, _, body) = cur.take().expect("boundary 判定保证 cur 存在");
|
||||
push_block(kind, body, &mut discipline, &mut claiming);
|
||||
} else if let Some((_, _, body)) = cur.as_mut() {
|
||||
// 更深层级标题属块内子结构,连行保留
|
||||
body.push_str(line);
|
||||
body.push('\n');
|
||||
continue;
|
||||
}
|
||||
if let Some((lv, text)) = heading {
|
||||
if let Some(kind) = classify_heading(text) {
|
||||
cur = Some((kind, lv, String::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((kind, _, body)) = cur.take() {
|
||||
push_block(kind, body, &mut discipline, &mut claiming);
|
||||
}
|
||||
|
||||
let dev = discipline.join("\n").trim().to_string();
|
||||
let claim = claiming.join("\n").trim().to_string();
|
||||
if dev.is_empty() && claim.is_empty() {
|
||||
return (content.trim().to_string(), String::new());
|
||||
}
|
||||
(dev, claim)
|
||||
}
|
||||
|
||||
fn push_block(kind: Partition, body: String, discipline: &mut Vec<String>, claiming: &mut Vec<String>) {
|
||||
let trimmed = body.trim();
|
||||
if trimmed.is_empty() {
|
||||
return;
|
||||
}
|
||||
match kind {
|
||||
Partition::Discipline => discipline.push(trimmed.to_string()),
|
||||
Partition::Claim => claiming.push(trimmed.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
/// 测试临时目录计数器:进程内唯一,防并发测试互踩 + 防缓存键串扰
|
||||
static TMP_SEQ: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
fn unique_tag() -> String {
|
||||
format!("{}-{}", std::process::id(), TMP_SEQ.fetch_add(1, Ordering::SeqCst))
|
||||
}
|
||||
|
||||
fn temp_project_dir() -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("devflow-md-test-{}", unique_tag()));
|
||||
std::fs::create_dir_all(&dir).expect("建临时目录");
|
||||
dir
|
||||
}
|
||||
|
||||
fn write_file(dir: &Path, name: &str, content: &str) {
|
||||
std::fs::write(dir.join(name), content).expect("写测试文件");
|
||||
}
|
||||
|
||||
// ── 零回归:无两文件 → prompt 逐字不变 ──
|
||||
#[tokio::test]
|
||||
async fn missing_files_leave_prompt_unchanged() {
|
||||
let base = "BASE PROMPT 段落".to_string();
|
||||
let dir = temp_project_dir();
|
||||
let out = append_projection(base.clone(), Some(dir.to_str().unwrap()), &format!("conv-{}", unique_tag())).await;
|
||||
assert_eq!(out, base, "两文件缺失时 prompt 必须逐字不变");
|
||||
let out_no_dir = append_projection(base.clone(), None, &format!("conv-{}", unique_tag())).await;
|
||||
assert_eq!(out_no_dir, base, "无授权目录时 prompt 必须逐字不变");
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ── 只有 CLAUDE.md → 并入生效 ──
|
||||
#[tokio::test]
|
||||
async fn claude_only_merged() {
|
||||
let dir = temp_project_dir();
|
||||
write_file(&dir, "CLAUDE.md", "# 项目约定\n- 提交信息用中文");
|
||||
let out = append_projection("BASE".to_string(), Some(dir.to_str().unwrap()), &format!("conv-{}", unique_tag())).await;
|
||||
assert!(out.starts_with("BASE"), "既有段必须是前缀");
|
||||
assert!(out.contains("提交信息用中文"), "CLAUDE.md 正文须并入");
|
||||
assert!(out.contains("### 项目规范(CLAUDE.md)"), "并入段须带 CLAUDE.md 标注");
|
||||
assert!(!out.contains("devflow.md"), "仅 CLAUDE.md 时不得出现 devflow.md 标注");
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ── 双文件并存 → 优先级正确(devflow.md 在前 + 冲突注明,双内容齐备) ──
|
||||
#[tokio::test]
|
||||
async fn both_files_devflow_priority() {
|
||||
let dir = temp_project_dir();
|
||||
write_file(&dir, "devflow.md", "## 规范纪律\n- 禁 sed 改代码\n\n## 领单纪律\n- 领单后改 [→]");
|
||||
write_file(&dir, "CLAUDE.md", "# 旧约定\n- 旧规则条目");
|
||||
let out = append_projection("BASE".to_string(), Some(dir.to_str().unwrap()), &format!("conv-{}", unique_tag())).await;
|
||||
let dev_pos = out.find("禁 sed 改代码").expect("devflow.md 纪律正文须注入");
|
||||
let claim_pos = out.find("领单后改").expect("领单分区须注入");
|
||||
let claude_pos = out.find("旧规则条目").expect("CLAUDE.md 正文须并入");
|
||||
assert!(dev_pos < claude_pos && claim_pos < claude_pos, "devflow.md 内容必须排在 CLAUDE.md 之前(优先级)");
|
||||
assert!(out.contains("冲突以 devflow.md 为准"), "双文件并存须注明优先级");
|
||||
assert!(out.contains("### 规范纪律(devflow.md)"));
|
||||
assert!(out.contains("### 领单纪律(devflow.md)"));
|
||||
assert!(out.contains("### 项目规范(CLAUDE.md)"));
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ── 超长裁剪:分区上限 + 总上限生效并注明 ──
|
||||
#[test]
|
||||
fn caps_truncate_with_marker() {
|
||||
let long = "纪".repeat(DISCIPLINE_MAX_CHARS + 100);
|
||||
let section = build_section(&long, "", None).expect("非空输入必有段");
|
||||
let discipline_part = section.split("### 规范纪律(devflow.md)\n").nth(1).unwrap_or("");
|
||||
assert!(discipline_part.contains("超上限已截断"), "分区超限须注明");
|
||||
let kept = discipline_part.split("\n…(超上限已截断)").next().unwrap();
|
||||
assert_eq!(kept.chars().count(), DISCIPLINE_MAX_CHARS, "分区保留长度须恰为上限");
|
||||
|
||||
// 总上限:各分区压线 + CLAUDE.md 超量,叠加必超总闸
|
||||
let discipline = "a".repeat(DISCIPLINE_MAX_CHARS);
|
||||
let claiming = "b".repeat(CLAIM_MAX_CHARS);
|
||||
let claude = "c".repeat(CLAUDE_MD_MAX_CHARS);
|
||||
let section = build_section(&discipline, &claiming, Some(&claude)).expect("非空输入必有段");
|
||||
assert!(section.chars().count() <= SECTION_MAX_CHARS + "…(投影段超出总上限已截断)".len());
|
||||
assert!(section.ends_with("…(投影段超出总上限已截断)"), "总超限须整段截断并注明");
|
||||
}
|
||||
|
||||
// ── 稳定尾段:前段逐字保留,投影段独占尾部 ──
|
||||
#[tokio::test]
|
||||
async fn stable_tail_append() {
|
||||
let dir = temp_project_dir();
|
||||
write_file(&dir, "CLAUDE.md", "- 规则条目");
|
||||
let base = "## 行为准则\n- 既有段内容\n";
|
||||
let out = append_projection(base.to_string(), Some(dir.to_str().unwrap()), &format!("conv-{}", unique_tag())).await;
|
||||
assert!(out.starts_with(base), "既有段必须逐字保留为前缀");
|
||||
let tail = out.strip_prefix(base).unwrap();
|
||||
assert!(tail.starts_with("\n\n## 项目认知投影"), "投影段须紧跟既有段之后成稳定尾段");
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ── 会话缓存:同会话只读一次盘,文件中途改写不影响本会话;新会话读到新内容 ──
|
||||
#[tokio::test]
|
||||
async fn cached_per_conversation() {
|
||||
let dir = temp_project_dir();
|
||||
let tag = unique_tag();
|
||||
write_file(&dir, "CLAUDE.md", "- 第一版规则");
|
||||
let conv = format!("conv-{}", tag);
|
||||
let first = append_projection("B".to_string(), Some(dir.to_str().unwrap()), &conv).await;
|
||||
write_file(&dir, "CLAUDE.md", "- 第二版规则");
|
||||
let again = append_projection("B".to_string(), Some(dir.to_str().unwrap()), &conv).await;
|
||||
assert_eq!(first, again, "同会话第二次组装必须复用缓存(文件改写不影响)");
|
||||
assert!(first.contains("第一版规则"));
|
||||
let fresh = append_projection("B".to_string(), Some(dir.to_str().unwrap()), &format!("conv-{}-new", tag)).await;
|
||||
assert!(fresh.contains("第二版规则"), "新会话须重读盘拿到最新内容");
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ── 分区解析:关键字命中 / 子标题保留 / 未命中块裁掉 / 扁平回退 ──
|
||||
#[test]
|
||||
fn partition_extraction() {
|
||||
let content = "\
|
||||
# 项目认知
|
||||
|
||||
前言段落应被裁掉。
|
||||
|
||||
## 规范纪律
|
||||
- 纪律条目一
|
||||
|
||||
### 提交规范
|
||||
- 子标题下的纪律条目
|
||||
|
||||
## 看板摘要
|
||||
- 未命中关键字的块应被裁掉
|
||||
|
||||
## 领单纪律
|
||||
- 领单条目一
|
||||
";
|
||||
let (dev, claim) = extract_partitions(content);
|
||||
assert!(dev.contains("纪律条目一"), "规范纪律块须命中");
|
||||
assert!(dev.contains("子标题下的纪律条目"), "块内子标题结构须保留");
|
||||
assert!(!dev.contains("看板摘要") && !dev.contains("前言段落"), "未命中块与前言须裁掉");
|
||||
assert_eq!(claim, "- 领单条目一", "领单分区须独立提取");
|
||||
|
||||
// 扁平文件(无命中标题)回退:整文件按规范纪律
|
||||
let (dev, claim) = extract_partitions("- 扁平规则一\n- 扁平规则二\n");
|
||||
assert_eq!(dev, "- 扁平规则一\n- 扁平规则二");
|
||||
assert!(claim.is_empty());
|
||||
|
||||
// 深层标题起始的块:同级才截断
|
||||
let (dev, claim) = extract_partitions("### 领单\n- 深层领单条目\n\n## 其他\n- 其他块内容\n");
|
||||
assert_eq!(claim, "- 深层领单条目", "深层起始块到同级标题截断");
|
||||
assert!(!dev.contains("其他块内容"));
|
||||
}
|
||||
|
||||
// ── 工作目录:排序取首稳定(HashSet 迭代序不定,不排序结果不可复现) ──
|
||||
#[test]
|
||||
fn work_dir_sorted_first() {
|
||||
let mut allowed = AllowedDirs::default();
|
||||
allowed.persistent.insert(PathBuf::from("E:/wk-b/b-project"));
|
||||
allowed.persistent.insert(PathBuf::from("E:/wk-a/a-project"));
|
||||
assert_eq!(work_dir_of(&allowed).as_deref(), Some("E:/wk-a/a-project"));
|
||||
let empty = AllowedDirs::default();
|
||||
assert_eq!(work_dir_of(&empty), None, "无授权目录返 None");
|
||||
}
|
||||
|
||||
// ── 构建纯函数:全空 None / 单区缺省不产生空小节 ──
|
||||
#[test]
|
||||
fn build_section_edge_cases() {
|
||||
assert!(build_section("", "", None).is_none(), "三路全空须 None");
|
||||
assert!(build_section("", "", Some(" ")).is_none(), "空白 CLAUDE.md 视同缺失");
|
||||
let only_claim = build_section("", "- 领单规则", None).expect("单分区非空须有段");
|
||||
assert!(only_claim.contains("### 领单纪律(devflow.md)"));
|
||||
assert!(!only_claim.contains("### 规范纪律"), "空分区不得产生空小节");
|
||||
assert!(!only_claim.contains("冲突以"), "单文件不得注明双文件优先级");
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 知识路标子段(kb 句柄经 projection_section 显式注入,不经进程级全局:
|
||||
// 单测并发零串扰,append_projection 生产路径的句柄解析另由 app_handle 缺席态天然覆盖)
|
||||
// ============================================================
|
||||
|
||||
use df_storage::crud::{AiConversationRepo, ProjectRepo};
|
||||
use df_storage::models::{AiConversationRecord, KnowledgeRecord};
|
||||
|
||||
/// 知识条目 fixture(published,未验证,归属可选)
|
||||
fn kentry(id: &str, title: &str, reuse: i32, verified: bool, project: Option<&str>) -> KnowledgeRecord {
|
||||
KnowledgeRecord {
|
||||
id: id.to_string(),
|
||||
kind: "lesson".to_string(),
|
||||
title: title.to_string(),
|
||||
content: "正文".to_string(),
|
||||
tags: Some("[]".to_string()),
|
||||
status: "published".to_string(),
|
||||
confidence: None,
|
||||
reuse_count: reuse,
|
||||
verified,
|
||||
source_project: project.map(|p| p.to_string()),
|
||||
source_ref: None,
|
||||
reasoning: None,
|
||||
embedding_status: None,
|
||||
created_at: "1700000000000".to_string(),
|
||||
updated_at: "1700000000000".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// 插入测试项目(同 knowledge_inject 测试口径)
|
||||
async fn ins_project(db: &Database, id: &str, path: &str) {
|
||||
ProjectRepo::new(db)
|
||||
.insert(df_storage::models::ProjectRecord {
|
||||
id: id.into(),
|
||||
name: "路标项目".into(),
|
||||
description: String::new(),
|
||||
status: df_types::types::ProjectStatus::Planning,
|
||||
idea_id: None,
|
||||
path: Some(path.into()),
|
||||
stack: None,
|
||||
archived: false,
|
||||
created_at: "2026-01-01".into(),
|
||||
updated_at: "2026-01-01".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// 插入测试会话,带 boundary_json(dir_allowlist 单目录 → 级 a 归属解析用)
|
||||
async fn ins_conv_with_boundary(db: &Database, conv_id: &str, allow_dir: &str) {
|
||||
let boundary = crate::commands::ai::boundary::TaskBoundary {
|
||||
risk_ceiling: df_ai::ai_tools::RiskLevel::Medium,
|
||||
dir_allowlist: vec![allow_dir.to_string()],
|
||||
forbid_destructive: true,
|
||||
budget: None,
|
||||
};
|
||||
AiConversationRepo::new(db)
|
||||
.insert(AiConversationRecord {
|
||||
id: conv_id.into(),
|
||||
title: Some("t".into()),
|
||||
messages: "[]".into(),
|
||||
provider_id: None,
|
||||
model: None,
|
||||
models: None,
|
||||
archived: false,
|
||||
pinned: false,
|
||||
prompt_tokens: None,
|
||||
completion_tokens: None,
|
||||
pinned_goals: None,
|
||||
pending_approvals: None,
|
||||
created_at: "2026-01-01".into(),
|
||||
updated_at: "2026-01-01".into(),
|
||||
origin: None,
|
||||
boundary_json: Some(serde_json::to_string(&boundary).unwrap()),
|
||||
loop_state: None,
|
||||
status: "active".into(),
|
||||
working_context_json: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
async fn memory_kb() -> Arc<Database> {
|
||||
Arc::new(Database::open_in_memory().await.expect("内存库"))
|
||||
}
|
||||
|
||||
// ── 空库零回归:注入空库句柄,投影段与无库时逐字一致 ──
|
||||
#[tokio::test]
|
||||
async fn empty_kb_zero_regression() {
|
||||
let db = memory_kb().await;
|
||||
let dir = temp_project_dir();
|
||||
// 无规则文件 + 空库 → None(prompt 逐字不变)
|
||||
let none = projection_section(Some(dir.to_str().unwrap()), &format!("conv-{}", unique_tag()), Some(db.clone())).await;
|
||||
assert_eq!(none, None, "空库且无规则文件,投影段必须缺席");
|
||||
// 有规则文件 + 空库 → 规则照常注入,路标子块零出现(其余行为零变化)
|
||||
write_file(&dir, "CLAUDE.md", "- 规则条目");
|
||||
let rules_only = projection_section(Some(dir.to_str().unwrap()), &format!("conv-{}", unique_tag()), Some(db)).await;
|
||||
let sec = rules_only.expect("有规则文件必有段");
|
||||
assert!(sec.contains("### 项目规范(CLAUDE.md)"));
|
||||
assert!(!sec.contains("知识库路标"), "空库不得出现路标子段");
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
|
||||
// ── 入选过滤:verified 或复用达标才入段,渲染为紧凑行 + 段首说明 + 段尾固定提示 ──
|
||||
#[tokio::test]
|
||||
async fn waymark_selects_verified_or_reused() {
|
||||
let db = memory_kb().await;
|
||||
let repo = KnowledgeRepo::new(&db);
|
||||
repo.insert(kentry("ok-v", "已验证经验", 0, true, None)).await.unwrap();
|
||||
repo.insert(kentry("ok-r", "复用达标经验", 3, false, None)).await.unwrap();
|
||||
repo.insert(kentry("no-r", "复用不足应淘汰", 2, false, None)).await.unwrap();
|
||||
let mut cand = kentry("no-c", "候选未发布应淘汰", 99, false, None);
|
||||
cand.status = "candidate".to_string();
|
||||
repo.insert(cand).await.unwrap();
|
||||
|
||||
let sec = projection_section(None, &format!("conv-{}", unique_tag()), Some(db))
|
||||
.await
|
||||
.expect("有合格条目必有段");
|
||||
assert!(sec.starts_with("## 项目认知投影"), "仅路标在场时须独占投影段");
|
||||
assert!(sec.contains("项目知识库路标(详情用 knowledge_search 按标题关键词检索)"), "段首说明行");
|
||||
assert!(sec.contains("\n- 已验证经验 | 复用0次"), "verified 豁免复用门槛入段");
|
||||
assert!(sec.contains("\n- 复用达标经验 | 复用3次"), "复用压线达标入段");
|
||||
assert!(!sec.contains("复用不足应淘汰"), "复用不足不入段");
|
||||
assert!(!sec.contains("候选未发布应淘汰"), "非 published 不入段");
|
||||
assert!(
|
||||
sec.ends_with("上述经验条目可直接复用;遇到工具故障/重复失败先检索路标"),
|
||||
"段尾固定提示行"
|
||||
);
|
||||
}
|
||||
|
||||
// ── 项目优先:boundary 解析出归属项目后,项目档在前,跨项目补充档按复用降序 ──
|
||||
#[tokio::test]
|
||||
async fn waymark_project_tier_first() {
|
||||
let db = memory_kb().await;
|
||||
ins_project(&db, "p-way", "e:/wk-lab/waymark-proj").await;
|
||||
ins_conv_with_boundary(&db, "conv-way", "e:/wk-lab/waymark-proj").await;
|
||||
let repo = KnowledgeRepo::new(&db);
|
||||
repo.insert(kentry("same1", "同项目条目", 5, false, Some("p-way"))).await.unwrap();
|
||||
repo.insert(kentry("foreign", "异项目高复用条目", 99, false, Some("p-other"))).await.unwrap();
|
||||
repo.insert(kentry("global1", "全局无归属条目", 10, false, None)).await.unwrap();
|
||||
|
||||
let sec = projection_section(None, "conv-way", Some(db)).await.expect("必有段");
|
||||
let same = sec.find("同项目条目").expect("同项目条目须入项目档");
|
||||
let global = sec.find("全局无归属条目").expect("全局条目须入补充档");
|
||||
let foreign = sec.find("异项目高复用条目").expect("异项目条目须入补充档");
|
||||
assert!(
|
||||
same < foreign && foreign < global,
|
||||
"项目档在前;补充档内复用降序(异项目99 先于全局10)"
|
||||
);
|
||||
}
|
||||
|
||||
// ── 会话缓存:同会话复用首查结果,库内追加不影响;新会话查到新条目 ──
|
||||
#[tokio::test]
|
||||
async fn waymark_cached_per_conversation() {
|
||||
let db = memory_kb().await;
|
||||
let repo = KnowledgeRepo::new(&db);
|
||||
repo.insert(kentry("a1", "首批经验", 3, false, None)).await.unwrap();
|
||||
let conv = format!("conv-{}", unique_tag());
|
||||
|
||||
let first = projection_section(None, &conv, Some(db.clone())).await.expect("必有段");
|
||||
assert!(first.contains("首批经验"));
|
||||
|
||||
repo.insert(kentry("b2", "次批经验", 3, false, None)).await.unwrap();
|
||||
let again = projection_section(None, &conv, Some(db.clone())).await.expect("必有段");
|
||||
assert_eq!(first, again, "同会话必须复用缓存(库内追加不影响)");
|
||||
assert!(!again.contains("次批经验"));
|
||||
|
||||
let fresh = projection_section(None, &format!("{conv}-new"), Some(db)).await.expect("必有段");
|
||||
assert!(fresh.contains("次批经验"), "新会话须重查库拿到新条目");
|
||||
}
|
||||
|
||||
// ── 渲染纯函数:标题压平换行 + 截断注省略号 + 空白标题跳过 ──
|
||||
#[test]
|
||||
fn render_waymark_flattens_and_caps_title() {
|
||||
let mut long = kentry("long", "", 7, false, None);
|
||||
long.title = format!("长{}标题", "词".repeat(60)); // 63 字,超 60 上限
|
||||
let mut multiline = kentry("multi", "含\n换行\t与制表", 2, true, None);
|
||||
multiline.verified = true;
|
||||
let blank = kentry("blank", " \n ", 1, true, None);
|
||||
let out = render_waymark(&[long, multiline, blank]);
|
||||
let line = out.lines().find(|l| l.starts_with("- 长")).expect("截断标题行在场");
|
||||
assert!(line.ends_with("… | 复用7次"), "超长标题须截断注省略号");
|
||||
assert!(line.matches('词').count() <= WAYMARK_TITLE_MAX_CHARS, "标题不得超上限");
|
||||
assert!(out.contains("- 含 换行 与制表 | 复用2次"), "换行/制表压平为单空格");
|
||||
assert!(!out.contains("- |"), "空白标题条目须跳过");
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,8 @@ pub mod command_stream;
|
||||
pub mod commands;
|
||||
pub mod compress;
|
||||
pub mod conversation;
|
||||
// 项目规则文件投影(devflow.md/CLAUDE.md):会话启动读取并入 system prompt 稳定尾段
|
||||
pub(crate) mod devflow_md;
|
||||
pub mod event_bus;
|
||||
pub mod http;
|
||||
pub mod fetch_url;
|
||||
@@ -315,6 +317,11 @@ pub enum AiChatEvent {
|
||||
/// 摘要 system 消息已由后端 insert_at,后续 stream 自然带出,无需整会话刷新。
|
||||
/// miniapp 仍插摘要气泡(对端发生压缩告知用户)。
|
||||
AiAutoCompressed { conversation_id: Option<String>, summary: String },
|
||||
/// E2 压缩失败降级透出(2026-10-18):LLM 压缩失败走关键词摘要兜底时,loop 仍在继续
|
||||
/// (不发 AiError——其 case 无条件 setStreaming(false) 会误判生成结束),但用户须知晓
|
||||
/// 上下文已降级(实证 76730ce8 seq166:静默降级→AI 失忆→用户被迫原句重发)。
|
||||
/// 前端弹一次性状态提示,不中断流。
|
||||
AiContextDegraded { conversation_id: Option<String>, reason: String },
|
||||
/// L1 求助协议(aichat 体验与 agent 能力系统化重构 §2.3,2026-06-21):
|
||||
///
|
||||
/// agent 断路器(§2.2)熔断 / 自省(识别"我反复失败")时发,区别于 prompt 教 AI
|
||||
@@ -1063,6 +1070,10 @@ pub struct PerConvState {
|
||||
/// 原轮次终点时读后清零消费、续跑一轮,让补充指令获得带工具的完整消费轮。
|
||||
/// 同锁读写(session lock 串行);loop 入口清零防跨 loop 残留。
|
||||
pub round_budget_extra: usize,
|
||||
/// 未消化注入计数(2026-10-14 实测):inject_runtime_message 每次 +1;每轮 build_for_request
|
||||
/// 组装后清零(消息已进本轮请求=消化);收敛出口查 >0 则不收敛续一轮,治「纯问答轮
|
||||
/// 一轮收敛,生成期间到达的补充指令无人消费只能等下次请求」的丢失。内存态不落库。
|
||||
pub pending_injects: u32,
|
||||
/// 当前 agent 循环的语言设置(用于审批后恢复循环)
|
||||
pub agent_language: Option<String>,
|
||||
/// 用户指定模型 override(主对话专用,语义同 AiSession.model_override)
|
||||
@@ -1264,6 +1275,7 @@ impl PerConvState {
|
||||
iteration_used: 0,
|
||||
loop_max_rounds: 0,
|
||||
round_budget_extra: 0,
|
||||
pending_injects: 0,
|
||||
agent_language: None,
|
||||
model_override: None,
|
||||
session_trust: HashSet::new(),
|
||||
|
||||
@@ -127,6 +127,7 @@ fn system_prompt_parts(lang: &str) -> (String, &'static str, &'static str) {
|
||||
- {}\n\
|
||||
- {}\n\
|
||||
- {}\n\
|
||||
- Response style: lead with the conclusion and the action/result; omit restating the user's question, pleasantries, and summary closers; prefer bullet points over paragraphs; do not expand on what was not asked. Explain whenever explanation is needed — cut filler, not substance.\n\
|
||||
## Focus\n\
|
||||
- Always center your response on the core goal of the user's current request; the previous round's topic is only background, not the current task.\n\
|
||||
- When the user switches topics (a clear new intent), follow the latest request; do not drag the old topic into the new answer.\n\
|
||||
@@ -160,6 +161,7 @@ fn system_prompt_parts(lang: &str) -> (String, &'static str, &'static str) {
|
||||
- {}\n\
|
||||
- {}\n\
|
||||
- {}\n\
|
||||
- 回复风格:结论先行,直接给动作/结果;不复述用户问题,不做客套开场和总结性收尾;要点优先于段落;用户没问的不展开。需要解释时照常解释——省的是空话,不是内容。\n\
|
||||
## 聚焦准则\n\
|
||||
- 始终围绕用户当前请求的核心目标回答;上一轮的主题只是背景,不是当前任务。\n\
|
||||
- 用户切换话题(明显的新意图)时,以最新请求为准,不要把旧话题带进新回答。\n\
|
||||
@@ -445,7 +447,10 @@ async fn entity_fingerprint(db: &Arc<Database>, sql: &'static str) -> Option<Str
|
||||
/// - 日期:env_profile_line 注入当日日期,跨天必须失效(否则缓存串日期过期)。
|
||||
/// - lang:system_prompt_parts / 各策略段 / 注明语随 lang 分支。
|
||||
/// - custom_prompt:与 build 内读的同一设置,变更即失效。
|
||||
/// - 活跃 project/task 的 id+updated_at:新增/软删/改 updated_at 均反映到指纹(比 MAX 更稳)。
|
||||
/// - 活跃 project/task 指纹:task 取 id+updated_at;project 取 id+活跃时间(三源取大:
|
||||
/// tasks.updated_at 最新/project_events 最新 created_at/projects.updated_at,仅未归档未删除,
|
||||
/// 与「当前项目」清单的 list_active_with_activity 排序输入对齐)——任务更新/归档变化均
|
||||
/// 反映到指纹,清单排序变了缓存串必失效。
|
||||
/// - 去重排除集:被@实体走 augmentation 精准投影,排除集变化会改变清单内容,须纳入指纹。
|
||||
async fn system_prompt_fingerprint(
|
||||
state: &AppState,
|
||||
@@ -463,7 +468,11 @@ async fn system_prompt_fingerprint(
|
||||
.unwrap_or_default();
|
||||
let proj_fp = entity_fingerprint(
|
||||
&state.db,
|
||||
"SELECT id, updated_at FROM projects WHERE deleted_at IS NULL",
|
||||
"SELECT p.id, MAX(\
|
||||
IFNULL((SELECT MAX(t.updated_at) FROM tasks t WHERE t.project_id = p.id AND t.deleted_at IS NULL), 0), \
|
||||
IFNULL((SELECT MAX(e.created_at) FROM project_events e WHERE e.project_id = p.id), 0), \
|
||||
IFNULL(p.updated_at, 0)\
|
||||
) FROM projects p WHERE p.deleted_at IS NULL AND p.archived = 0",
|
||||
)
|
||||
.await?;
|
||||
let task_fp = entity_fingerprint(
|
||||
@@ -586,24 +595,25 @@ async fn build_context_lists(
|
||||
) -> String {
|
||||
let (_, proj_label, task_label) = system_prompt_parts(lang);
|
||||
let mut out = String::new();
|
||||
// 附加当前数据上下文
|
||||
if let Ok(projects) = state.projects.list_active().await {
|
||||
// 附加当前数据上下文。项目段按最近活跃排序(任务活跃为主信号),治创建序误导项目绑定
|
||||
// (创建序会把早停摆项目排在清单首位,AI 误当最高优先项目锚点)。
|
||||
if let Ok(projects) = state.projects.list_active_with_activity().await {
|
||||
if !projects.is_empty() {
|
||||
out.push_str(proj_label);
|
||||
// system prompt 前缀克制:仅最近 20 个项目,防 context 膨胀
|
||||
// 去重:被 @ 的项目跳过(已有 augmentation 精准投影,清单再现致同一实体两次入 prompt)
|
||||
for p in projects.iter().take(20) {
|
||||
if excluded_project_ids.iter().any(|id| id == &p.id) {
|
||||
if excluded_project_ids.iter().any(|id| id == &p.record.id) {
|
||||
continue;
|
||||
}
|
||||
out.push_str(&format!(
|
||||
"- {} (id: {}) ({}): {}\n",
|
||||
p.name,
|
||||
p.id,
|
||||
p.status.as_str(),
|
||||
truncate_desc(&p.description, CONTEXT_DESC_MAX_CHARS)
|
||||
p.record.name,
|
||||
p.record.id,
|
||||
p.record.status.as_str(),
|
||||
truncate_desc(&p.record.description, CONTEXT_DESC_MAX_CHARS)
|
||||
));
|
||||
if let Some(ref dir) = p.path {
|
||||
if let Some(ref dir) = p.record.path {
|
||||
out.push_str(&format!(" 目录: {}\n", dir));
|
||||
}
|
||||
}
|
||||
@@ -921,6 +931,32 @@ mod tests {
|
||||
assert!(prefix.contains("聚焦准则"));
|
||||
}
|
||||
|
||||
// M4 回复风格纪律:中文版行为准则含「回复风格」条款(反口水话,不反内容)
|
||||
#[test]
|
||||
fn system_prompt_zh_has_response_style_clause() {
|
||||
let (prefix, _, _) = system_prompt_parts("zh-CN");
|
||||
assert!(
|
||||
prefix.contains("回复风格"),
|
||||
"中文 system prompt 应含回复风格条款,实际: {}",
|
||||
prefix
|
||||
);
|
||||
// 核心条款抽样:结论先行 + 「省的是空话,不是内容」的度(需要解释时照常解释)
|
||||
assert!(prefix.contains("结论先行"));
|
||||
assert!(prefix.contains("省的是空话,不是内容"));
|
||||
}
|
||||
|
||||
// M4 回复风格纪律:英文版 Guidelines 含 Response style 条款
|
||||
#[test]
|
||||
fn system_prompt_en_has_response_style_clause() {
|
||||
let (prefix, _, _) = system_prompt_parts("en");
|
||||
assert!(
|
||||
prefix.contains("Response style"),
|
||||
"英文 system prompt 应含 Response style 条款,实际: {}",
|
||||
prefix
|
||||
);
|
||||
assert!(prefix.contains("cut filler, not substance"));
|
||||
}
|
||||
|
||||
// 文档探索策略段(中/英)存在且含关键引导
|
||||
#[test]
|
||||
fn doc_exploration_strategy_section_present_zh_en() {
|
||||
|
||||
@@ -25,6 +25,25 @@ struct FailureEntry {
|
||||
last_error: String,
|
||||
}
|
||||
|
||||
/// 工具级超时连败计数(E13):治「同工具跨签名调参重试」逃逸——run_command 换 timeout
|
||||
/// 档位即换 key,签名级拦截不触发,8 连败照烧轮次(434c8c40 实证)。此处按工具聚合:
|
||||
/// 连续超时(错误特征匹配)≥3 次 → 该工具下次执行前注入软收敛警告(不硬拦,防误杀
|
||||
/// 同工具的轻量调用),信息给足引导 LLM 换方案/问用户。该工具任一次成功即清零。
|
||||
static TOOL_TIMEOUT_STREAKS: OnceLock<Mutex<HashMap<String, u32>>> = OnceLock::new();
|
||||
|
||||
/// 超时连败软收敛阈值(跨签名聚合口径)。
|
||||
pub const TIMEOUT_STREAK_WARN_AFTER: u32 = 3;
|
||||
|
||||
fn timeout_streaks() -> &'static Mutex<HashMap<String, u32>> {
|
||||
TOOL_TIMEOUT_STREAKS.get_or_init(|| Mutex::new(HashMap::new()))
|
||||
}
|
||||
|
||||
/// 错误摘要是否属超时族(中英特征,大小写不敏感)。
|
||||
fn is_timeout_error(error: &str) -> bool {
|
||||
let lower = error.to_lowercase();
|
||||
lower.contains("超时") || lower.contains("timeout") || lower.contains("timed out")
|
||||
}
|
||||
|
||||
/// 进程级失败记忆(全 conv 共享单锁;锁内零 await,微秒级)。
|
||||
static FAILURE_MEMORY: OnceLock<Mutex<HashMap<String, FailureEntry>>> = OnceLock::new();
|
||||
|
||||
@@ -70,34 +89,50 @@ fn sort_json(v: &serde_json::Value) -> serde_json::Value {
|
||||
}
|
||||
}
|
||||
|
||||
/// 执行前检查:同 key 连败达标 → 拦截,返回结构化失败提示(LLM 可读换路引导)。
|
||||
/// 未达标/无记忆 → None 放行。
|
||||
/// 执行前检查:同 key 连败达标 → 拦截;工具级超时连败达标 → 软收敛警告(不拦执行)。
|
||||
/// 两者都未达标/无记忆 → None 放行。
|
||||
pub fn precheck(tool: &str, args: &serde_json::Value) -> Option<String> {
|
||||
let key = memory_key(tool, args);
|
||||
let mem = memory().lock().unwrap_or_else(|p| p.into_inner());
|
||||
let Some(entry) = mem.get(&key) else { return None };
|
||||
if entry.consecutive >= ABORT_AFTER_CONSECUTIVE_FAILURES {
|
||||
Some(format!(
|
||||
"{{\"status\":\"blocked_by_failure_memory\",\"tool\":\"{tool}\",\"consecutive_failures\":{},\"last_error\":\"{}\",\"hint\":\"同一调用已连败 {} 次,已自动拦截。请勿原样重试:①检查参数(路径/SQL/命令拼写) ②换工具或换路径 ③若确认无法绕过,向用户报告放弃原因。\"}}",
|
||||
entry.consecutive,
|
||||
entry.last_error.replace('\"', "'"),
|
||||
entry.consecutive
|
||||
))
|
||||
} else {
|
||||
None
|
||||
if let Some(entry) = mem.get(&key) {
|
||||
if entry.consecutive >= ABORT_AFTER_CONSECUTIVE_FAILURES {
|
||||
return Some(format!(
|
||||
"{{\"status\":\"blocked_by_failure_memory\",\"tool\":\"{tool}\",\"consecutive_failures\":{},\"last_error\":\"{}\",\"hint\":\"同一调用已连败 {} 次,已自动拦截。请勿原样重试:①检查参数(路径/SQL/命令拼写) ②换工具或换路径 ③若确认无法绕过,向用户报告放弃原因。\"}}",
|
||||
entry.consecutive,
|
||||
entry.last_error.replace('\"', "'"),
|
||||
entry.consecutive
|
||||
));
|
||||
}
|
||||
}
|
||||
// E13 工具级超时连败(跨签名聚合):换参数/换档位逃不出工具维度。
|
||||
let streaks = timeout_streaks().lock().unwrap_or_else(|p| p.into_inner());
|
||||
if let Some(streak) = streaks.get(tool) {
|
||||
if *streak >= TIMEOUT_STREAK_WARN_AFTER {
|
||||
return Some(format!(
|
||||
"{{\"status\":\"timeout_streak_warning\",\"tool\":\"{tool}\",\"timeout_streak\":{},\"hint\":\"该工具已连续超时 {} 次(不同参数/档位都超)。继续原路大概率仍超时:①把任务拆小分步执行 ②换更轻量的方式(降低数据量/改后台执行) ③若确实需要长时间运行,向用户说明并确认后再继续。\"}}",
|
||||
streak, streak
|
||||
));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// 执行后回写:成功清零删除,失败递增并记最近错误。
|
||||
/// 执行后回写:成功清零删除(签名级+工具级超时计数),失败递增并记最近错误;
|
||||
/// 失败属超时族时工具级超时连败 +1。
|
||||
pub fn record(tool: &str, args: &serde_json::Value, ok: bool, error: Option<String>) {
|
||||
let key = memory_key(tool, args);
|
||||
let mut mem = memory().lock().unwrap_or_else(|p| p.into_inner());
|
||||
let mut streaks = timeout_streaks().lock().unwrap_or_else(|p| p.into_inner());
|
||||
if ok {
|
||||
mem.remove(&key);
|
||||
streaks.remove(tool);
|
||||
} else {
|
||||
let e = mem.entry(key).or_insert(FailureEntry { consecutive: 0, last_error: String::new() });
|
||||
e.consecutive += 1;
|
||||
e.last_error = error.unwrap_or_default().chars().take(200).collect();
|
||||
if is_timeout_error(&e.last_error) {
|
||||
*streaks.entry(tool.to_string()).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,4 +180,38 @@ mod tests {
|
||||
let a = json!({"command": "cargo test", "working_dir": "E:/x"});
|
||||
assert!(memory_key("run_command", &a).contains("cmd=cargo test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timeout_streak_aggregates_across_signatures_and_soft_warns() {
|
||||
clear();
|
||||
timeout_streaks().lock().unwrap().clear();
|
||||
// 换档位=换签名(E13 逃逸路径:超时档拼在命令里即不同 key):签名级各 1 次均不拦;
|
||||
// 工具级 streak 在第 3 次超时发生后达 3,同工具再调用(含当次迭代)即软警告
|
||||
for (i, timeout) in ["60", "300", "600"].iter().enumerate() {
|
||||
let args = json!({"command": format!("cargo build --timeout {timeout}")});
|
||||
record("run_command", &args, false, Some(format!("命令执行超时({timeout}s)")));
|
||||
if i < 2 {
|
||||
assert!(precheck("run_command", &args).is_none(), "签名级 1 次且 streak<3 不拦");
|
||||
}
|
||||
}
|
||||
// 新签名(第 4 档):工具级超时连败 ≥3 → 软收敛警告(放行执行但注入换路引导)
|
||||
let args4 = json!({"command": "cargo build --timeout 900"});
|
||||
let warn = precheck("run_command", &args4).unwrap();
|
||||
assert!(warn.contains("timeout_streak_warning"));
|
||||
assert!(warn.contains("\"timeout_streak\":3"));
|
||||
// 同工具任一成功 → 工具级清零
|
||||
record("run_command", &json!({"command": "ls"}), true, None);
|
||||
assert!(precheck("run_command", &args4).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_timeout_failures_do_not_aggregate_to_timeout_streak() {
|
||||
clear();
|
||||
timeout_streaks().lock().unwrap().clear();
|
||||
for path in ["/a.rs", "/b.rs", "/c.rs"] {
|
||||
record("read_file", &json!({"path": path}), false, Some("文件不存在".into()));
|
||||
}
|
||||
// 3 连败但非超时族 → 无工具级警告
|
||||
assert!(precheck("read_file", &json!({"path": "/d.rs"})).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1410,6 +1410,7 @@ fn make_test_spawn_agent_ctx(db: &Arc<Database>) -> crate::commands::ai::tools::
|
||||
crate::commands::ai::agentic::conv_state::ConvStateStore::new(),
|
||||
),
|
||||
llm_concurrency: LlmConcurrency::new(3, 2),
|
||||
allowed_dirs: Arc::new(tokio::sync::RwLock::new(crate::state::AllowedDirs::default())),
|
||||
db: db.clone(),
|
||||
sub_agents: crate::commands::ai::agentic::sub_agent::new_registry(),
|
||||
}
|
||||
|
||||
@@ -1098,7 +1098,7 @@ pub fn register(
|
||||
}
|
||||
|
||||
// output_mode 分派返回结构
|
||||
let result = match output_mode {
|
||||
let mut result = match output_mode {
|
||||
"files_with_matches" => {
|
||||
// 仅返命中文件路径列表(去重,顺序保留首次命中)
|
||||
let files: Vec<String> = matches_out.iter()
|
||||
@@ -1183,6 +1183,11 @@ pub fn register(
|
||||
})
|
||||
}
|
||||
};
|
||||
// 0 命中「阴性存疑」提示:路径/glob 写法/大小写任一不对都静默 0 命中,
|
||||
// LLM 拿空结果易直接当「不存在」下结论(实测假阴性被当事实断言 3 轮),强制附一行复核提示。
|
||||
if total == 0 {
|
||||
result["hint"] = serde_json::json!(negative_hit_hint("路径/glob 写法/大小写 -i"));
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
);
|
||||
@@ -1228,10 +1233,13 @@ pub fn register(
|
||||
let mut out = serde_json::json!({
|
||||
"path": path, "pattern": pattern, "results": page_results, "total": total, "has_more": has_more
|
||||
});
|
||||
// total=0 时空结果引导(治 LLM 搜不到就放弃/盲目重试)。
|
||||
// total=0 时空结果引导(治 LLM 搜不到就放弃/盲目重试)+ 阴性存疑提示(0 命中≠不存在)。
|
||||
// 注:search_files 已大小写不敏感(内部 pattern.to_lowercase + 包含匹配),文案勿写"换大小写"。
|
||||
if total == 0 {
|
||||
out["hint"] = serde_json::json!("未找到匹配文件。可尝试: ① 放宽关键词(更短/字符更少); ② 用 grep 工具做跨文件内容正则搜索(pattern 支持正则, -i 大小写不敏感)。注: search_files 为文件名大小写不敏感包含匹配");
|
||||
out["hint"] = serde_json::json!(format!(
|
||||
"{}\n未找到匹配文件。可尝试: ① 补 recursive=true 搜子目录(不传只搜当前层); ② 放宽关键词(更短/字符更少); ③ 用 grep 工具做跨文件内容正则搜索(pattern 支持正则, -i 大小写不敏感)。注: search_files 为文件名大小写不敏感包含匹配",
|
||||
negative_hit_hint("路径/recursive")
|
||||
));
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
@@ -1675,6 +1683,16 @@ fn file_not_found_error(path: &str) -> anyhow::Error {
|
||||
anyhow::anyhow!(msg)
|
||||
}
|
||||
|
||||
/// 搜索工具(search_files/grep)0 命中「阴性存疑」提示。
|
||||
///
|
||||
/// 治勘察假阴性被当事实断言:search_files 未传 recursive 只搜根目录,
|
||||
/// 0 命中被 LLM 直接当「功能未实施」连续断言 3 轮。路径/glob/recursive 等范围
|
||||
/// 参数写错时同样静默 0 命中,故空结果强制附本提示让 LLM 复核后再下结论。
|
||||
/// 措辞克制一行;`scope` 按工具传入各自的复核点。
|
||||
fn negative_hit_hint(scope: &str) -> String {
|
||||
format!("⚠ 0 命中不一定代表不存在——请复核搜索范围({scope})后再下结论")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -2003,6 +2021,23 @@ mod tests {
|
||||
assert!(msg.contains("相近文件候选"), "应含相近文件候选,实际: {msg}");
|
||||
assert!(msg.contains("target.rs"), "候选应含 target.rs,实际: {msg}");
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// negative_hit_hint — 搜索工具 0 命中阴性存疑提示(治假阴性被当事实断言)
|
||||
// ============================================================
|
||||
|
||||
/// 两搜索工具 0 命中提示共用句式:声明「0 命中≠不存在」+ 按工具各自的复核点。
|
||||
#[test]
|
||||
fn negative_hit_hint_states_doubt_and_scope() {
|
||||
// grep 侧复核点:路径/glob 写法/大小写
|
||||
let grep_hint = negative_hit_hint("路径/glob 写法/大小写 -i");
|
||||
assert!(grep_hint.contains("0 命中不一定代表不存在"), "应声明阴性存疑,实际: {grep_hint}");
|
||||
assert!(grep_hint.contains("复核搜索范围"), "应引导复核,实际: {grep_hint}");
|
||||
assert!(grep_hint.contains("glob"), "grep 侧应含 glob 复核点,实际: {grep_hint}");
|
||||
// search_files 侧复核点:recursive(实测根因是未传 recursive 只搜根目录)
|
||||
let search_hint = negative_hit_hint("路径/recursive");
|
||||
assert!(search_hint.contains("recursive"), "search_files 侧应含 recursive 复核点,实际: {search_hint}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
|
||||
use df_ai::ai_tools::{
|
||||
AiToolRegistry, GoalMeta, GoalStyle, RiskLevel, SigMeta, SigValKind, ToolMeta,
|
||||
@@ -52,6 +52,9 @@ pub struct SpawnAgentCtx {
|
||||
pub conv_states: Arc<ConvStateStore>,
|
||||
/// LLM 并发控制(子循环 global + per_conv(child) 双份额)
|
||||
pub llm_concurrency: LlmConcurrency,
|
||||
/// 文件访问授权白名单(子代理投影段定位工作区:首个持久授权目录;
|
||||
/// 与 AppState.allowed_dirs 共享同一 Arc)
|
||||
pub allowed_dirs: Arc<RwLock<crate::state::AllowedDirs>>,
|
||||
/// 数据库句柄(子循环 provider 解析)
|
||||
pub db: Arc<Database>,
|
||||
/// 级联取消注册表(parent→children,与 AppState.sub_agent_registry 共享同一 Arc)
|
||||
@@ -268,6 +271,15 @@ async fn spawn_agent_handler(
|
||||
let task_prompt = build_task_prompt(&task, &allowed, &trimmed);
|
||||
// P2-3:系统提示词注入实际生效的预算值(父可传 1..20,子代理按真实预算规划)
|
||||
let system_prompt = sub_agent_system_prompt(max_rounds, &parent_lang);
|
||||
// 项目规则文件投影与主会话同源:父会话工作区的 devflow.md/CLAUDE.md 对子代理同样生效
|
||||
// (以父会话为缓存键,复用父会话已读内容零重复读盘;无授权目录/无文件时原样返回)。
|
||||
let work_dir = {
|
||||
let snap = ctx.allowed_dirs.read().await;
|
||||
crate::commands::ai::devflow_md::work_dir_of(&snap)
|
||||
};
|
||||
let system_prompt = crate::commands::ai::devflow_md::append_projection(
|
||||
system_prompt, work_dir.as_deref(), &parent_conv_id,
|
||||
).await;
|
||||
|
||||
// P3-5:spawn 时刻快照父会话 save 元数据(active provider/created_at)。子代理后台
|
||||
// 长跑收尾时用户可能已切走会话,出口落库若读 active_* 会继承别的会话元数据;
|
||||
|
||||
+501
-131
@@ -63,6 +63,34 @@ fn cancel_watchers(
|
||||
CANCEL_WATCHERS.get_or_init(|| tokio::sync::Mutex::new(HashMap::new()))
|
||||
}
|
||||
|
||||
/// F5-2 终态窗口:审批前端默认 15min 超时自动拒绝,30min 窗覆盖「终态后用户补发决议词」
|
||||
/// 的迟到判定;窗口外的决议词视为普通聊天文本(无审批语境,现状语义)
|
||||
const RESOLVED_WINDOW_SECS: i64 = 1800;
|
||||
|
||||
/// F5-2 审批终态闭环:已推飞书侧的审批按钮卡句柄(tc_id → (卡片 message_id, 发卡时刻))。
|
||||
/// 桌面决议/超时自动拒绝后原卡原地更新为终态,不再恒挂可点。内存态,重启即失——重启后
|
||||
/// 陈旧卡点击走 ai_approve 幂等「已处理」回执,无功能损失。写入时顺带清过期条目防无界增长
|
||||
static APPROVAL_CARDS: std::sync::OnceLock<std::sync::Mutex<HashMap<String, (String, i64)>>> =
|
||||
std::sync::OnceLock::new();
|
||||
|
||||
/// F5-2 迟到决议判定:chat → 最近一次审批终态(时刻, 是否批准)。审批已终态但用户仍在
|
||||
/// 飞书回决议词时,据此前 30min 记录提示「已处理」而非把决议文本注入运行中任务
|
||||
static RESOLVED_CHATS: std::sync::OnceLock<std::sync::Mutex<HashMap<String, (i64, bool)>>> =
|
||||
std::sync::OnceLock::new();
|
||||
|
||||
fn approval_cards() -> &'static std::sync::Mutex<HashMap<String, (String, i64)>> {
|
||||
APPROVAL_CARDS.get_or_init(|| std::sync::Mutex::new(HashMap::new()))
|
||||
}
|
||||
|
||||
fn resolved_chats() -> &'static std::sync::Mutex<HashMap<String, (i64, bool)>> {
|
||||
RESOLVED_CHATS.get_or_init(|| std::sync::Mutex::new(HashMap::new()))
|
||||
}
|
||||
|
||||
/// 终态新鲜度判定(纯函数,迟到决议提示的窗口判据)
|
||||
fn within_resolved_window(at_secs: i64, now: i64) -> bool {
|
||||
now - at_secs < RESOLVED_WINDOW_SECS
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
struct FeishuConfig {
|
||||
#[serde(default)]
|
||||
@@ -125,6 +153,9 @@ struct Ctx {
|
||||
/// D3 在途会话数:消息受理(handle_message 白名单通过)到任务投递完成期间 >0,
|
||||
/// 看门狗要求为 0 才告警,防有回复待投递时误报
|
||||
inflight: Arc<AtomicUsize>,
|
||||
/// D5 假活自愈唤醒句柄:看门狗连续告警超阈值后 notify,run_loop 的 channel.start()
|
||||
/// select 到即主动退出,交给外层重连循环重建连接(Notify 生命周期同 Ctx,跨重连复用)
|
||||
selfheal: Arc<tokio::sync::Notify>,
|
||||
}
|
||||
|
||||
/// 启动入口:lib.rs setup 调用。未启用/配置缺失/构造失败一律记日志返回,不阻塞应用启动。
|
||||
@@ -182,6 +213,7 @@ pub fn start_if_enabled(app: tauri::AppHandle) {
|
||||
debounce: Arc::new(tokio::sync::Mutex::new(HashMap::new())),
|
||||
last_alive: Arc::new(AtomicI64::new(now_secs())),
|
||||
inflight: Arc::new(AtomicUsize::new(0)),
|
||||
selfheal: Arc::new(tokio::sync::Notify::new()),
|
||||
});
|
||||
// D1 僵尸资源修复:client 的 'static 化只做一次(原在 run_loop 内,每次重连都
|
||||
// Box::leak 一份 LarkClient,频繁断线场景内存阶梯上涨);Channel::builder 仅借用
|
||||
@@ -285,10 +317,16 @@ let ctx_msg = ctx.clone();
|
||||
})
|
||||
.build();
|
||||
tracing::info!("[feishu] 长连接启动(桌面端直连,免公网回调)");
|
||||
let result = channel
|
||||
.start()
|
||||
.await
|
||||
.map_err(|e: LarkError| anyhow::anyhow!("飞书长连接退出: {e}"));
|
||||
// D5 假活自愈:看门狗持续断流判定后 notify,主动终结本次 channel.start(),
|
||||
// 交给外层重连循环 backoff 重建连接(比 SDK 内部重连更彻底:全新 WS 握手)
|
||||
let heal = ctx.selfheal.clone();
|
||||
let result = tokio::select! {
|
||||
r = channel.start() => r
|
||||
.map_err(|e: LarkError| anyhow::anyhow!("飞书长连接退出: {e}")),
|
||||
_ = heal.notified() => {
|
||||
Err(anyhow::anyhow!("假活自愈: 看门狗判定持续断流,主动断开重建"))
|
||||
}
|
||||
};
|
||||
watchdog.abort();
|
||||
result?;
|
||||
Ok(())
|
||||
@@ -310,25 +348,45 @@ const LIVENESS_TICK: std::time::Duration = std::time::Duration::from_secs(60);
|
||||
/// 排查起点(此前 bot 静默死无任何日志可查)。
|
||||
async fn run_liveness_watchdog(ctx: Arc<Ctx>) {
|
||||
let mut warned = false;
|
||||
// D5 假活自愈:连续告警计数。每 60s 巡检一次,断流持续 LIVENESS_HEAL_TICKS 次
|
||||
// (即断流 ≥ 600s + 3×60s 确认期)仍无任何事件恢复,判定为协议假活(SDK 读空闲
|
||||
// 自愈覆盖不了),主动 notify 唤醒 run_loop 退出重建连接,复用外层 backoff 重连
|
||||
let mut stale_ticks: u32 = 0;
|
||||
loop {
|
||||
tokio::time::sleep(LIVENESS_TICK).await;
|
||||
let elapsed = now_secs() - ctx.last_alive.load(Ordering::SeqCst);
|
||||
if elapsed <= LIVENESS_STALE_SECS {
|
||||
warned = false;
|
||||
stale_ticks = 0;
|
||||
continue;
|
||||
}
|
||||
// 有会话在途不告警(回复投递依赖当前连接);同一段断流只告警一次防刷屏
|
||||
if ctx.inflight.load(Ordering::SeqCst) > 0 || warned {
|
||||
// 有会话在途不告警(回复投递依赖当前连接)
|
||||
if ctx.inflight.load(Ordering::SeqCst) > 0 {
|
||||
continue;
|
||||
}
|
||||
warned = true;
|
||||
tracing::warn!("[feishu] 探活告警: {elapsed}s 无任何事件且无在途会话,疑似连接假活");
|
||||
feishu_log(&format!(
|
||||
"探活告警: {elapsed}s 无任何事件且无在途会话(疑似假活,持续出现请重启应用重建连接)"
|
||||
));
|
||||
if !warned {
|
||||
warned = true;
|
||||
tracing::warn!("[feishu] 探活告警: {elapsed}s 无任何事件且无在途会话,疑似连接假活");
|
||||
feishu_log(&format!(
|
||||
"探活告警: {elapsed}s 无任何事件且无在途会话(疑似假活)"
|
||||
));
|
||||
}
|
||||
stale_ticks += 1;
|
||||
if stale_ticks >= LIVENESS_HEAL_TICKS {
|
||||
tracing::error!(
|
||||
"[feishu] 假活自愈触发: 断流持续 {} 个巡检周期,主动断开重建长连接",
|
||||
stale_ticks
|
||||
);
|
||||
feishu_log("假活自愈触发: 持续断流,主动断开重建长连接");
|
||||
ctx.selfheal.notify_waiters();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// D5 自愈确认期:首个告警后再等 N 个巡检周期仍断流才重建(防把正常空闲+慢恢复误杀)
|
||||
const LIVENESS_HEAL_TICKS: u32 = 3;
|
||||
|
||||
/// D3 在途会话计数 RAII:handle_message 从注册等待桥到投递完成的任意退出路径
|
||||
/// (spawn 失败早退/投递完成)都保证计数回落
|
||||
struct InflightGuard(Arc<AtomicUsize>);
|
||||
@@ -376,6 +434,27 @@ fn parse_command(text: &str) -> Option<(String, String)> {
|
||||
Some((cmd, tail))
|
||||
}
|
||||
|
||||
/// 审批决议词识别(F5-1):集合对齐按钮卡文案与常见同义词——批准 {同意|批准|通过|approve},
|
||||
/// 拒绝 {拒绝|驳回|不同意|reject}。容错链:半全角归一 → 前后空白 → 剥尾部标点(「批准。」
|
||||
/// 「同意!」)→ 小写(英文词)。整词精确匹配非包含(「不同意」含「同意」,靠整词比对防反判),
|
||||
/// 普通文本(「我同意这个方案」)不命中返回 None,由调用方落常规消息路径
|
||||
fn parse_approval_verdict(text: &str) -> Option<bool> {
|
||||
const APPROVE_WORDS: [&str; 4] = ["同意", "批准", "通过", "approve"];
|
||||
const REJECT_WORDS: [&str; 4] = ["拒绝", "驳回", "不同意", "reject"];
|
||||
let t = normalize_halfwidth(text);
|
||||
let t = t
|
||||
.trim()
|
||||
.trim_end_matches(['。', '.', ',', ',', '、', '!', '!', '?', '?', '~', '~', ';', ';', ' ', '\t'])
|
||||
.to_lowercase();
|
||||
if APPROVE_WORDS.contains(&t.as_str()) {
|
||||
Some(true)
|
||||
} else if REJECT_WORDS.contains(&t.as_str()) {
|
||||
Some(false)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// 图片消息喂模型的任务语境(#958):飞书 image 为独立消息类型无法带文字,
|
||||
/// 用引导词让 vision 模型知道「这是用户发来的图,按图作答」
|
||||
const IMAGE_INBOUND_PROMPT: &str = "(用户通过飞书发来一张图片,请查看图片并按图片内容处理)";
|
||||
@@ -384,6 +463,46 @@ const IMAGE_INBOUND_PROMPT: &str = "(用户通过飞书发来一张图片,请查
|
||||
/// 10MB 原图留足余量;超限引导用户压缩,防超大图烧 token 与转码内存
|
||||
const MAX_IMAGE_BYTES: usize = 10 * 1024 * 1024;
|
||||
|
||||
/// 文件入站大小上限:文件不经 base64 内嵌(模型经 read_file 按需读盘),上限只防
|
||||
/// 恶意超大件烧下载流量与磁盘,20MB 覆盖常规文档/报表/压缩包
|
||||
const MAX_FILE_BYTES: usize = 20 * 1024 * 1024;
|
||||
|
||||
/// 飞书消息资源下载带防线(图片/文件共用,对齐 u-claw fetchResource 经验):3 次指数
|
||||
/// 退避(1s/4s)+单次 120s 超时——飞书资源接口偶发抖动,无重试时用户收到一次性失败;
|
||||
/// 超时防接口挂起拖死受理链。空响应与错误同待遇进重试(可能为服务端瞬时异常),
|
||||
/// 耗尽后报最后一次原因。resource_type=image/file,同一资源接口
|
||||
async fn download_message_resource_with_retry(
|
||||
client: &LarkClient,
|
||||
message_id: &str,
|
||||
file_key: &str,
|
||||
resource_type: &str,
|
||||
label: &str,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let mut last_err = String::from("下载失败: 未知错误");
|
||||
for attempt in 0u32..3 {
|
||||
if attempt > 0 {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1 << (attempt - 1))).await;
|
||||
}
|
||||
let dl = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(120),
|
||||
client.channel_messaging().download_message_resource(
|
||||
message_id,
|
||||
file_key,
|
||||
resource_type,
|
||||
&RequestOption::default(),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
match dl {
|
||||
Ok(Ok(r)) if !r.data.is_empty() => return Ok(r.data),
|
||||
Ok(Ok(_)) => last_err = format!("{label}内容为空"),
|
||||
Ok(Err(e)) => last_err = format!("下载失败: {e}"),
|
||||
Err(_) => last_err = "下载超时(120s)".into(),
|
||||
}
|
||||
}
|
||||
Err(last_err)
|
||||
}
|
||||
|
||||
/// 下载飞书图片消息资源并落盘,返回本地引用 ContentPart(#958 引用化存储)。
|
||||
/// 存储面只存 `file://` 引用(base64 不进 SQLite,防大图随历史全量重放膨胀),
|
||||
/// 发送请求时由 df-ai::image_ref 单点按需读盘转 base64(模型使用按需转换)。
|
||||
@@ -396,53 +515,20 @@ async fn download_feishu_image(
|
||||
message_id: &str,
|
||||
file_key: &str,
|
||||
) -> Result<ContentPart, String> {
|
||||
// 下载带防线(对齐 u-claw fetchResource 经验):3 次指数退避(1s/4s)+单次 120s 超时
|
||||
// ——飞书资源接口偶发抖动,无重试时用户收到一次性失败;超时防接口挂起拖死受理链。
|
||||
// 空响应与错误同待遇进重试(可能为服务端瞬时异常),耗尽后报最后一次原因
|
||||
let resp = {
|
||||
let mut last_err = String::from("下载失败: 未知错误");
|
||||
let mut out = None;
|
||||
for attempt in 0u32..3 {
|
||||
if attempt > 0 {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1 << (attempt - 1))).await;
|
||||
}
|
||||
let dl = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(120),
|
||||
client.channel_messaging().download_message_resource(
|
||||
message_id,
|
||||
file_key,
|
||||
"image",
|
||||
&RequestOption::default(),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
match dl {
|
||||
Ok(Ok(r)) if !r.data.is_empty() => {
|
||||
out = Some(r);
|
||||
break;
|
||||
}
|
||||
Ok(Ok(_)) => last_err = "图片内容为空".into(),
|
||||
Ok(Err(e)) => last_err = format!("下载失败: {e}"),
|
||||
Err(_) => last_err = "下载超时(120s)".into(),
|
||||
}
|
||||
}
|
||||
match out {
|
||||
Some(r) => r,
|
||||
None => return Err(last_err),
|
||||
}
|
||||
};
|
||||
if resp.data.len() > MAX_IMAGE_BYTES {
|
||||
let data = download_message_resource_with_retry(client, message_id, file_key, "image", "图片")
|
||||
.await?;
|
||||
if data.len() > MAX_IMAGE_BYTES {
|
||||
return Err(format!(
|
||||
"图片超过 10MB 上限(约 {}MB),请压缩后重发",
|
||||
resp.data.len() / 1024 / 1024
|
||||
data.len() / 1024 / 1024
|
||||
));
|
||||
}
|
||||
let media_type = sniff_image_mime(&resp.data)
|
||||
let media_type = sniff_image_mime(&data)
|
||||
.ok_or_else(|| "不支持的图片格式(仅支持 png/jpeg/webp/gif)".to_string())?;
|
||||
// 存储决策收口 media_store:hash 去重落盘,OSS 配置在则双写并引用 https(跨设备可解析),
|
||||
// 失败降级本机 file://(不阻塞)。本函数只管飞书协议(下载+防线),不管存储。
|
||||
// 飞书 image 消息无原始文件名(None=纯 hash 名)
|
||||
let url = store.save(&resp.data, media_type, None).await?;
|
||||
let url = store.save(&data, media_type, None).await?;
|
||||
Ok(ContentPart::Image {
|
||||
url: Some(url),
|
||||
base64: None,
|
||||
@@ -451,6 +537,67 @@ async fn download_feishu_image(
|
||||
})
|
||||
}
|
||||
|
||||
/// 文件消息喂模型的任务语境:告知文件名与本机落盘路径,引导用 read_file 按需读取;
|
||||
/// 二进制/超大文件的读取局限如实交底,防模型谎称已完整处理。落盘前(无路径)给
|
||||
/// 占位版,仅供空判与命令/审批判定,不喂模型不落卡
|
||||
fn file_inbound_prompt(file_name: &str, path: Option<&str>) -> String {
|
||||
match path {
|
||||
Some(p) => format!(
|
||||
"(用户通过飞书发来文件「{file_name}」,已保存到本地路径 {p};请按用户需求用 read_file 工具读取该文件处理。二进制/超大文件可能无法完整读取,如实告知用户)"
|
||||
),
|
||||
None => format!("(用户通过飞书发来文件「{file_name}」,保存中)"),
|
||||
}
|
||||
}
|
||||
|
||||
/// 文件超限判定:超 20MB 上限时给可读错误话术(提示压缩/拆分),宁拒不落盘
|
||||
fn file_size_over_limit_error(len: usize) -> Option<String> {
|
||||
(len > MAX_FILE_BYTES).then(|| {
|
||||
format!(
|
||||
"文件超过 20MB 上限(约 {}MB),请压缩或拆分后重发",
|
||||
len / 1024 / 1024
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// 文件展示名裁决:SDK 归一化 file_name 优先(保真,清洗首尾空白);缺失回退
|
||||
/// `file_<内容 hash 前 8>`(与落盘 hash 命名同源,可对账辨认)
|
||||
fn file_display_name(raw: &str, bytes: &[u8]) -> String {
|
||||
let raw = raw.trim();
|
||||
if raw.is_empty() {
|
||||
format!("file_{}", &crate::media_store::content_hash(bytes)[..8])
|
||||
} else {
|
||||
raw.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// 下载飞书文件消息资源并落盘,返回 (展示名, 本机绝对路径)。
|
||||
/// 与图片同一资源接口(resource_type=file)与下载防线;落盘走 media_store 通用入口
|
||||
/// (hash 去重+OSS 双写+失败降级,原文件名缀后保目录可读)。返回本机路径喂模型
|
||||
/// read_file(OSS https 引用对本机读取无意义,不作返回);超 20MB 拒收回可读错误
|
||||
async fn download_feishu_file(
|
||||
client: &LarkClient,
|
||||
store: &crate::media_store::MediaStore,
|
||||
message_id: &str,
|
||||
res: &larksuite_oapi_sdk_rs::channel::ChannelResource,
|
||||
) -> Result<(String, String), String> {
|
||||
let data =
|
||||
download_message_resource_with_retry(client, message_id, &res.file_key, "file", "文件")
|
||||
.await?;
|
||||
if let Some(err) = file_size_over_limit_error(data.len()) {
|
||||
return Err(err);
|
||||
}
|
||||
let display_name = file_display_name(&res.file_name, &data);
|
||||
let original = res.file_name.trim();
|
||||
let (_, path) = store
|
||||
.save_with_path(
|
||||
&data,
|
||||
"application/octet-stream",
|
||||
(!original.is_empty()).then_some(original),
|
||||
)
|
||||
.await?;
|
||||
Ok((display_name, path.to_string_lossy().into_owned()))
|
||||
}
|
||||
|
||||
/// 读取媒体 OSS 配置(KV `media-oss-config`;未配置/解析失败 → None=纯本地模式)
|
||||
async fn read_media_oss_config(
|
||||
db: &df_storage::db::Database,
|
||||
@@ -588,12 +735,21 @@ async fn handle_message(
|
||||
) {
|
||||
// D3:任何入站消息都是事件管道存活证据,先于一切过滤更新活性时间戳
|
||||
ctx.last_alive.store(now_secs(), Ordering::SeqCst);
|
||||
// 类型分流(#958 图片入站):text 原样;image 走下载装配(vision ContentPart);
|
||||
// 其余类型维持 #25 提示卡。image 消息 SDK 归一化已把 image_key 放入
|
||||
// msg.resources(ChannelResource),无需自行解析 content JSON。
|
||||
let image_key = if msg.message_type == "image" {
|
||||
// 群聊响应门控对齐 u-claw 模式(feishu_events.go mentionedBot 四条):①@自己响应
|
||||
// ②@所有人响应 ③@别的bot不响应 ④无mention静默旁观;私聊恒响应。SDK 的
|
||||
// mentioned_bot/mention_all 已承载①②③的精确判定。门控必须在类型分流之前——
|
||||
// 分流段对语音等未支持类型会回提示卡,门控放后面时未艾特的群消息也会得到回复
|
||||
// (2026-10-15 用户实测「群里没艾特也处理」根因)。
|
||||
if msg.chat_type == "group" && !msg.mentioned_bot && !msg.mention_all {
|
||||
return;
|
||||
}
|
||||
// 类型分流(#958 图片入站,文件入站同源扩展):text 原样;image 走下载装配(vision
|
||||
// ContentPart);file 走下载落盘(read_file 本机路径);语音等其余类型维持提示卡。
|
||||
// image/file 消息 SDK 归一化已把 file_key/file_name 放入 msg.resources(ChannelResource),
|
||||
// 无需自行解析 content JSON。
|
||||
let (image_key, file_res) = if msg.message_type == "image" {
|
||||
match msg.resources.iter().find(|r| r.resource_type == "image") {
|
||||
Some(r) => Some(r.file_key.clone()),
|
||||
Some(r) => (Some(r.file_key.clone()), None),
|
||||
None => {
|
||||
let _ = reply_markdown_card(
|
||||
&ctx.client,
|
||||
@@ -604,26 +760,39 @@ async fn handle_message(
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if msg.message_type == "file" {
|
||||
match msg.resources.iter().find(|r| r.resource_type == "file") {
|
||||
Some(r) => (None, Some(r.clone())),
|
||||
None => {
|
||||
let _ = reply_markdown_card(
|
||||
&ctx.client,
|
||||
&msg.message_id,
|
||||
"⚠️ 文件消息缺少 file_key,无法处理。",
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if msg.message_type != "text" {
|
||||
// #25 非文本消息静默丢修复:回提示卡(D7 媒体能力前的兜底),不再零反馈。
|
||||
// 补替代路径引导:用户发文件等往往是想让 AI 处理内容,直接告知改用文字描述
|
||||
// #25 非文本消息静默丢修复:回提示卡,不再零反馈。文本/图片/文件已支持,
|
||||
// 余下语音等类型如实告知规划中
|
||||
let _ = reply_markdown_card(
|
||||
&ctx.client,
|
||||
&msg.message_id,
|
||||
"📎 暂支持文本与图片消息,文件/语音等其他类型规划中。\n\n如需处理文件内容,请用文字描述你的需求(如「把这段文字翻译成英文:…」)。",
|
||||
"📎 暂支持文本、图片与文件消息,语音等其他类型规划中。",
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
} else {
|
||||
None
|
||||
(None, None)
|
||||
};
|
||||
if msg.chat_type == "group" && !msg.mentioned_bot {
|
||||
return;
|
||||
}
|
||||
// 图片消息不带文字(飞书 image 为独立消息类型),喂固定引导词交代任务语境;
|
||||
// msg.text 的 markdown 图链([图片](image_key))对模型无意义,不喂
|
||||
let text = if image_key.is_some() {
|
||||
// 附件消息不带文字(飞书 image/file 均为独立消息类型),msg.text 的图链/文件标签
|
||||
// 对模型无意义,不喂:图片喂固定引导词交代任务语境;文件语境需落盘路径,先预填
|
||||
// 文件名占位版(命令/审批判定恒不命中),下载点覆写为含路径终版
|
||||
let mut text = if image_key.is_some() {
|
||||
IMAGE_INBOUND_PROMPT.to_string()
|
||||
} else if let Some(res) = &file_res {
|
||||
file_inbound_prompt(res.file_name.trim(), None)
|
||||
} else {
|
||||
let text = msg.text.clone().unwrap_or_default().trim().to_string();
|
||||
// 飞书 @ 占位清洗(如 @_user_1):@ 语义已由 mentioned_bot 承载,占位串只污染文本
|
||||
@@ -685,6 +854,30 @@ async fn handle_message(
|
||||
None => None,
|
||||
};
|
||||
|
||||
// 文件入站:下载消息资源→落盘拿本机路径→覆写任务语境终版(含路径,模型 read_file
|
||||
// 按需读取)。与图片同段白名单后下载(未授权不烧流量)、占位发票前早退(失败回
|
||||
// 可读错误卡,超 20MB 话术在下载错误内)
|
||||
if let Some(res) = &file_res {
|
||||
let state = ctx.app.state::<crate::state::AppState>();
|
||||
let oss_cfg = read_media_oss_config(&state.db).await;
|
||||
let store = crate::media_store::MediaStore::new(state.data_dir.clone(), oss_cfg);
|
||||
match download_feishu_file(&ctx.client, &store, &message_id, res).await {
|
||||
Ok((name, path)) => {
|
||||
text = file_inbound_prompt(&name, Some(&path));
|
||||
}
|
||||
Err(e) => {
|
||||
feishu_log(&format!("文件下载失败 chat={chat_id}: {e}"));
|
||||
let _ = reply_markdown_card(
|
||||
&ctx.client,
|
||||
&message_id,
|
||||
&format!("⚠️ 文件下载失败:{e}\n\n请重发,或直接用文字描述你的需求。"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 命令通路(#30 容错):全角/大小写/附言归一后识别,仅命令词走控制面,任务原文不动。
|
||||
// 顺序约束:命令与审批决议须先于注入旁路——conv 活跃时这两类文本否则会被当补充
|
||||
// 指令注入任务;未知命令词落回常规任务路径,零行为变更
|
||||
@@ -777,10 +970,13 @@ async fn handle_message(
|
||||
}
|
||||
}
|
||||
|
||||
// 24 审批决议通路:该会话有挂起审批时,「批准/拒绝」直调审批原语不入对话链路
|
||||
// (决议文本若落常规路径会被注入运行中任务,审批永远无人拍板)。决议取该会话最新
|
||||
// 一条挂起;无挂起不拦截,文本照常落常规路径,零行为变更
|
||||
if text == "批准" || text == "拒绝" {
|
||||
// 24 审批决议通路(F5-1 决议词容错):该会话有挂起审批时,决议词(同意/批准/通过 =
|
||||
// 批准;拒绝/驳回/不同意 = 拒绝,含空白/尾标点/大小写容错,集合对齐按钮卡文案)直调
|
||||
// 审批原语不入对话链路(决议文本若落常规路径会被注入运行中任务,审批永远无人拍板)。
|
||||
// 决议取该会话最新一条挂起;无挂起不拦截,文本照常落常规路径,零行为变更——唯一
|
||||
// 例外(F5-2 迟到决议):该 chat 近期刚有审批终态(桌面已决议/超时自动取消),决议词
|
||||
// 命中却无可拍板对象,回「已处理」提示而非当补充指令注入任务流
|
||||
if let Some(approved) = parse_approval_verdict(&text) {
|
||||
let state = ctx.app.state::<crate::state::AppState>();
|
||||
let conv_id = ctx.chat_map.lock().await.get(&chat_id).cloned();
|
||||
let pending = match conv_id {
|
||||
@@ -788,7 +984,6 @@ async fn handle_message(
|
||||
None => None,
|
||||
};
|
||||
if let Some(tc_id) = pending {
|
||||
let approved = text == "批准";
|
||||
feishu_log(&format!("审批决议 chat={chat_id} tc={tc_id} approved={approved}"));
|
||||
// 2026-10-08 决议后追加执行结果:先订阅(工具执行前,防 publish_event 无订阅者跳过),
|
||||
// 再调 ai_approve,后 spawn watcher 消费 AiToolCallCompleted 拿结果摘要
|
||||
@@ -814,7 +1009,7 @@ async fn handle_message(
|
||||
None => 0,
|
||||
};
|
||||
let reply = if remaining > 0 {
|
||||
format!("{reply}\n\n⚠️ 本会话还有 {remaining} 条待审批,请继续回复「批准」或「拒绝」。")
|
||||
format!("{reply}\n\n⚠️ 本会话还有 {remaining} 条待审批,请继续回复「同意 / 批准」或「拒绝」。")
|
||||
} else {
|
||||
reply
|
||||
};
|
||||
@@ -825,6 +1020,29 @@ async fn handle_message(
|
||||
}
|
||||
return;
|
||||
}
|
||||
// F5-2 迟到决议:无挂起但该 chat 近期有审批终态——如实提示,不落注入旁路
|
||||
let recently_resolved = {
|
||||
let now = now_secs();
|
||||
resolved_chats()
|
||||
.lock()
|
||||
.map(|m| {
|
||||
m.get(&chat_id)
|
||||
.is_some_and(|(at, _)| within_resolved_window(*at, now))
|
||||
})
|
||||
.unwrap_or(false)
|
||||
};
|
||||
if recently_resolved {
|
||||
feishu_log(&format!("迟到决议提示 chat={chat_id} text={}", truncate(&text, 40)));
|
||||
reply_message(
|
||||
&ctx.client,
|
||||
&message_id,
|
||||
&chat_id,
|
||||
"ℹ️ 该审批已处理(已批准/已拒绝或超时自动取消),无需再回复;可发 /status 查看任务状态。",
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
// 近期无审批终态:决议词属普通聊天文本,落常规路径(现状语义保留)
|
||||
}
|
||||
|
||||
// ── 纠偏注入旁路(todo.md 16,2026-10-06):会话运行中 → 直接注入运行中 conv,不排队 ──
|
||||
@@ -836,9 +1054,10 @@ async fn handle_message(
|
||||
let state = ctx.app.state::<crate::state::AppState>();
|
||||
let conv_id_now = ctx.chat_map.lock().await.get(&chat_id).cloned();
|
||||
if let Some(cid) = conv_id_now {
|
||||
// 图片消息不注入:inject_runtime_message 只收文本,注入则图被丢、模型只见
|
||||
// 引导词空跑;落常规路径由受理守卫拦,语义诚实(任务占用中,稍后重发)
|
||||
if image_key.is_none() && state.conv_states.is_active(&cid) {
|
||||
// 附件消息(图片/文件)不注入,走与图片相同的后续链:inject_runtime_message
|
||||
// 只收文本,图片注入则图被丢、模型只见引导词空跑;文件作为独立新任务语义
|
||||
// 同样应过受理/防抖/发票链,conv 占用时受理守卫如实回告,不并入运行中任务
|
||||
if image_key.is_none() && file_res.is_none() && state.conv_states.is_active(&cid) {
|
||||
match crate::commands::ai::commands::chat::inject_runtime_message(&state, &cid, &text).await {
|
||||
Ok(true) => {
|
||||
let _ = reply_markdown_card(&ctx.client, &message_id, "✅ 补充指令已注入运行中任务,下一轮生效").await;
|
||||
@@ -1313,48 +1532,77 @@ async fn run_approval_notifier(ctx: Arc<Ctx>) {
|
||||
let mut rx = state.ai_event_bus.subscribe();
|
||||
loop {
|
||||
match rx.recv().await {
|
||||
Ok(v) => {
|
||||
if v.get("type").and_then(|t| t.as_str()) != Some("AiApprovalRequired") {
|
||||
continue;
|
||||
}
|
||||
let Some(cid) = v.get("conversation_id").and_then(|c| c.as_str()) else {
|
||||
continue;
|
||||
};
|
||||
let chat_id = ctx
|
||||
.chat_map
|
||||
.lock()
|
||||
.await
|
||||
.iter()
|
||||
.find(|(_, c)| c.as_str() == cid)
|
||||
.map(|(k, _)| k.clone());
|
||||
let Some(chat_id) = chat_id else {
|
||||
continue;
|
||||
};
|
||||
let name = v.get("name").and_then(|n| n.as_str()).unwrap_or("工具");
|
||||
let reason = v
|
||||
.get("reason")
|
||||
.and_then(|r| r.as_str())
|
||||
.unwrap_or("")
|
||||
.replace('\n', " ");
|
||||
let brief = truncate(&reason, 80);
|
||||
// 审批卡按钮化(2026-10-08):改用带「同意/拒绝」按钮的交互卡片,
|
||||
// 按钮 value 携带 {approval_id, approved},回调经 on_card_action →
|
||||
// handle_card_action → ai_approve 原语(与文本决议通路同原语,双通道并存)。
|
||||
// 文本「批准/拒绝」通路保留作降级(旧卡片/按钮回调异常时仍可用)。
|
||||
let tc_id = v.get("id").and_then(|i| i.as_str()).unwrap_or("");
|
||||
if tc_id.is_empty() {
|
||||
// 无 tool_call_id 无法构造按钮载荷,降级文本卡(回复「批准/拒绝」)
|
||||
let card = if brief.is_empty() {
|
||||
format!("⏸ 需审批: `{name}`。回复「批准」或「拒绝」继续")
|
||||
} else {
|
||||
format!("⏸ 需审批: `{name}` {brief}。回复「批准」或「拒绝」继续")
|
||||
Ok(v) => match v.get("type").and_then(|t| t.as_str()) {
|
||||
// F5-2 审批终态闭环:批/拒/超时(前端超时亦调 ai_approve(false))全路径 emit
|
||||
// AiApprovalResult——订阅同 bus 复用 spawn_approval_result_watcher 先例,零后端
|
||||
// 改动。飞书侧原按钮卡原地更新为终态(不再恒挂可点),并记 chat 维度终态
|
||||
// (迟到决议提示判据)。事件无决议来源字段,拒绝文案注明含超时自动取消;
|
||||
// 飞书侧自身决议同经此收口(与决议回执双保险,防旧卡再点)
|
||||
Some("AiApprovalResult") => {
|
||||
let Some(cid) = v.get("conversation_id").and_then(|c| c.as_str()) else {
|
||||
continue;
|
||||
};
|
||||
send_markdown_card(&ctx.client, "", &chat_id, &card).await;
|
||||
} else {
|
||||
send_approval_button_card(&ctx.client, &chat_id, tc_id, name, &brief).await;
|
||||
let tc_id = v.get("id").and_then(|i| i.as_str()).unwrap_or("");
|
||||
let approved = v
|
||||
.get("approved")
|
||||
.and_then(|b| b.as_bool())
|
||||
.unwrap_or(false);
|
||||
let Some(chat_id) = chat_of_conv(&ctx, cid).await else {
|
||||
continue;
|
||||
};
|
||||
note_approval_resolved(&chat_id, approved);
|
||||
let mid = approval_cards()
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|mut cards| cards.remove(tc_id).map(|(mid, _)| mid))
|
||||
.filter(|m| !m.is_empty());
|
||||
// 无卡句柄(降级文本卡/他路无原卡):只记终态,迟到提示仍生效
|
||||
if let Some(mid) = mid {
|
||||
let text = if approved {
|
||||
"✅ 该审批已批准,任务继续执行(按钮已失效)。"
|
||||
} else {
|
||||
"🚫 该审批已结束:已拒绝或超时自动取消(按钮已失效)。"
|
||||
};
|
||||
let updated = update_card(&ctx.client, &mid, text).await;
|
||||
feishu_log(&format!(
|
||||
"审批终态收口 chat={chat_id} tc={tc_id} approved={approved} 更新={updated}"
|
||||
));
|
||||
}
|
||||
}
|
||||
feishu_log(&format!("审批挂起推送 chat={chat_id} conv={cid} tool={name}"));
|
||||
}
|
||||
Some("AiApprovalRequired") => {
|
||||
let Some(cid) = v.get("conversation_id").and_then(|c| c.as_str()) else {
|
||||
continue;
|
||||
};
|
||||
let Some(chat_id) = chat_of_conv(&ctx, cid).await else {
|
||||
continue;
|
||||
};
|
||||
let name = v.get("name").and_then(|n| n.as_str()).unwrap_or("工具");
|
||||
let reason = v
|
||||
.get("reason")
|
||||
.and_then(|r| r.as_str())
|
||||
.unwrap_or("")
|
||||
.replace('\n', " ");
|
||||
let brief = truncate(&reason, 80);
|
||||
// 审批卡按钮化(2026-10-08):改用带「同意/拒绝」按钮的交互卡片,
|
||||
// 按钮 value 携带 {approval_id, approved},回调经 on_card_action →
|
||||
// handle_card_action → ai_approve 原语(与文本决议通路同原语,双通道并存)。
|
||||
// 文本决议词通路保留作降级(旧卡片/按钮回调异常时仍可用)。
|
||||
let tc_id = v.get("id").and_then(|i| i.as_str()).unwrap_or("");
|
||||
if tc_id.is_empty() {
|
||||
// 无 tool_call_id 无法构造按钮载荷,降级文本卡(回复决议词)
|
||||
let card = if brief.is_empty() {
|
||||
format!("⏸ 需审批: `{name}`。回复「同意 / 批准」或「拒绝」继续")
|
||||
} else {
|
||||
format!("⏸ 需审批: `{name}` {brief}。回复「同意 / 批准」或「拒绝」继续")
|
||||
};
|
||||
send_markdown_card(&ctx.client, "", &chat_id, &card).await;
|
||||
} else {
|
||||
send_approval_button_card(&ctx.client, &chat_id, tc_id, name, &brief).await;
|
||||
}
|
||||
feishu_log(&format!("审批挂起推送 chat={chat_id} conv={cid} tool={name}"));
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
|
||||
Err(tokio::sync::broadcast::error::RecvError::Closed) => return,
|
||||
}
|
||||
@@ -1390,15 +1638,8 @@ async fn handle_card_action(
|
||||
if chat_id.is_empty() {
|
||||
let state = ctx.app.state::<crate::state::AppState>();
|
||||
if let Some(cid) = approval_conversation_id(&state, &approval_id).await {
|
||||
chat_id = ctx
|
||||
.chat_map
|
||||
.lock()
|
||||
.await
|
||||
.iter()
|
||||
.find(|(_, c)| c.as_str() == cid)
|
||||
.map(|(k, _)| k.clone())
|
||||
.unwrap_or_default();
|
||||
if !chat_id.is_empty() {
|
||||
if let Some(found) = chat_of_conv(&ctx, &cid).await {
|
||||
chat_id = found;
|
||||
feishu_log(&format!("卡片回调 chat_id 缺失,反查补齐 chat={chat_id}"));
|
||||
}
|
||||
}
|
||||
@@ -1460,9 +1701,14 @@ async fn handle_card_action(
|
||||
}
|
||||
}
|
||||
|
||||
/// F5-3 结果 watcher 超时话术:60s 未见完成事件时回告去向,不静默弃守让用户空等
|
||||
const APPROVAL_RESULT_TIMEOUT_MSG: &str =
|
||||
"⏳ 工具执行耗时较长(超 60s 仍无结果),已停止自动回推;完成后可在桌面端查看该工具的执行结果。";
|
||||
|
||||
/// 审批决议后执行结果 watcher(2026-10-08):订阅 ai_event_bus 的 AiToolCallCompleted
|
||||
/// (匹配 tool_call_id),拿 result 摘要回推 chat。原决议后只回「已批准」,用户不知工具
|
||||
/// 执行结果(成功/失败/输出)。设 60s 超时兜底(工具执行通常秒级,长工具超时静默放弃)。
|
||||
/// 执行结果(成功/失败/输出)。设 60s 超时兜底(工具执行通常秒级,长工具超时回告去向
|
||||
/// 后放弃,F5-3 修静默弃守)。
|
||||
///
|
||||
/// 订阅须在 ai_approve 调用前完成——publish_event 在无订阅者时跳过序列化,晚订阅必丢事件。
|
||||
fn spawn_approval_result_watcher(
|
||||
@@ -1477,6 +1723,7 @@ fn spawn_approval_result_watcher(
|
||||
loop {
|
||||
let remaining = deadline.saturating_duration_since(tokio::time::Instant::now());
|
||||
if remaining.is_zero() {
|
||||
let _ = send_markdown_card(&ctx.client, "", &chat_id, APPROVAL_RESULT_TIMEOUT_MSG).await;
|
||||
feishu_log(&format!("[approval-result] 等待工具结果超时 tc={tool_call_id}"));
|
||||
return;
|
||||
}
|
||||
@@ -1502,6 +1749,7 @@ fn spawn_approval_result_watcher(
|
||||
Ok(Err(tokio::sync::broadcast::error::RecvError::Lagged(_))) => continue,
|
||||
Ok(Err(tokio::sync::broadcast::error::RecvError::Closed)) => return,
|
||||
Err(_) => {
|
||||
let _ = send_markdown_card(&ctx.client, "", &chat_id, APPROVAL_RESULT_TIMEOUT_MSG).await;
|
||||
feishu_log(&format!("[approval-result] 等待工具结果超时 tc={tool_call_id}"));
|
||||
return;
|
||||
}
|
||||
@@ -1520,10 +1768,12 @@ async fn send_approval_button_card(
|
||||
tool_name: &str,
|
||||
brief: &str,
|
||||
) {
|
||||
// F5-1 文案统一:副注提示文字决议词(按钮不可用时降级通道),词表与 parse_approval_verdict 同源
|
||||
let hint = "点击按钮,或回复「同意 / 批准 / 通过 / 拒绝」";
|
||||
let detail = if brief.is_empty() {
|
||||
format!("⏸ 需审批: `{tool_name}`")
|
||||
format!("⏸ 需审批: `{tool_name}`\n\n{hint}")
|
||||
} else {
|
||||
format!("⏸ 需审批: `{tool_name}`\n\n{brief}")
|
||||
format!("⏸ 需审批: `{tool_name}`\n\n{brief}\n\n{hint}")
|
||||
};
|
||||
// 按钮 value 需为 SDK 的 JsonValue(其实现了 From<serde_json::Value>,直接 into 转换)
|
||||
let to_json_value = |v: serde_json::Value| -> larksuite_oapi_sdk_rs::JsonValue { v.into() };
|
||||
@@ -1554,7 +1804,7 @@ async fn send_approval_button_card(
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
tracing::warn!("[feishu] 审批按钮卡校验失败,降级文本卡: {e}");
|
||||
let fallback = format!("⏸ 需审批: `{tool_name}` {brief}。回复「批准」或「拒绝」继续");
|
||||
let fallback = format!("⏸ 需审批: `{tool_name}` {brief}。回复「同意 / 批准 / 通过 / 拒绝」继续");
|
||||
send_markdown_card(client, "", chat_id, &fallback).await;
|
||||
return;
|
||||
}
|
||||
@@ -1571,6 +1821,8 @@ async fn send_approval_button_card(
|
||||
.await
|
||||
{
|
||||
Ok(sent) if !sent.message_id.is_empty() => {
|
||||
// F5-2 登记卡句柄:桌面决议/超时终态事件到达时按 tc_id 原地更新该卡为终态
|
||||
note_approval_card(approval_id, &sent.message_id);
|
||||
feishu_log(&format!("审批按钮卡已发 chat={chat_id} card={}", sent.message_id));
|
||||
}
|
||||
Ok(_) => {
|
||||
@@ -1578,12 +1830,38 @@ async fn send_approval_button_card(
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("[feishu] 审批按钮卡发送失败,降级文本卡: {e}");
|
||||
let fallback = format!("⏸ 需审批: `{tool_name}` {brief}。回复「批准」或「拒绝」继续");
|
||||
let fallback = format!("⏸ 需审批: `{tool_name}` {brief}。回复「同意 / 批准 / 通过 / 拒绝」继续");
|
||||
send_markdown_card(client, "", chat_id, &fallback).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 登记审批按钮卡句柄(终态原地更新用),顺带清窗口外陈旧条目
|
||||
fn note_approval_card(tc_id: &str, message_id: &str) {
|
||||
let now = now_secs();
|
||||
let Ok(mut cards) = approval_cards().lock() else { return };
|
||||
cards.retain(|_, (_, at)| within_resolved_window(*at, now));
|
||||
cards.insert(tc_id.to_string(), (message_id.to_string(), now));
|
||||
}
|
||||
|
||||
/// conv → 绑定飞书 chat 反查(notifier 推卡/终态收口共用;无绑定(纯桌面会话)None)
|
||||
async fn chat_of_conv(ctx: &Ctx, conv_id: &str) -> Option<String> {
|
||||
ctx.chat_map
|
||||
.lock()
|
||||
.await
|
||||
.iter()
|
||||
.find(|(_, c)| c.as_str() == conv_id)
|
||||
.map(|(k, _)| k.clone())
|
||||
}
|
||||
|
||||
/// 记录 chat 维度审批终态(迟到决议提示判据),顺带清窗口外陈旧条目
|
||||
fn note_approval_resolved(chat_id: &str, approved: bool) {
|
||||
let now = now_secs();
|
||||
let Ok(mut chats) = resolved_chats().lock() else { return };
|
||||
chats.retain(|_, (at, _)| within_resolved_window(*at, now));
|
||||
chats.insert(chat_id.to_string(), (now, approved));
|
||||
}
|
||||
|
||||
/// 该 conv 最新一条挂起审批的 tool_call_id(决议原语的消费目标);无挂起返回 None。
|
||||
/// created_at 缺失视为最旧(宁取有时序的),同刻并列取遍历后者(HashMap 无序,可接受)
|
||||
async fn latest_pending_approval(
|
||||
@@ -2402,9 +2680,10 @@ async fn save_chat_map(db: &df_storage::db::Database, map: &HashMap<String, Stri
|
||||
mod tests {
|
||||
use super::{
|
||||
ContentPart, DebounceEntry, delivery_blocked, extract_delivery_paths, feishu_file_type,
|
||||
heartbeat_due, is_terminal_push, md_to_lark_friendly, merge_debounce_parts,
|
||||
merge_debounce_text, msg_after_acceptance, parse_command, sniff_image_mime,
|
||||
strip_mention_placeholders, stream_preview,
|
||||
file_display_name, file_inbound_prompt, file_size_over_limit_error, heartbeat_due,
|
||||
is_terminal_push, md_to_lark_friendly, merge_debounce_parts, merge_debounce_text,
|
||||
msg_after_acceptance, parse_approval_verdict, parse_command, sniff_image_mime,
|
||||
strip_mention_placeholders, stream_preview, within_resolved_window,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -2453,6 +2732,45 @@ mod tests {
|
||||
assert_eq!(sniff_image_mime(b"RIFF\x24\x08\x00\x00AVI "), None);
|
||||
}
|
||||
|
||||
// ── 文件消息入站:任务语境构造/大小限流/展示名回退 ──
|
||||
|
||||
#[test]
|
||||
fn file_prompt_carries_name_path_and_read_guidance() {
|
||||
// 落盘后终版:文件名+本机路径+read_file 引导+读取局限交底,四要素齐备
|
||||
let full = file_inbound_prompt("报表.xlsx", Some("E:\\data\\media\\ab12_报表.xlsx"));
|
||||
assert!(full.contains("「报表.xlsx」"), "缺文件名: {full}");
|
||||
assert!(full.contains("本地路径 E:\\data\\media\\ab12_报表.xlsx"), "缺路径: {full}");
|
||||
assert!(full.contains("read_file"), "缺读取引导: {full}");
|
||||
assert!(full.contains("如实告知用户"), "缺读取局限交底: {full}");
|
||||
// 落盘前占位版:不含路径(不喂模型不落卡,仅供空判与命令/审批判定)
|
||||
let pending = file_inbound_prompt("报表.xlsx", None);
|
||||
assert!(!pending.contains("本地路径"), "占位版不该有路径: {pending}");
|
||||
assert!(pending.contains("「报表.xlsx」"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_size_limit_rejects_over_20mb_only() {
|
||||
// 恰 20MB 放行(> 判定),超限给可读错误话术(含实际大小,引导压缩/拆分)
|
||||
assert_eq!(file_size_over_limit_error(20 * 1024 * 1024), None);
|
||||
assert_eq!(file_size_over_limit_error(1024), None);
|
||||
let err = file_size_over_limit_error(21 * 1024 * 1024).unwrap();
|
||||
assert!(err.contains("20MB") && err.contains("21MB"), "话术缺限值/实际值: {err}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_display_name_prefers_original_and_hash_fallback() {
|
||||
// 原始名保真(清洗首尾空白);缺失回退 file_<hash 前 8>,不同内容回退名不同
|
||||
assert_eq!(file_display_name(" 报表.xlsx ", b"abc"), "报表.xlsx");
|
||||
let fallback = file_display_name("", b"abc");
|
||||
assert!(fallback.starts_with("file_"), "回退名形态: {fallback}");
|
||||
assert_eq!(fallback.len(), "file_".len() + 8, "回退名取 hash 前 8: {fallback}");
|
||||
assert_ne!(
|
||||
fallback,
|
||||
file_display_name(" ", b"abcd"),
|
||||
"不同内容的回退名应可区分"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_case_and_tail_tolerance() {
|
||||
// 30:/new 大小写与附言容错,附言不烧 LLM
|
||||
@@ -2703,4 +3021,56 @@ mod tests {
|
||||
Some(vec![ContentPart::image_url("https://x/2.png")])
|
||||
);
|
||||
}
|
||||
|
||||
// ── F5-1 决议词识别(表驱动) ──
|
||||
|
||||
#[test]
|
||||
fn verdict_table_approve_and_reject_with_tolerance() {
|
||||
// 批准集含按钮卡文案「同意」;拒绝集含「不同意」;空白/尾标点/大小写/半全角容错
|
||||
let table = [
|
||||
// (输入, 期望)
|
||||
("同意", Some(true)),
|
||||
("批准", Some(true)),
|
||||
("通过", Some(true)),
|
||||
("approve", Some(true)),
|
||||
(" 同意 ", Some(true)),
|
||||
("批准。", Some(true)),
|
||||
("同意!", Some(true)),
|
||||
("通过~", Some(true)),
|
||||
(" 拒绝 ", Some(false)), // 全角空格
|
||||
("REJECT", Some(false)),
|
||||
("Approve", Some(true)), // 全角 ASCII 变体
|
||||
("拒绝", Some(false)),
|
||||
("驳回", Some(false)),
|
||||
("不同意", Some(false)),
|
||||
("驳回。", Some(false)),
|
||||
("不同意?", Some(false)),
|
||||
];
|
||||
for (input, expected) in table {
|
||||
assert_eq!(parse_approval_verdict(input), expected, "case {input:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verdict_plain_text_not_misjudged() {
|
||||
// 普通文本/带语气词/长句/子串形态不误判(整词精确匹配,「不同意」含「同意」靠整词防反判)
|
||||
let plain = [
|
||||
"你好", "我同意这个方案", "不同意这个做法", "批准吧", "通不过", "同意一下再看看",
|
||||
"/status", "拒绝的理由如下", "通过率不高", "", "ok 同意吗",
|
||||
];
|
||||
for input in plain {
|
||||
assert_eq!(parse_approval_verdict(input), None, "case {input:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// ── F5-2 迟到决议窗口判定 ──
|
||||
|
||||
#[test]
|
||||
fn resolved_window_boundary() {
|
||||
// 30min 窗口内算「刚终态」(迟到决议提示),窗外视为无审批语境(普通消息语义)
|
||||
assert!(within_resolved_window(1000, 1000 + 1799));
|
||||
assert!(within_resolved_window(1000, 1000 + 1800 - 1));
|
||||
assert!(!within_resolved_window(1000, 1000 + 1800));
|
||||
assert!(!within_resolved_window(1000, 1000 + 7200));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,6 +496,8 @@ pub fn run() {
|
||||
commands::ai::ai_pending_tool_calls,
|
||||
commands::ai::ai_chat_clear,
|
||||
commands::ai::ai_is_generating,
|
||||
// 桌面端补充注入(运行中会话 u-claw 语义:补充并进当前回答,不开新轮不入队)
|
||||
commands::ai::ai_inject_runtime,
|
||||
// F-15 阶段2 手动上下文管理:分段归档 + LLM 压缩
|
||||
commands::ai::ai_chat_clear_context,
|
||||
commands::ai::ai_chat_compress_context,
|
||||
|
||||
@@ -98,6 +98,20 @@ impl MediaStore {
|
||||
media_type: &str,
|
||||
original_name: Option<&str>,
|
||||
) -> Result<String, String> {
|
||||
self.save_with_path(bytes, media_type, original_name)
|
||||
.await
|
||||
.map(|(url, _)| url)
|
||||
}
|
||||
|
||||
/// 落盘并返回 (引用 url, 本机绝对路径)。文件消息入站用:模型 read_file 只认本机
|
||||
/// 路径,OSS `https://` 引用对本机读取无意义,须另取落盘路径;图片入站只要引用,
|
||||
/// 走 save 薄包装。落盘/双写/降级语义与 save 完全一致
|
||||
pub async fn save_with_path(
|
||||
&self,
|
||||
bytes: &[u8],
|
||||
media_type: &str,
|
||||
original_name: Option<&str>,
|
||||
) -> Result<(String, std::path::PathBuf), String> {
|
||||
let key = content_key(bytes, media_type, original_name);
|
||||
let dir = self.data_dir.join("media");
|
||||
tokio::fs::create_dir_all(&dir)
|
||||
@@ -112,26 +126,33 @@ impl MediaStore {
|
||||
return Err(format!("媒体写入失败: {e}"));
|
||||
}
|
||||
}
|
||||
match &self.oss {
|
||||
let url = match &self.oss {
|
||||
Some(cfg) => match upload_to_oss(cfg, &key, bytes, media_type).await {
|
||||
Ok(()) => Ok(public_url(cfg, &key)),
|
||||
Ok(()) => public_url(cfg, &key),
|
||||
Err(e) => {
|
||||
tracing::warn!(key = %key, err = %e, "OSS 上传失败,引用降级本机 file://");
|
||||
Ok(local_ref(&path))
|
||||
local_ref(&path)
|
||||
}
|
||||
},
|
||||
None => Ok(local_ref(&path)),
|
||||
}
|
||||
None => local_ref(&path),
|
||||
};
|
||||
Ok((url, path))
|
||||
}
|
||||
}
|
||||
|
||||
/// 内容 sha256 全量 hex。落盘键与展示名回退共用同一 hash 口径(飞书文件入站无原始名
|
||||
/// 时展示名取 `file_<hash 前 8>`,与落盘 hash 命名同源可对账)
|
||||
pub fn content_hash(bytes: &[u8]) -> String {
|
||||
use sha2::Digest as _;
|
||||
hex::encode(sha2::Sha256::digest(bytes))
|
||||
}
|
||||
|
||||
/// 内容寻址文件名:`<sha256前16hex>[_<清洗原始名>]<ext>`(对齐 u-claw safeAttachName
|
||||
/// 模式)——hash 前缀保去重(同内容必同文件)且排序聚簇,原始名缀后保目录可读。
|
||||
/// 平铺不分会话目录:会话归属经 DB 消息引用反查,文件系统不编码会话(否则同图跨会话
|
||||
/// 重复存储,去重失效);个人桌面应用媒体量级百~千,hash 前缀平铺可管理,分桶待量级上来再说
|
||||
fn content_key(bytes: &[u8], media_type: &str, original_name: Option<&str>) -> String {
|
||||
use sha2::Digest as _;
|
||||
let digest = hex::encode(&sha2::Sha256::digest(bytes)[..8]);
|
||||
let digest = content_hash(bytes)[..16].to_string();
|
||||
// 扩展名:原始名自带 ext 优先(保真),否则按 media_type 规范化
|
||||
let name = original_name.map(sanitize_name).filter(|s| !s.is_empty());
|
||||
let ext = name
|
||||
@@ -280,6 +301,25 @@ mod tests {
|
||||
tokio::fs::remove_dir_all(&dir).await.ok();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn save_with_path_returns_readable_local_path() {
|
||||
// 文件消息入站契约:引用 url 之外另给本机路径(模型 read_file 只认本机路径),
|
||||
// 通用文件落盘字节无损可读
|
||||
let dir = std::env::temp_dir().join(format!("df-media-test-{}", df_types::types::new_id()));
|
||||
let store = MediaStore::new(dir.clone(), None);
|
||||
let (url, path) = store
|
||||
.save_with_path(b"doc-bytes", "application/octet-stream", Some("合同.pdf"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(url.starts_with("file://"));
|
||||
assert_eq!(
|
||||
path.file_name().unwrap().to_string_lossy(),
|
||||
format!("{}_合同.pdf", &content_hash(b"doc-bytes")[..16])
|
||||
);
|
||||
assert_eq!(tokio::fs::read(&path).await.unwrap(), b"doc-bytes");
|
||||
tokio::fs::remove_dir_all(&dir).await.ok();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_key_stable_and_ext_aware() {
|
||||
let k1 = content_key(b"abc", "image/png", None);
|
||||
|
||||
@@ -362,6 +362,7 @@ impl AppState {
|
||||
session: ai_session.clone(),
|
||||
conv_states: conv_states.clone(),
|
||||
llm_concurrency: llm_concurrency.clone(),
|
||||
allowed_dirs: allowed_dirs.clone(),
|
||||
db: db.clone(),
|
||||
sub_agents: sub_agent_registry.clone(),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"productName": "devflow",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"identifier": "top.1216.devflow",
|
||||
"build": {
|
||||
"beforeDevCommand": "bun dev",
|
||||
|
||||
+12
-11
@@ -31,16 +31,16 @@
|
||||
|
||||
<!-- 走查 P3-16:全局 toast 统一收进同一纵向堆叠容器。原错误 toast 与托盘提示气泡
|
||||
各自 fixed 同位(bottom:24px 居中),两者同现时互相压盖、后弹者盖住先弹者。 -->
|
||||
<div class="df-toast-stack">
|
||||
<div class="app-toast-stack">
|
||||
<!-- 全局错误 toast(根级,主窗口与分离窗口共用)-->
|
||||
<transition name="toast">
|
||||
<div v-if="errorMsg" class="df-toast">⚠ {{ errorMsg }}</div>
|
||||
<div v-if="errorMsg" class="app-toast">⚠ {{ errorMsg }}</div>
|
||||
</transition>
|
||||
|
||||
<!-- 关窗后台运行气泡(主窗关闭被拦截且仍有会话运行时,后端 emit tray-hide-notice):
|
||||
告知会话转入后台继续生成、托盘图标可随时唤起,复用 df-toast 形态 -->
|
||||
告知会话转入后台继续生成、托盘图标可随时唤起,复用 app-toast 形态 -->
|
||||
<transition name="toast">
|
||||
<div v-if="trayNoticeMsg" class="df-toast df-toast--info">{{ trayNoticeMsg }}</div>
|
||||
<div v-if="trayNoticeMsg" class="app-toast app-toast--info">{{ trayNoticeMsg }}</div>
|
||||
</transition>
|
||||
</div>
|
||||
|
||||
@@ -114,7 +114,7 @@ watch(() => projectStore.error, (err) => {
|
||||
})
|
||||
|
||||
// ── 关窗后台运行气泡(主窗关闭被拦截且仍有会话运行时,后端 emit tray-hide-notice)──
|
||||
// 与错误 toast 同款 df-toast 形态,信息语义走 --info 变体底色,不与错误红混用
|
||||
// 与错误 toast 同款 app-toast 形态,信息语义走 --info 变体底色,不与错误红混用
|
||||
const trayNoticeMsg = ref('')
|
||||
let trayNoticeTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let _unlistenTrayHideNotice: (() => void) | null = null
|
||||
@@ -353,20 +353,21 @@ onUnmounted(() => {
|
||||
|
||||
/* ═══ 全局 toast 纵向堆叠容器(走查 P3-16)═══
|
||||
容器独占 fixed 定位,内部 flex 纵排 + 底对齐,多条 toast 依次向上堆叠不再同位互盖。
|
||||
子项保持 .df-toast 原形态(定宽自适应),定位字段从子项上移到容器。 */
|
||||
.df-toast-stack {
|
||||
子项 .app-toast 独立命名(2026-10-18 与 global.css .df-toast 顶部居中族撞名根治,
|
||||
不再依赖定位覆盖对冲),主题保持根级强信号形态(实底白字)。 */
|
||||
.app-toast-stack {
|
||||
position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
|
||||
display: flex; flex-direction: column; align-items: center; gap: 8px;
|
||||
z-index: 9999; max-width: 90vw; pointer-events: none;
|
||||
}
|
||||
.df-toast {
|
||||
.app-toast {
|
||||
background: var(--df-danger); color: #fff;
|
||||
padding: 10px 18px; border-radius: var(--df-radius-sm);
|
||||
font-size: 13px; max-width: 90vw;
|
||||
box-shadow: 0 4px 16px rgba(0,0,0,0.3);
|
||||
box-shadow: var(--df-shadow-md);
|
||||
}
|
||||
.toast-enter-active, .toast-leave-active { transition: opacity 0.25s var(--df-ease), transform 0.25s var(--df-ease); }
|
||||
.toast-enter-from, .toast-leave-to { opacity: 0; transform: translateY(10px); }
|
||||
/* 后台运行提示:同 df-toast 形态,信息语义用 accent 底色与错误红区分 */
|
||||
.df-toast--info { background: var(--df-accent); }
|
||||
/* 后台运行提示:同 app-toast 形态,信息语义用 accent 底色与错误红区分(实底需白字) */
|
||||
.app-toast--info { background: var(--df-accent); color: #fff; }
|
||||
</style>
|
||||
|
||||
+3
-2
@@ -421,9 +421,10 @@ export const aiApi = {
|
||||
|
||||
/**
|
||||
* 脉络卡:published 知识按 source_project 聚合(每项目取复用最高 perProject 条)。
|
||||
* focusConv 标记来源为当前会话的分组(focused=true 供前端高亮);后端未合版本会忽略该参数。
|
||||
* 纯读侧;用户点「带入上下文」才经正常发送路径显式注入,不触碰 L3 工具召回铁律。
|
||||
*/
|
||||
listContextBriefs(perProject?: number): Promise<{ source_project: string; briefs: { title: string; summary: string; source_ref: string | null; source_project: string | null; reuse_count: number }[] }[]> {
|
||||
return invoke('ai_context_briefs', { perProject: perProject ?? null })
|
||||
listContextBriefs(perProject?: number, focusConv?: string): Promise<{ source_project: string; focused?: boolean; briefs: { title: string; summary: string; source_ref: string | null; source_conv: string | null; source_project: string | null; reuse_count: number; updated_at: string }[] }[]> {
|
||||
return invoke('ai_context_briefs', { perProject: perProject ?? null, focusConv: focusConv ?? null })
|
||||
},
|
||||
}
|
||||
|
||||
+6
-1
@@ -104,6 +104,8 @@ export interface ProjectRecord {
|
||||
path: string | null
|
||||
/** 技术栈 JSON 数组字符串(如 ["rust","vue"],null=未探测) */
|
||||
stack: string | null
|
||||
/** 归档标记(归档功能 P2,V48)。true=归档态,退出主列表仅归档箱可见;详情页据此区分「已归档」与「不存在」 */
|
||||
archived?: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
/**
|
||||
@@ -537,6 +539,9 @@ export type AiChatEvent = ({
|
||||
} | {
|
||||
// 上下文已清空:前端刷新消息列表 + toast 提示
|
||||
type: 'AiContextCleared'
|
||||
} | {
|
||||
// E2 压缩失败降级(关键词摘要兜底,loop 仍在跑):前端 toast 提示不中断流
|
||||
type: 'AiContextDegraded'; reason: string
|
||||
}) & {
|
||||
conversation_id?: ConvId
|
||||
}
|
||||
@@ -569,7 +574,7 @@ export interface AiMessage {
|
||||
* 消息来源(958 溯源/961 轮次归属):undefined=null=桌面本端发起;'inject'=运行中
|
||||
* 补充注入(961② 轮次分桶判据,归属当前轮不开新轮);'feishu'=飞书入站发起。
|
||||
*/
|
||||
source?: { channel: string; message_id: string; chat_id?: string; sender?: string } | null
|
||||
source?: { channel: string; message_id?: string; chat_id?: string; sender?: string } | null
|
||||
/**
|
||||
* 推理过程文本(DeepSeek reasoning_content / Anthropic thinking 同通道,后端落库
|
||||
* ai_messages.reasoning_content)。undefined=该轮无思考内容。历史消息 reload 时
|
||||
|
||||
+44
-254
@@ -53,17 +53,9 @@
|
||||
<div v-if="autoCompressedFlash" class="ai-autocompressed-hint">{{ t('aiChat.autoCompressed') }}</div>
|
||||
<!-- 无人值守边界配置卡(默认收起=现状零变化):发起时一次授权,生成中锁编辑 -->
|
||||
<TaskBoundaryCard @toast="(p) => showToast(p.msg, p.type)" />
|
||||
<!-- AE-2025-07: Agentic 循环进度条(C 状态语义化)
|
||||
仅 agentic 多轮(streaming 且收到过 AiAgentRound round>0 事件)显示;
|
||||
单轮问答 agentRound 恒 0,不显示(避免误显)。
|
||||
文案:第 {round} 轮 · 累计 {total} 次调用 · 进行中/待审批;
|
||||
total 由前端聚合当前轮次 toolCalls(useTurnTrace),完成后进度条隐藏,
|
||||
完成聚合语义由 MessageList 的执行轨迹卡承接。
|
||||
降级省略:max(总轮次)后端 AiAgentRound 未透传 max_rounds,不显。 -->
|
||||
<div v-if="showAgenticProgress" class="ai-agentic-progress">
|
||||
<span class="ai-agentic-progress-dot"></span>
|
||||
<span class="ai-agentic-progress-text">{{ agenticProgressText }}</span>
|
||||
</div>
|
||||
<!-- AE-2025-07: Agentic 循环进度条(C 状态语义化)。
|
||||
C4b 拆分至 ai-chat/agentic-progress-bar.vue(纯展示,store 单例直读,零行为变更) -->
|
||||
<AgenticProgressBar />
|
||||
<!-- L1 求助协议(aichat 体验与 agent 能力系统化重构 §2.3,2026-06-21):
|
||||
断路器熔断 emit AiHelpRequired → pendingHelp(模块级 ref)→ 本卡显 reason + options 按钮供用户选。
|
||||
机制优先 prompt 说教:代码强制熔断 + 结构化求助卡(非教 AI 主动问用户)。 -->
|
||||
@@ -75,46 +67,10 @@
|
||||
path 挂起归一进 ToolCard 内联审批(单真相源:状态层合);关(false,兜底回退)时挂载
|
||||
DirAuthDialog 独立弹窗老链路。两路共存,appSettings 随时回退无需改代码。 -->
|
||||
<DirAuthDialog v-if="!unifiedApproval" @toast="(p) => showToast(p.msg, p.type)" />
|
||||
<!-- 待发送队列(生成中排队的消息,完成后自动续发;仅显示当前活跃会话的条目) -->
|
||||
<div v-if="activeQueue.length > 0" class="ai-queue" :class="{ 'ai-queue--timeout': queueTimedOut }">
|
||||
<div class="ai-queue-head">
|
||||
<span class="ai-queue-title">{{ $t('aiChat.queueTitle', { n: activeQueue.length }) }}</span>
|
||||
<div class="ai-queue-actions">
|
||||
<button v-if="queueTimedOut" class="ai-queue-force" @click="handleForceSend">{{ $t('ai.forceSendBtn') }}</button>
|
||||
<button class="ai-queue-clear" @click="handleClearQueue">{{ $t('aiChat.clearQueue') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ai-queue-list">
|
||||
<div v-for="(item, idx) in activeQueue" :key="idx" class="ai-queue-item">
|
||||
<!-- 编辑态只编 text:inline input,回车/失焦写回,ESC 取消 -->
|
||||
<template v-if="editingQueueIdx === idx">
|
||||
<span v-if="item.skill" class="ai-queue-skill">/{{ item.skill }}</span>
|
||||
<input
|
||||
v-model="editingQueueText"
|
||||
class="ai-queue-edit-input"
|
||||
type="text"
|
||||
@keydown="onQueueEditKeydown"
|
||||
@blur="saveEditQueued"
|
||||
/>
|
||||
<button class="ai-queue-btn" @mousedown.prevent="saveEditQueued" :title="$t('aiChat.queueSave')" :aria-label="$t('aiChat.queueSave')">✓</button>
|
||||
<button class="ai-queue-btn" @mousedown.prevent="cancelEditQueued" :title="$t('aiChat.queueCancel')" :aria-label="$t('aiChat.queueCancel')">✕</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span v-if="item.skill" class="ai-queue-skill">/{{ item.skill }}</span>
|
||||
<span class="ai-queue-text" :title="item.text">{{ item.text }}</span>
|
||||
<!-- V7 排队时钟:该项已等待时长 m:ss(nowTick 每秒推进,入发送随队列清空即停) -->
|
||||
<span class="ai-queue-wait">{{ queueItemWait(item) }}</span>
|
||||
<!-- I4 队列回填:取出该项填回输入框重新编辑(从队列移除) -->
|
||||
<button class="ai-queue-btn" @click="backfillQueued(idx)" :title="$t('aiChat.queueBackfill')">{{ $t('aiChat.queueBackfill') }}</button>
|
||||
<!-- 编辑按钮 -->
|
||||
<button class="ai-queue-btn" @click="startEditQueued(idx)" :title="$t('aiChat.queueEdit')">{{ $t('aiChat.queueEdit') }}</button>
|
||||
<!-- 立即发送(打断当前+发本条) -->
|
||||
<button class="ai-queue-btn" @click="handleSendQueuedNow(idx)" :title="$t('aiChat.queueSendNow')">{{ $t('aiChat.queueSendNow') }}</button>
|
||||
<button class="ai-queue-x" @click="store.cancelQueued(idx)" :title="$t('common.cancel')" :aria-label="$t('common.cancel')">×</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 待发送队列(生成中排队的消息,完成后自动续发;仅显示当前活跃会话的条目)。
|
||||
C4b 拆分至 ai-chat/queue-panel.vue(L2 发送韧性 + V7 排队时钟 + 队列编辑/回填随迁,
|
||||
confirm 自持同 ChatInput 模式;hasUnsentInput/fillDraft 经 props/emits 接 ChatInput ref) -->
|
||||
<QueuePanel :has-unsent-input="hasUnsentInput" @fill-draft="onQueueFillDraft" />
|
||||
<!-- 第二批抽离: ChatInput 子组件(输入框+附件+技能/实体联想+发送/停止) -->
|
||||
<ChatInput
|
||||
ref="chatInputRef"
|
||||
@@ -132,28 +88,14 @@
|
||||
:danger-label="confirmState.dangerLabel"
|
||||
@result="answerConfirm"
|
||||
/>
|
||||
<!-- 错误 toast(零依赖,复用 Settings.vue 同款 reactive toast;分离窗口无 App.vue 根 toast,故本组件自管) -->
|
||||
<Transition name="ai-toast">
|
||||
<div v-if="toast.visible" class="ai-toast" :class="'ai-toast-' + toast.type">{{ toast.msg }}</div>
|
||||
<!-- 错误 toast(零依赖 useToast;分离窗口无 App.vue 根 toast,故本组件自管;样式消费全局 .df-toast 族,error 映射 danger) -->
|
||||
<Transition name="df-toast">
|
||||
<div v-if="toast.visible" class="df-toast" :class="toast.type === 'error' ? 'df-toast--danger' : 'df-toast--' + toast.type">{{ toast.msg }}</div>
|
||||
</Transition>
|
||||
<!-- I12(2026-10-05):键盘快捷键速查。Teleport 到 body 防 .ai-panel overflow 裁剪;
|
||||
主窗/分离窗各自实例独立渲染,入口在 TopBar ... 菜单(emit show-shortcuts) -->
|
||||
<Teleport to="body">
|
||||
<div v-if="shortcutsVisible" class="ai-shortcuts-mask" @click.self="shortcutsVisible = false">
|
||||
<div class="ai-shortcuts-panel" role="dialog" :aria-label="t('aiChat.shortcutsTitle')">
|
||||
<div class="ai-shortcuts-head">
|
||||
<span class="ai-shortcuts-title">{{ t('aiChat.shortcutsTitle') }}</span>
|
||||
<button class="ai-shortcuts-close" :aria-label="t('aiChat.scCloseOverlay')" @click="shortcutsVisible = false">✕</button>
|
||||
</div>
|
||||
<ul class="ai-shortcuts-list">
|
||||
<li v-for="s in shortcuts" :key="s.key" class="ai-shortcuts-row">
|
||||
<span class="ai-shortcuts-key">{{ s.key }}</span>
|
||||
<span class="ai-shortcuts-act">{{ s.label }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
<!-- I12(2026-10-05):键盘快捷键速查。C4b 拆分至 ai-chat/shortcuts-overlay.vue
|
||||
(Teleport 到 body 防 .ai-panel overflow 裁剪;主窗/分离窗各自实例独立渲染,
|
||||
入口在 TopBar ... 菜单 emit show-shortcuts;visible 状态留父供 Esc 仲裁) -->
|
||||
<ShortcutsOverlay :visible="shortcutsVisible" @close="shortcutsVisible = false" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -176,10 +118,13 @@ import DirAuthDialog from './ai/DirAuthDialog.vue'
|
||||
import { useConfirm } from '../composables/useConfirm'
|
||||
import { useToast } from '../composables/useToast'
|
||||
import { useProjectStore } from '../stores/project'
|
||||
import { collectTurnStats, turnMessages } from '../composables/ai/useTurnTrace'
|
||||
import { useAiContext } from '../composables/ai/useAiContext'
|
||||
import { emitReattachToMain, registerMainReattachListener, emitOpenSettings, registerMainOpenSettingsListener } from '@/composables/ai/useAiWindow'
|
||||
import type { AiMessage } from '../api/types'
|
||||
import type { AiMessage, SkillInfo } from '../api/types'
|
||||
// C4b 拆分(第五批): Agentic 进度条/待发送队列/快捷键速查 三自有区块抽至 ai-chat/ 子目录
|
||||
import AgenticProgressBar from './ai-chat/agentic-progress-bar.vue'
|
||||
import QueuePanel from './ai-chat/queue-panel.vue'
|
||||
import ShortcutsOverlay from './ai-chat/shortcuts-overlay.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
detached?: boolean
|
||||
@@ -262,22 +207,7 @@ const messageListRef = ref<InstanceType<typeof MessageList> | null>(null)
|
||||
// 头部审批徽标 — 当前对话积压的待审批工具数(>0 时显示)
|
||||
const pendingApprovalCount = computed(() => store.state.pendingApprovals.length)
|
||||
|
||||
// Agentic 循环进度条
|
||||
// 仅 agentic 多轮(streaming 且 agentRound>0)显示;单轮问答不收 AiAgentRound 故恒隐藏。
|
||||
const showAgenticProgress = computed(() =>
|
||||
store.state.streaming && store.state.agentRound > 0,
|
||||
)
|
||||
// 进度文案(C 状态语义化):「第 N 轮 · 累计 M 次调用 · 进行中/待审批」。
|
||||
// 累计调用数由前端聚合当前轮次消息流上的 toolCalls(后端事件无累计字段,不改协议);
|
||||
// 替代旧「循环 N · X个工具完成」——旧 completedTools 每轮清零,轮初叙述期恒显 0 造成歧义。
|
||||
// 「已完成」态不出现在状态栏:完成后进度条隐藏(既有设计),完成聚合由执行轨迹卡承接。
|
||||
const agenticProgressText = computed(() => {
|
||||
const pending = store.state.pendingApprovals.length
|
||||
const total = collectTurnStats(turnMessages(store.state.messages)).total
|
||||
return pending > 0
|
||||
? t('ai.agenticProgress', { round: store.state.agentRound, total, pending })
|
||||
: t('ai.agenticProgressNoPending', { round: store.state.agentRound, total })
|
||||
})
|
||||
// C4b: Agentic 循环进度条(显示条件+文案 computed)已随 ai-chat/agentic-progress-bar.vue 迁出
|
||||
|
||||
/** 点击徽标:滚动到第一个 pending_approval 卡片(委托 MessageList.scrollToFirstPending) */
|
||||
function scrollToFirstPending(): void {
|
||||
@@ -337,10 +267,7 @@ const projectsStore = useProjectStore()
|
||||
// 滚动边沿/跟随意图重置随 MessageList 迁移,由子组件自管。
|
||||
watch(() => store.state.activeConversationId, () => {
|
||||
if (editingMsgId.value) cancelEdit()
|
||||
// UX-P3: 队列编辑态(editingQueueIdx/editingQueueText)绑定旧会话队列在 activeQueue
|
||||
// 视图内的下标,切会话后 activeQueue 已换成新会话的集合,残留 idx/text 会错挂到
|
||||
// 新会话同下标队列项上,随消息编辑态一并重置。
|
||||
if (editingQueueIdx.value !== null) cancelEditQueued()
|
||||
// UX-P3: 队列编辑态重置已随 QueuePanel 迁出(子组件内自 watch activeConversationId)。
|
||||
})
|
||||
|
||||
|
||||
@@ -485,135 +412,23 @@ function onBeforeUnloadGuard(e: BeforeUnloadEvent) {
|
||||
// (ChatInput 经 emit('sent')/emit('cancel-edit')/emit('error') 与父交互)
|
||||
|
||||
// ── L2 发送韧性:排队超时检测 + 强制发送 ──
|
||||
|
||||
/** 当前活跃会话的待发送队列(按 activeConversationId 过滤)。
|
||||
* 队列是全局数组,多会话并发可各自排队;旧实现渲染全部会话的 queue,切/新建后会显示
|
||||
* 旧会话排队消息。此处仅显当前活跃会话条目,相关操作(编辑/删除/立即发送/清空/超时)均按此收敛。 */
|
||||
const activeQueue = computed(() =>
|
||||
store.state.queue.filter(q => q.conversationId === store.state.activeConversationId),
|
||||
)
|
||||
// (activeQueue 过滤视图已随 queue-panel.vue 子组件迁移,父侧死副本删除)
|
||||
|
||||
// ── V7 排队时钟:响应式 tick 驱动排队项已等待时长 ──
|
||||
// 原 queueWaitSeconds 在 computed 内直接取 Date.now(),非响应式依赖:纯等待期(无 store 变更)
|
||||
// 永不重算,秒数冻结;且只覆盖队首。改为有排队时起 1s interval 推进 nowTick,展示函数读
|
||||
// nowTick 建立依赖实现每秒刷新;队列清空(含队首进入发送被移除)即关表,卸载时显式清理防泄漏。
|
||||
const nowTick = ref(Date.now())
|
||||
let queueTickTimer: ReturnType<typeof setInterval> | null = null
|
||||
// 队列超时横幅/强制发送/清空/等待时钟(V7 nowTick)已随 queue-panel.vue 子组件迁移
|
||||
// (2026-10-18 UI 重构批,子组件自带 interval 与清理),父侧死副本删除(vue-tsc TS6133;
|
||||
// 旧父组件时钟在无消费方后仍每秒空转,一并消除)。
|
||||
|
||||
/** 队首排队是否已超 30s(仅看当前活跃会话队列)。
|
||||
* UX-P2-A1:isQueueTimedOut 内取 Date.now() 非响应式,纯等待期(无 store 变更)本 computed
|
||||
* 永不重算,超时横幅/强制发送按钮延迟到下一次无关 store 变更才出现。显式读 nowTick
|
||||
* (V7 排队时钟,有排队时 1s interval 推进)建立每秒依赖,超时判定随 tick 每秒重算。 */
|
||||
const queueTimedOut = computed(() => {
|
||||
void nowTick.value
|
||||
return store.isQueueTimedOut(store.state.activeConversationId)
|
||||
})
|
||||
|
||||
watch(
|
||||
() => activeQueue.value.length > 0,
|
||||
(waiting) => {
|
||||
if (waiting && queueTickTimer === null) {
|
||||
nowTick.value = Date.now()
|
||||
queueTickTimer = setInterval(() => { nowTick.value = Date.now() }, 1000)
|
||||
} else if (!waiting && queueTickTimer !== null) {
|
||||
clearInterval(queueTickTimer)
|
||||
queueTickTimer = null
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/** 秒数转 m:ss(分钟不封顶,长等待继续累计) */
|
||||
function formatWaitTime(totalSeconds: number): string {
|
||||
return `${Math.floor(totalSeconds / 60)}:${String(totalSeconds % 60).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
/** 排队项已等待时长(m:ss);读 nowTick 建立响应式依赖,每秒随 tick 刷新 */
|
||||
function queueItemWait(item: { enqueuedAt: number }): string {
|
||||
return formatWaitTime(Math.max(0, Math.floor((nowTick.value - item.enqueuedAt) / 1000)))
|
||||
}
|
||||
|
||||
/** 强制发送:委托 tryForceSend 唯一负责弹 confirm + 移除队列 + force_send(作用于当前活跃会话) */
|
||||
async function handleForceSend() {
|
||||
await store.tryForceSend(confirmDialog, store.state.activeConversationId)
|
||||
}
|
||||
|
||||
/** UI-4(看板 943)清空队列:二次确认后全清当前活跃会话排队消息。
|
||||
* 一键误触会静默丢掉全部排队消息且不可恢复,复用本组件 ConfirmDialog 先例
|
||||
* (同 tryForceSend 的 confirmFn 注入形态),不引 window.confirm(仓风格)。 */
|
||||
async function handleClearQueue() {
|
||||
const convId = store.state.activeConversationId
|
||||
if (!convId) return
|
||||
const confirmed = await confirmDialog(t('aiChat.clearQueueConfirm'))
|
||||
if (confirmed) store.clearQueue(convId)
|
||||
/** QueuePanel emit fill-draft 的父侧转发:写入 ChatInput 草稿(拆分纪律:ChatInput ref 留父) */
|
||||
function onQueueFillDraft(text: string, skill: SkillInfo | null) {
|
||||
chatInputRef.value?.fillDraft(text, skill)
|
||||
}
|
||||
|
||||
// ── 队列消息编辑(只编 text)+ 立即发送(插队)──
|
||||
|
||||
/** 当前正在编辑的队列项 index;null=非编辑态 */
|
||||
const editingQueueIdx = ref<number | null>(null)
|
||||
/** 编辑态输入框文本(回车写回 / ESC 取消还原) */
|
||||
const editingQueueText = ref('')
|
||||
|
||||
/** 进入编辑态:记录 index + 快照当前 text(activeQueue 视图内下标) */
|
||||
function startEditQueued(idx: number) {
|
||||
const item = activeQueue.value[idx]
|
||||
if (!item) return
|
||||
editingQueueIdx.value = idx
|
||||
editingQueueText.value = item.text
|
||||
}
|
||||
|
||||
/** 取消编辑:还原非编辑态,不写回 */
|
||||
function cancelEditQueued() {
|
||||
editingQueueIdx.value = null
|
||||
editingQueueText.value = ''
|
||||
}
|
||||
|
||||
/** P1-1 队列编辑框键盘处理:输入法组词中(isComposing/229)的 Enter/Esc 属 IME 选词/取消组词,
|
||||
* 不当提交/取消处理,防半截拼音被写回队列项。原 @keydown.enter/.esc 内联修饰符挂不了守卫,
|
||||
* 收敛到本函数统一判。 */
|
||||
function onQueueEditKeydown(e: KeyboardEvent) {
|
||||
if (e.isComposing || e.keyCode === 229) return
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
saveEditQueued()
|
||||
} else if (e.key === 'Escape') {
|
||||
e.preventDefault()
|
||||
cancelEditQueued()
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存编辑:回车/失焦触发,委托 store.editQueued 写回 text */
|
||||
function saveEditQueued() {
|
||||
if (editingQueueIdx.value === null) return
|
||||
store.editQueued(editingQueueIdx.value, editingQueueText.value)
|
||||
editingQueueIdx.value = null
|
||||
editingQueueText.value = ''
|
||||
}
|
||||
|
||||
/** 立即发送:委托 store.sendQueuedNow(移除+stop+sendMessage) */
|
||||
async function handleSendQueuedNow(idx: number) {
|
||||
await store.sendQueuedNow(idx)
|
||||
}
|
||||
|
||||
/** I4 队列回填:取出该条填回输入框重新编辑(从队列移除,可改完再发)。
|
||||
* cancelQueued 内部经 activeQueueRealIndex 做过滤视图下标映射,越界 no-op;
|
||||
* 项携带技能时按名找回 SkillInfo 回挂 chip,找不到(技能已卸载)只回填文本,
|
||||
* 与队列原地编辑只保 text 同一取舍。 */
|
||||
async function backfillQueued(idx: number) {
|
||||
const item = activeQueue.value[idx]
|
||||
if (!item) return
|
||||
// UX-P3: 输入框已有未发送草稿(文本/图片/技能 chip 任一非空)时回填会静默覆盖,
|
||||
// 先 confirm 确认;取消则直接返回,队列项原样保留(尚未 cancelQueued)。
|
||||
if (chatInputRef.value?.hasUnsentInput()) {
|
||||
if (!await confirmDialog(t('aiChat.backfillOverwriteConfirm'))) return
|
||||
}
|
||||
const skill = item.skill
|
||||
? store.state.skills.find(s => s.name === item.skill) ?? null
|
||||
: null
|
||||
store.cancelQueued(idx)
|
||||
chatInputRef.value?.fillDraft(item.text, skill)
|
||||
}
|
||||
// 队列编辑态(编辑中 index/文本/进取消存取)已随 queue-panel.vue 子组件迁移(2026-10-18
|
||||
// UI 重构批),父组件死副本删除(vue-tsc TS6133);IME 守卫等行为在子组件内同名实现。
|
||||
|
||||
// 第四批抽离: 滚动跟随/回底部/流式 Markdown 分块渲染/工具卡自动收起/选区保持 全部随
|
||||
// MessageList 子组件迁移(零行为变更,store/useMarkdown 单例共享)。
|
||||
@@ -627,8 +442,7 @@ onBeforeUnmount(() => {
|
||||
// 归还 listener 租约(最后一份归还才真拆单例 listener;双重归还/下溢由 useAiEvents dev 断言暴露)
|
||||
_listenerRelease?.()
|
||||
_listenerRelease = null
|
||||
// V7 排队时钟 interval 随组件卸载清理(watch 随卸载停但 interval 本体不自停,须显式清)
|
||||
if (queueTickTimer !== null) { clearInterval(queueTickTimer); queueTickTimer = null }
|
||||
// V7 排队时钟已随 queue-panel.vue 迁移,其 interval 由子组件 onBeforeUnmount 自清。
|
||||
// 全局快捷键卸载时移除 window listener,防分离窗口/切组件后泄漏
|
||||
window.removeEventListener('keydown', onGlobalKeydown)
|
||||
// 摘除未发送输入保护(分离窗口关闭/页面刷新触发 beforeunload)
|
||||
@@ -786,16 +600,7 @@ async function toggleAlwaysOnTop() {
|
||||
// I12(2026-10-05):顶部 ... 菜单入口(TopBar emit show-shortcuts)→ 此处 Teleport 展示速查浮层。
|
||||
// 键位表 shortcuts 与 onGlobalKeydown 同文件同居——键区调整时表随手同步,防速查与真实键位漂移。
|
||||
const shortcutsVisible = ref(false)
|
||||
// computed:随 locale 即时翻译(仅面板打开时消费,开销可忽略);t 已在本组件上方 useI18n 解构
|
||||
const shortcuts = computed(() => [
|
||||
{ key: 'Ctrl+N', label: t('aiChat.scNewConv') },
|
||||
{ key: 'Ctrl+I', label: t('aiChat.scFocusInput') },
|
||||
{ key: 'Ctrl+R', label: t('aiChat.scRegenerate') },
|
||||
{ key: 'Ctrl+L', label: t('aiChat.scClearChat') },
|
||||
{ key: 'Ctrl+K', label: t('aiChat.scSearch') },
|
||||
{ key: 'Ctrl+B', label: t('aiChat.scToggleSidebar') },
|
||||
{ key: 'Esc', label: t('aiChat.scCloseOverlay') },
|
||||
])
|
||||
// 键位表已随 shortcuts-overlay.vue 子组件迁移(C4b),父侧死副本删除(vue-tsc TS6133)。
|
||||
function showShortcuts() {
|
||||
shortcutsVisible.value = true
|
||||
}
|
||||
@@ -893,6 +698,10 @@ async function initContextEventListeners(): Promise<void> {
|
||||
onError: (_convId, message) => {
|
||||
showToast(t('aiChat.compressError', { msg: message }), 'error')
|
||||
},
|
||||
// E2 压缩失败降级:仅提示不刷新不打断流(loop 仍在跑,实证静默降级致用户原句重发)
|
||||
onContextDegraded: (_convId, reason) => {
|
||||
showToast(t('aiChat.contextDegraded', { reason }), 'warning')
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -902,7 +711,7 @@ async function initContextEventListeners(): Promise<void> {
|
||||
复用按钮抽 components.css 全局。本块仅保留 AiChat 自身元素:面板布局/聊天区/input-area
|
||||
容器/agentic 进度/待发队列/toast。子组件元素由各子组件 scoped 负责,父级 scoped 不渗透。) ═══ */
|
||||
.ai-panel {
|
||||
position: relative; /* 容纳 .ai-toast(absolute,相对面板定位,嵌入/分离模式均生效) */
|
||||
position: relative; /* toast 已改全局 .df-toast(fixed 定位);relative 保留兜底其他绝对定位子元素 */
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 100%;
|
||||
@@ -924,7 +733,7 @@ async function initContextEventListeners(): Promise<void> {
|
||||
TopBar.vue scoped 自持 + .ai-btn-icon* 抽 components.css 全局共享,
|
||||
原 AiChat scoped 不渗透子组件根,删此重复块零视觉变更) */
|
||||
|
||||
/* ── 「信任所有目录」放行横幅(开关开启期间常驻,warning 色系对齐 .ai-toast-warning) ── */
|
||||
/* ── 「信任所有目录」放行横幅(开关开启期间常驻,warning 色系对齐 .df-toast--warning) ── */
|
||||
.ai-auth-bypass-banner {
|
||||
padding: 5px 14px;
|
||||
background: var(--df-warning-bg);
|
||||
@@ -1054,27 +863,8 @@ async function initContextEventListeners(): Promise<void> {
|
||||
|
||||
/* (.ai-btn-icon:disabled / .ai-btn-spinner / @keyframes ai-btn-spin 已抽 components.css 全局共享) */
|
||||
|
||||
/* ═══ 错误 toast(复用 Settings.vue .toast 样式,前缀 ai- 防 scoped 冲突) ═══ */
|
||||
.ai-toast {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
padding: 8px 14px;
|
||||
border-radius: var(--df-radius);
|
||||
font-size: 12px;
|
||||
z-index: 100;
|
||||
box-shadow: 0 4px 16px rgba(0,0,0,0.3);
|
||||
max-width: 80%;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.ai-toast-error { background: var(--df-danger-bg); color: var(--df-danger); border: 0.5px solid var(--df-danger); }
|
||||
.ai-toast-warning { background: var(--df-warning-bg); color: var(--df-warning); border: 0.5px solid var(--df-warning); }
|
||||
.ai-toast-info { background: var(--df-accent-bg); color: var(--df-accent); border: 0.5px solid var(--df-accent); }
|
||||
/* ToastType 新增 'success' 兜底样式 */
|
||||
.ai-toast-success { background: var(--df-success-bg); color: var(--df-success); border: 0.5px solid var(--df-success); }
|
||||
.ai-toast-enter-active, .ai-toast-leave-active { transition: opacity 0.2s, transform 0.2s; }
|
||||
.ai-toast-enter-from, .ai-toast-leave-to { opacity: 0; transform: translate(-50%, -8px); }
|
||||
/* ═══ 错误 toast:消费 global.css .df-toast 四色族 + .df-toast-enter/leave 过渡
|
||||
(2026-10-18 整洁波双轨合一,原 .ai-toast-* 本地族删除;error 态映射 --danger) ═══ */
|
||||
|
||||
/* ═══ I12 快捷键速查面板(Teleport 到 body,scoped 对 Teleport 内容仍生效——
|
||||
Vue scoped 把 data 属性打在编译期节点上,与挂载位置无关) ═══ */
|
||||
@@ -1091,7 +881,7 @@ async function initContextEventListeners(): Promise<void> {
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-lg, 8px);
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
width: 320px;
|
||||
max-width: calc(100vw - 48px);
|
||||
padding: 14px 16px;
|
||||
@@ -1116,7 +906,7 @@ async function initContextEventListeners(): Promise<void> {
|
||||
padding: 2px 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.ai-shortcuts-close:hover { color: var(--df-text); background: var(--df-bg-secondary); }
|
||||
.ai-shortcuts-close:hover { color: var(--df-text); background: var(--df-bg-card); }
|
||||
.ai-shortcuts-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
@@ -1132,9 +922,9 @@ async function initContextEventListeners(): Promise<void> {
|
||||
font-size: 12px;
|
||||
}
|
||||
.ai-shortcuts-key {
|
||||
font-family: var(--df-mono, monospace);
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 11px;
|
||||
background: var(--df-bg-secondary);
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: 4px;
|
||||
padding: 2px 8px;
|
||||
|
||||
+72
-50
@@ -21,9 +21,9 @@
|
||||
<span v-html="toolIcon(tc.name)"></span>
|
||||
</span>
|
||||
<div class="ai-tool-header-text">
|
||||
<span class="ai-tool-name">{{ toolDisplayName(tc) }}</span>
|
||||
<span v-if="tc.status === 'running'" class="ai-tool-sub">{{ $t('aiTool.running') }}</span>
|
||||
<span v-else-if="isFailed" class="ai-tool-sub ai-tool-sub--failed" :title="summaryTitle">{{ $t('aiTool.executionFailed') }}</span>
|
||||
<span class="ai-tool-name df-mono">{{ toolDisplayName(tc) }}</span>
|
||||
<span v-if="tc.status === 'running'" class="ai-tool-sub df-badge df-badge--info ai-tool-chip-run">{{ $t('aiTool.running') }}</span>
|
||||
<span v-else-if="isFailed" class="ai-tool-sub ai-tool-sub--failed df-badge df-badge--danger" :title="summaryTitle">{{ $t('aiTool.executionFailed') }}</span>
|
||||
<span v-else-if="resultSummary" class="ai-tool-sub" :title="summaryTitle">{{ resultSummary }}</span>
|
||||
</div>
|
||||
<span class="ai-tool-status-dot" :class="'ai-tool-status-dot--' + (isFailed ? 'failed' : tc.status)" :title="statusTitle"></span>
|
||||
@@ -31,7 +31,7 @@
|
||||
hover 显绝对起止时刻,相对时间不再占卡片行(B 聚合卡统一)。 -->
|
||||
<span
|
||||
v-if="durationText"
|
||||
class="ai-tool-duration"
|
||||
class="ai-tool-duration df-mono"
|
||||
:title="durationTitle"
|
||||
>{{ durationText }}</span>
|
||||
<span v-if="!shouldKeepOpen(tc)" class="ai-tool-collapse-hint" :class="{ 'is-open': isExpanded }">▸</span>
|
||||
@@ -56,8 +56,9 @@
|
||||
|
||||
<!-- 审批:参数内容 + 风险提示 + 按钮 -->
|
||||
<div v-if="tc.status === 'pending_approval'" class="ai-tool-approval">
|
||||
<!-- 风险徽章:High 橙红/Medium 黄,一眼识别操作等级(与左侧着色条同色系) -->
|
||||
<div v-if="riskLevel !== 'low'" class="ai-tool-risk-badge" :class="'is-' + riskLevel">
|
||||
<!-- 风险徽章:High 橙红/Medium 黄,一眼识别操作等级(与左侧着色条同色系)
|
||||
wave2:迁 .df-badge 透明彩底三件套(danger/warning 变体) -->
|
||||
<div v-if="riskLevel !== 'low'" class="ai-tool-risk-badge df-badge" :class="riskLevel === 'high' ? 'df-badge--danger' : 'df-badge--warning'">
|
||||
{{ riskLevel === 'high' ? $t('aiTool.riskHigh') : $t('aiTool.riskMedium') }}
|
||||
</div>
|
||||
<div v-if="visibleArgs.length" class="ai-tool-approval-args">
|
||||
@@ -81,7 +82,7 @@
|
||||
</div>
|
||||
<!-- AE-2025-03: write_file 审批 diff 预览(红删绿增,行级)。旧文件不存在→tc.diff 为空,回退显上方 args content -->
|
||||
<div v-if="tc.diff" class="ai-tool-approval-diff">
|
||||
<pre class="ai-tool-diff-pre"><code><span v-for="(ln, idx) in diffLines" :key="idx" class="ai-tool-diff-line" :class="'ai-tool-diff-line--' + ln.kind">{{ ln.text }}{{ '\n' }}</span></code></pre>
|
||||
<pre class="df-diff-pre"><code><span v-for="(ln, idx) in diffLines" :key="idx" class="df-diff-line" :class="'df-diff-line--' + ln.kind">{{ ln.text }}{{ '\n' }}</span></code></pre>
|
||||
</div>
|
||||
<!-- path_auth 审批链阶段3b:按 tc.kind 分两组按钮。
|
||||
- kind='path'(路径授权挂起):once/session/always/deny 四选项,调 authorizeDir
|
||||
@@ -415,7 +416,7 @@ const visibleArgs = computed(() => {
|
||||
不做 body 高度动画(v-show display 切换 + flex gap 会留双倍间距致布局跳变,见 ToolCardList 注释)。 */
|
||||
transition: border-color 0.2s var(--df-ease), box-shadow 0.2s var(--df-ease), opacity 0.2s var(--df-ease);
|
||||
}
|
||||
.ai-tool-card--pending_approval { border-color: rgba(240,199,94,0.3); box-shadow: 0 0 0 1px rgba(240,199,94,0.06); }
|
||||
.ai-tool-card--pending_approval { border-color: var(--df-warning-bd); box-shadow: 0 0 0 1px rgba(240,199,94,0.06); }
|
||||
.ai-tool-card--completed { border-color: rgba(61,219,160,0.2); }
|
||||
.ai-tool-card--rejected { border-color: rgba(240,101,101,0.2); opacity: 0.55; }
|
||||
/* 工具失败态——AR-6 下 status 仍为 completed,故单独覆盖边框与 completed 区分 */
|
||||
@@ -424,13 +425,17 @@ const visibleArgs = computed(() => {
|
||||
.ai-tool-sub--failed { color: var(--df-danger); }
|
||||
.ai-tool-rejected {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
padding: 4px 10px 8px 42px; font-size: 11px; color: var(--df-danger);
|
||||
padding: 4px 10px 8px var(--df-icon-gutter); font-size: 11px; color: var(--df-danger);
|
||||
}
|
||||
.ai-tool-rejected-icon { font-weight: 500; }
|
||||
|
||||
/* wave2:折叠轨迹卡的展开态左边 2px 强调边(对齐 workbench cv.on 范式);
|
||||
只作用于可折叠卡(completed),pending 的 data-risk 左缘与 running 强制展开态不参与 */
|
||||
.ai-tool-card--completed:not(.ai-tool-card--collapsed) { border-left: 2px solid var(--df-info); }
|
||||
|
||||
/* -- 卡片折叠态(running/pending 始终展开,completed/rejected 默认折叠为单行 header) -- */
|
||||
.ai-tool-card--collapsed .ai-tool-header { cursor: pointer; }
|
||||
.ai-tool-card--collapsed .ai-tool-header:hover { background: rgba(255,255,255,0.03); }
|
||||
.ai-tool-card--collapsed .ai-tool-header:hover { background: var(--df-bg-card-hover); }
|
||||
.ai-tool-body { overflow: hidden; }
|
||||
.ai-tool-collapse-hint {
|
||||
font-size: 10px; color: var(--df-text-dim); margin-left: auto; flex-shrink: 0;
|
||||
@@ -444,9 +449,9 @@ const visibleArgs = computed(() => {
|
||||
width: 24px; height: 24px; border-radius: var(--df-radius-sm);
|
||||
display: flex; align-items: center; justify-content: center; flex-shrink: 0;
|
||||
}
|
||||
.ai-tool-icon-wrap--file-read { background: rgba(94,175,240,0.12); color: var(--df-info); }
|
||||
.ai-tool-icon-wrap--file-read { background: var(--df-info-bg); color: var(--df-info); }
|
||||
.ai-tool-icon-wrap--file-write { background: var(--df-warning-bg); color: var(--df-warning); }
|
||||
.ai-tool-icon-wrap--dir { background: rgba(240,199,94,0.12); color: var(--df-warning); }
|
||||
.ai-tool-icon-wrap--dir { background: var(--df-warning-bg); color: var(--df-warning); }
|
||||
.ai-tool-icon-wrap--create { background: var(--df-success-bg); color: var(--df-success); }
|
||||
.ai-tool-icon-wrap--delete { background: var(--df-danger-bg); color: var(--df-danger); }
|
||||
.ai-tool-icon-wrap--list { background: var(--df-accent-bg); color: var(--df-accent); }
|
||||
@@ -455,14 +460,40 @@ const visibleArgs = computed(() => {
|
||||
display: flex; flex-direction: row; flex-wrap: wrap; align-items: baseline;
|
||||
column-gap: 8px; row-gap: 1px; flex: 1; min-width: 0;
|
||||
}
|
||||
/* wave2:工具名迁 mono 元数据(df-mono 接管字体,此处 10px dim 收敛视觉) */
|
||||
.ai-tool-name {
|
||||
font-size: 12px; font-weight: 500; color: var(--df-text);
|
||||
font-size: 10px; font-weight: 500; color: var(--df-text-dim);
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0;
|
||||
}
|
||||
.ai-tool-sub {
|
||||
font-size: 10px; color: var(--df-text-dim);
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
/* wave2:状态 chip 迁 .df-badge(running=info+脉冲点 / failed=danger);
|
||||
scoped 双类压过 .ai-tool-sub 灰字,色板与 df-badge 变体对齐(token 化) */
|
||||
.ai-tool-sub.df-badge {
|
||||
font-size: 10px;
|
||||
padding: 1px 6px;
|
||||
line-height: 16px;
|
||||
}
|
||||
.ai-tool-sub.df-badge--info {
|
||||
background: var(--df-info-bg);
|
||||
color: var(--df-info);
|
||||
border-color: color-mix(in srgb, var(--df-info) 30%, transparent);
|
||||
}
|
||||
.ai-tool-sub.df-badge--danger {
|
||||
background: var(--df-danger-bg);
|
||||
color: var(--df-danger);
|
||||
border-color: color-mix(in srgb, var(--df-danger) 30%, transparent);
|
||||
}
|
||||
/* running chip 内嵌脉冲点(全局 df-pulse 节奏,对齐 df-dot--run 活性语义) */
|
||||
.ai-tool-chip-run::before {
|
||||
content: '';
|
||||
width: 5px; height: 5px; border-radius: 50%;
|
||||
background: var(--df-info);
|
||||
flex-shrink: 0;
|
||||
animation: df-pulse 1.5s infinite;
|
||||
}
|
||||
|
||||
/* -- Status dot (脉冲动画) -- */
|
||||
.ai-tool-status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
|
||||
@@ -487,16 +518,16 @@ const visibleArgs = computed(() => {
|
||||
.ai-tool-status-dot--rejected { background: var(--df-danger); }
|
||||
|
||||
/* -- Skeleton (running 状态) -- */
|
||||
.ai-tool-skeleton { padding: 4px 10px 10px 42px; display: flex; flex-direction: column; gap: 5px; }
|
||||
.ai-tool-skeleton { padding: 4px 10px 10px var(--df-icon-gutter); display: flex; flex-direction: column; gap: 5px; }
|
||||
.ai-tool-skeleton-line {
|
||||
height: 8px; border-radius: var(--df-radius-xs);
|
||||
background: linear-gradient(90deg, var(--df-bg) 25%, var(--df-bg-card-hover) 50%, var(--df-bg) 75%);
|
||||
background-size: 200% 100%; animation: shimmer 1.5s infinite;
|
||||
background-size: 200% 100%; animation: df-shimmer 1.5s infinite;
|
||||
}
|
||||
|
||||
/* -- 实时流式输出(running 态:run_command 行 / ask_uclaw 进度块) -- */
|
||||
.ai-tool-stream {
|
||||
padding: 4px 10px 10px 42px;
|
||||
padding: 4px 10px 10px var(--df-icon-gutter);
|
||||
display: flex; flex-direction: column; gap: 2px;
|
||||
max-height: 160px; overflow-y: auto;
|
||||
}
|
||||
@@ -507,53 +538,47 @@ const visibleArgs = computed(() => {
|
||||
white-space: pre-wrap; word-break: break-all;
|
||||
}
|
||||
.ai-tool-stream-more {
|
||||
font-size: 10px; color: var(--df-text-tertiary);
|
||||
font-size: 10px; color: var(--df-text-dim);
|
||||
padding-top: 2px; font-style: italic;
|
||||
}
|
||||
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
|
||||
|
||||
/* -- 审批参数展示 -- */
|
||||
.ai-tool-approval-args {
|
||||
padding: 4px 10px 6px; margin-bottom: 6px;
|
||||
border-top: 0.5px solid var(--df-border); border-bottom: 0.5px solid var(--df-border);
|
||||
background: var(--df-bg-elevated, rgba(0, 0, 0, 0.03));
|
||||
background: var(--df-bg);
|
||||
}
|
||||
.ai-tool-arg { display: flex; gap: 8px; padding: 2px 0; font-size: 11px; line-height: 1.5; }
|
||||
.ai-tool-arg-key { flex-shrink: 0; min-width: 64px; color: var(--df-text-secondary); font-family: var(--df-font-mono); }
|
||||
.ai-tool-arg-val { flex: 1; word-break: break-all; white-space: pre-wrap; font-family: var(--df-font-mono); color: var(--df-text-primary); }
|
||||
.ai-tool-arg-val { flex: 1; word-break: break-all; white-space: pre-wrap; font-family: var(--df-font-mono); color: var(--df-text); }
|
||||
.ai-tool-approval-reason {
|
||||
padding: 4px 10px 6px; margin-bottom: 6px; font-size: 11px;
|
||||
color: var(--df-warning, #d97706); background: var(--df-warning-bg, rgba(217, 119, 6, 0.08));
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
color: var(--df-warning); background: var(--df-warning-bg);
|
||||
border-radius: var(--df-radius-sm);
|
||||
}
|
||||
|
||||
/* 审批挂起时长提示(>2分钟橙色,>5分钟红色) */
|
||||
.ai-tool-wait-time {
|
||||
padding: 3px 10px; margin-bottom: 6px; font-size: 11px;
|
||||
font-family: var(--df-font-mono);
|
||||
color: var(--df-text-dim, #888);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
color: var(--df-text-dim);
|
||||
border-radius: var(--df-radius-sm);
|
||||
}
|
||||
.ai-tool-wait-time.is-long {
|
||||
color: var(--df-warning, #d97706);
|
||||
color: var(--df-warning);
|
||||
animation: pulseGlow 1.5s ease-in-out infinite;
|
||||
}
|
||||
.ai-tool-wait-time.is-urgent {
|
||||
color: var(--df-danger, #e5484d);
|
||||
color: var(--df-danger);
|
||||
animation: pulseGlow 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
/* write_file 审批 diff 预览区(红删绿增行级) */
|
||||
/* write_file 审批 diff 预览区(红删绿增行级);
|
||||
基类 .df-diff-pre(+code)/.df-diff-line 消费 global.css 共享定义,此处仅留行配色变体 */
|
||||
.ai-tool-approval-diff { margin: 0 10px 8px; border: 0.5px solid var(--df-border); border-radius: var(--df-radius-sm, 4px); overflow: hidden; }
|
||||
.ai-tool-diff-pre {
|
||||
margin: 0; padding: 6px 0; max-height: 240px; overflow: auto;
|
||||
font-family: var(--df-font-mono); font-size: 11px; line-height: 1.5; background: var(--df-bg-card);
|
||||
}
|
||||
.ai-tool-diff-pre code { display: block; white-space: pre; }
|
||||
.ai-tool-diff-line { display: block; padding: 0 10px; white-space: pre-wrap; word-break: break-all; }
|
||||
.ai-tool-diff-line--add { color: var(--df-success, #3ddb9c); background: var(--df-success-bg, rgba(61, 219, 160, 0.08)); }
|
||||
.ai-tool-diff-line--del { color: var(--df-danger, #f06565); background: var(--df-danger-bg, rgba(240, 101, 101, 0.08)); }
|
||||
.ai-tool-diff-line--ctx { color: var(--df-text-dim, #888); }
|
||||
.df-diff-line--add { color: var(--df-success); background: var(--df-success-bg); }
|
||||
.df-diff-line--del { color: var(--df-danger); background: var(--df-danger-bg); }
|
||||
.df-diff-line--ctx { color: var(--df-text-dim); }
|
||||
|
||||
/* -- 审批按钮 -- */
|
||||
.ai-tool-actions { display: flex; gap: 6px; padding: 0 10px 8px; }
|
||||
@@ -566,11 +591,11 @@ const visibleArgs = computed(() => {
|
||||
.ai-tool-btn--approve:hover { background: var(--df-success); color: #fff; border-color: var(--df-success); }
|
||||
/* M4:session 按钮(accent 描边态,介于 approve 弱背景与 always 强 warning 之间;对齐 DirAuthDialog session 语义) */
|
||||
.ai-tool-btn--session {
|
||||
background: var(--df-accent-bg, rgba(123, 111, 240, 0.12));
|
||||
color: var(--df-accent, #7b6ff0);
|
||||
border-color: color-mix(in srgb, var(--df-accent, #7b6ff0) 40%, transparent);
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
border-color: color-mix(in srgb, var(--df-accent) 40%, transparent);
|
||||
}
|
||||
.ai-tool-btn--session:hover { background: var(--df-accent, #7b6ff0); color: #fff; border-color: var(--df-accent, #7b6ff0); }
|
||||
.ai-tool-btn--session:hover { background: var(--df-accent); color: #fff; border-color: var(--df-accent); }
|
||||
/* path_auth 审批链阶段3b:always 按钮(warning 色调,与 DirAuthDialog.vue 同款语义) */
|
||||
.ai-tool-btn--always { background: var(--df-warning-bg); color: var(--df-warning); }
|
||||
.ai-tool-btn--always:hover { background: var(--df-warning); color: #000; border-color: var(--df-warning); }
|
||||
@@ -587,15 +612,14 @@ const visibleArgs = computed(() => {
|
||||
.ai-tool-btn-icon :deep(svg) { display: block; }
|
||||
.ai-tool-btn-spinner {
|
||||
width: 12px; height: 12px; border: 1.5px solid currentColor; border-top-color: transparent;
|
||||
border-radius: 50%; display: inline-block; flex-shrink: 0; animation: aiToolBtnSpin 0.7s linear infinite;
|
||||
border-radius: 50%; display: inline-block; flex-shrink: 0; animation: df-spin 0.7s linear infinite;
|
||||
}
|
||||
@keyframes aiToolBtnSpin { to { transform: rotate(360deg); } }
|
||||
|
||||
/* -- 审批 loading 超时兜底 toast(复用 AiChat 同款视觉 token) -- */
|
||||
.ai-tool-toast {
|
||||
position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
|
||||
padding: 6px 12px; border-radius: var(--df-radius-sm); font-size: 11px; z-index: 100;
|
||||
box-shadow: 0 4px 16px rgba(0,0,0,0.3); max-width: 90%; overflow-wrap: anywhere; pointer-events: none;
|
||||
box-shadow: var(--df-shadow-sm); max-width: 90%; overflow-wrap: anywhere; pointer-events: none;
|
||||
}
|
||||
.ai-tool-toast--warning { background: var(--df-warning-bg); color: var(--df-warning); border: 0.5px solid var(--df-warning); }
|
||||
.ai-tool-toast-enter-active, .ai-tool-toast-leave-active { transition: opacity 0.2s, transform 0.2s; }
|
||||
@@ -605,15 +629,13 @@ const visibleArgs = computed(() => {
|
||||
.ai-tool-card[data-risk='high'] { border-left: 2px solid var(--df-danger); }
|
||||
.ai-tool-card[data-risk='medium'] { border-left: 2px solid var(--df-warning); }
|
||||
|
||||
/* -- 风险徽章(审批区首行,High 橙红底/Medium 黄底,10px 大写字距) -- */
|
||||
/* -- 风险徽章(审批区首行):wave2 迁 .df-badge 透明彩底(danger/warning 变体接管配色),
|
||||
此处只留布局(独立成行+外边距) -- */
|
||||
.ai-tool-risk-badge {
|
||||
display: inline-flex; align-items: center; align-self: flex-start;
|
||||
padding: 2px 8px; margin: 6px 10px 0;
|
||||
font-size: 10px; font-weight: 600; letter-spacing: 0.5px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
align-self: flex-start;
|
||||
margin: 6px 10px 0;
|
||||
font-weight: 600; letter-spacing: 0.5px;
|
||||
}
|
||||
.ai-tool-risk-badge.is-high { background: var(--df-danger-bg); color: var(--df-danger); border: 0.5px solid color-mix(in srgb, var(--df-danger) 40%, transparent); }
|
||||
.ai-tool-risk-badge.is-medium { background: var(--df-warning-bg); color: var(--df-warning); border: 0.5px solid color-mix(in srgb, var(--df-warning) 40%, transparent); }
|
||||
|
||||
/* 审批区改纵向 flex(徽章需独立成行,原块级布局不变) */
|
||||
.ai-tool-approval { display: flex; flex-direction: column; }
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
<button class="ai-btn ai-btn--sm ai-btn--danger" :disabled="batchProcessing" @click="$emit('batch-approve', 'reject')">
|
||||
{{ $t('aiTool.rejectAll') }}
|
||||
</button>
|
||||
<!-- High 风险计数徽标:批量批准将二次确认的项数,提示操作后果 -->
|
||||
<span v-if="highRiskPendingCount > 0" class="ai-batch-high-risk-hint">
|
||||
<!-- High 风险计数徽标:批量批准将二次确认的项数,提示操作后果(wave2 迁 .df-badge danger) -->
|
||||
<span v-if="highRiskPendingCount > 0" class="ai-batch-high-risk-hint df-badge df-badge--danger">
|
||||
{{ $t('aiTool.batchHighRiskHint', { n: highRiskPendingCount }) }}
|
||||
</span>
|
||||
</div>
|
||||
@@ -26,8 +26,8 @@
|
||||
<div v-if="group.calls.length >= 2" class="ai-tool-group-header" @click="toggleGroupCollapse(gi)">
|
||||
<span class="ai-tool-group-icon" v-html="groupIcon(group.name)"></span>
|
||||
<span class="ai-tool-group-name">{{ groupDisplayName(group) }}</span>
|
||||
<!-- R7 组头失败徽标:折叠组内失败卡不展开也能从组头发现(红字计数) -->
|
||||
<span v-if="groupFailCounts[gi] > 0" class="ai-tool-group-fail">{{ $t('aiTool.groupFailCount', { n: groupFailCounts[gi] }) }}</span>
|
||||
<!-- R7 组头失败徽标:折叠组内失败卡不展开也能从组头发现(wave2 迁 .df-badge danger) -->
|
||||
<span v-if="groupFailCounts[gi] > 0" class="ai-tool-group-fail df-badge df-badge--danger">{{ $t('aiTool.groupFailCount', { n: groupFailCounts[gi] }) }}</span>
|
||||
<span class="ai-tool-group-chevron" :class="{ 'is-open': !isGroupCollapsed(gi) }">▸</span>
|
||||
</div>
|
||||
<ToolCard
|
||||
@@ -451,23 +451,17 @@ function groupIcon(name: string): string {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* -- 批量操作栏 -- */
|
||||
/* -- 批量操作栏(wave2:白透明底残留改 token,浅色主题成立) -- */
|
||||
.ai-batch-approve {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 10px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: rgba(255,255,255,0.02);
|
||||
background: var(--df-bg-card);
|
||||
}
|
||||
/* 批量批准将二次确认的 High 风险项数徽标(橙红警示,不抢按钮焦点) */
|
||||
/* 批量批准将二次确认的 High 风险项数徽标:配色由 df-badge--danger 接管,此处只留布局 */
|
||||
.ai-batch-high-risk-hint {
|
||||
font-size: 10px;
|
||||
color: var(--df-danger);
|
||||
background: var(--df-danger-bg);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-danger) 40%, transparent);
|
||||
border-radius: var(--df-radius-sm);
|
||||
padding: 2px 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* .ai-btn 基类:批量审批按钮(历史重构遗漏定义,补全治本) */
|
||||
@@ -512,16 +506,13 @@ function groupIcon(name: string): string {
|
||||
color: var(--df-text-secondary);
|
||||
}
|
||||
.ai-tool-group-header:hover {
|
||||
background: rgba(255,255,255,0.03);
|
||||
background: var(--df-bg-card-hover);
|
||||
}
|
||||
/* R7 组头失败徽标:失败计数红字,margin-left auto 推到 chevron 之前右对齐 */
|
||||
/* R7 组头失败徽标:配色由 df-badge--danger 接管,此处只留布局(右对齐推到 chevron 前) */
|
||||
.ai-tool-group-fail {
|
||||
margin-left: auto;
|
||||
margin-right: 2px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
color: var(--df-danger);
|
||||
opacity: 0.9;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ai-tool-group-icon {
|
||||
|
||||
@@ -120,12 +120,12 @@
|
||||
<span v-if="typeof parsed?.encoding === 'string' && parsed.encoding !== 'utf-8'" class="ai-tool-write-meta">{{ $t('aiTool.encodingLabel', { enc: parsed.encoding }) }}</span>
|
||||
<!-- R12(2026-10-05):覆盖写入的行级 diff 回看(后端 diff 字段,新建/base64 为 null 不渲染) -->
|
||||
<div v-if="resultDiffLines.length" class="ai-tool-write-diff">
|
||||
<pre class="ai-tool-diff-pre"><code><span v-for="(ln, idx) in resultDiffLines" :key="idx" class="ai-tool-diff-line" :class="'ai-tool-diff-line--' + ln.kind">{{ ln.text }}{{ '\n' }}</span></code></pre>
|
||||
<pre class="df-diff-pre"><code><span v-for="(ln, idx) in resultDiffLines" :key="idx" class="df-diff-line" :class="'df-diff-line--' + ln.kind">{{ ln.text }}{{ '\n' }}</span></code></pre>
|
||||
<button v-if="diffTotal > DIFF_PREVIEW_LINES" type="button" class="ai-tool-diff-toggle" @click="diffExpanded = !diffExpanded">{{ diffExpanded ? $t('aiTool.diffCollapse') : $t('aiTool.diffExpand', { n: diffTotal }) }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- patch_file 结果:文件路径/字节增减 + unified diff 红删绿增行级预览(复用 ai-tool-diff-pre/--add/--del/--ctx 既有样式)
|
||||
<!-- patch_file 结果:文件路径/字节增减 + unified diff 红删绿增行级预览(复用 df-diff-pre/--add/--del/--ctx 样式)
|
||||
后端 generate_diff 产完整 diff,result.diff 字段此前被丢弃,用户无法验证改了什么 → 此分支渲染 diff -->
|
||||
<div v-else-if="tc.name === 'patch_file' && tc.result && tc.status === 'completed' && parsed" class="ai-tool-patch-result">
|
||||
<div class="ai-tool-file-bar">
|
||||
@@ -136,7 +136,7 @@
|
||||
</div>
|
||||
<div v-if="parsed?.warning" class="ai-tool-approval-reason"><span aria-hidden="true">⚠</span> {{ parsed.warning }}</div>
|
||||
<div v-if="resultDiffLines.length" class="ai-tool-approval-diff">
|
||||
<pre class="ai-tool-diff-pre"><code><span v-for="(ln, idx) in resultDiffLines" :key="idx" class="ai-tool-diff-line" :class="'ai-tool-diff-line--' + ln.kind">{{ ln.text }}{{ '\n' }}</span></code></pre>
|
||||
<pre class="df-diff-pre"><code><span v-for="(ln, idx) in resultDiffLines" :key="idx" class="df-diff-line" :class="'df-diff-line--' + ln.kind">{{ ln.text }}{{ '\n' }}</span></code></pre>
|
||||
<!-- R12a:长 diff 展开入口(默认预览 120 行,点开全量) -->
|
||||
<button v-if="diffTotal > DIFF_PREVIEW_LINES" type="button" class="ai-tool-diff-toggle" @click="diffExpanded = !diffExpanded">{{ diffExpanded ? $t('aiTool.diffCollapse') : $t('aiTool.diffExpand', { n: diffTotal }) }}</button>
|
||||
</div>
|
||||
@@ -468,7 +468,7 @@ watch(() => props.tc.status, (s) => {
|
||||
}
|
||||
.ai-tool-grep-match {
|
||||
padding: 3px 12px;
|
||||
border-bottom: 0.5px solid rgba(255,255,255,0.03);
|
||||
border-bottom: 0.5px solid var(--df-hover);
|
||||
}
|
||||
.ai-tool-grep-match:last-child {
|
||||
border-bottom: none;
|
||||
@@ -511,7 +511,7 @@ watch(() => props.tc.status, (s) => {
|
||||
word-break: break-all;
|
||||
background: rgba(61,219,160,0.05);
|
||||
padding: 2px 6px;
|
||||
border-radius: var(--df-radius-xs, 3px);
|
||||
border-radius: var(--df-radius-xs);
|
||||
}
|
||||
.ai-tool-grep-context {
|
||||
margin: 2px 0 0;
|
||||
@@ -521,8 +521,8 @@ watch(() => props.tc.status, (s) => {
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
background: rgba(255,255,255,0.02);
|
||||
border-radius: var(--df-radius-xs, 3px);
|
||||
background: var(--df-hover);
|
||||
border-radius: var(--df-radius-xs);
|
||||
}
|
||||
.ai-tool-grep-context code {
|
||||
display: block;
|
||||
@@ -533,7 +533,7 @@ watch(() => props.tc.status, (s) => {
|
||||
font-family: var(--df-font-sans);
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
background: rgba(255,255,255,0.04);
|
||||
background: var(--df-hover);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
padding: 2px 8px;
|
||||
@@ -586,13 +586,13 @@ watch(() => props.tc.status, (s) => {
|
||||
.ai-tool-dir-entry {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
gap: 6px;
|
||||
padding: 3px 12px;
|
||||
font-size: 11px;
|
||||
transition: background 0.1s;
|
||||
}
|
||||
.ai-tool-dir-entry:hover {
|
||||
background: rgba(255,255,255,0.03);
|
||||
background: var(--df-hover);
|
||||
}
|
||||
.ai-tool-dir-entry--directory .ai-tool-dir-name {
|
||||
font-weight: 500;
|
||||
@@ -650,8 +650,8 @@ watch(() => props.tc.status, (s) => {
|
||||
padding: 4px 10px 6px;
|
||||
margin-bottom: 6px;
|
||||
font-size: 11px;
|
||||
color: var(--df-warning, #d97706);
|
||||
background: var(--df-warning-bg, rgba(217, 119, 6, 0.08));
|
||||
color: var(--df-warning);
|
||||
background: var(--df-warning-bg);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
}
|
||||
.ai-tool-approval-diff {
|
||||
@@ -660,29 +660,11 @@ watch(() => props.tc.status, (s) => {
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
overflow: hidden;
|
||||
}
|
||||
.ai-tool-diff-pre {
|
||||
margin: 0;
|
||||
padding: 6px 0;
|
||||
max-height: 240px;
|
||||
overflow: auto;
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
background: var(--df-bg-card);
|
||||
}
|
||||
.ai-tool-diff-pre code {
|
||||
display: block;
|
||||
white-space: pre;
|
||||
}
|
||||
.ai-tool-diff-line {
|
||||
display: block;
|
||||
padding: 0 10px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
.ai-tool-diff-line--add { color: var(--df-success, #3ddb9c); background: var(--df-success-bg, rgba(61, 219, 160, 0.08)); }
|
||||
.ai-tool-diff-line--del { color: var(--df-danger, #f06565); background: var(--df-danger-bg, rgba(240, 101, 101, 0.08)); }
|
||||
.ai-tool-diff-line--ctx { color: var(--df-text-dim, #888); }
|
||||
/* diff 基类 .df-diff-pre(+code)/.df-diff-line 消费 global.css 共享定义(2026-10-18 整洁波
|
||||
双轨合一,与 ToolCard.vue 审批 diff 同源),此处仅留行配色变体 */
|
||||
.df-diff-line--add { color: var(--df-success); background: var(--df-success-bg); }
|
||||
.df-diff-line--del { color: var(--df-danger); background: var(--df-danger-bg); }
|
||||
.df-diff-line--ctx { color: var(--df-text-dim); }
|
||||
|
||||
/* -- Generic Result --
|
||||
max-height 100px→200px:通用结果常含 JSON/结构化文本,100px 仅约 5 行,默认滚动条挤压可读性;
|
||||
@@ -741,12 +723,12 @@ watch(() => props.tc.status, (s) => {
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: transparent;
|
||||
color: var(--df-text-dim);
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ai-tool-cmd-toggle:hover {
|
||||
color: var(--df-text);
|
||||
background: var(--df-bg-hover, rgba(255,255,255,0.06));
|
||||
background: var(--df-hover);
|
||||
}
|
||||
.ai-tool-cmd-output {
|
||||
margin: 0;
|
||||
@@ -803,8 +785,8 @@ watch(() => props.tc.status, (s) => {
|
||||
}
|
||||
.ai-tool-http-trunc-warn {
|
||||
padding: 4px 10px;
|
||||
font-size: 10.5px;
|
||||
color: var(--df-warning, #f0c75e);
|
||||
font-size: 10px;
|
||||
color: var(--df-warning);
|
||||
border-top: 0.5px solid var(--df-border);
|
||||
}
|
||||
|
||||
@@ -828,10 +810,10 @@ watch(() => props.tc.status, (s) => {
|
||||
}
|
||||
.ai-tool-fetch-mode--static,
|
||||
.ai-tool-fetch-mode--obscura {
|
||||
color: var(--df-success, #3ddb9c);
|
||||
color: var(--df-success);
|
||||
}
|
||||
.ai-tool-fetch-mode--static_fallback {
|
||||
color: var(--df-warning, #f0c75e);
|
||||
color: var(--df-warning);
|
||||
}
|
||||
.ai-tool-fetch-title {
|
||||
padding: 4px 10px 2px;
|
||||
@@ -845,8 +827,8 @@ watch(() => props.tc.status, (s) => {
|
||||
.ai-tool-obscura-hint {
|
||||
margin: 4px 10px 6px;
|
||||
padding: 6px 8px;
|
||||
background: var(--df-warning-bg, rgba(240,199,94,0.08));
|
||||
border: 0.5px solid var(--df-warning, #f0c75e);
|
||||
background: var(--df-warning-bg);
|
||||
border: 0.5px solid var(--df-warning);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -854,8 +836,8 @@ watch(() => props.tc.status, (s) => {
|
||||
}
|
||||
.ai-tool-obscura-hint-text {
|
||||
font-family: var(--df-font-sans);
|
||||
font-size: 10.5px;
|
||||
color: var(--df-warning, #f0c75e);
|
||||
font-size: 10px;
|
||||
color: var(--df-warning);
|
||||
line-height: 1.5;
|
||||
word-break: break-word;
|
||||
}
|
||||
@@ -870,7 +852,7 @@ watch(() => props.tc.status, (s) => {
|
||||
font-weight: 500;
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
border: none;
|
||||
background: var(--df-accent, #5b8def);
|
||||
background: var(--df-accent);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
font-family: var(--df-font-sans);
|
||||
@@ -891,5 +873,5 @@ watch(() => props.tc.status, (s) => {
|
||||
padding: 3px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ai-tool-diff-toggle:hover { color: var(--df-text); background: var(--df-bg-secondary); }
|
||||
.ai-tool-diff-toggle:hover { color: var(--df-text); background: var(--df-bg-card); }
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<!-- AE-2025-07: Agentic 循环进度条(C 状态语义化)
|
||||
仅 agentic 多轮(streaming 且收到过 AiAgentRound round>0 事件)显示;
|
||||
单轮问答 agentRound 恒 0,不显示(避免误显)。
|
||||
文案:第 {round} 轮 · 累计 {total} 次调用 · 进行中/待审批;
|
||||
total 由前端聚合当前轮次 toolCalls(useTurnTrace),完成后进度条隐藏,
|
||||
完成聚合语义由 MessageList 的执行轨迹卡承接。
|
||||
降级省略:max(总轮次)后端 AiAgentRound 未透传 max_rounds,不显。
|
||||
C4b 拆分自 AiChat.vue(纯展示,store 单例直读,零行为变更)。 -->
|
||||
<div v-if="showAgenticProgress" class="ai-agentic-progress">
|
||||
<span class="ai-agentic-progress-dot"></span>
|
||||
<span class="ai-agentic-progress-text">{{ agenticProgressText }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useAiStore } from '../../stores/ai'
|
||||
import { collectTurnStats, turnMessages } from '../../composables/ai/useTurnTrace'
|
||||
|
||||
const store = useAiStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
// 仅 agentic 多轮(streaming 且 agentRound>0)显示;单轮问答不收 AiAgentRound 故恒隐藏。
|
||||
const showAgenticProgress = computed(() =>
|
||||
store.state.streaming && store.state.agentRound > 0,
|
||||
)
|
||||
// 进度文案(C 状态语义化):「第 N 轮 · 累计 M 次调用 · 进行中/待审批」。
|
||||
// 累计调用数由前端聚合当前轮次消息流上的 toolCalls(后端事件无累计字段,不改协议);
|
||||
// 替代旧「循环 N · X个工具完成」——旧 completedTools 每轮清零,轮初叙述期恒显 0 造成歧义。
|
||||
// 「已完成」态不出现在状态栏:完成后进度条隐藏(既有设计),完成聚合由执行轨迹卡承接。
|
||||
const agenticProgressText = computed(() => {
|
||||
const pending = store.state.pendingApprovals.length
|
||||
const total = collectTurnStats(turnMessages(store.state.messages)).total
|
||||
return pending > 0
|
||||
? t('ai.agenticProgress', { round: store.state.agentRound, total, pending })
|
||||
: t('ai.agenticProgressNoPending', { round: store.state.agentRound, total })
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* ═══ Agentic 循环进度条(样式随区块自 AiChat.vue 迁入,零视觉变更) ═══ */
|
||||
.ai-agentic-progress {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-bottom: 6px;
|
||||
padding: 3px 8px;
|
||||
background: color-mix(in srgb, var(--df-accent) 8%, transparent);
|
||||
border-radius: var(--df-radius);
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
user-select: none;
|
||||
}
|
||||
.ai-agentic-progress-dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-accent);
|
||||
flex-shrink: 0;
|
||||
animation: ai-agentic-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
.ai-agentic-progress-text {
|
||||
font-family: var(--df-font-mono);
|
||||
white-space: nowrap;
|
||||
}
|
||||
@keyframes ai-agentic-pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.3; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,288 @@
|
||||
<template>
|
||||
<!-- ═══ 待发送队列(生成中排队的消息,完成后自动续发;仅显示当前活跃会话的条目)
|
||||
C4b 拆分自 AiChat.vue 队列区(模板 + L2 发送韧性 + V7 排队时钟 + 队列编辑/回填,零行为变更;
|
||||
store 单例共享,confirm 自持一份 useConfirm + ConfirmDialog——同 ChatInput/ConversationSidebar
|
||||
模式:useConfirm 非单例,子组件发起的 confirm 须本组件渲染) ═══ -->
|
||||
<div v-if="activeQueue.length > 0" class="ai-queue" :class="{ 'ai-queue--timeout': queueTimedOut }">
|
||||
<div class="ai-queue-head">
|
||||
<span class="ai-queue-title">{{ $t('aiChat.queueTitle', { n: activeQueue.length }) }}</span>
|
||||
<div class="ai-queue-actions">
|
||||
<button v-if="queueTimedOut" class="ai-queue-force" @click="handleForceSend">{{ $t('ai.forceSendBtn') }}</button>
|
||||
<button class="ai-queue-clear" @click="handleClearQueue">{{ $t('aiChat.clearQueue') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ai-queue-list">
|
||||
<div v-for="(item, idx) in activeQueue" :key="idx" class="ai-queue-item">
|
||||
<!-- 编辑态只编 text:inline input,回车/失焦写回,ESC 取消 -->
|
||||
<template v-if="editingQueueIdx === idx">
|
||||
<span v-if="item.skill" class="ai-queue-skill">/{{ item.skill }}</span>
|
||||
<input
|
||||
v-model="editingQueueText"
|
||||
class="ai-queue-edit-input"
|
||||
type="text"
|
||||
@keydown="onQueueEditKeydown"
|
||||
@blur="saveEditQueued"
|
||||
/>
|
||||
<button class="ai-queue-btn" @mousedown.prevent="saveEditQueued" :title="$t('aiChat.queueSave')" :aria-label="$t('aiChat.queueSave')">✓</button>
|
||||
<button class="ai-queue-btn" @mousedown.prevent="cancelEditQueued" :title="$t('aiChat.queueCancel')" :aria-label="$t('aiChat.queueCancel')">✕</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span v-if="item.skill" class="ai-queue-skill">/{{ item.skill }}</span>
|
||||
<span class="ai-queue-text" :title="item.text">{{ item.text }}</span>
|
||||
<!-- V7 排队时钟:该项已等待时长 m:ss(nowTick 每秒推进,入发送随队列清空即停) -->
|
||||
<span class="ai-queue-wait">{{ queueItemWait(item) }}</span>
|
||||
<!-- I4 队列回填:取出该项填回输入框重新编辑(从队列移除) -->
|
||||
<button class="ai-queue-btn" @click="backfillQueued(idx)" :title="$t('aiChat.queueBackfill')">{{ $t('aiChat.queueBackfill') }}</button>
|
||||
<!-- 编辑按钮 -->
|
||||
<button class="ai-queue-btn" @click="startEditQueued(idx)" :title="$t('aiChat.queueEdit')">{{ $t('aiChat.queueEdit') }}</button>
|
||||
<!-- 立即发送(打断当前+发本条) -->
|
||||
<button class="ai-queue-btn" @click="handleSendQueuedNow(idx)" :title="$t('aiChat.queueSendNow')">{{ $t('aiChat.queueSendNow') }}</button>
|
||||
<button class="ai-queue-x" @click="store.cancelQueued(idx)" :title="$t('common.cancel')" :aria-label="$t('common.cancel')">×</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 确认弹层(强制发送/清空/回填覆盖二次确认;同 ChatInput 自持模式) -->
|
||||
<ConfirmDialog
|
||||
:visible="confirmState.visible"
|
||||
:msg="confirmState.msg"
|
||||
:danger-label="confirmState.dangerLabel"
|
||||
@result="answerConfirm"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onBeforeUnmount } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useAiStore } from '../../stores/ai'
|
||||
import ConfirmDialog from '../ConfirmDialog.vue'
|
||||
import { useConfirm } from '../../composables/useConfirm'
|
||||
import type { SkillInfo } from '../../api/types'
|
||||
|
||||
// 回填链路跨组件:输入框 ref(chatInputRef)在父,本组件经 props 读草稿态(hasUnsentInput)、
|
||||
// 经 emit 写草稿(fill-draft),由父转发 ChatInput——共享函数留主文件 props/emits 传(拆分纪律)。
|
||||
const props = defineProps<{
|
||||
/** 父侧 ChatInput.hasUnsentInput 转发(回填覆盖未发送草稿前的 confirm 守卫) */
|
||||
hasUnsentInput: () => boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 队列项回填:父转发 ChatInput.fillDraft(text, skill) 写入输入框草稿 */
|
||||
(e: 'fill-draft', text: string, skill: SkillInfo | null): void
|
||||
}>()
|
||||
|
||||
const store = useAiStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
// ── 确认弹层(useConfirm 非单例,子组件自持一份 + 自渲染 ConfirmDialog,同 ChatInput 先例) ──
|
||||
const { confirmState, confirmDialog, answerConfirm } = useConfirm()
|
||||
|
||||
/** 当前活跃会话的待发送队列(按 activeConversationId 过滤)。
|
||||
* 队列是全局数组,多会话并发可各自排队;旧实现渲染全部会话的 queue,切/新建后会显示
|
||||
* 旧会话排队消息。此处仅显当前活跃会话条目,相关操作(编辑/删除/立即发送/清空/超时)均按此收敛。 */
|
||||
const activeQueue = computed(() =>
|
||||
store.state.queue.filter(q => q.conversationId === store.state.activeConversationId),
|
||||
)
|
||||
|
||||
// ── V7 排队时钟:响应式 tick 驱动排队项已等待时长 ──
|
||||
// 原 queueWaitSeconds 在 computed 内直接取 Date.now(),非响应式依赖:纯等待期(无 store 变更)
|
||||
// 永不重算,秒数冻结;且只覆盖队首。改为有排队时起 1s interval 推进 nowTick,展示函数读
|
||||
// nowTick 建立依赖实现每秒刷新;队列清空(含队首进入发送被移除)即关表,卸载时显式清理防泄漏。
|
||||
const nowTick = ref(Date.now())
|
||||
let queueTickTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
/** 队首排队是否已超 30s(仅看当前活跃会话队列)。
|
||||
* UX-P2-A1:isQueueTimedOut 内取 Date.now() 非响应式,纯等待期(无 store 变更)本 computed
|
||||
* 永不重算,超时横幅/强制发送按钮延迟到下一次无关 store 变更才出现。显式读 nowTick
|
||||
* (V7 排队时钟,有排队时 1s interval 推进)建立每秒依赖,超时判定随 tick 每秒重算。 */
|
||||
const queueTimedOut = computed(() => {
|
||||
void nowTick.value
|
||||
return store.isQueueTimedOut(store.state.activeConversationId)
|
||||
})
|
||||
|
||||
watch(
|
||||
() => activeQueue.value.length > 0,
|
||||
(waiting) => {
|
||||
if (waiting && queueTickTimer === null) {
|
||||
nowTick.value = Date.now()
|
||||
queueTickTimer = setInterval(() => { nowTick.value = Date.now() }, 1000)
|
||||
} else if (!waiting && queueTickTimer !== null) {
|
||||
clearInterval(queueTickTimer)
|
||||
queueTickTimer = null
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/** 秒数转 m:ss(分钟不封顶,长等待继续累计) */
|
||||
function formatWaitTime(totalSeconds: number): string {
|
||||
return `${Math.floor(totalSeconds / 60)}:${String(totalSeconds % 60).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
/** 排队项已等待时长(m:ss);读 nowTick 建立响应式依赖,每秒随 tick 刷新 */
|
||||
function queueItemWait(item: { enqueuedAt: number }): string {
|
||||
return formatWaitTime(Math.max(0, Math.floor((nowTick.value - item.enqueuedAt) / 1000)))
|
||||
}
|
||||
|
||||
/** 强制发送:委托 tryForceSend 唯一负责弹 confirm + 移除队列 + force_send(作用于当前活跃会话) */
|
||||
async function handleForceSend() {
|
||||
await store.tryForceSend(confirmDialog, store.state.activeConversationId)
|
||||
}
|
||||
|
||||
/** UI-4(看板 943)清空队列:二次确认后全清当前活跃会话排队消息。
|
||||
* 一键误触会静默丢掉全部排队消息且不可恢复,复用 ConfirmDialog 先例
|
||||
* (同 tryForceSend 的 confirmFn 注入形态),不引 window.confirm(仓风格)。 */
|
||||
async function handleClearQueue() {
|
||||
const convId = store.state.activeConversationId
|
||||
if (!convId) return
|
||||
const confirmed = await confirmDialog(t('aiChat.clearQueueConfirm'))
|
||||
if (confirmed) store.clearQueue(convId)
|
||||
}
|
||||
|
||||
// ── 队列消息编辑(只编 text)+ 立即发送(插队)──
|
||||
|
||||
/** 当前正在编辑的队列项 index;null=非编辑态 */
|
||||
const editingQueueIdx = ref<number | null>(null)
|
||||
/** 编辑态输入框文本(回车写回 / ESC 取消还原) */
|
||||
const editingQueueText = ref('')
|
||||
|
||||
// UX-P3: 队列编辑态(editingQueueIdx/editingQueueText)绑定旧会话队列在 activeQueue
|
||||
// 视图内的下标,切会话后 activeQueue 已换成新会话的集合,残留 idx/text 会错挂到
|
||||
// 新会话同下标队列项上,切会话即重置(原随父 watch activeConversationId,拆分后本组件自管)。
|
||||
watch(() => store.state.activeConversationId, () => {
|
||||
if (editingQueueIdx.value !== null) cancelEditQueued()
|
||||
})
|
||||
|
||||
/** 进入编辑态:记录 index + 快照当前 text(activeQueue 视图内下标) */
|
||||
function startEditQueued(idx: number) {
|
||||
const item = activeQueue.value[idx]
|
||||
if (!item) return
|
||||
editingQueueIdx.value = idx
|
||||
editingQueueText.value = item.text
|
||||
}
|
||||
|
||||
/** 取消编辑:还原非编辑态,不写回 */
|
||||
function cancelEditQueued() {
|
||||
editingQueueIdx.value = null
|
||||
editingQueueText.value = ''
|
||||
}
|
||||
|
||||
/** P1-1 队列编辑框键盘处理:输入法组词中(isComposing/229)的 Enter/Esc 属 IME 选词/取消组词,
|
||||
* 不当提交/取消处理,防半截拼音被写回队列项。原 @keydown.enter/.esc 内联修饰符挂不了守卫,
|
||||
* 收敛到本函数统一判。 */
|
||||
function onQueueEditKeydown(e: KeyboardEvent) {
|
||||
if (e.isComposing || e.keyCode === 229) return
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
saveEditQueued()
|
||||
} else if (e.key === 'Escape') {
|
||||
e.preventDefault()
|
||||
cancelEditQueued()
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存编辑:回车/失焦触发,委托 store.editQueued 写回 text */
|
||||
function saveEditQueued() {
|
||||
if (editingQueueIdx.value === null) return
|
||||
store.editQueued(editingQueueIdx.value, editingQueueText.value)
|
||||
editingQueueIdx.value = null
|
||||
editingQueueText.value = ''
|
||||
}
|
||||
|
||||
/** 立即发送:委托 store.sendQueuedNow(移除+stop+sendMessage) */
|
||||
async function handleSendQueuedNow(idx: number) {
|
||||
await store.sendQueuedNow(idx)
|
||||
}
|
||||
|
||||
/** I4 队列回填:取出该条填回输入框重新编辑(从队列移除,可改完再发)。
|
||||
* cancelQueued 内部经 activeQueueRealIndex 做过滤视图下标映射,越界 no-op;
|
||||
* 项携带技能时按名找回 SkillInfo 回挂 chip,找不到(技能已卸载)只回填文本,
|
||||
* 与队列原地编辑只保 text 同一取舍。 */
|
||||
async function backfillQueued(idx: number) {
|
||||
const item = activeQueue.value[idx]
|
||||
if (!item) return
|
||||
// UX-P3: 输入框已有未发送草稿(文本/图片/技能 chip 任一非空)时回填会静默覆盖,
|
||||
// 先 confirm 确认;取消则直接返回,队列项原样保留(尚未 cancelQueued)。
|
||||
if (props.hasUnsentInput()) {
|
||||
if (!await confirmDialog(t('aiChat.backfillOverwriteConfirm'))) return
|
||||
}
|
||||
const skill = item.skill
|
||||
? store.state.skills.find(s => s.name === item.skill) ?? null
|
||||
: null
|
||||
store.cancelQueued(idx)
|
||||
emit('fill-draft', item.text, skill)
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// V7 排队时钟 interval 随组件卸载清理(watch 随卸载停但 interval 本体不自停,须显式清)
|
||||
if (queueTickTimer !== null) { clearInterval(queueTickTimer); queueTickTimer = null }
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* ═══ 待发送队列(样式随区块自 AiChat.vue 迁入,零视觉变更) ═══ */
|
||||
.ai-queue {
|
||||
margin-bottom: 6px;
|
||||
padding: 6px 8px;
|
||||
background: color-mix(in srgb, var(--df-accent) 8%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-accent) 30%, transparent);
|
||||
border-radius: var(--df-radius);
|
||||
}
|
||||
.ai-queue--timeout {
|
||||
background: color-mix(in srgb, var(--df-warning) 10%, transparent);
|
||||
border-color: color-mix(in srgb, var(--df-warning) 40%, transparent);
|
||||
}
|
||||
.ai-queue-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.ai-queue-title { font-size: 11px; color: var(--df-text-dim); font-weight: 600; }
|
||||
.ai-queue--timeout .ai-queue-title { color: var(--df-warning); }
|
||||
.ai-queue-actions { display: flex; align-items: center; gap: 8px; }
|
||||
.ai-queue-force {
|
||||
background: var(--df-warning); border: none; color: #000; cursor: pointer;
|
||||
font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: calc(var(--df-radius) - 2px);
|
||||
}
|
||||
.ai-queue-force:hover { filter: brightness(1.1); }
|
||||
.ai-queue-clear { background: none; border: none; color: var(--df-text-dim); cursor: pointer; font-size: 11px; padding: 0; }
|
||||
.ai-queue-clear:hover { color: var(--df-text); }
|
||||
.ai-queue-list { display: flex; flex-direction: column; gap: 3px; }
|
||||
.ai-queue-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 3px 6px;
|
||||
background: var(--df-bg-card);
|
||||
border-radius: calc(var(--df-radius) - 2px);
|
||||
font-size: 12px;
|
||||
}
|
||||
.ai-queue-skill { color: var(--df-accent); font-weight: 600; flex-shrink: 0; }
|
||||
/* V7 排队时钟:每项已等待时长 */
|
||||
.ai-queue-wait { color: var(--df-text-dim); font-size: 10px; flex-shrink: 0; opacity: 0.7; }
|
||||
.ai-queue-text {
|
||||
color: var(--df-text);
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ai-queue-x { background: none; border: none; color: var(--df-text-dim); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; flex-shrink: 0; }
|
||||
.ai-queue-x:hover { color: var(--df-danger); }
|
||||
/* 队列项编辑/立即发送按钮 + 编辑态 input */
|
||||
.ai-queue-btn {
|
||||
background: none; border: none; color: var(--df-text-dim); cursor: pointer;
|
||||
font-size: 11px; line-height: 1; padding: 0 4px; flex-shrink: 0;
|
||||
}
|
||||
.ai-queue-btn:hover { color: var(--df-accent); }
|
||||
.ai-queue-edit-input {
|
||||
flex: 1; min-width: 0; font-size: 12px; padding: 1px 4px;
|
||||
background: var(--df-bg-card); color: var(--df-text);
|
||||
border: 0.5px solid var(--df-accent);
|
||||
border-radius: calc(var(--df-radius) - 2px);
|
||||
outline: none;
|
||||
}
|
||||
/* 聚焦可见环:边框恒为 accent 聚焦无变化,且 scoped 选择器特异性高于全局 :focus-visible 兜底,须就地补环,仅键盘聚焦显示 */
|
||||
.ai-queue-edit-input:focus-visible { outline: 2px solid var(--df-accent); outline-offset: 1px; }
|
||||
</style>
|
||||
@@ -0,0 +1,117 @@
|
||||
<template>
|
||||
<!-- I12(2026-10-05):键盘快捷键速查。Teleport 到 body 防 .ai-panel overflow 裁剪;
|
||||
主窗/分离窗各自实例独立渲染,入口在 TopBar ... 菜单(emit show-shortcuts)。
|
||||
C4b 拆分自 AiChat.vue(visible 状态留父——onGlobalKeydown Esc 仲裁需读写,开/关经 props/emits) -->
|
||||
<Teleport to="body">
|
||||
<div v-if="visible" class="ai-shortcuts-mask" @click.self="emit('close')">
|
||||
<div class="ai-shortcuts-panel" role="dialog" :aria-label="t('aiChat.shortcutsTitle')">
|
||||
<div class="ai-shortcuts-head">
|
||||
<span class="ai-shortcuts-title">{{ t('aiChat.shortcutsTitle') }}</span>
|
||||
<button class="ai-shortcuts-close" :aria-label="t('aiChat.scCloseOverlay')" @click="emit('close')">✕</button>
|
||||
</div>
|
||||
<ul class="ai-shortcuts-list">
|
||||
<li v-for="s in shortcuts" :key="s.key" class="ai-shortcuts-row">
|
||||
<span class="ai-shortcuts-key">{{ s.key }}</span>
|
||||
<span class="ai-shortcuts-act">{{ s.label }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
/** 面板显隐(状态留父:TopBar emit show-shortcuts 置 true,onGlobalKeydown Esc 分支仲裁) */
|
||||
visible: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'close'): void
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
// 键位表 shortcuts 与父 AiChat onGlobalKeydown 同族——键区调整时两边同步,防速查与真实键位漂移。
|
||||
// computed:随 locale 即时翻译(仅面板打开时消费,开销可忽略)。
|
||||
const shortcuts = computed(() => [
|
||||
{ key: 'Ctrl+N', label: t('aiChat.scNewConv') },
|
||||
{ key: 'Ctrl+I', label: t('aiChat.scFocusInput') },
|
||||
{ key: 'Ctrl+R', label: t('aiChat.scRegenerate') },
|
||||
{ key: 'Ctrl+L', label: t('aiChat.scClearChat') },
|
||||
{ key: 'Ctrl+K', label: t('aiChat.scSearch') },
|
||||
{ key: 'Ctrl+B', label: t('aiChat.scToggleSidebar') },
|
||||
{ key: 'Esc', label: t('aiChat.scCloseOverlay') },
|
||||
])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* ═══ I12 快捷键速查面板(Teleport 到 body,scoped 对 Teleport 内容仍生效——
|
||||
Vue scoped 把 data 属性打在编译期节点上,与挂载位置无关;样式随区块自 AiChat.vue 迁入) ═══ */
|
||||
.ai-shortcuts-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.ai-shortcuts-panel {
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-lg, 8px);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
width: 320px;
|
||||
max-width: calc(100vw - 48px);
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.ai-shortcuts-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.ai-shortcuts-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ai-shortcuts-close {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--df-text-secondary);
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
padding: 2px 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.ai-shortcuts-close:hover { color: var(--df-text); background: var(--df-bg-card); }
|
||||
.ai-shortcuts-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.ai-shortcuts-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 12px;
|
||||
}
|
||||
.ai-shortcuts-key {
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 11px;
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: 4px;
|
||||
padding: 2px 8px;
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ai-shortcuts-act { color: var(--df-text-secondary); }
|
||||
</style>
|
||||
@@ -108,7 +108,9 @@ function onDismiss() {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 浮层 — 右上角 fixed,z-index 高于 AI 面板与其他模态 */
|
||||
/* 浮层 — 右上角 fixed,z-index 高于 AI 面板与其他模态
|
||||
wave2(2026-10-18):danger 系透明彩底范式(待审批=需用户处置的阻断信号)——
|
||||
弹层底 bg-card+边框+10px 圆角,边框 color-mix 30%+左缘 3px 强调,标题同色 12px/600 */
|
||||
.approval-overlay {
|
||||
position: fixed;
|
||||
top: 16px;
|
||||
@@ -121,10 +123,10 @@ function onDismiss() {
|
||||
min-width: 260px;
|
||||
max-width: 360px;
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-accent);
|
||||
border-left: 3px solid var(--df-accent);
|
||||
border-radius: var(--df-radius-md);
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--df-accent-soft);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-danger) 30%, transparent);
|
||||
border-left: 3px solid var(--df-danger);
|
||||
border-radius: var(--df-radius-lg);
|
||||
box-shadow: var(--df-shadow-md), 0 0 0 1px color-mix(in srgb, var(--df-danger) 12%, transparent);
|
||||
cursor: pointer;
|
||||
transition: transform 0.18s var(--df-ease), border-color 0.18s var(--df-ease), box-shadow 0.18s var(--df-ease);
|
||||
user-select: none;
|
||||
@@ -132,8 +134,8 @@ function onDismiss() {
|
||||
|
||||
.approval-overlay:hover {
|
||||
transform: translateX(-2px);
|
||||
border-color: var(--df-accent);
|
||||
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5), 0 0 0 2px var(--df-accent);
|
||||
border-color: color-mix(in srgb, var(--df-danger) 55%, transparent);
|
||||
box-shadow: var(--df-shadow-md), 0 0 0 2px color-mix(in srgb, var(--df-danger) 45%, transparent);
|
||||
}
|
||||
|
||||
.approval-overlay-icon {
|
||||
@@ -144,8 +146,8 @@ function onDismiss() {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
background: color-mix(in srgb, var(--df-danger) 10%, transparent);
|
||||
color: var(--df-danger);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -172,15 +174,15 @@ function onDismiss() {
|
||||
}
|
||||
|
||||
.approval-overlay-title {
|
||||
font-size: 13px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--df-text);
|
||||
color: var(--df-danger);
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.approval-overlay-desc {
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
@@ -190,8 +192,8 @@ function onDismiss() {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
width: var(--df-h-icon-btn);
|
||||
height: var(--df-h-icon-btn);
|
||||
border: none;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: transparent;
|
||||
@@ -202,7 +204,7 @@ function onDismiss() {
|
||||
}
|
||||
|
||||
.approval-overlay-close:hover {
|
||||
background: var(--df-sidebar-hover);
|
||||
background: var(--df-bg-card-hover);
|
||||
color: var(--df-text);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ onMounted(async () => {
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
margin: 8px 0;
|
||||
background: var(--df-bg-secondary);
|
||||
background: var(--df-bg-card);
|
||||
font-size: 12px;
|
||||
}
|
||||
.ci-header {
|
||||
|
||||
+226
-106
@@ -45,81 +45,86 @@
|
||||
@select="selectMention"
|
||||
@update:mention-index="mentionIndex = $event"
|
||||
/>
|
||||
<!-- 2026-08-06:📎 图片选择按钮(tauri 原生对话框选图 → 已配置上传端点则上传换 URL,否则本地 base64 引用) -->
|
||||
<button
|
||||
type="button"
|
||||
class="ai-img-pick-btn"
|
||||
:title="$t('aiChat.pickImage')"
|
||||
:aria-label="$t('aiChat.pickImage')"
|
||||
@click="onPickImage"
|
||||
>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
|
||||
</button>
|
||||
<!-- I9(2026-10-05):文本/代码文件附件入口——选文件读内容以 ```<file> 块插入草稿,
|
||||
走既有文本发送链,零协议改动;大小/行数上限防刷屏 -->
|
||||
<button
|
||||
type="button"
|
||||
class="ai-img-pick-btn"
|
||||
:title="$t('aiChat.pickFileTitle')"
|
||||
:aria-label="$t('aiChat.pickFileTitle')"
|
||||
@click="onPickTextFile"
|
||||
>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V9z"/><polyline points="13 2 13 9 20 9"/></svg>
|
||||
</button>
|
||||
<!-- 定时/待发箱入口(设计 2026-10-10 §3.4):icon-only ⏰ 开 OutboxDrawer
|
||||
(组件内 Teleport 到 body,不占输入区布局;抽屉组件标签在模板尾部) -->
|
||||
<button
|
||||
type="button"
|
||||
class="ai-img-pick-btn"
|
||||
:title="$t('aiChat.outboxEntry')"
|
||||
:aria-label="$t('aiChat.outboxEntry')"
|
||||
@click="outboxOpen = true"
|
||||
>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
||||
</button>
|
||||
<!-- L2 状态机停止按钮三态(批2 1c):conv_state 派生 generating/stopping/error 三态,
|
||||
idle(或 conv_state 未收到回退旧 streaming=false)显发送按钮。双轨过渡不强制全替旧 bool。 -->
|
||||
<button
|
||||
v-if="stopBtnState === 'stopping'"
|
||||
type="button"
|
||||
class="ai-send-btn ai-send-btn--stop ai-send-btn--stopping"
|
||||
:title="$t('aiChat.stopping')"
|
||||
:aria-label="$t('aiChat.stopping')"
|
||||
disabled
|
||||
>
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>
|
||||
</button>
|
||||
<button
|
||||
v-else-if="stopBtnState === 'retry'"
|
||||
type="button"
|
||||
class="ai-send-btn ai-send-btn--stop ai-send-btn--retry"
|
||||
:title="$t('aiChat.stopFailedRetry')"
|
||||
:aria-label="$t('aiChat.stopFailedRetry')"
|
||||
@click="store.stopChat"
|
||||
>
|
||||
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
|
||||
</button>
|
||||
<button
|
||||
v-else-if="stopBtnState === 'stop'"
|
||||
type="button"
|
||||
class="ai-send-btn ai-send-btn--stop"
|
||||
:title="$t('aiChat.stopGenerating')"
|
||||
:aria-label="$t('aiChat.stopGenerating')"
|
||||
@click="store.stopChat"
|
||||
>
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="ai-send-btn"
|
||||
:class="{ 'ai-send-btn--active': canSend }"
|
||||
:disabled="!canSend"
|
||||
:aria-label="$t('aiChat.queueSendNow')"
|
||||
@click="handleSend"
|
||||
>
|
||||
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
|
||||
</button>
|
||||
<!-- 2026-10-18 wave2: 工具行(workbench .inp-row 范式)——textarea 下方分隔线,
|
||||
左侧功能钮 + 右侧发送/停止钮;纯布局重排,按钮类名/事件/禁用判定零变化 -->
|
||||
<div class="ai-input-row">
|
||||
<!-- 2026-08-06:📎 图片选择按钮(tauri 原生对话框选图 → 已配置上传端点则上传换 URL,否则本地 base64 引用) -->
|
||||
<button
|
||||
type="button"
|
||||
class="ai-img-pick-btn"
|
||||
:title="$t('aiChat.pickImage')"
|
||||
:aria-label="$t('aiChat.pickImage')"
|
||||
@click="onPickImage"
|
||||
>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
|
||||
</button>
|
||||
<!-- I9(2026-10-05):文本/代码文件附件入口——选文件读内容以 ```<file> 块插入草稿,
|
||||
走既有文本发送链,零协议改动;大小/行数上限防刷屏 -->
|
||||
<button
|
||||
type="button"
|
||||
class="ai-img-pick-btn"
|
||||
:title="$t('aiChat.pickFileTitle')"
|
||||
:aria-label="$t('aiChat.pickFileTitle')"
|
||||
@click="onPickTextFile"
|
||||
>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V9z"/><polyline points="13 2 13 9 20 9"/></svg>
|
||||
</button>
|
||||
<!-- 定时/待发箱入口(设计 2026-10-10 §3.4):icon-only ⏰ 开 OutboxDrawer
|
||||
(组件内 Teleport 到 body,不占输入区布局;抽屉组件标签在模板尾部) -->
|
||||
<button
|
||||
type="button"
|
||||
class="ai-img-pick-btn"
|
||||
:title="$t('aiChat.outboxEntry')"
|
||||
:aria-label="$t('aiChat.outboxEntry')"
|
||||
@click="outboxOpen = true"
|
||||
>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
||||
</button>
|
||||
<!-- L2 状态机停止按钮三态(批2 1c):conv_state 派生 generating/stopping/error 三态,
|
||||
idle(或 conv_state 未收到回退旧 streaming=false)显发送按钮。双轨过渡不强制全替旧 bool。 -->
|
||||
<button
|
||||
v-if="stopBtnState === 'stopping'"
|
||||
type="button"
|
||||
class="ai-send-btn ai-send-btn--stop ai-send-btn--stopping"
|
||||
:title="$t('aiChat.stopping')"
|
||||
:aria-label="$t('aiChat.stopping')"
|
||||
disabled
|
||||
>
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>
|
||||
</button>
|
||||
<button
|
||||
v-else-if="stopBtnState === 'retry'"
|
||||
type="button"
|
||||
class="ai-send-btn ai-send-btn--stop ai-send-btn--retry"
|
||||
:title="$t('aiChat.stopFailedRetry')"
|
||||
:aria-label="$t('aiChat.stopFailedRetry')"
|
||||
@click="store.stopChat"
|
||||
>
|
||||
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
|
||||
</button>
|
||||
<button
|
||||
v-else-if="stopBtnState === 'stop'"
|
||||
type="button"
|
||||
class="ai-send-btn ai-send-btn--stop"
|
||||
:title="$t('aiChat.stopGenerating')"
|
||||
:aria-label="$t('aiChat.stopGenerating')"
|
||||
@click="store.stopChat"
|
||||
>
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="ai-send-btn"
|
||||
:class="{ 'ai-send-btn--active': canSend }"
|
||||
:disabled="!canSend"
|
||||
:title="$t('aiChat.send')"
|
||||
:aria-label="$t('aiChat.send')"
|
||||
@click="handleSend"
|
||||
>
|
||||
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ⑥.4 Phase 4: @项目展开摘要(提取至 EnrichmentPanel.vue) -->
|
||||
<EnrichmentPanel
|
||||
@@ -132,6 +137,12 @@
|
||||
/>
|
||||
<!-- 定时/待发箱抽屉(⏰ 入口;Teleport 到 body 渲染,此处仅挂组件) -->
|
||||
<OutboxDrawer :open="outboxOpen" @close="outboxOpen = false" />
|
||||
<!-- F2-4(走查-信息UX 面二):示例卡覆盖未发送草稿的二次确认弹层(组件自持,见 setup 注释) -->
|
||||
<ConfirmDialog
|
||||
:visible="confirmState.visible"
|
||||
:msg="confirmState.msg"
|
||||
@result="answerConfirm"
|
||||
/>
|
||||
<div class="ai-input-hint">{{ $t('aiChat.inputHint') }}</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -145,7 +156,7 @@
|
||||
// - 出错 emit('error', { msg, type }) → 父 showToast(单一 toast 源)
|
||||
// - 示例问题卡片在父(空状态区),父调 expose sendExamplePrompt 触发本组件发送
|
||||
// store 单例共享:useAiStore(sendMessage/editMessage/stopChat)、useProjectStore(@ 联想源)
|
||||
import { ref, computed, nextTick, watch } from 'vue'
|
||||
import { ref, computed, nextTick, watch, onBeforeUnmount } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useAiStore } from '../../stores/ai'
|
||||
import { useProjectStore } from '../../stores/project'
|
||||
@@ -162,6 +173,8 @@ import ImageInput from './ImageInput.vue'
|
||||
import MentionPopover from './MentionPopover.vue'
|
||||
import EnrichmentPanel from './EnrichmentPanel.vue'
|
||||
import OutboxDrawer from './OutboxDrawer.vue'
|
||||
import ConfirmDialog from '../ConfirmDialog.vue'
|
||||
import { useConfirm } from '../../composables/useConfirm'
|
||||
import { taskApi } from '../../api/task'
|
||||
import type { AiMessage, ContentPart, SkillInfo, ProjectRecord, TaskRecord, IdeaRecord, MentionSpan } from '../../api/types'
|
||||
import type { MentionItem } from './MentionItem'
|
||||
@@ -1078,6 +1091,8 @@ async function handleSend() {
|
||||
// 生成中不再拦截:sendMessage 会把消息排入待发送队列,完成后自动续发
|
||||
// 先清输入(无论立即发还是入队);队列满/IPC 失败时 catch 回填
|
||||
inputText.value = ''
|
||||
// F2-2:草稿已消费,立即落盘删项(不等防抖——快速关窗 300ms 内会残留已发送稿)
|
||||
persistDraftNow()
|
||||
pendingSkill.value = null
|
||||
pendingImages.value = []
|
||||
// Input Augmentation: 清空 mention 区间(与 inputText 清空同处,保证下条消息从空白态起步)
|
||||
@@ -1113,12 +1128,20 @@ async function handleSend() {
|
||||
emit('sent')
|
||||
}
|
||||
|
||||
/** 点击示例问题卡片:填入输入框并发送(复用 handleSend 同款发送路径,错误回退一致) */
|
||||
/** 点击示例问题卡片:填入输入框并发送(复用 handleSend 同款发送路径,错误回退一致)。
|
||||
* F2-4(走查-信息UX 面二):输入框已有未发送草稿(文本/图片/技能 chip 任一)时先确认,
|
||||
* 取消则原样保留草稿——对齐父级 backfillQueued 的覆盖确认语义,不再静默替换。 */
|
||||
async function sendExamplePrompt(i18nKey: string) {
|
||||
if (hasUnsentInput() && !(await confirmDialog(t('aiChat.exampleOverwriteConfirm')))) return
|
||||
inputText.value = t(i18nKey)
|
||||
await handleSend()
|
||||
}
|
||||
|
||||
// ── F2-4:覆盖确认弹层(仓风格不引 window.confirm;AiChat 的 confirmDialog 状态机在父级
|
||||
// 经模板绑定,子组件复用需父接线 → 本组件自持一份 useConfirm + ConfirmDialog,
|
||||
// 行为/样式与父级 backfillQueued / clearQueue 确认同范式) ──
|
||||
const { confirmState, confirmDialog, answerConfirm } = useConfirm()
|
||||
|
||||
// ── 父调用 expose(父 startEdit/cancelEdit/beforeunload 调用) ──
|
||||
|
||||
/** UX-09 进入编辑态:回填末条 user 内容到输入框,聚焦,光标置末 */
|
||||
@@ -1140,7 +1163,9 @@ function startEditFocus(msg: AiMessage): void {
|
||||
const len = el.value.length
|
||||
el.setSelectionRange(len, len)
|
||||
el.style.height = 'auto'
|
||||
el.style.height = Math.min(el.scrollHeight, 120) + 'px'
|
||||
// F2-3(走查-信息UX):编辑态回填高度复用 INPUT_MAX_HEIGHT,与 autoResize 同源;
|
||||
// 原硬编码 120 使长草稿进编辑态首屏被压矮,任一按键才弹回 200
|
||||
el.style.height = Math.min(el.scrollHeight, INPUT_MAX_HEIGHT) + 'px'
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1155,6 +1180,8 @@ function clearInput(): void {
|
||||
mentionOpen.value = false
|
||||
mentionStart.value = -1
|
||||
if (inputEl.value) inputEl.value.style.height = 'auto'
|
||||
// F2-2:清空即落盘(取消编辑不应残留旧稿到下次重启)
|
||||
persistDraftNow()
|
||||
}
|
||||
|
||||
/** I4 队列回填:父把取出的队列项文本填回输入框重新编辑。
|
||||
@@ -1184,12 +1211,78 @@ function focus(): void {
|
||||
}
|
||||
|
||||
// ── V8 per-conv 草稿:切会话保存/恢复,防 A 会话未发送草稿串到 B 输入框 ──
|
||||
// 草稿真相源在 aiShared.convDrafts(内存 Map,不落 localStorage)。父组件 AiChat 的
|
||||
// 会话内真相源在 aiShared.convDrafts(内存 Map);F2-2(走查-信息UX 面二)追加落盘镜像:
|
||||
// 键入过程防抖写 localStorage,重启/换装后经回退链恢复。父组件 AiChat 的
|
||||
// activeConversationId watcher 注册更早先执行:编辑态切换时父先 cancelEdit 清输入,
|
||||
// 本 watcher 后执行,旧会话保存到的是清空后的空串,与既有「切会话丢弃编辑缓冲」语义一致。
|
||||
|
||||
// F2-2:per-conv 草稿 localStorage 镜像(df-ai-* 键约定;单 JSON 对象,LRU 限 20 条,
|
||||
// 空串收敛删项——与内存 Map 同语义)。读写全程 try/catch:持久化是尽力而为,
|
||||
// 解析失败/配额满不阻断输入主链。
|
||||
const DRAFTS_KEY = 'df-ai-conv-drafts'
|
||||
const DRAFTS_MAX = 20
|
||||
|
||||
function readDraftsStore(): Record<string, string> {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(localStorage.getItem(DRAFTS_KEY) || '{}')
|
||||
return parsed && typeof parsed === 'object' ? (parsed as Record<string, string>) : {}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
function persistDraft(convId: string, text: string): void {
|
||||
const all = readDraftsStore()
|
||||
if (text) {
|
||||
// 删后重插把该会话挪到键序末尾,Object 键序=写入序,溢出时从头淘汰即 LRU
|
||||
delete all[convId]
|
||||
all[convId] = text
|
||||
const keys = Object.keys(all)
|
||||
for (let i = 0; i < keys.length - DRAFTS_MAX; i++) delete all[keys[i]]
|
||||
} else {
|
||||
delete all[convId]
|
||||
}
|
||||
try {
|
||||
localStorage.setItem(DRAFTS_KEY, JSON.stringify(all))
|
||||
} catch {
|
||||
// 配额满等:放弃本次落盘,内存草稿不受影响
|
||||
}
|
||||
}
|
||||
|
||||
// 防抖落盘:逐键写盘不必要,300ms 静默期合并;发送/清空/切会话/卸载走立即落盘收口
|
||||
let draftPersistTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function persistDraftNow(): void {
|
||||
if (draftPersistTimer) {
|
||||
clearTimeout(draftPersistTimer)
|
||||
draftPersistTimer = null
|
||||
}
|
||||
const convId = store.state.activeConversationId
|
||||
if (convId) persistDraft(convId, inputText.value)
|
||||
}
|
||||
|
||||
watch(inputText, () => {
|
||||
if (draftPersistTimer) clearTimeout(draftPersistTimer)
|
||||
draftPersistTimer = setTimeout(persistDraftNow, 300)
|
||||
})
|
||||
|
||||
// F2-2:卸载(面板收起/关窗)前冲刷在途防抖,防最后 300ms 键入的草稿丢失
|
||||
onBeforeUnmount(() => {
|
||||
if (draftPersistTimer) persistDraftNow()
|
||||
})
|
||||
|
||||
watch(() => store.state.activeConversationId, (nv, ov) => {
|
||||
if (ov) setConvDraft(ov, inputText.value)
|
||||
// immediate:挂载时活跃会话已就位(分离窗/恢复会话直开)也走恢复链,不只在切换时
|
||||
if (ov) {
|
||||
setConvDraft(ov, inputText.value)
|
||||
persistDraft(ov, inputText.value)
|
||||
}
|
||||
inputText.value = getConvDraft(nv)
|
||||
// 内存 Map 无记录时回退落盘稿(重启后 Map 为空;同会话内 Map 恒比落盘新,优先)
|
||||
if (!inputText.value && nv) {
|
||||
const persisted = readDraftsStore()[nv]
|
||||
if (typeof persisted === 'string') inputText.value = persisted
|
||||
}
|
||||
// 随输入框的临时态不跨会话携带:mention 区间偏移只对旧文本有效,照搬到恢复的文本会渲染错位
|
||||
// chip;技能 chip 与待发图片同理,残留到新会话会静默混入下一条消息
|
||||
pendingMentionSpans.value = []
|
||||
@@ -1205,7 +1298,7 @@ watch(() => store.state.activeConversationId, (nv, ov) => {
|
||||
mentionStart.value = -1
|
||||
autoResize()
|
||||
})
|
||||
})
|
||||
}, { immediate: true })
|
||||
|
||||
// ── 脉络卡「带入上下文」外部投递:以输入框实时内容为基底追加(草稿 Map 不含键入
|
||||
// 过程,直接写 Map 会丢当前输入),一次性消费防重放;追加后聚焦输入框由用户决断 ──
|
||||
@@ -1259,32 +1352,33 @@ defineExpose({
|
||||
零视觉变更。原 AiChat scoped 不渗透子组件根,输入框/技能联想/发送按钮元素失配 → 本组件自持。
|
||||
CSS 变量(--df-*)由根级 global.css 提供,共享同一份。.ai-input-area 容器留父级 AiChat scoped。) ═══ -->
|
||||
<style scoped>
|
||||
/* 2026-10-18 wave2: 输入盒迁移 workbench .inp-box 范式——bg-card 底+0.5px 边框+9px 圆角,
|
||||
focus-within 边框转 info;纵向布局让全宽图片预览行自然换行(替代原 flex-wrap 手法) */
|
||||
.ai-input-wrap {
|
||||
position: relative;
|
||||
display: flex;
|
||||
/* F-260614-05 Phase 2b: flex-wrap 让全宽的图片预览行强制 textarea+按钮换行到下一行 */
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-direction: column;
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-lg);
|
||||
padding: 6px 8px;
|
||||
border-radius: 9px;
|
||||
padding: 9px 12px;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
|
||||
/* F-260614-05 Phase 2b: 图片预览样式已提取到 styles/components.css 全局(ImageInput.vue 共享) */
|
||||
|
||||
.ai-input-wrap:focus-within {
|
||||
border-color: color-mix(in srgb, var(--df-accent) 40%, transparent);
|
||||
border-color: var(--df-info);
|
||||
}
|
||||
|
||||
/* ── 技能 chip / 联想浮层样式已提取到 styles/components.css 全局(SkillMention.vue + MentionPopover.vue 共享)── */
|
||||
|
||||
/* ── UX-10 §1.4: @ 实体引用浮层样式已随 MentionPopover.vue 提取 ── */
|
||||
|
||||
/* textarea 透明无边框占满输入盒首行(workbench .inp-box textarea 范式);
|
||||
autosize 高度参数(min/height/max-height)为行为契约,禁动 */
|
||||
.ai-input {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
border: none;
|
||||
outline: none;
|
||||
@@ -1301,6 +1395,19 @@ defineExpose({
|
||||
.ai-input::placeholder {
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
|
||||
/* 工具行(workbench .inp-row 范式):textarea 下方 --df-border 分隔线,左功能钮+右发送钮 */
|
||||
.ai-input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 6px;
|
||||
padding-top: 6px;
|
||||
border-top: 0.5px solid var(--df-border);
|
||||
}
|
||||
|
||||
/* 发送钮(workbench .isend 范式):info→accent 135° 渐变+深色 icon+600 字重;
|
||||
禁用态 opacity .4(禁用判定逻辑不动)。原 --active 实心紫规则并入基类,类名绑定保留无害 */
|
||||
.ai-send-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -1309,38 +1416,37 @@ defineExpose({
|
||||
height: 28px;
|
||||
border: none;
|
||||
border-radius: var(--df-radius);
|
||||
background: var(--df-bg-raised);
|
||||
color: var(--df-text-dim);
|
||||
background: linear-gradient(135deg, var(--df-info), var(--df-accent));
|
||||
color: color-mix(in srgb, var(--df-bg) 70%, #000);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
transition: filter 0.15s, opacity 0.15s;
|
||||
flex-shrink: 0;
|
||||
margin-left: auto;
|
||||
}
|
||||
.ai-send-btn:not(:disabled):hover {
|
||||
filter: brightness(1.1);
|
||||
}
|
||||
/* 功能钮统一 28px 高 bg-card 边框钮(workbench 工具行左侧范式),hover 边框亮 */
|
||||
.ai-img-pick-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border: none;
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
background: transparent;
|
||||
background: var(--df-bg-card);
|
||||
color: var(--df-text-dim);
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
flex-shrink: 0;
|
||||
margin-right: 4px;
|
||||
}
|
||||
.ai-img-pick-btn:hover {
|
||||
background: var(--df-bg-raised);
|
||||
background: var(--df-bg-card-hover);
|
||||
border-color: var(--df-border-strong);
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ai-send-btn--active {
|
||||
background: var(--df-accent);
|
||||
color: #fff;
|
||||
}
|
||||
.ai-send-btn--active:hover {
|
||||
background: var(--df-accent-hover);
|
||||
}
|
||||
.ai-send-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
@@ -1364,20 +1470,34 @@ defineExpose({
|
||||
.ai-send-btn--retry:hover {
|
||||
background: #d63a3f;
|
||||
}
|
||||
/* 命令提示 chip(workbench .icmd 范式):mono 10px --df-text-dim */
|
||||
.ai-input-hint {
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
text-align: right;
|
||||
margin-top: 4px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
/* ── ⑥.4 Phase 4: @项目展开摘要样式已随 EnrichmentPanel.vue 提取 ── */
|
||||
|
||||
/* B1: 非视觉模型贴图警示条(待发送图片预览行下方,warning 色轻量提示,不抢输入框注意力) */
|
||||
.ai-img-warn-chip {
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-warning);
|
||||
padding: 1px 4px;
|
||||
}
|
||||
|
||||
/* ── 2026-10-18 wave2: 草稿/mention 弹层对齐 workbench 弹层范式 ──
|
||||
SkillMention/MentionPopover 共用 styles/components.css 的 .ai-skill-* 全局基类(禁碰),
|
||||
经 :deep 在此集中覆写一份(两子组件弹层同源,避免各自 scoped 重复):
|
||||
8px 圆角+浅阴影;选中项 bg-card-hover+左 2px 强调边(inset 阴影实现,零布局位移) */
|
||||
.ai-input-wrap :deep(.ai-skill-popover) {
|
||||
border-radius: var(--df-radius-md);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
}
|
||||
.ai-input-wrap :deep(.ai-skill-item--active) {
|
||||
background: var(--df-bg-card-hover);
|
||||
box-shadow: inset 2px 0 0 var(--df-accent);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -104,16 +104,16 @@ watch(
|
||||
|
||||
<style scoped>
|
||||
.conflict-resolver {
|
||||
border: 1px solid var(--df-warning, #ffc107);
|
||||
border: 1px solid var(--df-warning);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
margin: 8px 0;
|
||||
background: var(--df-bg-secondary);
|
||||
background: var(--df-bg-card);
|
||||
}
|
||||
.conflict-header {
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: var(--df-warning, #ffc107);
|
||||
color: var(--df-warning);
|
||||
}
|
||||
.conflict-item {
|
||||
border-top: 1px solid var(--df-border);
|
||||
@@ -153,8 +153,8 @@ watch(
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.badge--file { background: rgba(255, 193, 7, 0.15); color: #ffc107; }
|
||||
.badge--semantic { background: rgba(220, 53, 69, 0.15); color: #dc3545; }
|
||||
.badge--file { background: var(--df-warning-bg); color: var(--df-warning); }
|
||||
.badge--semantic { background: var(--df-danger-bg); color: var(--df-danger); }
|
||||
.conflict-file code { font-size: 12px; color: var(--df-text); }
|
||||
.conflict-diffs {
|
||||
display: grid;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<!-- 脉络卡:同项目近期决策摘要,纯读侧。用户点「带入上下文」向输入框投递追加文本,
|
||||
由用户编辑后自行发送——注入决策权在用户,不触碰 L3 召回铁律。 -->
|
||||
由用户编辑后自行发送——注入决策权在用户,不触碰 L3 召回铁律。
|
||||
有源会话的条目标题可点跳回原文,空源或跳转失败静默不打断阅读。 -->
|
||||
<div class="ctx-briefs">
|
||||
<button
|
||||
class="ctx-briefs-toggle"
|
||||
@@ -19,9 +20,19 @@
|
||||
<div v-if="loading" class="ctx-briefs-empty">{{ t('aiChat.contextBriefsLoading') }}</div>
|
||||
<div v-else-if="groups.length === 0" class="ctx-briefs-empty">{{ t('aiChat.contextBriefsEmpty') }}</div>
|
||||
<div v-for="g in groups" v-else :key="g.source_project" class="ctx-briefs-group">
|
||||
<div class="ctx-briefs-project">{{ g.source_project }}</div>
|
||||
<div class="ctx-briefs-project">
|
||||
<span v-if="g.focused" class="ctx-briefs-focus-dot" />{{ g.source_project }}
|
||||
</div>
|
||||
<div v-for="b in g.briefs" :key="g.source_project + b.title" class="ctx-briefs-item">
|
||||
<div class="ctx-briefs-item-title">{{ b.title }}</div>
|
||||
<div class="ctx-briefs-item-head">
|
||||
<button
|
||||
v-if="b.source_conv"
|
||||
class="ctx-briefs-item-title ctx-briefs-item-link"
|
||||
@click="openSource(b)"
|
||||
>{{ b.title }}</button>
|
||||
<span v-else class="ctx-briefs-item-title">{{ b.title }}</span>
|
||||
<span class="ctx-briefs-item-time">{{ formatRelative(b.updated_at) }}</span>
|
||||
</div>
|
||||
<div class="ctx-briefs-item-summary">{{ b.summary }}</div>
|
||||
<button
|
||||
class="ctx-briefs-bring"
|
||||
@@ -35,26 +46,32 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { aiApi } from '../../api/ai'
|
||||
import { useAiStore } from '../../stores/ai'
|
||||
import { pushConvDraftAppend } from '../../composables/ai/aiShared'
|
||||
import { useAiConversations } from '../../composables/ai/useAiConversations'
|
||||
import { formatRelative } from '../../utils/time'
|
||||
|
||||
interface ContextBrief {
|
||||
title: string
|
||||
summary: string
|
||||
source_ref: string | null
|
||||
source_conv: string | null
|
||||
source_project: string | null
|
||||
reuse_count: number
|
||||
updated_at: string
|
||||
}
|
||||
interface ProjectBriefs {
|
||||
source_project: string
|
||||
focused?: boolean
|
||||
briefs: ContextBrief[]
|
||||
}
|
||||
|
||||
const { t } = useI18n()
|
||||
const store = useAiStore()
|
||||
const { openConversation } = useAiConversations()
|
||||
|
||||
const expanded = ref(false)
|
||||
const loading = ref(false)
|
||||
@@ -62,17 +79,39 @@ const groups = ref<ProjectBriefs[]>([])
|
||||
|
||||
const totalBriefs = computed(() => groups.value.reduce((n, g) => n + g.briefs.length, 0))
|
||||
|
||||
/** 拉取脉络,按当前会话标注聚焦分组;会话已切走时丢弃过期响应(防旧 focused 污染新列表) */
|
||||
async function load() {
|
||||
const convId = store.state.activeConversationId ?? undefined
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await aiApi.listContextBriefs(undefined, convId)
|
||||
if ((store.state.activeConversationId ?? undefined) === convId) groups.value = result
|
||||
} catch {
|
||||
if ((store.state.activeConversationId ?? undefined) === convId) groups.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle() {
|
||||
expanded.value = !expanded.value
|
||||
if (expanded.value && groups.value.length === 0) {
|
||||
loading.value = true
|
||||
try {
|
||||
groups.value = await aiApi.listContextBriefs()
|
||||
} catch {
|
||||
groups.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
if (expanded.value && groups.value.length === 0) await load()
|
||||
}
|
||||
|
||||
/** 切会话重新拉取(focused 跟随当前会话);收起态只清缓存,保持按需加载 */
|
||||
watch(() => store.state.activeConversationId, () => {
|
||||
groups.value = []
|
||||
if (expanded.value) void load()
|
||||
})
|
||||
|
||||
/** 跳回摘要来源会话(source_conv 由后端自 source_ref 解析,消息级引用已反查);
|
||||
* 源为空或已删除(not_found)一律静默,不加 toast */
|
||||
async function openSource(b: ContextBrief) {
|
||||
if (!b.source_conv) return
|
||||
try {
|
||||
await openConversation(b.source_conv)
|
||||
} catch {
|
||||
// 静默:跳转失败不打断阅读
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +125,10 @@ function bringIn(g: ProjectBriefs, b: ContextBrief) {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* wave2(2026-10-18):旧 token 全量迁 --df-*;统一透明彩底卡范式,accent 系(脉络=系统功能信号)
|
||||
——边框 color-mix 30% + 底 6% + 标题同色 12px/600 + 正文 secondary 12px + 透明底描边钮 */
|
||||
.ctx-briefs {
|
||||
border-bottom: 1px solid var(--border, #e0e0e0);
|
||||
border-bottom: 0.5px solid var(--df-border);
|
||||
padding: 4px 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -99,54 +140,94 @@ function bringIn(g: ProjectBriefs, b: ContextBrief) {
|
||||
padding: 3px 2px;
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--text-secondary, #666);
|
||||
cursor: pointer;
|
||||
color: var(--df-accent);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ctx-briefs-count {
|
||||
background: var(--accent-soft, rgba(64, 128, 255, 0.15));
|
||||
color: var(--accent, #4080ff);
|
||||
border-radius: 8px;
|
||||
background: var(--df-accent-soft);
|
||||
color: var(--df-accent);
|
||||
border-radius: var(--df-radius-md);
|
||||
padding: 0 6px;
|
||||
font-size: 11px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.ctx-briefs-body {
|
||||
max-height: 220px;
|
||||
overflow-y: auto;
|
||||
padding-bottom: 4px;
|
||||
padding: 6px 8px;
|
||||
background: color-mix(in srgb, var(--df-accent) 6%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-accent) 30%, transparent);
|
||||
border-radius: var(--df-radius);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.ctx-briefs-empty {
|
||||
color: var(--text-tertiary, #999);
|
||||
color: var(--df-text-dim);
|
||||
padding: 6px 2px;
|
||||
}
|
||||
.ctx-briefs-project {
|
||||
font-weight: 600;
|
||||
color: var(--text-primary, #333);
|
||||
color: var(--df-text);
|
||||
font-size: 12px;
|
||||
padding: 5px 2px 2px;
|
||||
}
|
||||
.ctx-briefs-focus-dot {
|
||||
display: inline-block;
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
margin-right: 4px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-accent);
|
||||
vertical-align: 2px;
|
||||
}
|
||||
.ctx-briefs-item {
|
||||
padding: 4px 2px;
|
||||
border-top: 1px dashed var(--border, #eee);
|
||||
border-top: 0.5px dashed var(--df-border);
|
||||
}
|
||||
.ctx-briefs-item-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
}
|
||||
.ctx-briefs-item-title {
|
||||
font-weight: 500;
|
||||
color: var(--text-primary, #333);
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ctx-briefs-item-link {
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: none;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ctx-briefs-item-link:hover {
|
||||
color: var(--df-accent);
|
||||
}
|
||||
.ctx-briefs-item-time {
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
font-family: var(--df-font-mono);
|
||||
}
|
||||
.ctx-briefs-item-summary {
|
||||
color: var(--text-secondary, #666);
|
||||
color: var(--df-text-secondary);
|
||||
font-size: 12px;
|
||||
margin: 2px 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.ctx-briefs-bring {
|
||||
border: 1px solid var(--border, #ddd);
|
||||
background: none;
|
||||
color: var(--accent, #4080ff);
|
||||
border-radius: 4px;
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-accent) 40%, transparent);
|
||||
background: transparent;
|
||||
color: var(--df-accent);
|
||||
border-radius: var(--df-radius-sm);
|
||||
padding: 1px 8px;
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ctx-briefs-bring:hover {
|
||||
background: var(--accent-soft, rgba(64, 128, 255, 0.1));
|
||||
background: var(--df-accent-soft);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -52,6 +52,18 @@
|
||||
@keydown="onItemKeydown($event, conv.id, true)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2 u-agent 范式: 左侧 7px 状态点。字段源 store.isGenerating(conv_state
|
||||
generating/stopping/compressed) / pendingCountOf(审批挂起) / loop_state='parked',
|
||||
无 error 字段故不映射;优先级 generating > 待审批 > parked > 灰 -->
|
||||
<span
|
||||
class="df-dot ai-conv-status"
|
||||
:class="store.isGenerating(conv.id) ? 'df-dot--run ai-conv-status--run'
|
||||
: pendingCountOf(conv.id) > 0 ? 'ai-conv-status--danger'
|
||||
: conv.loop_state === 'parked' ? 'ai-conv-status--paused'
|
||||
: 'df-dot--stop'"
|
||||
:title="store.isGenerating(conv.id) ? t('aiChat.generating') : undefined"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
<!-- UX走查 P3-1: 搜索态此前无重命名入口(无 startRename 分支),与分组视图降级不一致;
|
||||
双击入口对齐分组视图,菜单入口供键盘用户(P2-6) -->
|
||||
<input
|
||||
@@ -70,7 +82,6 @@
|
||||
@dblclick.stop="startRename(conv)"
|
||||
>
|
||||
{{ conv.title || t('aiChat.newConversation') }}
|
||||
<span v-if="store.isGenerating(conv.id)" class="ai-conv-gen-dot" :title="t('aiChat.generating')"></span>
|
||||
<!-- V1: 待审批徽标(橙点计数,复用既有 aiChat.pendingApprovalCount 文案) -->
|
||||
<span v-if="pendingCountOf(conv.id) > 0" class="ai-conv-approve-badge" :title="t('aiChat.pendingApprovalCount', { n: pendingCountOf(conv.id) })">{{ pendingCountOf(conv.id) }}</span>
|
||||
<!-- 无人值守边界徽标:该会话已授权任务边界(镜像渐进填充);点击随会话切回显 -->
|
||||
@@ -145,6 +156,16 @@
|
||||
@keydown="onItemKeydown($event, conv.id, true)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2 u-agent 范式: 左侧 7px 状态点(映射源同搜索态块注) -->
|
||||
<span
|
||||
class="df-dot ai-conv-status"
|
||||
:class="store.isGenerating(conv.id) ? 'df-dot--run ai-conv-status--run'
|
||||
: pendingCountOf(conv.id) > 0 ? 'ai-conv-status--danger'
|
||||
: conv.loop_state === 'parked' ? 'ai-conv-status--paused'
|
||||
: 'df-dot--stop'"
|
||||
:title="store.isGenerating(conv.id) ? t('aiChat.generating') : undefined"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
<input
|
||||
v-if="editingConvId === conv.id"
|
||||
:ref="setEditEl"
|
||||
@@ -168,8 +189,6 @@
|
||||
class="ai-conv-item-title-badge"
|
||||
width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"
|
||||
><polyline points="20 6 9 17 4 12"/></svg>
|
||||
<!-- F-09: 多会话并发生成指示器(后台/当前会话生成中均显脉冲点,多会话可同时显示) -->
|
||||
<span v-if="store.isGenerating(conv.id)" class="ai-conv-gen-dot" :title="t('aiChat.generating')"></span>
|
||||
<!-- V1: 待审批徽标(橙点计数,复用既有 aiChat.pendingApprovalCount 文案) -->
|
||||
<span v-if="pendingCountOf(conv.id) > 0" class="ai-conv-approve-badge" :title="t('aiChat.pendingApprovalCount', { n: pendingCountOf(conv.id) })">{{ pendingCountOf(conv.id) }}</span>
|
||||
<!-- 无人值守边界徽标:该会话已授权任务边界(镜像渐进填充);点击随会话切回显 -->
|
||||
@@ -225,6 +244,8 @@
|
||||
@keydown.space.prevent="onRecover(conv.id)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2: 本组数据源 ai_list_recoverable(loop_state='parked' 完备真相),整组恒 parked→静态琥珀点 -->
|
||||
<span class="df-dot ai-conv-status ai-conv-status--paused" aria-hidden="true"></span>
|
||||
<span class="ai-conv-item-title">
|
||||
{{ conv.title || t('aiChat.newConversation') }}
|
||||
<span class="ai-conv-recover-badge">⏸</span>
|
||||
@@ -260,9 +281,18 @@
|
||||
@keydown="onItemKeydown($event, conv.id)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2 u-agent 范式: 归档项同款状态点(归档为静息态,默认落灰) -->
|
||||
<span
|
||||
class="df-dot ai-conv-status"
|
||||
:class="store.isGenerating(conv.id) ? 'df-dot--run ai-conv-status--run'
|
||||
: pendingCountOf(conv.id) > 0 ? 'ai-conv-status--danger'
|
||||
: conv.loop_state === 'parked' ? 'ai-conv-status--paused'
|
||||
: 'df-dot--stop'"
|
||||
:title="store.isGenerating(conv.id) ? t('aiChat.generating') : undefined"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
<span class="ai-conv-item-title" :title="conv.title || ''">
|
||||
{{ conv.title || t('aiChat.newConversation') }}
|
||||
<span v-if="store.isGenerating(conv.id)" class="ai-conv-gen-dot" :title="t('aiChat.generating')"></span>
|
||||
<!-- V1: 待审批徽标(橙点计数,复用既有 aiChat.pendingApprovalCount 文案) -->
|
||||
<span v-if="pendingCountOf(conv.id) > 0" class="ai-conv-approve-badge" :title="t('aiChat.pendingApprovalCount', { n: pendingCountOf(conv.id) })">{{ pendingCountOf(conv.id) }}</span>
|
||||
<!-- 无人值守边界徽标:该会话已授权任务边界(镜像渐进填充);点击随会话切回显 -->
|
||||
@@ -296,6 +326,17 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- F4-1: 会话列表分页——底部「加载更多」续拉下一页(首屏 50/组,归档组同口径放开) -->
|
||||
<div
|
||||
v-if="convListPaging.hasMore"
|
||||
class="ai-conv-load-more"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@click="onLoadMore"
|
||||
@keydown.enter.prevent="onLoadMore"
|
||||
@keydown.space.prevent="onLoadMore"
|
||||
>{{ convListPaging.loading ? t('common.loading') : t('gitChanges.loadMore') }}</div>
|
||||
|
||||
<div v-if="store.state.conversations.length === 0" class="ai-conv-empty">
|
||||
{{ t('aiChat.emptyConversation') }}
|
||||
</div>
|
||||
@@ -338,7 +379,8 @@ import { convPendingApprovals } from '../../composables/ai/aiShared'
|
||||
// 镜像由边界配置卡在切会话/写入时渐进填充,无批量 IPC 属契约限制)
|
||||
import { getConvBoundary, fetchConvBoundary } from '../../composables/ai/useTaskBoundary'
|
||||
// UX走查 P2-7 只读订阅:rename/archive/pin 失败通知由 useAiConversations 发布,本组件弹就近 toast
|
||||
import { convOpFailNotice } from '../../composables/ai/useAiConversations'
|
||||
// F4-1: 会话列表分页游标(reactive,绑「加载更多」显隐/loading)+ 续拉/拉满动作
|
||||
import { convOpFailNotice, convListPaging, loadMoreConversations, loadAllConversations } from '../../composables/ai/useAiConversations'
|
||||
import { useToast } from '../../composables/useToast'
|
||||
import { formatRelative } from '../../utils/time'
|
||||
import type { AiConversationSummary } from '../../api/types'
|
||||
@@ -662,6 +704,28 @@ const searchResults = computed<AiConversationSummary[] | null>(
|
||||
() => store.filteredConversations.value,
|
||||
)
|
||||
|
||||
// ── F4-1: 会话列表分页(加载更多按钮 + 搜索全量兜底) ──
|
||||
|
||||
/** 「加载更多」:续拉下一页(失败/无新增静默,按钮 loading 态由 convListPaging 驱动) */
|
||||
function onLoadMore(): void {
|
||||
void loadMoreConversations()
|
||||
}
|
||||
|
||||
// 搜索输入即拉满:搜索过滤(stores.filteredConversations)跑在已加载列表上,未拉满时
|
||||
// 第 51 条起的会话搜不到(硬 50 截断=搜索失灵)——输入非空且还有未拉页时一次拉尽,
|
||||
// 之后搜索自然覆盖全量;已拉满(hasMore=false)零开销不触发。
|
||||
watch(() => store.state.searchQuery, (q) => {
|
||||
if (q.trim() && convListPaging.hasMore && !convListPaging.loading) {
|
||||
void loadAllConversations()
|
||||
}
|
||||
})
|
||||
|
||||
// 加载更多/搜索拉满追加的新会话补拉边界徽标镜像(A10 空洞随列表加深扩大;
|
||||
// hydrate 对已入镜像的会话跳过,常规刷新时零 IPC)
|
||||
watch(() => store.state.conversations.length, () => {
|
||||
void hydrateBoundaryBadges()
|
||||
})
|
||||
|
||||
// ── 侧栏宽度拖拽 ──
|
||||
const resizeState = { startX: 0, startWidth: 0 }
|
||||
function onResizeMove(e: MouseEvent) {
|
||||
@@ -756,7 +820,7 @@ defineExpose({
|
||||
transition: background 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-sidebar-resize-handle:hover {
|
||||
background: var(--df-accent, #4f8cff);
|
||||
background: var(--df-accent);
|
||||
opacity: 0.5;
|
||||
}
|
||||
/* 拖拽中全局锁 cursor + 禁选中文本(挂在 body 上,跨元素生效) */
|
||||
@@ -773,18 +837,26 @@ body.ai-sidebar-resizing * {
|
||||
border-bottom: 0.5px solid var(--df-border);
|
||||
}
|
||||
.ai-conv-sidebar-title {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--df-text);
|
||||
}
|
||||
|
||||
/* UX-06 §3.1: 对话搜索框(紧贴 header 下,样式跟随周围输入控件) */
|
||||
/* UX-06 §3.1: 对话搜索框(wave2 u-agent .sb-search 范式:容器成框,卡底+focus 边框 info) */
|
||||
.ai-conv-search {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 6px 10px;
|
||||
border-bottom: 0.5px solid var(--df-border);
|
||||
margin: 8px 10px;
|
||||
padding: 0 8px;
|
||||
height: 30px;
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
transition: border-color 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-conv-search:focus-within {
|
||||
border-color: var(--df-info);
|
||||
}
|
||||
.ai-conv-search-icon {
|
||||
flex: none;
|
||||
@@ -800,8 +872,8 @@ body.ai-sidebar-resizing * {
|
||||
font-size: 12px;
|
||||
color: var(--df-text);
|
||||
}
|
||||
/* 聚焦可见环:无边框输入聚焦无变化,且 scoped 选择器特异性高于全局 :focus-visible 兜底,须就地补环,仅键盘聚焦显示 */
|
||||
.ai-conv-search-input:focus-visible { outline: 2px solid var(--df-accent); outline-offset: 1px; }
|
||||
/* 聚焦可见环:容器已随 :focus-within 变 info 边框,键盘环同色补强(scoped 特异性须盖全局兜底) */
|
||||
.ai-conv-search-input:focus-visible { outline: 2px solid var(--df-info); outline-offset: 1px; }
|
||||
.ai-conv-search-input::placeholder {
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
@@ -819,12 +891,15 @@ body.ai-sidebar-resizing * {
|
||||
.ai-conv-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 4px;
|
||||
padding: 4px 6px; /* u-agent .sb-list 范式;滚动条走 global ::-webkit-scrollbar token 体系 */
|
||||
}
|
||||
/* wave2 u-agent 范式: 分组头 10px uppercase + letter-spacing 1px + dim */
|
||||
.ai-conv-group-title {
|
||||
padding: 8px 8px 3px;
|
||||
padding: 10px 8px 4px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
color: var(--df-text-dim);
|
||||
user-select: none;
|
||||
}
|
||||
@@ -851,7 +926,10 @@ body.ai-sidebar-resizing * {
|
||||
.ai-conv-group-count {
|
||||
margin-left: 2px;
|
||||
font-weight: 400;
|
||||
opacity: 0.7;
|
||||
font-family: var(--df-font-mono); /* mono 计数(df-mono 范式),upper/lsp 回退保证数字不散 */
|
||||
font-size: 10px;
|
||||
letter-spacing: 0;
|
||||
opacity: 0.9;
|
||||
}
|
||||
.ai-conv-group-empty {
|
||||
padding: 2px 8px 4px 20px;
|
||||
@@ -859,40 +937,48 @@ body.ai-sidebar-resizing * {
|
||||
color: var(--df-text-dim);
|
||||
font-style: italic;
|
||||
}
|
||||
/* wave2 u-agent .cv 范式: 单行条目,8px 级密度;hover/active 同走灰阶卡底(GitHub 两级同底、
|
||||
active 由左 2px accent 实线区分),深浅主题同 token 自动适配 */
|
||||
.ai-conv-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 6px 8px;
|
||||
padding: 8px;
|
||||
border-radius: var(--df-radius);
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
gap: 4px;
|
||||
gap: 6px;
|
||||
}
|
||||
.ai-conv-item:hover {
|
||||
background: var(--df-sidebar-hover);
|
||||
background: var(--df-bg-card-hover);
|
||||
}
|
||||
.ai-conv-item--active {
|
||||
background: var(--df-sidebar-active);
|
||||
background: var(--df-bg-card-hover);
|
||||
box-shadow: inset 2px 0 0 var(--df-accent);
|
||||
}
|
||||
/* 切换进行时(UX走查 P1):与活跃项同底色示"已选中"(乐观预高亮),降不透明度示"加载中";
|
||||
IPC 返回后 activeConversationId 落定、本类移除,视觉无缝衔接;失败回滚高亮回原活跃项 */
|
||||
.ai-conv-item--switching {
|
||||
background: var(--df-sidebar-active);
|
||||
background: var(--df-bg-card-hover);
|
||||
opacity: 0.7;
|
||||
}
|
||||
.ai-conv-item--archived .ai-conv-item-title {
|
||||
opacity: 0.6;
|
||||
}
|
||||
/* wave2: 行内布局对齐 .cv-top([状态点][标题省略][时间]) */
|
||||
.ai-conv-item-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.ai-conv-item-title {
|
||||
font-size: 11px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--df-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
@@ -901,7 +987,6 @@ body.ai-sidebar-resizing * {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
}
|
||||
/* UX-2025-20 §7.4: AI 生成标题淡入(0.3s opacity + transform 过渡) */
|
||||
.ai-conv-item-title--flash {
|
||||
@@ -916,34 +1001,35 @@ body.ai-sidebar-resizing * {
|
||||
to { opacity: 1; transform: translateX(0); }
|
||||
}
|
||||
.ai-conv-item-edit {
|
||||
flex: 1 1 0; /* wave2: main 已行化,输入框按 flex 填充(min-width:0 防 input 固有宽撑破窄侧栏) */
|
||||
min-width: 0;
|
||||
width: auto;
|
||||
font-size: 11px;
|
||||
color: var(--df-text);
|
||||
width: 100%;
|
||||
height: 18px;
|
||||
padding: 0 4px;
|
||||
border: 1px solid var(--df-accent);
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: var(--df-bg, #fff);
|
||||
background: var(--df-bg);
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
/* 聚焦可见环:边框恒为 accent 聚焦无变化,且 scoped 选择器特异性高于全局 :focus-visible 兜底,须就地补环,仅键盘聚焦显示 */
|
||||
.ai-conv-item-edit:focus-visible { outline: 2px solid var(--df-accent); outline-offset: 1px; }
|
||||
/* wave2 u-agent 范式: 时间/计数元数据 mono 10px dim(.df-mono 同款视觉) */
|
||||
.ai-conv-item-time {
|
||||
font-size: 9px;
|
||||
flex: none;
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* 多会话并发生成指示器(会话项标题行内脉冲点,多会话可同时显示) */
|
||||
.ai-conv-gen-dot {
|
||||
display: inline-block;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-accent);
|
||||
flex-shrink: 0;
|
||||
animation: ai-conv-gen-pulse 1.4s ease-in-out infinite;
|
||||
}
|
||||
/* wave2 u-agent .st 状态点变体: 公共 .df-dot/.df-dot--run/.df-dot--stop 管造型与绿/灰底,
|
||||
此处只补动效与缺位色(全 token): run 绿+glow+脉冲(global df-pulse)、danger 待审批红、paused 停靠琥珀 */
|
||||
.ai-conv-status--run { box-shadow: 0 0 6px var(--df-success); animation: df-pulse 1.5s infinite; }
|
||||
.ai-conv-status--danger { background: var(--df-danger); }
|
||||
.ai-conv-status--paused { background: var(--df-warning); }
|
||||
@keyframes ai-conv-gen-pulse {
|
||||
/* 供 .ai-conv-recover-dot 分组级脉冲用(原行内 gen-dot 已由状态点接管) */
|
||||
0%, 100% { opacity: 0.35; transform: scale(0.85); }
|
||||
50% { opacity: 1; transform: scale(1.15); }
|
||||
}
|
||||
@@ -954,7 +1040,7 @@ body.ai-sidebar-resizing * {
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
margin-right: 5px;
|
||||
background: var(--df-warning, #f0c75e);
|
||||
background: var(--df-warning);
|
||||
animation: ai-conv-gen-pulse 2s ease-in-out infinite;
|
||||
}
|
||||
.ai-conv-item--recoverable {
|
||||
@@ -965,7 +1051,7 @@ body.ai-sidebar-resizing * {
|
||||
margin-left: 2px;
|
||||
font-size: 10px;
|
||||
line-height: 1;
|
||||
color: var(--df-warning, #f0c75e);
|
||||
color: var(--df-warning);
|
||||
cursor: help;
|
||||
}
|
||||
/* V1: 跨会话待审批徽标(橙点计数,warning 色系与待审批语义一致;固定尺寸不挤标题换行) */
|
||||
@@ -974,7 +1060,7 @@ body.ai-sidebar-resizing * {
|
||||
height: 12px;
|
||||
padding: 0 3px;
|
||||
border-radius: 6px;
|
||||
background: var(--df-warning, #f0c75e);
|
||||
background: var(--df-warning);
|
||||
color: #000;
|
||||
font-size: 9px;
|
||||
font-weight: 600;
|
||||
@@ -1031,9 +1117,13 @@ body.ai-sidebar-resizing * {
|
||||
color: var(--df-text);
|
||||
}
|
||||
/* 已置顶对话视觉强调(左边线,不依赖菜单展开,一眼识别)。
|
||||
pinned 类挂在 .ai-conv-item 上(操作收进更多菜单后,按钮不再常驻,改 item 级类)。 */
|
||||
pinned 类挂在 .ai-conv-item 上(操作收进更多菜单后,按钮不再常驻,改 item 级类)。
|
||||
wave2: 选中态同占左缘,置顶线降为 45% 透明 accent 让位,选中实线优先 */
|
||||
.ai-conv-item--pinned {
|
||||
box-shadow: inset 2px 0 0 var(--df-accent, var(--df-text));
|
||||
box-shadow: inset 2px 0 0 color-mix(in srgb, var(--df-accent) 45%, transparent);
|
||||
}
|
||||
.ai-conv-item--active.ai-conv-item--pinned {
|
||||
box-shadow: inset 2px 0 0 var(--df-accent);
|
||||
}
|
||||
/* ── 「更多」操作菜单(置顶/归档/删除)──
|
||||
「...」按钮 hover 时随 actions 浮出(同原 4 按钮交互),点击展开下拉。
|
||||
@@ -1055,8 +1145,8 @@ body.ai-sidebar-resizing * {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
background: var(--df-bg, #fff);
|
||||
border: 1px solid var(--df-border, #e2e2e2);
|
||||
background: var(--df-bg);
|
||||
border: 1px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
@@ -1087,6 +1177,21 @@ body.ai-sidebar-resizing * {
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* F4-1: 列表底部「加载更多」(轻量文字行,hover 同列表项灰阶卡底范式) */
|
||||
.ai-conv-load-more {
|
||||
margin: 4px 2px;
|
||||
padding: 6px 8px;
|
||||
border-radius: var(--df-radius);
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
.ai-conv-load-more:hover {
|
||||
background: var(--df-bg-card-hover);
|
||||
color: var(--df-text);
|
||||
}
|
||||
|
||||
/* UX走查 P2-7: 会话操作失败就近 toast(仅 error 一型)。视觉对齐 AiChat .ai-toast,
|
||||
但 AiChat 版是 scoped 样式渗透不进来,故自持一份;侧栏窄,max-width 收 85% */
|
||||
@@ -1101,7 +1206,7 @@ body.ai-sidebar-resizing * {
|
||||
z-index: 30; /* 高于操作菜单(20),菜单展开时失败反馈不被盖 */
|
||||
max-width: 85%;
|
||||
overflow-wrap: anywhere;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
background: var(--df-danger-bg);
|
||||
color: var(--df-danger);
|
||||
border: 0.5px solid var(--df-danger);
|
||||
|
||||
@@ -154,12 +154,12 @@ watch(() => visibleDirAuths.value.map(d => d.id).join('|'), async () => {
|
||||
border-radius: var(--df-radius);
|
||||
}
|
||||
.ai-dir-auth-text {
|
||||
font-size: 11.5px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--df-warning);
|
||||
}
|
||||
.ai-dir-auth-hint {
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.9;
|
||||
word-break: break-all;
|
||||
|
||||
@@ -34,7 +34,7 @@ const examplePrompts = [
|
||||
<div class="ai-empty">
|
||||
<template v-if="!hasProvider">
|
||||
<div class="ai-empty-icon">
|
||||
<svg aria-hidden="true" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="var(--df-warning)" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
|
||||
<svg aria-hidden="true" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
|
||||
</div>
|
||||
<p class="ai-empty-text">{{ $t('aiChat.emptyNoProvider') }}</p>
|
||||
<p class="ai-empty-sub">{{ $t('aiChat.emptyNoProviderHint') }}</p>
|
||||
@@ -46,7 +46,7 @@ const examplePrompts = [
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="ai-empty-icon">
|
||||
<svg aria-hidden="true" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="var(--df-text-dim)" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2a7 7 0 014 12.74V17a1 1 0 01-1 1H9a1 1 0 01-1-1v-2.26A7 7 0 0112 2z"/><line x1="9" y1="21" x2="15" y2="21"/></svg>
|
||||
<svg aria-hidden="true" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2a7 7 0 014 12.74V17a1 1 0 01-1 1H9a1 1 0 01-1-1v-2.26A7 7 0 0112 2z"/><line x1="9" y1="21" x2="15" y2="21"/></svg>
|
||||
</div>
|
||||
<p class="ai-empty-text">{{ $t('aiChat.emptyTitle') }}</p>
|
||||
<p class="ai-empty-sub">{{ $t('aiChat.emptyHint') }}</p>
|
||||
@@ -73,7 +73,8 @@ const examplePrompts = [
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.ai-empty-icon { margin-bottom: 4px; opacity: 0.4; }
|
||||
/* wave2:空态图标统一 dim 色(经 currentColor 接管 stroke),引导文字 secondary 层级 */
|
||||
.ai-empty-icon { margin-bottom: 4px; opacity: 0.4; color: var(--df-text-dim); }
|
||||
.ai-empty-text {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
@@ -81,7 +82,7 @@ const examplePrompts = [
|
||||
}
|
||||
.ai-empty-sub {
|
||||
font-size: 12px;
|
||||
color: var(--df-text-dim);
|
||||
color: var(--df-text-secondary);
|
||||
text-align: center;
|
||||
line-height: 1.5;
|
||||
}
|
||||
@@ -117,7 +118,7 @@ const examplePrompts = [
|
||||
border-radius: var(--df-radius);
|
||||
background: var(--df-bg-card);
|
||||
color: var(--df-text-secondary);
|
||||
font-size: 11.5px;
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
|
||||
@@ -74,30 +74,30 @@ function handleSelectOption(opt: string): void {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 复用 MaxRoundsCard 样式基调(warning 色系,求助属"需用户介入"信号,视觉一致) */
|
||||
/* wave2(2026-10-18):统一透明彩底卡范式,danger 系(断路器熔断=最高警示级)——
|
||||
边框 color-mix 30% + 底 8% + 标题同色 12px/600 + 正文 secondary 12px + 透明底描边钮 */
|
||||
.ai-help-required {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
margin-bottom: 6px;
|
||||
padding: 6px 8px;
|
||||
background: color-mix(in srgb, var(--df-warning) 10%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-warning) 40%, transparent);
|
||||
background: color-mix(in srgb, var(--df-danger) 8%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-danger) 30%, transparent);
|
||||
border-radius: var(--df-radius);
|
||||
}
|
||||
.ai-help-required-text {
|
||||
font-size: 11.5px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--df-warning);
|
||||
color: var(--df-danger);
|
||||
}
|
||||
.ai-help-required-hint {
|
||||
font-size: 10.5px;
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.9;
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
word-break: break-all;
|
||||
/* M7:context 含错误堆栈,长栈撑高卡片。等宽字体利堆栈行对齐;max-height + overflow-y:auto
|
||||
短内容自动不显滚动条,长堆栈滚动扫看(比折叠实用,无需展开按钮)。 */
|
||||
font-family: var(--df-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
||||
font-family: var(--df-font-mono);
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
@@ -109,15 +109,15 @@ function handleSelectOption(opt: string): void {
|
||||
margin-top: 2px;
|
||||
}
|
||||
.ai-help-required-btn {
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-warning) 60%, transparent);
|
||||
background: var(--df-warning);
|
||||
color: #000;
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-danger) 40%, transparent);
|
||||
background: color-mix(in srgb, var(--df-danger) 10%, transparent);
|
||||
color: var(--df-danger);
|
||||
cursor: pointer;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
padding: 3px 10px;
|
||||
border-radius: calc(var(--df-radius) - 2px);
|
||||
transition: filter 0.15s var(--df-ease);
|
||||
transition: background 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-help-required-btn:hover { filter: brightness(1.1); }
|
||||
.ai-help-required-btn:hover { background: color-mix(in srgb, var(--df-danger) 16%, transparent); }
|
||||
</style>
|
||||
|
||||
@@ -84,7 +84,7 @@ const emit = defineEmits<{
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* 类型标签小色块(项目/任务区分) */
|
||||
/* 类型标签小色块(项目/任务区分)。2026-10-18: 原底色引用未定义 token 静默失效,修正为 bg-card-hover */
|
||||
.ai-mention-item-type {
|
||||
flex-shrink: 0;
|
||||
padding: 1px 5px;
|
||||
@@ -92,7 +92,7 @@ const emit = defineEmits<{
|
||||
font-size: 9px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.3px;
|
||||
background: var(--df-bg-hover);
|
||||
background: var(--df-bg-card-hover);
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
.ai-mention-item-type--project {
|
||||
|
||||
@@ -149,29 +149,34 @@ const imageParts = computed(() => msgImageParts(props.msg))
|
||||
align-items: flex-start;
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
/* 头像通用 */
|
||||
/* 头像通用 — workbench .av 范式:24px 圆角方块渐变,用户 warning→danger 系,
|
||||
字色随主题底色反转保证渐变上对比;内部字符 9px 700(当前为 svg 图标,字号字重为字符兜底) */
|
||||
.ai-msg-avatar {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: var(--df-radius);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
font-size: 9px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.ai-msg-avatar--user {
|
||||
background: var(--df-info-bg, rgba(100,181,246,0.15));
|
||||
color: var(--df-info, #64b5f6);
|
||||
background: linear-gradient(135deg, color-mix(in srgb, var(--df-warning) 70%, var(--df-danger)), var(--df-danger));
|
||||
color: var(--df-bg);
|
||||
}
|
||||
/* 气泡通用 */
|
||||
/* 气泡通用 — workbench 聊天范式:用户气泡=bg-card 底+0.5px 边框+9px 圆角。
|
||||
9px 圆角与 9px 13px 内距均为 u-agent workbench 移植值,勿规整 */
|
||||
.ai-msg-bubble {
|
||||
border-radius: 10px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 9px;
|
||||
padding: 9px 13px;
|
||||
word-break: break-word;
|
||||
max-width: 80%;
|
||||
}
|
||||
.ai-msg-bubble--user {
|
||||
background: var(--df-info-bg, rgba(100,181,246,0.1));
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
color: var(--df-text);
|
||||
}
|
||||
/* chip */
|
||||
@@ -181,13 +186,13 @@ const imageParts = computed(() => msgImageParts(props.msg))
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
margin: 0 2px;
|
||||
background: var(--df-accent-bg, rgba(108,99,255,0.1));
|
||||
color: var(--df-accent, #6c63ff);
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
}
|
||||
/* 技能调用徽章(问题3):与 mention chip 同视觉家族,亮一档紫色底 + ⚡ 前缀区分 */
|
||||
.ai-msg-chip--skill {
|
||||
background: var(--df-accent-bg, rgba(108,99,255,0.18));
|
||||
color: var(--df-accent, #6c63ff);
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
/* 图片 */
|
||||
|
||||
+144
-165
@@ -45,7 +45,7 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const store = useAiStore()
|
||||
const { t } = useI18n()
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
// ── 消息任务关联(有的消息有,有的没):从 toolCalls[].args 派生 ──
|
||||
// 数据源:AiToolCallInfo.args 已携带工具入参,任务工具的 task_id 就在其中
|
||||
@@ -676,23 +676,28 @@ const _decoCache = new Map<string, string>()
|
||||
const DECO_CACHE_LIMIT = 800
|
||||
function decorateCodeHtml(raw: string): string {
|
||||
if (!raw || !raw.includes('<pre><code')) return raw
|
||||
const hit = _decoCache.get(raw)
|
||||
// F1-1:复制按钮文案走 i18n(v-html 渲染层拿不到 $t,经参数注入);locale 入缓存键,
|
||||
// 否则切语言后命中旧缓存,按钮文案停留在旧语言。locale 读取同时建立响应式依赖,
|
||||
// 切语言时调用方(computed/渲染函数)重算拿到新语言装饰结果。
|
||||
const cacheKey = locale.value + '\u0000' + raw
|
||||
const hit = _decoCache.get(cacheKey)
|
||||
if (hit !== undefined) {
|
||||
// LRU:命中即置为最近使用(delete+set 移到 Map 末尾),淘汰时优先保留热项
|
||||
_decoCache.delete(raw)
|
||||
_decoCache.set(raw, hit)
|
||||
_decoCache.delete(cacheKey)
|
||||
_decoCache.set(cacheKey, hit)
|
||||
return hit
|
||||
}
|
||||
// marked 的 code renderer 统一输出 <pre><code class="hljs ...">…</code></pre>
|
||||
//(含缩进码块),代码内容已 HTML 转义,正则非贪婪到首个闭合标签不会越界。
|
||||
// R4 语言角标:code class 形如 hljs language-ts,捕获 language-xxx 输出到 .md-code-block
|
||||
// 的 data-lang,CSS ::after 显示;无语言(裸块/auto 猜测无 language- 类)不显角标。
|
||||
const copyLabel = t('aiChat.copyCode')
|
||||
const out = raw.replace(
|
||||
/<pre><code([^>]*)>([\s\S]*?)<\/code><\/pre>/g,
|
||||
(_m: string, attrs: string, body: string) => {
|
||||
const lang = /language-([a-z0-9+#.-]+)/i.exec(attrs)?.[1] ?? ''
|
||||
const langAttr = lang ? ` data-lang="${lang}"` : ''
|
||||
return `<div class="md-code-block"${langAttr}><button type="button" class="md-code-copy">复制</button><pre><code${attrs}>${body}</code></pre></div>`
|
||||
return `<div class="md-code-block"${langAttr}><button type="button" class="md-code-copy">${copyLabel}</button><pre><code${attrs}>${body}</code></pre></div>`
|
||||
},
|
||||
)
|
||||
// 有界 LRU 淘汰:超限删最久未用项(Map 首项)后插入,替代原整体 clear
|
||||
@@ -700,7 +705,7 @@ function decorateCodeHtml(raw: string): string {
|
||||
const oldest = _decoCache.keys().next().value
|
||||
if (oldest !== undefined) _decoCache.delete(oldest)
|
||||
}
|
||||
_decoCache.set(raw, out)
|
||||
_decoCache.set(cacheKey, out)
|
||||
return out
|
||||
}
|
||||
/** renderMd 包装:渲染 + 代码块装饰(双层 memo:renderMd 的 _mdCache + 本缓存,未变即零成本) */
|
||||
@@ -744,7 +749,7 @@ async function onMdCodeCopyClick(e: MouseEvent): Promise<void> {
|
||||
}
|
||||
// 成功态短暂反馈(直接改按钮 DOM;下次 v-html 重渲染自然还原,无需状态机)
|
||||
const prev = btn.textContent
|
||||
btn.textContent = ok ? '已复制' : '复制失败'
|
||||
btn.textContent = ok ? t('aiChat.copied') : t('aiChat.copyFailed')
|
||||
btn.classList.add(ok ? 'is-ok' : 'is-err')
|
||||
setTimeout(() => {
|
||||
btn.textContent = prev
|
||||
@@ -924,13 +929,12 @@ function collapsedPreviewHtml(msg: AiMessage): string {
|
||||
// R3:折叠条带量 —— 折叠态按钮显示「已折叠 N 字符 / 约 M tokens,点击展开」。
|
||||
// 折叠量按 M1 的标定估算(400px 视口 ≈ 阈值字符量,见 LONG_MSG_THRESHOLD 注),
|
||||
// 即 content.length - 阈值;token 为粗估(中英混合 1 token ≈ 2.5 字符),只供量级感知。
|
||||
// 文案硬编码中文:i18n locale 文件本批锁定(他代理并行追加,不新增键),
|
||||
// 展开态仍复用既有 aiChat.collapse 键。
|
||||
// 文案走 i18n(F1-1 补键);展开态仍复用既有 aiChat.collapse 键。
|
||||
const CHAR_PER_TOKEN_EST = 2.5
|
||||
function collapsedLongLabel(msg: AiMessage): string {
|
||||
const folded = Math.max(0, (msg.content?.length ?? 0) - LONG_MSG_THRESHOLD)
|
||||
const tokens = Math.max(1, Math.round(folded / CHAR_PER_TOKEN_EST))
|
||||
return `已折叠 ${folded} 字符 / 约 ${tokens} tokens,点击展开`
|
||||
return t('aiChat.foldedSummary', { chars: folded, tokens })
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1226,7 +1230,13 @@ const renderItems = computed<RenderItem[]>(() => {
|
||||
bucket = []
|
||||
if (msgs.length === 0) return
|
||||
const lastStoreId = store.state.messages[store.state.messages.length - 1]?.id
|
||||
const executing = isViewingGenerating.value && msgs[msgs.length - 1].id === lastStoreId
|
||||
// F1-3(10-17 走查):执行中判定补充「桶内存在 running/pending_approval 工具」。
|
||||
// 仅靠「桶末=store 末条」时,生成中注入补充消息会在 store 末尾 push 本地 user 气泡,
|
||||
// 判定瞬间失配 → 执行桶被误判为完成态,降级成默认折叠 trace 卡,正在跑/待审批的
|
||||
// 工具卡跌进折叠体不可见(下一轮 assistant push 才自愈)。桶内工具仍活跃即说明该轮
|
||||
// 未收敛,保持 step 形态内联可见;工具全部收敛后回到末条比对,历史桶不受影响(BUG-261001)。
|
||||
const hasLiveTool = msgs.some(m => (m.toolCalls ?? []).some(tc => tc.status === 'running' || tc.status === 'pending_approval'))
|
||||
const executing = isViewingGenerating.value && (msgs[msgs.length - 1].id === lastStoreId || hasLiveTool)
|
||||
// 961③: 轮号=当前发起计数(与轨迹卡是否产出解耦,单消息桶不吞号)
|
||||
const round = currentRound
|
||||
const built = buildBucket(msgs, round, executing, lastTs)
|
||||
@@ -1566,7 +1576,7 @@ watch(() => store.state.activeConversationId, (newId, oldId) => {
|
||||
onBeforeUnmount(() => {
|
||||
cancelPendingRaf()
|
||||
document.removeEventListener('click', closeTokenPopoverOnOutsideClick)
|
||||
document.removeEventListener('keydown', closeAgentTraceOnEsc)
|
||||
document.removeEventListener('keydown', closeOverlaysOnEsc)
|
||||
})
|
||||
|
||||
// token 详情面板:点击外部关闭(token 区内的 @click.stop 已阻冒泡,故文档级点击必为外部)
|
||||
@@ -1575,11 +1585,14 @@ function closeTokenPopoverOnOutsideClick(): void {
|
||||
}
|
||||
document.addEventListener('click', closeTokenPopoverOnOutsideClick)
|
||||
|
||||
// 子代理轨迹浮层 Esc 关闭(与遮罩点击/X 同为关闭出口;仅浮层开着时消费,不干扰其他快捷键)
|
||||
function closeAgentTraceOnEsc(e: KeyboardEvent): void {
|
||||
if (e.key === 'Escape' && agentPeekVisible.value) closeAgentTrace()
|
||||
// 浮层 Esc 关闭:子代理轨迹浮层 + token 详情 popover(F6-3:后者原先仅外点关闭,
|
||||
// 键盘用户开了面板只能点别处)。两者同时开着时逐层关(先浮层后 popover),Esc 不冒泡旁路。
|
||||
function closeOverlaysOnEsc(e: KeyboardEvent): void {
|
||||
if (e.key !== 'Escape') return
|
||||
if (agentPeekVisible.value) closeAgentTrace()
|
||||
else if (tokenPopoverMsgId.value !== null) tokenPopoverMsgId.value = null
|
||||
}
|
||||
document.addEventListener('keydown', closeAgentTraceOnEsc)
|
||||
document.addEventListener('keydown', closeOverlaysOnEsc)
|
||||
|
||||
// Markdown 预热(父原 loadMarkdown 在 onMounted 调,子组件同样幂等——useMarkdown 单例,
|
||||
// 多次调用安全,确保子组件挂载即预热)。
|
||||
@@ -2141,7 +2154,7 @@ defineExpose({
|
||||
background: var(--df-bg-card);
|
||||
color: var(--df-text-dim);
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
z-index: 15;
|
||||
transition: color 0.15s var(--df-ease), border-color 0.15s var(--df-ease);
|
||||
}
|
||||
@@ -2161,7 +2174,7 @@ defineExpose({
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-warning, #e8a33d);
|
||||
background: var(--df-warning);
|
||||
animation: ai-btb-pulse 2s ease-in-out infinite;
|
||||
}
|
||||
@keyframes ai-btb-pulse {
|
||||
@@ -2172,14 +2185,8 @@ defineExpose({
|
||||
/* -- Empty State 样式已随 EmptyState.vue 提取 -- */
|
||||
|
||||
/* -- Message Layout -- */
|
||||
.ai-msg-user {
|
||||
position: relative;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
flex-direction: row-reverse; /* 头像在右:DOM 仍 avatar 在先,视觉反转成【气泡】【头像】靠右 */
|
||||
margin-top: -3px; /* user 与上方消息间距略收(全局 gap 14 → 视觉 11),更紧凑 */
|
||||
}
|
||||
/* 用户消息行 .ai-msg-user 随 MessageItem.vue 抽离(自带 scoped,本组件 scoped 不渗透其内部),
|
||||
原重复定义删除(2026-10-18 整洁波,死样式验证:模板零引用+scoped 隔离永不命中) */
|
||||
.ai-msg-ai {
|
||||
position: relative;
|
||||
display: flex;
|
||||
@@ -2197,7 +2204,8 @@ defineExpose({
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* -- Avatar -- */
|
||||
/* -- Avatar -- workbench .av 范式:24px 圆角方块渐变(用户 warning→danger 系 / AI info→accent 系),
|
||||
字色随主题底色反转保证渐变上对比;内部字符 9px 700(当前为 svg 图标,字号字重为字符兜底) */
|
||||
.ai-msg-avatar {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
@@ -2206,41 +2214,44 @@ defineExpose({
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
font-size: 9px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.ai-msg-avatar--user {
|
||||
background: var(--df-info-bg);
|
||||
color: var(--df-info);
|
||||
}
|
||||
/* .ai-msg-avatar--user 随 MessageItem.vue 抽离(自带 scoped) */
|
||||
.ai-msg-avatar--ai {
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
background: linear-gradient(135deg, color-mix(in srgb, var(--df-info) 70%, var(--df-accent)), var(--df-accent));
|
||||
color: var(--df-bg);
|
||||
}
|
||||
|
||||
/* -- Bubble -- */
|
||||
/* -- Bubble -- workbench 聊天范式:用户=bg-card 底+0.5px 边框+9px 圆角;AI=无气泡(透明底直接排版)。
|
||||
9px 圆角与 9px 13px 内距均为 u-agent workbench 移植值,勿规整 */
|
||||
.ai-msg-bubble {
|
||||
position: relative;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
max-width: var(--df-msg-max-width);
|
||||
padding: 8px 12px;
|
||||
border-radius: var(--df-radius-lg);
|
||||
padding: 9px 13px;
|
||||
border-radius: 9px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.ai-msg-bubble--user {
|
||||
background: var(--df-accent);
|
||||
color: #fff;
|
||||
border-bottom-right-radius: var(--df-radius-sm);
|
||||
}
|
||||
/* 用户气泡 .ai-msg-bubble--user 随 MessageItem.vue 抽离(自带 scoped,原「同范式兜底」
|
||||
实为 scoped 隔离永不命中的死规则,2026-10-18 整洁波删除) */
|
||||
.ai-msg-bubble--ai {
|
||||
background: var(--df-bg-card);
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
color: var(--df-text);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-bottom-left-radius: var(--df-radius-sm);
|
||||
}
|
||||
/* 错误气泡对齐 workbench .blocked-card 范式:30% 红边框+6% 红底+12px 字;
|
||||
AI 无气泡后本卡自含 padding/边框/圆角(排在 --ai 后覆盖) */
|
||||
.ai-msg-bubble--error {
|
||||
background: var(--df-danger-bg);
|
||||
padding: 10px 13px;
|
||||
border: 1px solid color-mix(in srgb, var(--df-danger) 30%, transparent);
|
||||
border-radius: 9px;
|
||||
background: color-mix(in srgb, var(--df-danger) 6%, transparent);
|
||||
color: var(--df-danger);
|
||||
border-color: rgba(240,101,101,0.3);
|
||||
font-size: 12px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
/* 修正 的 display:block 方案——display:block 让 table 失去表格
|
||||
布局上下文,tr/td 脱离 table 上下文塌成块级堆叠丢列对齐(用户截图反馈测试报告四列表格错乱)。
|
||||
@@ -2255,8 +2266,8 @@ defineExpose({
|
||||
overflow-x: auto;
|
||||
}
|
||||
/* M1:超长 assistant 文本折叠——max-height 截断 + 底部渐变遮罩 + 展开按钮。
|
||||
背景 var(--df-bg-card) 对齐 .ai-msg-bubble--ai(L876):渐变淡出到气泡背景,
|
||||
视觉上内容「沉入」气泡而非被硬切。overflow:hidden 覆盖 .ai-md 的 overflow-x:auto。 */
|
||||
AI 气泡已透明(workbench 范式):渐变淡出到页面背景 --df-bg,视觉上内容「沉入」页面
|
||||
而非被硬切。overflow:hidden 覆盖 .ai-md 的 overflow-x:auto。 */
|
||||
.ai-msg-bubble--collapsed {
|
||||
max-height: 400px;
|
||||
overflow: hidden;
|
||||
@@ -2269,7 +2280,7 @@ defineExpose({
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 48px;
|
||||
background: linear-gradient(transparent, var(--df-bg-card));
|
||||
background: linear-gradient(transparent, var(--df-bg));
|
||||
pointer-events: none; /* 让点击穿透到下方展开按钮 */
|
||||
}
|
||||
/* 展开按钮:气泡底部居中,置于渐变遮罩之上 */
|
||||
@@ -2293,10 +2304,12 @@ defineExpose({
|
||||
background: var(--df-bg-card-hover);
|
||||
}
|
||||
|
||||
/* ── JSON 工具结果折叠防御(对齐 miniapp .msg-toolresult 视觉:灰 #b0b0b0 / 11px /
|
||||
/* ── JSON 工具结果折叠防御(对齐 miniapp .msg-toolresult 视觉:弱化灰字 / 11px /
|
||||
等宽 / max-height 80px 裁剪):assistant content 为纯 JSON 工具结果时弱化为折叠块,
|
||||
不渲染 markdown 大气泡刷屏。默认 max-height 80px + overflow-y:auto 可滚动,
|
||||
点击整块切换 --expanded(移除高度限制)展开/收起完整内容。 ── */
|
||||
点击整块切换 --expanded(移除高度限制)展开/收起完整内容。
|
||||
F1-2:灰字由硬编码 #b0b0b0 改 --df-text-dim——硬编码值在浅色主题白底上
|
||||
对比度约 2.6:1 不可读;token 双主题各有值,弱化语义不变。 ── */
|
||||
.ai-msg-json {
|
||||
max-height: 80px;
|
||||
overflow-y: auto;
|
||||
@@ -2307,7 +2320,7 @@ defineExpose({
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
color: #b0b0b0;
|
||||
color: var(--df-text-dim);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
@@ -2325,27 +2338,8 @@ defineExpose({
|
||||
border-color: var(--df-accent);
|
||||
}
|
||||
|
||||
/* ── Input Augmentation: 用户气泡内 mention chip(圆角徽标,复用 ChatInput .ai-skill-chip-name 风格) ──
|
||||
用户气泡背景 = --df-accent(主题强调色,如深色蓝/紫),chip 用半透明白底+深字 保证对比度;
|
||||
按 kind 区分颜色变体(project/task/idea/skill),与 @ mention 浮层 .ai-mention-item-type--* 视觉呼应。 */
|
||||
.ai-msg-chip {
|
||||
display: inline-block;
|
||||
padding: 1px 6px;
|
||||
margin: 0 1px;
|
||||
border-radius: var(--df-radius);
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
color: #fff;
|
||||
vertical-align: baseline;
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* kind 颜色变体(用更亮的底色区分,但保持白字可读) */
|
||||
.ai-msg-chip--project { background: rgba(255, 255, 255, 0.32); }
|
||||
.ai-msg-chip--task { background: rgba(255, 255, 255, 0.26); }
|
||||
.ai-msg-chip--idea { background: rgba(255, 255, 255, 0.22); border: 1px solid rgba(255, 255, 255, 0.35); }
|
||||
.ai-msg-chip--skill { background: rgba(0, 0, 0, 0.18); }
|
||||
/* ── mention chip(.ai-msg-chip 族)随 MessageItem.vue 抽离(自带 scoped,含 --skill 变体;
|
||||
此处原 kind 变体因 scoped 隔离永不命中,2026-10-18 整洁波删除) ── */
|
||||
|
||||
/* ── UX 密度改造:居中时间分隔线(相邻消息间隔 ≥30 分钟或跨天;
|
||||
per-block 相对时间漂移无价值已移除,精确时刻在消息容器 title) ── */
|
||||
@@ -2368,10 +2362,13 @@ defineExpose({
|
||||
background: color-mix(in srgb, var(--df-text-dim) 22%, transparent);
|
||||
}
|
||||
|
||||
/* ── 最终回答卡:左 2px 品牌色强调边条 + 背景微抬升(与轨迹内思考 pill 明确分层) ── */
|
||||
/* ── 最终回答卡:左 2px 品牌色强调边条 + 背景微抬升(与轨迹内思考 pill 明确分层);
|
||||
AI 无气泡后本卡自含 padding 保持卡感(普通 AI 消息仍无气泡) ── */
|
||||
.ai-msg-bubble--answer {
|
||||
border-left: 2px solid var(--df-accent);
|
||||
background: color-mix(in srgb, var(--df-accent) 4%, var(--df-bg-card));
|
||||
border-radius: var(--df-radius);
|
||||
background: color-mix(in srgb, var(--df-accent) 4%, transparent);
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
/* ── 轮次导航条(仅多轮长会话 ≥3 张轨迹卡出现,sticky 置顶,只做跳转) ── */
|
||||
@@ -2415,8 +2412,8 @@ defineExpose({
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
width: var(--df-h-icon-btn);
|
||||
height: var(--df-h-icon-btn);
|
||||
border: none;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
@@ -2426,14 +2423,13 @@ defineExpose({
|
||||
transition: opacity 0.2s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-msg-user:hover .ai-copy-btn,
|
||||
.ai-msg-ai:hover .ai-copy-btn--ai {
|
||||
opacity: 1;
|
||||
}
|
||||
.ai-copy-btn:hover {
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
}
|
||||
/* 图片复制按钮排在文本复制按钮左侧(right 让位 22px 按钮 + 4px 间距) */
|
||||
/* 图片复制按钮排在文本复制按钮左侧(right 让位 26px 按钮 + 4px 间距) */
|
||||
.ai-copy-btn--image {
|
||||
right: 30px;
|
||||
}
|
||||
@@ -2443,6 +2439,23 @@ defineExpose({
|
||||
.ai-md :deep(.md-code-block) {
|
||||
position: relative;
|
||||
}
|
||||
/* workbench .code 范式:比 --df-bg 更深一档的底 + 边框 + md 圆角 + mono 11px,
|
||||
覆盖全局 ai-md.css 的 .ai-md pre(现有 hljs github-dark 语法高亮色不动)。
|
||||
浅色主题降为 8% 黑:45% 全量在浅底上会压垮正文/高亮对比,违背双主题成立铁律。 */
|
||||
.ai-md :deep(pre) {
|
||||
background: color-mix(in srgb, var(--df-bg), #000 45%);
|
||||
border: 1px solid var(--df-border);
|
||||
border-radius: var(--df-radius-md);
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 11px;
|
||||
}
|
||||
.ai-md :deep(pre code) {
|
||||
font-size: 11px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
[data-theme='light'] .ai-md :deep(pre) {
|
||||
background: color-mix(in srgb, var(--df-bg), #000 8%);
|
||||
}
|
||||
.ai-md :deep(.md-code-copy) {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
@@ -2468,8 +2481,8 @@ defineExpose({
|
||||
}
|
||||
.ai-md :deep(.md-code-copy.is-ok) {
|
||||
opacity: 1;
|
||||
color: var(--df-success, #4caf50);
|
||||
border-color: var(--df-success, #4caf50);
|
||||
color: var(--df-success);
|
||||
border-color: var(--df-success);
|
||||
}
|
||||
.ai-md :deep(.md-code-copy.is-err) {
|
||||
opacity: 1;
|
||||
@@ -2519,7 +2532,7 @@ defineExpose({
|
||||
/* Fatal 错误(不可重试)的提示文案——替代隐藏的「重试」按钮,
|
||||
说明为何无重试入口,引导走「去设置」。 */
|
||||
.ai-msg-not-retryable {
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
font-style: italic;
|
||||
align-self: center;
|
||||
@@ -2528,12 +2541,12 @@ defineExpose({
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 2px 7px;
|
||||
padding: 2px 6px;
|
||||
border: none;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: transparent;
|
||||
color: var(--df-text-dim);
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
line-height: 1.4;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
@@ -2565,11 +2578,11 @@ defineExpose({
|
||||
margin-top: 4px;
|
||||
padding: 3px 8px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: color-mix(in srgb, var(--df-warning, #ffc107) 10%, transparent);
|
||||
background: color-mix(in srgb, var(--df-warning) 10%, transparent);
|
||||
width: fit-content;
|
||||
}
|
||||
.ai-msg-truncated-text {
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
line-height: 1.4;
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
@@ -2600,7 +2613,7 @@ defineExpose({
|
||||
padding-top: 6px;
|
||||
border-top: 0.5px solid var(--df-border);
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 9px;
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.7;
|
||||
}
|
||||
@@ -2618,8 +2631,9 @@ defineExpose({
|
||||
cursor: pointer;
|
||||
opacity: 1;
|
||||
}
|
||||
/* workbench .round-meta 范式:元数据 hover 变 --df-info */
|
||||
.ai-token-usage-trigger:hover {
|
||||
color: var(--df-text);
|
||||
color: var(--df-info);
|
||||
opacity: 1;
|
||||
}
|
||||
.ai-token-sep {
|
||||
@@ -2627,7 +2641,7 @@ defineExpose({
|
||||
}
|
||||
/* G4.3:估算值标注(估算非真实,弱化 dim + warning 色调,不喧宾夺主) */
|
||||
.ai-token-est {
|
||||
color: var(--df-warning, #f0c75e);
|
||||
color: var(--df-warning);
|
||||
opacity: 0.85;
|
||||
}
|
||||
/* 详情面板:复用 TopBar popout 风格(absolute / right 0 / bg-card / border / shadow) */
|
||||
@@ -2638,7 +2652,7 @@ defineExpose({
|
||||
margin-top: 4px;
|
||||
padding: 8px 10px;
|
||||
min-width: 200px;
|
||||
background: var(--df-bg-card, var(--df-bg));
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
@@ -2678,23 +2692,7 @@ defineExpose({
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 用户气泡内的图片(多模态消息渲染) */
|
||||
.ai-msg-images {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.ai-msg-image {
|
||||
max-width: 200px;
|
||||
max-height: 200px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: var(--df-radius);
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
background: var(--df-bg);
|
||||
}
|
||||
/* 用户气泡内图片(.ai-msg-images/.ai-msg-image)随 MessageItem.vue 抽离(自带 scoped) */
|
||||
|
||||
/* ═══ 压缩摘要 system 块(compressed 原文已展开,摘要置顶提示发给 AI 的是它) ═══
|
||||
用户诉求:压缩只后端省 token,界面不藏消息。原文 compressed 照常 user/ai 气泡展开,
|
||||
@@ -2773,7 +2771,7 @@ defineExpose({
|
||||
.ai-trace-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
gap: 8px;
|
||||
padding: 6px 10px;
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
@@ -2806,6 +2804,11 @@ defineExpose({
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* workbench .round-meta 范式:轮次/时间/token 小元数据 hover 变 --df-info(折叠交互不动) */
|
||||
.ai-trace-head:hover .ai-trace-agg,
|
||||
.ai-trace-head:hover .ai-trace-tokens {
|
||||
color: var(--df-info);
|
||||
}
|
||||
/* 任务关联 chip(仅含任务工具调用的轮次渲染):accent 弱化底 + hover 提亮,点击跳任务 */
|
||||
.ai-trace-task-chip {
|
||||
flex-shrink: 0;
|
||||
@@ -2826,7 +2829,8 @@ defineExpose({
|
||||
}
|
||||
|
||||
/* ── 轨迹展开态 rail 面板:左轨竖线贯通,思考 pill 与工具卡图标锚定其上(git-graph 式轮次结构)。
|
||||
轨 x=22px 对齐工具卡图标中心(卡内 padding 10px + 24px 图标位一半),pill 灯泡图标同 x。 ── */
|
||||
轨 x=22px 对齐工具卡图标中心(卡内 padding 10px + 24px 图标位一半),pill 灯泡图标同 x。
|
||||
workbench .tr 范式:1px 连线用 --df-border。 ── */
|
||||
.ai-trace-body {
|
||||
position: relative;
|
||||
padding: 2px 10px 8px 0;
|
||||
@@ -2838,7 +2842,7 @@ defineExpose({
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 1px;
|
||||
background: color-mix(in srgb, var(--df-text-dim) 22%, transparent);
|
||||
background: var(--df-border);
|
||||
}
|
||||
.ai-trace-round {
|
||||
position: relative;
|
||||
@@ -2852,10 +2856,10 @@ defineExpose({
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
min-height: 24px;
|
||||
padding: 3px 8px 3px 38px;
|
||||
padding: 3px 8px 3px var(--df-icon-gutter);
|
||||
border: none;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: transparent;
|
||||
@@ -2872,16 +2876,16 @@ defineExpose({
|
||||
}
|
||||
.ai-think-ic {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
left: 11px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--df-accent-bg);
|
||||
background: color-mix(in srgb, var(--df-accent) 15%, transparent);
|
||||
color: var(--df-accent);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@@ -2896,14 +2900,14 @@ defineExpose({
|
||||
flex: 0 0 auto;
|
||||
white-space: nowrap;
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 9.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.75;
|
||||
margin-left: auto;
|
||||
}
|
||||
/* 展开的完整思考段落:保持既有卡片样式(气泡卡同底),挂在 pill 下方缩进对齐正文 */
|
||||
.ai-think-full {
|
||||
margin: 2px 0 6px 38px;
|
||||
margin: 2px 0 6px var(--df-icon-gutter);
|
||||
padding: 8px 12px;
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
@@ -2916,30 +2920,14 @@ defineExpose({
|
||||
}
|
||||
|
||||
/* 执行中态轨迹卡(骨架与完成态完全同构,仅色/态微差):accent 底 + 脉冲点替代 chevron,
|
||||
step→trace 切换时卡片高度/内边距一致,只 patch 内部文字 → 无跳变 */
|
||||
step→trace 切换时卡片高度/内边距一致,只 patch 内部文字 → 无跳变。
|
||||
(.ai-trace-toggle--running/.ai-step-line/.ai-step-text 旧单行摘要骨架已废:step 卡
|
||||
改用 trace-card 同构骨架,模板零引用,2026-10-18 整洁波删除) */
|
||||
.ai-trace-card--running {
|
||||
border-style: solid;
|
||||
border-color: color-mix(in srgb, var(--df-accent) 28%, transparent);
|
||||
background: color-mix(in srgb, var(--df-accent) 7%, transparent);
|
||||
}
|
||||
.ai-trace-toggle--running {
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* 执行中实时步骤摘要(已完成步骤收进一行,accent 呼吸点对齐状态栏 .ai-agentic-progress) */
|
||||
.ai-step-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
max-width: var(--df-msg-max-width);
|
||||
padding: 4px 10px;
|
||||
border-radius: var(--df-radius);
|
||||
background: color-mix(in srgb, var(--df-accent) 7%, transparent);
|
||||
font-size: 11px;
|
||||
color: var(--df-text-secondary);
|
||||
user-select: none;
|
||||
}
|
||||
.ai-step-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
@@ -2948,13 +2936,6 @@ defineExpose({
|
||||
flex-shrink: 0;
|
||||
animation: ai-step-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
.ai-step-text {
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10.5px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
@keyframes ai-step-pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.3; }
|
||||
@@ -2969,7 +2950,7 @@ defineExpose({
|
||||
max-width: var(--df-msg-max-width);
|
||||
padding: 4px 10px;
|
||||
border-radius: var(--df-radius);
|
||||
background: color-mix(in srgb, var(--df-warning, #f0c75e) 8%, transparent);
|
||||
background: color-mix(in srgb, var(--df-warning) 8%, transparent);
|
||||
font-size: 11px;
|
||||
color: var(--df-text-secondary);
|
||||
user-select: none;
|
||||
@@ -2978,13 +2959,13 @@ defineExpose({
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-warning, #f0c75e);
|
||||
background: var(--df-warning);
|
||||
flex-shrink: 0;
|
||||
animation: ai-step-pulse 1.2s ease-in-out infinite;
|
||||
}
|
||||
.ai-retry-text {
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
@@ -3018,10 +2999,10 @@ defineExpose({
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-agent-fin--warn {
|
||||
background: color-mix(in srgb, var(--df-warning, #f0c75e) 8%, transparent);
|
||||
background: color-mix(in srgb, var(--df-warning) 8%, transparent);
|
||||
}
|
||||
.ai-agent-fin--warn .ai-agent-fin-dot {
|
||||
background: var(--df-warning, #f0c75e);
|
||||
background: var(--df-warning);
|
||||
}
|
||||
.ai-agent-fin--err {
|
||||
background: color-mix(in srgb, var(--df-danger) 10%, transparent);
|
||||
@@ -3044,7 +3025,7 @@ defineExpose({
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-agent-fin--warn .ai-agent-fin-status {
|
||||
color: var(--df-warning, #f0c75e);
|
||||
color: var(--df-warning);
|
||||
}
|
||||
.ai-agent-fin--err .ai-agent-fin-status {
|
||||
color: var(--df-danger);
|
||||
@@ -3057,7 +3038,8 @@ defineExpose({
|
||||
.ai-agent-fin-meta {
|
||||
flex-shrink: 0;
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* 被拒工具 chip(P2-1):琥珀警示层与 truncated 同色系;限宽防长清单挤掉摘要行 */
|
||||
.ai-agent-fin-rejected {
|
||||
@@ -3068,9 +3050,9 @@ defineExpose({
|
||||
white-space: nowrap;
|
||||
padding: 0 6px;
|
||||
border-radius: 999px;
|
||||
font-size: 10.5px;
|
||||
background: color-mix(in srgb, var(--df-warning, #f0c75e) 16%, transparent);
|
||||
color: var(--df-warning, #f0c75e);
|
||||
font-size: 10px;
|
||||
background: color-mix(in srgb, var(--df-warning) 16%, transparent);
|
||||
color: var(--df-warning);
|
||||
}
|
||||
/* 无轨迹(启动失败)卡:禁点视觉,hover 不提亮(cursor 维持默认) */
|
||||
.ai-agent-fin--notrace {
|
||||
@@ -3080,7 +3062,7 @@ defineExpose({
|
||||
.ai-agent-fin--notrace:hover {
|
||||
background: color-mix(in srgb, var(--df-text-secondary) 6%, transparent);
|
||||
}
|
||||
/* peek 拉取中的加载微标(挂在具体卡右端) */
|
||||
/* peek 拉取中的加载微标(挂在具体卡右端);旋转动画消费 global.css @keyframes df-spin */
|
||||
.ai-agent-fin-spin {
|
||||
flex-shrink: 0;
|
||||
width: 10px;
|
||||
@@ -3088,10 +3070,7 @@ defineExpose({
|
||||
border: 1.5px solid color-mix(in srgb, var(--df-text-secondary) 35%, transparent);
|
||||
border-top-color: var(--df-text-secondary);
|
||||
border-radius: 50%;
|
||||
animation: ai-agent-fin-spin 0.8s linear infinite;
|
||||
}
|
||||
@keyframes ai-agent-fin-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
animation: df-spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
/* ═══ S3 子代理轨迹浮层(只读,关即弃) ═══ */
|
||||
@@ -3112,7 +3091,7 @@ defineExpose({
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border-strong);
|
||||
border-radius: var(--df-radius-lg);
|
||||
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
|
||||
box-shadow: var(--df-shadow-md);
|
||||
overflow: hidden;
|
||||
}
|
||||
.ai-agent-peek-head {
|
||||
@@ -3124,7 +3103,7 @@ defineExpose({
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-agent-peek-title {
|
||||
font-size: 12.5px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--df-text);
|
||||
}
|
||||
@@ -3169,7 +3148,7 @@ defineExpose({
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
color: var(--df-text-secondary);
|
||||
margin-bottom: 4px;
|
||||
@@ -3193,7 +3172,7 @@ defineExpose({
|
||||
.ai-agent-peek-msg--tool .ai-agent-peek-text,
|
||||
.ai-agent-peek-msg--system .ai-agent-peek-text {
|
||||
color: var(--df-text-secondary);
|
||||
font-size: 11.5px;
|
||||
font-size: 11px;
|
||||
}
|
||||
/* 浮层头身份标识行:置于标题下方,窄容器内单行省略 */
|
||||
.ai-agent-peek-head-text {
|
||||
@@ -3214,7 +3193,7 @@ defineExpose({
|
||||
.ai-agent-peek-agent {
|
||||
flex-shrink: 0;
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-info);
|
||||
background: var(--df-info-bg);
|
||||
border-radius: var(--df-radius-sm);
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
// OutboxDrawer:定时/待发消息统一列表(跨会话),支持 改期/立即发送/取消 + 底部新建。
|
||||
// 挂载点在 ChatInput.vue(⏰ 入口按钮旁,Teleport 自脱离输入区布局);
|
||||
// 后端 ai_outbox_* 命令未接线时 invoke 静默降级(useAiOutbox 内),抽屉空态可用。
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { ref, computed, watch, onBeforeUnmount } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useAiOutbox, type AiOutboxItem } from '../../composables/ai/useAiOutbox'
|
||||
import { useAiStore } from '../../stores/ai'
|
||||
@@ -96,6 +96,20 @@ watch(() => props.open, (v) => {
|
||||
if (v) void refresh()
|
||||
})
|
||||
|
||||
// F6-2(走查-信息UX 面六):Esc 关抽屉(与遮罩点击/✕ 同出口,键盘可达)。
|
||||
// 监听挂 document:AiChat 全局 Esc 仲裁在 window 层,document 先于 window 收到冒泡,
|
||||
// 此处消费即收口(stopPropagation),防「关抽屉的同时误关分离窗」一次按键双效果;
|
||||
// IME 组词中的 Esc(229/isComposing)归输入法,不关抽屉(仓内三处同款守卫)。
|
||||
function onEscClose(e: KeyboardEvent): void {
|
||||
if (!props.open || e.key !== 'Escape') return
|
||||
if (e.isComposing || e.keyCode === 229) return
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
emit('close')
|
||||
}
|
||||
document.addEventListener('keydown', onEscClose)
|
||||
onBeforeUnmount(() => document.removeEventListener('keydown', onEscClose))
|
||||
|
||||
// ── 列表展示 ──
|
||||
|
||||
// 排序:活跃在前(sending→pending→failed),终态沉底;同级按 due_at 升序(尽快项 due null 排最前)
|
||||
@@ -230,7 +244,8 @@ async function onCreate(): Promise<void> {
|
||||
.outbox-panel {
|
||||
width: min(420px, 92vw);
|
||||
height: 100%;
|
||||
background: var(--df-bg-card);
|
||||
/* wave2:抽屉底 bg-raised(比 bg-card 抬一级,与遮罩分层) */
|
||||
background: var(--df-bg-raised);
|
||||
border-left: 0.5px solid var(--df-border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -259,7 +274,7 @@ async function onCreate(): Promise<void> {
|
||||
border-radius: var(--df-radius);
|
||||
}
|
||||
.outbox-close:hover {
|
||||
background: var(--df-bg-raised);
|
||||
background: var(--df-bg-card-hover);
|
||||
color: var(--df-text);
|
||||
}
|
||||
.outbox-list {
|
||||
@@ -309,8 +324,8 @@ async function onCreate(): Promise<void> {
|
||||
border-color: color-mix(in srgb, var(--df-warning) 40%, transparent);
|
||||
}
|
||||
.outbox-badge--failed {
|
||||
color: #e5484d;
|
||||
border-color: color-mix(in srgb, #e5484d 40%, transparent);
|
||||
color: var(--df-danger);
|
||||
border-color: color-mix(in srgb, var(--df-danger) 40%, transparent);
|
||||
}
|
||||
.outbox-text {
|
||||
font-size: 12px;
|
||||
@@ -336,7 +351,7 @@ async function onCreate(): Promise<void> {
|
||||
transition: background 0.15s, color 0.15s;
|
||||
}
|
||||
.outbox-act:hover:not(:disabled) {
|
||||
background: var(--df-bg-raised);
|
||||
background: var(--df-bg-card-hover);
|
||||
color: var(--df-text);
|
||||
}
|
||||
.outbox-act:disabled {
|
||||
@@ -353,12 +368,12 @@ async function onCreate(): Promise<void> {
|
||||
color: #fff;
|
||||
}
|
||||
.outbox-act--danger:hover:not(:disabled) {
|
||||
color: #e5484d;
|
||||
border-color: color-mix(in srgb, #e5484d 40%, transparent);
|
||||
color: var(--df-danger);
|
||||
border-color: color-mix(in srgb, var(--df-danger) 40%, transparent);
|
||||
}
|
||||
.outbox-dt {
|
||||
border: 0.5px solid var(--df-border);
|
||||
background: var(--df-bg-raised);
|
||||
background: var(--df-bg-card);
|
||||
color: var(--df-text);
|
||||
font-size: 11px;
|
||||
padding: 3px 6px;
|
||||
@@ -382,7 +397,7 @@ async function onCreate(): Promise<void> {
|
||||
box-sizing: border-box;
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
background: var(--df-bg-raised);
|
||||
background: var(--df-bg-card);
|
||||
color: var(--df-text);
|
||||
font-size: 12px;
|
||||
font-family: var(--df-font-sans);
|
||||
|
||||
@@ -276,7 +276,8 @@ const echoSummary = computed(() => {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 输入区上方的轻量折叠条,视觉克制度对齐 .ai-input-hint(不抢输入框焦点注意力) */
|
||||
/* 输入区上方的轻量折叠条,视觉克制度对齐 .ai-input-hint(不抢输入框焦点注意力)
|
||||
wave2(2026-10-18):info 系透明彩底范式(授权边界=信息/配置信号,非警示) */
|
||||
.ai-boundary {
|
||||
margin-bottom: 4px;
|
||||
font-size: 11px;
|
||||
@@ -292,7 +293,7 @@ const echoSummary = computed(() => {
|
||||
color: var(--df-text-dim);
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
border-radius: var(--df-radius-sm);
|
||||
max-width: 100%;
|
||||
}
|
||||
.ai-boundary-toggle:hover { color: var(--df-text); }
|
||||
@@ -301,26 +302,29 @@ const echoSummary = computed(() => {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-boundary-chevron.is-open { transform: rotate(90deg); }
|
||||
.ai-boundary-toggle-label { font-weight: 600; }
|
||||
/* 标题同色(info)12px 600 */
|
||||
.ai-boundary-toggle-label { font-weight: 600; font-size: 12px; color: var(--df-info); }
|
||||
.ai-boundary-echo {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--df-accent);
|
||||
color: var(--df-info);
|
||||
opacity: 0.85;
|
||||
}
|
||||
.ai-boundary-body {
|
||||
margin-top: 4px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
background: color-mix(in srgb, var(--df-accent) 5%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-accent) 20%, transparent);
|
||||
background: color-mix(in srgb, var(--df-info) 6%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-info) 30%, transparent);
|
||||
border-radius: var(--df-radius);
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
}
|
||||
.ai-boundary-locked {
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-warning);
|
||||
}
|
||||
.ai-boundary-loadfail {
|
||||
@@ -328,7 +332,7 @@ const echoSummary = computed(() => {
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-danger);
|
||||
}
|
||||
.ai-boundary-row {
|
||||
@@ -350,7 +354,7 @@ const echoSummary = computed(() => {
|
||||
color: var(--df-text-dim);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ai-boundary-unlimited input { accent-color: var(--df-accent); margin: 0; }
|
||||
.ai-boundary-unlimited input { accent-color: var(--df-info); margin: 0; }
|
||||
.ai-boundary-unlimited:has(input:disabled) { cursor: not-allowed; opacity: 0.6; }
|
||||
.ai-boundary-input {
|
||||
flex: 1;
|
||||
@@ -363,7 +367,7 @@ const echoSummary = computed(() => {
|
||||
border-radius: calc(var(--df-radius) - 2px);
|
||||
outline: none;
|
||||
}
|
||||
.ai-boundary-input:focus { border-color: color-mix(in srgb, var(--df-accent) 40%, transparent); }
|
||||
.ai-boundary-input:focus { border-color: color-mix(in srgb, var(--df-info) 40%, transparent); }
|
||||
.ai-boundary-input:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.ai-boundary-input--num { flex: 0 0 90px; }
|
||||
.ai-boundary-mini-btn {
|
||||
@@ -413,10 +417,11 @@ const echoSummary = computed(() => {
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
/* 一次授权钮:info 系透明底描边钮(对应色操作钮范式) */
|
||||
.ai-boundary-confirm {
|
||||
border: none;
|
||||
background: var(--df-accent);
|
||||
color: #fff;
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-info) 40%, transparent);
|
||||
background: color-mix(in srgb, var(--df-info) 10%, transparent);
|
||||
color: var(--df-info);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
padding: 4px 10px;
|
||||
@@ -424,7 +429,7 @@ const echoSummary = computed(() => {
|
||||
border-radius: calc(var(--df-radius) - 2px);
|
||||
transition: background 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-boundary-confirm:hover:not(:disabled) { background: var(--df-accent-hover); }
|
||||
.ai-boundary-confirm:hover:not(:disabled) { background: color-mix(in srgb, var(--df-info) 18%, transparent); }
|
||||
.ai-boundary-confirm:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.ai-boundary-clear {
|
||||
border: 0.5px solid var(--df-border);
|
||||
@@ -442,7 +447,7 @@ const echoSummary = computed(() => {
|
||||
.ai-boundary-field.is-error span { color: var(--df-danger); }
|
||||
/* A11: 脏编辑提示条(切会话保留编辑时的可见说明) */
|
||||
.ai-boundary-dirty {
|
||||
font-size: 10.5px;
|
||||
font-size: 10px;
|
||||
color: var(--df-warning);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -99,15 +99,16 @@ async function handleStopArchive(): Promise<void> {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 复用 HelpRequiredCard 样式基调(warning 色系,停靠属"需用户拍板"信号,视觉一致) */
|
||||
/* wave2(2026-10-18):统一透明彩底卡范式,danger 系(非正常终局停靠=需用户拍板信号)——
|
||||
边框 color-mix 30% + 底 8% + 标题同色 12px/600 + 正文 secondary 12px + 透明底描边钮 */
|
||||
.ai-task-parked {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
margin-bottom: 6px;
|
||||
padding: 6px 8px;
|
||||
background: color-mix(in srgb, var(--df-warning) 10%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-warning) 40%, transparent);
|
||||
background: color-mix(in srgb, var(--df-danger) 8%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-danger) 30%, transparent);
|
||||
border-radius: var(--df-radius);
|
||||
}
|
||||
.ai-task-parked-head {
|
||||
@@ -115,37 +116,39 @@ async function handleStopArchive(): Promise<void> {
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
/* stop_kind 标签:透明 danger 描边 chip;fatal 连续失败重入耗尽=实底警示级最高 */
|
||||
.ai-task-parked-tag {
|
||||
flex-shrink: 0;
|
||||
padding: 0 6px;
|
||||
border-radius: calc(var(--df-radius) - 2px);
|
||||
background: var(--df-warning);
|
||||
color: #000;
|
||||
background: color-mix(in srgb, var(--df-danger) 12%, transparent);
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-danger) 30%, transparent);
|
||||
color: var(--df-danger);
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
line-height: 16px;
|
||||
}
|
||||
.ai-task-parked-tag--fatal {
|
||||
background: var(--df-danger);
|
||||
border-color: var(--df-danger);
|
||||
color: #fff;
|
||||
}
|
||||
.ai-task-parked-title {
|
||||
font-size: 11.5px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--df-warning);
|
||||
color: var(--df-danger);
|
||||
}
|
||||
.ai-task-parked-reason {
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.9;
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
/* preserved 行与 reason 同色系但更弱一级:保证信息在,不与真实原因抢视觉权重 */
|
||||
.ai-task-parked-preserved {
|
||||
font-size: 10.5px;
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.8;
|
||||
opacity: 0.85;
|
||||
}
|
||||
.ai-task-parked-actions {
|
||||
display: flex;
|
||||
@@ -155,17 +158,17 @@ async function handleStopArchive(): Promise<void> {
|
||||
margin-top: 2px;
|
||||
}
|
||||
.ai-task-parked-btn {
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-warning) 60%, transparent);
|
||||
background: var(--df-warning);
|
||||
color: #000;
|
||||
border: 0.5px solid color-mix(in srgb, var(--df-danger) 40%, transparent);
|
||||
background: color-mix(in srgb, var(--df-danger) 10%, transparent);
|
||||
color: var(--df-danger);
|
||||
cursor: pointer;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
padding: 3px 10px;
|
||||
border-radius: calc(var(--df-radius) - 2px);
|
||||
transition: filter 0.15s var(--df-ease);
|
||||
transition: background 0.15s var(--df-ease), color 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-task-parked-btn:hover { filter: brightness(1.1); }
|
||||
.ai-task-parked-btn:hover { background: color-mix(in srgb, var(--df-danger) 16%, transparent); }
|
||||
.ai-task-parked-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.ai-task-parked-btn--muted {
|
||||
background: transparent;
|
||||
|
||||
+109
-78
@@ -14,7 +14,7 @@
|
||||
<button
|
||||
v-if="pendingApprovalCount > 0"
|
||||
type="button"
|
||||
class="ai-approval-badge"
|
||||
class="ai-approval-badge df-badge df-badge--danger"
|
||||
:title="$t('aiChat.pendingApprovalHint')"
|
||||
@click="emit('scroll-to-pending')"
|
||||
>
|
||||
@@ -24,7 +24,7 @@
|
||||
<button
|
||||
v-if="unattendedStatus?.breaker_tripped"
|
||||
type="button"
|
||||
class="ai-unattended-badge ai-unattended-badge--tripped"
|
||||
class="ai-unattended-badge df-badge df-badge--danger"
|
||||
:title="$t('aiChat.unattendedResetHint')"
|
||||
@click="resetUnattendedBreaker"
|
||||
>
|
||||
@@ -33,7 +33,7 @@
|
||||
<button
|
||||
v-else-if="unattendedStatus?.enabled"
|
||||
type="button"
|
||||
class="ai-unattended-badge"
|
||||
class="ai-unattended-badge df-badge df-badge--accent"
|
||||
:title="$t('aiChat.unattendedBadgeHint')"
|
||||
@click="jumpToUnattendedSettings"
|
||||
>
|
||||
@@ -50,7 +50,7 @@
|
||||
:title="store.state.providers.length > 1 ? $t('aiChat.providerSwitchSetsDefault') : ''"
|
||||
@click="cycleProvider"
|
||||
>
|
||||
<span class="provider-dot" :class="'provider-dot--' + providerStatus"></span>
|
||||
<span class="df-dot provider-dot" :class="'provider-dot--' + providerStatus"></span>
|
||||
<span class="provider-name">{{ activeProviderName }}</span>
|
||||
</button>
|
||||
<div class="ai-provider-bar ai-provider-empty" v-else>
|
||||
@@ -182,7 +182,7 @@
|
||||
</div>
|
||||
<!-- #14 桌面任务卡:后台在途任务(多会话并发生成中,点击切回) -->
|
||||
<div v-if="runningTasks.length || recoverableTasks.length" class="ai-running-tasks-inline">
|
||||
<button type="button" class="ai-running-tasks-badge ai-tool-badge" :class="{ 'is-active': runningTasksExpanded }" @click="togglePanel('running')" :title="$t('aiChat.runningTasks')">
|
||||
<button type="button" class="ai-running-tasks-badge ai-tool-badge df-badge df-badge--info" :class="{ 'is-active': runningTasksExpanded }" @click="togglePanel('running')" :title="$t('aiChat.runningTasks')">
|
||||
<span class="ai-running-tasks-pulse"></span>
|
||||
{{ runningTasks.length }}
|
||||
</button>
|
||||
@@ -236,6 +236,8 @@
|
||||
<span class="ai-history-text">{{ h.text }}</span>
|
||||
<span class="ai-history-time">{{ h.time }}</span>
|
||||
</div>
|
||||
<!-- F6-1:目标消息在折叠段内未渲染,面板不收 + 行内提示 -->
|
||||
<div v-if="locateMissHint" class="ai-locate-miss">{{ locateMissHint }}</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
@@ -251,6 +253,8 @@
|
||||
<span class="ai-summary-label">{{ $t('aiChat.compressedSummaryLabel') }} #{{ summaryMsgs.length - i }}</span>
|
||||
<p class="ai-summary-preview">{{ s.text }}</p>
|
||||
</div>
|
||||
<!-- F6-1:摘要项同享定位未命中提示(压缩段折叠时 system 消息同样不在 DOM) -->
|
||||
<div v-if="locateMissHint" class="ai-locate-miss">{{ locateMissHint }}</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
@@ -413,6 +417,7 @@ onMounted(() => { void refreshUnattended() })
|
||||
onBeforeUnmount(() => {
|
||||
unattendedDisposed = true
|
||||
if (unattendedTimer) { clearTimeout(unattendedTimer); unattendedTimer = null }
|
||||
if (locateMissTimer) { clearTimeout(locateMissTimer); locateMissTimer = null }
|
||||
})
|
||||
|
||||
// ══ 更多菜单 popout 状态(上下文管理操作收纳)══
|
||||
@@ -768,8 +773,23 @@ const summaryMsgs = computed<SummaryItem[]>(() => msgDerived.value.summaries)
|
||||
const historyExpanded = ref(false)
|
||||
|
||||
/** 点击历史消息项 → 滚动定位到对应的消息气泡 */
|
||||
// F6-1(走查-信息UX 面六):目标消息在折叠段(已归档/已压缩)内时,折叠态不渲染
|
||||
// [data-msg-id] 元素,querySelector 必空。原实现先收面板再查 DOM,未命中即静默无反应;
|
||||
// 现改为面板保持展开 + 行内提示引导展开分隔条。展开折叠段的状态在 MessageList 内持有,
|
||||
// 本组件不可达,提示是最小闭环(不跨组件撬状态)。
|
||||
const locateMissHint = ref('')
|
||||
let locateMissTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function showLocateMiss(): void {
|
||||
locateMissHint.value = t('aiChat.historyLocateInSegment')
|
||||
if (locateMissTimer) clearTimeout(locateMissTimer)
|
||||
locateMissTimer = setTimeout(() => {
|
||||
locateMissHint.value = ''
|
||||
locateMissTimer = null
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
function scrollToMessage(msgId: string) {
|
||||
historyExpanded.value = false
|
||||
// 消息列表已有 data-msg-id 属性,直接 DOM 查询定位。
|
||||
// msgId 由后端生成,可能含 CSS 选择器元字符(: . [ ] / 空格 等),
|
||||
// 模板拼 selector 会被选择器解析器当伪类/类名异常 → querySelector 抛错或返回 null。
|
||||
@@ -787,8 +807,13 @@ function scrollToMessage(msgId: string) {
|
||||
el = Array.from(all).find(n => n.getAttribute('data-msg-id') === msgId) ?? null
|
||||
}
|
||||
if (el) {
|
||||
locateMissHint.value = ''
|
||||
historyExpanded.value = false
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
return
|
||||
}
|
||||
// 未命中:不收面板,提示替代静默
|
||||
showLocateMiss()
|
||||
}
|
||||
|
||||
/** 目标/历史下拉容器 DOM 引用(用于点击外部检测) */
|
||||
@@ -824,6 +849,7 @@ const contextExpanded = ref(false)
|
||||
|
||||
/** 弹出面板互斥:goals/history/summary/context/running 五个 badge 面板,点一个收起其他,再点当前切换。 */
|
||||
function togglePanel(panel: 'goals' | 'history' | 'summary' | 'context' | 'running') {
|
||||
locateMissHint.value = ''
|
||||
const refs = { goals: goalsExpanded, history: historyExpanded, summary: summaryExpanded, context: contextExpanded, running: runningTasksExpanded }
|
||||
const willOpen = !refs[panel].value
|
||||
goalsExpanded.value = historyExpanded.value = summaryExpanded.value = contextExpanded.value = runningTasksExpanded.value = false
|
||||
@@ -965,56 +991,37 @@ onBeforeUnmount(() => {
|
||||
white-space: nowrap;
|
||||
max-width: 200px;
|
||||
}
|
||||
/* 审批徽标(待审批>0 时显于头部,点击跳首个审批卡;div→button 后归零默认样式) */
|
||||
/* 审批徽标(待审批>0 时显于头部,点击跳首个审批卡)
|
||||
2026-10-18 wave2:迁 .df-badge--danger 透明彩底徽章(色由全局公共类接管,此处只留布局) */
|
||||
.ai-approval-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
background: var(--df-warning-bg);
|
||||
color: var(--df-warning);
|
||||
padding: 2px 8px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
transition: opacity 0.15s var(--df-ease);
|
||||
font-family: inherit;
|
||||
appearance: none;
|
||||
/* review ③:div→button 后 UA outset 边框需显式归零(appearance:none 不含 border) */
|
||||
border: none;
|
||||
}
|
||||
.ai-approval-badge:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
.ai-approval-badge:focus-visible {
|
||||
outline: 1.5px solid var(--df-accent, #4a9eff);
|
||||
outline: 1.5px solid var(--df-accent);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
/* 挂机引擎态徽章(开启=accent 弱底;熔断=红底红字,点击复位) */
|
||||
/* 挂机引擎态徽章(开启=accent / 熔断=danger,均由 df-badge 变体接管,此处只留布局) */
|
||||
.ai-unattended-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
padding: 2px 8px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
font-family: inherit;
|
||||
appearance: none;
|
||||
border: none;
|
||||
transition: opacity 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-unattended-badge:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
.ai-unattended-badge--tripped {
|
||||
background: var(--df-danger-bg);
|
||||
color: var(--df-danger);
|
||||
border: 0.5px solid var(--df-danger);
|
||||
}
|
||||
|
||||
/* ═══ 模型选择器(对话透明化 L1:紧凑下拉) ═══ */
|
||||
.ai-model-picker {
|
||||
@@ -1053,25 +1060,28 @@ onBeforeUnmount(() => {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
/* ── 图标按钮(共享工具类,header-actions 内清空/压缩/最大化/分离/关闭等)── */
|
||||
/* ── 图标按钮(共享工具类,header-actions 内清空/压缩/最大化/分离/关闭等)
|
||||
2026-10-18 wave2:统一 workbench .hd-btn 范式——bg-card 底+边框+md 圆角+hover 边框亮 ── */
|
||||
.ai-btn-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border: none;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: transparent;
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-md);
|
||||
background: var(--df-bg-card);
|
||||
color: var(--df-text-dim);
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
transition: border-color 0.15s var(--df-ease), color 0.15s var(--df-ease), background 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-btn-icon:hover {
|
||||
background: var(--df-bg-card);
|
||||
border-color: var(--df-border-strong);
|
||||
background: var(--df-bg-card-hover);
|
||||
color: var(--df-text-secondary);
|
||||
}
|
||||
.ai-btn-icon--active {
|
||||
border-color: color-mix(in srgb, var(--df-accent) 45%, transparent);
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
}
|
||||
@@ -1080,7 +1090,8 @@ onBeforeUnmount(() => {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.ai-btn-icon:disabled:hover {
|
||||
background: transparent;
|
||||
border-color: var(--df-border);
|
||||
background: var(--df-bg-card);
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* ── 更多菜单 popout(清空/压缩上下文等低频操作收纳;CSS 原缺失致打开样式错乱)── */
|
||||
@@ -1094,7 +1105,7 @@ onBeforeUnmount(() => {
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -1113,16 +1124,13 @@ onBeforeUnmount(() => {
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ai-more-item:hover:not(:disabled) { background: var(--df-bg-hover, rgba(0,0,0,0.06)); color: var(--df-text); }
|
||||
.ai-more-item:hover:not(:disabled) { background: var(--df-bg-card-hover); color: var(--df-text); }
|
||||
.ai-more-item:disabled { opacity: 0.35; cursor: not-allowed; }
|
||||
/* Transition:淡入 + 下滑 */
|
||||
.ai-more-popout-enter-active, .ai-more-popout-leave-active { transition: opacity .15s, transform .15s; }
|
||||
.ai-more-popout-enter-from, .ai-more-popout-leave-to { opacity: 0; transform: translateY(-4px); }
|
||||
/* 压缩中 spinner 图标旋转动画(@keyframes ai-btn-spin 在父级 AiChat.vue 全局定义,
|
||||
scoped 不重命名 @keyframes,此处按名引用) */
|
||||
.ai-btn-spinner {
|
||||
animation: ai-btn-spin 0.9s linear infinite;
|
||||
}
|
||||
/* 压缩中 spinner:.ai-btn-spinner(含 ai-btn-spin 旋转动画)由 components.css 全局定义,
|
||||
原本地重复 animation 声明删除(2026-10-18 整洁波,逐字重复零视觉变更) */
|
||||
/* 底部工具区(标题左 + 工具右) */
|
||||
.ai-bottom-tools {
|
||||
display: flex;
|
||||
@@ -1192,6 +1200,10 @@ onBeforeUnmount(() => {
|
||||
.ai-task-progress--warn .ai-task-progress-dot {
|
||||
animation-duration: 3.2s;
|
||||
}
|
||||
/* 警示档(静默>10min)状态点转琥珀:给判断材料,不自动判死 */
|
||||
.ai-task-progress--warn .ai-task-progress-dot {
|
||||
background: var(--df-warning);
|
||||
}
|
||||
.ai-task-progress-stage {
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
@@ -1200,39 +1212,45 @@ onBeforeUnmount(() => {
|
||||
font-size: 11px;
|
||||
color: color-mix(in srgb, var(--df-warning) 70%, var(--df-text-secondary));
|
||||
}
|
||||
/* ═══ Provider Bar (header 中间区;div→button 后归零默认样式) ═══ */
|
||||
/* ═══ Provider Bar (header 中间区)
|
||||
2026-10-18 wave2:对齐 workbench .session-status pill 范式——bg-card 底+边框+8px 圆角+12px 字,
|
||||
状态点迁 .df-dot(7px 尺寸由全局公共类提供);div→button 后归零默认样式 ═══ */
|
||||
.ai-provider-bar {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 11px;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
white-space: nowrap;
|
||||
font-family: inherit;
|
||||
appearance: none;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-md);
|
||||
padding: 4px 12px;
|
||||
transition: border-color 0.15s var(--df-ease);
|
||||
}
|
||||
.ai-provider-bar--switchable {
|
||||
cursor: pointer;
|
||||
}
|
||||
.ai-provider-bar--switchable:hover {
|
||||
color: var(--df-text-primary);
|
||||
border-color: var(--df-border-strong);
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ai-provider-bar--switchable:focus-visible {
|
||||
outline: 1.5px solid var(--df-accent, #4a9eff);
|
||||
outline: 1.5px solid var(--df-accent);
|
||||
outline-offset: 2px;
|
||||
border-radius: 2px;
|
||||
border-radius: var(--df-radius-md);
|
||||
}
|
||||
/* provider 连通状态点:灰=未测/绿=最近成功/红=最近失败(基于最后 assistant 消息 isError) */
|
||||
.provider-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--df-text-dim); flex-shrink: 0; transition: background .2s; }
|
||||
/* provider 连通状态点:灰=未测/绿=最近成功/红=最近失败(基于最后 assistant 消息 isError);
|
||||
尺寸/圆角走全局 .df-dot,此处只管色 */
|
||||
.provider-dot { flex-shrink: 0; transition: background .2s; background: var(--df-text-dim); }
|
||||
.provider-dot--ok { background: var(--df-success); }
|
||||
.provider-dot--error { background: var(--df-danger); }
|
||||
.provider-name {
|
||||
font-size: 11px;
|
||||
font-size: 12px;
|
||||
font-family: var(--df-font-mono);
|
||||
color: var(--df-text-dim);
|
||||
color: var(--df-text-secondary);
|
||||
}
|
||||
.ai-provider-empty {
|
||||
background: var(--df-danger-bg);
|
||||
@@ -1265,7 +1283,7 @@ onBeforeUnmount(() => {
|
||||
appearance: none;
|
||||
}
|
||||
.ai-tool-badge:focus-visible {
|
||||
outline: 1.5px solid var(--df-accent, #4a9eff);
|
||||
outline: 1.5px solid var(--df-accent);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
.ai-tool-badge svg { vertical-align: middle; } /* 图标在行高内垂直居中(与数字同基线)*/
|
||||
@@ -1291,11 +1309,17 @@ onBeforeUnmount(() => {
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
/* wave2:后台会话徽章迁 .df-badge--info(透明彩底 info 系);scoped 需显式覆写压过 .ai-tool-badge 灰底 */
|
||||
.ai-running-tasks-badge.df-badge--info {
|
||||
background: var(--df-info-bg);
|
||||
color: var(--df-info);
|
||||
border-color: color-mix(in srgb, var(--df-info) 30%, transparent);
|
||||
}
|
||||
.ai-running-tasks-pulse {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-success, #34c77b);
|
||||
background: var(--df-success);
|
||||
animation: ai-running-pulse 2s ease-in-out infinite;
|
||||
}
|
||||
@keyframes ai-running-pulse {
|
||||
@@ -1311,9 +1335,9 @@ onBeforeUnmount(() => {
|
||||
max-width: 400px;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
background: var(--df-bg);
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
border-radius: var(--df-radius);
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
padding: 4px 0;
|
||||
}
|
||||
@@ -1331,14 +1355,14 @@ onBeforeUnmount(() => {
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ai-running-task-item:hover {
|
||||
background: var(--df-hover, rgba(128,128,128,0.08));
|
||||
background: var(--df-bg-card-hover);
|
||||
}
|
||||
.ai-running-task-dot {
|
||||
flex-shrink: 0;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--df-success, #34c77b);
|
||||
background: var(--df-success);
|
||||
}
|
||||
.ai-running-task-title {
|
||||
flex: 1;
|
||||
@@ -1349,7 +1373,7 @@ onBeforeUnmount(() => {
|
||||
.ai-running-task-round {
|
||||
flex-shrink: 0;
|
||||
font-size: 11px;
|
||||
color: var(--df-text-secondary, #888);
|
||||
color: var(--df-text-secondary);
|
||||
}
|
||||
/* V49 可恢复分区:琥珀点+「可恢复」徽标,与进行中(绿)区分 */
|
||||
.ai-running-tasks-sep {
|
||||
@@ -1358,7 +1382,7 @@ onBeforeUnmount(() => {
|
||||
background: var(--df-border);
|
||||
}
|
||||
.ai-running-task-dot--parked {
|
||||
background: var(--df-warning, #e6a23c);
|
||||
background: var(--df-warning);
|
||||
}
|
||||
/* B4 parked 行改双钮布局(切回 | 恢复),恢复钮琥珀描边醒目 */
|
||||
.ai-running-task-item--parked {
|
||||
@@ -1385,21 +1409,21 @@ onBeforeUnmount(() => {
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ai-running-task-main:hover {
|
||||
background: var(--df-hover, rgba(128,128,128,0.08));
|
||||
background: var(--df-bg-card-hover);
|
||||
}
|
||||
.ai-running-task-recover {
|
||||
flex-shrink: 0;
|
||||
margin-right: 10px;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid var(--df-warning, #e6a23c);
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--df-warning);
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 11px;
|
||||
color: var(--df-warning, #e6a23c);
|
||||
color: var(--df-warning);
|
||||
}
|
||||
.ai-running-task-recover:hover {
|
||||
background: var(--df-warning, #e6a23c);
|
||||
background: var(--df-warning);
|
||||
color: #fff;
|
||||
}
|
||||
.ai-history-inline-list {
|
||||
@@ -1411,9 +1435,9 @@ onBeforeUnmount(() => {
|
||||
max-width: 400px;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
background: var(--df-bg);
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
border-radius: var(--df-radius);
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
padding: 4px 0;
|
||||
margin-top: 2px;
|
||||
@@ -1454,6 +1478,13 @@ onBeforeUnmount(() => {
|
||||
color: var(--df-text-dim);
|
||||
font-family: var(--df-font-mono);
|
||||
}
|
||||
/* F6-1:历史/摘要定位未命中提示(目标消息在折叠段内,引导展开分隔条) */
|
||||
.ai-locate-miss {
|
||||
padding: 6px 10px;
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
color: var(--df-warning);
|
||||
}
|
||||
|
||||
/* ═══ 上下文摘要(底部) ═══ */
|
||||
.ai-summary-inline {
|
||||
@@ -1470,9 +1501,9 @@ onBeforeUnmount(() => {
|
||||
max-width: 420px;
|
||||
max-height: 360px;
|
||||
overflow-y: auto;
|
||||
background: var(--df-bg);
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
border-radius: var(--df-radius);
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
padding: 6px 0;
|
||||
margin-top: 2px;
|
||||
@@ -1518,9 +1549,9 @@ onBeforeUnmount(() => {
|
||||
z-index: 100;
|
||||
min-width: 280px;
|
||||
max-width: 420px;
|
||||
background: var(--df-bg);
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
border-radius: var(--df-radius);
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
margin-top: 2px;
|
||||
}
|
||||
@@ -1571,9 +1602,9 @@ onBeforeUnmount(() => {
|
||||
z-index: 100;
|
||||
min-width: 200px;
|
||||
max-width: 360px;
|
||||
background: var(--df-bg, #fff);
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
border-radius: var(--df-radius);
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
padding: 4px 0;
|
||||
margin-top: 2px;
|
||||
@@ -1601,7 +1632,7 @@ onBeforeUnmount(() => {
|
||||
.ai-goal-check { color: var(--df-success); font-weight: 500; flex-shrink: 0; }
|
||||
.ai-goal-remove { border: none; background: transparent; color: var(--df-text-dim); cursor: pointer; padding: 0 2px; font-size: 13px; line-height: 1; flex-shrink: 0; }
|
||||
.ai-goal-remove:hover {
|
||||
color: var(--df-danger, #e5484d);
|
||||
color: var(--df-danger);
|
||||
}
|
||||
.provider-hint {
|
||||
font-size: 11px;
|
||||
|
||||
@@ -0,0 +1,913 @@
|
||||
<template>
|
||||
<!-- ═══ 会话列表体(拆自 ConversationSidebar.vue C4a,零行为变更) ═══ -->
|
||||
<!-- UX-06 §3.1: 搜索态(searchResults 非 null)→ 平铺,活跃+归档全量按 updated_at DESC -->
|
||||
<template v-if="searchResults">
|
||||
<div
|
||||
v-for="conv in searchResults"
|
||||
:key="'s-' + conv.id"
|
||||
class="ai-conv-item"
|
||||
:class="{
|
||||
'ai-conv-item--active': conv.id === store.state.activeConversationId,
|
||||
'ai-conv-item--switching': conv.id === pendingSwitchId,
|
||||
'ai-conv-item--archived': conv.archived,
|
||||
'ai-conv-item--pinned': conv.pinned,
|
||||
}"
|
||||
tabindex="0"
|
||||
@click="onSelectSearchResult(conv.id)"
|
||||
@keydown="onItemKeydown($event, conv.id, true)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2 u-agent 范式: 左侧 7px 状态点。字段源 store.isGenerating(conv_state
|
||||
generating/stopping/compressed) / pendingCountOf(审批挂起) / loop_state='parked',
|
||||
无 error 字段故不映射;优先级 generating > 待审批 > parked > 灰 -->
|
||||
<span
|
||||
class="df-dot ai-conv-status"
|
||||
:class="store.isGenerating(conv.id) ? 'df-dot--run ai-conv-status--run'
|
||||
: pendingCountOf(conv.id) > 0 ? 'ai-conv-status--danger'
|
||||
: conv.loop_state === 'parked' ? 'ai-conv-status--paused'
|
||||
: 'df-dot--stop'"
|
||||
:title="store.isGenerating(conv.id) ? t('aiChat.generating') : undefined"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
<!-- UX走查 P3-1: 搜索态此前无重命名入口(无 startRename 分支),与分组视图降级不一致;
|
||||
双击入口对齐分组视图,菜单入口供键盘用户(P2-6) -->
|
||||
<input
|
||||
v-if="editingConvId === conv.id"
|
||||
:ref="setEditEl"
|
||||
v-model="editText"
|
||||
class="ai-conv-item-edit"
|
||||
@keydown="onRenameKeydown($event, conv.id)"
|
||||
@blur="commitRename(conv.id)"
|
||||
@click.stop
|
||||
/>
|
||||
<span
|
||||
v-else
|
||||
class="ai-conv-item-title"
|
||||
:title="conv.title || t('aiChat.doubleClickToRename')"
|
||||
@dblclick.stop="startRename(conv)"
|
||||
>
|
||||
{{ conv.title || t('aiChat.newConversation') }}
|
||||
<!-- V1: 待审批徽标(橙点计数,复用既有 aiChat.pendingApprovalCount 文案) -->
|
||||
<span v-if="pendingCountOf(conv.id) > 0" class="ai-conv-approve-badge" :title="t('aiChat.pendingApprovalCount', { n: pendingCountOf(conv.id) })">{{ pendingCountOf(conv.id) }}</span>
|
||||
<!-- 无人值守边界徽标:该会话已授权任务边界(镜像渐进填充);点击随会话切回显 -->
|
||||
<span v-if="hasBoundary(conv.id)" class="ai-conv-boundary-badge" :title="t('ai.taskBoundary.badge')">
|
||||
<svg aria-hidden="true" width="8" height="8" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3z"/></svg>
|
||||
</span>
|
||||
</span>
|
||||
<span class="ai-conv-item-time">{{ formatRelative(conv.updated_at) }}</span>
|
||||
</div>
|
||||
<div class="ai-conv-item-actions">
|
||||
<div class="ai-conv-item-more">
|
||||
<button class="ai-conv-item-act" @click.stop="toggleActionsMenu(conv.id)" :title="t('aiChat.moreActions')" :aria-label="t('aiChat.moreActions')">
|
||||
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="2"/><circle cx="12" cy="12" r="2"/><circle cx="19" cy="12" r="2"/></svg>
|
||||
</button>
|
||||
<div v-if="actionsOpenId === conv.id" class="ai-conv-actions-menu">
|
||||
<button class="ai-conv-actions-opt" @click.stop="startRename(conv); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.828 2.828 0 114 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>
|
||||
{{ t('aiChat.renameConversation') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt" @click.stop="store.setPinnedConversation(conv.id, !conv.pinned); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" :fill="conv.pinned ? 'currentColor' : 'none'" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 01-1.11 1.79l-1.78.9A2 2 0 005 15.24V16a1 1 0 001 1h12a1 1 0 001-1v-.76a2 2 0 00-1.11-1.79l-1.78-.9A2 2 0 0115 10.76V7a1 1 0 011-1 2 2 0 002-2V3H6v1a2 2 0 002 2 1 1 0 011 1z"/></svg>
|
||||
{{ conv.pinned ? t('aiChat.unpinConversation') : t('aiChat.pinConversation') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt" @click.stop="store.archiveConversation(conv.id, !conv.archived); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="5" rx="1"/><path d="M4 9v9a2 2 0 002 2h12a2 2 0 002-2V9"/><line x1="10" y1="13" x2="14" y2="13"/></svg>
|
||||
{{ conv.archived ? t('aiChat.unarchive') : t('aiChat.archive') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt ai-conv-actions-opt--danger" @click.stop="emit('confirm-delete', conv.id); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
{{ t('common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="searchResults.length === 0" class="ai-conv-empty">
|
||||
{{ t('aiChat.searchEmpty') }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 非搜索态:原时间分组(活跃) + 归档分组 -->
|
||||
<template v-else>
|
||||
<!-- 活跃对话:按 今天/昨天/更早 分组 -->
|
||||
<template v-for="group in groupedActive" :key="'g-' + group.key">
|
||||
<div
|
||||
class="ai-conv-group-title ai-conv-group-title--fold"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-expanded="!store.state.foldedGroups[group.key]"
|
||||
@click="store.toggleGroupFold(group.key)"
|
||||
@keydown.enter.prevent="store.toggleGroupFold(group.key)"
|
||||
@keydown.space.prevent="store.toggleGroupFold(group.key)"
|
||||
>
|
||||
<span class="ai-conv-group-arrow" :class="{ 'is-folded': store.state.foldedGroups[group.key] }">▸</span>
|
||||
{{ group.label }}
|
||||
<span class="ai-conv-group-count">({{ group.items.length }})</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="group.key === 'today' && !group.items.length"
|
||||
v-show="!store.state.foldedGroups[group.key]"
|
||||
class="ai-conv-group-empty"
|
||||
>{{ t('aiChat.groupEmpty') }}</div>
|
||||
<div
|
||||
v-for="conv in group.items"
|
||||
v-show="!store.state.foldedGroups[group.key]"
|
||||
:key="conv.id"
|
||||
:ref="(el) => setItemEl(conv.id, el)"
|
||||
class="ai-conv-item"
|
||||
:class="{ 'ai-conv-item--active': conv.id === store.state.activeConversationId, 'ai-conv-item--switching': conv.id === pendingSwitchId, 'ai-conv-item--pinned': conv.pinned }"
|
||||
tabindex="0"
|
||||
@click="beginSwitch(conv.id)"
|
||||
@keydown="onItemKeydown($event, conv.id, true)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2 u-agent 范式: 左侧 7px 状态点(映射源同搜索态块注) -->
|
||||
<span
|
||||
class="df-dot ai-conv-status"
|
||||
:class="store.isGenerating(conv.id) ? 'df-dot--run ai-conv-status--run'
|
||||
: pendingCountOf(conv.id) > 0 ? 'ai-conv-status--danger'
|
||||
: conv.loop_state === 'parked' ? 'ai-conv-status--paused'
|
||||
: 'df-dot--stop'"
|
||||
:title="store.isGenerating(conv.id) ? t('aiChat.generating') : undefined"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
<input
|
||||
v-if="editingConvId === conv.id"
|
||||
:ref="setEditEl"
|
||||
v-model="editText"
|
||||
class="ai-conv-item-edit"
|
||||
@keydown="onRenameKeydown($event, conv.id)"
|
||||
@blur="commitRename(conv.id)"
|
||||
@click.stop
|
||||
/>
|
||||
<span
|
||||
v-else
|
||||
class="ai-conv-item-title"
|
||||
:class="{ 'ai-conv-item-title--flash': titleFlash && conv.id === store.state.activeConversationId }"
|
||||
@dblclick.stop="startRename(conv)"
|
||||
:title="conv.title || t('aiChat.doubleClickToRename')"
|
||||
>
|
||||
{{ conv.title || t('aiChat.newConversation') }}
|
||||
<!-- UX-2025-20 §7.4:AI 生成标题标识小图标(标题非空非占位时显示) -->
|
||||
<svg aria-hidden="true"
|
||||
v-if="conv.title && titleFlash && conv.id === store.state.activeConversationId"
|
||||
class="ai-conv-item-title-badge"
|
||||
width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"
|
||||
><polyline points="20 6 9 17 4 12"/></svg>
|
||||
<!-- V1: 待审批徽标(橙点计数,复用既有 aiChat.pendingApprovalCount 文案) -->
|
||||
<span v-if="pendingCountOf(conv.id) > 0" class="ai-conv-approve-badge" :title="t('aiChat.pendingApprovalCount', { n: pendingCountOf(conv.id) })">{{ pendingCountOf(conv.id) }}</span>
|
||||
<!-- 无人值守边界徽标:该会话已授权任务边界(镜像渐进填充);点击随会话切回显 -->
|
||||
<span v-if="hasBoundary(conv.id)" class="ai-conv-boundary-badge" :title="t('ai.taskBoundary.badge')">
|
||||
<svg aria-hidden="true" width="8" height="8" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3z"/></svg>
|
||||
</span>
|
||||
</span>
|
||||
<span class="ai-conv-item-time">{{ formatRelative(conv.updated_at) }}</span>
|
||||
</div>
|
||||
<div class="ai-conv-item-actions">
|
||||
<div class="ai-conv-item-more">
|
||||
<button class="ai-conv-item-act" @click.stop="toggleActionsMenu(conv.id)" :title="t('aiChat.moreActions')" :aria-label="t('aiChat.moreActions')">
|
||||
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="2"/><circle cx="12" cy="12" r="2"/><circle cx="19" cy="12" r="2"/></svg>
|
||||
</button>
|
||||
<div v-if="actionsOpenId === conv.id" class="ai-conv-actions-menu">
|
||||
<button class="ai-conv-actions-opt" @click.stop="startRename(conv); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.828 2.828 0 114 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>
|
||||
{{ t('aiChat.renameConversation') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt" @click.stop="store.setPinnedConversation(conv.id, !conv.pinned); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" :fill="conv.pinned ? 'currentColor' : 'none'" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 01-1.11 1.79l-1.78.9A2 2 0 005 15.24V16a1 1 0 001 1h12a1 1 0 001-1v-.76a2 2 0 00-1.11-1.79l-1.78-.9A2 2 0 0115 10.76V7a1 1 0 011-1 2 2 0 002-2V3H6v1a2 2 0 002 2 1 1 0 011 1z"/></svg>
|
||||
{{ conv.pinned ? t('aiChat.unpinConversation') : t('aiChat.pinConversation') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt" @click.stop="store.archiveConversation(conv.id, true); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="5" rx="1"/><path d="M4 9v9a2 2 0 002 2h12a2 2 0 002-2V9"/><line x1="10" y1="13" x2="14" y2="13"/></svg>
|
||||
{{ t('aiChat.archive') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt ai-conv-actions-opt--danger" @click.stop="emit('confirm-delete', conv.id); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
{{ t('common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- G5 可恢复分组(loop_state='parked',断点续跑闭环读侧;置于活跃分组后、归档前) -->
|
||||
<template v-if="recoverable.length">
|
||||
<div class="ai-conv-group-title">
|
||||
<span class="ai-conv-recover-dot" aria-hidden="true"></span>
|
||||
{{ t('aiChat.recoverableCount', { n: recoverable.length }) }}
|
||||
</div>
|
||||
<div
|
||||
v-for="conv in recoverable"
|
||||
:key="'r-' + conv.id"
|
||||
class="ai-conv-item ai-conv-item--recoverable"
|
||||
:class="{ 'ai-conv-item--active': conv.id === store.state.activeConversationId }"
|
||||
tabindex="0"
|
||||
:title="t('aiChat.recoverableHint')"
|
||||
@click="onRecover(conv.id)"
|
||||
@keydown.enter.prevent="onRecover(conv.id)"
|
||||
@keydown.space.prevent="onRecover(conv.id)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2: 本组数据源 ai_list_recoverable(loop_state='parked' 完备真相),整组恒 parked→静态琥珀点 -->
|
||||
<span class="df-dot ai-conv-status ai-conv-status--paused" aria-hidden="true"></span>
|
||||
<span class="ai-conv-item-title">
|
||||
{{ conv.title || t('aiChat.newConversation') }}
|
||||
<span class="ai-conv-recover-badge">⏸</span>
|
||||
</span>
|
||||
<span class="ai-conv-item-time">{{ formatRelative(conv.updated_at) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 归档分组(可折叠) -->
|
||||
<template v-if="archivedConvs.length">
|
||||
<div
|
||||
class="ai-conv-group-title ai-conv-group-title--fold"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-expanded="!store.state.archivedCollapsed"
|
||||
@click="store.toggleArchivedFold()"
|
||||
@keydown.enter.prevent="store.toggleArchivedFold()"
|
||||
@keydown.space.prevent="store.toggleArchivedFold()"
|
||||
>
|
||||
<span class="ai-conv-group-arrow" :class="{ 'is-folded': store.state.archivedCollapsed }">▸</span>
|
||||
{{ t('aiChat.archivedCount', { n: archivedConvs.length }) }}
|
||||
</div>
|
||||
<div
|
||||
v-for="conv in archivedConvs"
|
||||
v-show="!store.state.archivedCollapsed"
|
||||
:key="'a-' + conv.id"
|
||||
:ref="(el) => setItemEl(conv.id, el)"
|
||||
class="ai-conv-item ai-conv-item--archived"
|
||||
:class="{ 'ai-conv-item--active': conv.id === store.state.activeConversationId, 'ai-conv-item--switching': conv.id === pendingSwitchId, 'ai-conv-item--pinned': conv.pinned }"
|
||||
tabindex="0"
|
||||
@click="beginSwitch(conv.id)"
|
||||
@keydown="onItemKeydown($event, conv.id)"
|
||||
>
|
||||
<div class="ai-conv-item-main">
|
||||
<!-- wave2 u-agent 范式: 归档项同款状态点(归档为静息态,默认落灰) -->
|
||||
<span
|
||||
class="df-dot ai-conv-status"
|
||||
:class="store.isGenerating(conv.id) ? 'df-dot--run ai-conv-status--run'
|
||||
: pendingCountOf(conv.id) > 0 ? 'ai-conv-status--danger'
|
||||
: conv.loop_state === 'parked' ? 'ai-conv-status--paused'
|
||||
: 'df-dot--stop'"
|
||||
:title="store.isGenerating(conv.id) ? t('aiChat.generating') : undefined"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
<span class="ai-conv-item-title" :title="conv.title || ''">
|
||||
{{ conv.title || t('aiChat.newConversation') }}
|
||||
<!-- V1: 待审批徽标(橙点计数,复用既有 aiChat.pendingApprovalCount 文案) -->
|
||||
<span v-if="pendingCountOf(conv.id) > 0" class="ai-conv-approve-badge" :title="t('aiChat.pendingApprovalCount', { n: pendingCountOf(conv.id) })">{{ pendingCountOf(conv.id) }}</span>
|
||||
<!-- 无人值守边界徽标:该会话已授权任务边界(镜像渐进填充);点击随会话切回显 -->
|
||||
<span v-if="hasBoundary(conv.id)" class="ai-conv-boundary-badge" :title="t('ai.taskBoundary.badge')">
|
||||
<svg aria-hidden="true" width="8" height="8" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3z"/></svg>
|
||||
</span>
|
||||
</span>
|
||||
<span class="ai-conv-item-time">{{ formatRelative(conv.updated_at) }}</span>
|
||||
</div>
|
||||
<div class="ai-conv-item-actions">
|
||||
<div class="ai-conv-item-more">
|
||||
<button class="ai-conv-item-act" @click.stop="toggleActionsMenu(conv.id)" :title="t('aiChat.moreActions')" :aria-label="t('aiChat.moreActions')">
|
||||
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="2"/><circle cx="12" cy="12" r="2"/><circle cx="19" cy="12" r="2"/></svg>
|
||||
</button>
|
||||
<div v-if="actionsOpenId === conv.id" class="ai-conv-actions-menu">
|
||||
<button class="ai-conv-actions-opt" @click.stop="store.setPinnedConversation(conv.id, !conv.pinned); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" :fill="conv.pinned ? 'currentColor' : 'none'" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 01-1.11 1.79l-1.78.9A2 2 0 005 15.24V16a1 1 0 001 1h12a1 1 0 001-1v-.76a2 2 0 00-1.11-1.79l-1.78-.9A2 2 0 0115 10.76V7a1 1 0 011-1 2 2 0 002-2V3H6v1a2 2 0 002 2 1 1 0 011 1z"/></svg>
|
||||
{{ conv.pinned ? t('aiChat.unpinConversation') : t('aiChat.pinConversation') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt" @click.stop="store.archiveConversation(conv.id, false); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="5" rx="1"/><path d="M4 9v9a2 2 0 002 2h12a2 2 0 002-2V9"/><line x1="12" y1="13" x2="12" y2="17"/><polyline points="10 15 12 13 14 15"/></svg>
|
||||
{{ t('aiChat.unarchive') }}
|
||||
</button>
|
||||
<button class="ai-conv-actions-opt ai-conv-actions-opt--danger" @click.stop="emit('confirm-delete', conv.id); closeActionsMenu()">
|
||||
<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
{{ t('common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- F4-1: 会话列表分页——底部「加载更多」续拉下一页(首屏 50/组,归档组同口径放开) -->
|
||||
<div
|
||||
v-if="convListPaging.hasMore"
|
||||
class="ai-conv-load-more"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@click="onLoadMore"
|
||||
@keydown.enter.prevent="onLoadMore"
|
||||
@keydown.space.prevent="onLoadMore"
|
||||
>{{ convListPaging.loading ? t('common.loading') : t('gitChanges.loadMore') }}</div>
|
||||
|
||||
<div v-if="store.state.conversations.length === 0" class="ai-conv-empty">
|
||||
{{ t('aiChat.emptyConversation') }}
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 会话列表体 — 拆自 ConversationSidebar.vue(C4a 大文件拆分,零行为变更)。
|
||||
*
|
||||
* 职责:侧栏列表两态渲染(搜索态平铺 / 时间分组+可恢复+归档)及项级自治状态:
|
||||
* 重命名(editingConvId/editText)、更多操作菜单(actionsOpenId + document 级外部点击/Esc 关闭)、
|
||||
* 切换过渡(pendingSwitchId)、项 DOM ref 收集(M3 展开折叠组后 scrollIntoView)、
|
||||
* 标题生成淡入(titleFlash)、时间分组归桶(groupedActive/archivedConvs)。
|
||||
*
|
||||
* 跨文件依赖(策略同侧栏第一批:store 共享走 useAiStore,不 props 传 store):
|
||||
* - props.pendingCountOf:V1 待审批计数(主文件 computed + 2.5s 轮询兜底锚定,函数透传保响应式);
|
||||
* - props.recoverable:G5 可恢复清单(主文件 onMounted 拉取,侧栏开合不重复 IPC),恢复动作 emit('recover');
|
||||
* - emit('confirm-delete'):删除需父级 ConfirmDialog,侧栏主文件继续上抛 AiChat。
|
||||
* 边界徽标只读消费 getConvBoundary(reactive Map,模板内读取可追踪),直接 import 同源 composable。
|
||||
*/
|
||||
import { ref, computed, nextTick, watch, onMounted, onBeforeUnmount, type ComponentPublicInstance } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useAiStore } from '../../../stores/ai'
|
||||
import { getConvBoundary } from '../../../composables/ai/useTaskBoundary'
|
||||
import { convListPaging, loadMoreConversations } from '../../../composables/ai/useAiConversations'
|
||||
import { formatRelative } from '../../../utils/time'
|
||||
import type { AiConversationSummary } from '../../../api/types'
|
||||
|
||||
/** G5 可恢复会话条目(主文件数据源透传,字段口径同 aiApi.listRecoverable) */
|
||||
interface RecoverableConv { id: string; title: string | null; model: string | null; updated_at: string }
|
||||
|
||||
defineProps<{
|
||||
/** V1 跨会话待审批计数(主文件 computed:三响应式源锚定 + 轮询兜底;函数透传,模板调用可追踪) */
|
||||
pendingCountOf: (convId: string) => number
|
||||
/** G5 可恢复分组数据(主文件拉取与防重,本组件纯渲染 + emit 恢复动作) */
|
||||
recoverable: RecoverableConv[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 删除对话(需二次确认),上抛侧栏主文件继续交 AiChat 弹 ConfirmDialog */
|
||||
(e: 'confirm-delete', id: string): void
|
||||
/** G5 恢复 parked 会话,主文件持 recoveringId 防重 + toast 反馈 */
|
||||
(e: 'recover', id: string): void
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const store = useAiStore()
|
||||
|
||||
// ── 标题生成淡入(UX-2025-20 §7.4):监听当前对话标题从空→非空触发 ──
|
||||
const titleFlash = ref(false)
|
||||
let _titleFlashTimer: ReturnType<typeof setTimeout> | null = null
|
||||
const activeConv = computed(() =>
|
||||
store.state.conversations.find(c => c.id === store.state.activeConversationId) || null,
|
||||
)
|
||||
watch(
|
||||
() => activeConv.value?.title,
|
||||
(newTitle, oldTitle) => {
|
||||
// 标题从空→非空才触发淡入,其他变化不闪
|
||||
if (!newTitle || oldTitle) return
|
||||
titleFlash.value = true
|
||||
if (_titleFlashTimer) clearTimeout(_titleFlashTimer)
|
||||
_titleFlashTimer = setTimeout(() => { titleFlash.value = false }, 320)
|
||||
},
|
||||
)
|
||||
|
||||
// ── 对话项 inline 重命名 ──
|
||||
const editingConvId = ref<string | null>(null)
|
||||
const editText = ref('')
|
||||
let editEl: HTMLInputElement | null = null
|
||||
function setEditEl(el: Element | { $el?: Element } | null): void {
|
||||
editEl = (el as HTMLInputElement) || null
|
||||
}
|
||||
|
||||
function startRename(conv: { id: string; title: string | null }) {
|
||||
editingConvId.value = conv.id
|
||||
editText.value = conv.title || ''
|
||||
nextTick(() => {
|
||||
editEl?.focus()
|
||||
editEl?.select()
|
||||
})
|
||||
}
|
||||
|
||||
async function commitRename(id: string) {
|
||||
const title = editText.value.trim()
|
||||
if (title && editingConvId.value === id) {
|
||||
await store.renameConversation(id, title)
|
||||
}
|
||||
editingConvId.value = null
|
||||
}
|
||||
|
||||
function cancelRename() {
|
||||
editingConvId.value = null
|
||||
}
|
||||
|
||||
/** P1-1 重命名框键盘处理:输入法组词中(isComposing/229)的 Enter/Esc 属 IME 选词/取消组词,
|
||||
* 不当重命名提交/取消处理,防标题被半截拼音覆盖。原 keyup.enter/.esc 改 keydown 统一挂守卫:
|
||||
* 组词上屏的回车到 keyup 阶段 isComposing 已复位守不住,keydown 才拦得到。 */
|
||||
function onRenameKeydown(e: KeyboardEvent, convId: string) {
|
||||
if (e.isComposing || e.keyCode === 229) return
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
commitRename(convId)
|
||||
} else if (e.key === 'Escape') {
|
||||
e.preventDefault()
|
||||
cancelRename()
|
||||
}
|
||||
}
|
||||
|
||||
// UX走查 P2-6: 会话项键盘可达(tabindex=0)。Enter/Space 等价点击选中;仅焦点落在本项 div
|
||||
// 自身时处理——焦点在内部按钮/重命名输入框时 target≠currentTarget,避免与控件自身语义双触发。
|
||||
// renamable=true 的会话项(搜索结果/时间分组,即双击标题可重命名的项)额外支持 F2 键盘重命名,
|
||||
// 作为 .ai-conv-item-title 双击入口的键盘等价(文件管理器惯例;归档项不支持重命名故不传该标志)。
|
||||
function onItemKeydown(e: KeyboardEvent, convId: string, renamable = false) {
|
||||
if (e.isComposing || e.keyCode === 229) return
|
||||
if (e.target !== e.currentTarget) return
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
beginSwitch(convId)
|
||||
} else if (renamable && e.key === 'F2') {
|
||||
e.preventDefault()
|
||||
const conv = store.state.conversations.find(c => c.id === convId)
|
||||
if (conv) startRename(conv)
|
||||
}
|
||||
}
|
||||
|
||||
// ── 会话项「更多」操作菜单(置顶/归档/删除)──
|
||||
const actionsOpenId = ref<string | null>(null)
|
||||
|
||||
function toggleActionsMenu(id: string) {
|
||||
actionsOpenId.value = actionsOpenId.value === id ? null : id
|
||||
}
|
||||
|
||||
function closeActionsMenu() {
|
||||
actionsOpenId.value = null
|
||||
}
|
||||
|
||||
// 点击外部关闭更多操作菜单
|
||||
function onActionsOutsideClick(e: MouseEvent) {
|
||||
if (!actionsOpenId.value) return
|
||||
const target = e.target as HTMLElement | null
|
||||
if (target?.closest('.ai-conv-item-more')) return
|
||||
actionsOpenId.value = null
|
||||
}
|
||||
|
||||
// UX走查 P2-6: 操作菜单原仅外部点击可关,键盘用户开菜单后无 Esc 逃逸;IME 守卫防组词取消误关
|
||||
function onActionsEscClose(e: KeyboardEvent) {
|
||||
if (!actionsOpenId.value) return
|
||||
if (e.isComposing || e.keyCode === 229) return
|
||||
if (e.key === 'Escape') actionsOpenId.value = null
|
||||
}
|
||||
|
||||
// ── 会话切换过渡态(UX走查 2026-10-03 P1):点击即预高亮目标项(乐观),IPC 返回后随
|
||||
// activeConversationId 落定接管高亮;失败/过期时 finally 清 pending,高亮自动回滚到原活跃项。
|
||||
// 治:大历史会话 IPC 数百 ms 期间点击项不高亮、原高亮不动、无任何进行时反馈,快速连点像失灵。
|
||||
const pendingSwitchId = ref<string | null>(null)
|
||||
function beginSwitch(id: string) {
|
||||
// 已活跃会话:switchConversation 内部同判短路,无过渡期,不挂 pending
|
||||
if (id === store.state.activeConversationId) {
|
||||
void store.switchConversation(id)
|
||||
return
|
||||
}
|
||||
pendingSwitchId.value = id
|
||||
void store.switchConversation(id).finally(() => {
|
||||
// 仅当 pending 仍是本次点击的 id 才清:快速连点 B 覆盖 A 后,A 的迟到返回不得清掉 B 的过渡态
|
||||
if (pendingSwitchId.value === id) pendingSwitchId.value = null
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索结果点击切对话后清空 searchQuery,退出搜索模式回原时间分组视图。
|
||||
* M3:命中项可能在折叠的时间分组或折叠的归档分组内,选中态不可见。切回分组视图后展开所在分组
|
||||
* 并 scrollIntoView,确保选中项立即可见(原仅切 searchQuery,选中项落在折叠组里看不到高亮)。
|
||||
*/
|
||||
function onSelectSearchResult(id: string) {
|
||||
// 走 beginSwitch 挂切换过渡态(乐观预高亮),与分组视图点击口径一致
|
||||
beginSwitch(id)
|
||||
store.state.searchQuery = ''
|
||||
// nextTick 后视图已切回分组态;ensureVisible 展开所在组 + 滚动定位
|
||||
void nextTick(() => ensureActiveVisible())
|
||||
}
|
||||
|
||||
// ── M3:活跃会话项 DOM ref 收集(id → el),用于展开折叠组后 scrollIntoView ──
|
||||
// Vue 3 函数 ref:每项 :ref="(el) => setItemEl(id, el)"。卸载时 el 为 null,删 key 防 Map 泄漏。
|
||||
const itemEls = new Map<string, Element>()
|
||||
function setItemEl(id: string, el: Element | ComponentPublicInstance | null): void {
|
||||
if (!el) {
|
||||
itemEls.delete(id)
|
||||
return
|
||||
}
|
||||
// 组件实例取 $el,但本项是普通 div(el 即 Element)
|
||||
itemEls.set(id, el as Element)
|
||||
}
|
||||
|
||||
/**
|
||||
* M3:确保当前活跃会话在分组视图可见。若它落在折叠的时间分组(今天/昨天/更早)或折叠的归档分组,
|
||||
* 展开该组让 v-show 渲染出来,再 scrollIntoView。用于搜索点选、切对话后选中态不被折叠吞掉。
|
||||
*/
|
||||
function ensureActiveVisible(): void {
|
||||
const id = store.state.activeConversationId
|
||||
if (!id) return
|
||||
const conv = store.state.conversations.find(c => c.id === id)
|
||||
if (!conv) return
|
||||
// 先按归档态/时间桶决定应展开哪个组折叠态
|
||||
if (conv.archived) {
|
||||
if (store.state.archivedCollapsed) store.state.archivedCollapsed = false
|
||||
} else {
|
||||
const bucket = timeBucket(conv.updated_at)
|
||||
if (store.state.foldedGroups[bucket]) store.state.foldedGroups[bucket] = false
|
||||
}
|
||||
// 折叠态翻转后 v-show 需一帧才渲染,再 nextTick 取 el 滚动
|
||||
void nextTick(() => {
|
||||
const el = itemEls.get(id)
|
||||
if (el) {
|
||||
;(el as HTMLElement).scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 该会话是否已授权无人值守边界(徽标显隐)。直接读 reactive Map,渲染效应自动追踪增删 */
|
||||
function hasBoundary(convId: string): boolean {
|
||||
return getConvBoundary(convId) !== null
|
||||
}
|
||||
|
||||
// ── 对话分组:今天 / 昨天 / 更早 ──
|
||||
const bucketLabels = computed<Record<string, string>>(() => ({
|
||||
today: t('aiChat.today'),
|
||||
yesterday: t('aiChat.yesterday'),
|
||||
earlier: t('aiChat.earlier'),
|
||||
}))
|
||||
|
||||
function timeBucket(ts: string): 'today' | 'yesterday' | 'earlier' {
|
||||
const t = parseInt(ts, 10)
|
||||
if (!Number.isFinite(t)) return 'earlier'
|
||||
const d = new Date(t)
|
||||
const now = new Date()
|
||||
const sameDay = d.getFullYear() === now.getFullYear()
|
||||
&& d.getMonth() === now.getMonth()
|
||||
&& d.getDate() === now.getDate()
|
||||
if (sameDay) return 'today'
|
||||
const yest = new Date(now)
|
||||
yest.setDate(now.getDate() - 1)
|
||||
if (d.getFullYear() === yest.getFullYear()
|
||||
&& d.getMonth() === yest.getMonth()
|
||||
&& d.getDate() === yest.getDate()) return 'yesterday'
|
||||
return 'earlier'
|
||||
}
|
||||
|
||||
const groupedActive = computed(() => {
|
||||
const map = new Map<string, AiConversationSummary[]>()
|
||||
for (const c of store.state.conversations) {
|
||||
if (c.archived) continue
|
||||
const b = timeBucket(c.updated_at)
|
||||
if (!map.has(b)) map.set(b, [])
|
||||
map.get(b)!.push(c)
|
||||
}
|
||||
for (const items of map.values()) {
|
||||
items.sort((a, b) => Number(b.pinned ? 1 : 0) - Number(a.pinned ? 1 : 0)
|
||||
|| Number(b.updated_at) - Number(a.updated_at))
|
||||
}
|
||||
const groups: { key: string; label: string; items: AiConversationSummary[] }[] = []
|
||||
for (const key of ['today', 'yesterday', 'earlier']) {
|
||||
const items = map.get(key) || []
|
||||
if (key === 'today' || items.length) groups.push({ key, label: bucketLabels.value[key], items })
|
||||
}
|
||||
return groups
|
||||
})
|
||||
|
||||
const archivedConvs = computed(() =>
|
||||
store.state.conversations
|
||||
.filter(c => c.archived)
|
||||
.sort((a, b) => Number(b.pinned ? 1 : 0) - Number(a.pinned ? 1 : 0)
|
||||
|| Number(b.updated_at) - Number(a.updated_at)),
|
||||
)
|
||||
|
||||
const searchResults = computed<AiConversationSummary[] | null>(
|
||||
() => store.filteredConversations.value,
|
||||
)
|
||||
|
||||
// ── F4-1: 会话列表分页(加载更多按钮 + 搜索全量兜底) ──
|
||||
|
||||
/** 「加载更多」:续拉下一页(失败/无新增静默,按钮 loading 态由 convListPaging 驱动) */
|
||||
function onLoadMore(): void {
|
||||
void loadMoreConversations()
|
||||
}
|
||||
|
||||
/** G5 恢复动作透传主文件(主文件持 recoveringId 防重与 toast 反馈),模板零改动 */
|
||||
function onRecover(id: string) {
|
||||
emit('recover', id)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 点击外部关闭更多操作菜单
|
||||
document.addEventListener('click', onActionsOutsideClick)
|
||||
// 操作菜单 Esc 关闭(P2-6,与外部点击同生命周期)
|
||||
document.addEventListener('keydown', onActionsEscClose)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', onActionsOutsideClick)
|
||||
document.removeEventListener('keydown', onActionsEscClose)
|
||||
// 释放标题淡入计时器
|
||||
if (_titleFlashTimer) { clearTimeout(_titleFlashTimer); _titleFlashTimer = null }
|
||||
})
|
||||
</script>
|
||||
|
||||
<!-- ═══ 会话列表体 scoped 样式(拆自 ConversationSidebar.vue,零视觉变更;列表滚动容器
|
||||
.ai-conv-sidebar/.ai-conv-list 等壳层样式留主文件,本组件只持项/分组/菜单/徽标层) ═══ -->
|
||||
<style scoped>
|
||||
/* wave2 u-agent 范式: 分组头 10px uppercase + letter-spacing 1px + dim */
|
||||
.ai-conv-group-title {
|
||||
padding: 10px 8px 4px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
color: var(--df-text-dim);
|
||||
user-select: none;
|
||||
}
|
||||
.ai-conv-group-title--fold {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
}
|
||||
.ai-conv-group-title--fold:hover {
|
||||
color: var(--df-text);
|
||||
}
|
||||
.ai-conv-group-arrow {
|
||||
display: inline-block;
|
||||
transition: transform 0.15s;
|
||||
font-size: 9px;
|
||||
}
|
||||
.ai-conv-group-arrow.is-folded {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
.ai-conv-group-arrow:not(.is-folded) {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.ai-conv-group-count {
|
||||
margin-left: 2px;
|
||||
font-weight: 400;
|
||||
font-family: var(--df-font-mono); /* mono 计数(df-mono 范式),upper/lsp 回退保证数字不散 */
|
||||
font-size: 10px;
|
||||
letter-spacing: 0;
|
||||
opacity: 0.9;
|
||||
}
|
||||
.ai-conv-group-empty {
|
||||
padding: 2px 8px 4px 20px;
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
font-style: italic;
|
||||
}
|
||||
/* wave2 u-agent .cv 范式: 单行条目,8px 级密度;hover/active 同走灰阶卡底(GitHub 两级同底、
|
||||
active 由左 2px accent 实线区分),深浅主题同 token 自动适配 */
|
||||
.ai-conv-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px;
|
||||
border-radius: var(--df-radius);
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
gap: 6px;
|
||||
}
|
||||
.ai-conv-item:hover {
|
||||
background: var(--df-bg-card-hover);
|
||||
}
|
||||
.ai-conv-item--active {
|
||||
background: var(--df-bg-card-hover);
|
||||
box-shadow: inset 2px 0 0 var(--df-accent);
|
||||
}
|
||||
/* 切换进行时(UX走查 P1):与活跃项同底色示"已选中"(乐观预高亮),降不透明度示"加载中";
|
||||
IPC 返回后 activeConversationId 落定、本类移除,视觉无缝衔接;失败回滚高亮回原活跃项 */
|
||||
.ai-conv-item--switching {
|
||||
background: var(--df-bg-card-hover);
|
||||
opacity: 0.7;
|
||||
}
|
||||
.ai-conv-item--archived .ai-conv-item-title {
|
||||
opacity: 0.6;
|
||||
}
|
||||
/* wave2: 行内布局对齐 .cv-top([状态点][标题省略][时间]) */
|
||||
.ai-conv-item-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.ai-conv-item-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--df-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
}
|
||||
/* UX-2025-20 §7.4: AI 生成标题淡入(0.3s opacity + transform 过渡) */
|
||||
.ai-conv-item-title--flash {
|
||||
animation: ai-title-flash 0.3s var(--df-ease);
|
||||
}
|
||||
.ai-conv-item-title-badge {
|
||||
flex-shrink: 0;
|
||||
color: var(--df-success);
|
||||
}
|
||||
@keyframes ai-title-flash {
|
||||
from { opacity: 0; transform: translateX(-3px); }
|
||||
to { opacity: 1; transform: translateX(0); }
|
||||
}
|
||||
.ai-conv-item-edit {
|
||||
flex: 1 1 0; /* wave2: main 已行化,输入框按 flex 填充(min-width:0 防 input 固有宽撑破窄侧栏) */
|
||||
min-width: 0;
|
||||
width: auto;
|
||||
font-size: 11px;
|
||||
color: var(--df-text);
|
||||
height: 18px;
|
||||
padding: 0 4px;
|
||||
border: 1px solid var(--df-accent);
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: var(--df-bg);
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
/* 聚焦可见环:边框恒为 accent 聚焦无变化,且 scoped 选择器特异性高于全局 :focus-visible 兜底,须就地补环,仅键盘聚焦显示 */
|
||||
.ai-conv-item-edit:focus-visible { outline: 2px solid var(--df-accent); outline-offset: 1px; }
|
||||
/* wave2 u-agent 范式: 时间/计数元数据 mono 10px dim(.df-mono 同款视觉) */
|
||||
.ai-conv-item-time {
|
||||
flex: none;
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* wave2 u-agent .st 状态点变体: 公共 .df-dot/.df-dot--run/.df-dot--stop 管造型与绿/灰底,
|
||||
此处只补动效与缺位色(全 token): run 绿+glow+脉冲(global df-pulse)、danger 待审批红、paused 停靠琥珀 */
|
||||
.ai-conv-status--run { box-shadow: 0 0 6px var(--df-success); animation: df-pulse 1.5s infinite; }
|
||||
.ai-conv-status--danger { background: var(--df-danger); }
|
||||
.ai-conv-status--paused { background: var(--df-warning); }
|
||||
@keyframes ai-conv-gen-pulse {
|
||||
/* 供 .ai-conv-recover-dot 分组级脉冲用(原行内 gen-dot 已由状态点接管) */
|
||||
0%, 100% { opacity: 0.35; transform: scale(0.85); }
|
||||
50% { opacity: 1; transform: scale(1.15); }
|
||||
}
|
||||
/* G5 可恢复分组(parked 会话,amber 系提示「需注意/可继续」语义;⏸ 徽标+分组标题小圆点) */
|
||||
.ai-conv-recover-dot {
|
||||
display: inline-block;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
margin-right: 5px;
|
||||
background: var(--df-warning);
|
||||
animation: ai-conv-gen-pulse 2s ease-in-out infinite;
|
||||
}
|
||||
.ai-conv-item--recoverable {
|
||||
cursor: pointer;
|
||||
}
|
||||
.ai-conv-recover-badge {
|
||||
flex-shrink: 0;
|
||||
margin-left: 2px;
|
||||
font-size: 10px;
|
||||
line-height: 1;
|
||||
color: var(--df-warning);
|
||||
cursor: help;
|
||||
}
|
||||
/* V1: 跨会话待审批徽标(橙点计数,warning 色系与待审批语义一致;固定尺寸不挤标题换行) */
|
||||
.ai-conv-approve-badge { flex-shrink: 0;
|
||||
min-width: 12px;
|
||||
height: 12px;
|
||||
padding: 0 3px;
|
||||
border-radius: 6px;
|
||||
background: var(--df-warning);
|
||||
color: #000;
|
||||
font-size: 9px;
|
||||
font-weight: 600;
|
||||
line-height: 12px;
|
||||
text-align: center;
|
||||
cursor: help;
|
||||
}
|
||||
/* 无人值守边界徽标(盾形,accent 色系与「已授权」语义一致;纯标记不计数) */
|
||||
.ai-conv-boundary-badge {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 6px;
|
||||
background: color-mix(in srgb, var(--df-accent) 18%, transparent);
|
||||
color: var(--df-accent);
|
||||
cursor: help;
|
||||
}
|
||||
.ai-conv-item-actions {
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-conv-item:hover .ai-conv-item-actions {
|
||||
display: flex;
|
||||
}
|
||||
/* UX走查 P2-6: 键盘 Tab 进会话项(项自身 tabindex=0,或焦点在项内按钮/输入框)时同样浮出
|
||||
操作按钮——原仅 :hover 渲染,键盘用户永远够不到「...」菜单触发点 */
|
||||
.ai-conv-item:focus-within .ai-conv-item-actions {
|
||||
display: flex;
|
||||
}
|
||||
/* 菜单展开时强制 actions 可见(鼠标移到菜单上 item 不再 hover,防菜单消失) */
|
||||
.ai-conv-item:has(.ai-conv-actions-menu) .ai-conv-item-actions {
|
||||
display: flex;
|
||||
}
|
||||
.ai-conv-item-act {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: none;
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: transparent;
|
||||
color: var(--df-text-dim);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-conv-item-act:hover {
|
||||
background: var(--df-sidebar-hover);
|
||||
color: var(--df-text);
|
||||
}
|
||||
/* 已置顶对话视觉强调(左边线,不依赖菜单展开,一眼识别)。
|
||||
pinned 类挂在 .ai-conv-item 上(操作收进更多菜单后,按钮不再常驻,改 item 级类)。
|
||||
wave2: 选中态同占左缘,置顶线降为 45% 透明 accent 让位,选中实线优先 */
|
||||
.ai-conv-item--pinned {
|
||||
box-shadow: inset 2px 0 0 color-mix(in srgb, var(--df-accent) 45%, transparent);
|
||||
}
|
||||
.ai-conv-item--active.ai-conv-item--pinned {
|
||||
box-shadow: inset 2px 0 0 var(--df-accent);
|
||||
}
|
||||
/* ── 「更多」操作菜单(置顶/归档/删除)──
|
||||
「...」按钮 hover 时随 actions 浮出(同原 4 按钮交互),点击展开下拉。
|
||||
菜单绝对定位浮于 item 下方右侧,窄侧栏避免溢出。 */
|
||||
.ai-conv-item-more {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ai-conv-actions-menu {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
right: 0;
|
||||
margin-top: 2px;
|
||||
z-index: 20;
|
||||
min-width: 104px;
|
||||
padding: 2px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
background: var(--df-bg);
|
||||
border: 1px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
.ai-conv-actions-opt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
padding: 5px 8px;
|
||||
font-size: 11px;
|
||||
color: var(--df-text);
|
||||
cursor: pointer;
|
||||
border-radius: var(--df-radius-sm);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ai-conv-actions-opt:hover {
|
||||
background: var(--df-sidebar-hover);
|
||||
}
|
||||
.ai-conv-actions-opt--danger:hover {
|
||||
background: var(--df-danger-bg);
|
||||
color: var(--df-danger);
|
||||
}
|
||||
.ai-conv-empty {
|
||||
padding: 16px 8px;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* F4-1: 列表底部「加载更多」(轻量文字行,hover 同列表项灰阶卡底范式) */
|
||||
.ai-conv-load-more {
|
||||
margin: 4px 2px;
|
||||
padding: 6px 8px;
|
||||
border-radius: var(--df-radius);
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
.ai-conv-load-more:hover {
|
||||
background: var(--df-bg-card-hover);
|
||||
color: var(--df-text);
|
||||
}
|
||||
</style>
|
||||
@@ -114,7 +114,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="eval-report eval-report--muted">
|
||||
<button class="btn-evaluate" :disabled="evaluating" @click="$emit('evaluate')">
|
||||
<button class="btn btn-primary" :disabled="evaluating" @click="$emit('evaluate')">
|
||||
{{ evaluating ? $t('ideas.evaluating') : $t('ideas.startEval') }}
|
||||
</button>
|
||||
<!-- P1-⑥ 重试样式:错误提示分两行,重试用 ghost btn-sm(替代突兀的内联 accent 按钮) -->
|
||||
@@ -690,7 +690,7 @@ watch(() => props.idea.id, loadHistory)
|
||||
gap: 12px;
|
||||
margin-bottom: var(--df-gap-head);
|
||||
}
|
||||
.detail-title { font-size: 20px; font-weight: 500; color: var(--df-text); flex: 1; min-width: 0; }
|
||||
.detail-title { font-size: var(--df-fs-title); font-weight: 500; color: var(--df-text); flex: 1; min-width: 0; }
|
||||
/* P0-② 标题行右侧操作组:立项按钮 + 状态 badge 一行排布 */
|
||||
.detail-header-actions {
|
||||
display: flex;
|
||||
@@ -752,7 +752,7 @@ watch(() => props.idea.id, loadHistory)
|
||||
padding: 14px 16px;
|
||||
background: var(--df-accent-bg);
|
||||
border-left: 3px solid var(--df-accent);
|
||||
border-radius: 0 8px 8px 0;
|
||||
border-radius: 0 var(--df-radius-md) var(--df-radius-md) 0;
|
||||
}
|
||||
/* 弱化态(空数据/加载中占位,原 inline opacity:0.5 统一为 class) */
|
||||
.eval-report--muted { opacity: 0.5; }
|
||||
@@ -764,47 +764,48 @@ watch(() => props.idea.id, loadHistory)
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
padding: 13px;
|
||||
margin-bottom: 13px;
|
||||
}
|
||||
|
||||
.debate-container {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1.5rem;
|
||||
gap: 13px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.debate-column {
|
||||
padding: 1rem;
|
||||
padding: 13px;
|
||||
border-radius: var(--df-radius);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* 正反方论据栏底/边走语义 token(双主题自适应) */
|
||||
.debate-column.positive {
|
||||
background: rgba(61, 219, 160, 0.08);
|
||||
border: 0.5px solid rgba(61, 219, 160, 0.2);
|
||||
background: var(--df-success-bg);
|
||||
border: 0.5px solid var(--df-success-bd);
|
||||
}
|
||||
|
||||
.debate-column.negative {
|
||||
background: rgba(240, 101, 101, 0.08);
|
||||
border: 0.5px solid rgba(240, 101, 101, 0.2);
|
||||
background: var(--df-danger-bg);
|
||||
border: 0.5px solid var(--df-danger-bd);
|
||||
}
|
||||
|
||||
.debate-column h4 {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem;
|
||||
margin: 0 0 7px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
gap: 7px;
|
||||
}
|
||||
|
||||
.confidence-bar {
|
||||
height: 4px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: var(--df-radius-xs);
|
||||
margin-bottom: 0.25rem;
|
||||
margin-bottom: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -820,13 +821,13 @@ watch(() => props.idea.id, loadHistory)
|
||||
.confidence-text {
|
||||
font-size: 11px;
|
||||
color: var(--df-text-dim);
|
||||
margin-bottom: 0.5rem;
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.debate-column .thesis {
|
||||
font-size: 12px;
|
||||
color: var(--df-text);
|
||||
margin-bottom: 0.5rem;
|
||||
margin-bottom: 7px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
@@ -839,16 +840,16 @@ watch(() => props.idea.id, loadHistory)
|
||||
.debate-column li {
|
||||
font-size: 11px;
|
||||
color: var(--df-text-secondary);
|
||||
margin-bottom: 0.25rem;
|
||||
padding-left: 0.5rem;
|
||||
margin-bottom: 3px;
|
||||
padding-left: 7px;
|
||||
}
|
||||
|
||||
.analyst-conclusion {
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
padding: 13px;
|
||||
margin-bottom: 13px;
|
||||
}
|
||||
|
||||
/* assessment-badge 系列已提取到 styles/components.css 全局 */
|
||||
@@ -857,39 +858,39 @@ watch(() => props.idea.id, loadHistory)
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--df-text);
|
||||
margin: 0.5rem 0;
|
||||
margin: 7px 0;
|
||||
}
|
||||
|
||||
.net-sentiment {
|
||||
font-size: 12px;
|
||||
padding: 4px 8px;
|
||||
font-size: var(--df-fs-ctrl);
|
||||
padding: var(--df-pad-badge);
|
||||
border-radius: var(--df-radius-xs);
|
||||
display: inline-block;
|
||||
margin: 0.5rem 0;
|
||||
margin: 7px 0;
|
||||
}
|
||||
|
||||
.net-sentiment.positive { background: rgba(61, 219, 160, 0.15); color: var(--df-success); }
|
||||
.net-sentiment.negative { background: rgba(240, 101, 101, 0.15); color: var(--df-danger); }
|
||||
.net-sentiment.positive { background: var(--df-success-bg); color: var(--df-success); }
|
||||
.net-sentiment.negative { background: var(--df-danger-bg); color: var(--df-danger); }
|
||||
.net-sentiment.neutral { background: var(--df-bg-raised); color: var(--df-text-secondary); }
|
||||
|
||||
.summary {
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
line-height: 1.5;
|
||||
margin: 0.5rem 0;
|
||||
margin: 7px 0;
|
||||
}
|
||||
|
||||
.action-recommendations {
|
||||
background: var(--df-bg-raised);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
padding: 1rem;
|
||||
padding: 13px;
|
||||
}
|
||||
|
||||
.action-recommendations h4 {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem;
|
||||
margin: 0 0 7px;
|
||||
}
|
||||
|
||||
.action-recommendations ul {
|
||||
@@ -901,12 +902,12 @@ watch(() => props.idea.id, loadHistory)
|
||||
.action-recommendations li {
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
margin-bottom: 0.25rem;
|
||||
padding-left: 0.5rem;
|
||||
margin-bottom: 3px;
|
||||
padding-left: 7px;
|
||||
}
|
||||
|
||||
/* P0-① 详细论据折叠切换条 */
|
||||
.debate-toggle-row { margin-bottom: 0.75rem; }
|
||||
.debate-toggle-row { margin-bottom: 10px; }
|
||||
.debate-toggle-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
@@ -924,23 +925,10 @@ watch(() => props.idea.id, loadHistory)
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
.debate-toggle-arrow.is-open { transform: rotate(180deg); }
|
||||
.debate-detail { margin-top: 0.5rem; }
|
||||
.debate-detail .debate-container { margin-bottom: 0.75rem; }
|
||||
.debate-detail { margin-top: 7px; }
|
||||
.debate-detail .debate-container { margin-bottom: 10px; }
|
||||
|
||||
.btn-evaluate {
|
||||
background: var(--df-accent);
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: var(--df-radius);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
}
|
||||
|
||||
.btn-evaluate:hover {
|
||||
background: var(--df-accent-hover);
|
||||
}
|
||||
/* 「开始评估」按钮并轨全局 .btn .btn-primary(30px 主档),本地副本删除 */
|
||||
|
||||
/* P1-⑥ 重试样式:错误提示与重试按钮分行,重试用 ghost btn-sm(替代突兀的内联 accent 按钮) */
|
||||
.eval-error {
|
||||
@@ -952,11 +940,11 @@ watch(() => props.idea.id, loadHistory)
|
||||
.btn-retry { margin-top: 4px; }
|
||||
|
||||
.eval-mode-tag {
|
||||
font-size: 11px;
|
||||
font-size: var(--df-fs-aux);
|
||||
font-weight: 400;
|
||||
padding: 1px 8px;
|
||||
padding: var(--df-pad-chip);
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: rgba(255, 217, 61, 0.15);
|
||||
background: var(--df-warning-bg);
|
||||
color: var(--df-warning);
|
||||
margin-left: 6px;
|
||||
vertical-align: middle;
|
||||
@@ -991,26 +979,26 @@ watch(() => props.idea.id, loadHistory)
|
||||
font-size: 12px;
|
||||
}
|
||||
.version-badge {
|
||||
font-size: 11px;
|
||||
font-size: var(--df-fs-aux);
|
||||
font-weight: 500;
|
||||
padding: 2px 8px;
|
||||
padding: var(--df-pad-badge);
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: var(--df-accent-soft);
|
||||
color: var(--df-accent);
|
||||
}
|
||||
.latest-tag {
|
||||
font-size: 10px;
|
||||
font-size: var(--df-fs-meta);
|
||||
font-weight: 500;
|
||||
padding: 1px 6px;
|
||||
padding: var(--df-pad-chip);
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: rgba(100, 255, 218, 0.15);
|
||||
background: var(--df-success-bg);
|
||||
color: var(--df-success);
|
||||
}
|
||||
.history-eval-mode {
|
||||
font-size: 11px;
|
||||
padding: 1px 6px;
|
||||
font-size: var(--df-fs-aux);
|
||||
padding: var(--df-pad-chip);
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: rgba(255, 217, 61, 0.12);
|
||||
background: var(--df-warning-bg);
|
||||
color: var(--df-warning);
|
||||
}
|
||||
.history-score {
|
||||
@@ -1046,7 +1034,7 @@ watch(() => props.idea.id, loadHistory)
|
||||
/* ===== 标签 ===== */
|
||||
.tag-list { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||
.tag {
|
||||
font-size: 12px; padding: 4px 10px;
|
||||
font-size: var(--df-fs-ctrl); padding: var(--df-pad-badge);
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
@@ -1055,7 +1043,7 @@ watch(() => props.idea.id, loadHistory)
|
||||
/* ===== 关联灵感 ===== */
|
||||
.related-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
|
||||
.related-chip {
|
||||
font-size: 12px; padding: 4px 10px;
|
||||
font-size: var(--df-fs-ctrl); padding: var(--df-pad-badge);
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-accent);
|
||||
|
||||
@@ -400,13 +400,14 @@ watch(renderedContent, () => {
|
||||
|
||||
/* 状态徽章 / 置信度 */
|
||||
.kn-card-status { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: var(--df-radius-xs); white-space: nowrap; }
|
||||
.st-candidate { background: rgba(255,217,61,0.15); color: var(--df-warning); }
|
||||
.st-pending_review { background: rgba(108,159,255,0.15); color: var(--df-info); }
|
||||
.st-published { background: rgba(100,255,218,0.15); color: var(--df-success); }
|
||||
.st-archived { background: rgba(90,99,128,0.2); color: var(--df-text-dim); }
|
||||
.conf-high { background: rgba(100,255,218,0.15); color: var(--df-success); padding: 1px 6px; border-radius: var(--df-radius-xs); }
|
||||
.conf-medium { background: rgba(255,217,61,0.15); color: var(--df-warning); padding: 1px 6px; border-radius: var(--df-radius-xs); }
|
||||
.conf-low { background: rgba(255,107,107,0.15); color: var(--df-danger); padding: 1px 6px; border-radius: var(--df-radius-xs); }
|
||||
/* 状态/置信度徽章底统一走语义 token(双主题自适应,与 Knowledge.vue 同规) */
|
||||
.st-candidate { background: var(--df-warning-bg); color: var(--df-warning); }
|
||||
.st-pending_review { background: var(--df-info-bg); color: var(--df-info); }
|
||||
.st-published { background: var(--df-success-bg); color: var(--df-success); }
|
||||
.st-archived { background: var(--df-neutral-bg); color: var(--df-text-dim); }
|
||||
.conf-high { background: var(--df-success-bg); color: var(--df-success); padding: 1px 6px; border-radius: var(--df-radius-xs); }
|
||||
.conf-medium { background: var(--df-warning-bg); color: var(--df-warning); padding: 1px 6px; border-radius: var(--df-radius-xs); }
|
||||
.conf-low { background: var(--df-danger-bg); color: var(--df-danger); padding: 1px 6px; border-radius: var(--df-radius-xs); }
|
||||
|
||||
/* 溯源 */
|
||||
.section-title { font-size: 13px; font-weight: 500; color: var(--df-text); margin-bottom: 10px; }
|
||||
@@ -439,7 +440,7 @@ watch(renderedContent, () => {
|
||||
}
|
||||
.detail-content.content-collapsed::after {
|
||||
content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 28px;
|
||||
background: linear-gradient(to bottom, transparent, var(--df-bg-panel, var(--df-bg-card)));
|
||||
background: linear-gradient(to bottom, transparent, var(--df-bg-card));
|
||||
pointer-events: none;
|
||||
}
|
||||
.detail-content { position: relative; }
|
||||
|
||||
@@ -94,7 +94,7 @@ const knowledgeStore = useKnowledgeStore()
|
||||
const appSettings = useAppSettingsStore()
|
||||
|
||||
// ── 侧边栏收缩状态(持久化到 appSettings,小窗口自动收缩) ──
|
||||
// 展开 192px(文字+图标) / 收缩 56px(仅图标,hover tooltip 显示文字)
|
||||
// 展开 220px(文字+图标) / 收缩 56px(仅图标,hover tooltip 显示文字)
|
||||
// 优先级:用户手动设置 > 小窗口自动收缩(≤768px)
|
||||
const COLLAPSE_THRESHOLD = 768
|
||||
// useSetting 响应式读(loadAll 异步填充缓存后 watch 自动同步刷新)——
|
||||
@@ -172,8 +172,8 @@ const secondaryNav = [
|
||||
|
||||
<style scoped>
|
||||
.df-sidebar {
|
||||
width: 192px;
|
||||
min-width: 192px;
|
||||
width: 220px;
|
||||
min-width: 220px;
|
||||
background: var(--df-sidebar-bg);
|
||||
border-right: 0.5px solid var(--df-border);
|
||||
display: flex;
|
||||
@@ -219,8 +219,8 @@ const secondaryNav = [
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10px;
|
||||
color: var(--df-text-dim);
|
||||
background: rgba(255,255,255,0.04);
|
||||
padding: 1px 6px;
|
||||
background: var(--df-hover);
|
||||
padding: var(--df-pad-chip);
|
||||
border-radius: var(--df-radius-xs);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ const secondaryNav = [
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
padding: 1px 6px;
|
||||
padding: var(--df-pad-chip);
|
||||
border-radius: var(--df-radius);
|
||||
min-width: 18px;
|
||||
text-align: center;
|
||||
@@ -360,8 +360,8 @@ const secondaryNav = [
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 9px;
|
||||
color: var(--df-text-dim);
|
||||
background: rgba(255,255,255,0.04);
|
||||
padding: 1px 5px;
|
||||
background: var(--df-hover);
|
||||
padding: var(--df-pad-chip);
|
||||
border-radius: var(--df-radius-sm);
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ async function onInstall() {
|
||||
color: var(--df-accent);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
transition: filter 0.15s;
|
||||
}
|
||||
.update-badge-btn:hover {
|
||||
@@ -193,7 +193,7 @@ async function onInstall() {
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-lg);
|
||||
background: var(--df-bg-card);
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
}
|
||||
.update-pop-head {
|
||||
font-size: 13px;
|
||||
@@ -213,11 +213,12 @@ async function onInstall() {
|
||||
.update-pop-progress {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
/* 进度条轨道:原 --df-bg-hover 为未定义幽灵 token(靠回退侥幸渲染),改中性底 */
|
||||
.update-pop-bar {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: var(--df-bg-hover, rgba(128, 128, 128, 0.2));
|
||||
background: var(--df-neutral-bg);
|
||||
overflow: hidden;
|
||||
}
|
||||
.update-pop-fill {
|
||||
@@ -234,10 +235,10 @@ async function onInstall() {
|
||||
.update-pop-error {
|
||||
margin-bottom: 12px;
|
||||
padding: 8px 10px;
|
||||
border-radius: var(--df-radius-md, 6px);
|
||||
background: rgba(220, 53, 69, 0.12);
|
||||
border-radius: var(--df-radius-md);
|
||||
background: var(--df-danger-bg);
|
||||
font-size: 12px;
|
||||
color: var(--df-danger, #dc3545);
|
||||
color: var(--df-danger);
|
||||
line-height: 1.5;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
</div>
|
||||
<!-- M31: 审批失败反馈(store approveHumanApproval 内部 catch 吞错,失败时 pendingApproval 不清空)
|
||||
对话框保持开启,用户可看到错误并重试 -->
|
||||
<div v-if="toast.visible" class="ad-toast" :class="'ad-toast-' + toast.type">{{ toast.msg }}</div>
|
||||
<div v-if="toast.visible" class="df-toast df-toast--bottom" :class="toast.type === 'error' ? 'df-toast--danger' : 'df-toast--' + toast.type">{{ toast.msg }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -162,19 +162,7 @@ watch(() => pendingApproval.value, (newApproval) => {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* M31: 审批失败 toast(scoped 自治,不引入全局样式;沿用 Projects.vue .toast 视觉规范) */
|
||||
.ad-toast {
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 10001;
|
||||
padding: 10px 18px;
|
||||
border-radius: var(--df-radius-md);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
|
||||
pointer-events: none;
|
||||
}
|
||||
.ad-toast-error { background: var(--df-danger); color: #fff; }
|
||||
/* M31: 审批失败 toast(样式走全局 .df-toast 族+--bottom 底部变体;
|
||||
scoped 仅保留 z-index 覆写——本组件浮在弹层(z≈10000)之上,toast 须更高) */
|
||||
.df-toast { z-index: 10001; }
|
||||
</style>
|
||||
|
||||
@@ -442,7 +442,7 @@ function bindEdgeDeleteButtons() {
|
||||
graph.on('edge:mouseleave', onEdgeLeave)
|
||||
}
|
||||
|
||||
/** 依赖类型 → 边颜色 */
|
||||
/** 依赖类型 → 边颜色(X6 画布演示色板·品牌/演示豁免,不入 token) */
|
||||
function depTypeColor(depType: string): string {
|
||||
switch (depType) {
|
||||
case 'api': return '#5378e8'
|
||||
@@ -490,7 +490,7 @@ onBeforeUnmount(() => {
|
||||
height: 100%;
|
||||
background: var(--df-bg);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-lg, 8px);
|
||||
border-radius: var(--df-radius-lg);
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
@@ -593,11 +593,12 @@ onBeforeUnmount(() => {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 200;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.4);
|
||||
box-shadow: var(--df-shadow-md);
|
||||
transition: background 0.15s;
|
||||
pointer-events: auto;
|
||||
}
|
||||
/* hover 由 danger 派生加深,替换孤色 */
|
||||
.dep-edge-delete-btn:hover {
|
||||
background: #c24040;
|
||||
background: color-mix(in srgb, var(--df-danger) 75%, #000);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -488,11 +488,8 @@ onUnmounted(() => { _unlistenDataChanged?.() })
|
||||
async function onScanSubmodules() {
|
||||
moduleDropdownOpen.value = false
|
||||
try {
|
||||
const n = await moduleApi.scanProjectModules(props.projectId)
|
||||
await moduleApi.scanProjectModules(props.projectId)
|
||||
await loadModules()
|
||||
if (n > 0) {
|
||||
console.log('[FileExplorer] 扫描到新工程:', n)
|
||||
}
|
||||
} catch (e) {
|
||||
Message.error(t('common.unknownError'))
|
||||
console.error('[FileExplorer] 扫描子仓库失败:', e)
|
||||
@@ -594,7 +591,7 @@ async function onRemoveModule() {
|
||||
max-height: 100%;
|
||||
background: var(--df-bg);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-lg, 8px);
|
||||
border-radius: var(--df-radius-lg);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -625,7 +622,7 @@ async function onRemoveModule() {
|
||||
padding: 5px 10px;
|
||||
background: var(--df-bg);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
border-radius: var(--df-radius-sm);
|
||||
color: var(--df-text);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
@@ -651,12 +648,11 @@ async function onRemoveModule() {
|
||||
max-width: 320px;
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
box-shadow: 0 6px 16px rgba(0,0,0,0.25);
|
||||
border-radius: var(--df-radius-sm);
|
||||
box-shadow: var(--df-shadow-sm);
|
||||
z-index: 20;
|
||||
max-height: 280px;
|
||||
overflow-y: auto;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.module-dropdown-item {
|
||||
@@ -665,10 +661,10 @@ async function onRemoveModule() {
|
||||
gap: 2px;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
border-bottom: 0.5px solid rgba(255,255,255,0.04);
|
||||
border-bottom: 0.5px solid var(--df-hover);
|
||||
}
|
||||
.module-dropdown-item:last-child { border-bottom: none; }
|
||||
.module-dropdown-item:hover { background: rgba(255,255,255,0.04); }
|
||||
.module-dropdown-item:hover { background: var(--df-hover); }
|
||||
.module-dropdown-item.active {
|
||||
background: rgba(255,255,255,0.06);
|
||||
border-left: 2px solid var(--df-accent);
|
||||
@@ -778,7 +774,7 @@ async function onRemoveModule() {
|
||||
|
||||
.view-tab:hover {
|
||||
color: var(--df-text);
|
||||
background: rgba(255,255,255,0.03);
|
||||
background: var(--df-hover);
|
||||
}
|
||||
|
||||
.view-tab.active {
|
||||
@@ -809,7 +805,9 @@ async function onRemoveModule() {
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 4px 4px 4px 0;
|
||||
scrollbar-width: thin;
|
||||
/* 滚动条样式走全局 ::-webkit-scrollbar(5px + var(--df-scrollbar) 主题色):
|
||||
此处不得设 scrollbar-width —— Chromium 121+ 一旦设了标准 scrollbar-* 属性,
|
||||
该元素 ::-webkit-scrollbar 定制即失效,文件列表会回退成原生样式滚动条(不随主题) */
|
||||
}
|
||||
|
||||
.explorer-changes {
|
||||
@@ -817,13 +815,6 @@ async function onRemoveModule() {
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
min-height: 0;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.explorer-changes .gc-body {
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.tree-loading {
|
||||
@@ -865,8 +856,8 @@ async function onRemoveModule() {
|
||||
.tree-loading .spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--df-border, #444);
|
||||
border-top-color: var(--df-accent, #3a8);
|
||||
border: 2px solid var(--df-border);
|
||||
border-top-color: var(--df-accent);
|
||||
border-radius: 50%;
|
||||
animation: df-spin 0.8s linear infinite;
|
||||
}
|
||||
@@ -888,43 +879,8 @@ async function onRemoveModule() {
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
/* 全局滚动条样式(薄) */
|
||||
.explorer-sidebar ::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
.explorer-sidebar ::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: var(--df-radius-xs);
|
||||
}
|
||||
|
||||
.explorer-sidebar ::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
}
|
||||
|
||||
.explorer-sidebar ::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
/* 文件列表(.explorer-tree)滚动条显式对齐全局,与右侧预览区一致 */
|
||||
.explorer-tree ::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
.explorer-tree ::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: var(--df-radius-xs);
|
||||
}
|
||||
|
||||
.explorer-tree ::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
}
|
||||
|
||||
.explorer-tree ::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
/* 滚动条统一样式(styles/global.css 全局 ::-webkit-scrollbar:5px + var(--df-scrollbar))已覆盖,
|
||||
此处不重复声明 —— 原局部副本硬编码白色系 rgba,浅色主题下 thumb 不可见 */
|
||||
|
||||
/* 窄窗口自适应 */
|
||||
@media (max-width: 900px) {
|
||||
@@ -946,20 +902,14 @@ async function onRemoveModule() {
|
||||
}
|
||||
}
|
||||
|
||||
/* spinner(刷新按钮内) */
|
||||
/* spinner(刷新按钮内);df-spin keyframes 消费 global.css 全局定义(原本地重复定义已删) */
|
||||
.spinner {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border: 1.5px solid var(--df-border, #444);
|
||||
border-top-color: var(--df-accent, #3a8);
|
||||
border: 1.5px solid var(--df-border);
|
||||
border-top-color: var(--df-accent);
|
||||
border-radius: 50%;
|
||||
animation: df-spin 0.8s linear infinite;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
@keyframes df-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -171,7 +171,7 @@
|
||||
import { ref, watch, computed, onUnmounted, nextTick } from 'vue'
|
||||
import { moduleApi, type OutlineSymbol } from '@/api/module'
|
||||
import hljs from 'highlight.js/lib/common'
|
||||
import { useMarkdown, useRendered } from '@/composables/useMarkdown'
|
||||
import { useRendered } from '@/composables/useMarkdown'
|
||||
import { escapeHtml } from '@/utils/html'
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -184,7 +184,6 @@ const props = defineProps<{
|
||||
externalDiff?: string
|
||||
}>()
|
||||
|
||||
const { } = useMarkdown()
|
||||
const content = ref('')
|
||||
const htmlContent = ref('')
|
||||
const loading = ref(false)
|
||||
@@ -469,12 +468,12 @@ const outlineGroups = computed(() => {
|
||||
.map((g) => ({ key: g, labelKey: GROUP_LABEL_KEY[g], items: buckets.get(g)! }))
|
||||
})
|
||||
|
||||
/** 点击符号滚动到对应行:偏移 = 代码区 padding-top 14px + (line-1) × 行高(12.5px × 1.55)。 */
|
||||
/** 点击符号滚动到对应行:偏移 = 代码区 padding-top 14px + (line-1) × 行高(12px × 1.55)。 */
|
||||
function gotoOutlineLine(line: number) {
|
||||
activeOutlineLine.value = line
|
||||
const el = codeScrollRef.value
|
||||
if (!el) return
|
||||
const lineHeight = 12.5 * 1.55
|
||||
const lineHeight = 12 * 1.55
|
||||
const topPad = 14 // 对齐 .preview-code / .preview-line-numbers 的 padding-top
|
||||
el.scrollTo({ top: Math.max(0, topPad + (line - 1) * lineHeight), behavior: 'smooth' })
|
||||
}
|
||||
@@ -732,11 +731,6 @@ onUnmounted(() => {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.binary-icon {
|
||||
font-size: 40px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.binary-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
@@ -748,7 +742,7 @@ onUnmounted(() => {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
background: var(--df-hover);
|
||||
border-radius: 8px;
|
||||
padding: 12px 16px;
|
||||
min-width: 280px;
|
||||
@@ -771,7 +765,7 @@ onUnmounted(() => {
|
||||
.binary-meta-value {
|
||||
color: var(--df-text-secondary);
|
||||
font-family: var(--df-font-mono, Consolas, monospace);
|
||||
font-size: 12.5px;
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@@ -785,7 +779,7 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.preview-error { color: var(--df-danger); }
|
||||
.binary-icon { font-size: 32px; opacity: 0.5; }
|
||||
.binary-icon { font-size: 32px; opacity: 0.5; } /* 2026-10-18 合并重复定义:40px/0.8 旧版被本行完全覆盖,已删 */
|
||||
|
||||
.preview-image {
|
||||
display: flex;
|
||||
@@ -799,7 +793,7 @@ onUnmounted(() => {
|
||||
.preview-image img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
border-radius: var(--df-radius-sm);
|
||||
}
|
||||
|
||||
/* Markdown 视图:独立滚动容器(preview-body 是 overflow:hidden,不设 overflow 会被裁剪无法滚) */
|
||||
@@ -814,7 +808,7 @@ onUnmounted(() => {
|
||||
margin: 0;
|
||||
padding: 14px 16px;
|
||||
font-family: var(--df-font-mono, 'Cascadia Code', Consolas, 'Courier New', monospace);
|
||||
font-size: 12.5px;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
white-space: pre;
|
||||
overflow: visible;
|
||||
@@ -838,7 +832,7 @@ onUnmounted(() => {
|
||||
padding: 14px 0;
|
||||
min-width: 44px;
|
||||
text-align: right;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
background: var(--df-hover);
|
||||
border-right: 0.5px solid var(--df-border);
|
||||
user-select: none;
|
||||
position: sticky;
|
||||
@@ -850,7 +844,7 @@ onUnmounted(() => {
|
||||
.preview-line-num {
|
||||
padding: 0 10px 0 8px;
|
||||
font-family: var(--df-font-mono, 'Cascadia Code', Consolas, monospace);
|
||||
font-size: 12.5px;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
color: var(--df-text-dim);
|
||||
opacity: 0.5;
|
||||
@@ -859,24 +853,25 @@ onUnmounted(() => {
|
||||
.preview-line-num.is-active {
|
||||
color: var(--df-accent);
|
||||
opacity: 1;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
background: var(--df-hover);
|
||||
}
|
||||
|
||||
/* Diff 视图 — 在自身区域滚动,不溢出到父级 */
|
||||
/* Diff 视图 — 在自身区域滚动,不溢出到父级(2026-10-18 合并文末重复定义) */
|
||||
.preview-diff {
|
||||
font-family: var(--df-font-mono, 'Cascadia Code', Consolas, monospace);
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid var(--df-border, #444);
|
||||
border-top-color: var(--df-accent, #3a8);
|
||||
border: 2px solid var(--df-border);
|
||||
border-top-color: var(--df-accent);
|
||||
border-radius: 50%;
|
||||
animation: df-spin 0.8s linear infinite;
|
||||
display: inline-block;
|
||||
@@ -890,7 +885,7 @@ onUnmounted(() => {
|
||||
padding: 4px 10px;
|
||||
font-size: 11px;
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
border-radius: var(--df-radius-sm);
|
||||
background: transparent;
|
||||
color: var(--df-text-secondary);
|
||||
cursor: pointer;
|
||||
@@ -927,7 +922,7 @@ onUnmounted(() => {
|
||||
padding: 4px 9px;
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
background: var(--df-hover);
|
||||
color: var(--df-text-secondary);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
@@ -958,7 +953,7 @@ onUnmounted(() => {
|
||||
background: rgba(20, 22, 34, 0.95);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
|
||||
box-shadow: var(--df-shadow-md);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -1031,7 +1026,7 @@ onUnmounted(() => {
|
||||
gap: 6px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 6px;
|
||||
font-size: 11.5px;
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
color: var(--df-text-secondary);
|
||||
@@ -1039,7 +1034,7 @@ onUnmounted(() => {
|
||||
transition: background 0.15s;
|
||||
}
|
||||
|
||||
.outline-item:hover { background: rgba(255, 255, 255, 0.05); color: var(--df-text); }
|
||||
.outline-item:hover { background: var(--df-hover); color: var(--df-text); }
|
||||
|
||||
.outline-item.is-active {
|
||||
background: rgba(255, 255, 255, 0.09);
|
||||
@@ -1047,7 +1042,7 @@ onUnmounted(() => {
|
||||
box-shadow: inset 2px 0 0 var(--df-accent);
|
||||
}
|
||||
|
||||
/* 分组徽章配色:类型蓝 / 函数绿 / 变量橙 / 模块紫 */
|
||||
/* 分组徽章配色:类型蓝 / 函数绿 / 变量橙 / 模块紫(语法色板·演示豁免,不入 token) */
|
||||
.outline-item.grp-type .outline-kind { color: #4FC3F7; }
|
||||
.outline-item.grp-fn .outline-kind { color: #81C784; }
|
||||
.outline-item.grp-var .outline-kind { color: #FFB74D; }
|
||||
@@ -1066,6 +1061,7 @@ onUnmounted(() => {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.outline-line {
|
||||
@@ -1076,15 +1072,6 @@ onUnmounted(() => {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* Diff 视图 */
|
||||
.preview-diff {
|
||||
font-family: var(--df-font-mono, 'Cascadia Code', Consolas, monospace);
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.diff-line {
|
||||
display: flex;
|
||||
padding: 0 8px;
|
||||
@@ -1115,6 +1102,7 @@ onUnmounted(() => {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Diff 行底(差异色·演示豁免,与 git 语义 token 并行的语法高亮族) */
|
||||
.diff-add {
|
||||
background: rgba(40, 160, 70, 0.12);
|
||||
}
|
||||
@@ -1137,7 +1125,7 @@ onUnmounted(() => {
|
||||
color: var(--df-text);
|
||||
}
|
||||
|
||||
@keyframes df-spin { to { transform: rotate(360deg); } }
|
||||
/* df-spin keyframes 消费 global.css 全局定义(原本地同名重复定义已删,2026-10-18 整洁波) */
|
||||
</style>
|
||||
|
||||
<!-- highlight.js github-dark 主题(全局,非 scoped) -->
|
||||
|
||||
@@ -384,16 +384,16 @@ watch(
|
||||
gap: 6px;
|
||||
padding: 3px 8px;
|
||||
cursor: pointer;
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
border-radius: var(--df-radius-sm);
|
||||
transition: background 0.12s;
|
||||
}
|
||||
|
||||
.tree-row:hover {
|
||||
background: var(--df-bg-card, rgba(255, 255, 255, 0.04));
|
||||
background: var(--df-bg-card);
|
||||
}
|
||||
|
||||
.tree-row-file.is-selected {
|
||||
background: var(--df-accent, #3a8);
|
||||
background: var(--df-accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
@@ -415,8 +415,8 @@ watch(
|
||||
display: inline-block;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border: 1.5px solid var(--df-border, #444);
|
||||
border-top-color: var(--df-accent, #3a8);
|
||||
border: 1.5px solid var(--df-border);
|
||||
border-top-color: var(--df-accent);
|
||||
border-radius: 50%;
|
||||
animation: df-spin 0.8s linear infinite;
|
||||
vertical-align: middle;
|
||||
@@ -544,19 +544,14 @@ watch(
|
||||
color: #e05050;
|
||||
}
|
||||
|
||||
/* spinner;df-spin keyframes 消费 global.css 全局定义(原本地重复定义已删,2026-10-18 整洁波) */
|
||||
.spinner {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border: 1.5px solid var(--df-border, #444);
|
||||
border-top-color: var(--df-accent, #3a8);
|
||||
border: 1.5px solid var(--df-border);
|
||||
border-top-color: var(--df-accent);
|
||||
border-radius: 50%;
|
||||
animation: df-spin 0.8s linear infinite;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
@keyframes df-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -422,7 +422,6 @@ async function loadStatus() {
|
||||
const showBranchPicker = ref(false)
|
||||
const branchList = ref<{ name: string; is_current: boolean }[]>([])
|
||||
const branchLoading = ref(false)
|
||||
const currentBranch = ref('')
|
||||
|
||||
async function onSwitchBranch() {
|
||||
if (showBranchPicker.value) {
|
||||
@@ -435,7 +434,6 @@ async function onSwitchBranch() {
|
||||
try {
|
||||
const res = await moduleApi.listBranches(props.moduleId)
|
||||
branchList.value = res.branches
|
||||
currentBranch.value = res.current
|
||||
} catch (e) {
|
||||
branchList.value = []
|
||||
actionError.value = String(e)
|
||||
@@ -607,7 +605,7 @@ watch(() => props.refreshKey, () => {
|
||||
}
|
||||
.branch-switch-btn:hover {
|
||||
color: var(--df-text);
|
||||
background: rgba(255,255,255,0.05);
|
||||
background: var(--df-hover);
|
||||
}
|
||||
|
||||
/* Tabs */
|
||||
@@ -620,14 +618,14 @@ watch(() => props.refreshKey, () => {
|
||||
.gc-tab.active { color: var(--df-text); border-bottom-color: var(--df-accent); }
|
||||
.gc-tab:hover { color: var(--df-text); }
|
||||
|
||||
.gc-body { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; scrollbar-width: thin; }
|
||||
.gc-body { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
|
||||
.gc-changes { min-height: 0; }
|
||||
|
||||
/* 分组 */
|
||||
.gc-group-header {
|
||||
padding: 6px 14px; font-size: 11px; font-weight: 600;
|
||||
color: var(--df-text-dim); text-transform: uppercase; letter-spacing: 0.5px;
|
||||
background: rgba(255,255,255,0.02); border-bottom: 0.5px solid var(--df-border);
|
||||
background: var(--df-hover); border-bottom: 0.5px solid var(--df-border);
|
||||
position: sticky; top: 0; z-index: 1;
|
||||
}
|
||||
|
||||
@@ -645,8 +643,8 @@ watch(() => props.refreshKey, () => {
|
||||
.gc-search-icon { color: var(--df-text-dim); flex-shrink: 0; }
|
||||
.gc-search-input {
|
||||
flex: 1; min-width: 0;
|
||||
background: rgba(255,255,255,0.04); border: 0.5px solid var(--df-border);
|
||||
border-radius: 4px; padding: 4px 8px;
|
||||
background: var(--df-hover); border: 0.5px solid var(--df-border);
|
||||
border-radius: 4px; height: var(--df-h-input); padding: 0 8px;
|
||||
color: var(--df-text); font-size: 12px; outline: none;
|
||||
}
|
||||
.gc-search-input:focus { border-color: var(--df-accent); }
|
||||
@@ -658,13 +656,13 @@ watch(() => props.refreshKey, () => {
|
||||
.gc-search-clear:hover { color: var(--df-text); }
|
||||
|
||||
/* 提交列表 */
|
||||
.gc-history-list { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
|
||||
.gc-history-list { flex: 1; min-height: 0; overflow-y: auto; }
|
||||
.gc-commit-row {
|
||||
display: flex; flex-direction: column; gap: 2px;
|
||||
padding: 6px 14px; border-bottom: 0.5px solid rgba(255,255,255,0.03);
|
||||
padding: 6px 14px; border-bottom: 0.5px solid var(--df-hover);
|
||||
cursor: pointer; transition: background 0.1s;
|
||||
}
|
||||
.gc-commit-row:hover { background: rgba(255,255,255,0.04); }
|
||||
.gc-commit-row:hover { background: var(--df-hover); }
|
||||
.gc-commit-row.selected { background: rgba(255,255,255,0.06); }
|
||||
.gc-commit-line1 {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
@@ -696,7 +694,7 @@ watch(() => props.refreshKey, () => {
|
||||
}
|
||||
.gc-commit-detail-header {
|
||||
display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
|
||||
padding: 8px 14px; background: rgba(255,255,255,0.03);
|
||||
padding: 8px 14px; background: var(--df-hover);
|
||||
border-bottom: 0.5px solid var(--df-border);
|
||||
}
|
||||
.gc-commit-detail-hash {
|
||||
@@ -720,14 +718,14 @@ watch(() => props.refreshKey, () => {
|
||||
/* 提交的文件列表 */
|
||||
.gc-commit-files {
|
||||
border-bottom: 0.5px solid var(--df-border);
|
||||
overflow-y: auto; max-height: 140px; scrollbar-width: thin; flex-shrink: 0;
|
||||
overflow-y: auto; max-height: 140px; flex-shrink: 0;
|
||||
}
|
||||
.gc-commit-file-row {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 5px 14px 5px 28px; cursor: pointer; transition: background 0.1s;
|
||||
border-bottom: 0.5px solid rgba(255,255,255,0.02);
|
||||
border-bottom: 0.5px solid var(--df-hover);
|
||||
}
|
||||
.gc-commit-file-row:hover { background: rgba(255,255,255,0.04); }
|
||||
.gc-commit-file-row:hover { background: var(--df-hover); }
|
||||
.gc-commit-file-row.active { background: rgba(255,255,255,0.06); }
|
||||
|
||||
/* 滑出动画 */
|
||||
@@ -757,7 +755,7 @@ watch(() => props.refreshKey, () => {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
cursor: pointer; transition: background 0.1s;
|
||||
}
|
||||
.gc-file-row:hover { background: rgba(255,255,255,0.04); }
|
||||
.gc-file-row:hover { background: var(--df-hover); }
|
||||
.gc-file-row.selected { background: rgba(255,255,255,0.06); }
|
||||
|
||||
/* 加载更多 */
|
||||
@@ -766,7 +764,7 @@ watch(() => props.refreshKey, () => {
|
||||
color: var(--df-accent); font-size: 12px;
|
||||
transition: background 0.1s; flex-shrink: 0;
|
||||
}
|
||||
.gc-load-more:hover { background: rgba(255,255,255,0.04); }
|
||||
.gc-load-more:hover { background: var(--df-hover); }
|
||||
|
||||
/* 分支列表弹窗 */
|
||||
.gc-branch-picker {
|
||||
@@ -790,7 +788,6 @@ watch(() => props.refreshKey, () => {
|
||||
.gc-branch-list {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
.gc-branch-item {
|
||||
display: flex;
|
||||
@@ -827,13 +824,9 @@ watch(() => props.refreshKey, () => {
|
||||
.gc-skeleton-row {
|
||||
height: 24px;
|
||||
border-radius: 4px;
|
||||
background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 100%);
|
||||
background: linear-gradient(90deg, var(--df-hover) 0%, rgba(255,255,255,0.08) 50%, var(--df-hover) 100%);
|
||||
background-size: 200% 100%;
|
||||
animation: gc-shimmer 1.5s infinite linear;
|
||||
}
|
||||
@keyframes gc-shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
animation: df-shimmer 1.5s infinite linear; /* 消费 global.css df-shimmer(原本地 gc-shimmer 重复定义已删) */
|
||||
}
|
||||
|
||||
/* 通用 */
|
||||
@@ -853,24 +846,5 @@ watch(() => props.refreshKey, () => {
|
||||
border: 2px solid var(--df-border); border-top-color: var(--df-accent);
|
||||
border-radius: 50%; animation: df-spin 0.8s linear infinite; display: inline-block;
|
||||
}
|
||||
@keyframes df-spin { to { transform: rotate(360deg); } }
|
||||
|
||||
/* 滚动条对齐全局(变更/历史提交列表与全局统一样式) */
|
||||
.git-changes ::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
.git-changes ::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: var(--df-radius-xs);
|
||||
}
|
||||
|
||||
.git-changes ::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
}
|
||||
|
||||
.git-changes ::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
/* df-spin keyframes 消费 global.css 全局定义(原本地同名重复定义已删,2026-10-18 整洁波) */
|
||||
</style>
|
||||
|
||||
@@ -242,13 +242,9 @@ onBeforeUnmount(() => window.removeEventListener('resize', onWinResize))
|
||||
width: 18px;
|
||||
height: 12px;
|
||||
border-radius: 3px;
|
||||
background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 100%);
|
||||
background: linear-gradient(90deg, var(--df-hover) 0%, rgba(255,255,255,0.08) 50%, var(--df-hover) 100%);
|
||||
background-size: 200% 100%;
|
||||
animation: pc-shimmer 1.5s infinite linear;
|
||||
}
|
||||
@keyframes pc-shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
animation: df-shimmer 1.5s infinite linear; /* 消费 global.css df-shimmer(原本地 pc-shimmer 重复定义已删) */
|
||||
}
|
||||
|
||||
.card-top-actions { display: flex; align-items: center; gap: 8px; }
|
||||
|
||||
@@ -91,8 +91,8 @@
|
||||
<div class="update-progress-text">{{ progressText }}</div>
|
||||
</div>
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<div v-if="installError" class="update-error">{{ installError }}</div>
|
||||
<!-- 错误提示:视觉走全局 .df-note--danger -->
|
||||
<div v-if="installError" class="df-note df-note--danger update-error">{{ installError }}</div>
|
||||
|
||||
<div class="update-card-actions">
|
||||
<button
|
||||
@@ -373,11 +373,12 @@ async function onIntervalChange() {
|
||||
.update-progress {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
/* 进度条轨道:原 --df-bg-hover 为未定义幽灵 token(靠回退侥幸渲染),改中性底 */
|
||||
.update-progress-bar {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: var(--df-bg-hover, rgba(128, 128, 128, 0.2));
|
||||
background: var(--df-neutral-bg);
|
||||
overflow: hidden;
|
||||
}
|
||||
.update-progress-fill {
|
||||
@@ -391,14 +392,9 @@ async function onIntervalChange() {
|
||||
font-family: var(--df-font-mono, monospace);
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* 安装错误提示 */
|
||||
/* 安装错误提示:底色/边/圆角/字号走全局 .df-note--danger(token 直引无回退),此处仅留排版 */
|
||||
.update-error {
|
||||
margin-bottom: 12px;
|
||||
padding: 8px 10px;
|
||||
border-radius: var(--df-radius-md, 6px);
|
||||
background: rgba(220, 53, 69, 0.12);
|
||||
font-size: 12px;
|
||||
color: var(--df-danger, #dc3545);
|
||||
line-height: 1.5;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@@ -86,11 +86,12 @@
|
||||
</div>
|
||||
|
||||
<!-- all 二次确认弹层(独立,不与 Settings 壳层共用:壳层按钮写死「删除」不适合「确认接管」) -->
|
||||
<Transition name="confirm">
|
||||
<!-- 按钮行/过渡消费 global.css .df-confirm-actions + df-confirm(2026-10-18 整洁波并轨) -->
|
||||
<Transition name="df-confirm">
|
||||
<div v-if="confirmState.visible" class="confirm-mask" @click.self="answerConfirm(false)">
|
||||
<div class="confirm-box">
|
||||
<div class="confirm-msg">{{ confirmState.msg }}</div>
|
||||
<div class="confirm-actions">
|
||||
<div class="df-confirm-actions">
|
||||
<button class="btn btn-ghost btn-sm" @click="answerConfirm(false)">{{ $t('common.cancel') }}</button>
|
||||
<button class="btn btn-danger btn-sm" @click="answerConfirm(true)">{{ confirmState.dangerLabel || $t('common.confirm') }}</button>
|
||||
</div>
|
||||
@@ -252,8 +253,9 @@ function onApprovalTimeoutChange() {
|
||||
.setting-select/.setting-textarea + SettingRow(封装 .setting-row/.setting-info/.setting-label/
|
||||
.setting-desc/.setting-control)。本 Section 仅保留 all 二次确认弹层特有 scoped 样式。
|
||||
|
||||
F-#97 all 二次确认弹层:复用 Settings.vue 壳层 confirm 弹层同款样式(mask/box/msg/
|
||||
actions/transition),此处独立持有 useConfirm 状态(不与壳层共用,壳层按钮写死「删除」)。 */
|
||||
F-#97 all 二次确认弹层:mask/box/msg 本地特有样式;actions 按钮行与过渡已并轨
|
||||
global.css .df-confirm-actions + df-confirm 过渡(2026-10-18 整洁波双轨合一)。
|
||||
此处独立持有 useConfirm 状态(不与壳层共用,壳层按钮写死「删除」)。 */
|
||||
.data-dir-path {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
@@ -284,8 +286,6 @@ function onApprovalTimeoutChange() {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
.prompt-row .setting-info { align-items: flex-start; }
|
||||
.prompt-row .setting-control { align-items: flex-start; }
|
||||
/* select 类设置行(自定义布局,不复用 SettingRow):label 与 select 同一行靠左顶对齐,
|
||||
desc 换行到整行下方。
|
||||
┌───────────────────────────────┐
|
||||
@@ -326,12 +326,7 @@ function onApprovalTimeoutChange() {
|
||||
padding: 20px;
|
||||
min-width: 280px;
|
||||
max-width: 420px;
|
||||
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
|
||||
box-shadow: var(--df-shadow-md);
|
||||
}
|
||||
.confirm-msg { font-size: 13px; color: var(--df-text); line-height: 1.5; margin-bottom: 16px; white-space: pre-line; }
|
||||
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
||||
.btn-danger { background: var(--df-danger); color: #fff; }
|
||||
.btn-danger:hover { filter: brightness(1.1); }
|
||||
.confirm-enter-active, .confirm-leave-active { transition: opacity 0.15s; }
|
||||
.confirm-enter-from, .confirm-leave-to { opacity: 0; }
|
||||
</style>
|
||||
|
||||
@@ -87,12 +87,13 @@
|
||||
</section>
|
||||
|
||||
<!-- 「信任所有目录」二次确认弹层(同 AdvancedSection 的 all 接管确认:自渲染独立弹层,
|
||||
msg 拼标题+正文,confirm-msg 用 pre-line 保留换行) -->
|
||||
<Transition name="confirm">
|
||||
msg 拼标题+正文,confirm-msg 用 pre-line 保留换行;
|
||||
按钮行/过渡消费 global.css .df-confirm-actions + df-confirm,2026-10-18 整洁波并轨) -->
|
||||
<Transition name="df-confirm">
|
||||
<div v-if="confirmState.visible" class="confirm-mask" @click.self="answerConfirm(false)">
|
||||
<div class="confirm-box">
|
||||
<div class="confirm-msg">{{ confirmState.msg }}</div>
|
||||
<div class="confirm-actions">
|
||||
<div class="df-confirm-actions">
|
||||
<button class="btn btn-ghost btn-sm" @click="answerConfirm(false)">{{ $t('common.cancel') }}</button>
|
||||
<button class="btn btn-danger btn-sm" @click="answerConfirm(true)">{{ confirmState.dangerLabel || $t('common.confirm') }}</button>
|
||||
</div>
|
||||
@@ -296,8 +297,10 @@ onMounted(load)
|
||||
.script-safety-desc {
|
||||
font-size: 12px; color: var(--df-text-dim); margin: 0 0 4px; line-height: 1.5;
|
||||
}
|
||||
/* 名单输入定宽 280px + max-width 窄窗收缩(原 min-width:280px 在窄列不可收缩致横向溢出) */
|
||||
.script-safety-input {
|
||||
min-width: 280px;
|
||||
width: 280px;
|
||||
max-width: 100%;
|
||||
font-family: var(--df-font-mono, monospace);
|
||||
}
|
||||
.script-safety-note {
|
||||
@@ -321,12 +324,7 @@ onMounted(load)
|
||||
padding: 20px;
|
||||
min-width: 280px;
|
||||
max-width: 420px;
|
||||
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
|
||||
box-shadow: var(--df-shadow-md);
|
||||
}
|
||||
.confirm-msg { font-size: 13px; color: var(--df-text); line-height: 1.5; margin-bottom: 16px; white-space: pre-line; }
|
||||
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
||||
.btn-danger { background: var(--df-danger); color: #fff; }
|
||||
.btn-danger:hover { filter: brightness(1.1); }
|
||||
.confirm-enter-active, .confirm-leave-active { transition: opacity 0.15s; }
|
||||
.confirm-enter-from, .confirm-leave-to { opacity: 0; }
|
||||
</style>
|
||||
|
||||
@@ -263,13 +263,10 @@ onMounted(loadConnections)
|
||||
<style scoped>
|
||||
/* 阶段1/3 UX 重构:panel/panel-header/empty-hint/btn 系列/setting-select/setting-input
|
||||
已迁移到 settings.css 全局。
|
||||
本 scoped 仅保留 ConnectionPanel 特有样式:connection-card/conn 系列/type 系列/form 系列/
|
||||
btn-link 及 form-field 内输入控件布局覆盖等。 */
|
||||
本 scoped 仅保留 ConnectionPanel 特有样式:connection-card/conn 系列/type 系列/form 系列
|
||||
及 form-field 内输入控件布局覆盖等。 */
|
||||
|
||||
/* ===== 链接按钮(本面板特有,未进全局) ===== */
|
||||
.btn-link { background: none; border: none; color: var(--df-accent); font-size: 12px; cursor: pointer; padding: 2px 6px; }
|
||||
.btn-link:hover { text-decoration: underline; }
|
||||
.btn-link-danger { color: var(--df-danger); }
|
||||
/* 链接按钮 .btn-link/.btn-link-danger 已并轨 global.css(样式大重构去重) */
|
||||
|
||||
/* ===== 标题组(panel-header 内 标题+badge 一组,与右侧按钮 space-between) ===== */
|
||||
.panel-title-group { display: flex; align-items: center; gap: 8px; }
|
||||
@@ -307,10 +304,10 @@ onMounted(loadConnections)
|
||||
border-radius: var(--df-radius-sm);
|
||||
font-weight: 500;
|
||||
}
|
||||
.type-mysql { background: rgba(100,181,246,0.15); color: var(--df-info); }
|
||||
.type-mysql { background: var(--df-info-bg); color: var(--df-info); }
|
||||
.type-ssh { background: var(--df-accent-soft); color: var(--df-accent); }
|
||||
.type-redis { background: rgba(255,107,107,0.15); color: var(--df-danger); }
|
||||
.type-mongo { background: rgba(100,255,218,0.15); color: var(--df-success); }
|
||||
.type-redis { background: var(--df-danger-bg); color: var(--df-danger); }
|
||||
.type-mongo { background: var(--df-success-bg); color: var(--df-success); }
|
||||
|
||||
.conn-host, .conn-user {
|
||||
font-size: 12px;
|
||||
@@ -318,7 +315,7 @@ onMounted(loadConnections)
|
||||
font-family: var(--df-font-mono);
|
||||
}
|
||||
.conn-user {
|
||||
background: rgba(90,99,128,0.2);
|
||||
background: var(--df-neutral-bg);
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
}
|
||||
|
||||
@@ -142,9 +142,11 @@ async function save() {
|
||||
<style scoped>
|
||||
/* panel/panel-header/btn 系列/setting-input 均在 settings.css 全局,此处仅本面板特有样式 */
|
||||
.feishu-settings { display: flex; flex-direction: column; gap: 4px; }
|
||||
.feishu-input { width: 280px; }
|
||||
/* 定宽输入补 max-width,窄窗收缩防横向溢出 */
|
||||
.feishu-input { width: 280px; max-width: 100%; }
|
||||
.feishu-whitelist {
|
||||
width: 320px;
|
||||
max-width: 100%;
|
||||
min-height: 64px;
|
||||
resize: vertical;
|
||||
font-family: var(--df-font-mono, monospace);
|
||||
@@ -153,7 +155,7 @@ async function save() {
|
||||
margin: 0 0 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--df-text-tertiary, #888);
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
.actions { display: flex; gap: 8px; margin-top: 8px; }
|
||||
</style>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
</select>
|
||||
</SettingRow>
|
||||
<SettingRow v-if="knowledgeConfig.vector_enabled" ref="rowEmbeddingModel" :label="$t('settings.labelEmbeddingModel')" :desc="$t('settings.descEmbeddingModel')">
|
||||
<input type="text" :value="knowledgeConfig.embedding_model ?? ''" @input="knowledgeConfig.embedding_model = ($event.target as HTMLInputElement).value || null" @change="markSaved('embeddingModel')" class="setting-input" :placeholder="$t('settings.phEmbeddingModel')" style="width:220px" />
|
||||
<input type="text" :value="knowledgeConfig.embedding_model ?? ''" @input="knowledgeConfig.embedding_model = ($event.target as HTMLInputElement).value || null" @change="markSaved('embeddingModel')" class="setting-input" :placeholder="$t('settings.phEmbeddingModel')" style="width:220px; max-width:100%" />
|
||||
</SettingRow>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -5,55 +5,9 @@
|
||||
<h2>{{ $t('settings.panelAiProvider') }}</h2>
|
||||
<button class="btn btn-ghost btn-sm" @click="openProviderForm()">{{ $t('settings.addProvider') }}</button>
|
||||
</div>
|
||||
<div class="provider-list" v-if="aiProviders.length > 0">
|
||||
<div class="provider-card" :class="{ 'provider-card--default': p.is_default, 'provider-card--disabled': p.enabled === false }" v-for="p in aiProviders" :key="p.id">
|
||||
<div class="provider-top">
|
||||
<div class="provider-info">
|
||||
<span class="provider-name">{{ p.name }}</span>
|
||||
<span v-if="p.is_default" class="default-badge">{{ $t('settings.badgeDefault') }}</span>
|
||||
<span v-if="p.enabled === false" class="pool-badge">{{ $t('settings.badgePoolDisabled') }}</span>
|
||||
</div>
|
||||
<div class="provider-actions">
|
||||
<button class="btn-link" @click="setDefaultProvider(p.id)" v-if="!p.is_default">{{ $t('settings.actionSetDefault') }}</button>
|
||||
<button class="btn-link" @click="openProviderForm(p)">{{ $t('common.edit') }}</button>
|
||||
<button class="btn-link btn-link-danger" @click="deleteProvider(p.id)">{{ $t('common.delete') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="provider-detail">
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ $t('settings.detailBaseUrl') }}</span>
|
||||
<span class="detail-value">{{ p.base_url }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ $t('settings.detailModel') }}</span>
|
||||
<span class="detail-value">{{ p.default_model }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ $t('settings.detailApiKey') }}</span>
|
||||
<span class="detail-value mask">{{ maskKey(p.api_key) }}</span>
|
||||
</div>
|
||||
<!-- F-260614-04c 负载均衡池:enabled toggle + weight 即时调 IPC,落库即重建 caps -->
|
||||
<div class="detail-row detail-row--pool">
|
||||
<span class="detail-label" :title="$t('settings.descPoolEnabled')">{{ $t('settings.detailPoolEnabled') }}</span>
|
||||
<div class="detail-value detail-value--control">
|
||||
<label class="toggle toggle--sm" :title="$t('settings.descPoolEnabled')">
|
||||
<input type="checkbox" :checked="p.enabled !== false" @change="onPoolToggle(p, ($event.target as HTMLInputElement).checked)" />
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="detail-row detail-row--pool" v-if="p.enabled !== false">
|
||||
<span class="detail-label" :title="$t('settings.descPoolWeight')">{{ $t('settings.detailPoolWeight') }}</span>
|
||||
<div class="detail-value detail-value--control">
|
||||
<input type="number" class="setting-input setting-input--sm" min="0" max="100"
|
||||
:value="p.weight ?? 50"
|
||||
@change="onPoolWeightChange(p, ($event.target as HTMLInputElement).valueAsNumber)" />
|
||||
<span class="pool-weight-hint">0-100</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 卡片列表 + 负载均衡池控件拆至 provider-panel/provider-list.vue(C4c) -->
|
||||
<ProviderList v-if="aiProviders.length > 0" ref="providerListRef" :providers="aiProviders"
|
||||
@edit="openProviderForm" @delete="deleteProvider" @set-default="setDefaultProvider" @toast="relayToast" />
|
||||
<div class="empty-hint" v-else>{{ $t('settings.emptyProvider') }}</div>
|
||||
</section>
|
||||
|
||||
@@ -127,8 +81,8 @@
|
||||
</div>
|
||||
<!-- P0-2: 保存失败持久错误横幅(常驻表单内,非自隐 toast)。
|
||||
含分类建议:keyring/迁移失败 → 查系统钥匙串权限;其它 → 通用重试。
|
||||
用户看到错误同时表单保持编辑态,改完点保存即可重试。 -->
|
||||
<div v-if="providerForm.saveError" class="save-error-banner">
|
||||
用户看到错误同时表单保持编辑态,改完点保存即可重试。视觉走全局 .df-note--danger。 -->
|
||||
<div v-if="providerForm.saveError" class="df-note df-note--danger">
|
||||
<pre class="save-error-msg">{{ providerForm.saveError }}</pre>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
@@ -140,59 +94,10 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ═══ 拉取到的模型列表(F-01 阶段6)═══ -->
|
||||
<!-- ═══ 拉取到的模型列表(F-01 阶段6;表格+标签标注拆至 provider-panel/model-table.vue)═══ -->
|
||||
<div class="form-field form-field--full" v-if="providerForm.models.length > 0">
|
||||
<label class="form-label">{{ $t('settings.modelListTitle', { count: providerForm.models.length }) }}</label>
|
||||
<table class="model-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-enabled">{{ $t('settings.colEnabled') }}</th>
|
||||
<th class="col-model">{{ $t('settings.colModel') }}</th>
|
||||
<th class="col-ability">{{ $t('settings.colAbility') }}</th>
|
||||
<th class="col-weight">{{ $t('settings.labelWeight') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="m in providerForm.models" :key="m.model_id">
|
||||
<td class="col-enabled">
|
||||
<label class="toggle toggle--sm">
|
||||
<input type="checkbox" v-model="m.enabled" />
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</td>
|
||||
<td class="col-model">
|
||||
<span class="model-id">{{ m.model_id }}</span>
|
||||
</td>
|
||||
<td class="col-ability">
|
||||
<!-- 能力/模态标签(可编辑:点 × 删除;点 + 添加;手动改后标为「手动」) -->
|
||||
<div class="model-tags">
|
||||
<span v-for="md in m.modalities" v-show="!redundantTags.modalities.has(md)" :key="'md-' + md"
|
||||
class="tag tag-modality" :title="$t('settings.tagTooltipModality')">
|
||||
{{ $t('settings.tagModality.' + md) }}<span class="tag-remove" role="button" tabindex="0" :aria-label="$t('common.delete')" @click.stop="removeModality(m, md)" @keydown.enter.prevent="removeModality(m, md)" @keydown.space.prevent="removeModality(m, md)">×</span>
|
||||
</span>
|
||||
<span v-for="cap in m.capabilities" v-show="!redundantTags.capabilities.has(cap)" :key="'cap-' + cap"
|
||||
class="tag tag-capability" :title="$t('settings.tagTooltipCapability')">
|
||||
{{ $t('settings.tagCapability.' + cap) }}<span class="tag-remove" role="button" tabindex="0" :aria-label="$t('common.delete')" @click.stop="removeCapability(m, cap)" @keydown.enter.prevent="removeCapability(m, cap)" @keydown.space.prevent="removeCapability(m, cap)">×</span>
|
||||
</span>
|
||||
<span v-if="m.probe_source && m.probe_source !== 'user_set'" v-show="!redundantTags.sources.has(m.probe_source)"
|
||||
class="tag tag-source" :title="$t('settings.tagTooltipSource')">{{ $t('settings.tagSource.' + m.probe_source) }}</span>
|
||||
<span v-if="m.probe_source === 'user_set'" class="tag tag-source" :title="$t('settings.tagTooltipSource')">{{ $t('settings.tagSource.user_set') }}</span>
|
||||
<span class="tag-add" role="button" tabindex="0" :title="$t('settings.addTagTitle')" :aria-label="$t('settings.addTagTitle')" @click.stop="startAddTag(m)" @keydown.enter.prevent="startAddTag(m)" @keydown.space.prevent="startAddTag(m)">+</span>
|
||||
</div>
|
||||
<!-- 添加能力内联菜单(点+展开;选未有的能力/模态即添加) -->
|
||||
<div v-if="addingTagModel === m.model_id" class="add-tag-menu">
|
||||
<span v-for="opt in addableTags(m)" :key="opt.kind + '-' + opt.key"
|
||||
class="tag" :class="opt.kind === 'modality' ? 'tag-modality' : 'tag-capability'"
|
||||
@click.stop="addTag(m, opt.key, opt.kind)">{{ opt.label }}</span>
|
||||
<span v-if="addableTags(m).length === 0" class="add-tag-empty">{{ $t('settings.addTagNone') }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="col-weight">
|
||||
<input type="number" class="setting-input setting-input--sm" min="0" max="100" v-model.number="m.weight" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ModelTable :models="providerForm.models" />
|
||||
<div class="model-list-hint">{{ $t('settings.modelListHint') }}</div>
|
||||
<!-- M32: 模型列表 enabled/weight 改了未保存时显提示(关闭/切走将丢弃) -->
|
||||
<div v-if="isFormDirty" class="model-list-unsaved-hint">{{ $t('settings.modelListUnsavedHint') }}</div>
|
||||
@@ -205,11 +110,17 @@
|
||||
import { reactive, ref, computed, onMounted, useTemplateRef } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { aiApi } from '@/api'
|
||||
import type { AiProviderConfig, ModelConfig, Modality, Capability, ProbeSource } from '@/api/types'
|
||||
import type { AiProviderConfig, ModelConfig } from '@/api/types'
|
||||
import { PROVIDER_PRESETS, CUSTOM_PRESET_ID, findPreset } from './providerPresets'
|
||||
import ProviderList from './provider-panel/provider-list.vue'
|
||||
import ModelTable from './provider-panel/model-table.vue'
|
||||
|
||||
// ============================================================
|
||||
// AI 提供商域 — 真实后端 CRUD + c 负载均衡池(enabled / weight)
|
||||
// C4c 拆分:卡片列表+池控件 → provider-panel/provider-list.vue;
|
||||
// 模型表格+能力标签标注 → provider-panel/model-table.vue。
|
||||
// 本件保留:表单状态机(校验红框/温度与权重钳制/快照脏判)、保存/测试连接/预设回填、
|
||||
// 列表 CRUD 与 loadProviders 闭环、对壳 defineExpose 契约。
|
||||
// ============================================================
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -286,37 +197,7 @@ const providerForm = reactive({
|
||||
savedSnapshot: '' as string,
|
||||
})
|
||||
|
||||
/**
|
||||
* 冗余标签判定:全模型共有的 modality/capability/probe_source 无区分度,
|
||||
* 每行都渲染会刷屏(如全部命中预设表 → 全是「预设」;对话模型默认 ToolUse → 全是「工具调用」)。
|
||||
* 计算「所有模型都含」的值集合,模板渲染时跳过 → 只显示有区分度的标签。
|
||||
*/
|
||||
const redundantTags = computed(() => {
|
||||
const models = providerForm.models
|
||||
// SA-6: 去冗余的前提是「模型间对比」——仅 1 个模型时它的所有标签都满足「全模型共有」,
|
||||
// 无脑隐藏会把唯一模型的能力标签全抹掉(行内空白,用户看不到该模型能力)。
|
||||
// 故 ≥2 个模型起才去冗余;0/1 个一律全显(sources 分支本就 <2 直接放行,此处对齐)。
|
||||
if (models.length < 2) return { modalities: new Set<string>(), capabilities: new Set<string>(), sources: new Set<string>() }
|
||||
const common = (pick: (m: ModelConfig) => string[]) => {
|
||||
const sets = models.map(m => new Set(pick(m)))
|
||||
const first = sets[0]
|
||||
const result = new Set<string>()
|
||||
for (const v of first) {
|
||||
if (sets.every(s => s.has(v))) result.add(v)
|
||||
}
|
||||
return result
|
||||
}
|
||||
return {
|
||||
modalities: common(m => m.modalities),
|
||||
capabilities: common(m => m.capabilities),
|
||||
// 探测来源:全模型相同的值也冗余(如全 PresetTable)
|
||||
sources: (() => {
|
||||
const vals = models.map(m => m.probe_source).filter((v): v is ProbeSource => !!v)
|
||||
if (vals.length < 2) return new Set<string>()
|
||||
return new Set([...new Set(vals)].filter(v => vals.every(x => x === v)))
|
||||
})(),
|
||||
}
|
||||
})
|
||||
// (冗余标签判定 redundantTags 随模型表格拆至 provider-panel/model-table.vue)
|
||||
|
||||
/**
|
||||
* L19/M32: 表单脏判定——当前表单状态与已落库快照不一致即脏。
|
||||
@@ -349,59 +230,7 @@ function formBusinessSnapshot(): string {
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 模型能力手动标注(表格内编辑 tags;改动即标 UserSet,手动优先)
|
||||
// ============================================================
|
||||
|
||||
/** 当前展开「添加能力」菜单的模型名;null=无展开 */
|
||||
const addingTagModel = ref<string | null>(null)
|
||||
|
||||
/** 可添加的模态(与 tagModality 对齐;text 是对话基础模态,允许删但一般不主动加) */
|
||||
const ADDABLE_MODALITIES: Modality[] = ['text', 'vision', 'audio', 'video']
|
||||
/** 可添加的能力 */
|
||||
const ADDABLE_CAPABILITIES: Capability[] = ['tool_use', 'embedding', 'code_gen']
|
||||
|
||||
/** 某模型可添加的可选 tag(模态 + 能力,排除已选的) */
|
||||
function addableTags(m: ModelConfig): { key: string; kind: 'modality' | 'capability'; label: string }[] {
|
||||
const mods = ADDABLE_MODALITIES
|
||||
.filter(x => !m.modalities.includes(x))
|
||||
.map(x => ({ key: x, kind: 'modality' as const, label: t('settings.tagModality.' + x) }))
|
||||
const caps = ADDABLE_CAPABILITIES
|
||||
.filter(x => !m.capabilities.includes(x))
|
||||
.map(x => ({ key: x, kind: 'capability' as const, label: t('settings.tagCapability.' + x) }))
|
||||
return [...mods, ...caps]
|
||||
}
|
||||
|
||||
/** 标记模型为「手动标注」(probe_source=user_set),下次探测不覆盖 */
|
||||
function markManual(m: ModelConfig) {
|
||||
m.probe_source = 'user_set'
|
||||
addingTagModel.value = null
|
||||
}
|
||||
|
||||
function removeModality(m: ModelConfig, md: Modality) {
|
||||
m.modalities = m.modalities.filter(x => x !== md)
|
||||
markManual(m)
|
||||
}
|
||||
|
||||
function removeCapability(m: ModelConfig, cap: Capability) {
|
||||
m.capabilities = m.capabilities.filter(x => x !== cap)
|
||||
markManual(m)
|
||||
}
|
||||
|
||||
function addTag(m: ModelConfig, key: string, kind: 'modality' | 'capability') {
|
||||
if (kind === 'modality') {
|
||||
const md = key as Modality
|
||||
if (!m.modalities.includes(md)) m.modalities = [...m.modalities, md]
|
||||
} else {
|
||||
const cap = key as Capability
|
||||
if (!m.capabilities.includes(cap)) m.capabilities = [...m.capabilities, cap]
|
||||
}
|
||||
markManual(m)
|
||||
}
|
||||
|
||||
function startAddTag(m: ModelConfig) {
|
||||
addingTagModel.value = addingTagModel.value === m.model_id ? null : m.model_id
|
||||
}
|
||||
// (模型能力手动标注 tag 编辑块随模型表格拆至 provider-panel/model-table.vue)
|
||||
|
||||
/**
|
||||
* L19: 关闭表单入口——脏表单二次确认,清表单后关闭。
|
||||
@@ -677,64 +506,15 @@ async function setDefaultProvider(id: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// c: 负载均衡池可编辑层(enabled / weight)
|
||||
// 卡片即时调 IPC(对齐 syncConcurrencyConfig 模式);落库后后端 reload_provider_caps
|
||||
// 重建 per_provider caps,下条消息即按新配置 acquire。
|
||||
// 不走 saveProvider(全量 INSERT OR REPLACE 会触发 R-PD-1 密钥迁移分支,与 c 轻量 UPDATE 路径冲突)。
|
||||
// ============================================================
|
||||
// 计时器按 provider id 分键:单例计时器下 300ms 内先后改两家权重,B 的变更会清掉
|
||||
// A 尚未落库的保存,先改的一方静默丢失(走查 P2-8)。
|
||||
const _poolTimers = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
// (负载均衡池 enabled/weight 即时 IPC 块随卡片列表拆至 provider-panel/provider-list.vue)
|
||||
|
||||
/**
|
||||
* toggle 即时生效(开关语义=立即入/出池,无 debounce 必要;但失败需回滚视图)。
|
||||
* 乐观更新本地数组,失败 revert + toast。
|
||||
*/
|
||||
async function onPoolToggle(p: AiProviderConfig, enabled: boolean) {
|
||||
const prev = p.enabled
|
||||
p.enabled = enabled
|
||||
try {
|
||||
// 防御钳制:p.weight 理论上已被 onPoolWeightChange 钳过,此处兜底防脏数据直传 IPC
|
||||
const w = Math.min(100, Math.max(0, p.weight ?? 50))
|
||||
await aiApi.updateProviderPool(p.id, enabled, w)
|
||||
emit('toast', t('settings.toastPoolUpdateOk'), 'info')
|
||||
} catch (e) {
|
||||
p.enabled = prev // revert
|
||||
console.error(t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), e)
|
||||
emit('toast', t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), 'error')
|
||||
}
|
||||
/** 子件 toast 上抛中继(池控件 IPC 结果反馈) */
|
||||
function relayToast(msg: string, type: 'error' | 'warning' | 'info' | 'success') {
|
||||
emit('toast', msg, type)
|
||||
}
|
||||
|
||||
/**
|
||||
* weight 变更 debounce 300ms(防快速连续输入触发频繁 IPC),clamp [0,100] 对齐后端。
|
||||
* 双 clamp:前端 clamp 视觉输入 + 后端 command 再 clamp(防御性)。
|
||||
*/
|
||||
function onPoolWeightChange(p: AiProviderConfig, raw: number) {
|
||||
// NaN 兜底(清空输入):回退 50,防 IPC 传 NaN 后端 serde u32 失败
|
||||
const clamped = Math.min(100, Math.max(0, Number.isFinite(raw) ? Math.trunc(raw) : 50))
|
||||
const prev = p.weight
|
||||
p.weight = clamped
|
||||
// 仅重置同一 provider 的待发计时;跨 provider 互不干扰
|
||||
const prevTimer = _poolTimers.get(p.id)
|
||||
if (prevTimer) clearTimeout(prevTimer)
|
||||
_poolTimers.set(p.id, setTimeout(async () => {
|
||||
_poolTimers.delete(p.id)
|
||||
try {
|
||||
await aiApi.updateProviderPool(p.id, p.enabled !== false, clamped)
|
||||
emit('toast', t('settings.toastPoolUpdateOk'), 'info')
|
||||
} catch (e) {
|
||||
p.weight = prev // revert
|
||||
console.error(t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), e)
|
||||
emit('toast', t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), 'error')
|
||||
}
|
||||
}, 300))
|
||||
}
|
||||
|
||||
function maskKey(key: string): string {
|
||||
if (!key || key.length < 8) return '••••••••'
|
||||
return key.slice(0, 4) + '••••••••' + key.slice(-4)
|
||||
}
|
||||
/** 卡片列表子件引用(池 debounce 计时器下沉子件,卸载清理经此委托) */
|
||||
const providerListRef = useTemplateRef<InstanceType<typeof ProviderList>>('providerListRef')
|
||||
|
||||
/** 暴露给 shell:loadProviders 供外部主动刷新 / Knowledge 读 aiProviders / 卸载清 timer。
|
||||
* L19: isFormDirty + closeProviderForm 暴露,供外部(如导航切走前)查询/触发拦截。
|
||||
@@ -744,7 +524,7 @@ defineExpose({
|
||||
loadProviders,
|
||||
isFormDirty,
|
||||
closeProviderForm,
|
||||
clearPoolTimer() { for (const t of _poolTimers.values()) clearTimeout(t); _poolTimers.clear() },
|
||||
clearPoolTimer() { providerListRef.value?.clearPoolTimer() },
|
||||
})
|
||||
|
||||
// 阶段3 UX 重构:本面板改为 ai-model 类懒挂载,不再由 Settings.vue onMounted 调用,
|
||||
@@ -754,92 +534,24 @@ onMounted(loadProviders)
|
||||
|
||||
<style scoped>
|
||||
/* 阶段1/3 UX 重构:panel/panel-header/empty-hint/btn 系列/setting-select/
|
||||
setting-input/toggle/toggle-slider 已迁移到 settings.css 全局。
|
||||
本 scoped 仅保留 ProviderPanel 特有样式:provider-card/default-badge/
|
||||
pool-badge/detail 系列/form 系列/btn-link/toggle--sm 及输入控件布局覆盖等。
|
||||
setting-input/toggle/toggle-slider 已迁移到 settings.css 全局,btn-link 已并轨 global.css。
|
||||
C4c 拆分:provider 卡片/池控件样式随 provider-list.vue、模型表格/标签样式随
|
||||
model-table.vue 下沉子件;本 scoped 仅保留表单区样式(form 系列/红框/错误横幅/
|
||||
模型列表区容器与提示行)。.setting-input--sm/.toggle--sm 为两子件共用,各持一份。
|
||||
注:注释列举类名时勿写星斜杠序列(会提前闭合 CSS 注释)。 */
|
||||
|
||||
/* ===== 链接按钮(本面板特有,未进全局) ===== */
|
||||
.btn-link { background: none; border: none; color: var(--df-accent); font-size: 12px; cursor: pointer; padding: 2px 6px; }
|
||||
.btn-link:hover { text-decoration: underline; }
|
||||
.btn-link-danger { color: var(--df-danger); }
|
||||
|
||||
/* ===== Provider 卡片 ===== */
|
||||
.provider-list { display: flex; flex-direction: column; gap: 12px; }
|
||||
.provider-card {
|
||||
background: var(--df-bg);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.provider-card--default {
|
||||
border-color: var(--df-accent);
|
||||
box-shadow: inset 3px 0 0 var(--df-accent);
|
||||
}
|
||||
.provider-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.provider-info { display: flex; align-items: center; gap: 8px; }
|
||||
.provider-name { font-size: 14px; font-weight: 500; color: var(--df-text); }
|
||||
.default-badge {
|
||||
font-size: 10px;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: rgba(100,255,218,0.15);
|
||||
color: var(--df-success);
|
||||
font-weight: 500;
|
||||
}
|
||||
.provider-actions { display: flex; gap: 4px; }
|
||||
|
||||
.provider-detail { display: flex; flex-direction: column; gap: 6px; }
|
||||
.detail-row { display: flex; align-items: flex-start; gap: 12px; }
|
||||
.detail-label {
|
||||
font-size: 12px;
|
||||
color: var(--df-text-dim);
|
||||
min-width: 60px;
|
||||
}
|
||||
.detail-value {
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
font-family: var(--df-font-mono);
|
||||
}
|
||||
.detail-value.mask { color: var(--df-text-dim); letter-spacing: 1px; }
|
||||
|
||||
/* Provider 卡片 disabled 态(c:enabled=false 视觉弱化) */
|
||||
.provider-card--disabled { opacity: 0.6; }
|
||||
.pool-badge {
|
||||
font-size: 10px;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: rgba(255,107,107,0.15);
|
||||
color: var(--df-danger);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 负载均衡池行(toggle / weight 控件) */
|
||||
.detail-row--pool { align-items: center; }
|
||||
.detail-value--control { display: flex; align-items: center; gap: 8px; font-family: var(--df-font-mono); }
|
||||
.pool-weight-hint { font-size: 11px; color: var(--df-text-dim); }
|
||||
|
||||
/* 表单(本面板特有输入控件样式;.setting-select 走全局) */
|
||||
.form-grid { display: flex; flex-direction: column; gap: 14px; }
|
||||
/* 表单(本面板特有输入控件样式;.setting-select 走全局)。
|
||||
--form-label-w 为标签列宽单一来源:hint 缩进用 calc(label 列宽+行 gap) 对齐 input 位,
|
||||
免手算魔法数。 */
|
||||
.form-grid { --form-label-w: 72px; display: flex; flex-direction: column; gap: 14px; }
|
||||
.form-field { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
||||
.form-label { flex: 0 0 72px; font-size: 12px; font-weight: 500; color: var(--df-text-secondary); text-align: right; }
|
||||
.form-label { flex: 0 0 var(--form-label-w); font-size: 12px; font-weight: 500; color: var(--df-text-secondary); text-align: right; }
|
||||
/* 字段级辅助说明(默认模型提示等):弱化色 + 小字,与 label/input 区分层级。
|
||||
横向布局下占满整行换到 label+input 下方。 */
|
||||
.form-field-hint { flex-basis: 100%; margin-left: 82px; font-size: 11px; color: var(--df-text-dim); line-height: 1.5; }
|
||||
横向布局下占满整行换到 label+input 下方,缩进与 input 左缘结构对齐。 */
|
||||
.form-field-hint { flex-basis: 100%; margin-left: calc(var(--form-label-w) + 10px); font-size: 11px; color: var(--df-text-dim); line-height: 1.5; }
|
||||
.form-actions { display: flex; justify-content: flex-end; padding-top: 4px; }
|
||||
|
||||
/* 保存失败持久错误横幅(常驻 form-actions 上方,醒目于自隐 toast) */
|
||||
.save-error-banner {
|
||||
background: var(--df-danger-bg);
|
||||
border: 0.5px solid var(--df-danger);
|
||||
border-radius: var(--df-radius-sm);
|
||||
padding: 10px 12px;
|
||||
}
|
||||
/* 保存失败持久错误横幅:视觉(底色/边/圆角/内距)走全局 .df-note--danger,此处仅留内部排版 */
|
||||
.save-error-msg {
|
||||
margin: 0;
|
||||
font-family: var(--df-font-sans);
|
||||
@@ -860,12 +572,6 @@ onMounted(loadProviders)
|
||||
/* 走查 P3-10:校验缺失字段红框(@input 即清,用户开始修正就不再红) */
|
||||
.setting-input--invalid { border-color: var(--df-danger) !important; }
|
||||
.setting-input--invalid:focus { border-color: var(--df-danger) !important; box-shadow: 0 0 0 1px var(--df-danger); }
|
||||
.setting-input--sm { flex: 0 0 auto; min-width: 0; width: 70px; padding: 4px 8px; font-size: 12px; }
|
||||
|
||||
/* Toggle 小号变体(本面板负载均衡池用;.toggle 基础走全局) */
|
||||
.toggle--sm { width: 32px; height: 18px; }
|
||||
.toggle--sm .toggle-slider::before { width: 12px; height: 12px; left: 3px; bottom: 3px; }
|
||||
.toggle--sm input:checked + .toggle-slider::before { transform: translateX(14px); }
|
||||
|
||||
/* M32: 模型列表有未保存调整时的提示(弱 warning 色,贴合 model-list-hint 之下) */
|
||||
.model-list-unsaved-hint {
|
||||
@@ -874,86 +580,6 @@ onMounted(loadProviders)
|
||||
line-height: 1.5;
|
||||
color: var(--df-warning);
|
||||
}
|
||||
|
||||
/* ===== 模型列表(表格形式:表头 + 数据行) =====
|
||||
原 model-list/model-row 等无任何样式定义(裸渲染),本批补齐并改为表格。
|
||||
风格对齐 provider-card(浅底 / 圆角 / 0.5px 边框)。 */
|
||||
.model-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
overflow: hidden;
|
||||
font-size: 12px;
|
||||
}
|
||||
.model-table th,
|
||||
.model-table td {
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.model-table thead th {
|
||||
background: var(--df-bg);
|
||||
font-weight: 500;
|
||||
color: var(--df-text-dim);
|
||||
font-size: 11px;
|
||||
border-bottom: 0.5px solid var(--df-border);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.model-table tbody tr { border-bottom: 0.5px solid var(--df-border); }
|
||||
.model-table tbody tr:last-child { border-bottom: none; }
|
||||
.model-table tbody tr:hover { background: var(--df-accent-bg); }
|
||||
/* 列宽:启用窄、模型/能力弹性、权重窄 */
|
||||
.model-table .col-enabled { width: 56px; text-align: center; }
|
||||
.model-table .col-weight { width: 110px; }
|
||||
.model-table .col-model { min-width: 140px; }
|
||||
.col-enabled .toggle--sm { display: inline-block; }
|
||||
.model-id {
|
||||
font-size: 13px;
|
||||
font-family: var(--df-font-mono);
|
||||
color: var(--df-text);
|
||||
font-weight: 500;
|
||||
word-break: break-all;
|
||||
}
|
||||
/* 标签列:小圆角 chip,三类语义色区分 */
|
||||
.model-tags { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.tag {
|
||||
font-size: 10px;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--df-radius-xs);
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tag-modality { background: rgba(100,181,246,0.15); color: var(--df-info); }
|
||||
.tag-capability { background: rgba(108,99,255,0.15); color: var(--df-accent); }
|
||||
.tag-source { background: rgba(90,99,128,0.2); color: var(--df-text-dim); }
|
||||
/* 可编辑 tag:×删除按钮(悬停显红)+ 添加按钮 */
|
||||
.tag-remove { margin-left: 3px; cursor: pointer; opacity: 0.6; font-weight: 700; }
|
||||
.tag-remove:hover { opacity: 1; color: var(--df-danger); }
|
||||
.tag-add {
|
||||
cursor: pointer;
|
||||
background: transparent;
|
||||
border: 1px dashed var(--df-border);
|
||||
color: var(--df-text-dim);
|
||||
font-weight: 700;
|
||||
}
|
||||
.tag-add:hover { border-color: var(--df-accent); color: var(--df-accent); }
|
||||
/* 添加能力内联菜单(点+展开):浅底容器包可选 tag */
|
||||
.add-tag-menu {
|
||||
margin-top: 4px;
|
||||
padding: 4px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
background: var(--df-bg);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
}
|
||||
.add-tag-menu .tag { cursor: pointer; }
|
||||
.add-tag-menu .tag:hover { filter: brightness(1.2); }
|
||||
.add-tag-empty { font-size: 10px; color: var(--df-text-dim); padding: 2px 4px; }
|
||||
/* 权重输入框:表格内固定窄宽 */
|
||||
.model-table .setting-input--sm { width: 64px; }
|
||||
.model-list-hint {
|
||||
margin-top: 8px;
|
||||
font-size: 11px;
|
||||
|
||||
@@ -115,10 +115,12 @@ async function save() {
|
||||
<style scoped>
|
||||
/* panel/panel-header/btn 系列/setting-input 均在 settings.css 全局,此处仅本面板特有样式 */
|
||||
.uclaw-settings { display: flex; flex-direction: column; gap: 4px; }
|
||||
.uclaw-input { width: 320px; font-family: var(--df-font-mono, monospace); }
|
||||
/* 定宽输入补 max-width,窄窗收缩防横向溢出 */
|
||||
.uclaw-input { width: 320px; max-width: 100%; font-family: var(--df-font-mono, monospace); }
|
||||
/* 原 var(--df-text-tertiary) 为幽灵 token(全 styles 未定义,渲染成继承色),改用已定义的弱化色 */
|
||||
.uclaw-hint {
|
||||
font-size: 11px;
|
||||
color: var(--df-text-tertiary);
|
||||
color: var(--df-text-dim);
|
||||
line-height: 1.6;
|
||||
margin-top: 4px;
|
||||
white-space: pre-line;
|
||||
|
||||
@@ -145,7 +145,8 @@ function onPollSecsChange(raw: string) {
|
||||
<style scoped>
|
||||
/* panel/panel-header/toggle/setting-input 均在 settings.css 全局,此处仅本面板特有样式 */
|
||||
.unattended-settings { display: flex; flex-direction: column; gap: 4px; }
|
||||
.unattended-input { width: 280px; }
|
||||
/* 定宽输入补 max-width,窄窗收缩防横向溢出(--num 变体继承同款收缩) */
|
||||
.unattended-input { width: 280px; max-width: 100%; }
|
||||
.unattended-input--num { width: 110px; }
|
||||
.unattended-radios { display: flex; gap: 16px; flex-wrap: wrap; }
|
||||
.unattended-radio {
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
<template>
|
||||
<!-- 拉取到的模型列表表格(F-01 阶段6)。自 ProviderPanel 拆出(C4c 纯搬迁):
|
||||
表格渲染 + 能力/模态标签手动标注(改动即标 UserSet)自治在本件。
|
||||
models 为主文件 providerForm.models 的引用,行内 v-model/标签增删直接改
|
||||
item 字段(共享响应式对象),脏态由主文件 isFormDirty 统一比对。 -->
|
||||
<table class="model-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-enabled">{{ $t('settings.colEnabled') }}</th>
|
||||
<th class="col-model">{{ $t('settings.colModel') }}</th>
|
||||
<th class="col-ability">{{ $t('settings.colAbility') }}</th>
|
||||
<th class="col-weight">{{ $t('settings.labelWeight') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="m in models" :key="m.model_id">
|
||||
<td class="col-enabled">
|
||||
<label class="toggle toggle--sm">
|
||||
<input type="checkbox" v-model="m.enabled" />
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</td>
|
||||
<td class="col-model">
|
||||
<span class="model-id">{{ m.model_id }}</span>
|
||||
</td>
|
||||
<td class="col-ability">
|
||||
<!-- 能力/模态标签(可编辑:点 × 删除;点 + 添加;手动改后标为「手动」) -->
|
||||
<div class="model-tags">
|
||||
<span v-for="md in m.modalities" v-show="!redundantTags.modalities.has(md)" :key="'md-' + md"
|
||||
class="tag tag-modality" :title="$t('settings.tagTooltipModality')">
|
||||
{{ $t('settings.tagModality.' + md) }}<span class="tag-remove" role="button" tabindex="0" :aria-label="$t('common.delete')" @click.stop="removeModality(m, md)" @keydown.enter.prevent="removeModality(m, md)" @keydown.space.prevent="removeModality(m, md)">×</span>
|
||||
</span>
|
||||
<span v-for="cap in m.capabilities" v-show="!redundantTags.capabilities.has(cap)" :key="'cap-' + cap"
|
||||
class="tag tag-capability" :title="$t('settings.tagTooltipCapability')">
|
||||
{{ $t('settings.tagCapability.' + cap) }}<span class="tag-remove" role="button" tabindex="0" :aria-label="$t('common.delete')" @click.stop="removeCapability(m, cap)" @keydown.enter.prevent="removeCapability(m, cap)" @keydown.space.prevent="removeCapability(m, cap)">×</span>
|
||||
</span>
|
||||
<span v-if="m.probe_source && m.probe_source !== 'user_set'" v-show="!redundantTags.sources.has(m.probe_source)"
|
||||
class="tag tag-source" :title="$t('settings.tagTooltipSource')">{{ $t('settings.tagSource.' + m.probe_source) }}</span>
|
||||
<span v-if="m.probe_source === 'user_set'" class="tag tag-source" :title="$t('settings.tagTooltipSource')">{{ $t('settings.tagSource.user_set') }}</span>
|
||||
<span class="tag-add" role="button" tabindex="0" :title="$t('settings.addTagTitle')" :aria-label="$t('settings.addTagTitle')" @click.stop="startAddTag(m)" @keydown.enter.prevent="startAddTag(m)" @keydown.space.prevent="startAddTag(m)">+</span>
|
||||
</div>
|
||||
<!-- 添加能力内联菜单(点+展开;选未有的能力/模态即添加) -->
|
||||
<div v-if="addingTagModel === m.model_id" class="add-tag-menu">
|
||||
<span v-for="opt in addableTags(m)" :key="opt.kind + '-' + opt.key"
|
||||
class="tag" :class="opt.kind === 'modality' ? 'tag-modality' : 'tag-capability'"
|
||||
@click.stop="addTag(m, opt.key, opt.kind)">{{ opt.label }}</span>
|
||||
<span v-if="addableTags(m).length === 0" class="add-tag-empty">{{ $t('settings.addTagNone') }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="col-weight">
|
||||
<input type="number" class="setting-input setting-input--sm" min="0" max="100" v-model.number="m.weight" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { ModelConfig, Modality, Capability, ProbeSource } from '@/api/types'
|
||||
|
||||
// ============================================================
|
||||
// 模型能力手动标注(表格内编辑 tags;改动即标 UserSet,手动优先)
|
||||
// —— 原 ProviderPanel 整块搬迁(C4c 纯搬迁,共享函数不新造)。
|
||||
// ============================================================
|
||||
const { t } = useI18n()
|
||||
|
||||
const props = defineProps<{
|
||||
/** 主文件 providerForm.models 引用(行内直改 item 字段,保存闭环留主文件 saveProvider) */
|
||||
models: ModelConfig[]
|
||||
}>()
|
||||
|
||||
/**
|
||||
* 冗余标签判定:全模型共有的 modality/capability/probe_source 无区分度,
|
||||
* 每行都渲染会刷屏(如全部命中预设表 → 全是「预设」;对话模型默认 ToolUse → 全是「工具调用」)。
|
||||
* 计算「所有模型都含」的值集合,模板渲染时跳过 → 只显示有区分度的标签。
|
||||
*/
|
||||
const redundantTags = computed(() => {
|
||||
const models = props.models
|
||||
// SA-6: 去冗余的前提是「模型间对比」——仅 1 个模型时它的所有标签都满足「全模型共有」,
|
||||
// 无脑隐藏会把唯一模型的能力标签全抹掉(行内空白,用户看不到该模型能力)。
|
||||
// 故 ≥2 个模型起才去冗余;0/1 个一律全显(sources 分支本就 <2 直接放行,此处对齐)。
|
||||
if (models.length < 2) return { modalities: new Set<string>(), capabilities: new Set<string>(), sources: new Set<string>() }
|
||||
const common = (pick: (m: ModelConfig) => string[]) => {
|
||||
const sets = models.map(m => new Set(pick(m)))
|
||||
const first = sets[0]
|
||||
const result = new Set<string>()
|
||||
for (const v of first) {
|
||||
if (sets.every(s => s.has(v))) result.add(v)
|
||||
}
|
||||
return result
|
||||
}
|
||||
return {
|
||||
modalities: common(m => m.modalities),
|
||||
capabilities: common(m => m.capabilities),
|
||||
// 探测来源:全模型相同的值也冗余(如全 PresetTable)
|
||||
sources: (() => {
|
||||
const vals = models.map(m => m.probe_source).filter((v): v is ProbeSource => !!v)
|
||||
if (vals.length < 2) return new Set<string>()
|
||||
return new Set([...new Set(vals)].filter(v => vals.every(x => x === v)))
|
||||
})(),
|
||||
}
|
||||
})
|
||||
|
||||
/** 当前展开「添加能力」菜单的模型名;null=无展开 */
|
||||
const addingTagModel = ref<string | null>(null)
|
||||
|
||||
/** 可添加的模态(与 tagModality 对齐;text 是对话基础模态,允许删但一般不主动加) */
|
||||
const ADDABLE_MODALITIES: Modality[] = ['text', 'vision', 'audio', 'video']
|
||||
/** 可添加的能力 */
|
||||
const ADDABLE_CAPABILITIES: Capability[] = ['tool_use', 'embedding', 'code_gen']
|
||||
|
||||
/** 某模型可添加的可选 tag(模态 + 能力,排除已选的) */
|
||||
function addableTags(m: ModelConfig): { key: string; kind: 'modality' | 'capability'; label: string }[] {
|
||||
const mods = ADDABLE_MODALITIES
|
||||
.filter(x => !m.modalities.includes(x))
|
||||
.map(x => ({ key: x, kind: 'modality' as const, label: t('settings.tagModality.' + x) }))
|
||||
const caps = ADDABLE_CAPABILITIES
|
||||
.filter(x => !m.capabilities.includes(x))
|
||||
.map(x => ({ key: x, kind: 'capability' as const, label: t('settings.tagCapability.' + x) }))
|
||||
return [...mods, ...caps]
|
||||
}
|
||||
|
||||
/** 标记模型为「手动标注」(probe_source=user_set),下次探测不覆盖 */
|
||||
function markManual(m: ModelConfig) {
|
||||
m.probe_source = 'user_set'
|
||||
addingTagModel.value = null
|
||||
}
|
||||
|
||||
function removeModality(m: ModelConfig, md: Modality) {
|
||||
m.modalities = m.modalities.filter(x => x !== md)
|
||||
markManual(m)
|
||||
}
|
||||
|
||||
function removeCapability(m: ModelConfig, cap: Capability) {
|
||||
m.capabilities = m.capabilities.filter(x => x !== cap)
|
||||
markManual(m)
|
||||
}
|
||||
|
||||
function addTag(m: ModelConfig, key: string, kind: 'modality' | 'capability') {
|
||||
if (kind === 'modality') {
|
||||
const md = key as Modality
|
||||
if (!m.modalities.includes(md)) m.modalities = [...m.modalities, md]
|
||||
} else {
|
||||
const cap = key as Capability
|
||||
if (!m.capabilities.includes(cap)) m.capabilities = [...m.capabilities, cap]
|
||||
}
|
||||
markManual(m)
|
||||
}
|
||||
|
||||
function startAddTag(m: ModelConfig) {
|
||||
addingTagModel.value = addingTagModel.value === m.model_id ? null : m.model_id
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 自 ProviderPanel scoped 拆出(C4c 纯搬迁):模型表格/标签样式随区块走;
|
||||
.setting-input--sm 与 .toggle--sm 为本件与 provider-list 子件共用,两处各持一份
|
||||
(scoped 不跨组件,全局化去重留待后续统一处理)。 */
|
||||
|
||||
/* ===== 模型列表(表格形式:表头 + 数据行) =====
|
||||
原 model-list/model-row 等无任何样式定义(裸渲染),本批补齐并改为表格。
|
||||
风格对齐 provider-card(浅底 / 圆角 / 0.5px 边框)。 */
|
||||
.model-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
overflow: hidden;
|
||||
font-size: 12px;
|
||||
}
|
||||
.model-table th,
|
||||
.model-table td {
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.model-table thead th {
|
||||
background: var(--df-bg);
|
||||
font-weight: 500;
|
||||
color: var(--df-text-dim);
|
||||
font-size: 11px;
|
||||
border-bottom: 0.5px solid var(--df-border);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.model-table tbody tr { border-bottom: 0.5px solid var(--df-border); }
|
||||
.model-table tbody tr:last-child { border-bottom: none; }
|
||||
.model-table tbody tr:hover { background: var(--df-accent-bg); }
|
||||
/* 列宽:启用窄、模型/能力弹性、权重窄 */
|
||||
.model-table .col-enabled { width: 56px; text-align: center; }
|
||||
.model-table .col-weight { width: 110px; }
|
||||
.model-table .col-model { min-width: 140px; }
|
||||
.col-enabled .toggle--sm { display: inline-block; }
|
||||
.model-id {
|
||||
font-size: 13px;
|
||||
font-family: var(--df-font-mono);
|
||||
color: var(--df-text);
|
||||
font-weight: 500;
|
||||
word-break: break-all;
|
||||
}
|
||||
/* 标签列:小圆角 chip,三类语义色区分 */
|
||||
.model-tags { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.tag {
|
||||
font-size: 10px;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--df-radius-xs);
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tag-modality { background: var(--df-info-bg); color: var(--df-info); }
|
||||
.tag-capability { background: var(--df-accent-soft); color: var(--df-accent); }
|
||||
.tag-source { background: var(--df-neutral-bg); color: var(--df-text-dim); }
|
||||
/* 可编辑 tag:×删除按钮(悬停显红)+ 添加按钮 */
|
||||
.tag-remove { margin-left: 3px; cursor: pointer; opacity: 0.6; font-weight: 700; }
|
||||
.tag-remove:hover { opacity: 1; color: var(--df-danger); }
|
||||
.tag-add {
|
||||
cursor: pointer;
|
||||
background: transparent;
|
||||
border: 1px dashed var(--df-border);
|
||||
color: var(--df-text-dim);
|
||||
font-weight: 700;
|
||||
}
|
||||
.tag-add:hover { border-color: var(--df-accent); color: var(--df-accent); }
|
||||
/* 添加能力内联菜单(点+展开):浅底容器包可选 tag */
|
||||
.add-tag-menu {
|
||||
margin-top: 4px;
|
||||
padding: 4px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
background: var(--df-bg);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm);
|
||||
}
|
||||
.add-tag-menu .tag { cursor: pointer; }
|
||||
.add-tag-menu .tag:hover { filter: brightness(1.2); }
|
||||
.add-tag-empty { font-size: 10px; color: var(--df-text-dim); padding: 2px 4px; }
|
||||
/* 权重输入框:表格内固定窄宽 */
|
||||
.model-table .setting-input--sm { width: 64px; }
|
||||
|
||||
/* 行内窄输入(权重等):定高 26px 档(--df-h-input),与 .setting-input 主体高度齐平 */
|
||||
.setting-input--sm { flex: 0 0 auto; min-width: 0; width: 70px; height: var(--df-h-input); padding: 4px 8px; font-size: 12px; }
|
||||
|
||||
/* Toggle 小号变体(表格启用开关用;.toggle 基础走全局) */
|
||||
.toggle--sm { width: 32px; height: 18px; }
|
||||
.toggle--sm .toggle-slider::before { width: 12px; height: 12px; left: 3px; bottom: 3px; }
|
||||
.toggle--sm input:checked + .toggle-slider::before { transform: translateX(14px); }
|
||||
</style>
|
||||
@@ -0,0 +1,214 @@
|
||||
<template>
|
||||
<!-- provider 卡片列表。自 ProviderPanel 拆出(C4c 纯搬迁):
|
||||
卡片渲染 + 负载均衡池控件(enabled/weight 即时 IPC)自治在本件,
|
||||
增删改/设默认经 emit 上抛主文件(共享 loadProviders 闭环)。 -->
|
||||
<div class="provider-list">
|
||||
<div class="provider-card" :class="{ 'provider-card--default': p.is_default, 'provider-card--disabled': p.enabled === false }" v-for="p in providers" :key="p.id">
|
||||
<div class="provider-top">
|
||||
<div class="provider-info">
|
||||
<span class="provider-name">{{ p.name }}</span>
|
||||
<span v-if="p.is_default" class="default-badge">{{ $t('settings.badgeDefault') }}</span>
|
||||
<span v-if="p.enabled === false" class="pool-badge">{{ $t('settings.badgePoolDisabled') }}</span>
|
||||
</div>
|
||||
<div class="provider-actions">
|
||||
<button class="btn-link" @click="emit('set-default', p.id)" v-if="!p.is_default">{{ $t('settings.actionSetDefault') }}</button>
|
||||
<button class="btn-link" @click="emit('edit', p)">{{ $t('common.edit') }}</button>
|
||||
<button class="btn-link btn-link-danger" @click="emit('delete', p.id)">{{ $t('common.delete') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="provider-detail">
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ $t('settings.detailBaseUrl') }}</span>
|
||||
<span class="detail-value">{{ p.base_url }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ $t('settings.detailModel') }}</span>
|
||||
<span class="detail-value">{{ p.default_model }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">{{ $t('settings.detailApiKey') }}</span>
|
||||
<span class="detail-value mask">{{ maskKey(p.api_key) }}</span>
|
||||
</div>
|
||||
<!-- F-260614-04c 负载均衡池:enabled toggle + weight 即时调 IPC,落库即重建 caps -->
|
||||
<div class="detail-row detail-row--pool">
|
||||
<span class="detail-label" :title="$t('settings.descPoolEnabled')">{{ $t('settings.detailPoolEnabled') }}</span>
|
||||
<div class="detail-value detail-value--control">
|
||||
<label class="toggle toggle--sm" :title="$t('settings.descPoolEnabled')">
|
||||
<input type="checkbox" :checked="p.enabled !== false" @change="onPoolToggle(p, ($event.target as HTMLInputElement).checked)" />
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="detail-row detail-row--pool" v-if="p.enabled !== false">
|
||||
<span class="detail-label" :title="$t('settings.descPoolWeight')">{{ $t('settings.detailPoolWeight') }}</span>
|
||||
<div class="detail-value detail-value--control">
|
||||
<input type="number" class="setting-input setting-input--sm" min="0" max="100"
|
||||
:value="p.weight ?? 50"
|
||||
@change="onPoolWeightChange(p, ($event.target as HTMLInputElement).valueAsNumber)" />
|
||||
<span class="pool-weight-hint">0-100</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { aiApi } from '@/api'
|
||||
import type { AiProviderConfig } from '@/api/types'
|
||||
|
||||
// ============================================================
|
||||
// c: 负载均衡池可编辑层(enabled / weight)——原 ProviderPanel 整块搬迁
|
||||
// 卡片即时调 IPC(对齐 syncConcurrencyConfig 模式);落库后后端 reload_provider_caps
|
||||
// 重建 per_provider caps,下条消息即按新配置 acquire。
|
||||
// 不走 saveProvider(全量 INSERT OR REPLACE 会触发 R-PD-1 密钥迁移分支,与 c 轻量 UPDATE 路径冲突)。
|
||||
// ============================================================
|
||||
const { t } = useI18n()
|
||||
|
||||
defineProps<{
|
||||
/** 主文件 aiProviders 引用;池控件直接改 item 字段(共享响应式对象,乐观更新),列表整体替换仍由主文件驱动 */
|
||||
providers: AiProviderConfig[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'edit', p: AiProviderConfig): void
|
||||
(e: 'delete', id: string): void
|
||||
(e: 'set-default', id: string): void
|
||||
(e: 'toast', msg: string, type: 'error' | 'warning' | 'info' | 'success'): void
|
||||
}>()
|
||||
|
||||
function errMsg(e: unknown): string { return e instanceof Error ? e.message : String(e) }
|
||||
|
||||
// 计时器按 provider id 分键:单例计时器下 300ms 内先后改两家权重,B 的变更会清掉
|
||||
// A 尚未落库的保存,先改的一方静默丢失(走查 P2-8)。
|
||||
const _poolTimers = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
|
||||
/**
|
||||
* toggle 即时生效(开关语义=立即入/出池,无 debounce 必要;但失败需回滚视图)。
|
||||
* 乐观更新本地数组,失败 revert + toast。
|
||||
*/
|
||||
async function onPoolToggle(p: AiProviderConfig, enabled: boolean) {
|
||||
const prev = p.enabled
|
||||
p.enabled = enabled
|
||||
try {
|
||||
// 防御钳制:p.weight 理论上已被 onPoolWeightChange 钳过,此处兜底防脏数据直传 IPC
|
||||
const w = Math.min(100, Math.max(0, p.weight ?? 50))
|
||||
await aiApi.updateProviderPool(p.id, enabled, w)
|
||||
emit('toast', t('settings.toastPoolUpdateOk'), 'info')
|
||||
} catch (e) {
|
||||
p.enabled = prev // revert
|
||||
console.error(t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), e)
|
||||
emit('toast', t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* weight 变更 debounce 300ms(防快速连续输入触发频繁 IPC),clamp [0,100] 对齐后端。
|
||||
* 双 clamp:前端 clamp 视觉输入 + 后端 command 再 clamp(防御性)。
|
||||
*/
|
||||
function onPoolWeightChange(p: AiProviderConfig, raw: number) {
|
||||
// NaN 兜底(清空输入):回退 50,防 IPC 传 NaN 后端 serde u32 失败
|
||||
const clamped = Math.min(100, Math.max(0, Number.isFinite(raw) ? Math.trunc(raw) : 50))
|
||||
const prev = p.weight
|
||||
p.weight = clamped
|
||||
// 仅重置同一 provider 的待发计时;跨 provider 互不干扰
|
||||
const prevTimer = _poolTimers.get(p.id)
|
||||
if (prevTimer) clearTimeout(prevTimer)
|
||||
_poolTimers.set(p.id, setTimeout(async () => {
|
||||
_poolTimers.delete(p.id)
|
||||
try {
|
||||
await aiApi.updateProviderPool(p.id, p.enabled !== false, clamped)
|
||||
emit('toast', t('settings.toastPoolUpdateOk'), 'info')
|
||||
} catch (e) {
|
||||
p.weight = prev // revert
|
||||
console.error(t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), e)
|
||||
emit('toast', t('settings.toastPoolUpdateFail', { msg: errMsg(e) }), 'error')
|
||||
}
|
||||
}, 300))
|
||||
}
|
||||
|
||||
function maskKey(key: string): string {
|
||||
if (!key || key.length < 8) return '••••••••'
|
||||
return key.slice(0, 4) + '••••••••' + key.slice(-4)
|
||||
}
|
||||
|
||||
/** 主文件 defineExpose.clearPoolTimer 委托到此处(壳卸载清 timer 的对外契约不变)。 */
|
||||
defineExpose({
|
||||
clearPoolTimer() { for (const t of _poolTimers.values()) clearTimeout(t); _poolTimers.clear() },
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 自 ProviderPanel scoped 拆出(C4c 纯搬迁):provider 卡片/池控件样式随区块走;
|
||||
.setting-input--sm 与 .toggle--sm 为本件与 model-table 子件共用,两处各持一份
|
||||
(scoped 不跨组件,全局化去重留待后续统一处理)。 */
|
||||
|
||||
/* ===== Provider 卡片 ===== */
|
||||
.provider-list { display: flex; flex-direction: column; gap: 12px; }
|
||||
.provider-card {
|
||||
background: var(--df-bg);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.provider-card--default {
|
||||
border-color: var(--df-accent);
|
||||
box-shadow: inset 3px 0 0 var(--df-accent);
|
||||
}
|
||||
.provider-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.provider-info { display: flex; align-items: center; gap: 8px; }
|
||||
.provider-name { font-size: 14px; font-weight: 500; color: var(--df-text); }
|
||||
.default-badge {
|
||||
font-size: 10px;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: var(--df-success-bg);
|
||||
color: var(--df-success);
|
||||
font-weight: 500;
|
||||
}
|
||||
.provider-actions { display: flex; gap: 4px; }
|
||||
|
||||
.provider-detail { display: flex; flex-direction: column; gap: 6px; }
|
||||
.detail-row { display: flex; align-items: flex-start; gap: 12px; }
|
||||
.detail-label {
|
||||
font-size: 12px;
|
||||
color: var(--df-text-dim);
|
||||
min-width: 60px;
|
||||
}
|
||||
.detail-value {
|
||||
font-size: 12px;
|
||||
color: var(--df-text-secondary);
|
||||
font-family: var(--df-font-mono);
|
||||
}
|
||||
.detail-value.mask { color: var(--df-text-dim); letter-spacing: 1px; }
|
||||
|
||||
/* Provider 卡片 disabled 态(c:enabled=false 视觉弱化) */
|
||||
.provider-card--disabled { opacity: 0.6; }
|
||||
.pool-badge {
|
||||
font-size: 10px;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: var(--df-danger-bg);
|
||||
color: var(--df-danger);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 负载均衡池行(toggle / weight 控件) */
|
||||
.detail-row--pool { align-items: center; }
|
||||
.detail-value--control { display: flex; align-items: center; gap: 8px; font-family: var(--df-font-mono); }
|
||||
.pool-weight-hint { font-size: 11px; color: var(--df-text-dim); }
|
||||
|
||||
/* 行内窄输入(权重等):定高 26px 档(--df-h-input),与 .setting-input 主体高度齐平 */
|
||||
.setting-input--sm { flex: 0 0 auto; min-width: 0; width: 70px; height: var(--df-h-input); padding: 4px 8px; font-size: 12px; }
|
||||
|
||||
/* Toggle 小号变体(本面板负载均衡池用;.toggle 基础走全局) */
|
||||
.toggle--sm { width: 32px; height: 18px; }
|
||||
.toggle--sm .toggle-slider::before { width: 12px; height: 12px; left: 3px; bottom: 3px; }
|
||||
.toggle--sm input:checked + .toggle-slider::before { transform: translateX(14px); }
|
||||
</style>
|
||||
@@ -120,15 +120,8 @@
|
||||
.toggle input:checked + .toggle-slider { background: var(--df-accent); }
|
||||
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }
|
||||
|
||||
/* ===== 按钮(原 Settings.vue,列表型 Panel 共用) ===== */
|
||||
.btn { padding: 8px 16px; border: none; border-radius: var(--df-radius-sm); font-size: 13px; cursor: pointer; transition: background 0.15s, color 0.15s; }
|
||||
.btn-primary { background: var(--df-accent); color: #fff; }
|
||||
.btn-primary:hover { background: var(--df-accent-hover); }
|
||||
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.btn-ghost { background: transparent; color: var(--df-text-secondary); border: 0.5px solid var(--df-border); }
|
||||
.btn-ghost:hover { background: var(--df-bg-card); color: var(--df-text); }
|
||||
.btn-ghost:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.btn-sm { padding: 4px 12px; font-size: 12px; }
|
||||
/* ===== 按钮 =====
|
||||
样式大重构 R0(2026-10-18):.btn 族副本已删除,并轨 global.css 唯一基类(高度档 --df-h-btn)。 */
|
||||
|
||||
/* ===== 空提示(列表型 Panel 共用) ===== */
|
||||
.empty-hint { color: var(--df-text-dim); font-size: 13px; padding: 16px 0; text-align: center; }
|
||||
|
||||
@@ -214,50 +214,50 @@ function cancelEdit() {
|
||||
<style scoped>
|
||||
.wf-dag {
|
||||
margin-top: 8px; padding: 8px 12px;
|
||||
background: var(--df-bg-card, #fafafa);
|
||||
background: var(--df-bg-card);
|
||||
border-radius: var(--df-radius-sm, 4px); font-size: 12px;
|
||||
}
|
||||
.wf-dag--empty { color: var(--df-text-dim, #888); }
|
||||
.wf-dag--empty { color: var(--df-text-dim); }
|
||||
.wf-dag-title { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
|
||||
|
||||
.wf-dag-layers { display: flex; flex-direction: column; align-items: center; gap: 2px; }
|
||||
.wf-dag-layer { display: flex; flex-direction: column; align-items: center; gap: 4px; }
|
||||
.wf-dag-layer-label { font-size: 10px; color: var(--df-text-dim, #888); align-self: flex-start; }
|
||||
.wf-dag-layer-label { font-size: 10px; color: var(--df-text-dim); align-self: flex-start; }
|
||||
.wf-dag-layer-nodes {
|
||||
display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
|
||||
}
|
||||
.wf-dag-layer-arrow { font-size: 16px; color: var(--df-text-dim, #888); line-height: 1; }
|
||||
.wf-dag-layer-arrow { font-size: 16px; color: var(--df-text-dim); line-height: 1; }
|
||||
|
||||
.wf-dag-node {
|
||||
display: inline-flex; align-items: center; gap: 4px;
|
||||
padding: 4px 10px;
|
||||
background: var(--df-bg, #fff);
|
||||
border: 1px solid var(--df-border, #ddd);
|
||||
background: var(--df-bg);
|
||||
border: 1px solid var(--df-border);
|
||||
border-radius: var(--df-radius-sm, 4px);
|
||||
transition: border-color 0.3s, background 0.3s;
|
||||
}
|
||||
.wf-dag-node-name { font-weight: 500; white-space: nowrap; }
|
||||
.wf-dag-node-type {
|
||||
font-size: 10px; color: var(--df-text-dim, #888);
|
||||
background: var(--df-bg-card, #f0f0f0); padding: 0 4px; border-radius: 4px;
|
||||
font-size: 10px; color: var(--df-text-dim);
|
||||
background: var(--df-bg-card); padding: 0 4px; border-radius: 4px;
|
||||
}
|
||||
.wf-dag-node-status { font-size: 11px; }
|
||||
.wf-dag-node-status-dot {
|
||||
width: 6px; height: 6px; border-radius: 50%;
|
||||
background: var(--df-text-dim, #ccc);
|
||||
background: var(--df-text-dim);
|
||||
}
|
||||
.wf-dag-node--running {
|
||||
border-color: var(--df-info, #4a90e2);
|
||||
background: rgba(74,144,226,0.05);
|
||||
border-color: var(--df-info);
|
||||
background: var(--df-info-bg);
|
||||
}
|
||||
.wf-dag-node--running .wf-dag-node-status-dot {
|
||||
background: var(--df-info, #4a90e2);
|
||||
background: var(--df-info);
|
||||
animation: pulse 1s ease-in-out infinite;
|
||||
}
|
||||
.wf-dag-node--completed { border-color: var(--df-success, #3ddba0); }
|
||||
.wf-dag-node--completed .wf-dag-node-status-dot { background: var(--df-success, #3ddba0); }
|
||||
.wf-dag-node--failed { border-color: var(--df-danger, #e5484d); background: rgba(229,72,77,0.05); }
|
||||
.wf-dag-node--failed .wf-dag-node-status-dot { background: var(--df-danger, #e5484d); }
|
||||
.wf-dag-node--completed { border-color: var(--df-success); }
|
||||
.wf-dag-node--completed .wf-dag-node-status-dot { background: var(--df-success); }
|
||||
.wf-dag-node--failed { border-color: var(--df-danger); background: var(--df-danger-bg); }
|
||||
.wf-dag-node--failed .wf-dag-node-status-dot { background: var(--df-danger); }
|
||||
.wf-dag-node--skipped { opacity: 0.5; }
|
||||
|
||||
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
|
||||
@@ -270,28 +270,29 @@ function cancelEdit() {
|
||||
.wf-dag-outedge {
|
||||
display: inline-flex; align-items: center; gap: 4px; font-size: 10px;
|
||||
}
|
||||
.wf-dag-outedge-arrow { color: var(--df-text-primary); white-space: nowrap; }
|
||||
/* 箭头色:原 --df-text-primary 为未定义幽灵 token(声明失效),改主文字色 */
|
||||
.wf-dag-outedge-arrow { color: var(--df-text); white-space: nowrap; }
|
||||
|
||||
/* 条件标签(共享:出边展示 + 编辑列表) */
|
||||
.wf-dag-cond-label {
|
||||
font-family: var(--df-font-mono); font-size: 10px; padding: 0 4px;
|
||||
background: rgba(74,144,226,0.08); border-radius: 2px; color: var(--df-info, #4a90e2);
|
||||
background: var(--df-info-bg); border-radius: 2px; color: var(--df-info);
|
||||
max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
.wf-dag-cond-label--uncond { background: transparent; color: var(--df-text-dim, #aaa); }
|
||||
.wf-dag-cond-label--uncond { background: transparent; color: var(--df-text-dim); }
|
||||
.wf-dag-cond-label--editable {
|
||||
cursor: pointer; font-size: 11px; padding: 1px 6px; border-radius: 4px;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.wf-dag-cond-label--editable:hover { background: rgba(74,144,226,0.18); }
|
||||
.wf-dag-cond-label--editable:hover { background: color-mix(in srgb, var(--df-info) 18%, transparent); }
|
||||
.wf-dag-cond-label--uncond.wf-dag-cond-label--editable:hover { background: var(--df-bg-card); }
|
||||
|
||||
/* 边条件编辑列表 */
|
||||
.wf-dag-edges-detail { margin-top: 8px; }
|
||||
.wf-dag-edges-summary { cursor: pointer; font-size: 11px; color: var(--df-info, #4a90e2); }
|
||||
.wf-dag-edges-summary { cursor: pointer; font-size: 11px; color: var(--df-info); }
|
||||
.wf-dag-edges { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
|
||||
.wf-dag-edge { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 11px; }
|
||||
.wf-dag-edge-arrow { color: var(--df-text-primary); white-space: nowrap; }
|
||||
.wf-dag-edge-arrow { color: var(--df-text); white-space: nowrap; }
|
||||
.wf-dag-edge-input {
|
||||
flex: 1; min-width: 0; font-family: var(--df-font-mono); font-size: 11px;
|
||||
padding: 2px 6px; border: 0.5px solid var(--df-border); border-radius: 4px;
|
||||
|
||||
@@ -46,6 +46,7 @@ async function initContextListener(callbacks: {
|
||||
onCleared?: (conversationId: string) => void
|
||||
onCompressed?: (conversationId: string, summary: string) => void
|
||||
onError?: (conversationId: string, message: string) => void
|
||||
onContextDegraded?: (conversationId: string, reason: string) => void
|
||||
}): Promise<void> {
|
||||
setContextCallbacks({
|
||||
onCompressing: () => { isCompressing.value = true },
|
||||
@@ -62,6 +63,11 @@ async function initContextListener(callbacks: {
|
||||
autoCompressedFlashTimer = setTimeout(() => { autoCompressedFlash.value = false }, 4000)
|
||||
},
|
||||
onCleared: (convId) => callbacks.onCleared?.(convId),
|
||||
onContextDegraded: (convId, reason) => {
|
||||
// E2:压缩失败降级为关键词摘要兜底——复位 loading + 上抛 toast(不中断 LLM 流)
|
||||
isCompressing.value = false
|
||||
callbacks.onContextDegraded?.(convId, reason)
|
||||
},
|
||||
onError: (convId, message) => {
|
||||
// AiError 也用于流式生成失败(useAiEvents 已处理);此处仅在压缩中时复位 + toast,
|
||||
// 避免双重处理流式错误。
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
//! - 多处调 useAiEvents.notifyConversationChanged
|
||||
//! - newConversation/switchConversation 写 appSettings 持久化活跃会话 id
|
||||
|
||||
import { ref } from 'vue'
|
||||
import { ref, reactive } from 'vue'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
|
||||
import { aiApi } from '@/api'
|
||||
import { useAppSettingsStore } from '@/stores/appSettings'
|
||||
@@ -14,7 +15,7 @@ import { setStreaming } from './streamingGuard'
|
||||
import { emitDetachedOpenConversation, registerDetachedOpenConvListener } from './useAiWindow'
|
||||
import { nextMsgId, getConvState, clearConvStreamState, clearLastDelta, startApprovalTimer, clearAllApprovalTimers, switchingConvs, getConvStreamState, setConvCurrentText, notifyConversationChanged, setConvPendingApprovals, discardConvPendingApprovals, backfillConvAgentFinished, bumpToolEpoch } from './aiShared'
|
||||
import { t } from '@/i18n/i18n-helpers'
|
||||
import type { AiConversationDetail, AiMessage, AiToolCallInfo, AiToolCallStatus, ConvId, MessageId } from '@/api/types'
|
||||
import type { AiConversationDetail, AiConversationSummary, AiMessage, AiToolCallInfo, AiToolCallStatus, ConvId, MessageId } from '@/api/types'
|
||||
|
||||
// ── V11c(2026-10-05)活跃会话 KV 按窗口域分流 ──
|
||||
// 主窗与分离窗是独立 JS context,却共用同一 SQLite KV:两窗各自切会话都写 'df-ai-active-conv'
|
||||
@@ -35,17 +36,78 @@ export function activeConvKvKey(): string {
|
||||
|
||||
const appSettings = useAppSettingsStore()
|
||||
|
||||
/** 拉取会话列表;首次加载时若 appSettings 仍有有效 active-conv 且当前无活跃对话则恢复 */
|
||||
// ============================================================
|
||||
// F4-1(2026-10-17)会话列表分页:后端 ai_conversation_list 活跃/归档各自
|
||||
// offset+limit 分页(每页 CONV_PAGE_SIZE/组),首屏一页保启动性能;侧栏「加载更多」
|
||||
// 按游标续拉,搜索输入时拉满(搜索过滤跑在已加载列表上,截断列表=搜索失灵)。
|
||||
// 治实测 115 条活跃主会话 57% 在桌面端零入口(硬 50 截断)。
|
||||
// ============================================================
|
||||
|
||||
/** 每页条数(每组独立;对齐后端 limit.unwrap_or(50) 首屏口径) */
|
||||
const CONV_PAGE_SIZE = 50
|
||||
/** 单次「拉满」安全页数上限(防异常数据下无限循环;50*40=2000/组远超真实规模) */
|
||||
const CONV_MAX_PAGES = 40
|
||||
|
||||
/** 分页游标(模块级单例,主/分离窗各自实例):已拉取条数按组计数 + 是否还有下一页。
|
||||
* reactive 供侧栏「加载更多」按钮直接绑显隐/loading 态。 */
|
||||
export const convListPaging = reactive({
|
||||
activeLoaded: 0,
|
||||
archivedLoaded: 0,
|
||||
hasMore: false,
|
||||
loading: false,
|
||||
})
|
||||
|
||||
/** 拉一页会话摘要。直接 invoke:api 层 listConversations 封装不带 offset 参数,
|
||||
* 分页需透传 activeOffset/archivedOffset(composable 直连 invoke 有 useAiSend 等先例)。 */
|
||||
function fetchConvPage(activeOffset: number, archivedOffset: number): Promise<AiConversationSummary[]> {
|
||||
return invoke<AiConversationSummary[]>('ai_conversation_list', {
|
||||
limit: CONV_PAGE_SIZE,
|
||||
includeArchived: true,
|
||||
activeOffset,
|
||||
archivedOffset,
|
||||
})
|
||||
}
|
||||
|
||||
/** 拉取会话列表;首次加载时若 appSettings 仍有有效 active-conv 且当前无活跃对话则恢复。
|
||||
* F4-1 分页:从第一页重拉到覆盖既有加载深度(convListPaging)或拉尽——事件后刷新
|
||||
* (scheduleConversationsRefresh)不把「加载更多」拉出的深度回缩成首屏 50;首启深度 0
|
||||
* 即只拉一页,首屏性能不变。 */
|
||||
async function loadConversations() {
|
||||
if (convListPaging.loading) return
|
||||
convListPaging.loading = true
|
||||
try {
|
||||
const depthActive = convListPaging.activeLoaded
|
||||
const depthArchived = convListPaging.archivedLoaded
|
||||
const accActive: AiConversationSummary[] = []
|
||||
const accArchived: AiConversationSummary[] = []
|
||||
const seen = new Set<string>()
|
||||
let aOff = 0
|
||||
let rOff = 0
|
||||
// includeArchived=true:侧栏归档分组(ConversationSidebar archivedConvs)数据源即本内存列表,
|
||||
// 若拉取时排除归档,重启后已归档会话不可见且无恢复入口(2026-10-05 实锤 bug)。
|
||||
// 活跃/归档分组由侧栏 groupedActive/archivedConvs 各自分离渲染;后端已分组截断,归档不挤占活跃名额。
|
||||
state.conversations = await aiApi.listConversations(50, true)
|
||||
// 活跃/归档分组由侧栏 groupedActive/archivedConvs 各自分离渲染;后端分组分页,归档不挤占活跃名额。
|
||||
for (let i = 0; i < CONV_MAX_PAGES; i++) {
|
||||
const page = await fetchConvPage(aOff, rOff)
|
||||
const act = page.filter(c => !c.archived)
|
||||
const arc = page.filter(c => c.archived)
|
||||
for (const c of act) if (!seen.has(c.id)) { seen.add(c.id); accActive.push(c) }
|
||||
for (const c of arc) if (!seen.has(c.id)) { seen.add(c.id); accArchived.push(c) }
|
||||
aOff += act.length
|
||||
rOff += arc.length
|
||||
// 某组满额一页即可能还有下一页(后端无显式 has_more,满额启发式同 load_more 消息分页)
|
||||
convListPaging.hasMore = act.length === CONV_PAGE_SIZE || arc.length === CONV_PAGE_SIZE
|
||||
if (!convListPaging.hasMore) break
|
||||
// 已覆盖此前加载深度即止(刷新场景),首启深度 0 第一页后即止
|
||||
if (aOff >= depthActive && rOff >= depthArchived) break
|
||||
}
|
||||
state.conversations = [...accActive, ...accArchived]
|
||||
convListPaging.activeLoaded = aOff
|
||||
convListPaging.archivedLoaded = rOff
|
||||
// 虚拟项保底:活跃会话未落库(懒创建——首条消息前 DB 无记录)时,侧栏显示虚拟占位项。
|
||||
// 后端 ai_conversation_create 仅生成 id 存内存不落库,首条消息发送后 save_conversation 才写库。
|
||||
// 此处 active 会话不在 DB 列表时补一个虚拟项,实现「点新建立即出现在侧栏,不发消息不落库」。
|
||||
// 首条消息落库后 AiCompleted/AiError 触发的 loadConversations 拉到同 id 真实记录,虚拟项被替代无重复。
|
||||
// (虚拟项不计入分页游标——游标只数 DB 真实拉取条数。)
|
||||
if (state.activeConversationId
|
||||
&& !state.conversations.some(c => c.id === state.activeConversationId)) {
|
||||
const now = String(Date.now())
|
||||
@@ -94,6 +156,41 @@ async function loadConversations() {
|
||||
} as AiMessage)
|
||||
notifyConversationChanged()
|
||||
}
|
||||
} finally {
|
||||
convListPaging.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
/** F4-1「加载更多」:从当前游标续拉一页并追加(不重拉首页,避免重复传输+闪烁);
|
||||
* 返回是否实际新增条目(侧栏据此决定是否继续,数据漂移致空页时自然停)。 */
|
||||
async function loadMoreConversations(): Promise<boolean> {
|
||||
if (convListPaging.loading || !convListPaging.hasMore) return false
|
||||
convListPaging.loading = true
|
||||
try {
|
||||
const page = await fetchConvPage(convListPaging.activeLoaded, convListPaging.archivedLoaded)
|
||||
const act = page.filter(c => !c.archived)
|
||||
const arc = page.filter(c => c.archived)
|
||||
const existing = new Set(state.conversations.map(c => c.id))
|
||||
const fresh = page.filter(c => !existing.has(c.id))
|
||||
if (fresh.length) state.conversations = [...state.conversations, ...fresh]
|
||||
convListPaging.activeLoaded += act.length
|
||||
convListPaging.archivedLoaded += arc.length
|
||||
convListPaging.hasMore = act.length === CONV_PAGE_SIZE || arc.length === CONV_PAGE_SIZE
|
||||
return fresh.length > 0
|
||||
} catch (e) {
|
||||
console.error('[AI] 加载更多会话失败:', e)
|
||||
return false
|
||||
} finally {
|
||||
convListPaging.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
/** F4-1 搜索全量兜底:把列表拉满。搜索过滤(stores.filteredConversations)跑在已加载
|
||||
* 列表上,未拉满时老会话搜不到——搜索本就该扫全量,输入触发时一次拉尽。 */
|
||||
async function loadAllConversations(): Promise<void> {
|
||||
for (let i = 0; i < CONV_MAX_PAGES; i++) {
|
||||
if (!convListPaging.hasMore) break
|
||||
if (!(await loadMoreConversations())) break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,6 +851,8 @@ export function useAiConversations() {
|
||||
return {
|
||||
loadConversations,
|
||||
scheduleConversationsRefresh,
|
||||
loadMoreConversations,
|
||||
loadAllConversations,
|
||||
newConversation,
|
||||
switchConversation,
|
||||
deleteConversation,
|
||||
@@ -768,4 +867,4 @@ export function useAiConversations() {
|
||||
}
|
||||
}
|
||||
|
||||
export { loadConversations, scheduleConversationsRefresh, loadMoreHistory, getLoadMoreState }
|
||||
export { loadConversations, scheduleConversationsRefresh, loadMoreConversations, loadAllConversations, loadMoreHistory, getLoadMoreState }
|
||||
|
||||
@@ -30,6 +30,8 @@ export interface ContextCallbacks {
|
||||
onCleared?: (conversationId: string) => void
|
||||
/** 错误(AiError,含压缩失败):仅在 loading 时置 false + toast */
|
||||
onError?: (conversationId: string, message: string) => void
|
||||
/** E2 压缩失败降级(AiContextDegraded):loop 仍在跑,仅提示上下文已降级不中断流 */
|
||||
onContextDegraded?: (conversationId: string, reason: string) => void
|
||||
}
|
||||
let _contextCallbacks: ContextCallbacks = {}
|
||||
|
||||
@@ -344,6 +346,11 @@ export async function handleLifecycleEvent(event: AiChatEvent): Promise<boolean>
|
||||
_contextCallbacks.onCleared?.(event.conversation_id || '')
|
||||
return true
|
||||
|
||||
case 'AiContextDegraded':
|
||||
// E2:压缩失败已走关键词摘要兜底,loop 继续——透出降级提示而非静默失忆
|
||||
_contextCallbacks.onContextDegraded?.(event.conversation_id || '', event.reason || '')
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//!
|
||||
//! L2 发送韧性:三级降级
|
||||
//! L0 normal:后端 idle → 直接发送
|
||||
//! L1 queued: 后端 busy → 入队等待(≤30s 正常排队)
|
||||
//! L1 queued: 后端 busy → 纯文本先试补充注入(并入当前轮,u-claw 语义);失败/带载荷 → 入队等待(≤30s 正常排队)
|
||||
//! L2 force: 排队>30s → 弹 confirm → 用户确认后调 ai_chat_force_send 复位残留并强制发出
|
||||
//!
|
||||
//! 耦合:
|
||||
@@ -356,7 +356,7 @@ export function drainQueue(convId?: string | null) {
|
||||
* 发送消息 — 三级降级(L0 直接发 / L1 入队 / L2 强制):
|
||||
*
|
||||
* L0 normal: 后端 idle → 直接 doSend()
|
||||
* L1 queued: 后端 busy → 入队等 AiCompleted 续发
|
||||
* L1 queued: 后端 busy → 纯文本先试 ai_inject_runtime(补充并入当前轮);失败回退入队等 AiCompleted 续发
|
||||
* L2 force: 排队>30s → 返回特殊标记,由调用方(handleSend)弹 confirm;
|
||||
* 用户确认后重新进 sendMessage(forceMode=true)走 forceSend IPC
|
||||
*
|
||||
@@ -387,9 +387,40 @@ async function sendMessage(text: string, skill?: string, forceMode = false, part
|
||||
backendGenerating = false
|
||||
}
|
||||
|
||||
// ── L1:后端 busy → 入队(消息已在本地显示,待后端空闲后自动发送)──
|
||||
// ── L1:后端 busy → 纯文本先试补充注入,失败回退入队(消息已在本地显示,待后端空闲后自动发送)──
|
||||
// 仅用 backendGenerating,不用 state.streaming。streaming 是渲染态,不是后端忙的代理。
|
||||
if (backendGenerating) {
|
||||
// 补充注入旁路(u-claw 语义,与飞书渠道 feishu_channel 同源同一后端实现):纯文本补充
|
||||
// 经 ai_inject_runtime 直写运行中会话,loop 下一轮自然消化——补充并进当前回答,不开新轮不入队。
|
||||
// 注入通道只收文本:带图(parts 含 image)/带技能/带 mention 增强的消息注入会丢载荷
|
||||
// (同飞书「图被丢、引导词空跑」判定),照旧入队走完整发送路径。
|
||||
// Ok(false)=会话不存在、Err=非活跃/Stopping 均为常态路径:静默回退下方入队,
|
||||
// 行为与接入注入前逐字一致。
|
||||
const pureText = !skill && !(spans && spans.length > 0) && !(parts && parts.some(p => p.type === 'image'))
|
||||
if (pureText && targetConvId) {
|
||||
try {
|
||||
const injected = await invoke<boolean>('ai_inject_runtime', { conversationId: targetConvId, message: text.trim() })
|
||||
if (injected) {
|
||||
// 本地气泡即时可见(后端已落库同内容,重进会话从 DB 加载不重复):
|
||||
// 当前视图才 push,后台会话续发不污染当前视图(与下方 L0 既有口径一致)
|
||||
if (targetConvId === state.activeConversationId) {
|
||||
state.messages.push({
|
||||
id: `user-${nextMsgId()}` as MessageId,
|
||||
role: 'user',
|
||||
content: text.trim(),
|
||||
timestamp: Date.now(),
|
||||
// 与后端落库同标记(chat.rs 落库带 source.channel='inject'):本地气泡
|
||||
// 不带则轮次分桶把它当「发起消息」多计一轮,重载后才归位
|
||||
source: { channel: 'inject' },
|
||||
})
|
||||
}
|
||||
void emit('ai-toast', { msg: t('ai.injectMerged'), type: 'success' })
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
// 非活跃(生成刚收尾的竞态窗口)是常态:静默回退入队,不弹错不打扰
|
||||
}
|
||||
}
|
||||
if (state.queue.length >= QUEUE_LIMIT) {
|
||||
throw new Error(t('ai.queueFull', { limit: QUEUE_LIMIT }))
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ export default {
|
||||
// UX-P2-A2: toast when queued messages get dropped by error/regenerate/edit (was silent)
|
||||
queueCleared: 'Cleared {n} queued message(s)',
|
||||
queueWillContinue: 'Stopped. {n} queued message(s) will still send automatically.',
|
||||
// Success toast when a runtime supplement is merged into the in-flight answer (u-claw semantics: no new round)
|
||||
injectMerged: 'Merged into the current answer; takes effect next round.',
|
||||
approvalTimeout: '⚰ Approval timed out, automatically rejected: {toolName}',
|
||||
// conversation load/switch failure feedback (network jitter/IPC down → empty list/blank, was silent)
|
||||
loadConvFail: 'Failed to load conversations. Please check your network or backend connection.',
|
||||
|
||||
+12
-1
@@ -133,6 +133,8 @@ export default {
|
||||
queueSave: 'Save',
|
||||
queueCancel: 'Cancel',
|
||||
queueSendNow: 'Send now',
|
||||
// UX walk panel-2 F2-1: send button title/aria (was mis-bound to queueSendNow)
|
||||
send: 'Send',
|
||||
// 3c UX batch addition (I4 queue backfill: pull a queued item back into the input box)
|
||||
queueBackfill: 'Backfill',
|
||||
|
||||
@@ -185,6 +187,10 @@ export default {
|
||||
copyMsg: 'Copy message',
|
||||
copied: 'Copied',
|
||||
copyFailed: 'Copy failed',
|
||||
// F1-1: code block copy button (injected at v-html render layer via decorateCodeHtml)
|
||||
copyCode: 'Copy',
|
||||
// F1-1: collapsed long-message summary toggle (expanded state reuses collapse key)
|
||||
foldedSummary: '{chars} chars collapsed / ~{tokens} tokens — click to expand',
|
||||
// Copy bubble as image (html2canvas → clipboard; falls back to download)
|
||||
copyAsImage: 'Copy as image',
|
||||
copiedAsImage: 'Copied as image',
|
||||
@@ -269,6 +275,7 @@ export default {
|
||||
// B4: one-shot auto-compress notice (loop auto-compress no longer fully silent)
|
||||
autoCompressed: 'Context auto-compressed (earlier messages folded into summary)',
|
||||
compressError: 'Compression failed: {msg}',
|
||||
contextDegraded: 'Context degraded: {reason} — the AI may be missing some earlier details',
|
||||
clearError: 'Clear failed: {msg}',
|
||||
initError: 'AI panel init failed: {msg} (reopen panel to retry)',
|
||||
initDegraded: 'List load failed, continuing in degraded mode: {msg}',
|
||||
@@ -287,6 +294,8 @@ export default {
|
||||
recoverNow: 'Resume',
|
||||
viewHistory: 'View history messages',
|
||||
viewSummary: 'View context summary',
|
||||
// UX walk panel-6 F6-1: inline hint when a history/summary jump misses (target inside a collapsed segment)
|
||||
historyLocateInSegment: 'This message is inside a collapsed segment (archived/compressed). Expand the divider in the message flow first',
|
||||
viewContext: 'View AI context',
|
||||
contextSystemPrompt: 'System Prompt',
|
||||
contextEnvironment: 'Environment',
|
||||
@@ -342,6 +351,8 @@ export default {
|
||||
editEmptyBlocked: 'Edit content is empty, submission cancelled',
|
||||
skillNoMatchQuery: 'No skill matches "{q}", send blocked',
|
||||
backfillOverwriteConfirm: 'The input box has an unsent draft; backfilling will overwrite it. Continue?',
|
||||
// UX walk panel-2 F2-4: example-card overwrite confirm (aligned with backfill confirm)
|
||||
exampleOverwriteConfirm: 'The input box has an unsent draft; the example will overwrite it. Continue?',
|
||||
|
||||
// ── Outbox / scheduled messages (OutboxDrawer + ChatInput clock entry, design 2026-10-10 §3.4) ──
|
||||
outboxEntry: 'Scheduled messages',
|
||||
@@ -366,7 +377,7 @@ export default {
|
||||
contextBriefsToggle: 'Expand or collapse project briefs',
|
||||
contextBriefsTitle: 'Project briefs',
|
||||
contextBriefsLoading: 'Loading…',
|
||||
contextBriefsEmpty: 'No published knowledge yet',
|
||||
contextBriefsEmpty: 'No briefs yet. Conversation takeaways are distilled here automatically when a conversation ends',
|
||||
contextBriefsBringIn: 'Bring into context',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ export default {
|
||||
edit: 'Edit',
|
||||
close: 'Close',
|
||||
loading: 'Loading…',
|
||||
retry: 'Retry',
|
||||
unknownError: 'Unknown error',
|
||||
// Collapse/expand (reusable generic verbs for description/log/future long content)
|
||||
expand: 'Expand',
|
||||
|
||||
@@ -33,6 +33,13 @@ export default {
|
||||
taskListTitle: '🔀 Tasks',
|
||||
taskCount: '{n} tasks',
|
||||
emptyTasks: 'No tasks yet',
|
||||
filterEmptyTasks: 'No tasks match the current filter',
|
||||
// Sync (PD5-9)
|
||||
syncDone: 'Sync complete',
|
||||
// PD5-4 tri-state: archived (restore from archive box)
|
||||
archivedNotice: 'This project is archived and not in the project list',
|
||||
restoreFromArchive: 'Restore from Archive',
|
||||
restoreSuccess: 'Restored to the project list',
|
||||
// Workflow log panel
|
||||
workflowLogTitle: '📋 Workflow Log',
|
||||
// A2[PD-P1-3]: event stream has no project_id dimension, cannot filter per project; label "global events" to avoid misreading as this project's logs
|
||||
|
||||
@@ -52,6 +52,8 @@ export default {
|
||||
// UX-P2-A2:出错/重生成/编辑清排队消息的 toast 提示(原静默丢弃无任何反馈)
|
||||
queueCleared: '已清 {n} 条排队消息',
|
||||
queueWillContinue: '已停止,{n} 条排队消息仍将自动发送',
|
||||
// 运行中补充注入成功(u-claw 语义:纯文本补充并进当前回答,不开新轮)的 toast 提示
|
||||
injectMerged: '已并入当前回答,下一轮生效',
|
||||
approvalTimeout: '⚰ 审批超时,已自动拒绝:{toolName}',
|
||||
// 对话加载/切换失败反馈(网络抖动/IPC 断开 → 列表空/切换空白,原静默无反馈)
|
||||
loadConvFail: '对话列表加载失败,请检查网络或后端连接',
|
||||
|
||||
@@ -133,6 +133,8 @@ export default {
|
||||
queueSave: '保存',
|
||||
queueCancel: '取消',
|
||||
queueSendNow: '立即发送',
|
||||
// 走查-信息UX 面二 F2-1:发送钮 title/aria(原误绑 queueSendNow,语义是插队而非发送)
|
||||
send: '发送',
|
||||
// 3c UX 批追加(I4 队列回填:取出排队项填回输入框重新编辑)
|
||||
queueBackfill: '回填',
|
||||
|
||||
@@ -186,6 +188,10 @@ export default {
|
||||
copyMsg: '复制消息',
|
||||
copied: '已复制',
|
||||
copyFailed: '复制失败',
|
||||
// F1-1:代码块复制按钮(v-html 渲染层注入,decorateCodeHtml 传参)
|
||||
copyCode: '复制',
|
||||
// F1-1:长文折叠条带量按钮(展开态复用 collapse 键)
|
||||
foldedSummary: '已折叠 {chars} 字符 / 约 {tokens} tokens,点击展开',
|
||||
// 气泡复制为图片(html2canvas 渲染 → 剪贴板;失败降级下载)
|
||||
copyAsImage: '复制为图片',
|
||||
copiedAsImage: '已复制为图片',
|
||||
@@ -270,6 +276,8 @@ export default {
|
||||
// B4: 自动压缩完成一次性提示(loop 自动压缩不再全程静默)
|
||||
autoCompressed: '上下文已自动压缩(较早消息已折叠为摘要)',
|
||||
compressError: '压缩失败:{msg}',
|
||||
// E2:压缩失败走关键词摘要兜底,loop 继续——提示降级而非静默失忆
|
||||
contextDegraded: '上下文已降级:{reason},AI 可能缺失部分早前细节',
|
||||
clearError: '清空失败:{msg}',
|
||||
initError: 'AI 面板初始化失败:{msg}(重开面板可重试)',
|
||||
initDegraded: '列表加载失败,面板降级继续:{msg}',
|
||||
@@ -288,6 +296,8 @@ export default {
|
||||
recoverNow: '恢复',
|
||||
viewHistory: '查看历史消息',
|
||||
viewSummary: '查看上下文摘要',
|
||||
// 走查-信息UX 面六 F6-1:历史/摘要项点击定位未命中(目标在折叠段内未渲染 DOM)的行内提示
|
||||
historyLocateInSegment: '该消息在折叠段(已归档/已压缩)内,请先在消息流中展开对应分隔条',
|
||||
viewContext: '查看 AI 上下文',
|
||||
contextSystemPrompt: '系统提示',
|
||||
contextEnvironment: '环境',
|
||||
@@ -343,6 +353,8 @@ export default {
|
||||
editEmptyBlocked: '编辑内容为空,已取消提交',
|
||||
skillNoMatchQuery: '未找到技能「{q}」,已阻止发送',
|
||||
backfillOverwriteConfirm: '输入框已有未发送草稿,回填将覆盖,确定继续?',
|
||||
// 走查-信息UX 面二 F2-4:示例问题卡覆盖草稿二次确认(对齐回填确认语义)
|
||||
exampleOverwriteConfirm: '输入框已有未发送草稿,点击示例将覆盖,确定继续?',
|
||||
|
||||
// ── 待发箱/定时消息(OutboxDrawer + ChatInput ⏰ 入口,设计 2026-10-10 §3.4)──
|
||||
outboxEntry: '定时消息',
|
||||
@@ -367,7 +379,7 @@ export default {
|
||||
contextBriefsToggle: '展开或收起项目脉络',
|
||||
contextBriefsTitle: '项目脉络',
|
||||
contextBriefsLoading: '加载中…',
|
||||
contextBriefsEmpty: '暂无项目沉淀知识',
|
||||
contextBriefsEmpty: '暂无知识沉淀。会话结束时会自动提炼对话要点,沉淀到这里',
|
||||
contextBriefsBringIn: '带入上下文',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ export default {
|
||||
edit: '编辑',
|
||||
close: '关闭',
|
||||
loading: '加载中…',
|
||||
retry: '重试',
|
||||
unknownError: '未知错误',
|
||||
// 折叠/展开(可复用通用词,描述折叠/日志折叠/未来长内容)
|
||||
expand: '展开',
|
||||
|
||||
@@ -33,6 +33,13 @@ export default {
|
||||
taskListTitle: '🔀 任务列表',
|
||||
taskCount: '{n} 个任务',
|
||||
emptyTasks: '暂无任务',
|
||||
filterEmptyTasks: '当前筛选无任务',
|
||||
// 同步(PD5-9)
|
||||
syncDone: '同步完成',
|
||||
// PD5-4 三态:已归档(归档箱恢复)
|
||||
archivedNotice: '项目已归档,不在项目列表中',
|
||||
restoreFromArchive: '从归档箱恢复',
|
||||
restoreSuccess: '已恢复到项目列表',
|
||||
// 工作流日志面板
|
||||
workflowLogTitle: '📋 工作流日志',
|
||||
// A2[PD-P1-3]:事件流无 project_id 维度,无法按项目过滤,标注「全局事件」避免误读为本项目
|
||||
|
||||
@@ -54,11 +54,14 @@ export function createProjectsStore() {
|
||||
return record
|
||||
}
|
||||
|
||||
async function deleteProject(id: string) {
|
||||
await runWithCatch(state, t('projects.err.deleteFailed'), async () => {
|
||||
async function deleteProject(id: string): Promise<boolean> {
|
||||
// 返成功布尔(失败时 runWithCatch 已置 state.error),详情页删除据此阻断失败后的误跳转
|
||||
const ok = await runWithCatch(state, t('projects.err.deleteFailed'), async () => {
|
||||
await projectApi.delete(id) // 软删 → 回收站(可恢复)
|
||||
state.projects = state.projects.filter(p => p.id !== id)
|
||||
return true
|
||||
})
|
||||
return ok === true
|
||||
}
|
||||
|
||||
async function loadDeletedProjects() {
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
font-family: var(--df-font-mono);
|
||||
font-size: 12px;
|
||||
padding: 1px 5px;
|
||||
background: rgba(255,255,255,0.06);
|
||||
/* 2026-10-18 配色收口:白叠层字面量改文字色派生,浅色主题自动转黑叠层 */
|
||||
background: color-mix(in srgb, var(--df-text) 6%, transparent);
|
||||
border-radius: var(--df-radius-sm);
|
||||
color: var(--df-accent);
|
||||
}
|
||||
|
||||
+105
-29
@@ -27,7 +27,7 @@
|
||||
.error-banner {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
||||
padding: 8px 12px;
|
||||
background: rgba(255,107,107,0.12); border: 0.5px solid var(--df-danger);
|
||||
background: var(--df-danger-bg); border: 0.5px solid var(--df-danger);
|
||||
border-radius: var(--df-radius-sm); color: var(--df-danger); font-size: 12px;
|
||||
}
|
||||
.error-text { word-break: break-word; }
|
||||
@@ -39,32 +39,36 @@
|
||||
|
||||
/* — 灵感状态标签:ideas 列表(Ideas.vue) + 灵感详情(IdeaDetail.vue) 共享 —
|
||||
原 Ideas.vue / IdeaDetail.vue <style scoped> 两处逐字一致(灵感专属 5 态色系,
|
||||
与 Tasks/AuditLog 的 status-tag 语义不同,独立提取避免混淆)。 */
|
||||
与 Tasks/AuditLog 的 status-tag 语义不同,独立提取避免混淆)。
|
||||
2026-10-18 配色收口:圆角/内距对齐徽章档(xs+pad-badge,AuditLog 同档),
|
||||
显色改语义 token 三件套(底 *-bg/边 1px *-bd/字同色),清除 Material 并行色板;
|
||||
中性档(draft/archived)走 neutral-bg+text-dim 不加边。 */
|
||||
.status-tag {
|
||||
font-size: 11px; font-weight: 500; padding: 4px 10px;
|
||||
border-radius: var(--df-radius-sm);
|
||||
font-size: 11px; font-weight: 500; padding: var(--df-pad-badge);
|
||||
border-radius: var(--df-radius-xs);
|
||||
flex-shrink: 0; white-space: nowrap;
|
||||
}
|
||||
.status-draft { background: rgba(90,99,128,0.2); color: var(--df-text-dim); }
|
||||
.status-pending_review { background: rgba(100,181,246,0.2); color: var(--df-info); }
|
||||
.status-approved { background: rgba(100,255,218,0.15); color: var(--df-success); }
|
||||
.status-promoted { background: rgba(108,99,255,0.2); color: var(--df-accent); }
|
||||
.status-rejected { background: rgba(255,107,107,0.2); color: var(--df-danger); }
|
||||
.status-draft { background: var(--df-neutral-bg); color: var(--df-text-dim); }
|
||||
.status-pending_review { background: var(--df-info-bg); color: var(--df-info); border: 1px solid var(--df-info-bd); }
|
||||
.status-approved { background: var(--df-success-bg); color: var(--df-success); border: 1px solid var(--df-success-bd); }
|
||||
.status-promoted { background: var(--df-accent-bg); color: var(--df-accent); border: 1px solid var(--df-accent-bd); }
|
||||
.status-rejected { background: var(--df-danger-bg); color: var(--df-danger); border: 1px solid var(--df-danger-bd); }
|
||||
/* 归档态(归档箱内才有):中性灰,与 draft 同系;此前列表/详情渲染 .status-archived 无对应色 → 徽章悬空 */
|
||||
.status-archived { background: rgba(90,99,128,0.2); color: var(--df-text-dim); }
|
||||
.status-archived { background: var(--df-neutral-bg); color: var(--df-text-dim); }
|
||||
|
||||
/* — 任务状态徽章色(7 态):Tasks 列表 + TaskDetail/ProjectDetail 详情共用 —
|
||||
WK-6:原仅 TaskDetail/ProjectDetail scoped 定义,Tasks.vue 列表拿不到 → 裸文本。
|
||||
提取全局对齐三视图;配色以 TaskDetail.vue(7 态最全)为准,尺寸/圆角统一走上方 .status-tag。
|
||||
(TaskDetail 的 scoped 同名类特异度更高会覆盖,但值与全局一致,无视觉差异) */
|
||||
.status-todo { background: rgba(90,99,128,0.2); color: var(--df-text-dim); }
|
||||
.status-progress { background: rgba(100,181,246,0.2); color: var(--df-info); }
|
||||
.status-review { background: rgba(255,217,61,0.2); color: var(--df-warning); }
|
||||
.status-testing { background: rgba(255,152,0,0.2); color: #ff9800; }
|
||||
.status-done { background: rgba(100,255,218,0.15); color: var(--df-success); }
|
||||
.status-blocked { background: rgba(255,107,107,0.12); color: var(--df-danger); border: 0.5px solid var(--df-danger); }
|
||||
.status-abandoned { background: rgba(255,107,107,0.2); color: var(--df-danger); }
|
||||
.status-deferred { background: rgba(255,193,7,0.15); color: #f0a030; }
|
||||
/* — 任务状态徽章色(8 态):Tasks 列表 + TaskDetail/ProjectDetail 详情共用 —
|
||||
原 TaskDetail/ProjectDetail scoped 副本已删,此处为唯一真值。
|
||||
2026-10-18 配色收口:Material 并行色板(hex/rgba)全清,改语义 token 三件套;
|
||||
testing(#ff9800)/deferred(#ffc107)原 amber/orange 系按配色审计归警告族;
|
||||
review/testing/deferred 三态同走 warning,靠徽章文字区分。 */
|
||||
.status-todo { background: var(--df-neutral-bg); color: var(--df-text-dim); }
|
||||
.status-progress { background: var(--df-info-bg); color: var(--df-info); border: 1px solid var(--df-info-bd); }
|
||||
.status-review { background: var(--df-warning-bg); color: var(--df-warning); border: 1px solid var(--df-warning-bd); }
|
||||
.status-testing { background: var(--df-warning-bg); color: var(--df-warning); border: 1px solid var(--df-warning-bd); }
|
||||
.status-done { background: var(--df-success-bg); color: var(--df-success); border: 1px solid var(--df-success-bd); }
|
||||
.status-blocked { background: var(--df-danger-bg); color: var(--df-danger); border: 1px solid var(--df-danger-bd); }
|
||||
.status-abandoned { background: var(--df-danger-bg); color: var(--df-danger); border: 1px solid var(--df-danger-bd); }
|
||||
.status-deferred { background: var(--df-warning-bg); color: var(--df-warning); border: 1px solid var(--df-warning-bd); }
|
||||
|
||||
/* — 多维评分条:IdeaDetail.vue + ProjectDetail.vue 共享 —
|
||||
原 IdeaDetail.vue L770-808 / ProjectDetail.vue L678-692 两处逐字一致
|
||||
@@ -181,7 +185,7 @@
|
||||
font-size: 11px;
|
||||
padding: 2px 8px;
|
||||
border-radius: var(--df-radius-xs);
|
||||
background: rgba(108, 99, 255, 0.08);
|
||||
background: var(--df-accent-bg);
|
||||
color: var(--df-text-secondary);
|
||||
border: 0.5px solid var(--df-border);
|
||||
}
|
||||
@@ -261,7 +265,7 @@
|
||||
background: var(--df-bg-card);
|
||||
border: 0.5px solid var(--df-border);
|
||||
border-radius: var(--df-radius);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
|
||||
box-shadow: var(--df-shadow-md);
|
||||
z-index: 20;
|
||||
}
|
||||
.ai-skill-item {
|
||||
@@ -374,11 +378,83 @@
|
||||
color: var(--df-text-dim);
|
||||
}
|
||||
/* 压缩中 spinner 图标旋转动画(原 AiChat.vue <style scoped> 抽取;
|
||||
TopBar.vue .ai-btn-spinner 按名引用,Vue 不对 @keyframes scoped 故全局可见) */
|
||||
TopBar.vue .ai-btn-spinner 按名引用,Vue 不对 @keyframes scoped 故全局可见;
|
||||
2026-10-18 动画并入 global.css df-spin 单一来源) */
|
||||
.ai-btn-spinner {
|
||||
animation: ai-btn-spin 0.9s linear infinite;
|
||||
animation: df-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes ai-btn-spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════
|
||||
样式大重构 R0 公共类(2026-10-18 新增)
|
||||
来源:u-agent 管理台范式(D:\Downloads\u-agent),hairline 网格/发丝线行/染色两档
|
||||
染色统一走 token:底 --df-*-bg(12%)+ 边 --df-*-bd(30%)+ 同色字
|
||||
═══════════════════════════════════════════════════════════ */
|
||||
|
||||
/* — .df-kv: hairline 网格档案卡(gap:1px 以边框色作发丝分隔线) — */
|
||||
.df-kv {
|
||||
display: grid;
|
||||
gap: 1px;
|
||||
background: var(--df-border);
|
||||
border: 1px solid var(--df-border);
|
||||
border-radius: var(--df-radius-md);
|
||||
overflow: hidden;
|
||||
}
|
||||
.df-kv-i {
|
||||
background: var(--df-bg-raised);
|
||||
padding: 10px 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
.df-kv-k {
|
||||
font-size: var(--df-fs-micro);
|
||||
text-transform: uppercase;
|
||||
color: var(--df-text-dim);
|
||||
font-family: var(--df-font-mono);
|
||||
}
|
||||
.df-kv-v {
|
||||
font-size: var(--df-fs-aux);
|
||||
font-family: var(--df-font-mono);
|
||||
margin-top: 2px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* — .df-row: 发丝线行(末行无线) — */
|
||||
.df-row {
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid var(--df-border);
|
||||
}
|
||||
.df-row:last-child { border-bottom: none; }
|
||||
|
||||
/* — .df-note: 通知条(info/warning/danger 染色) — */
|
||||
.df-note {
|
||||
padding: 8px 12px;
|
||||
border-radius: var(--df-radius-md);
|
||||
font-size: var(--df-fs-ctrl);
|
||||
}
|
||||
.df-note--info { background: var(--df-info-bg); border: 1px solid var(--df-info-bd); color: var(--df-info); }
|
||||
.df-note--warning { background: var(--df-warning-bg); border: 1px solid var(--df-warning-bd); color: var(--df-warning); }
|
||||
.df-note--danger { background: var(--df-danger-bg); border: 1px solid var(--df-danger-bd); color: var(--df-danger); }
|
||||
|
||||
/* — .df-pill: 状态胶囊(全圆 + 染色,体系同 .df-note) — */
|
||||
.df-pill {
|
||||
border-radius: 999px;
|
||||
padding: 1px 8px;
|
||||
font-size: var(--df-fs-meta);
|
||||
font-family: var(--df-font-mono);
|
||||
}
|
||||
.df-pill--success { background: var(--df-success-bg); border: 1px solid var(--df-success-bd); color: var(--df-success); }
|
||||
.df-pill--warning { background: var(--df-warning-bg); border: 1px solid var(--df-warning-bd); color: var(--df-warning); }
|
||||
.df-pill--danger { background: var(--df-danger-bg); border: 1px solid var(--df-danger-bd); color: var(--df-danger); }
|
||||
.df-pill--info { background: var(--df-info-bg); border: 1px solid var(--df-info-bd); color: var(--df-info); }
|
||||
|
||||
/* — .df-tab: 下划线 tab(激活 2px accent 底线) — */
|
||||
.df-tab {
|
||||
padding: 6px 10px;
|
||||
font-size: var(--df-fs-ctrl);
|
||||
color: var(--df-text-secondary);
|
||||
border-bottom: 2px solid transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
.df-tab--active {
|
||||
color: var(--df-text);
|
||||
border-bottom-color: var(--df-accent);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user