Skip to content

Commit cf2a6b2

Browse files
committed
feat(ui): 重构变量系统并实现测试区独立变量管理
## 核心功能 ### 变量系统重构 - 移除会话变量系统,实现独立的测试变量功能 - 将 useContextManagement 从 web 模块迁移到 ui 模块 - 升级 usePromptTester 支持测试变量注入和上下文 ### 测试区临时变量管理 - 临时变量数据结构升级为 { value, timestamp } - 按时间戳降序排序显示(最新在前) - 支持手动增删改操作 - 添加变量对话框,支持变量名验证 - 删除按钮,支持单个变量删除 - 与优化后提示词解耦,不再自动绑定 ### 变量提取功能 - 新增 variable-extraction 组件目录 - VariableAwareInput: 支持文本选择提取变量 - VariableExtractionDialog: 变量提取对话框 - useTextSelection: 文本选择管理 - useInputHistory: 输入历史管理 - 支持全局/临时变量类型选择 - 支持全部替换功能 ## 技术改进 ### 组件优化 - TestAreaPanel.vue: testVariables 从 Record<string, string> 升级为 Record<string, TestVariable> - InputPanel.vue: 集成 VariableAwareInput 组件,支持变量提取 - ContextUserWorkspace.vue: 新增 temporaryVariables 状态管理 ### 国际化完善 - 补充缺失的 test.invalidVariables 和 test.getVariablesFailed 键 - 新增变量提取相关的完整国际化文本 - 覆盖中文简体/繁体/英文三种语言 - 同步三语言国际化键值(en-US/zh-CN/zh-TW) ## 其他更新 - 修复 web/extension 中未使用变量和错误 API 调用 - 更新测试文件的组件导入路径 - 清理过度 debug 日志 - 更新相关文档(ui-refactor-plan.md, variable-system-redesign.md) ## 相关 Issue - 解决测试区变量显示依赖优化结果的问题 - 实现变量独立管理需求 - 补充缺失的国际化文本 **测试:所有测试通过(core: 367, ui: 95)**
1 parent 1d39f11 commit cf2a6b2

26 files changed

+6260
-1063
lines changed

docs/workspace/ui-design-analysis.md

Lines changed: 1789 additions & 0 deletions
Large diffs are not rendered by default.

docs/workspace/ui-refactor-plan.md

Lines changed: 804 additions & 0 deletions
Large diffs are not rendered by default.

docs/workspace/variable-system-redesign.md

Lines changed: 788 additions & 0 deletions
Large diffs are not rendered by default.

packages/extension/src/App.vue

Lines changed: 808 additions & 560 deletions
Large diffs are not rendered by default.

packages/ui/src/components/InputPanel.vue

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,22 @@
7070
</NFlex>
7171
</NFlex>
7272

73-
<!-- 输入框 -->
73+
<!-- 输入框 - 使用变量感知输入框 (支持变量提取) -->
74+
<VariableAwareInput
75+
v-if="enableVariableExtraction"
76+
:model-value="modelValue"
77+
@update:model-value="$emit('update:modelValue', $event)"
78+
:placeholder="placeholder"
79+
:autosize="{ minRows: 4, maxRows: 12 }"
80+
:existing-global-variables="existingGlobalVariables"
81+
:existing-temporary-variables="existingTemporaryVariables"
82+
:predefined-variables="predefinedVariables"
83+
@variable-extracted="handleVariableExtracted"
84+
/>
85+
86+
<!-- 原生输入框 (不支持变量提取) -->
7487
<NInput
88+
v-else
7589
:value="modelValue"
7690
@update:value="$emit('update:modelValue', $event)"
7791
type="textarea"
@@ -164,19 +178,50 @@ import {
164178
} from "naive-ui";
165179
import { useFullscreen } from "../composables/useFullscreen";
166180
import FullscreenDialog from "./FullscreenDialog.vue";
181+
import { VariableAwareInput } from "./variable-extraction";
182+
183+
/**
184+
* 输入面板组件
185+
*
186+
* 功能:
187+
* 1. 提供输入框用于用户输入内容
188+
* 2. 支持全屏编辑模式
189+
* 3. 支持变量提取功能 (可选)
190+
* 4. 提供模型选择、模板选择等控制面板
191+
*/
167192
168193
interface Props {
194+
/** 输入框的值 */
169195
modelValue: string;
196+
/** 选中的模型 */
170197
selectedModel: string;
198+
/** 面板标题 */
171199
label: string;
200+
/** 占位符文本 */
172201
placeholder?: string;
202+
/** 模型选择标签 */
173203
modelLabel: string;
204+
/** 模板选择标签 */
174205
templateLabel?: string;
206+
/** 提交按钮文本 */
175207
buttonText: string;
208+
/** 加载中文本 */
176209
loadingText: string;
210+
/** 是否正在加载 */
177211
loading?: boolean;
212+
/** 是否禁用 */
178213
disabled?: boolean;
214+
/** 是否显示预览按钮 */
179215
showPreview?: boolean;
216+
217+
/** 🆕 是否启用变量提取功能 */
218+
enableVariableExtraction?: boolean;
219+
/** 🆕 已存在的全局变量名列表 */
220+
existingGlobalVariables?: string[];
221+
/** 🆕 已存在的临时变量名列表 */
222+
existingTemporaryVariables?: string[];
223+
/** 🆕 系统预定义变量名列表 */
224+
predefinedVariables?: string[];
180225
}
181226
182227
const props = withDefaults(defineProps<Props>(), {
@@ -185,6 +230,10 @@ const props = withDefaults(defineProps<Props>(), {
185230
loading: false,
186231
disabled: false,
187232
showPreview: false,
233+
enableVariableExtraction: false,
234+
existingGlobalVariables: () => [],
235+
existingTemporaryVariables: () => [],
236+
predefinedVariables: () => [],
188237
});
189238
190239
const emit = defineEmits<{
@@ -193,11 +242,28 @@ const emit = defineEmits<{
193242
submit: [];
194243
configModel: [];
195244
"open-preview": [];
245+
/** 🆕 变量提取事件 */
246+
"variable-extracted": [
247+
data: {
248+
variableName: string;
249+
variableValue: string;
250+
variableType: "global" | "temporary";
251+
},
252+
];
196253
}>();
197254
198255
// 使用全屏组合函数
199256
const { isFullscreen, fullscreenValue, openFullscreen } = useFullscreen(
200257
computed(() => props.modelValue),
201258
(value) => emit("update:modelValue", value),
202259
);
260+
261+
// 处理变量提取事件
262+
const handleVariableExtracted = (data: {
263+
variableName: string;
264+
variableValue: string;
265+
variableType: "global" | "temporary";
266+
}) => {
267+
emit("variable-extracted", data);
268+
};
203269
</script>

0 commit comments

Comments
 (0)