refactor: 静态变量提到对话外 + System Prompt 模板展开可视化
- 新建 SessionBar:会话变量独立于消息气泡,显示在对话顶部
- 重写 SystemPromptView:解析 {{var}} 占位符并内联展示模板→变量映射
- 重构 MessageList:提取 static_var 到 varMap,过滤后传入气泡
- 更新 SegmentRenderer + MessageBubble:传递 varMap 到 SystemPromptView
- 更新所有 Demo:static_var 从 user 消息迁移到 system 消息,使用真实会话配置(current_date、language、knowledge_cutoff)
- 更新导出逻辑:system 消息中收集 static_var 并在模板中展开 {{var}}
- 更新测试:新增模板展开用例,18 tests pass
This commit is contained in:
@@ -38,10 +38,16 @@ export interface TextSegment {
|
||||
content: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话级静态变量 —— 在对话开始时注入到 System Prompt 模板中展开。
|
||||
* 例如 {{current_date}} 在模板中展开为 "2026年6月7日"。
|
||||
* 这些变量对用户可见,解释了模型"看到"的上下文配置。
|
||||
*/
|
||||
export interface StaticVarSegment {
|
||||
kind: 'static_var'
|
||||
name: string // e.g. "user_name"
|
||||
value: string // e.g. "张三"
|
||||
name: string // 模板变量名,e.g. "current_date"
|
||||
value: string // 展开后的值,e.g. "2026年6月7日"
|
||||
description?: string // 简短说明该变量的用途
|
||||
}
|
||||
|
||||
export interface SystemPromptSegment {
|
||||
|
||||
Reference in New Issue
Block a user