vue-agent-start 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/package.json +30 -0
  2. package/pnpm-workspace.yaml +3 -0
  3. package/src/agent-flow/adapter/backend.ts +99 -0
  4. package/src/agent-flow/components/ChatIframePanel.vue +773 -0
  5. package/src/agent-flow/components/DatasetItemCard.vue +313 -0
  6. package/src/agent-flow/components/MemoryWindow.vue +104 -0
  7. package/src/agent-flow/components/PromptEditor.vue +804 -0
  8. package/src/agent-flow/components/PromptEditorTagPanel.vue +460 -0
  9. package/src/agent-flow/components/SvgIcon.vue +32 -0
  10. package/src/agent-flow/components/ToolItemCard.vue +169 -0
  11. package/src/agent-flow/components/VariableCard.vue +161 -0
  12. package/src/agent-flow/components/VariableSelector.vue +162 -0
  13. package/src/agent-flow/components/chat-iframe-types.ts +35 -0
  14. package/src/agent-flow/components/stubs/DatasetChooser.vue +70 -0
  15. package/src/agent-flow/components/stubs/Embedding.vue +22 -0
  16. package/src/agent-flow/components/stubs/ModelSelect.vue +24 -0
  17. package/src/agent-flow/components/stubs/RestfulSelectCard.vue +24 -0
  18. package/src/agent-flow/components/stubs/ToolChooser.vue +96 -0
  19. package/src/agent-flow/components/stubs/TriggersItemCard.vue +126 -0
  20. package/src/agent-flow/components/stubs/VariableModal.vue +115 -0
  21. package/src/agent-flow/index.ts +73 -0
  22. package/src/agent-flow/stores/workflow.ts +72 -0
  23. package/src/agent-flow/utils/langUtils.ts +173 -0
  24. package/src/agent-flow/workflow/Ability.vue +65 -0
  25. package/src/agent-flow/workflow/AuthorizationItem.vue +101 -0
  26. package/src/agent-flow/workflow/ConversationVar.vue +42 -0
  27. package/src/agent-flow/workflow/CustomEdge.vue +94 -0
  28. package/src/agent-flow/workflow/EnvironmentVar.vue +40 -0
  29. package/src/agent-flow/workflow/FlowDesigner.vue +2802 -0
  30. package/src/agent-flow/workflow/Icon.vue +179 -0
  31. package/src/agent-flow/workflow/NodeConfig.vue +509 -0
  32. package/src/agent-flow/workflow/NodeConfigCard.vue +460 -0
  33. package/src/agent-flow/workflow/NodeHandle.vue +147 -0
  34. package/src/agent-flow/workflow/NodeHeaderToolbar.vue +77 -0
  35. package/src/agent-flow/workflow/NodeHoverToolbar.vue +176 -0
  36. package/src/agent-flow/workflow/OutputItemCard.vue +668 -0
  37. package/src/agent-flow/workflow/ParamTableItem.vue +200 -0
  38. package/src/agent-flow/workflow/StructTable.vue +202 -0
  39. package/src/agent-flow/workflow/VarInsertField.vue +517 -0
  40. package/src/agent-flow/workflow/VarSelectField.vue +223 -0
  41. package/src/agent-flow/workflow/VariableSelectorItem.vue +48 -0
  42. package/src/agent-flow/workflow/WfField.vue +206 -0
  43. package/src/agent-flow/workflow/_config-base.css +470 -0
  44. package/src/agent-flow/workflow/composables/useNode.js +55 -0
  45. package/src/agent-flow/workflow/index.vue +53 -0
  46. package/src/agent-flow/workflow/nodeCard/AgentNodeCard.vue +180 -0
  47. package/src/agent-flow/workflow/nodeCard/AnswerNodeCard.vue +65 -0
  48. package/src/agent-flow/workflow/nodeCard/ClassifierCard.vue +152 -0
  49. package/src/agent-flow/workflow/nodeCard/CodeNodeCard.vue +139 -0
  50. package/src/agent-flow/workflow/nodeCard/ConditionNodeCard.vue +323 -0
  51. package/src/agent-flow/workflow/nodeCard/DocumentExtractorCard.vue +83 -0
  52. package/src/agent-flow/workflow/nodeCard/EndNodeCard.vue +123 -0
  53. package/src/agent-flow/workflow/nodeCard/HttpNodeCard.vue +451 -0
  54. package/src/agent-flow/workflow/nodeCard/HumanInputCard.vue +152 -0
  55. package/src/agent-flow/workflow/nodeCard/IterationCard.vue +66 -0
  56. package/src/agent-flow/workflow/nodeCard/KnowledgeRetrievalCard.vue +48 -0
  57. package/src/agent-flow/workflow/nodeCard/LLMNodeCard.vue +206 -0
  58. package/src/agent-flow/workflow/nodeCard/ListOperatorCard.vue +188 -0
  59. package/src/agent-flow/workflow/nodeCard/ParameterExtractorCard.vue +352 -0
  60. package/src/agent-flow/workflow/nodeCard/ServiceApiNodeCard.vue +188 -0
  61. package/src/agent-flow/workflow/nodeCard/StartNodeCard.vue +216 -0
  62. package/src/agent-flow/workflow/nodeCard/VariableAssignerCard.vue +125 -0
  63. package/src/agent-flow/workflow/nodeCard/VariableNodeCard.vue +121 -0
  64. package/src/agent-flow/workflow/nodes/AgentNode.vue +122 -0
  65. package/src/agent-flow/workflow/nodes/AnswerNode.vue +99 -0
  66. package/src/agent-flow/workflow/nodes/ClassifierNode.vue +199 -0
  67. package/src/agent-flow/workflow/nodes/CodeNode.vue +152 -0
  68. package/src/agent-flow/workflow/nodes/ConditionNode.vue +232 -0
  69. package/src/agent-flow/workflow/nodes/DocumentExtractorNode.vue +96 -0
  70. package/src/agent-flow/workflow/nodes/EndNode.vue +119 -0
  71. package/src/agent-flow/workflow/nodes/FileUploadNode.vue +97 -0
  72. package/src/agent-flow/workflow/nodes/HttpNode.vue +204 -0
  73. package/src/agent-flow/workflow/nodes/HumanInputNode.vue +110 -0
  74. package/src/agent-flow/workflow/nodes/IterationNode.vue +98 -0
  75. package/src/agent-flow/workflow/nodes/KnowledgeRetrievalNode.vue +253 -0
  76. package/src/agent-flow/workflow/nodes/LLMNode.vue +134 -0
  77. package/src/agent-flow/workflow/nodes/ListOperatorNode.vue +111 -0
  78. package/src/agent-flow/workflow/nodes/LoopNode.vue +94 -0
  79. package/src/agent-flow/workflow/nodes/ParameterExtractorNode.vue +147 -0
  80. package/src/agent-flow/workflow/nodes/ServiceApiNode.vue +161 -0
  81. package/src/agent-flow/workflow/nodes/StartNode.vue +199 -0
  82. package/src/agent-flow/workflow/nodes/TemplateNode.vue +103 -0
  83. package/src/agent-flow/workflow/nodes/UserInputNode.vue +92 -0
  84. package/src/agent-flow/workflow/nodes/VariableAssignerNode.vue +145 -0
  85. package/src/agent-flow/workflow/nodes/VariableNode.vue +130 -0
  86. package/src/agent-flow/workflow/nodes/_node-base.css +338 -0
  87. package/src/agent-flow/workflow/utils/node_card_form.ts +335 -0
  88. package/src/agent-flow/workflow/utils/node_config.ts +63 -0
  89. package/src/agent-flow/workflow/utils/workflow_utils.ts +151 -0
  90. package/src/agent-studio/adapters/springAgentStart.ts +390 -0
  91. package/src/agent-studio/api/index.ts +1 -0
  92. package/src/agent-studio/api/types.ts +173 -0
  93. package/src/agent-studio/components/AgentApiDocs.vue +500 -0
  94. package/src/agent-studio/components/AgentAppsPage.vue +1601 -0
  95. package/src/agent-studio/components/AgentCardGrid.vue +259 -0
  96. package/src/agent-studio/components/AgentChatPage.vue +553 -0
  97. package/src/agent-studio/components/AgentDebugPanel.vue +350 -0
  98. package/src/agent-studio/components/AgentLogsPanel.vue +391 -0
  99. package/src/agent-studio/components/AgentMonitorPanel.vue +204 -0
  100. package/src/agent-studio/components/AgentOrchestrate.vue +505 -0
  101. package/src/agent-studio/components/AgentPromptEditor.vue +237 -0
  102. package/src/agent-studio/components/AgentStudioShell.vue +227 -0
  103. package/src/agent-studio/components/AgentToolsPanel.vue +394 -0
  104. package/src/agent-studio/components/AgentVariablesPanel.vue +205 -0
  105. package/src/agent-studio/components/ApiKeyManager.vue +251 -0
  106. package/src/agent-studio/components/AppDesignDrawer.vue +3391 -0
  107. package/src/agent-studio/components/CreateAppModal.vue +737 -0
  108. package/src/agent-studio/components/SparkChart.vue +200 -0
  109. package/src/agent-studio/components/VariableEditorModal.vue +499 -0
  110. package/src/agent-studio/composables/useAgentStudio.ts +347 -0
  111. package/src/agent-studio/index.ts +60 -0
  112. package/src/agent-studio/panels/DrawerFlowDesigner.vue +203 -0
  113. package/src/agent-studio/panels/LogAnnotationPanel.vue +490 -0
  114. package/src/agent-studio/panels/MonitorPanel.vue +535 -0
  115. package/src/agent-studio/types.ts +242 -0
  116. package/src/index.ts +155 -0
  117. package/src/knowledge-hub/adapters/springAgentStart.ts +472 -0
  118. package/src/knowledge-hub/components/AddDocumentsWizard.vue +1452 -0
  119. package/src/knowledge-hub/components/CreateDatasetWizard.vue +1723 -0
  120. package/src/knowledge-hub/components/DatasetCardGrid.vue +467 -0
  121. package/src/knowledge-hub/components/DatasetDetailDrawer.vue +888 -0
  122. package/src/knowledge-hub/components/DatasetPicker.vue +65 -0
  123. package/src/knowledge-hub/components/DatasetPickerModal.vue +526 -0
  124. package/src/knowledge-hub/components/DatasetSettingsPanel.vue +908 -0
  125. package/src/knowledge-hub/components/DatasetSidebar.vue +781 -0
  126. package/src/knowledge-hub/components/DocumentChunksView.vue +802 -0
  127. package/src/knowledge-hub/components/DocumentTable.vue +552 -0
  128. package/src/knowledge-hub/components/HitTestingPanel.vue +74 -0
  129. package/src/knowledge-hub/components/KnowledgeApp.vue +66 -0
  130. package/src/knowledge-hub/components/KnowledgeHubApp.vue +504 -0
  131. package/src/knowledge-hub/components/RecallTestingPanelV2.vue +515 -0
  132. package/src/knowledge-hub/components/RetrievalConfigPopover.vue +270 -0
  133. package/src/knowledge-hub/components/RetrievalMethodPicker.vue +547 -0
  134. package/src/knowledge-hub/components/RetrievedList.vue +24 -0
  135. package/src/knowledge-hub/components/internal/KhDialog.vue +195 -0
  136. package/src/knowledge-hub/composables/useKnowledge.ts +89 -0
  137. package/src/knowledge-hub/i18n/index.ts +2 -0
  138. package/src/knowledge-hub/i18n/messages.ts +422 -0
  139. package/src/knowledge-hub/i18n/useKhI18n.ts +107 -0
  140. package/src/knowledge-hub/index.ts +46 -0
  141. package/src/knowledge-hub/styles/index.css +4 -0
  142. package/src/knowledge-hub/styles/tokens.css +138 -0
  143. package/src/knowledge-hub/types/api.ts +213 -0
  144. package/src/knowledge-hub/types/dataset.ts +88 -0
  145. package/src/knowledge-hub/types/document.ts +45 -0
  146. package/src/knowledge-hub/types/index.ts +9 -0
  147. package/src/knowledge-hub/types/retrieval.ts +46 -0
  148. package/src/provider-hub/components/CredentialForm.vue +103 -0
  149. package/src/provider-hub/components/DefaultModelsPanel.vue +270 -0
  150. package/src/provider-hub/components/GroupedModelSelect.vue +445 -0
  151. package/src/provider-hub/components/ModelCardGrid.vue +332 -0
  152. package/src/provider-hub/components/ModelParameterDrawer.vue +739 -0
  153. package/src/provider-hub/components/ModelPickerPopover.vue +1282 -0
  154. package/src/provider-hub/components/ProviderApp.vue +159 -0
  155. package/src/provider-hub/components/ProviderCredentialModal.vue +321 -0
  156. package/src/provider-hub/components/ProviderGallery.vue +131 -0
  157. package/src/provider-hub/components/ProviderHubShell.vue +1992 -0
  158. package/src/provider-hub/components/ProviderIcon.vue +130 -0
  159. package/src/provider-hub/composables/useProviderHub.ts +358 -0
  160. package/src/provider-hub/index.ts +43 -0
  161. package/src/provider-hub/svg/MiniMax.svg +1 -0
  162. package/src/provider-hub/svg/Volcengine.svg +1 -0
  163. package/src/provider-hub/svg/Zhipu.svg +1 -0
  164. package/src/provider-hub/svg/deepseek.svg +1 -0
  165. package/src/provider-hub/svg/moonshot.svg +1 -0
  166. package/src/provider-hub/svg/openai.svg +1 -0
  167. package/src/provider-hub/svg/qwen.svg +1 -0
  168. package/src/provider-hub/svg/siliconflow.svg +1 -0
  169. package/src/provider-hub/types.ts +256 -0
