femo-plugin 1.0.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 (166) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +627 -0
  3. package/femo2host/__init__.py +4 -0
  4. package/femo2host/femoToolcall/chronica.py +156 -0
  5. package/femo2host/femoToolcall/femo-chat.mjs +69 -0
  6. package/femo2host/femoToolcall/femo_debugger.py +1515 -0
  7. package/femo2host/femo_api.py +437 -0
  8. package/femo2host/femo_gen_api.jsx +77 -0
  9. package/femoBridges/ContextExample.py +555 -0
  10. package/femoBridges/MemoryExample.py +163 -0
  11. package/femoBridges/__init__.py +1 -0
  12. package/femoBridges/getDir/get_dir.py +56 -0
  13. package/femoBridges/getDir//344/275/240/345/217/257/344/273/245/350/256/276/345/256/232/344/273/273/346/204/217/346/226/207/344/273/266/345/244/271/344/270/272/347/224/250/346/210/267/346/225/260/346/215/256/346/226/207/344/273/266/345/244/271.txt +10 -0
  14. package/femoBridges/llmBridge.py +247 -0
  15. package/femoBridges/llmProviders.py +308 -0
  16. package/femoCompiler/FEMO_CLIrenderer.py +198 -0
  17. package/femoCompiler/FEMO_config.py +35 -0
  18. package/femoCompiler/FEMO_errors.py +278 -0
  19. package/femoCompiler/FEMO_interpreter.py +163 -0
  20. package/femoCompiler/FEMO_normalizer.py +396 -0
  21. package/femoCompiler/FEMO_parser.py +2468 -0
  22. package/femoCompiler/FEMO_runtime.py +3630 -0
  23. package/femoCompiler/FEMO_scope_resolver.py +209 -0
  24. package/femoCompiler/__init__.py +1 -0
  25. package/femoCompiler/actor_resolver.py +86 -0
  26. package/femoCompiler/block_collector.py +441 -0
  27. package/femoCompiler/db_utils.py +485 -0
  28. package/femoCompiler/femoAsync.py +401 -0
  29. package/femoCompiler/host_manifest.py +68 -0
  30. package/femoCompiler/job_manager.py +767 -0
  31. package/femoCompiler/protocol.py +126 -0
  32. package/femoCompiler/save_dialog.py +402 -0
  33. package/femoCompiler/task_world.py +544 -0
  34. package/femoCompiler/vars/__init__.py +19 -0
  35. package/femoCompiler/vars/checkpoint.py +113 -0
  36. package/femoCompiler/vars/env.py +686 -0
  37. package/femoCompiler/vars/evaluator.py +567 -0
  38. package/femoCompiler/vars/join.py +303 -0
  39. package/femoCompiler/vars/merge.py +157 -0
  40. package/femoCompiler/vars/model.py +245 -0
  41. package/femoExamples/AI/345/211/252/350/247/206/351/242/221/AI/345/211/252/350/247/206/351/242/221.femo +192 -0
  42. package/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
  43. package/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
  44. package/femoExamples/LuxFiat/luxfiat.femo +38 -0
  45. package/femoExamples/LuxFiat/wait.py +29 -0
  46. package/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
  47. package/femoExamples/discussion.femo +70 -0
  48. package/femoExamples/goal-mode.femo +23 -0
  49. package/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
  50. package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
  51. package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
  52. package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210.femo +544 -0
  53. package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
  54. package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
  55. package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225-/350/217/234/345/270/202/345/234/272/345/261/200.femo +348 -0
  56. package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +392 -0
  57. package/femoGen/document_ch.html +2352 -0
  58. package/femoGen/document_en.html +2279 -0
  59. package/femoGen/index.html +19 -0
  60. package/femoGen/intro_ch.html +942 -0
  61. package/femoGen/intro_en.html +932 -0
  62. package/femoGen/package-lock.json +1698 -0
  63. package/femoGen/package.json +19 -0
  64. package/femoGen/public/character_need.ttf +0 -0
  65. package/femoGen/public/favicon.ico +0 -0
  66. package/femoGen/public/femo-logo-slogan.svg +83 -0
  67. package/femoGen/public/femo-logo.svg +55 -0
  68. package/femoGen/public/logo-fullsize.ico +0 -0
  69. package/femoGen/src/FemoWorAuto.jsx +5444 -0
  70. package/femoGen/src/actionModal.jsx +358 -0
  71. package/femoGen/src/bubbleOverlay.jsx +701 -0
  72. package/femoGen/src/canvasNodes.jsx +608 -0
  73. package/femoGen/src/common.jsx +715 -0
  74. package/femoGen/src/debugPanel.jsx +530 -0
  75. package/femoGen/src/faIcons.jsx +84 -0
  76. package/femoGen/src/femoDiagnostics.js +122 -0
  77. package/femoGen/src/femoFileList.jsx +357 -0
  78. package/femoGen/src/femoGenerator.jsx +1198 -0
  79. package/femoGen/src/femoLog.js +107 -0
  80. package/femoGen/src/femoParser.jsx +2255 -0
  81. package/femoGen/src/femoPreview.jsx +297 -0
  82. package/femoGen/src/graphBuilder.jsx +358 -0
  83. package/femoGen/src/libPanel.jsx +519 -0
  84. package/femoGen/src/main.jsx +22 -0
  85. package/femoGen/src/mobileView.jsx +2796 -0
  86. package/femoGen/src/projectPanel.jsx +529 -0
  87. package/femoGen/src/soulModal.jsx +162 -0
  88. package/femoGen/src/styles/font.css +10 -0
  89. package/femoGen/src/themes.js +465 -0
  90. package/femoGen/src/useCanvasInteraction.jsx +319 -0
  91. package/femoGen/vite.config.js +28 -0
  92. package/femoGen//347/222/207/345/255/230/346/247/221.txt +15 -0
  93. package/hostAdapter/dshAdapter/README.md +68 -0
  94. package/hostAdapter/dshAdapter/build.mjs +75 -0
  95. package/hostAdapter/dshAdapter/client/client-ui/chat-node.tsx +339 -0
  96. package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +997 -0
  97. package/hostAdapter/dshAdapter/client/client-ui/editor-page.tsx +726 -0
  98. package/hostAdapter/dshAdapter/client/client-ui/editor-view.tsx +88 -0
  99. package/hostAdapter/dshAdapter/client/client-ui/femo-stream-live.tsx +264 -0
  100. package/hostAdapter/dshAdapter/client/client-ui/proj2/frame-router.ts +282 -0
  101. package/hostAdapter/dshAdapter/client/client-ui/proj2/index.ts +44 -0
  102. package/hostAdapter/dshAdapter/client/client-ui/proj2/ledger.ts +329 -0
  103. package/hostAdapter/dshAdapter/client/client-ui/proj2/turn-view.tsx +211 -0
  104. package/hostAdapter/dshAdapter/client/client-ui/proj2/window-id.ts +28 -0
  105. package/hostAdapter/dshAdapter/client/client-ui/stream-store.ts +550 -0
  106. package/hostAdapter/dshAdapter/client/client-ui/styles.ts +144 -0
  107. package/hostAdapter/dshAdapter/client/client-ui/view-button.tsx +572 -0
  108. package/hostAdapter/dshAdapter/client/client-ui/view-state.ts +61 -0
  109. package/hostAdapter/dshAdapter/client/client.tsx +518 -0
  110. package/hostAdapter/dshAdapter/client/fa-icons.tsx +112 -0
  111. package/hostAdapter/dshAdapter/client/femo-reasoning-row.tsx +103 -0
  112. package/hostAdapter/dshAdapter/client/lineage-fork-native.jsx +624 -0
  113. package/hostAdapter/dshAdapter/client/lineage-fork.jsx +585 -0
  114. package/hostAdapter/dshAdapter/cordis.patch.yml +8 -0
  115. package/hostAdapter/dshAdapter/dshPatch/DSH-0.1.2-fork/344/277/256/346/224/271/351/234/200/346/261/202.md +184 -0
  116. package/hostAdapter/dshAdapter/dshPatch/MEOW_MODIFICATIONS.md +3105 -0
  117. package/hostAdapter/dshAdapter/dshPatch/patch-dsh-0.1.2-alpha.1.py +313 -0
  118. package/hostAdapter/dshAdapter/host/api-retry.ts +141 -0
  119. package/hostAdapter/dshAdapter/host/bridge.ts +224 -0
  120. package/hostAdapter/dshAdapter/host/config.ts +124 -0
  121. package/hostAdapter/dshAdapter/host/debug-log.ts +29 -0
  122. package/hostAdapter/dshAdapter/host/debug-run.ts +793 -0
  123. package/hostAdapter/dshAdapter/host/diag-feed.ts +56 -0
  124. package/hostAdapter/dshAdapter/host/engine-events.ts +891 -0
  125. package/hostAdapter/dshAdapter/host/engine-transcript.ts +122 -0
  126. package/hostAdapter/dshAdapter/host/femo-files.ts +210 -0
  127. package/hostAdapter/dshAdapter/host/god-mirror.ts +234 -0
  128. package/hostAdapter/dshAdapter/host/host-log.ts +101 -0
  129. package/hostAdapter/dshAdapter/host/http.ts +66 -0
  130. package/hostAdapter/dshAdapter/host/index.ts +633 -0
  131. package/hostAdapter/dshAdapter/host/list-cache.ts +183 -0
  132. package/hostAdapter/dshAdapter/host/main-actor.ts +853 -0
  133. package/hostAdapter/dshAdapter/host/main-delivery-queue.ts +115 -0
  134. package/hostAdapter/dshAdapter/host/native-state.ts +21 -0
  135. package/hostAdapter/dshAdapter/host/node-retry.ts +246 -0
  136. package/hostAdapter/dshAdapter/host/persona.ts +146 -0
  137. package/hostAdapter/dshAdapter/host/pre-step-gate.ts +95 -0
  138. package/hostAdapter/dshAdapter/host/proj-trace.ts +49 -0
  139. package/hostAdapter/dshAdapter/host/projection-input.ts +238 -0
  140. package/hostAdapter/dshAdapter/host/projection.ts +742 -0
  141. package/hostAdapter/dshAdapter/host/routes.ts +1196 -0
  142. package/hostAdapter/dshAdapter/host/run-control.ts +641 -0
  143. package/hostAdapter/dshAdapter/host/safe-steer.ts +33 -0
  144. package/hostAdapter/dshAdapter/host/section-gate.ts +108 -0
  145. package/hostAdapter/dshAdapter/host/session-events.ts +45 -0
  146. package/hostAdapter/dshAdapter/host/state-files.ts +301 -0
  147. package/hostAdapter/dshAdapter/host/stream-frames.ts +229 -0
  148. package/hostAdapter/dshAdapter/host/subagent-native.ts +997 -0
  149. package/hostAdapter/dshAdapter/host/subagent.ts +1205 -0
  150. package/hostAdapter/dshAdapter/host/tools.ts +486 -0
  151. package/hostAdapter/dshAdapter/host/windowing-native.ts +294 -0
  152. package/hostAdapter/dshAdapter/host.manifest.json +6 -0
  153. package/hostAdapter/dshAdapter/lib/client.js +19161 -0
  154. package/hostAdapter/dshAdapter/lib/client.js.map +7 -0
  155. package/hostAdapter/dshAdapter/lib/index.js +8173 -0
  156. package/hostAdapter/dshAdapter/lib/index.js.map +7 -0
  157. package/hostAdapter/dshAdapter/package-lock.json +500 -0
  158. package/hostAdapter/dshAdapter/package.json +55 -0
  159. package/hostAdapter/dshAdapter/pnpm-lock.yaml +596 -0
  160. package/hostAdapter/dshAdapter/pnpm-workspace.yaml +2 -0
  161. package/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
  162. package/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
  163. package/hostAdapter/dshAdapter/tsconfig.host.json +9 -0
  164. package/hostAdapter/dshAdapter/tsconfig.json +21 -0
  165. package/package.json +40 -0
  166. package//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
