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,319 @@
1
+ // ═══════════════════════════════════════════════════════════════
2
+ // ═══ useWorkflowRuntime.jsx ═══
3
+ // ═══════════════════════════════════════════════════════════════
4
+
5
+ import { useCallback, useRef, useState } from 'react';
6
+ import { eid, getNodeSize, smartBezier, SPW, SPH, SINK_ONLY } from './common';
7
+
8
+ function useCanvasInteraction({
9
+ cvRef,
10
+ nodesRef,
11
+ setNodes,
12
+ edges,
13
+ setEdges,
14
+ scale,
15
+ setScale,
16
+ pan,
17
+ setPan,
18
+ setSel,
19
+ addNode,
20
+ addModuleNode,
21
+ addSpecialNode,
22
+ addPositionNode,
23
+ lib,
24
+ }) {
25
+ const [drag, setDrag] = useState(null);
26
+ const [conn, setConn] = useState(null);
27
+ const [isPanning, setIsPanning] = useState(false);
28
+ const [panStart, setPanStart] = useState({ x: 0, y: 0, px: 0, py: 0 });
29
+ const isMouseDownRef = useRef(false);
30
+ const isDraggingRef = useRef(false);
31
+ const mouseDownPosRef = useRef({ x: 0, y: 0 });
32
+
33
+ // Node map helper
34
+ const nm = new Map((nodesRef.current || []).map((n) => [n.id, n]));
35
+
36
+ // Convert client coords to canvas coords
37
+ const xy = useCallback(
38
+ (e) => {
39
+ const r = cvRef.current?.getBoundingClientRect();
40
+ if (!r) return [0, 0];
41
+ return [
42
+ (e.clientX - r.left - pan.x) / scale,
43
+ (e.clientY - r.top - pan.y) / scale,
44
+ ];
45
+ },
46
+ [cvRef, pan, scale]
47
+ );
48
+
49
+ // Mouse move handler
50
+ const onMM = useCallback(
51
+ (e) => {
52
+ // 节点拖拽、连线时,无需检查 isMouseDownRef
53
+ if (drag) {
54
+ setNodes((p) => {
55
+ const draggedNode = p.find((n) => n.id === drag.id);
56
+ if (!draggedNode) return p;
57
+ const newX = drag.ox + (e.clientX - drag.sx) / scale;
58
+ const newY = drag.oy + (e.clientY - drag.sy) / scale;
59
+ return p.map((n) => {
60
+ if (n.id === drag.id) {
61
+ return { ...n, x: newX, y: newY };
62
+ }
63
+ // 拖拽 FOR 节点 → 联动 for_out 小圆点
64
+ if (draggedNode.specialType === 'FOR' && n.type === 'for_out' && n.id === draggedNode.forOutNodeId) {
65
+ return { ...n, x: newX + SPW - 22, y: newY + (SPH - 22) / 2 };
66
+ }
67
+ // 拖拽 for_out 小圆点 → 联动 FOR 节点
68
+ if (draggedNode.type === 'for_out' && n.id === draggedNode.forNodeId) {
69
+ return { ...n, x: newX - SPW + 22, y: newY - (SPH - 22) / 2 };
70
+ }
71
+ // par_out 不做任何联动(自由移动)
72
+ // 注意:par_out 不做任何联动,自由移动
73
+ return n;
74
+ });
75
+ });
76
+ return;
77
+ }
78
+ if (conn) {
79
+ const [cx, cy] = xy(e);
80
+ setConn((p) => ({ ...p, mx: cx, my: cy }));
81
+ return;
82
+ }
83
+
84
+ // 画布平移:必须按下鼠标才开始判断
85
+ if (!isMouseDownRef.current) return;
86
+
87
+ if (!isPanning) {
88
+ const dx = e.clientX - mouseDownPosRef.current.x;
89
+ const dy = e.clientY - mouseDownPosRef.current.y;
90
+ if (Math.abs(dx) > 3 || Math.abs(dy) > 3) {
91
+ setIsPanning(true);
92
+ isDraggingRef.current = true;
93
+ }
94
+ return;
95
+ }
96
+ setPan({
97
+ x: panStart.px + e.clientX - panStart.x,
98
+ y: panStart.py + e.clientY - panStart.y,
99
+ });
100
+ },
101
+ [drag, conn, xy, isPanning, panStart, scale]
102
+ );
103
+
104
+ // Wheel handler (zoom/pan)
105
+ const handleWheel = useCallback(
106
+ (e) => {
107
+ e.preventDefault();
108
+ e.stopPropagation();
109
+ e.nativeEvent?.stopImmediatePropagation?.();
110
+
111
+ if (e.ctrlKey || e.metaKey) {
112
+ const rect = cvRef.current?.getBoundingClientRect();
113
+ if (!rect) return;
114
+ const mouseX = e.clientX - rect.left;
115
+ const mouseY = e.clientY - rect.top;
116
+ const worldX = (mouseX - pan.x) / scale;
117
+ const worldY = (mouseY - pan.y) / scale;
118
+ const delta = e.deltaY > 0 ? 0.9 : 1.1;
119
+ const newScale = Math.min(3, Math.max(0.2, scale * delta));
120
+ const newPanX = mouseX - worldX * newScale;
121
+ const newPanY = mouseY - worldY * newScale;
122
+ setScale(newScale);
123
+ setPan({ x: newPanX, y: newPanY });
124
+ } else {
125
+ setPan((prev) => ({
126
+ x: prev.x - e.deltaX,
127
+ y: prev.y - e.deltaY,
128
+ }));
129
+ }
130
+ },
131
+ [scale, pan]
132
+ );
133
+
134
+ // Mouse up handler
135
+ const onMU = useCallback(() => {
136
+ if (isMouseDownRef.current && !isDraggingRef.current) {
137
+ setSel(null);
138
+ }
139
+ setDrag(null);
140
+ setConn(null);
141
+ setIsPanning(false);
142
+ isDraggingRef.current = false;
143
+ isMouseDownRef.current = false;
144
+ }, []);
145
+
146
+ // Canvas mouse down (for panning)
147
+ const onCanvasDown = useCallback(
148
+ (e) => {
149
+ if (!e.target?.dataset?.canvasBg && e.target !== cvRef.current) return;
150
+ if (drag || isPanning || conn) {
151
+ setDrag(null);
152
+ setIsPanning(false);
153
+ setConn(null);
154
+ isDraggingRef.current = false;
155
+ isMouseDownRef.current = false;
156
+ return;
157
+ }
158
+ if (e.button === 0 || e.button === 1) {
159
+ isMouseDownRef.current = true;
160
+ mouseDownPosRef.current = { x: e.clientX, y: e.clientY };
161
+ setPanStart({ x: e.clientX, y: e.clientY, px: pan.x, py: pan.y });
162
+ e.preventDefault();
163
+ }
164
+ },
165
+ [pan, drag, isPanning, conn]
166
+ );
167
+
168
+ // Port handlers
169
+ function handlePortDown(e, nodeId, portDir, portX, portY) {
170
+ const node = nm.get(nodeId);
171
+ if (node?.type === 'special' && SINK_ONLY.has(node.specialType) && portDir !== 'for_out') return;
172
+ const [cx, cy] = xy(e);
173
+ let srcX = portX, srcY = portY;
174
+ if (srcX === undefined || srcY === undefined) {
175
+ const size = getNodeSize(node);
176
+ srcX = node.x + size.w / 2;
177
+ srcY = node.y + size.h / 2;
178
+ }
179
+ setConn({ srcId: nodeId, srcDir: portDir, mx: cx, my: cy, srcX, srcY });
180
+ }
181
+
182
+ function handlePortUp(e, nodeId, portDir) {
183
+ if (!conn) return;
184
+ if (conn.srcId === nodeId) {
185
+ if (!edges.some((ed) => ed.src === nodeId && ed.tgt === nodeId)) {
186
+ setEdges((p) => [
187
+ ...p,
188
+ { id: eid(), src: nodeId, tgt: nodeId, cond: '', isSelfLoop: true },
189
+ ]);
190
+ }
191
+ setConn(null);
192
+ } else {
193
+ if (!edges.some((ed) => ed.src === conn.srcId && ed.tgt === nodeId)) {
194
+ setEdges((p) => [
195
+ ...p,
196
+ { id: eid(), src: conn.srcId, tgt: nodeId, cond: '' },
197
+ ]);
198
+ }
199
+ setConn(null);
200
+ }
201
+ }
202
+
203
+ function handleBodyMouseUp(e, nodeId) {
204
+ if (conn && conn.srcId !== nodeId) {
205
+ if (!edges.some((ed) => ed.src === conn.srcId && ed.tgt === nodeId)) {
206
+ setEdges((p) => [
207
+ ...p,
208
+ { id: eid(), src: conn.srcId, tgt: nodeId, cond: '' },
209
+ ]);
210
+ }
211
+ setConn(null);
212
+ }
213
+ }
214
+
215
+ // Library drag/drop
216
+ function handleLibDragStart(e, type, idOrType) {
217
+ e.dataTransfer.setData(
218
+ 'application/femo-item',
219
+ JSON.stringify({ type, id: idOrType })
220
+ );
221
+ e.dataTransfer.effectAllowed = 'copy';
222
+ }
223
+
224
+ function handleCanvasDragOver(e) {
225
+ e.preventDefault();
226
+ e.dataTransfer.dropEffect = 'copy';
227
+ }
228
+
229
+ function handleCanvasDrop(e) {
230
+ e.preventDefault();
231
+ let data;
232
+ try {
233
+ data = JSON.parse(e.dataTransfer.getData('application/femo-item'));
234
+ } catch {
235
+ return;
236
+ }
237
+ if (!data) return;
238
+
239
+ const [cx, cy] = xy(e);
240
+ const dropX = cx - 50;
241
+ const dropY = cy - 20;
242
+
243
+ if (data.type === 'action') {
244
+ let action = lib.actions.find((a) => a.id === data.id);
245
+ if (action && isFinite(dropX) && isFinite(dropY))
246
+ addNode(action, dropX, dropY);
247
+ } else if (data.type === 'module') {
248
+ const mod = lib.modules.find((m) => m.id === data.id);
249
+ if (mod) addModuleNode(mod, dropX, dropY);
250
+ } else if (data.type === 'special') {
251
+ addSpecialNode(data.id, dropX, dropY);
252
+ } else if (data.type === 'position') {
253
+ addPositionNode(dropX, dropY);
254
+ }
255
+ }
256
+
257
+ // Compute temporary connection line
258
+ function getTempConnLine() {
259
+ if (!conn) return null;
260
+ const srcNode = nm.get(conn.srcId);
261
+ if (!srcNode) return null;
262
+ const ss = getNodeSize(srcNode);
263
+
264
+ let srcPort;
265
+ switch (conn.srcDir) {
266
+ case 'top':
267
+ srcPort = { x: srcNode.x + ss.w / 2, y: srcNode.y };
268
+ break;
269
+ case 'bottom':
270
+ srcPort = { x: srcNode.x + ss.w / 2, y: srcNode.y + ss.h };
271
+ break;
272
+ case 'left':
273
+ srcPort = { x: srcNode.x, y: srcNode.y + ss.h / 2 };
274
+ break;
275
+ case 'right':
276
+ srcPort = { x: srcNode.x + ss.w, y: srcNode.y + ss.h / 2 };
277
+ break;
278
+ default:
279
+ srcPort = { x: srcNode.x + ss.w, y: srcNode.y + ss.h / 2 };
280
+ }
281
+ const dx = (conn.mx || 0) - srcPort.x;
282
+ const dy = (conn.my || 0) - srcPort.y;
283
+ let srcDir = conn.srcDir || 'right';
284
+ if (!conn.srcDir) {
285
+ if (Math.abs(dx) > Math.abs(dy)) srcDir = dx > 0 ? 'right' : 'left';
286
+ else srcDir = dy > 0 ? 'bottom' : 'top';
287
+ }
288
+ const oppositeDir = {
289
+ right: 'left',
290
+ left: 'right',
291
+ top: 'bottom',
292
+ bottom: 'top',
293
+ }[srcDir];
294
+ return smartBezier(
295
+ srcPort.x,
296
+ srcPort.y,
297
+ srcDir,
298
+ conn.mx || srcPort.x,
299
+ conn.my || srcPort.y,
300
+ oppositeDir
301
+ );
302
+ }
303
+
304
+ return {
305
+ drag, setDrag,
306
+ conn, setConn,
307
+ isPanning, setIsPanning,
308
+ panStart, setPanStart,
309
+ onMM, onMU, onCanvasDown,
310
+ handleWheel,
311
+ handlePortDown, handlePortUp,
312
+ handleBodyMouseUp,
313
+ handleLibDragStart, handleCanvasDragOver, handleCanvasDrop,
314
+ getTempConnLine,
315
+ xy, nm,
316
+ };
317
+ }
318
+
319
+ export { useCanvasInteraction };
@@ -0,0 +1,28 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ server: {
7
+ port: 5173,
8
+ host: '0.0.0.0',
9
+ proxy: {
10
+ '/api': {
11
+ target: `http://127.0.0.1:${process.env.VITE_BACKEND_PORT || 8000}`,
12
+ changeOrigin: true,
13
+ },
14
+ },
15
+ },
16
+ // ✅ 新增多页面配置
17
+ build: {
18
+ rollupOptions: {
19
+ input: {
20
+ main: 'index.html', // 主页面
21
+ intro: 'intro_ch.html', // 介绍页面
22
+ intro_en: 'intro_en.html', // 介绍页面
23
+ document: 'document_ch.html', // 中文文档
24
+ document_en: 'document_en.html', // 英文文档
25
+ },
26
+ },
27
+ },
28
+ });
@@ -0,0 +1,15 @@
1
+ 每次更新在本目录运行这两步。
2
+
3
+ 1.创建新的dist文件夹:
4
+
5
+ npm run build
6
+
7
+
8
+ 2. 上传给Cloudflare服务器:
9
+
10
+ wrangler pages deploy ./dist --project-name=femo
11
+
12
+
13
+ rm -r dist
14
+ npm run build
15
+ wrangler pages deploy ./dist --project-name=femo
@@ -0,0 +1,68 @@
1
+ # dshAdapter — dsh 接口侧
2
+
3
+ Femo 引擎与 dsh 宿主之间的全部胶水代码。现居 `hostAdapter/`(宿主适配层,
4
+ 与 `zcodeAdapter/` 并列,2026-09-13 归拢);引擎侧 `femoCompiler/`(本体)、
5
+ `femoGen/`(编辑器)与边界层 `femo2host/`(门面 API + CLI 工具箱)在仓库根。
6
+
7
+ 分两半,**两半零共享文件**(2026-08-23 重构定的线):
8
+
9
+ ```
10
+ dshAdapter/
11
+ ├── host/ Node 侧:跑在 dsh 宿主进程,入口 index.ts → lib/index.js
12
+ ├── client/ 浏览器侧:打进聊天窗 bundle,入口 client.tsx → lib/client.js
13
+ └── python/ 桥进程 femo_bridge.py(stdio JSON-RPC,host/ 的 bridge.ts 拉起)
14
+ ```
15
+
16
+ 构建:`build.mjs` 两个 entryPoints 分别指向这两个入口;产物都在 `lib/`,
17
+ `package.json` exports 的 `.` / `./client` 不变,dsh 无感。
18
+
19
+ ## host/ — Node 侧模块
20
+
21
+ - **接入层**:`index.ts`(插件入口,注册钩子/路由/工具)、`config.ts`(配置)、
22
+ `http.ts`、`routes.ts`(`/femo-plugin/*` HTTP 路由 + SSE 事件流)、`host-log.ts`
23
+ - **会话钩子与导控**:`pre-step-gate.ts`(轮首拦截 plugin 注入)、`session-events.ts`、
24
+ `tools.ts`(femo-mount/run/debug 等工具注册)、`safe-steer.ts`、`section-gate.ts`、
25
+ `run-control.ts`、`persona.ts`、`main-actor.ts` + `main-delivery-queue.ts`
26
+ (主模型 = 导演;戏内戏外不掺一轮的下场排队)
27
+ - **投影窗 / 子代理**:`projection.ts`、`projection-input.ts`、`proj-trace.ts`、
28
+ `subagent.ts`、`subagent-native.ts`、`god-mirror.ts`(上帝窗镜像)、
29
+ `stream-frames.ts`、`windowing-native.ts`、`native-state.ts`、`state-files.ts`
30
+ - **引擎桥**:`bridge.ts`(拉起 `python/femo_bridge.py`,stdio JSON-RPC)、
31
+ `femo-files.ts`、`debug-run.ts`(零 token 干跑)、`engine-events.ts`、
32
+ `engine-transcript.ts`(事件重放/转写)、`diag-feed.ts`、`list-cache.ts`
33
+ - **重试设施**:`api-retry.ts`(LLM 请求退避)、`node-retry.ts`(节点重演)
34
+
35
+ ## client/ — 浏览器侧模块
36
+
37
+ - `client-ui/`:聊天窗 React 组件——`composer.tsx`(输入)、`chat-node.tsx` /
38
+ `turn-nodes.tsx`(回合渲染)、`femo-stream-live.tsx`(SSE 活帧)、
39
+ `stream-store.ts` / `view-state.ts`(状态)、`editor-page.tsx` / `editor-view.tsx`
40
+ (编辑器标签页,经 `femoGen/femo_gen_api.jsx` 门面 import 编辑器应用——
41
+ 宿主不深入 femoGen/src 内部)、`proj2/`(转写层)
42
+ - 散件:`lineage-fork.jsx` / `lineage-fork-native.jsx`(谱系分叉 UI)、
43
+ `fa-icons.tsx`、`femo-reasoning-row.tsx`
44
+
45
+ ## python/ — 桥进程
46
+
47
+ `femo_bridge.py`(stdio NDJSON JSON-RPC,`host/bridge.ts` 拉起)。引擎面唯一
48
+ 入口 = `femoCompiler/femo_api.py`(2026-09-13 API 化改造):桥只准 import 这个
49
+ 门面,不直接 import 引擎内部模块(parse_script / FEMORunner / JobManager /
50
+ db_utils / host_manifest)——引擎内部重构保住门面签名即可,桥与宿主零改动。
51
+ 私有属性注入(`_human_input_event` / `_host_ai_backend` / `_context_mode`)
52
+ 已在门面 `create_runner` 收口为显式参数。
53
+
54
+ 零 token 干跑也已收进门面(`femo_api.debug_dry_run`,与 CLI run 子命令同一
55
+ 实现面),但本宿主仍走一次性子进程 CLI(`debug-run.ts` spawn
56
+ `femoToolcall/femo_debugger.py`):干跑要能被 terminate 不留僵尸、不与运行桥
57
+ 同进程(门面函数在桥进程内禁用——print 会污染 NDJSON 流)。
58
+
59
+ ## 注意
60
+
61
+ - **本目录就是 dsh 插件根**(2026-09-13 插件根下沉):package.json / lib/ /
62
+ cordis.patch.yml / host.manifest.json / tsconfig 都在这里,构建请在本目录跑
63
+ (`npm run build` 或 `node build.mjs`)。引擎侧(femoCompiler / femoBridges /
64
+ femoGen / femo2host / user_data)在仓库根——config.ts 的 `engineRoot` 负责向上
65
+ 两层指回,femoRoot 仍可被 dsh 配置显式覆盖。
66
+ - `host.manifest.json` 随插件根本地化(与 zcode 侧 zcode.host.manifest.json 同款)。
67
+ - `tests/` 里三个 mjs 单测(safe-steer / pre-step-gate / main-delivery-queue)
68
+ 用 esbuild 直接打包 `dshAdapter/host/` 的源文件跑,改路径记得同步。
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Build script: TS source -> deployable package.
3
+ *
4
+ * Two artifacts:
5
+ * - lib/client.js — browser bundle in ModuleLoader.load format (the web
6
+ * shell's client module loader; see @deepseek-ai/dsh-client-modules).
7
+ * - lib/index.js — host loader entry (exports["."] / main), loaded by the
8
+ * dsh Node process.
9
+ */
10
+ import { build, context } from 'esbuild';
11
+ import { fileURLToPath } from 'node:url';
12
+
13
+ const watch = process.argv.includes('--watch');
14
+
15
+ const nodePaths = [fileURLToPath(new URL('./node_modules', import.meta.url))];
16
+
17
+ const clientOptions = {
18
+ entryPoints: ['./client/client.tsx'],
19
+ bundle: true,
20
+ platform: 'browser',
21
+ format: 'cjs',
22
+ // 必须显式 automatic:femoGen/src/faIcons.jsx(.jsx)不在本 tsconfig 的
23
+ // react-jsx 覆盖范围内,默认 transform 会编出裸 React.createElement,
24
+ // 运行时抛 "React is not defined"(2026-09-14 FaIcon 崩溃修复)。
25
+ jsx: 'automatic',
26
+ outfile: 'lib/client.js',
27
+ // react 走 shell 单例(ModuleLoader 的 require 解析到 seed 里的 react),
28
+ // 不能打进 bundle——否则双 React 实例会崩掉 slots 渲染。
29
+ // ui-primitives 同理。2026-09-04:client-runtime 从 externals 移除——rc.1 删除
30
+ // 该包,femo 的最后一位运行时消费者(lineage-fork 的 indexSubagentDescendants)
31
+ // 已本地化,client bundle 对已删包零引用(type-only 导入构建期擦除)。
32
+ external: [
33
+ 'react', 'react/jsx-runtime', 'react-dom', 'react-dom/client',
34
+ '@deepseek-ai/dsh-client-ui-primitives',
35
+ ],
36
+ banner: {
37
+ js: [
38
+ 'window.__ModuleLoader__.load({',
39
+ ' id: "femo-plugin",',
40
+ ' factory: (require) => {',
41
+ ' var module = { exports: {} };',
42
+ ' var exports = module.exports;',
43
+ ].join('\n'),
44
+ },
45
+ footer: {
46
+ js: [' return module.exports;', ' }', '});'].join('\n'),
47
+ },
48
+ sourcemap: true,
49
+ logLevel: 'info',
50
+ };
51
+
52
+ const hostOptions = {
53
+ entryPoints: ['./host/index.ts'],
54
+ bundle: true,
55
+ platform: 'node',
56
+ format: 'esm',
57
+ target: 'node22',
58
+ nodePaths,
59
+ outfile: 'lib/index.js',
60
+ sourcemap: true,
61
+ logLevel: 'info',
62
+ // dsh-session must stay external: its runtime registry (registerSessionEventType)
63
+ // is instance state shared with the host's persistence coordinator. Bundling a
64
+ // copy would register into a private Set the coordinator never sees. The host
65
+ // resolves this import to the same module instance (tsx tsconfig paths -> src).
66
+ external: ['@deepseek-ai/dsh-session'],
67
+ };
68
+
69
+ if (watch) {
70
+ await (await context(clientOptions)).watch();
71
+ await (await context(hostOptions)).watch();
72
+ console.log('[build] watching dshAdapter/ for changes...');
73
+ } else {
74
+ await Promise.all([build(clientOptions), build(hostOptions)]);
75
+ }