Skip to content

Commit f0c5caf

Browse files
committed
refactor(ui): 重构变量管理系统和编辑器代码结构
**架构重构** - 从集中式变量管理迁移到分层架构(临时/全局/预定义) - 废弃 ContextEditorState.variables,保持向后兼容 - 移除组件间不必要的 services prop 传递 - 添加 VariableManager 工厂函数和异步初始化机制 - 完善国际化支持,统一术语("上下文变量" → "临时变量") **补全逻辑优化** - 移除预定义变量的自动补全功能,简化补全列表 - 调整补全优先级:临时变量 (boost: 3) > 全局变量 (boost: 2) > 预定义变量 (boost: 1) - 修改 global-variables 传递为仅自定义变量 - 新增 createVariableCompletionOption 函数,统一处理补全逻辑 - 智能检测光标后已有的右括号数量,动态计算需要插入的右括号数量 **UI 和代码结构优化** - 新增 useContextEditorUIState composable 统一管理编辑器 UI 状态 - 消除 extension/web App.vue 中约 40 行重复代码 - 使用配置驱动方式简化标签页可见性逻辑 - 移除 watch(props.visible) 中的冗余 else 分支 - 合并重复的 CSS 规则 - 将卡片标题从"变量值设置"更改为"临时变量",更准确地反映功能定位 - 移除重复的"管理变量"按钮,避免与上方"全局变量"按钮功能重复 **代码清理和测试增强** - 清理未使用的 handleOpenVariableManager 函数 - 消除重复的补全选项构建逻辑,提高代码可维护性 - 新增右括号补齐测试用例,增强现有测试使用实际编辑器视图模拟 - 更新所有相关测试用例,所有测试通过 - 提升整体代码可维护性和简洁性 影响范围:core, ui, web, extension
1 parent d47f162 commit f0c5caf

28 files changed

+1306
-515
lines changed

packages/core/src/types/advanced.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,11 @@ export interface ContextTemplate {
140140
export interface ContextEditorState {
141141
/** 当前消息列表 */
142142
messages: ConversationMessage[];
143-
/** 当前变量 */
144-
variables: Record<string, string>;
143+
/**
144+
* 当前变量
145+
* @deprecated 已迁移到 useTemporaryVariables() 和 useVariableManager(),此字段保留仅为向后兼容
146+
*/
147+
variables?: Record<string, string>;
145148
/** 当前工具 */
146149
tools: ToolDefinition[];
147150
/** 是否显示变量预览 */

packages/extension/src/App.vue

Lines changed: 38 additions & 56 deletions
Large diffs are not rendered by default.

packages/ui/src/components/PromptPanel.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
"
162162
:type="templateType"
163163
:optimization-mode="optimizationMode"
164-
:services="services"
165164
@manage="$emit('openTemplateManager', templateType)"
166165
/>
167166
</div>
@@ -202,15 +201,14 @@
202201
</template>
203202

204203
<script setup lang="ts">
205-
import { ref, computed, nextTick, watch, type Ref } from "vue";
204+
import { ref, computed, nextTick, watch } from "vue";
206205
import { useI18n } from "vue-i18n";
207206
import { NButton, NText, NInput, NCard, NFlex, NSpace, NTag, NIcon } from "naive-ui";
208207
import { useToast } from '../composables/ui/useToast';
209208
import TemplateSelect from "./TemplateSelect.vue";
210209
import Modal from "./Modal.vue";
211210
import OutputDisplay from "./OutputDisplay.vue";
212211
import type { Template, PromptRecord } from "@prompt-optimizer/core";
213-
import type { AppServices } from "../types/services";
214212
215213
const { t } = useI18n();
216214
const toast = useToast();
@@ -258,10 +256,6 @@ const props = defineProps({
258256
type: String as () => import("@prompt-optimizer/core").OptimizationMode,
259257
required: true,
260258
},
261-
services: {
262-
type: Object as () => Ref<AppServices | null>,
263-
required: true,
264-
},
265259
advancedModeEnabled: {
266260
type: Boolean,
267261
default: false,

packages/ui/src/components/TemplateSelect.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</template>
3131

3232
<script setup lang="ts">
33-
import { ref, computed, watch, inject } from 'vue'
33+
import { ref, computed, watch, inject, type Ref } from 'vue'
3434
3535
import { useI18n } from 'vue-i18n'
3636
import { NSelect, NButton, NSpace, NText } from 'naive-ui'

packages/ui/src/components/TestAreaPanel.vue

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@
114114
>
115115
{{ t("test.variables.addVariable") }}
116116
</NButton>
117-
<NButton
118-
size="small"
119-
@click="handleOpenVariableManager"
120-
>
121-
{{ t("test.variables.manageVariables") }}
122-
</NButton>
123117
</NSpace>
124118
</NSpace>
125119
</NCard>
@@ -635,12 +629,6 @@ const getVariablePlaceholder = (varName: string): string => {
635629
// 变量列表变化时的清理逻辑已不再需要(不再使用 userInputValues)
636630
637631
// 事件处理函数
638-
const handleOpenVariableManager = () => {
639-
emit("open-variable-manager");
640-
recordUpdate();
641-
};
642-
643-
644632
const handleVariableValueChange = (varName: string, value: string) => {
645633
// 🧪 更新测试区临时变量
646634
if (testVariables.value[varName]) {

0 commit comments

Comments
 (0)