femo-plugin 1.0.1 → 1.0.2
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.
- package/FEMO_logo.svg +55 -0
- package/FEMO_logo_slogan.svg +29 -0
- package/_tmp/fallback/driver2.py +176 -0
- package/_tmp/fallback/events.jsonl +108 -0
- package/_tmp/fallback/gateway_ui.py +325 -0
- package/_tmp/fallback/outbox/j1553_human_[/347/234/213/347/211/214]_1.done +1 -0
- package/_tmp/fallback/outbox/r1.done +1 -0
- package/_tmp/fallback/outbox/r2.done +1 -0
- package/_tmp/fallback/outbox/r3.done +1 -0
- package/_tmp/fallback/outbox/r4.done +1 -0
- package/_tmp/fallback/outbox/r5.done +1 -0
- 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 +3 -2
- package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +112 -9
- package/hostAdapter/dshAdapter/client/client-ui/styles.ts +17 -0
- package/hostAdapter/dshAdapter/client/fa-icons.tsx +3 -0
- package/hostAdapter/dshAdapter/host/engine-events.ts +4 -1
- package/hostAdapter/dshAdapter/host/index.ts +5 -0
- package/hostAdapter/dshAdapter/host/preset-install.ts +59 -0
- package/hostAdapter/dshAdapter/host/projection-input.ts +14 -6
- package/hostAdapter/dshAdapter/lib/client.js +124 -5
- package/hostAdapter/dshAdapter/lib/client.js.map +3 -3
- package/hostAdapter/dshAdapter/lib/index.js +58 -18
- package/hostAdapter/dshAdapter/lib/index.js.map +4 -4
- package/hostAdapter/dshAdapter/package.json +1 -5
- package/hostAdapter/dshAdapter/preset/agent.cordis.yml +220 -0
- package/hostAdapter/dshAdapter/preset/preset.yml +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/gateway.port +1 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_52a9_624b.jsonl +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_6211.jsonl +10 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-god.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-stage.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/README.md +61 -0
- package/hostAdapter/zcodeAdapter/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/LICENSE +201 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/README.md +635 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/__init__.py +4 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/chronica.py +156 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo-chat.mjs +69 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo_debugger.py +1515 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_api.py +437 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_gen_api.jsx +77 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/ContextExample.py +555 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/MemoryExample.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/getDir/get_dir.py +56 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmBridge.py +247 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmProviders.py +308 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_CLIrenderer.py +198 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_config.py +35 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_errors.py +278 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_interpreter.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_normalizer.py +396 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_parser.py +2468 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_runtime.py +3630 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_scope_resolver.py +209 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/actor_resolver.py +86 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/block_collector.py +441 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/db_utils.py +485 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/femoAsync.py +401 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/host_manifest.py +68 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/job_manager.py +767 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/protocol.py +126 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/save_dialog.py +402 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/task_world.py +544 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/__init__.py +19 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/checkpoint.py +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/env.py +686 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/evaluator.py +567 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/join.py +303 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/merge.py +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/model.py +245 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/345/211/252/350/247/206/351/242/221/AI/345/211/252/350/247/206/351/242/221.femo +192 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/luxfiat.femo +38 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/discussion.femo +70 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/goal-mode.femo +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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 +393 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
- package/hostAdapter/zcodeAdapter/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/package.json +1 -1
- package/scripts/diag-find-redblue.mjs +38 -0
- package/scripts/diag-god-log.mjs +31 -0
- package/scripts/diag-god-log2.mjs +39 -0
- package/scripts/diag-god-log3.mjs +35 -0
- package/scripts/diag-god-log4.mjs +59 -0
- package/scripts/diag-god-log4b.mjs +39 -0
- package/scripts/diag-redblue-god.mjs +39 -0
- package/scripts/diag-redblue-log.mjs +37 -0
- package/scripts/diag-redblue-span.mjs +41 -0
- package/scripts/diag-stage-1017.mjs +63 -0
- package/scripts/dump_session.py +36 -0
- package/scripts/link-workspace.ps1 +51 -0
- package/scripts/list_souls.py +18 -0
- package/scripts/probe-composer-refresh.mjs +197 -0
- package/scripts/seed_story_souls.py +86 -0
- package/scripts/sync-zcode-dist.ps1 +55 -0
- package/scripts/theme-tokenize/color-extract.txt +288 -0
- package/scripts/theme-tokenize/round1-quoted.ps1 +149 -0
- package/scripts/theme-tokenize/round2-bare.ps1 +138 -0
- package/scripts/theme-tokenize/round3-shape.ps1 +110 -0
- package/tests/_diag_r4_join.femo +32 -0
- package/tests/conftest.py +95 -0
- package/tests/diag-subagent-dir-3081.mjs +101 -0
- package/tests/femoGenerator.test.mjs +3909 -0
- package/tests/femoParser.test.mjs +4813 -0
- package/tests/femogen_notice.test.mjs +109 -0
- package/tests/femoparser_validation.test.mjs +84 -0
- package/tests/main-delivery-queue.test.mjs +329 -0
- package/tests/pre-step-gate.test.mjs +282 -0
- package/tests/read-subagent-model.mjs +24 -0
- package/tests/run-script-tests.py +97 -0
- package/tests/safe-steer.test.mjs +59 -0
- package/tests/strip_comments.test.mjs +164 -0
- package/tests/test_actor_failed.py +92 -0
- package/tests/test_compile_warnings.py +99 -0
- package/tests/test_debug_log_bus.py +108 -0
- package/tests/test_debugger_module_mode.py +141 -0
- package/tests/test_error_buckets.py +117 -0
- package/tests/test_error_dispatcher.py +261 -0
- package/tests/test_exec_ai_retry.py +155 -0
- package/tests/test_exec_human_retry.py +159 -0
- package/tests/test_file_resolve.py +104 -0
- package/tests/test_flow_events.py +311 -0
- package/tests/test_flow_ref_validation.py +92 -0
- package/tests/test_func_dict_fallback.py +39 -0
- package/tests/test_job_lifecycle.py +236 -0
- package/tests/test_job_manager.py +424 -0
- package/tests/test_mind.py +99 -0
- package/tests/test_module_call_args.py +258 -0
- package/tests/test_module_visibility.py +238 -0
- package/tests/test_notice.py +143 -0
- package/tests/test_out_whitelist.py +83 -0
- package/tests/test_par_if_dispatch.py +64 -0
- package/tests/test_par_nested_for.py +78 -0
- package/tests/test_parser.py +494 -0
- package/tests/test_pause.py +102 -0
- package/tests/test_pause_contract.py +135 -0
- package/tests/test_protocol_transcript.py +158 -0
- package/tests/test_scope_self.py +202 -0
- package/tests/test_source_validate.py +113 -0
- package/tests/test_task_world.py +447 -0
- package/tests/test_town_structure.py +70 -0
- package/tests/test_v2_checkpoint.py +115 -0
- package/tests/test_v2_env.py +383 -0
- package/tests/test_v2_evaluator.py +227 -0
- package/tests/test_v2_join.py +315 -0
- package/tests/test_v2_join_wiring.py +429 -0
- package/tests/test_v2_merge.py +167 -0
- package/tests/test_v2_model.py +143 -0
- package/tests/test_v2_resume_e2e.py +472 -0
- package/tests/test_var_decls.py +271 -0
- package/tests/verify-model-functions.mjs +90 -0
- package/tests/verify-subagent-model-3081.mjs +153 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225/node-notice-/346/226/275/345/267/245/346/270/205/345/215/225.md +395 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//344/270/244/344/270/252/345/276/205/350/247/243/345/206/263/347/232/204/351/227/256/351/242/230.MD +66 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/201/234/346/255/242/351/223/276/344/277/256/345/244/215-/346/226/275/345/267/245/346/270/205/345/215/225.md +475 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/217/230/351/207/217/344/270/216task/347/263/273/347/273/237/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225-v2.md +847 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//350/277/220/350/241/214/347/212/266/346/200/201/351/223/276/350/267/257/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225v4.md +654 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//351/224/231/350/257/257/346/263/250/345/205/245/347/273/255/350/201/212-/346/226/275/345/267/245/346/270/205/345/215/225.md +471 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""原版 femoGen 舞台适配器:femoGen/dist 静态页 + gateway.mjs 同款 API 契约。
|
|
3
|
+
|
|
4
|
+
数据源 = 兜底 driver 的 events.jsonl + outbox(*.done 交卷原文)。
|
|
5
|
+
实现面(与 mcp/gateway.mjs 对齐):
|
|
6
|
+
GET /events SSE:run_state / femo_stream(user_line) 帧
|
|
7
|
+
GET /api/session-state router.state() + windows
|
|
8
|
+
GET /api/projection/<win> {win, rows}(afterSeq 增量)
|
|
9
|
+
POST /api/human-input {text} 原文直投 pending human_wait
|
|
10
|
+
GET /* femoGen/dist 静态文件
|
|
11
|
+
"""
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import threading
|
|
15
|
+
import time
|
|
16
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
WORKDIR = Path(os.environ.get("FEMO_FALLBACK_DIR") or Path(__file__).resolve().parent)
|
|
20
|
+
EVENTS = WORKDIR / "events.jsonl"
|
|
21
|
+
OUTBOX = WORKDIR / "outbox"
|
|
22
|
+
DIST = Path(r"D:\myFiles\dsh\femo-plugin\femoGen\dist")
|
|
23
|
+
PORT = int(os.environ.get("FEMO_UI_PORT", "3890"))
|
|
24
|
+
SID = "femo-main"
|
|
25
|
+
|
|
26
|
+
DEFAULT_ACTORS = ["@胖婶", "@老李", "@张较真", "@戚老师", "@王炸", "@小白", "@猫猫"]
|
|
27
|
+
MIME = {".html": "text/html; charset=utf-8", ".js": "text/javascript", ".css": "text/css",
|
|
28
|
+
".json": "application/json", ".svg": "image/svg+xml", ".png": "image/png",
|
|
29
|
+
".ico": "image/x-icon", ".ttf": "font/ttf", ".woff2": "font/woff2"}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def actor_key(name):
|
|
33
|
+
out = ""
|
|
34
|
+
for ch in str(name):
|
|
35
|
+
out += ch if ("a" <= ch <= "z" or "A" <= ch <= "Z" or "0" <= ch <= "9" or ch in "_-") \
|
|
36
|
+
else f"_{ord(ch):x}"
|
|
37
|
+
return out or "_"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Store:
|
|
41
|
+
"""god/stage/角色 三窗内存投影 + 运行态镜像(语义对齐 projection-writer.mjs)。"""
|
|
42
|
+
|
|
43
|
+
def __init__(self):
|
|
44
|
+
self.wins = {"god": [], "stage": []} # key -> rows [{seq,ts,type,data}]
|
|
45
|
+
self.actor_keys = [] # actorKey 顺序
|
|
46
|
+
self.seq = 0
|
|
47
|
+
self.lock = threading.Lock()
|
|
48
|
+
self.running = False
|
|
49
|
+
self.play_name = ""
|
|
50
|
+
self.actors = []
|
|
51
|
+
self.main_actors = []
|
|
52
|
+
self.waiting_human = None
|
|
53
|
+
self.node_scopes = {}
|
|
54
|
+
self.node_actors = {}
|
|
55
|
+
self.briefs = {} # wait_key -> {ai_name, scope}
|
|
56
|
+
self.human_texts = {} # wait_key -> text(UI POST 的)
|
|
57
|
+
self.projected_done = set() # 已投影的 outbox 文件名
|
|
58
|
+
self.broadcast = None # 由 HTTP 层注入
|
|
59
|
+
|
|
60
|
+
# ── 投影写入(append 语义:god+stage 恒全量;角色窗按 targetActors)──
|
|
61
|
+
def chat(self, text, kind="notice", actor=None, target_actors=None):
|
|
62
|
+
with self.lock:
|
|
63
|
+
self.seq += 1
|
|
64
|
+
data = {"text": text, "kind": kind, "seq": int(time.time() * 1000)}
|
|
65
|
+
if actor is not None:
|
|
66
|
+
data["actor"] = actor
|
|
67
|
+
targets = target_actors if target_actors else None # []/None = 全员可见
|
|
68
|
+
row = {"seq": self.seq, "ts": time.strftime("%Y-%m-%dT%H:%M:%S"), "type": "femo/chat", "data": data}
|
|
69
|
+
self.wins["god"].append(row)
|
|
70
|
+
self.wins["stage"].append(row)
|
|
71
|
+
for ak in self.actor_keys:
|
|
72
|
+
if targets is None or any(actor_key(a) == ak for a in targets):
|
|
73
|
+
self.wins.setdefault(f"a:{ak}", []).append(row)
|
|
74
|
+
|
|
75
|
+
def ensure_windows(self, actors):
|
|
76
|
+
for a in actors:
|
|
77
|
+
ak = actor_key(a)
|
|
78
|
+
if ak not in self.actor_keys:
|
|
79
|
+
self.actor_keys.append(ak)
|
|
80
|
+
self.wins.setdefault(f"a:{ak}", [])
|
|
81
|
+
|
|
82
|
+
def list_windows(self):
|
|
83
|
+
return ["god", "stage"] + [f"a:{ak}" for ak in self.actor_keys]
|
|
84
|
+
|
|
85
|
+
def read_window(self, key, after_seq=0):
|
|
86
|
+
rows = self.wins.get(key)
|
|
87
|
+
if rows is None and key.startswith("a:"):
|
|
88
|
+
rows = self.wins.get(key)
|
|
89
|
+
return [r for r in (rows or []) if r["seq"] > after_seq]
|
|
90
|
+
|
|
91
|
+
def state(self):
|
|
92
|
+
running = self.running or bool(self.waiting_human)
|
|
93
|
+
play = self.play_name or ("谁是卧底·菜市场局" if running else "")
|
|
94
|
+
return {"sid": SID, "running": running, "playName": play,
|
|
95
|
+
"actors": self.actors, "mainActors": self.main_actors,
|
|
96
|
+
"waitingHuman": self.waiting_human, "pendingDirectives": 0}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
STORE = Store()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def handle_event(et, d):
|
|
103
|
+
st = STORE
|
|
104
|
+
if et == "flow_start":
|
|
105
|
+
st.actors = [a for a in (d.get("actors") or []) if isinstance(a, str)] or DEFAULT_ACTORS
|
|
106
|
+
st.main_actors = [a for a in (d.get("main_actors") or []) if isinstance(a, str)]
|
|
107
|
+
st.play_name = d.get("name") if isinstance(d.get("name"), str) else ""
|
|
108
|
+
st.running = True
|
|
109
|
+
st.ensure_windows(st.actors)
|
|
110
|
+
st.chat(f"🎬 《{st.play_name or '未命名剧本'}》开演", "sys")
|
|
111
|
+
elif et == "node_start":
|
|
112
|
+
node = d.get("node_name")
|
|
113
|
+
scope = d.get("scope") if isinstance(d.get("scope"), list) else None
|
|
114
|
+
if node is not None and scope is not None:
|
|
115
|
+
st.node_scopes[node] = scope
|
|
116
|
+
if d.get("node_type") in ("human", "notice") and str(d.get("prompt") or "").strip():
|
|
117
|
+
st.chat(f"📢 {d['prompt']}", "prompt", target_actors=scope)
|
|
118
|
+
elif et == "context_ready":
|
|
119
|
+
node, ai = d.get("node_name"), d.get("ai_name")
|
|
120
|
+
if node is not None and ai:
|
|
121
|
+
st.node_actors[node] = ai
|
|
122
|
+
sp = d.get("showprompt")
|
|
123
|
+
if isinstance(sp, str) and sp.strip():
|
|
124
|
+
st.chat(f"📢 {sp}", "prompt", target_actors=st.node_scopes.get(node))
|
|
125
|
+
elif et == "ai_request":
|
|
126
|
+
node = d.get("node_name")
|
|
127
|
+
scope = d.get("scope_info") if isinstance(d.get("scope_info"), list) else None
|
|
128
|
+
if node is not None and scope is not None:
|
|
129
|
+
st.node_scopes[node] = scope
|
|
130
|
+
if d.get("wait_key"):
|
|
131
|
+
st.briefs[d["wait_key"]] = {"ai_name": d.get("ai_name") or "", "scope": scope}
|
|
132
|
+
elif et == "human_wait":
|
|
133
|
+
wh = {"job_id": d.get("job_id"), "wait_key": str(d.get("wait_key") or ""),
|
|
134
|
+
"node_name": d.get("node_name"), "prompt": d.get("prompt") or "",
|
|
135
|
+
"scope": d.get("scope") if isinstance(d.get("scope"), list) else []}
|
|
136
|
+
st.waiting_human = wh
|
|
137
|
+
st.chat(("🎭 等待你的回应:" + wh["prompt"]) if wh["prompt"].strip() else "🎭 等待你的回应",
|
|
138
|
+
"human_wait", target_actors=wh["scope"])
|
|
139
|
+
elif et == "human_done":
|
|
140
|
+
st.waiting_human = None
|
|
141
|
+
elif et == "flow_done":
|
|
142
|
+
st.running = False
|
|
143
|
+
st.chat("✅ 剧本已跑完", "sys")
|
|
144
|
+
elif et == "flow_error":
|
|
145
|
+
st.running = False
|
|
146
|
+
st.chat(f"❌ 剧本出错:{d.get('error') or 'unknown'}", "error")
|
|
147
|
+
elif et == "notify_author":
|
|
148
|
+
if str(d.get("message") or "").strip():
|
|
149
|
+
st.chat(f"⚠️ {d['message']}", "notice")
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def project_outbox_deliveries():
|
|
153
|
+
"""board.py / UI 交卷成功(*.done)后补 role 行:台词 = 交卷原文。"""
|
|
154
|
+
if not OUTBOX.exists():
|
|
155
|
+
return
|
|
156
|
+
for p in sorted(OUTBOX.glob("*.done")):
|
|
157
|
+
if p.name in STORE.projected_done:
|
|
158
|
+
continue
|
|
159
|
+
STORE.projected_done.add(p.name)
|
|
160
|
+
try:
|
|
161
|
+
body = json.loads(p.read_text(encoding="utf-8"))
|
|
162
|
+
except Exception:
|
|
163
|
+
continue
|
|
164
|
+
wk, text = body.get("wait_key"), (body.get("text") or "").strip()
|
|
165
|
+
if not wk or not text or wk.startswith("j") and "human_" in wk:
|
|
166
|
+
continue # 人类拍已在 POST 时投影
|
|
167
|
+
b = STORE.briefs.get(wk) or {}
|
|
168
|
+
actor = b.get("ai_name") or ""
|
|
169
|
+
STORE.chat(text, "role", actor=actor or None, target_actors=b.get("scope"))
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def poll_loop():
|
|
173
|
+
seen = 0
|
|
174
|
+
STORE.ensure_windows(DEFAULT_ACTORS) # flow_start 可能已随清洗丢失,先建齐角色窗
|
|
175
|
+
STORE.actors = DEFAULT_ACTORS
|
|
176
|
+
while True:
|
|
177
|
+
try:
|
|
178
|
+
lines = EVENTS.read_text(encoding="utf-8").splitlines() if EVENTS.exists() else []
|
|
179
|
+
new = lines[seen:]
|
|
180
|
+
seen = len(lines)
|
|
181
|
+
fired = False
|
|
182
|
+
for line in new:
|
|
183
|
+
try:
|
|
184
|
+
e = json.loads(line)
|
|
185
|
+
except Exception:
|
|
186
|
+
continue
|
|
187
|
+
handle_event(e.get("event"), e.get("data") or {})
|
|
188
|
+
fired = True
|
|
189
|
+
project_outbox_deliveries()
|
|
190
|
+
if fired and STORE.broadcast:
|
|
191
|
+
try:
|
|
192
|
+
STORE.broadcast("run_state", STORE.state())
|
|
193
|
+
except Exception:
|
|
194
|
+
pass
|
|
195
|
+
except Exception:
|
|
196
|
+
pass
|
|
197
|
+
time.sleep(1.0)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class H(BaseHTTPRequestHandler):
|
|
201
|
+
protocol_version = "HTTP/1.1"
|
|
202
|
+
|
|
203
|
+
def _send(self, code, body, ctype="application/json; charset=utf-8"):
|
|
204
|
+
data = body.encode("utf-8") if isinstance(body, str) else body
|
|
205
|
+
self.send_response(code)
|
|
206
|
+
self.send_header("Content-Type", ctype)
|
|
207
|
+
self.send_header("Content-Length", str(len(data)))
|
|
208
|
+
self.send_header("Access-Control-Allow-Origin", "*")
|
|
209
|
+
self.send_header("Cache-Control", "no-store")
|
|
210
|
+
self.end_headers()
|
|
211
|
+
try:
|
|
212
|
+
self.wfile.write(data)
|
|
213
|
+
except Exception:
|
|
214
|
+
pass
|
|
215
|
+
|
|
216
|
+
def do_GET(self):
|
|
217
|
+
path = self.path.split("?")[0]
|
|
218
|
+
if path == "/events":
|
|
219
|
+
self._sse()
|
|
220
|
+
return
|
|
221
|
+
if path == "/api/session-state":
|
|
222
|
+
with STORE.lock:
|
|
223
|
+
st = STORE.state()
|
|
224
|
+
st["windows"] = STORE.list_windows()
|
|
225
|
+
self._send(200, json.dumps(st, ensure_ascii=False))
|
|
226
|
+
return
|
|
227
|
+
if path.startswith("/api/projection/"):
|
|
228
|
+
win = path[len("/api/projection/"):].rstrip("/")
|
|
229
|
+
try:
|
|
230
|
+
after = int(self.path.split("afterSeq=")[-1]) if "afterSeq=" in self.path else 0
|
|
231
|
+
except ValueError:
|
|
232
|
+
after = 0
|
|
233
|
+
with STORE.lock:
|
|
234
|
+
rows = STORE.read_window(win, after)
|
|
235
|
+
self._send(200, json.dumps({"win": win, "rows": rows}, ensure_ascii=False))
|
|
236
|
+
return
|
|
237
|
+
if path in ("/api/state", "/fallback-state"):
|
|
238
|
+
self._send(200, json.dumps({"waiting": STORE.waiting_human}, ensure_ascii=False))
|
|
239
|
+
return
|
|
240
|
+
# 静态 femoGen/dist
|
|
241
|
+
if DIST.exists():
|
|
242
|
+
rel = "index.html" if path == "/" else path.lstrip("/")
|
|
243
|
+
f = DIST / rel
|
|
244
|
+
if f.is_file() and DIST in f.resolve().parents or f == DIST / "index.html":
|
|
245
|
+
ctype = MIME.get(f.suffix.lower(), "application/octet-stream")
|
|
246
|
+
self._send(200, f.read_bytes(), ctype)
|
|
247
|
+
return
|
|
248
|
+
self._send(404, json.dumps({"error": "not found",
|
|
249
|
+
"hint": "GET /events | /api/session-state | /api/projection/<win> | POST /api/human-input"}))
|
|
250
|
+
|
|
251
|
+
def _sse(self):
|
|
252
|
+
self.send_response(200)
|
|
253
|
+
self.send_header("Content-Type", "text/event-stream")
|
|
254
|
+
self.send_header("Cache-Control", "no-cache")
|
|
255
|
+
self.send_header("Connection", "keep-alive")
|
|
256
|
+
self.send_header("Access-Control-Allow-Origin", "*")
|
|
257
|
+
self.end_headers()
|
|
258
|
+
clients = SSE_CLIENTS
|
|
259
|
+
clients.append(self.wfile)
|
|
260
|
+
try:
|
|
261
|
+
with STORE.lock:
|
|
262
|
+
self._sse_frame("run_state", STORE.state())
|
|
263
|
+
while True:
|
|
264
|
+
time.sleep(15)
|
|
265
|
+
self.wfile.write(b": heartbeat\n\n")
|
|
266
|
+
except Exception:
|
|
267
|
+
pass
|
|
268
|
+
finally:
|
|
269
|
+
try:
|
|
270
|
+
clients.remove(self.wfile)
|
|
271
|
+
except ValueError:
|
|
272
|
+
pass
|
|
273
|
+
|
|
274
|
+
def _sse_frame(self, ev, payload):
|
|
275
|
+
self.wfile.write(f"event: {ev}\ndata: {json.dumps({**payload, 'ts': int(time.time()*1000)}, ensure_ascii=False)}\n\n".encode("utf-8"))
|
|
276
|
+
self.wfile.flush()
|
|
277
|
+
|
|
278
|
+
def do_POST(self):
|
|
279
|
+
if self.path != "/api/human-input":
|
|
280
|
+
self._send(404, json.dumps({"error": "not found"}))
|
|
281
|
+
return
|
|
282
|
+
n = int(self.headers.get("Content-Length") or 0)
|
|
283
|
+
try:
|
|
284
|
+
body = json.loads(self.rfile.read(n).decode("utf-8"))
|
|
285
|
+
except Exception:
|
|
286
|
+
self._send(400, json.dumps({"error": "bad json"}))
|
|
287
|
+
return
|
|
288
|
+
text = str(body.get("text", "")).strip()
|
|
289
|
+
if not text:
|
|
290
|
+
self._send(400, json.dumps({"error": "empty text"}))
|
|
291
|
+
return
|
|
292
|
+
with STORE.lock:
|
|
293
|
+
wh = STORE.waiting_human
|
|
294
|
+
if not wh:
|
|
295
|
+
self._send(409, json.dumps({"error": "引擎当前不在等待人类输入"}))
|
|
296
|
+
return
|
|
297
|
+
wk = wh["wait_key"]
|
|
298
|
+
scope = wh.get("scope") or []
|
|
299
|
+
actor = body.get("actor") or (scope[0] if scope else "@猫猫")
|
|
300
|
+
STORE.chat(text, "role", actor=actor, target_actors=wh.get("scope"))
|
|
301
|
+
safe = wk.replace("/", "_").replace("\\", "_").replace(":", "_")
|
|
302
|
+
OUTBOX.mkdir(exist_ok=True)
|
|
303
|
+
with STORE.lock:
|
|
304
|
+
(OUTBOX / (safe + ".json")).write_text(
|
|
305
|
+
json.dumps({"wait_key": wk, "text": text}, ensure_ascii=False), encoding="utf-8")
|
|
306
|
+
STORE.human_texts[wk] = text
|
|
307
|
+
try:
|
|
308
|
+
frame = f"event: femo_stream\ndata: {json.dumps({'kind': 'user_line', 'actor': actor, 'text': text, 'ts': int(time.time()*1000)}, ensure_ascii=False)}\n\n".encode("utf-8")
|
|
309
|
+
for c in list(SSE_CLIENTS):
|
|
310
|
+
c.write(frame)
|
|
311
|
+
c.flush()
|
|
312
|
+
except Exception:
|
|
313
|
+
pass
|
|
314
|
+
self._send(200, json.dumps({"ok": True, "wait_key": wk}, ensure_ascii=False))
|
|
315
|
+
|
|
316
|
+
def log_message(self, *a):
|
|
317
|
+
pass
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
SSE_CLIENTS = []
|
|
321
|
+
|
|
322
|
+
if __name__ == "__main__":
|
|
323
|
+
threading.Thread(target=poll_loop, daemon=True).start()
|
|
324
|
+
print(f"femoGen stage adapter on http://127.0.0.1:{PORT} (workdir={WORKDIR})")
|
|
325
|
+
ThreadingHTTPServer(("127.0.0.1", PORT), H).serve_forever()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"wait_key": "j1553:human_[看牌]_1", "text": "收到"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"wait_key": "j1553:ai_[看牌]_1", "text": "(低头舔了舔爪子,把牌面看完,尾巴轻轻摇了摇)喵~"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"wait_key": "j1553:ai_[看牌]_2", "text": "收到,牌已看,稳住不慌。"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"wait_key": "j1553:ai_[看牌]_3", "text": "收到,看好了。"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"wait_key": "j1553:ai_[看牌]_4", "text": "(歪头盯着自己的牌看了三秒,尾巴慢慢摇起来)收到收到,汪!这个词我熟,绝对不露馅。"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"wait_key": "j1553:ai_[看牌]_5", "text": "(把手机屏幕翻来覆去看了两遍,一脸问号)……这牌是空的?行吧,我先记下了。"}
|
|
@@ -43,6 +43,7 @@ vars:
|
|
|
43
43
|
@speaker = ""
|
|
44
44
|
@VOTE = ""
|
|
45
45
|
announce_text = ""
|
|
46
|
+
round_task = ""
|
|
46
47
|
verdict_text = ""
|
|
47
48
|
|
|
48
49
|
action 结束判定 @func(u.next_round_stage):
|
|
@@ -128,11 +129,11 @@ module 发言:
|
|
|
128
129
|
round_no = round_no
|
|
129
130
|
alive_players = $alive
|
|
130
131
|
out:
|
|
131
|
-
announce_text
|
|
132
|
+
announce_text, round_task
|
|
132
133
|
|
|
133
134
|
action 回合公告 @notice:
|
|
134
135
|
prompt: |
|
|
135
|
-
"{announce_text}"
|
|
136
|
+
"{announce_text}\n{round_task}"
|
|
136
137
|
scope: all
|
|
137
138
|
|
|
138
139
|
action 陈述 @mind(@speaker):
|
|
@@ -38,8 +38,8 @@ import type { KeyboardEvent as ReactKeyboardEvent, MouseEvent as ReactMouseEvent
|
|
|
38
38
|
import { IconChevronDownOutline14, Menu, RiskConfirmation, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
39
39
|
import type { MenuEntry } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
40
40
|
import { femoStreamAcquire, useActorUsage, subscribeControlEvents } from './stream-store'
|
|
41
|
-
import { LeadingIconText } from './chat-node'
|
|
42
|
-
import { FemoLogo } from '../fa-icons'
|
|
41
|
+
import { LeadingIconText } from './chat-node'
|
|
42
|
+
import { FemoLogo, FaCode, FaCircleCheck } from '../fa-icons'
|
|
43
43
|
|
|
44
44
|
/** 提交失败的提示条状态:seq 保证连续同文错误也会重开计时。 */
|
|
45
45
|
interface ComposerError {
|
|
@@ -663,9 +663,11 @@ interface FemoRunState {
|
|
|
663
663
|
waiting: boolean
|
|
664
664
|
waitScope: string[]
|
|
665
665
|
prompt?: string
|
|
666
|
+
/** 等待人类节点声明的 out 变量名(变量赋值浮层的数据源;非等待为 [])。 */
|
|
667
|
+
outVars: string[]
|
|
666
668
|
}
|
|
667
669
|
|
|
668
|
-
const IDLE_RUN_STATE: FemoRunState = { running: false, waiting: false, waitScope: [] }
|
|
670
|
+
const IDLE_RUN_STATE: FemoRunState = { running: false, waiting: false, waitScope: [], outVars: [] }
|
|
669
671
|
|
|
670
672
|
/**
|
|
671
673
|
* 按钮状态机(各投影窗唯一的控制逻辑,2026-09-06 猫猫拍板的矩阵):
|
|
@@ -765,13 +767,14 @@ export function ProjectionComposer({ useSession, useSessions, getSessionFace }:
|
|
|
765
767
|
// 单通道的实时性)。
|
|
766
768
|
const [run, setRun] = useState<FemoRunState>(IDLE_RUN_STATE)
|
|
767
769
|
const [winInfo, setWinInfo] = useState<{ winKind: 'god' | 'stage' | 'actor' | 'none'; actor?: string }>({ winKind: 'none' })
|
|
768
|
-
const applyState = useCallback((data: { ok?: boolean; winKind?: 'god' | 'stage' | 'actor' | 'none'; actor?: string; running?: boolean; waiting?: boolean; waitScope?: string[]; prompt?: string }) => {
|
|
770
|
+
const applyState = useCallback((data: { ok?: boolean; winKind?: 'god' | 'stage' | 'actor' | 'none'; actor?: string; running?: boolean; waiting?: boolean; waitScope?: string[]; prompt?: string; outVars?: string[] }) => {
|
|
769
771
|
setWinInfo({ winKind: data.winKind ?? 'none', actor: data.actor })
|
|
770
772
|
if (data.ok === true) {
|
|
771
773
|
setRun({
|
|
772
774
|
running: data.running === true,
|
|
773
775
|
waiting: data.waiting === true,
|
|
774
776
|
waitScope: Array.isArray(data.waitScope) ? data.waitScope : [],
|
|
777
|
+
outVars: Array.isArray(data.outVars) ? data.outVars : [],
|
|
775
778
|
prompt: typeof data.prompt === 'string' ? data.prompt : undefined,
|
|
776
779
|
})
|
|
777
780
|
}
|
|
@@ -810,12 +813,13 @@ export function ProjectionComposer({ useSession, useSessions, getSessionFace }:
|
|
|
810
813
|
if (mainSid === undefined) return
|
|
811
814
|
return subscribeControlEvents(msg => {
|
|
812
815
|
if (msg.type !== 'projection_state') return
|
|
813
|
-
const data = msg.data as { sid?: string; running?: boolean; waiting?: boolean; waitScope?: string[]; prompt?: string } | undefined
|
|
816
|
+
const data = msg.data as { sid?: string; running?: boolean; waiting?: boolean; waitScope?: string[]; prompt?: string; outVars?: string[] } | undefined
|
|
814
817
|
if (data === undefined || data.sid !== mainSid) return
|
|
815
818
|
setRun({
|
|
816
819
|
running: data.running === true,
|
|
817
820
|
waiting: data.waiting === true,
|
|
818
821
|
waitScope: Array.isArray(data.waitScope) ? data.waitScope : [],
|
|
822
|
+
outVars: Array.isArray(data.outVars) ? data.outVars : [],
|
|
819
823
|
prompt: typeof data.prompt === 'string' ? data.prompt : undefined,
|
|
820
824
|
})
|
|
821
825
|
})
|
|
@@ -823,14 +827,65 @@ export function ProjectionComposer({ useSession, useSessions, getSessionFace }:
|
|
|
823
827
|
|
|
824
828
|
const buttonState = composerButtonState({ winKind: winInfo.winKind, actor: winInfo.actor, run, mainRunning })
|
|
825
829
|
|
|
826
|
-
|
|
830
|
+
// ── 变量赋值浮层(2026-09-14)──────────────────────────────────────────
|
|
831
|
+
// 轮到人类节点且节点声明了 out:输入框上方出现 fa-code 小按钮,点击向上弹
|
|
832
|
+
// 出「变量名 = 输入框」浮层;确认把非空行收成结构化 variables 与文本一起
|
|
833
|
+
// POST(引擎 _try_apply_human_variables 直取,绕过 chat_text 文本解析)。
|
|
834
|
+
const [varsOpen, setVarsOpen] = useState(false)
|
|
835
|
+
const [varValues, setVarValues] = useState<Record<string, string>>({})
|
|
836
|
+
const varsPanelRef = useRef<HTMLDivElement | null>(null)
|
|
837
|
+
// 等待回合切换(outVars 变化)即收起浮层并清空旧值,防止上一回合的赋值
|
|
838
|
+
// 残留误提交到下一回合。
|
|
839
|
+
const outVarsKey = run.outVars.join('\u0000')
|
|
840
|
+
useEffect(() => {
|
|
841
|
+
setVarsOpen(false)
|
|
842
|
+
setVarValues({})
|
|
843
|
+
}, [outVarsKey])
|
|
844
|
+
// 浮层开着时:外部点击 / Escape 关闭(ContextRing 同款单监听器模式)。
|
|
845
|
+
useEffect(() => {
|
|
846
|
+
if (!varsOpen) return
|
|
847
|
+
const onPointerDown = (e: PointerEvent): void => {
|
|
848
|
+
if (e.target instanceof Node && varsPanelRef.current?.contains(e.target) === true) return
|
|
849
|
+
setVarsOpen(false)
|
|
850
|
+
}
|
|
851
|
+
const onKeyDown = (e: KeyboardEvent): void => {
|
|
852
|
+
if (e.key === 'Escape') setVarsOpen(false)
|
|
853
|
+
}
|
|
854
|
+
document.addEventListener('pointerdown', onPointerDown)
|
|
855
|
+
document.addEventListener('keydown', onKeyDown)
|
|
856
|
+
return () => {
|
|
857
|
+
document.removeEventListener('pointerdown', onPointerDown)
|
|
858
|
+
document.removeEventListener('keydown', onKeyDown)
|
|
859
|
+
}
|
|
860
|
+
}, [varsOpen])
|
|
861
|
+
const setVarValue = (name: string, value: string): void => {
|
|
862
|
+
setVarValues(prev => ({ ...prev, [name]: value }))
|
|
863
|
+
}
|
|
864
|
+
// 确认:只提交填了值的变量;全空=收起浮层不发(空输入会喂引擎空回合)。
|
|
865
|
+
const confirmVars = (): void => {
|
|
866
|
+
const filled: Record<string, string> = {}
|
|
867
|
+
for (const name of run.outVars) {
|
|
868
|
+
const value = varValues[name]?.trim()
|
|
869
|
+
if (value !== undefined && value.length > 0) filled[name] = value
|
|
870
|
+
}
|
|
871
|
+
if (Object.keys(filled).length === 0) {
|
|
872
|
+
setVarsOpen(false)
|
|
873
|
+
return
|
|
874
|
+
}
|
|
875
|
+
submit(filled)
|
|
876
|
+
}
|
|
877
|
+
// 显示条件与发送钮同源(buttonState==='send' 已含 waiting + 本窗在 scope)。
|
|
878
|
+
const showVarUi = buttonState === 'send' && run.outVars.length > 0
|
|
879
|
+
|
|
880
|
+
const submit = (variables: Record<string, string> = {}): void => {
|
|
827
881
|
const value = text.trim()
|
|
828
|
-
|
|
882
|
+
const hasVars = Object.keys(variables).length > 0
|
|
883
|
+
if ((value.length === 0 && !hasVars) || busy || sessionId === undefined) return
|
|
829
884
|
setBusy(true)
|
|
830
885
|
const post = async (): Promise<Response> => fetch('/femo-plugin/projection-input', {
|
|
831
886
|
method: 'POST',
|
|
832
887
|
headers: { 'content-type': 'application/json' },
|
|
833
|
-
body: JSON.stringify({ sessionId, text: value }),
|
|
888
|
+
body: JSON.stringify({ sessionId, text: value, ...(hasVars ? { variables } : {}) }),
|
|
834
889
|
})
|
|
835
890
|
void (async (): Promise<void> => {
|
|
836
891
|
try {
|
|
@@ -854,6 +909,9 @@ export function ProjectionComposer({ useSession, useSessions, getSessionFace }:
|
|
|
854
909
|
if (data.ok === true) {
|
|
855
910
|
// 官方同语义:提交成功清空草稿(state + 持久层一起)。
|
|
856
911
|
changeText('')
|
|
912
|
+
// 变量浮层随之收起并清空已填值(下个等待回合重新开始)。
|
|
913
|
+
setVarsOpen(false)
|
|
914
|
+
setVarValues({})
|
|
857
915
|
return
|
|
858
916
|
}
|
|
859
917
|
errorSeqRef.current += 1
|
|
@@ -926,6 +984,51 @@ export function ProjectionComposer({ useSession, useSessions, getSessionFace }:
|
|
|
926
984
|
手机触摸豁免/软键盘避让全部委托 [data-composer-card] 与
|
|
927
985
|
[data-input-scroll] 识别——不挂钩子这些适配层对我们失效。 */}
|
|
928
986
|
<div className="femo-comp-card" data-composer-card="">
|
|
987
|
+
{showVarUi && (
|
|
988
|
+
<div className="femo-comp-var-bar">
|
|
989
|
+
<button
|
|
990
|
+
type="button"
|
|
991
|
+
className="femo-comp-var-trigger"
|
|
992
|
+
aria-label="变量赋值"
|
|
993
|
+
aria-haspopup="dialog"
|
|
994
|
+
aria-expanded={varsOpen}
|
|
995
|
+
data-open={varsOpen}
|
|
996
|
+
onMouseDown={keepFocus}
|
|
997
|
+
onClick={() => { setVarsOpen(!varsOpen) }}
|
|
998
|
+
>
|
|
999
|
+
<FaCode size={12} />
|
|
1000
|
+
<span>变量赋值</span>
|
|
1001
|
+
</button>
|
|
1002
|
+
{varsOpen && (
|
|
1003
|
+
<div ref={varsPanelRef} className="femo-comp-var-panel" role="dialog" aria-label="变量赋值">
|
|
1004
|
+
<div className="femo-comp-var-head">本节点变量赋值(可只填其中几项)</div>
|
|
1005
|
+
{run.outVars.map(name => (
|
|
1006
|
+
<div key={name} className="femo-comp-var-row">
|
|
1007
|
+
<span className="femo-comp-var-name" title={name}>{name}</span>
|
|
1008
|
+
<span className="femo-comp-var-eq" aria-hidden>=</span>
|
|
1009
|
+
<input
|
|
1010
|
+
className="femo-comp-var-input"
|
|
1011
|
+
value={varValues[name] ?? ''}
|
|
1012
|
+
placeholder="留空=不赋值"
|
|
1013
|
+
spellCheck={false}
|
|
1014
|
+
onChange={(e) => { setVarValue(name, e.currentTarget.value) }}
|
|
1015
|
+
/>
|
|
1016
|
+
</div>
|
|
1017
|
+
))}
|
|
1018
|
+
<button
|
|
1019
|
+
type="button"
|
|
1020
|
+
className="femo-comp-var-confirm"
|
|
1021
|
+
disabled={busy}
|
|
1022
|
+
onMouseDown={keepFocus}
|
|
1023
|
+
onClick={confirmVars}
|
|
1024
|
+
>
|
|
1025
|
+
<FaCircleCheck size={13} />
|
|
1026
|
+
<span>{busy ? '发送中' : '确认赋值并发送'}</span>
|
|
1027
|
+
</button>
|
|
1028
|
+
</div>
|
|
1029
|
+
)}
|
|
1030
|
+
</div>
|
|
1031
|
+
)}
|
|
929
1032
|
<div className="femo-comp-scroll" data-input-scroll="">
|
|
930
1033
|
<div className="femo-comp-grow">
|
|
931
1034
|
<div aria-hidden className="femo-comp-mirror" data-input-mirror="">{`${text}\n`}</div>
|
|
@@ -973,7 +1076,7 @@ export function ProjectionComposer({ useSession, useSessions, getSessionFace }:
|
|
|
973
1076
|
onMouseDown={keepFocus}
|
|
974
1077
|
onClick={buttonState === 'stop'
|
|
975
1078
|
? () => { void mainFace?.cancel?.()?.catch(() => { /* 失败经主会话快照 promptError 呈现(官方 stop 同语义) */ }) }
|
|
976
|
-
: submit}
|
|
1079
|
+
: () => { submit() }}
|
|
977
1080
|
>
|
|
978
1081
|
{/* 官方 InputBar 同款 glyph:stop=方块 Stop(primaryStops),
|
|
979
1082
|
send/disabled=箭头 Send(箭头态由按钮 disabled 样式置灰)。 */}
|
|
@@ -133,6 +133,23 @@ const FEMO_COMPOSER_CSS = `
|
|
|
133
133
|
.femo-comp-meter-row{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:2px 0}
|
|
134
134
|
.femo-comp-meter-row dt{color:var(--dsw-alias-label-secondary)}
|
|
135
135
|
.femo-comp-meter-row dd{margin:0;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary)}
|
|
136
|
+
/* 变量赋值浮层(2026-09-14):等待人类节点且节点声明 out 时,输入框上方的
|
|
137
|
+
fa-code 小按钮 + 向上弹出的「变量名 = 输入框」列表;确认钮=FaCircleCheck。 */
|
|
138
|
+
.femo-comp-var-bar{position:relative;display:flex;padding:0 8px;align-items:center}
|
|
139
|
+
.femo-comp-var-trigger{display:inline-flex;align-items:center;gap:5px;height:24px;padding:0 8px;border:none;border-radius:12px;outline:none;background:transparent;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:16px;font-family:inherit;cursor:pointer}
|
|
140
|
+
.femo-comp-var-trigger:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
141
|
+
.femo-comp-var-trigger:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-border-l3)}
|
|
142
|
+
.femo-comp-var-trigger[data-open='true']{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
143
|
+
.femo-comp-var-panel{position:absolute;bottom:calc(100% + 6px);left:8px;z-index:100;box-sizing:border-box;min-width:260px;max-width:min(420px,calc(100% - 16px));padding:10px 12px 12px;border:1px solid var(--dsw-alias-border-inverted);border-radius:12px;background:var(--dsw-specific-menu);box-shadow:var(--dsw-shadow-lv3);font-size:13px;line-height:20px;color:var(--dsw-alias-label-secondary);cursor:default}
|
|
144
|
+
.femo-comp-var-head{margin-bottom:8px;font-weight:500;color:var(--dsw-alias-label-primary)}
|
|
145
|
+
.femo-comp-var-row{display:flex;align-items:center;gap:8px;padding:3px 0}
|
|
146
|
+
.femo-comp-var-name{max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--dsw-font-mono,ui-monospace,monospace);color:var(--dsw-alias-label-primary)}
|
|
147
|
+
.femo-comp-var-eq{flex:none;color:var(--dsw-alias-label-tertiary)}
|
|
148
|
+
.femo-comp-var-input{flex:1 1 auto;min-width:0;box-sizing:border-box;height:28px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2-darkmode-thin);border-radius:8px;outline:none;background:var(--dsw-specific-input-major);color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px;font-family:inherit}
|
|
149
|
+
.femo-comp-var-input:focus{border-color:var(--dsw-alias-state-business-primary)}
|
|
150
|
+
.femo-comp-var-confirm{display:inline-flex;align-items:center;gap:5px;margin-top:10px;height:28px;padding:0 12px;border:none;border-radius:999px;outline:none;background:var(--dsw-alias-button-info-fill,#3964FE);color:#fff;font-size:12px;line-height:16px;font-weight:500;font-family:inherit;cursor:pointer;transition:background-color 100ms ease}
|
|
151
|
+
.femo-comp-var-confirm:hover{background:var(--dsw-alias-button-info-hover)}
|
|
152
|
+
.femo-comp-var-confirm:disabled{opacity:.4;cursor:default}
|
|
136
153
|
`
|
|
137
154
|
|
|
138
155
|
export function ensureFemoStreamStyles(): void {
|
|
@@ -110,3 +110,6 @@ export const FaBullhorn = make("0 0 512 512", "M480 32c0-12.9-7.8-24.6-19.8-29.6
|
|
|
110
110
|
|
|
111
111
|
/** fa--wrench — Font Awesome Free 6.5.2 (CC BY 4.0, Fonticons Inc.) */
|
|
112
112
|
export const FaWrench = make("0 0 512 512", "M352 320c88.4 0 160-71.6 160-160c0-15.3-2.2-30.1-6.2-44.2c-3.1-10.8-16.4-13.2-24.3-5.3l-76.8 76.8c-3 3-7.1 4.7-11.3 4.7H336c-8.8 0-16-7.2-16-16V118.6c0-4.2 1.7-8.3 4.7-11.3l76.8-76.8c7.9-7.9 5.4-21.2-5.3-24.3C382.1 2.2 367.3 0 352 0C263.6 0 192 71.6 192 160c0 19.1 3.4 37.5 9.5 54.5L19.9 396.1C7.2 408.8 0 426.1 0 444.1C0 481.6 30.4 512 67.9 512c18 0 35.3-7.2 48-19.9L297.5 310.5c17 6.2 35.4 9.5 54.5 9.5zM80 408a24 24 0 1 1 0 48 24 24 0 1 1 0-48z")
|
|
113
|
+
|
|
114
|
+
/** fa--code — Font Awesome Free 6.5.2 (CC BY 4.0, Fonticons Inc.) */
|
|
115
|
+
export const FaCode = make("0 0 640 512", "M392.8 1.2c-17-4.9-34.7 5-39.6 22l-128 448c-4.9 17 5 34.7 22 39.6s34.7-5 39.6-22l128-448c4.9-17-5-34.7-22-39.6zm80.6 120.1c-12.5 12.5-12.5 32.8 0 45.3L562.7 256l-89.4 89.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l112-112c12.5-12.5 12.5-32.8 0-45.3l-112-112c-12.5-12.5-32.8-12.5-45.3 0zm-306.7 0c-12.5-12.5-32.8-12.5-45.3 0l-112 112c-12.5 12.5-12.5 32.8 0 45.3l112 112c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l89.4-89.4c12.5-12.5 12.5-32.8 0-45.3z")
|
|
@@ -234,6 +234,9 @@ export interface ProjectionRunState {
|
|
|
234
234
|
waitScope: string[]
|
|
235
235
|
/** 轮到人类节点时的提示全文(composer 内嵌等待横幅的数据源;非等待缺省)。 */
|
|
236
236
|
prompt?: string
|
|
237
|
+
/** 等待人类节点声明的 out 变量名列表(composer 变量赋值浮层的数据源;
|
|
238
|
+
* dynamic out 为 `变量名.@actor` 完整形式,human_wait 事件自带;非等待为 [])。 */
|
|
239
|
+
outVars: string[]
|
|
237
240
|
}
|
|
238
241
|
|
|
239
242
|
export function projectionStateOf(runState: RunState, mainSid: string): ProjectionRunState {
|
|
@@ -247,7 +250,7 @@ export function projectionStateOf(runState: RunState, mainSid: string): Projecti
|
|
|
247
250
|
? job.waitingHuman?.waitScope
|
|
248
251
|
?? (job.waitingHuman?.nodeName !== undefined ? job.nodeScopes.get(job.waitingHuman.nodeName) ?? [] : [])
|
|
249
252
|
: []
|
|
250
|
-
return { running, waiting, waitScope, ...(waiting ? { prompt: job.waitingHuman?.prompt } : {}) }
|
|
253
|
+
return { running, waiting, waitScope, outVars: waiting ? job.waitingHuman?.outVars ?? [] : [], ...(waiting ? { prompt: job.waitingHuman?.prompt } : {}) }
|
|
251
254
|
}
|
|
252
255
|
|
|
253
256
|
/** 快照广播(SSE projection_state,信封 sid=主会话):waitingHuman 变化与
|
|
@@ -76,6 +76,7 @@ import { apiRetry } from './api-retry'
|
|
|
76
76
|
import { activeChildRuns, abortAllSubagents } from './subagent'
|
|
77
77
|
import { disposeMainDeliveries, isMainAnswerPending, mainActorSceneActor, pendingNodeName } from './main-actor'
|
|
78
78
|
import { broker } from './node-retry'
|
|
79
|
+
import { installFemoPreset } from './preset-install'
|
|
79
80
|
|
|
80
81
|
declare module '@deepseek-ai/dsh-session/types' {
|
|
81
82
|
interface SessionEventMap {
|
|
@@ -115,6 +116,10 @@ export async function apply(ctx: Context, config: unknown): Promise<void> {
|
|
|
115
116
|
console.log('[femo-plugin] disabled by config')
|
|
116
117
|
return
|
|
117
118
|
}
|
|
119
|
+
// 先于一切会话加载:把随插件打包的 FEMO preset 镜像到 dsh home 的
|
|
120
|
+
// .agent-presets/femo-plugin/,模式菜单里才有「FEMO模式」可选
|
|
121
|
+
// (issue #1:preset 从前只活在开发者自己的 dsh-home,普通用户装完没有)。
|
|
122
|
+
console.log(`[femo-plugin] preset install: ${installFemoPreset()}`)
|
|
118
123
|
// 全局默认模型选择(用户在模型选择 UI 保存的推理等级在这里);
|
|
119
124
|
// 子 agent 不走 apiproxy 的 selection 安装,需要手动注入。
|
|
120
125
|
const defaultModel = ctx.get('agentDefaultModel') as
|