Skip to content

Commit f7ff77f

Browse files
committed
refactor(ui): 重构 ContextEditor 并优化测试并发执行
- 移除 ContextEditor 中的变量管理标签页: - 删除变量标签页 UI(移除 125 行代码) - 禁用变量标签页的显示配置 - 保留变量编辑对话框,用于快速创建缺失变量 - 移除 ContextEditor 中不必要的 contextMode 判断: - 移除 ContextEditorProps 中的 contextMode 属性 - 简化标签页可见性逻辑,删除冗余的 contextMode 条件判断 - 添加注释明确 ContextEditor 仅用于 Context System 模式 - 优化提示词对比测试为并发执行: - usePromptTester:从串行改为并发执行 - useContextUserTester:从串行改为并发执行 - useConversationTester:保持并发不变,无需修改 - 使用 Promise.all 实现并发请求,提升执行效率
1 parent 6b3a740 commit f7ff77f

File tree

4 files changed

+40
-163
lines changed

4 files changed

+40
-163
lines changed

packages/ui/src/components/context-mode/ContextEditor.vue

Lines changed: 6 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -824,132 +824,7 @@
824824
</div>
825825
</NTabPane>
826826

827-
<!-- 变量管理标签页 -->
828-
<NTabPane name="variables" v-if="showVariablesTab" :tab="t('contextEditor.variablesTab')">
829-
<div
830-
class="variables-panel"
831-
role="region"
832-
:aria-label="aria.getLabel('variablesPanel')"
833-
>
834-
<!-- 变量状态信息 -->
835-
<NCard size="small" embedded class="mb-4">
836-
<NSpace align="center" justify="space-between" wrap>
837-
<NSpace align="center" :size="8">
838-
<NText strong>{{
839-
t("contextEditor.variableManagement")
840-
}}</NText>
841-
<NTag :size="tagSize" type="warning">
842-
{{
843-
t("contextEditor.temporaryVariableCount", {
844-
count: Object.keys(
845-
tempVars.listVariables(),
846-
).length,
847-
})
848-
}}
849-
</NTag>
850-
<NTag
851-
:size="tagSize"
852-
type="info"
853-
v-if="globalCustomVariableCount > 0"
854-
>
855-
{{
856-
t("contextEditor.globalVariables", {
857-
count: globalCustomVariableCount,
858-
})
859-
}}
860-
</NTag>
861-
</NSpace>
862-
</NSpace>
863-
<!-- 添加说明文案 -->
864-
<NText depth="3" class="text-xs mt-2 block">
865-
{{
866-
t("contextEditor.variableManagementHint")
867-
}}
868-
</NText>
869-
</NCard>
870-
871-
<!-- 变量列表 -->
872-
<NEmpty
873-
v-if="
874-
Object.keys(tempVars.listVariables()).length === 0 &&
875-
globalCustomVariableCount === 0
876-
"
877-
:description="t('contextEditor.noVariables')"
878-
role="status"
879-
:aria-label="aria.getLabel('emptyVariables')"
880-
>
881-
<template #icon>
882-
<svg
883-
width="48"
884-
height="48"
885-
viewBox="0 0 24 24"
886-
fill="none"
887-
stroke="currentColor"
888-
stroke-width="1"
889-
>
890-
<path
891-
d="M4 7v10c0 2.21 1.79 4 4 4h8c2.21 0 4-1.79 4-4V7M4 7c0-2.21 1.79-4 4-4h8c2.21 0 4-1.79 4-4M4 7h16M8 11h8M8 15h6"
892-
/>
893-
</svg>
894-
</template>
895-
<template #extra>
896-
<NButton
897-
@click="addVariable"
898-
:size="buttonSize"
899-
type="primary"
900-
:disabled="disabled"
901-
>
902-
{{ t("contextEditor.addFirstVariable") }}
903-
</NButton>
904-
</template>
905-
</NEmpty>
906-
907-
<div v-else>
908-
<!-- 变量表格 -->
909-
<NDataTable
910-
:columns="variableColumns"
911-
:data="variableTableData"
912-
:pagination="false"
913-
:bordered="false"
914-
size="small"
915-
striped
916-
class="mb-4"
917-
/>
918-
919-
<!-- 添加变量按钮 -->
920-
<NCard :size="cardSize" embedded dashed>
921-
<NSpace justify="center">
922-
<NButton
923-
@click="addVariable"
924-
:size="buttonSize"
925-
dashed
926-
type="primary"
927-
block
928-
:disabled="disabled"
929-
>
930-
<template #icon>
931-
<svg
932-
width="16"
933-
height="16"
934-
viewBox="0 0 24 24"
935-
fill="none"
936-
stroke="currentColor"
937-
>
938-
<path
939-
stroke-linecap="round"
940-
stroke-linejoin="round"
941-
stroke-width="2"
942-
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
943-
/>
944-
</svg>
945-
</template>
946-
{{ t("contextEditor.addVariable") }}
947-
</NButton>
948-
</NSpace>
949-
</NCard>
950-
</div>
951-
</div>
952-
</NTabPane>
827+
<!-- 变量管理标签页已移除,使用独立的 VariableManagerModal -->
953828