@@ -0,0 +1,773 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * ChatIframePanel — 通用聊天调试壳
4
+ * --------------------------------------------------
5
+ * 承载对同源 / 跨域部署的 antd-react-chat 项目 iframe:
6
+ * - 顶部 header:标题 + 变量按钮(气泡展开填写调试参数)+ 关闭
7
+ * - 变量填写:写入 localStorage,chat 项目 provider 在每次发消息前读取,
8
+ * 参数即时生效(无需 postMessage 时序保障)
9
+ * - 上下文推送:chat 就绪后经 postMessage 下发 host:context / host:command
10
+ *
11
+ * 组件不写死任何 URL / apiKey,全部由宿主注入,方便工作流、Agent、独立
12
+ * playground 各自复用。
13
+ */
14
+ import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
15
+
16
+ import type { ChatDebugVariable } from './chat-iframe-types';
17
+
18
+ interface Props {
19
+ /** iframe 基础 URL,例如 `/chat/` 或 `http://localhost:5073/chat/` */
20
+ src: string;
21
+ /** 顶部标题,默认「调试与预览」 */
22
+ title?: string;
23
+ /** 追加到 iframe URL 的查询参数(difyApiKey / label 等);空值/undefined 自动过滤 */
24
+ params?: Record<string, boolean | number | string | null | undefined>;
25
+ /** 待填写的调试变量清单;空数组 → 隐藏"变量"入口 */
26
+ variables?: ChatDebugVariable[];
27
+ /**
28
+ * 会话隔离 key,用于给 localStorage 加命名空间;不填自动生成。
29
+ * chat 项目通过 URL 参数 `debugInputsKey` 拿到全路径,直接读该 key。
30
+ */
31
+ sessionKey?: string;
32
+ /** chat 就绪后 postMessage 下发的上下文(token/user/theme 等业务字段) */
33
+ context?: Record<string, unknown>;
34
+ /** 是否显示关闭按钮 */
35
+ closable?: boolean;
36
+ }
37
+
38
+ const props = withDefaults(defineProps<Props>(), {
39
+ title: '调试与预览',
40
+ params: () => ({}),
41
+ variables: () => [],
42
+ context: () => ({}),
43
+ closable: true,
44
+ });
45
+
46
+ const emit = defineEmits<{
47
+ (e: 'close'): void;
48
+ (e: 'ready'): void;
49
+ (e: 'inputs-change', inputs: Record<string, unknown>): void;
50
+ }>();
51
+
52
+ const CHANNEL = 'boot-school-chat';
53
+ const INPUTS_STORAGE_PREFIX = 'spring-agent-chat-inputs:';
54
+
55
+ /** 会话隔离 key —— 组件生命周期内固定,用于 localStorage 命名空间 */
56
+ const sessionId = ref(
57
+ props.sessionKey ||
58
+ `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`,
59
+ );
60
+ const inputsStorageKey = computed(
61
+ () => `${INPUTS_STORAGE_PREFIX}${sessionId.value}`,
62
+ );
63
+
64
+ /** 变量值:{ varName: value },写入 localStorage 供 chat provider 读取 */
65
+ const inputValues = ref<Record<string, unknown>>({});
66
+ /** 变量气泡卡是否展开 */
67
+ const showVarPanel = ref(false);
68
+
69
+ const iframeRef = ref<HTMLIFrameElement | null>(null);
70
+ const iframeLoaded = ref(false);
71
+ const chatReady = ref(false);
72
+
73
+ // ---------------------------------------------------------------------------
74
+ // URL 组装:把 params + inputsStorageKey 一起拼上去。
75
+ // ---------------------------------------------------------------------------
76
+ const iframeSrc = computed(() => {
77
+ try {
78
+ const url = new URL(props.src, window.location.href);
79
+ for (const [k, v] of Object.entries(props.params ?? {})) {
80
+ if (v === undefined || v === null || v === '') continue;
81
+ url.searchParams.set(k, String(v));
82
+ }
83
+ url.searchParams.set('debugInputsKey', inputsStorageKey.value);
84
+ return url.toString();
85
+ } catch {
86
+ // 兜底:src 不是合法 URL 时按字符串拼接
87
+ const sep = props.src.includes('?') ? '&' : '?';
88
+ const qs = new URLSearchParams();
89
+ for (const [k, v] of Object.entries(props.params ?? {})) {
90
+ if (v === undefined || v === null || v === '') continue;
91
+ qs.set(k, String(v));
92
+ }
93
+ qs.set('debugInputsKey', inputsStorageKey.value);
94
+ return `${props.src}${sep}${qs.toString()}`;
95
+ }
96
+ });
97
+
98
+ const targetOrigin = computed(() => {
99
+ try {
100
+ return new URL(props.src, window.location.href).origin;
101
+ } catch {
102
+ return '*';
103
+ }
104
+ });
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // 变量表单:默认值初始化 & 持久化到 localStorage
108
+ // ---------------------------------------------------------------------------
109
+ function coerceDefault(v: ChatDebugVariable): unknown {
110
+ if (v.defaultValue === undefined || v.defaultValue === null) {
111
+ return typeInitial(v.type);
112
+ }
113
+ const t = (v.type || 'string').toLowerCase();
114
+ if (t === 'number') {
115
+ const n = Number(v.defaultValue);
116
+ return Number.isFinite(n) ? n : '';
117
+ }
118
+ if (t === 'boolean') return !!v.defaultValue;
119
+ if (t === 'object' || t === 'array') {
120
+ if (typeof v.defaultValue === 'string') {
121
+ try {
122
+ return JSON.parse(v.defaultValue);
123
+ } catch {
124
+ return v.defaultValue;
125
+ }
126
+ }
127
+ return v.defaultValue;
128
+ }
129
+ return String(v.defaultValue);
130
+ }
131
+
132
+ function typeInitial(type?: string): unknown {
133
+ const t = (type || 'string').toLowerCase();
134
+ if (t === 'number') return '';
135
+ if (t === 'boolean') return false;
136
+ if (t === 'object') return {};
137
+ if (t === 'array') return [];
138
+ return '';
139
+ }
140
+
141
+ function initFromVariables(vars: ChatDebugVariable[]) {
142
+ const next: Record<string, unknown> = {};
143
+ for (const v of vars) {
144
+ if (!v?.name) continue;
145
+ // 保留用户已经填过的值,只补新增字段的默认值
146
+ next[v.name] =
147
+ v.name in inputValues.value ? inputValues.value[v.name] : coerceDefault(v);
148
+ }
149
+ inputValues.value = next;
150
+ persistInputs();
151
+ }
152
+
153
+ function persistInputs() {
154
+ try {
155
+ window.localStorage.setItem(
156
+ inputsStorageKey.value,
157
+ JSON.stringify(inputValues.value),
158
+ );
159
+ } catch {
160
+ /* localStorage 不可用则退化为仅当前会话生效 */
161
+ }
162
+ emit('inputs-change', { ...inputValues.value });
163
+ // chat 已就绪时同步 push 一次,避免用户在 chat 页做了缓存
164
+ pushInputsToChat();
165
+ }
166
+
167
+ /** 校验 required 是否都填了;返回缺失的 label 列表 */
168
+ const missingRequired = computed(() => {
169
+ return (props.variables ?? [])
170
+ .filter((v) => {
171
+ if (!v.required) return false;
172
+ const val = inputValues.value[v.name];
173
+ if (val === undefined || val === null) return true;
174
+ if (typeof val === 'string' && val.trim() === '') return true;
175
+ return false;
176
+ })
177
+ .map((v) => v.label || v.name);
178
+ });
179
+
180
+ /** 展示在按钮上的"未填必填数" */
181
+ const requiredMissingCount = computed(() => missingRequired.value.length);
182
+
183
+ function onValueChange(name: string, value: unknown) {
184
+ inputValues.value = { ...inputValues.value, [name]: value };
185
+ persistInputs();
186
+ }
187
+
188
+ function onJsonBlur(name: string, raw: string) {
189
+ const trimmed = raw.trim();
190
+ if (!trimmed) {
191
+ onValueChange(name, undefined);
192
+ return;
193
+ }
194
+ try {
195
+ onValueChange(name, JSON.parse(trimmed));
196
+ } catch {
197
+ // 解析失败保留原字符串,用户下次修改再试
198
+ onValueChange(name, raw);
199
+ }
200
+ }
201
+
202
+ function resetAll() {
203
+ const next: Record<string, unknown> = {};
204
+ for (const v of props.variables ?? []) {
205
+ if (!v?.name) continue;
206
+ next[v.name] = coerceDefault(v);
207
+ }
208
+ inputValues.value = next;
209
+ persistInputs();
210
+ }
211
+
212
+ // ---------------------------------------------------------------------------
213
+ // postMessage 通讯(复用 chat 项目已用的 boot-school-chat 信封)
214
+ // ---------------------------------------------------------------------------
215
+ function postToChat(type: string, payload?: unknown) {
216
+ const win = iframeRef.value?.contentWindow;
217
+ if (!win) return;
218
+ win.postMessage({ channel: CHANNEL, type, payload }, targetOrigin.value);
219
+ }
220
+
221
+ function pushContextToChat() {
222
+ if (!chatReady.value) return;
223
+ postToChat('host:context', props.context ?? {});
224
+ }
225
+
226
+ /** chat 已就绪时把最新变量值以 host:command 形式再推一次(storage 已同步,这里主要为 UI 层预热) */
227
+ function pushInputsToChat() {
228
+ if (!chatReady.value) return;
229
+ postToChat('host:command', {
230
+ type: 'set-inputs',
231
+ inputs: { ...inputValues.value },
232
+ });
233
+ }
234
+
235
+ function onMessage(event: MessageEvent) {
236
+ const src = iframeRef.value?.contentWindow;
237
+ if (!src || event.source !== src) return;
238
+ const data = event.data as { channel?: string; type?: string; payload?: unknown } | null;
239
+ if (!data || data.channel !== CHANNEL || !data.type) return;
240
+ switch (data.type) {
241
+ case 'chat:ready':
242
+ chatReady.value = true;
243
+ pushContextToChat();
244
+ pushInputsToChat();
245
+ emit('ready');
246
+ break;
247
+ case 'chat:close':
248
+ emit('close');
249
+ break;
250
+ default:
251
+ break;
252
+ }
253
+ }
254
+
255
+ function onIframeLoad() {
256
+ iframeLoaded.value = true;
257
+ }
258
+
259
+ function reload() {
260
+ chatReady.value = false;
261
+ iframeLoaded.value = false;
262
+ if (iframeRef.value) {
263
+ iframeRef.value.src = iframeSrc.value;
264
+ }
265
+ }
266
+
267
+ // 组件挂载:绑定监听 + 用初始 variables 建仓
268
+ window.addEventListener('message', onMessage);
269
+ initFromVariables(props.variables ?? []);
270
+
271
+ onBeforeUnmount(() => {
272
+ window.removeEventListener('message', onMessage);
273
+ // 清理该会话的 localStorage 输入,避免残留污染下一次挂载
274
+ try {
275
+ window.localStorage.removeItem(inputsStorageKey.value);
276
+ } catch {
277
+ /* noop */
278
+ }
279
+ });
280
+
281
+ // props.variables 变化(宿主重新收集了 START 节点变量) → 用新 schema 合并
282
+ watch(
283
+ () => props.variables,
284
+ (next) => {
285
+ initFromVariables(next ?? []);
286
+ },
287
+ { deep: true },
288
+ );
289
+
290
+ // props.context 变化 → 立即推给 chat
291
+ watch(
292
+ () => props.context,
293
+ () => {
294
+ pushContextToChat();
295
+ },
296
+ { deep: true },
297
+ );
298
+
299
+ // src / params 变化 → 重新加载 iframe(用户切换调试目标应用时有用)
300
+ watch(
301
+ () => iframeSrc.value,
302
+ async () => {
303
+ await nextTick();
304
+ reload();
305
+ },
306
+ );
307
+
308
+ defineExpose({
309
+ reload,
310
+ getInputs: () => ({ ...inputValues.value }),
311
+ setInput: onValueChange,
312
+ postMessage: postToChat,
313
+ });
314
+ </script>
315
+
316
+ <template>
317
+ <div class="cip-root">
318
+ <!-- 头部:标题 + 变量入口 + 关闭 -->
319
+ <div class="cip-head">
320
+ <div class="cip-head-title" :title="title">
321
+ <span class="cip-dot" />
322
+ {{ title }}
323
+ </div>
324
+ <div class="cip-head-actions">
325
+ <button
326
+ v-if="(variables?.length ?? 0) > 0"
327
+ type="button"
328
+ class="cip-var-btn"
329
+ :class="{ 'cip-var-btn-open': showVarPanel, 'cip-var-btn-warn': requiredMissingCount > 0 }"
330
+ :title="requiredMissingCount > 0 ? `${requiredMissingCount} 个必填项待填` : '编辑调试参数'"
331
+ @click="showVarPanel = !showVarPanel"
332
+ >
333
+ <span class="cip-var-btn-icon" aria-hidden="true">◆</span>
334
+ <span>变量</span>
335
+ <span
336
+ v-if="variables.length > 0"
337
+ class="cip-var-btn-badge"
338
+ :class="{ 'cip-var-btn-badge-warn': requiredMissingCount > 0 }"
339
+ >
340
+ {{ requiredMissingCount > 0 ? requiredMissingCount : variables.length }}
341
+ </span>
342
+ </button>
343
+ <button
344
+ type="button"
345
+ class="cip-icon-btn"
346
+ title="刷新会话"
347
+ @click="reload"
348
+ >
349
+
350
+ </button>
351
+ <button
352
+ v-if="closable"
353
+ type="button"
354
+ class="cip-icon-btn"
355
+ title="关闭"
356
+ @click="emit('close')"
357
+ >
358
+
359
+ </button>
360
+ </div>
361
+ </div>
362
+
363
+ <!-- 变量填写卡(气泡样式,浮在 iframe 上) -->
364
+ <div v-if="showVarPanel && variables.length > 0" class="cip-var-panel">
365
+ <div class="cip-var-panel-head">
366
+ <span class="cip-var-panel-title">调试参数</span>
367
+ <div class="cip-var-panel-actions">
368
+ <button
369
+ type="button"
370
+ class="cip-link-btn"
371
+ title="重置为默认值"
372
+ @click="resetAll"
373
+ >
374
+ 重置
375
+ </button>
376
+ <button
377
+ type="button"
378
+ class="cip-icon-btn cip-icon-btn-sm"
379
+ title="收起"
380
+ @click="showVarPanel = false"
381
+ >
382
+
383
+ </button>
384
+ </div>
385
+ </div>
386
+ <div v-if="missingRequired.length > 0" class="cip-var-warn">
387
+ 必填项未填:{{ missingRequired.join('、') }}
388
+ </div>
389
+ <div class="cip-var-body">
390
+ <div v-for="v in variables" :key="v.name" class="cip-var-row">
391
+ <label class="cip-var-label" :title="v.description">
392
+ {{ v.label || v.name }}
393
+ <span v-if="v.required" class="cip-var-required">*</span>
394
+ <span class="cip-var-type">{{ (v.type || 'string').toLowerCase() }}</span>
395
+ </label>
396
+ <!-- string / 未识别类型 → 单行输入 -->
397
+ <template v-if="!v.type || ['string', 'file'].includes(v.type.toLowerCase())">
398
+ <input
399
+ class="cip-input"
400
+ :value="(inputValues[v.name] as string) ?? ''"
401
+ :placeholder="v.description || v.name"
402
+ @input="(e) => onValueChange(v.name, (e.target as HTMLInputElement).value)"
403
+ />
404
+ </template>
405
+ <!-- number -->
406
+ <template v-else-if="v.type.toLowerCase() === 'number'">
407
+ <input
408
+ type="number"
409
+ class="cip-input"
410
+ :value="(inputValues[v.name] as number) ?? ''"
411
+ :placeholder="v.description"
412
+ @input="(e) => onValueChange(v.name, Number((e.target as HTMLInputElement).value))"
413
+ />
414
+ </template>
415
+ <!-- boolean -->
416
+ <template v-else-if="v.type.toLowerCase() === 'boolean'">
417
+ <label class="cip-switch">
418
+ <input
419
+ type="checkbox"
420
+ :checked="!!inputValues[v.name]"
421
+ @change="(e) => onValueChange(v.name, (e.target as HTMLInputElement).checked)"
422
+ />
423
+ <span>{{ inputValues[v.name] ? '是' : '否' }}</span>
424
+ </label>
425
+ </template>
426
+ <!-- object / array → JSON textarea -->
427
+ <template v-else>
428
+ <textarea
429
+ class="cip-textarea"
430
+ rows="3"
431
+ :value="
432
+ typeof inputValues[v.name] === 'string'
433
+ ? (inputValues[v.name] as string)
434
+ : JSON.stringify(inputValues[v.name] ?? (v.type.toLowerCase() === 'array' ? [] : {}), null, 2)
435
+ "
436
+ :placeholder="`JSON ${v.type}`"
437
+ @blur="(e) => onJsonBlur(v.name, (e.target as HTMLTextAreaElement).value)"
438
+ />
439
+ </template>
440
+ </div>
441
+ </div>
442
+ <div class="cip-var-panel-foot">
443
+ 参数会自动同步到聊天窗口,无需保存
444
+ </div>
445
+ </div>
446
+
447
+ <!-- iframe 主体 -->
448
+ <div class="cip-body">
449
+ <iframe
450
+ ref="iframeRef"
451
+ class="cip-iframe"
452
+ :src="iframeSrc"
453
+ title="调试聊天"
454
+ allow="microphone; clipboard-write"
455
+ @load="onIframeLoad"
456
+ />
457
+ <div v-if="!iframeLoaded" class="cip-loading">
458
+ <div class="cip-spinner"><span /><span /></div>
459
+ <div class="cip-loading-text">聊天窗口加载中</div>
460
+ </div>
461
+ </div>
462
+ </div>
463
+ </template>
464
+
465
+ <style scoped>
466
+ .cip-root {
467
+ position: relative;
468
+ display: flex;
469
+ flex-direction: column;
470
+ width: 100%;
471
+ height: 100%;
472
+ min-height: 0;
473
+ background: #fff;
474
+ border: 1px solid #e5e7eb;
475
+ border-radius: 12px;
476
+ overflow: hidden;
477
+ }
478
+ .cip-head {
479
+ display: flex;
480
+ align-items: center;
481
+ justify-content: space-between;
482
+ gap: 8px;
483
+ padding: 10px 14px;
484
+ border-bottom: 1px solid #f1f5f9;
485
+ background: #fff;
486
+ flex-shrink: 0;
487
+ }
488
+ .cip-head-title {
489
+ display: flex;
490
+ align-items: center;
491
+ gap: 6px;
492
+ min-width: 0;
493
+ font-size: 13px;
494
+ font-weight: 600;
495
+ color: #334155;
496
+ overflow: hidden;
497
+ text-overflow: ellipsis;
498
+ white-space: nowrap;
499
+ }
500
+ .cip-dot {
501
+ width: 6px;
502
+ height: 6px;
503
+ border-radius: 50%;
504
+ background: linear-gradient(135deg, #6366f1, #4f46e5);
505
+ flex-shrink: 0;
506
+ }
507
+ .cip-head-actions {
508
+ display: flex;
509
+ align-items: center;
510
+ gap: 4px;
511
+ flex-shrink: 0;
512
+ }
513
+ .cip-var-btn {
514
+ display: inline-flex;
515
+ align-items: center;
516
+ gap: 4px;
517
+ height: 26px;
518
+ padding: 0 8px 0 6px;
519
+ border: 1px solid #e2e8f0;
520
+ border-radius: 999px;
521
+ background: #f8fafc;
522
+ color: #475569;
523
+ font-size: 12px;
524
+ cursor: pointer;
525
+ transition: background 0.15s, border-color 0.15s;
526
+ }
527
+ .cip-var-btn:hover {
528
+ background: #eef2ff;
529
+ border-color: #c7d2fe;
530
+ color: #4338ca;
531
+ }
532
+ .cip-var-btn-open {
533
+ background: #eef2ff;
534
+ border-color: #a5b4fc;
535
+ color: #4338ca;
536
+ }
537
+ .cip-var-btn-warn {
538
+ border-color: #fecaca;
539
+ background: #fef2f2;
540
+ color: #b91c1c;
541
+ }
542
+ .cip-var-btn-icon {
543
+ color: #6366f1;
544
+ font-size: 10px;
545
+ }
546
+ .cip-var-btn-badge {
547
+ display: inline-flex;
548
+ align-items: center;
549
+ justify-content: center;
550
+ min-width: 16px;
551
+ height: 16px;
552
+ padding: 0 4px;
553
+ border-radius: 999px;
554
+ background: #e0e7ff;
555
+ color: #4338ca;
556
+ font-size: 10px;
557
+ line-height: 1;
558
+ }
559
+ .cip-var-btn-badge-warn {
560
+ background: #fee2e2;
561
+ color: #b91c1c;
562
+ }
563
+ .cip-icon-btn {
564
+ width: 26px;
565
+ height: 26px;
566
+ padding: 0;
567
+ border: none;
568
+ background: transparent;
569
+ border-radius: 6px;
570
+ color: #94a3b8;
571
+ font-size: 14px;
572
+ cursor: pointer;
573
+ }
574
+ .cip-icon-btn:hover {
575
+ background: #f1f5f9;
576
+ color: #475569;
577
+ }
578
+ .cip-icon-btn-sm {
579
+ width: 22px;
580
+ height: 22px;
581
+ font-size: 12px;
582
+ }
583
+
584
+ /* 变量气泡卡:浮在 iframe 上方,右上角伸出,尾巴指向按钮 */
585
+ .cip-var-panel {
586
+ position: absolute;
587
+ top: 46px;
588
+ right: 12px;
589
+ z-index: 5;
590
+ width: min(360px, calc(100% - 24px));
591
+ max-height: min(60vh, 480px);
592
+ display: flex;
593
+ flex-direction: column;
594
+ background: #fff;
595
+ border: 1px solid #e2e8f0;
596
+ border-radius: 12px;
597
+ box-shadow: 0 10px 32px rgba(15, 23, 42, 0.14),
598
+ 0 2px 6px rgba(15, 23, 42, 0.06);
599
+ overflow: hidden;
600
+ animation: cip-pop-in 0.16s ease-out;
601
+ }
602
+ @keyframes cip-pop-in {
603
+ from {
604
+ opacity: 0;
605
+ transform: translateY(-4px) scale(0.98);
606
+ }
607
+ to {
608
+ opacity: 1;
609
+ transform: translateY(0) scale(1);
610
+ }
611
+ }
612
+ .cip-var-panel-head {
613
+ display: flex;
614
+ align-items: center;
615
+ justify-content: space-between;
616
+ padding: 10px 12px;
617
+ border-bottom: 1px solid #f1f5f9;
618
+ }
619
+ .cip-var-panel-title {
620
+ font-size: 12px;
621
+ font-weight: 600;
622
+ color: #334155;
623
+ }
624
+ .cip-var-panel-actions {
625
+ display: flex;
626
+ align-items: center;
627
+ gap: 4px;
628
+ }
629
+ .cip-link-btn {
630
+ padding: 2px 6px;
631
+ border: none;
632
+ background: transparent;
633
+ color: #4338ca;
634
+ font-size: 12px;
635
+ cursor: pointer;
636
+ border-radius: 4px;
637
+ }
638
+ .cip-link-btn:hover {
639
+ background: #eef2ff;
640
+ }
641
+ .cip-var-warn {
642
+ padding: 6px 12px;
643
+ background: #fef2f2;
644
+ color: #b91c1c;
645
+ font-size: 11px;
646
+ border-bottom: 1px solid #fee2e2;
647
+ }
648
+ .cip-var-body {
649
+ flex: 1;
650
+ overflow-y: auto;
651
+ padding: 8px 12px 4px;
652
+ }
653
+ .cip-var-row {
654
+ padding: 8px 0;
655
+ border-bottom: 1px dashed #f1f5f9;
656
+ }
657
+ .cip-var-row:last-child {
658
+ border-bottom: none;
659
+ }
660
+ .cip-var-label {
661
+ display: flex;
662
+ align-items: center;
663
+ gap: 4px;
664
+ margin-bottom: 4px;
665
+ font-size: 12px;
666
+ color: #475569;
667
+ }
668
+ .cip-var-required {
669
+ color: #ef4444;
670
+ }
671
+ .cip-var-type {
672
+ margin-left: auto;
673
+ padding: 0 6px;
674
+ background: #f1f5f9;
675
+ color: #94a3b8;
676
+ border-radius: 999px;
677
+ font-size: 10px;
678
+ line-height: 16px;
679
+ }
680
+ .cip-input,
681
+ .cip-textarea {
682
+ width: 100%;
683
+ padding: 6px 8px;
684
+ border: 1px solid #e2e8f0;
685
+ border-radius: 6px;
686
+ background: #f8fafc;
687
+ color: #0f172a;
688
+ font-family: inherit;
689
+ font-size: 12px;
690
+ line-height: 1.5;
691
+ outline: none;
692
+ transition: border-color 0.15s, background 0.15s;
693
+ }
694
+ .cip-input:focus,
695
+ .cip-textarea:focus {
696
+ border-color: #6366f1;
697
+ background: #fff;
698
+ }
699
+ .cip-textarea {
700
+ resize: vertical;
701
+ min-height: 60px;
702
+ font-family: 'Menlo', 'Consolas', monospace;
703
+ }
704
+ .cip-switch {
705
+ display: inline-flex;
706
+ align-items: center;
707
+ gap: 6px;
708
+ font-size: 12px;
709
+ color: #475569;
710
+ cursor: pointer;
711
+ }
712
+ .cip-var-panel-foot {
713
+ padding: 8px 12px;
714
+ border-top: 1px solid #f1f5f9;
715
+ background: #f8fafc;
716
+ color: #94a3b8;
717
+ font-size: 11px;
718
+ }
719
+
720
+ /* iframe 主体 */
721
+ .cip-body {
722
+ flex: 1;
723
+ min-height: 0;
724
+ position: relative;
725
+ background: #f8fafc;
726
+ }
727
+ .cip-iframe {
728
+ display: block;
729
+ width: 100%;
730
+ height: 100%;
731
+ border: none;
732
+ background: #fff;
733
+ }
734
+ .cip-loading {
735
+ position: absolute;
736
+ inset: 0;
737
+ z-index: 1;
738
+ display: flex;
739
+ flex-direction: column;
740
+ align-items: center;
741
+ justify-content: center;
742
+ gap: 12px;
743
+ background: #f8fafc;
744
+ }
745
+ .cip-spinner {
746
+ position: relative;
747
+ width: 36px;
748
+ height: 36px;
749
+ }
750
+ .cip-spinner span {
751
+ position: absolute;
752
+ inset: 0;
753
+ border-radius: 50%;
754
+ border: 3px solid transparent;
755
+ border-top-color: #6366f1;
756
+ animation: cip-spin 1s linear infinite;
757
+ }
758
+ .cip-spinner span:nth-child(2) {
759
+ inset: 6px;
760
+ border-top-color: #a855f7;
761
+ animation-duration: 1.4s;
762
+ animation-direction: reverse;
763
+ }
764
+ .cip-loading-text {
765
+ color: #94a3b8;
766
+ font-size: 12px;
767
+ }
768
+ @keyframes cip-spin {
769
+ to {
770
+ transform: rotate(360deg);
771
+ }
772
+ }
773
+ </style>