@@ -0,0 +1,701 @@
1
+ // ═══════════════════════════════════════════════════════════════
2
+ // ═══ bubbleOverlay.jsx ═══
3
+ // ═══════════════════════════════════════════════════════════════
4
+
5
+ import React, { useState, useEffect, useLayoutEffect, useRef, useCallback } from 'react';
6
+ import { ti, inp, btnP } from './common';
7
+
8
+ // ── func/assign 气泡的 In/Out 面板(2026-09-07)──
9
+ // 运行值来自 func_result/assign_result 事件的 input/output 字段(后端
10
+ // FEMO_runtime 落在 ns.ins/ns.outs);未运行时回退显示 action 静态声明名。
11
+
12
+ // 从 action 静态声明文本(inMappings/outVars)提取变量名,作未运行时的回退。
13
+ // 兼容三种写法:逗号列表(`a, b, c`)、映射行(`local = @day`)、
14
+ // 赋值表达式(`count += 1` / `dict.@actor = {}`)与带注解的 out(`x(dropdown, ...)`)。
15
+ function parseDeclaredNames(raw) {
16
+ if (!raw || typeof raw !== 'string') return [];
17
+ const names = [];
18
+ for (const rawLine of raw.split('\n')) {
19
+ const line = rawLine.trim();
20
+ if (!line || line.startsWith('#')) continue;
21
+ const items = /[=(]/.test(line)
22
+ ? [line]
23
+ : line.split(',').map((s) => s.trim()).filter(Boolean);
24
+ for (const item of items) {
25
+ const m = item.match(/^[\w$\u4e00-\u9fff.@]+/);
26
+ if (m) names.push(m[0]);
27
+ }
28
+ }
29
+ return names;
30
+ }
31
+
32
+ const VAR_VALUE_MAX = 1500;
33
+ function formatVarValue(v) {
34
+ let s;
35
+ if (v === null) s = 'null';
36
+ else if (v === undefined) s = '—';
37
+ else if (typeof v === 'string') s = v;
38
+ else {
39
+ try { s = JSON.stringify(v, null, 2) ?? String(v); }
40
+ catch { s = String(v); }
41
+ }
42
+ if (s === '') s = '""';
43
+ return s.length > VAR_VALUE_MAX ? s.slice(0, VAR_VALUE_MAX) + ' …' : s;
44
+ }
45
+
46
+ // in/out 区的行:entries=运行值(名字→值),names=静态声明名(未运行的回退)
47
+ function VarRows({ entries, names }) {
48
+ const hasEntries = !!entries?.length;
49
+ const hasNames = !!names?.length;
50
+ if (!hasEntries && !hasNames) {
51
+ return (
52
+ <div style={{ fontSize: 11.5, color: 'var(--femo-text-3)' }}>(无)</div>
53
+ );
54
+ }
55
+ const rows = hasEntries
56
+ ? entries.map(([k, v]) => ({ name: k, value: formatVarValue(v) }))
57
+ : names.map((n) => ({ name: n, value: '—' }));
58
+ return (
59
+ <div>
60
+ {rows.map((r, i) => (
61
+ <div key={i} style={{ display: 'flex', gap: 8, alignItems: 'flex-start', marginBottom: 4 }}>
62
+ <span
63
+ style={{
64
+ minWidth: 90,
65
+ maxWidth: '40%',
66
+ fontFamily: 'var(--femo-font-mono)',
67
+ fontSize: 12,
68
+ fontWeight: 700,
69
+ color: 'var(--femo-text-2)',
70
+ flexShrink: 0,
71
+ wordBreak: 'break-all',
72
+ }}
73
+ >
74
+ {r.name}:
75
+ </span>
76
+ <span
77
+ style={{
78
+ fontFamily: 'var(--femo-font-mono)',
79
+ fontSize: 12,
80
+ color: 'var(--femo-text-1)',
81
+ whiteSpace: 'pre-wrap',
82
+ wordBreak: 'break-word',
83
+ flex: 1,
84
+ }}
85
+ >
86
+ {r.value}
87
+ </span>
88
+ </div>
89
+ ))}
90
+ </div>
91
+ );
92
+ }
93
+
94
+ // func/assign 浮层的 in/out 面板(2026-09-07):上半区 in、分割横线、下半区 out。
95
+ // 运行值来自 func_result/assign_result 事件的 input/output(ns.ins/ns.outs);
96
+ // 未运行回退显示 action 静态声明名。
97
+ function FuncAssignSection({ ns, action, accent }) {
98
+ const insEntries = ns.ins ? Object.entries(ns.ins) : null;
99
+ const outsEntries = ns.outs ? Object.entries(ns.outs) : null;
100
+ const declaredIn = insEntries?.length ? null : parseDeclaredNames(action?.inMappings);
101
+ const declaredOut = outsEntries?.length ? null : parseDeclaredNames(action?.outVars);
102
+ // func 未声明 out 时后端把返回值 repr 进 output 字符串——兜底展示在 out 区
103
+ const showReturnValue =
104
+ !outsEntries?.length && typeof ns.output === 'string' && ns.output.length > 0;
105
+ const isRunning = ns.status === 'running';
106
+ const nothing =
107
+ !insEntries?.length && !outsEntries?.length &&
108
+ !declaredIn.length && !declaredOut.length && !showReturnValue && !isRunning;
109
+ if (nothing) return null;
110
+
111
+ const labelChip = {
112
+ display: 'inline-block',
113
+ background: accent + '18',
114
+ color: accent,
115
+ borderRadius: 'var(--femo-radius-sm)',
116
+ padding: '1px 10px',
117
+ fontSize: 11,
118
+ fontWeight: 800,
119
+ fontFamily: 'var(--femo-font-mono)',
120
+ marginBottom: 6,
121
+ };
122
+ const fallbackHintStyle = (
123
+ <span style={{ fontWeight: 400, fontSize: 10, marginLeft: 6, color: 'var(--femo-text-3)' }}>
124
+ (未运行,仅显示声明名)
125
+ </span>
126
+ );
127
+ const inFallback = !insEntries?.length && declaredIn.length > 0;
128
+ const outFallback = !outsEntries?.length && declaredOut.length > 0;
129
+
130
+ return (
131
+ <div style={{ marginBottom: 12 }}>
132
+ {/* ── in ── */}
133
+ <div>
134
+ <span style={labelChip}>in</span>
135
+ {inFallback && fallbackHintStyle}
136
+ <VarRows entries={insEntries} names={declaredIn} />
137
+ </div>
138
+
139
+ {/* ── 分割横线 ── */}
140
+ <div
141
+ style={{
142
+ height: 1,
143
+ background: 'var(--femo-border)',
144
+ margin: '10px 0 12px',
145
+ }}
146
+ />
147
+
148
+ {/* ── out ── */}
149
+ <div>
150
+ <span style={labelChip}>out</span>
151
+ {outFallback && fallbackHintStyle}
152
+ <VarRows entries={outsEntries} names={declaredOut} />
153
+ {showReturnValue && (
154
+ <div
155
+ style={{
156
+ fontFamily: 'var(--femo-font-mono)',
157
+ fontSize: 12,
158
+ color: 'var(--femo-text-1)',
159
+ whiteSpace: 'pre-wrap',
160
+ wordBreak: 'break-word',
161
+ }}
162
+ >
163
+ {formatVarValue(ns.output)}
164
+ </div>
165
+ )}
166
+ </div>
167
+
168
+ {isRunning && (
169
+ <div style={{ marginTop: 8, fontSize: 11.5, color: 'var(--femo-text-3)', fontWeight: 700 }}>
170
+ ⏳ 运行中…
171
+ </div>
172
+ )}
173
+ </div>
174
+ );
175
+ }
176
+
177
+ function BubbleSection({ title, content, streaming }) {
178
+ if (!content && !streaming) return null;
179
+ return (
180
+ <div style={{ marginBottom: 12 }}>
181
+ {title && (
182
+ <div
183
+ style={{
184
+ fontSize: 11,
185
+ fontWeight: 700,
186
+ color: 'var(--femo-text-3)',
187
+ marginBottom: 4,
188
+ }}
189
+ >
190
+ {title}
191
+ </div>
192
+ )}
193
+ <div
194
+ style={{
195
+ fontSize: 12.5,
196
+ color: 'var(--femo-text-1)',
197
+ whiteSpace: 'pre-wrap',
198
+ lineHeight: 1.6,
199
+ maxHeight: streaming ? 'none' : 'auto',
200
+ }}
201
+ >
202
+ {content}
203
+ {streaming && <span className="streaming-cursor">|</span>}
204
+ </div>
205
+ </div>
206
+ );
207
+ }
208
+
209
+ function HumanInputSection({ nodeId, onSubmit, outVars, inputError }) {
210
+ const [chatText, setChatText] = useState('');
211
+ const [dragOver, setDragOver] = useState(false);
212
+ const [varValues, setVarValues] = useState({});
213
+
214
+ const handleVarChange = (varName, value) => {
215
+ setVarValues((prev) => ({ ...prev, [varName]: value }));
216
+ };
217
+
218
+ const handleSend = async () => {
219
+ const hasChat = chatText.trim();
220
+ const hasVars = Object.values(varValues).some((v) => v && v.trim());
221
+ if (!hasChat && !hasVars) return;
222
+ const assignments = {};
223
+ for (const [k, v] of Object.entries(varValues)) {
224
+ if (v && v.trim()) {
225
+ assignments[k] = v.trim();
226
+ }
227
+ }
228
+ console.log('[HumanInputSection] handleSend:', { nodeId, chatText: chatText.trim(), assignments });
229
+ // 提交失败(onSubmit 返回 false,气泡内会显示红色错误条)时保留输入,
230
+ // 不清空——用户不必重打一遍。
231
+ const ok = await onSubmit(nodeId, chatText.trim(), assignments);
232
+ if (ok !== false) {
233
+ setChatText('');
234
+ setVarValues({});
235
+ }
236
+ };
237
+
238
+ const handleDrop = (e) => {
239
+ e.preventDefault();
240
+ setDragOver(false);
241
+ const files = Array.from(e.dataTransfer.files);
242
+ if (!files.length) return;
243
+ let combined = chatText;
244
+ let readCount = 0;
245
+ files.forEach((file) => {
246
+ const reader = new FileReader();
247
+ reader.onload = (ev) => {
248
+ const content = ev.target.result;
249
+ if (combined.length > 0 && !combined.endsWith('\n')) combined += '\n';
250
+ combined += `\n====== ${file.name} ======\n${content}\n`;
251
+ readCount++;
252
+ if (readCount === files.length) {
253
+ setChatText(combined);
254
+ }
255
+ };
256
+ reader.onerror = () => {
257
+ readCount++;
258
+ if (readCount === files.length) {
259
+ setChatText(combined);
260
+ }
261
+ };
262
+ reader.readAsText(file);
263
+ });
264
+ };
265
+
266
+ const vars = Array.isArray(outVars) ? outVars : [];
267
+ const hasVars = vars.length > 0;
268
+ const VAR_INPUT_WIDTH = 120;
269
+
270
+ return (
271
+ <div style={{ marginTop: 8, flexShrink: 0 }}>
272
+ <div
273
+ style={{
274
+ fontSize: 11,
275
+ fontWeight: 700,
276
+ color: 'var(--femo-warning)',
277
+ marginBottom: 4,
278
+ }}
279
+ >
280
+ ⏳ 等待人类输入
281
+ </div>
282
+ {inputError && (
283
+ <div
284
+ style={{
285
+ fontSize: 11,
286
+ color: 'var(--femo-danger-strong)',
287
+ background: 'var(--femo-danger-soft)',
288
+ border: 'var(--femo-border-w) solid var(--femo-danger-border)',
289
+ borderRadius: 'var(--femo-radius-sm)',
290
+ padding: '6px 8px',
291
+ marginBottom: 6,
292
+ whiteSpace: 'pre-wrap',
293
+ }}
294
+ >
295
+ ❌ 输入被拒绝:{inputError}
296
+ </div>
297
+ )}
298
+ <div
299
+ onDragOver={(e) => { e.preventDefault(); setDragOver(true); }}
300
+ onDragLeave={() => setDragOver(false)}
301
+ onDrop={handleDrop}
302
+ style={{
303
+ border: dragOver ? 'var(--femo-border-w-selected) dashed var(--femo-warning)' : 'var(--femo-border-w-selected) solid transparent',
304
+ borderRadius: 'var(--femo-radius-md)',
305
+ transition: 'border 0.15s',
306
+ }}
307
+ >
308
+ <textarea
309
+ data-field="chatText"
310
+ value={chatText}
311
+ onChange={(e) => setChatText(e.target.value)}
312
+ placeholder="输入回复,或拖拽文件到此处..."
313
+ rows={4}
314
+ style={{
315
+ ...inp,
316
+ resize: 'vertical',
317
+ width: '100%',
318
+ boxSizing: 'border-box',
319
+ }}
320
+ onKeyDown={(e) => {
321
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
322
+ e.preventDefault();
323
+ handleSend();
324
+ }
325
+ }}
326
+ />
327
+ </div>
328
+ <div
329
+ style={{
330
+ display: 'flex',
331
+ alignItems: 'center',
332
+ gap: 8,
333
+ marginTop: 6,
334
+ flexWrap: 'wrap',
335
+ }}
336
+ >
337
+ <button style={{ ...btnP }} onClick={handleSend}>
338
+ 发送
339
+ </button>
340
+ {hasVars && vars.map((varName) => (
341
+ <div
342
+ key={varName}
343
+ style={{
344
+ display: 'flex',
345
+ alignItems: 'center',
346
+ gap: 4,
347
+ }}
348
+ >
349
+ <span
350
+ style={{
351
+ fontSize: 11,
352
+ fontWeight: 700,
353
+ color: 'var(--femo-text-3)',
354
+ fontFamily: 'var(--femo-font-mono)',
355
+ whiteSpace: 'nowrap',
356
+ }}
357
+ >
358
+ {varName}:
359
+ </span>
360
+ <input
361
+ data-var={varName}
362
+ value={varValues[varName] || ''}
363
+ onChange={(e) => handleVarChange(varName, e.target.value)}
364
+ placeholder="值/+=1/add(@x)"
365
+ style={{
366
+ ...inp,
367
+ width: `${VAR_INPUT_WIDTH}px`,
368
+ fontSize: 12,
369
+ padding: '3px 6px',
370
+ flexShrink: 0,
371
+ }}
372
+ onKeyDown={(e) => {
373
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
374
+ e.preventDefault();
375
+ handleSend();
376
+ }
377
+ }}
378
+ />
379
+ </div>
380
+ ))}
381
+ </div>
382
+ </div>
383
+ );
384
+ }
385
+
386
+ function BubbleOverlay({ bubbleOverlay, nodes, nodeStates, humanWaits, actionStore, onClose, submitHumanInput }) {
387
+ if (!bubbleOverlay) return null;
388
+ const node = nodes.find((n) => n.id === bubbleOverlay.nodeId);
389
+ if (!node || node.type !== 'action') return null;
390
+ const action = actionStore?.find(a => a.id === node.actionId);
391
+ const ns = nodeStates[node.id] || {};
392
+ // 常驻人类等待(par 并发修复 2026-09-07):来自独立账本 humanWaits。
393
+ // 同一 mind 画布节点被 par 多实例(AI+人类混合)并行时,所有实例事件同名,
394
+ // AI 实例的 node_start/ai_token 会把共享 nodeStates[nodeId] 的 status/type
395
+ // 覆盖成 ai_streaming——旧实现按 ns.status 渲染输入框,导致人类输入框
396
+ // 「闪一下就被 AI 气泡取代」。账本里的等待只有 human_done/提交成功/本场
397
+ // 终态才撤下,AI 实例事件碰不到 → 输入面板常驻。
398
+ const hw = humanWaits?.[node.id] || null;
399
+ // mind 节点按运行时 node_type 判断(node_start 事件写入 ns.type):
400
+ // 执行者运行时才确定(可能是变量赋值),静态 executorType 无法预判;
401
+ // 未运行(ns.type 空)时回退到静态 executorType。
402
+ const runType = ns.type || action?.executorType;
403
+ const isAI = runType === 'ai';
404
+ const isHuman = runType === 'human';
405
+ const isFuncAssign = runType === 'func' || runType === 'assign';
406
+ const isStreaming = ns.status === 'ai_streaming';
407
+ const c = ti(action?.executorType)?.c || 'var(--femo-neutral)';
408
+ // AI 活动区:有人等待时仅在 AI 实例真在跑/刚跑完(ai_streaming/ai_done)
409
+ // 显示——人类输入第一优先,也不给静态 ai 类型渲染空 AI 区;无人等待时
410
+ // 保持旧口径(含静态 executorType 回退与「(等待输出)」占位)。
411
+ const aiLive = ns.status === 'ai_streaming' || ns.status === 'ai_done';
412
+ const showAI = hw ? aiLive : isAI;
413
+ const scrollRef = useRef(null);
414
+ const userScrolledUpRef = useRef(false);
415
+
416
+ // 用户滚动监听:判断是否在底部
417
+ const handleScroll = useCallback(() => {
418
+ const el = scrollRef.current;
419
+ if (!el) return;
420
+ const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 50;
421
+ userScrolledUpRef.current = !atBottom;
422
+ }, []);
423
+
424
+ // 自动滚动:仅当用户没有主动上滚时才跟随流式输出;
425
+ // 有人等待时不跟滚(常驻人类卡置顶,AI 流式不抢视图——输入是第一优先级)
426
+ useEffect(() => {
427
+ const el = scrollRef.current;
428
+ if (!el || userScrolledUpRef.current || hw) return;
429
+ el.scrollTop = el.scrollHeight;
430
+ }, [ns.streamingText, ns.output, ns.context, hw]);
431
+
432
+ // 浮层弹起时的定位(2026-09-11 用户点名):**一律拉到长文本最底**——此前
433
+ // 「有人等待 → 定位到顶部常驻卡」,人类节点的 prompt/context 一长就得先往下
434
+ // 翻才看得到最新内容;现在统一到底(输入框本就固定在浮层底部,不受滚动影响)。
435
+ // 用 useLayoutEffect:提交后、绘制前定位,弹起时不会先闪一下顶部再跳到底。
436
+ // hw 变化(等待出现/提交完成)同样重定位到底:语义与"跟最新"一致。
437
+ useLayoutEffect(() => {
438
+ userScrolledUpRef.current = false;
439
+ const el = scrollRef.current;
440
+ if (!el) return;
441
+ el.scrollTop = el.scrollHeight;
442
+ }, [bubbleOverlay?.nodeId, hw]);
443
+
444
+ // 人类等待卡内的提示块(showprompt/prompt/context 读独立账本,与 ns 解耦)
445
+ const hwPromptLabel = hw?.showprompt ? '补充说明' : '提示';
446
+
447
+ return (
448
+ <>
449
+ <div
450
+ onClick={onClose}
451
+ style={{
452
+ position: 'fixed',
453
+ inset: 0,
454
+ background: 'var(--femo-mask-soft)',
455
+ zIndex: 2999,
456
+ }}
457
+ />
458
+ <div
459
+ style={{
460
+ position: 'fixed',
461
+ top: '50%',
462
+ left: '50%',
463
+ transform: 'translate(-50%, -50%)',
464
+ width: Math.min(window.innerWidth * 0.6, 640),
465
+ maxHeight: '80vh',
466
+ background: 'var(--femo-surface)',
467
+ borderRadius: 'var(--femo-radius-xl)',
468
+ boxShadow: '0 24px 64px var(--femo-shadow-lg)',
469
+ border: `var(--femo-border-w-selected) solid ${c}`,
470
+ fontFamily: 'var(--femo-font-sans)',
471
+ zIndex: 3000,
472
+ display: 'flex',
473
+ flexDirection: 'column',
474
+ overflow: 'hidden',
475
+ }}
476
+ >
477
+ {/* 关闭按钮行 */}
478
+ <div
479
+ style={{
480
+ display: 'flex',
481
+ justifyContent: 'space-between',
482
+ alignItems: 'center',
483
+ padding: '16px 20px',
484
+ borderBottom: 'var(--femo-border-w) solid var(--femo-border)',
485
+ flexShrink: 0,
486
+ }}
487
+ >
488
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
489
+ <span
490
+ style={{
491
+ background: c + '18',
492
+ color: c,
493
+ borderRadius: 'var(--femo-radius-sm)',
494
+ padding: '2px 8px',
495
+ fontSize: 11,
496
+ fontWeight: 700,
497
+ fontFamily: 'var(--femo-font-mono)',
498
+ }}
499
+ >
500
+ @{action?.executorType || '?'}
501
+ </span>
502
+ <span style={{ fontWeight: 800, color: 'var(--femo-text-1)', fontSize: 16 }}>
503
+ {action?.name || 'Node'}
504
+ </span>
505
+ {hw && (
506
+ <span
507
+ style={{
508
+ background: 'var(--femo-warning-soft)',
509
+ color: 'var(--femo-warning)',
510
+ borderRadius: 'var(--femo-radius-sm)',
511
+ padding: '2px 8px',
512
+ fontSize: 11,
513
+ fontWeight: 700,
514
+ }}
515
+ >
516
+ 📌 等待人类输入
517
+ </span>
518
+ )}
519
+ </div>
520
+ <button
521
+ onClick={(e) => {
522
+ e.stopPropagation();
523
+ onClose();
524
+ }}
525
+ style={{
526
+ background: 'var(--femo-bg-2)',
527
+ border: 'none',
528
+ fontSize: 16,
529
+ cursor: 'pointer',
530
+ color: 'var(--femo-text-2-alt)',
531
+ borderRadius: 'var(--femo-radius-md)',
532
+ width: 32,
533
+ height: 32,
534
+ display: 'flex',
535
+ alignItems: 'center',
536
+ justifyContent: 'center',
537
+ transition: 'background 0.15s',
538
+ }}
539
+ onMouseEnter={(e) => (e.target.style.background = 'var(--femo-bg-hover)')}
540
+ onMouseLeave={(e) => (e.target.style.background = 'var(--femo-bg-2)')}
541
+ >
542
+ ✕
543
+ </button>
544
+ </div>
545
+
546
+ {/* 可滚动内容区域 */}
547
+ <div
548
+ ref={scrollRef}
549
+ onScroll={handleScroll}
550
+ style={{
551
+ flex: 1,
552
+ overflowY: 'auto',
553
+ padding: '16px 20px',
554
+ lineHeight: 1.6,
555
+ fontSize: 13,
556
+ color: 'var(--femo-text-1)',
557
+ }}
558
+ >
559
+ {hw ? (
560
+ <>
561
+ {/* ── 上下文(置顶普通文本,与 AI 节点视图一致)── */}
562
+ {hw.context && (
563
+ <div style={{ whiteSpace: 'pre-wrap', marginBottom: 12 }}>
564
+ {hw.context}
565
+ </div>
566
+ )}
567
+
568
+ {/* ── 常驻人类卡:AI 实例并发输出不顶掉;prompt 独立成卡 ── */}
569
+ <div
570
+ style={{
571
+ marginBottom: 12,
572
+ background: 'var(--femo-warning-soft)',
573
+ border: 'var(--femo-border-w) solid var(--femo-warning)',
574
+ borderRadius: 'var(--femo-radius-md)',
575
+ padding: '10px 12px',
576
+ }}
577
+ >
578
+ <div style={{ fontWeight: 700, color: 'var(--femo-warning)', marginBottom: 6, fontSize: 12 }}>
579
+ ⏳ 等待人类输入{aiLive ? '(AI 并行输出在下方,此卡常驻)' : ''}
580
+ </div>
581
+ {hw.showprompt && (
582
+ <div style={{ marginBottom: hw.prompt ? 10 : 0 }}>
583
+ <div style={{ fontWeight: 700, color: 'var(--femo-warning-strong)', marginBottom: 4 }}>[节点提示]</div>
584
+ <div style={{ whiteSpace: 'pre-wrap' }}>{hw.showprompt}</div>
585
+ </div>
586
+ )}
587
+ {hw.prompt && (
588
+ <div>
589
+ <div style={{ fontWeight: 700, color: 'var(--femo-warning-strong)', marginBottom: 4 }}>[{hwPromptLabel}]</div>
590
+ <div style={{ whiteSpace: 'pre-wrap' }}>{hw.prompt}</div>
591
+ </div>
592
+ )}
593
+ </div>
594
+
595
+ {/* ── AI 实例活动区(下方):par 并发的 AI 分支输出 ── */}
596
+ {showAI && (
597
+ <div>
598
+ <div style={{ fontWeight: 700, marginBottom: 4 }}>
599
+ [{ns.ai_name || 'AI'}]:
600
+ </div>
601
+ {ns.status === 'ai_streaming' ? (
602
+ <div style={{ whiteSpace: 'pre-wrap' }}>
603
+ {ns.streamingText || ''}
604
+ <span className="streaming-cursor">|</span>
605
+ </div>
606
+ ) : (
607
+ <div style={{ whiteSpace: 'pre-wrap' }}>
608
+ {ns.output || '(等待输出)'}
609
+ </div>
610
+ )}
611
+ </div>
612
+ )}
613
+ </>
614
+ ) : (
615
+ <>
616
+ {/* 上下文 */}
617
+ {ns.context && (
618
+ <div style={{ whiteSpace: 'pre-wrap', marginBottom: 12 }}>
619
+ {ns.context}
620
+ </div>
621
+ )}
622
+
623
+ {/* 节点提示(showprompt)—— 仅当存在时显示 */}
624
+ {ns.showprompt && (
625
+ <div style={{ marginBottom: 12, background: 'var(--femo-bg)', padding: '8px 12px', borderRadius: 'var(--femo-radius-md)' }}>
626
+ <div style={{ fontWeight: 700, color: 'var(--femo-text-3)', marginBottom: 4 }}>[节点提示]</div>
627
+ <div style={{ whiteSpace: 'pre-wrap' }}>{ns.showprompt}</div>
628
+ </div>
629
+ )}
630
+
631
+ {/* 人类 prompt(独立显示,与 showprompt 分开) */}
632
+ {isHuman && ns.prompt && !ns.showprompt && (
633
+ <div style={{ marginBottom: 12, background: 'var(--femo-bg)', padding: '8px 12px', borderRadius: 'var(--femo-radius-md)' }}>
634
+ <div style={{ fontWeight: 700, color: 'var(--femo-text-3)', marginBottom: 4 }}>[提示]</div>
635
+ <div style={{ whiteSpace: 'pre-wrap' }}>{ns.prompt}</div>
636
+ </div>
637
+ )}
638
+ {isHuman && ns.prompt && ns.showprompt && (
639
+ <div style={{ marginBottom: 12, background: 'var(--femo-bg)', padding: '8px 12px', borderRadius: 'var(--femo-radius-md)' }}>
640
+ <div style={{ fontWeight: 700, color: 'var(--femo-text-3)', marginBottom: 4 }}>[补充说明]</div>
641
+ <div style={{ whiteSpace: 'pre-wrap' }}>{ns.prompt}</div>
642
+ </div>
643
+ )}
644
+
645
+ {/* notice:公告本体(node_start 存 prompt,notice_done 存 output) */}
646
+ {runType === 'notice' && (ns.output || ns.prompt) && (
647
+ <div style={{ marginBottom: 12, background: 'var(--femo-bg)', padding: '8px 12px', borderRadius: 'var(--femo-radius-md)' }}>
648
+ <div style={{ fontWeight: 700, color: 'var(--femo-text-3)', marginBottom: 4 }}>[公告]</div>
649
+ <div style={{ whiteSpace: 'pre-wrap' }}>{ns.output || ns.prompt}</div>
650
+ </div>
651
+ )}
652
+
653
+ {/* func/assign:in/分割线/out 面板(未运行回退静态声明名) */}
654
+ {isFuncAssign && <FuncAssignSection ns={ns} action={action} accent={c} />}
655
+
656
+ {/* AI 输出区域 */}
657
+ {showAI && (
658
+ <div>
659
+ <div style={{ fontWeight: 700, marginBottom: 4 }}>
660
+ [{ns.ai_name || 'AI'}]:
661
+ </div>
662
+ {isStreaming ? (
663
+ <div style={{ whiteSpace: 'pre-wrap' }}>
664
+ {ns.streamingText || ''}
665
+ <span className="streaming-cursor">|</span>
666
+ </div>
667
+ ) : (
668
+ <div style={{ whiteSpace: 'pre-wrap' }}>
669
+ {ns.output || '(等待输出)'}
670
+ </div>
671
+ )}
672
+ </div>
673
+ )}
674
+ </>
675
+ )}
676
+ </div>
677
+
678
+ {/* 人类输入框(固定在底部):由独立账本驱动——AI 实例事件把 ns 翻成
679
+ ai_streaming 也不再收起输入框;账本为空才回退旧 ns.status 口径 */}
680
+ {(hw || (isHuman && ns.status === 'human_wait')) && (
681
+ <div
682
+ style={{
683
+ flexShrink: 0,
684
+ padding: '12px 20px 20px',
685
+ borderTop: 'var(--femo-border-w) solid var(--femo-border)',
686
+ }}
687
+ >
688
+ <HumanInputSection
689
+ nodeId={node.id}
690
+ onSubmit={submitHumanInput}
691
+ outVars={(hw || ns).outVars || []}
692
+ inputError={(hw || ns).inputError}
693
+ />
694
+ </div>
695
+ )}
696
+ </div>
697
+ </>
698
+ );
699
+ }
700
+
701
+ export { BubbleOverlay, HumanInputSection, BubbleSection };