954829
<!-- 工具管理标签页 -->
955830
<NTabPane v-if="showToolsTab" name="tools" :tab="t('contextEditor.toolsTab')">
@@ -1833,7 +1708,6 @@ const props = withDefaults(
18331708
visible: false,
18341709
showToolManager: true,
18351710
optimizationMode: "system",
1836-
contextMode: "system",
18371711
title: "",
18381712
width: "90vw",
18391713
height: "85vh",
@@ -1925,11 +1799,12 @@ const tagSize = computed(() => {
19251799
// 标签页显示控制逻辑 - 配置驱动
19261800
type TabName = 'messages' | 'templates' | 'variables' | 'tools';
19271801
1928-
// 标签页默认可见性配置
1802+
// 标签页默认可见性配置(ContextEditor 仅用于 Context System 模式)
1803+
// 变量管理已移除,使用独立的 VariableManagerModal
19291804
const TAB_VISIBILITY_CONFIG: Record<TabName, () => boolean> = {
1930-
messages: () => props.contextMode !== "user",
1931-
templates: () => props.contextMode !== "user",
1932-
variables: () => true, // 变量标签页默认总是显示
1805+
messages: () => true,
1806+
templates: () => true,
1807+
variables: () => false, // 已移除变量标签页
19331808
tools: () => props.showToolManager,
19341809
};
19351810

packages/ui/src/composables/prompt/useContextUserTester.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,23 @@ export function useContextUserTester(
112112
}
113113

114114
if (isCompareMode) {
115-
// 对比模式:测试原始和优化提示词
116-
await state.testPromptWithType(
117-
'original',
118-
prompt,
119-
optimizedPrompt,
120-
testContent,
121-
testVariables
122-
)
123-
await state.testPromptWithType(
124-
'optimized',
125-
prompt,
126-
optimizedPrompt,
127-
testContent,
128-
testVariables
129-
)
115+
// 对比模式:并发测试原始和优化提示词
116+
await Promise.all([
117+
state.testPromptWithType(
118+
'original',
119+
prompt,
120+
optimizedPrompt,
121+
testContent,
122+
testVariables
123+
),
124+
state.testPromptWithType(
125+
'optimized',
126+
prompt,
127+
optimizedPrompt,
128+
testContent,
129+
testVariables
130+
)
131+
])
130132
} else {
131133
// 单一模式:只测试优化后的提示词
132134
await state.testPromptWithType(

packages/ui/src/composables/prompt/usePromptTester.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,23 @@ export function usePromptTester(
7676
}
7777

7878
if (isCompareMode) {
79-
// 对比模式:测试原始和优化提示词
80-
await state.testPromptWithType(
81-
'original',
82-
prompt,
83-
optimizedPrompt,
84-
testContent,
85-
testVariables
86-
)
87-
await state.testPromptWithType(
88-
'optimized',
89-
prompt,
90-
optimizedPrompt,
91-
testContent,
92-
testVariables
93-
)
79+
// 对比模式:并发测试原始和优化提示词
80+
await Promise.all([
81+
state.testPromptWithType(
82+
'original',
83+
prompt,
84+
optimizedPrompt,
85+
testContent,
86+
testVariables
87+
),
88+
state.testPromptWithType(
89+
'optimized',
90+
prompt,
91+
optimizedPrompt,
92+
testContent,
93+
testVariables
94+
)
95+
])
9496
} else {
9597
// 单一模式:只测试优化后的提示词
9698
await state.testPromptWithType(

packages/ui/src/types/components.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ export interface ContextEditorProps extends BaseComponentProps {
146146
tools?: ToolDefinition[]
147147
/** 优化模式(用于模板分类) */
148148
optimizationMode?: 'system' | 'user'
149-
/** 上下文模式(用于控制UI行为) */
150-
contextMode?: import('@prompt-optimizer/core').ContextMode
151149
/** 变量扫描函数(标准化注入) */
152150
scanVariables: (content: string) => string[]
153151
/** 变量替换函数(标准化注入) */

0 commit comments

Comments
 (0)