@yyc3/ai-family-kernel 0.0.0-stage → 2.54.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.
- package/README.md +11 -2
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/index.d.ts +24 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/index.js +24 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-1-foundation/foundation-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-1-foundation/foundation-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-1-foundation/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-1-foundation/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-2-bole/bole-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-2-bole/bole-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-2-bole/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-2-bole/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-3-prophet/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-3-prophet/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-3-prophet/prophet-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-3-prophet/prophet-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-4-thinker/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-4-thinker/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-4-thinker/thinker-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-4-thinker/thinker-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-5-navigator/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-5-navigator/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-5-navigator/navigator-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-5-navigator/navigator-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-6-creative/creative-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-6-creative/creative-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-6-creative/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-6-creative/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-7-master/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-7-master/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-7-master/master-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-7-master/master-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-8-guardian/guardian-capability.d.ts +16 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-8-guardian/guardian-capability.js +29 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-8-guardian/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-8-guardian/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-9-meta-oracle/index.d.ts +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-9-meta-oracle/index.js +4 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-9-meta-oracle/meta-oracle-capability.d.ts +17 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-9-meta-oracle/meta-oracle-capability.js +30 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-registry.d.ts +34 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/layer-registry.js +76 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/types.d.ts +49 -0
- package/dist/src/01-/344/271/235/345/261/202/346/236/266/346/236/204/345/210/206/345/261/202/345/272/225/345/272/247/types.js +33 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/index.d.ts +7 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/index.js +7 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/orchestrator.d.ts +47 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/orchestrator.js +59 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/task-decomposer.d.ts +21 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/task-decomposer.js +72 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/confidence-calibrator.d.ts +31 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/confidence-calibrator.js +39 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/consistency-metrics.d.ts +45 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/consistency-metrics.js +44 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/cross-validator.d.ts +44 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/cross-validator.js +69 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/gateway.d.ts +64 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/gateway.js +96 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/ground-truth-checker.d.ts +33 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/ground-truth-checker.js +74 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/index.d.ts +12 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/index.js +12 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/oracle-registry.d.ts +18 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/cloud-pivot-orchestrator/verification-gateway/oracle-registry.js +26 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/dashu-self-healing/index.d.ts +5 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/dashu-self-healing/index.js +5 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/dashu-self-healing/self-healing-controller.d.ts +33 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/dashu-self-healing/self-healing-controller.js +68 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-communication-bus/event-bus.d.ts +99 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-communication-bus/event-bus.js +178 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-communication-bus/index.d.ts +7 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-communication-bus/index.js +7 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-communication-bus/trajectory-bridge.d.ts +57 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-communication-bus/trajectory-bridge.js +72 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-phone-system/index.d.ts +4 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-phone-system/index.js +4 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-phone-system/phone-system.d.ts +46 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/family-phone-system/phone-system.js +85 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/global-status-center/index.d.ts +4 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/global-status-center/index.js +4 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/global-status-center/status-center.d.ts +27 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/global-status-center/status-center.js +57 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/index.d.ts +21 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/index.js +21 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/bus-mcp-codec.d.ts +29 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/bus-mcp-codec.js +84 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/index.d.ts +31 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/index.js +28 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/server/index.d.ts +5 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/server/index.js +5 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/server/protocol.d.ts +80 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/server/protocol.js +148 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/stdio-transport.d.ts +47 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/stdio-transport.js +178 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/types.d.ts +63 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/mcp-adapter/types.js +7 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/types.d.ts +167 -0
- package/dist/src/02-/344/272/221/346/236/242/346/240/270/345/277/203/345/274/225/346/223/216/types.js +23 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/index.d.ts +7 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/index.js +7 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/outcome-labeler.d.ts +34 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/outcome-labeler.js +38 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/pattern-extractor.d.ts +64 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/pattern-extractor.js +94 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/trajectory-collector.d.ts +39 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/experience-reflow/trajectory-collector.js +36 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/index.d.ts +23 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/index.js +23 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/index.d.ts +7 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/index.js +7 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/preference-tracker.d.ts +32 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/preference-tracker.js +49 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/rule-evolution.d.ts +41 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/rule-evolution.js +60 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/semantic-diff.d.ts +32 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/knowledge-update/semantic-diff.js +69 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-loop.d.ts +146 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-loop.js +171 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-scheduler/budget-allocator.d.ts +29 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-scheduler/budget-allocator.js +58 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-scheduler/index.d.ts +6 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-scheduler/index.js +6 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-scheduler/priority-queue.d.ts +22 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/learning-scheduler/priority-queue.js +34 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/param-adaptation.d.ts +59 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/param-adaptation.js +55 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/index.d.ts +12 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/index.js +12 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-eval.d.ts +77 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-eval.js +110 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-executor.d.ts +51 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-executor.js +63 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-id.d.ts +32 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-id.js +54 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-index.d.ts +29 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-index.js +32 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-merger.d.ts +26 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-merger.js +65 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-pruner.d.ts +31 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-pruner.js +35 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-store-file.d.ts +33 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-store-file.js +76 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-versioner.d.ts +33 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/skill-consolidation/skill-versioner.js +63 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/forgetting-detector.d.ts +31 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/forgetting-detector.js +26 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/index.d.ts +7 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/index.js +7 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/regression-tester.d.ts +30 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/regression-tester.js +48 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/rollback-controller.d.ts +19 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/stability-guard/rollback-controller.js +19 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/types.d.ts +137 -0
- package/dist/src/05-/346/214/201/347/273/255/345/255/246/344/271/240/345/274/225/346/223/216/types.js +22 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/compliance-audit/compliance-audit.d.ts +20 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/compliance-audit/compliance-audit.js +83 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/compliance-audit/index.d.ts +4 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/compliance-audit/index.js +4 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/index.d.ts +18 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/index.js +18 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/index.d.ts +6 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/index.js +6 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/policy-bus.d.ts +39 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/policy-bus.js +73 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/policy-registry.d.ts +19 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/policy-registry.js +44 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/security-policies.d.ts +54 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/policy-registry/security-policies.js +80 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/quality-governance/index.d.ts +4 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/quality-governance/index.js +4 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/quality-governance/quality-governance.d.ts +23 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/quality-governance/quality-governance.js +38 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/security-governance/index.d.ts +4 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/security-governance/index.js +4 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/security-governance/security-governance.d.ts +24 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/security-governance/security-governance.js +29 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/types.d.ts +77 -0
- package/dist/src/06-/346/262/273/347/220/206/344/270/255/345/277/203/types.js +17 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/consistency-repair/consistency-repair.d.ts +25 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/consistency-repair/consistency-repair.js +66 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/consistency-repair/index.d.ts +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/consistency-repair/index.js +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/degradation-controller/degradation-controller.d.ts +50 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/degradation-controller/degradation-controller.js +90 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/degradation-controller/index.d.ts +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/degradation-controller/index.js +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/fault-detector/fault-detector.d.ts +42 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/fault-detector/fault-detector.js +55 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/fault-detector/index.d.ts +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/fault-detector/index.js +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/index.d.ts +19 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/index.js +19 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/rollback-controller/index.d.ts +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/rollback-controller/index.js +4 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/rollback-controller/rollback-controller.d.ts +36 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/rollback-controller/rollback-controller.js +71 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/types.d.ts +73 -0
- package/dist/src/07-/350/207/252/346/204/210/344/270/255/345/277/203/types.js +63 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/index.d.ts +5 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/index.js +5 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/mcp-server-assembly.d.ts +48 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/mcp-server-assembly.js +53 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/runtime-assembly.d.ts +175 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/runtime-assembly.js +249 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/runtime-entry.d.ts +68 -0
- package/dist/src/08-/347/263/273/347/273/237/350/243/205/351/205/215/runtime-entry.js +86 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/capability-instrumentation.d.ts +53 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/capability-instrumentation.js +85 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/collaboration-instrumentation.d.ts +56 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/collaboration-instrumentation.js +100 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/family-metrics.d.ts +172 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/family-metrics.js +314 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/index.d.ts +8 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/index.js +8 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/metrics-registry.d.ts +123 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/metrics-registry.js +270 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/metrics-server.d.ts +45 -0
- package/dist/src/09-/345/217/257/350/247/202/346/265/213/346/200/247/metrics-server.js +86 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/allowlist.d.ts +79 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/allowlist.js +122 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/catalog.d.ts +67 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/catalog.js +71 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/index.d.ts +14 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/index.js +10 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/integrity.d.ts +44 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/integrity.js +99 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/plugin-loader.d.ts +39 -0
- package/dist/src/10-/350/203/275/345/212/233/346/263/250/345/206/214/344/270/255/345/277/203/plugin-loader.js +89 -0
- package/dist/src/a2a-adapter/card-discovery.d.ts +40 -0
- package/dist/src/a2a-adapter/card-discovery.js +47 -0
- package/dist/src/a2a-adapter/index.d.ts +7 -0
- package/dist/src/a2a-adapter/index.js +7 -0
- package/dist/src/a2a-adapter/task-delegate.d.ts +85 -0
- package/dist/src/a2a-adapter/task-delegate.js +94 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +10 -0
- package/dist/vendor/memory-framework/episodic-store/episode-indexer.d.ts +30 -0
- package/dist/vendor/memory-framework/episodic-store/episode-indexer.js +45 -0
- package/dist/vendor/memory-framework/episodic-store/index.d.ts +30 -0
- package/dist/vendor/memory-framework/episodic-store/index.js +45 -0
- package/dist/vendor/memory-framework/episodic-store/retrieval-adapter.d.ts +20 -0
- package/dist/vendor/memory-framework/episodic-store/retrieval-adapter.js +29 -0
- package/dist/vendor/memory-framework/episodic-store/trajectory-logger.d.ts +36 -0
- package/dist/vendor/memory-framework/episodic-store/trajectory-logger.js +32 -0
- package/dist/vendor/memory-framework/index.d.ts +19 -0
- package/dist/vendor/memory-framework/index.js +19 -0
- package/dist/vendor/memory-framework/memory-orchestrator/consistency-checker.d.ts +20 -0
- package/dist/vendor/memory-framework/memory-orchestrator/consistency-checker.js +41 -0
- package/dist/vendor/memory-framework/memory-orchestrator/index.d.ts +55 -0
- package/dist/vendor/memory-framework/memory-orchestrator/index.js +185 -0
- package/dist/vendor/memory-framework/memory-orchestrator/retrieval-router.d.ts +21 -0
- package/dist/vendor/memory-framework/memory-orchestrator/retrieval-router.js +37 -0
- package/dist/vendor/memory-framework/procedural-memory/guardrail-registry.d.ts +34 -0
- package/dist/vendor/memory-framework/procedural-memory/guardrail-registry.js +22 -0
- package/dist/vendor/memory-framework/procedural-memory/index.d.ts +31 -0
- package/dist/vendor/memory-framework/procedural-memory/index.js +34 -0
- package/dist/vendor/memory-framework/procedural-memory/prompt-rule-extractor.d.ts +95 -0
- package/dist/vendor/memory-framework/procedural-memory/prompt-rule-extractor.js +160 -0
- package/dist/vendor/memory-framework/procedural-memory/skill-registry.d.ts +115 -0
- package/dist/vendor/memory-framework/procedural-memory/skill-registry.js +165 -0
- package/dist/vendor/memory-framework/procedural-memory/workflow-patterns.d.ts +36 -0
- package/dist/vendor/memory-framework/procedural-memory/workflow-patterns.js +22 -0
- package/dist/vendor/memory-framework/semantic-graph/entity-resolver.d.ts +26 -0
- package/dist/vendor/memory-framework/semantic-graph/entity-resolver.js +61 -0
- package/dist/vendor/memory-framework/semantic-graph/index.d.ts +23 -0
- package/dist/vendor/memory-framework/semantic-graph/index.js +25 -0
- package/dist/vendor/memory-framework/semantic-graph/knowledge-graph.d.ts +50 -0
- package/dist/vendor/memory-framework/semantic-graph/knowledge-graph.js +44 -0
- package/dist/vendor/memory-framework/sensory-buffer/index.d.ts +41 -0
- package/dist/vendor/memory-framework/sensory-buffer/index.js +70 -0
- package/dist/vendor/memory-framework/types.d.ts +192 -0
- package/dist/vendor/memory-framework/types.js +42 -0
- package/dist/vendor/memory-framework/working-context/attention-scorer.d.ts +39 -0
- package/dist/vendor/memory-framework/working-context/attention-scorer.js +45 -0
- package/dist/vendor/memory-framework/working-context/context-window.d.ts +33 -0
- package/dist/vendor/memory-framework/working-context/context-window.js +35 -0
- package/dist/vendor/memory-framework/working-context/index.d.ts +30 -0
- package/dist/vendor/memory-framework/working-context/index.js +44 -0
- package/dist/vendor/memory-framework/write-policy/consolidation.d.ts +37 -0
- package/dist/vendor/memory-framework/write-policy/consolidation.js +50 -0
- package/dist/vendor/memory-framework/write-policy/forgetting-policy.d.ts +28 -0
- package/dist/vendor/memory-framework/write-policy/forgetting-policy.js +31 -0
- package/dist/vendor/memory-framework/write-policy/index.d.ts +40 -0
- package/dist/vendor/memory-framework/write-policy/index.js +50 -0
- package/dist/vendor/memory-framework/write-policy/salience-scorer.d.ts +41 -0
- package/dist/vendor/memory-framework/write-policy/salience-scorer.js +70 -0
- package/dist/vendor/self-judge-kit/assumption-tracker.d.ts +31 -0
- package/dist/vendor/self-judge-kit/assumption-tracker.js +45 -0
- package/dist/vendor/self-judge-kit/confidence-scorer.d.ts +46 -0
- package/dist/vendor/self-judge-kit/confidence-scorer.js +60 -0
- package/dist/vendor/self-judge-kit/deviation-detector.d.ts +23 -0
- package/dist/vendor/self-judge-kit/deviation-detector.js +55 -0
- package/dist/vendor/self-judge-kit/escalation-policy.d.ts +17 -0
- package/dist/vendor/self-judge-kit/escalation-policy.js +45 -0
- package/dist/vendor/self-judge-kit/index.d.ts +46 -0
- package/dist/vendor/self-judge-kit/index.js +79 -0
- package/dist/vendor/self-judge-kit/types.d.ts +87 -0
- package/dist/vendor/self-judge-kit/types.js +18 -0
- package/package.json +41 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 总线事件 ↔ MCP 消息编解码(bus-mcp-codec)—— P1-T3。
|
|
3
|
+
* 职责:把内部 BusEvent 编码为 MCP JSON-RPC 通知,并把入站 MCP 消息解码回 BusEvent。
|
|
4
|
+
* 边界:只做形状转换与字段校验;路由、重试、死信归 EventBus。
|
|
5
|
+
*
|
|
6
|
+
* 线上形状(method 可配,默认 `yyc3/event`):
|
|
7
|
+
* {"jsonrpc":"2.0","method":"yyc3/event","params":{"key":{...},"topic":"...","mode":"...","target":"...","payload":{},"at":0}}
|
|
8
|
+
*/
|
|
9
|
+
const MODES = ['point-to-point', 'broadcast'];
|
|
10
|
+
/**
|
|
11
|
+
* 总线事件 MCP 编解码器。
|
|
12
|
+
* encode 失败抛出(调用方决定是否阻断);decode 失败抛出(EventBus 统一入 DLQ)。
|
|
13
|
+
*/
|
|
14
|
+
export class BusMcpCodec {
|
|
15
|
+
id;
|
|
16
|
+
method;
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.id = options.id ?? 'bus';
|
|
19
|
+
this.method = options.method ?? 'yyc3/event';
|
|
20
|
+
}
|
|
21
|
+
/** BusEvent → MCP JSON-RPC 通知。 */
|
|
22
|
+
encode(event) {
|
|
23
|
+
if (!event.topic)
|
|
24
|
+
throw new Error('BusEvent.topic 不能为空');
|
|
25
|
+
if (!MODES.includes(event.mode))
|
|
26
|
+
throw new Error(`不支持的投递模式:${String(event.mode)}`);
|
|
27
|
+
if (event.mode === 'point-to-point' && !event.target) {
|
|
28
|
+
throw new Error('点对点事件缺少 target');
|
|
29
|
+
}
|
|
30
|
+
const params = {
|
|
31
|
+
key: event.key,
|
|
32
|
+
topic: event.topic,
|
|
33
|
+
mode: event.mode,
|
|
34
|
+
...(event.target ? { target: event.target } : {}),
|
|
35
|
+
payload: event.payload,
|
|
36
|
+
at: event.at,
|
|
37
|
+
};
|
|
38
|
+
return { jsonrpc: '2.0', method: this.method, params };
|
|
39
|
+
}
|
|
40
|
+
/** MCP JSON-RPC 通知 → BusEvent。 */
|
|
41
|
+
decode(raw) {
|
|
42
|
+
if (!isRecord(raw))
|
|
43
|
+
throw new Error('MCP 消息必须是对象');
|
|
44
|
+
if (raw.jsonrpc !== '2.0')
|
|
45
|
+
throw new Error('不是 JSON-RPC 2.0 消息');
|
|
46
|
+
if (raw.method !== this.method) {
|
|
47
|
+
throw new Error(`不支持的方法:${String(raw.method)}(期望 ${this.method})`);
|
|
48
|
+
}
|
|
49
|
+
const params = raw.params;
|
|
50
|
+
if (!isRecord(params))
|
|
51
|
+
throw new Error('MCP 消息缺少 params');
|
|
52
|
+
const key = params.key;
|
|
53
|
+
if (!isRecord(key))
|
|
54
|
+
throw new Error('params.key 缺失');
|
|
55
|
+
if (typeof key.traceId !== 'string' || key.traceId === '')
|
|
56
|
+
throw new Error('params.key.traceId 非法');
|
|
57
|
+
if (typeof key.agentId !== 'string' || key.agentId === '')
|
|
58
|
+
throw new Error('params.key.agentId 非法');
|
|
59
|
+
if (!Number.isInteger(key.seq) || key.seq < 0)
|
|
60
|
+
throw new Error('params.key.seq 非法');
|
|
61
|
+
if (typeof params.topic !== 'string' || params.topic === '')
|
|
62
|
+
throw new Error('params.topic 非法');
|
|
63
|
+
if (!MODES.includes(params.mode))
|
|
64
|
+
throw new Error(`params.mode 非法:${String(params.mode)}`);
|
|
65
|
+
if (params.mode === 'point-to-point' && (typeof params.target !== 'string' || params.target === '')) {
|
|
66
|
+
throw new Error('点对点消息缺少 params.target');
|
|
67
|
+
}
|
|
68
|
+
if (!('payload' in params))
|
|
69
|
+
throw new Error('params.payload 缺失');
|
|
70
|
+
if (typeof params.at !== 'number' || !Number.isFinite(params.at))
|
|
71
|
+
throw new Error('params.at 非法');
|
|
72
|
+
return {
|
|
73
|
+
key: { traceId: key.traceId, agentId: key.agentId, seq: key.seq },
|
|
74
|
+
topic: params.topic,
|
|
75
|
+
mode: params.mode,
|
|
76
|
+
...(typeof params.target === 'string' && params.target !== '' ? { target: params.target } : {}),
|
|
77
|
+
payload: params.payload,
|
|
78
|
+
at: params.at,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function isRecord(value) {
|
|
83
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
84
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 适配层入口(mcp-adapter/index)—— P1-T3。
|
|
3
|
+
* 职责:导出编解码器、stdio 传输与「传输 ↔ 总线」绑定器。
|
|
4
|
+
* 边界:MCP 为对外接入标准;内部路由与死信归 EventBus。
|
|
5
|
+
*/
|
|
6
|
+
import type { BusEvent, McpAdapter } from '../types.js';
|
|
7
|
+
import type { EventBus } from '../family-communication-bus/event-bus.js';
|
|
8
|
+
import type { McpTransport } from './types.js';
|
|
9
|
+
export type { McpJsonRpcRequest, McpJsonRpcNotification, McpJsonRpcResponse, McpJsonRpcError, McpMessageHandler, McpStderrHandler, McpTransport, StdioTransportOptions, } from './types.js';
|
|
10
|
+
export { BusMcpCodec } from './bus-mcp-codec.js';
|
|
11
|
+
export type { BusMcpCodecOptions } from './bus-mcp-codec.js';
|
|
12
|
+
export { StdioMcpTransport } from './stdio-transport.js';
|
|
13
|
+
export * from './server/index.js';
|
|
14
|
+
/** 绑定选项。 */
|
|
15
|
+
export interface McpBindingOptions {
|
|
16
|
+
readonly bus: EventBus;
|
|
17
|
+
readonly adapter: McpAdapter;
|
|
18
|
+
readonly transport: McpTransport;
|
|
19
|
+
}
|
|
20
|
+
/** 绑定句柄。 */
|
|
21
|
+
export interface McpBinding {
|
|
22
|
+
/** 把内部事件编码后发往对端。 */
|
|
23
|
+
send(event: BusEvent): void;
|
|
24
|
+
/** 解绑入站监听并关闭传输。 */
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 绑定「传输 ↔ 总线」:入站消息交给 `bus.ingestMcp`(解码失败入 DLQ),
|
|
29
|
+
* 出站事件经 `adapter.encode` 后写入传输。单向依赖:适配层 → 总线。
|
|
30
|
+
*/
|
|
31
|
+
export declare function bindMcpTransport(options: McpBindingOptions): McpBinding;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 适配层入口(mcp-adapter/index)—— P1-T3。
|
|
3
|
+
* 职责:导出编解码器、stdio 传输与「传输 ↔ 总线」绑定器。
|
|
4
|
+
* 边界:MCP 为对外接入标准;内部路由与死信归 EventBus。
|
|
5
|
+
*/
|
|
6
|
+
export { BusMcpCodec } from './bus-mcp-codec.js';
|
|
7
|
+
export { StdioMcpTransport } from './stdio-transport.js';
|
|
8
|
+
export * from './server/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* 绑定「传输 ↔ 总线」:入站消息交给 `bus.ingestMcp`(解码失败入 DLQ),
|
|
11
|
+
* 出站事件经 `adapter.encode` 后写入传输。单向依赖:适配层 → 总线。
|
|
12
|
+
*/
|
|
13
|
+
export function bindMcpTransport(options) {
|
|
14
|
+
const { bus, adapter, transport } = options;
|
|
15
|
+
const unsubscribe = transport.onMessage((raw) => {
|
|
16
|
+
// 解码失败与处理器失败均由总线内部消化(DLQ),此处不向事件循环抛出
|
|
17
|
+
void bus.ingestMcp(adapter.id, raw);
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
send(event) {
|
|
21
|
+
transport.send(adapter.encode(event));
|
|
22
|
+
},
|
|
23
|
+
async close() {
|
|
24
|
+
unsubscribe();
|
|
25
|
+
await transport.close();
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 服务端协议语义(mcp-adapter/server/protocol)—— P3-MCP + P4-T5。
|
|
3
|
+
* 职责:无状态 JSON-RPC 2.0 方法分派——initialize / ping / tools/list / tools/call。
|
|
4
|
+
* 边界:对齐 MCP 2026-07-28 规范的最小子集;工具目录由部署侧注入(P4-T5:
|
|
5
|
+
* `scripts/gen-mcp-tools.mjs` 由 manifest 派生 assets/mcp-tools.json),
|
|
6
|
+
* 内核不反向依赖 family-agents / presets(单向依赖:server → types)。
|
|
7
|
+
* 治理:`visible` 过滤未准入工具(tools/list 与 tools/call 同源),
|
|
8
|
+
* `policy` 在分派前裁决(可接 CapabilityAllowlist / PolicyRegistry)。
|
|
9
|
+
* 红线:零运行时依赖,仅 node 标准 JSON 能力;通知类消息不产生响应行。
|
|
10
|
+
*/
|
|
11
|
+
/** 本实现锚定的 MCP 规范版本(2026-07-28:无状态核心 + 可缓存列表)。 */
|
|
12
|
+
export declare const MCP_PROTOCOL_VERSION = "2026-07-28";
|
|
13
|
+
/** MCP 工具描述符(tools/list 单项)。 */
|
|
14
|
+
export interface McpToolDescriptor {
|
|
15
|
+
/** 工具名:MCP 规范要求 `^[a-zA-Z0-9_-]+$`(家族 id 的 `.` 由部署侧映射为 `__`)。 */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly description: string;
|
|
18
|
+
/** JSON Schema 形状的输入描述。 */
|
|
19
|
+
readonly inputSchema: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** 服务端自描述信息(initialize 回显)。 */
|
|
22
|
+
export interface McpServerInfo {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly version: string;
|
|
25
|
+
}
|
|
26
|
+
/** W3C Trace Context 解析结果(traceparent 头)。 */
|
|
27
|
+
export interface TraceContext {
|
|
28
|
+
readonly traceId: string;
|
|
29
|
+
readonly spanId: string;
|
|
30
|
+
readonly flags: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 严格解析 W3C `traceparent`(M21 关联维):`00-<32hex traceId>-<16hex spanId>-<2hex flags>`;
|
|
34
|
+
* 版本 ff、全零 traceId/spanId、长度或字符集不符 → null(调用方按未携带处理,不炸协议层)。
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseTraceparent(header: string): TraceContext | null;
|
|
37
|
+
/** tools/call 上下文(策略裁决与分派共用)。 */
|
|
38
|
+
export interface McpToolCallContext {
|
|
39
|
+
readonly toolName: string;
|
|
40
|
+
/** 工具入参(缺省 `{}`)。 */
|
|
41
|
+
readonly args: unknown;
|
|
42
|
+
/** 可选链路 / 主体(部署侧经 `params._meta` 注入);traceId 优先级:显式 > traceparent 派生。 */
|
|
43
|
+
readonly traceId?: string;
|
|
44
|
+
readonly actor?: string;
|
|
45
|
+
/** W3C Trace Context(`_meta.traceparent` 严格解析通过时存在,M21)。 */
|
|
46
|
+
readonly traceparent?: TraceContext;
|
|
47
|
+
}
|
|
48
|
+
/** 策略裁决(tools/call 唯一闸门;`admitted=false` 即拒绝)。 */
|
|
49
|
+
export interface McpToolPolicyDecision {
|
|
50
|
+
readonly admitted: boolean;
|
|
51
|
+
readonly reason?: string;
|
|
52
|
+
}
|
|
53
|
+
/** 工具调用策略(可接 CapabilityAllowlist / PolicyRegistry 等治理实现)。 */
|
|
54
|
+
export type McpToolPolicy = (ctx: McpToolCallContext) => McpToolPolicyDecision;
|
|
55
|
+
/** 工具分派器:仅做路由 / 执行,返回可 JSON 序列化的同步结果或 Promise(M16 异步臂)。 */
|
|
56
|
+
export type McpToolDispatcher = (ctx: McpToolCallContext) => unknown;
|
|
57
|
+
/** 服务端选项。 */
|
|
58
|
+
export interface McpServerOptions {
|
|
59
|
+
readonly serverInfo: McpServerInfo;
|
|
60
|
+
/** 只读工具目录:构造期校验命名与唯一性(fail-fast)。 */
|
|
61
|
+
readonly tools: readonly McpToolDescriptor[];
|
|
62
|
+
/** 覆盖协议版本(默认 {@link MCP_PROTOCOL_VERSION})。 */
|
|
63
|
+
readonly protocolVersion?: string;
|
|
64
|
+
/** 可见性过滤(未准入工具不可见:tools/list 与 tools/call 同源过滤)。 */
|
|
65
|
+
readonly visible?: (tool: McpToolDescriptor) => boolean;
|
|
66
|
+
/** 工具调用策略(缺省全放行;拒绝时返回 `isError: true` 的工具结果)。 */
|
|
67
|
+
readonly policy?: McpToolPolicy;
|
|
68
|
+
/** 工具分派(未配置时 tools/call 回 -32603)。 */
|
|
69
|
+
readonly dispatch?: McpToolDispatcher;
|
|
70
|
+
}
|
|
71
|
+
/** 无状态请求处理器:一行请求 → 一行响应;通知返回 null。同步分派返回 string,
|
|
72
|
+
* 异步分派(返回 thenable,M16 LLM 语义执行臂)返回 Promise<string>。 */
|
|
73
|
+
export interface McpRequestHandler {
|
|
74
|
+
handle(raw: string): string | null | Promise<string | null>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 创建无状态 MCP 请求处理器。
|
|
78
|
+
* 不保留任何跨请求状态:同一输入恒得同一输出(幂等),可水平扩展。
|
|
79
|
+
*/
|
|
80
|
+
export declare function createMcpRequestHandler(options: McpServerOptions): McpRequestHandler;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 服务端协议语义(mcp-adapter/server/protocol)—— P3-MCP + P4-T5。
|
|
3
|
+
* 职责:无状态 JSON-RPC 2.0 方法分派——initialize / ping / tools/list / tools/call。
|
|
4
|
+
* 边界:对齐 MCP 2026-07-28 规范的最小子集;工具目录由部署侧注入(P4-T5:
|
|
5
|
+
* `scripts/gen-mcp-tools.mjs` 由 manifest 派生 assets/mcp-tools.json),
|
|
6
|
+
* 内核不反向依赖 family-agents / presets(单向依赖:server → types)。
|
|
7
|
+
* 治理:`visible` 过滤未准入工具(tools/list 与 tools/call 同源),
|
|
8
|
+
* `policy` 在分派前裁决(可接 CapabilityAllowlist / PolicyRegistry)。
|
|
9
|
+
* 红线:零运行时依赖,仅 node 标准 JSON 能力;通知类消息不产生响应行。
|
|
10
|
+
*/
|
|
11
|
+
/** 本实现锚定的 MCP 规范版本(2026-07-28:无状态核心 + 可缓存列表)。 */
|
|
12
|
+
export const MCP_PROTOCOL_VERSION = '2026-07-28';
|
|
13
|
+
const TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
|
|
14
|
+
/**
|
|
15
|
+
* 严格解析 W3C `traceparent`(M21 关联维):`00-<32hex traceId>-<16hex spanId>-<2hex flags>`;
|
|
16
|
+
* 版本 ff、全零 traceId/spanId、长度或字符集不符 → null(调用方按未携带处理,不炸协议层)。
|
|
17
|
+
*/
|
|
18
|
+
export function parseTraceparent(header) {
|
|
19
|
+
const m = (header ?? '').trim().toLowerCase().match(TRACEPARENT_RE);
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
const [, version, traceId, spanId, flags] = m;
|
|
23
|
+
if (version === 'ff')
|
|
24
|
+
return null;
|
|
25
|
+
if (/^0+$/.test(traceId) || /^0+$/.test(spanId))
|
|
26
|
+
return null;
|
|
27
|
+
return { traceId, spanId, flags };
|
|
28
|
+
}
|
|
29
|
+
function jsonError(id, code, message) {
|
|
30
|
+
const error = { code, message };
|
|
31
|
+
return JSON.stringify({ jsonrpc: '2.0', id, error });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 创建无状态 MCP 请求处理器。
|
|
35
|
+
* 不保留任何跨请求状态:同一输入恒得同一输出(幂等),可水平扩展。
|
|
36
|
+
*/
|
|
37
|
+
export function createMcpRequestHandler(options) {
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
for (const tool of options.tools) {
|
|
40
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(tool.name))
|
|
41
|
+
throw new Error(`MCP 工具名不合规(^[a-zA-Z0-9_-]+$):${tool.name}`);
|
|
42
|
+
if (seen.has(tool.name))
|
|
43
|
+
throw new Error(`MCP 工具名重复:${tool.name}`);
|
|
44
|
+
seen.add(tool.name);
|
|
45
|
+
}
|
|
46
|
+
// 可见性过滤(未准入工具不可见)——列表与调用共用同一集合,杜绝「列表隐藏但可调用」的泄漏
|
|
47
|
+
const visibleTools = options.tools.filter((tool) => options.visible?.(tool) ?? true);
|
|
48
|
+
const visibleByName = new Map(visibleTools.map((tool) => [tool.name, tool]));
|
|
49
|
+
const toolsResult = {
|
|
50
|
+
tools: visibleTools.map((t) => ({
|
|
51
|
+
name: t.name,
|
|
52
|
+
description: t.description,
|
|
53
|
+
inputSchema: t.inputSchema,
|
|
54
|
+
})),
|
|
55
|
+
};
|
|
56
|
+
const initializeResult = {
|
|
57
|
+
protocolVersion: options.protocolVersion ?? MCP_PROTOCOL_VERSION,
|
|
58
|
+
capabilities: { tools: { listChanged: false } },
|
|
59
|
+
serverInfo: options.serverInfo,
|
|
60
|
+
};
|
|
61
|
+
const toolResult = (text, isError) => ({ content: [{ type: 'text', text }], isError });
|
|
62
|
+
const isThenable = (v) => typeof v === 'object' && v !== null && typeof v.then === 'function';
|
|
63
|
+
const okResponse = (id, output) => JSON.stringify({ jsonrpc: '2.0', id, result: toolResult(JSON.stringify(output ?? null), false) });
|
|
64
|
+
const errResponse = (id, error) => JSON.stringify({
|
|
65
|
+
jsonrpc: '2.0',
|
|
66
|
+
id,
|
|
67
|
+
result: toolResult(error instanceof Error ? error.message : String(error), true),
|
|
68
|
+
});
|
|
69
|
+
/** tools/call:参数校验 → 可见性 → Policy 裁决 → 分派(同步快速路径;异步分派自动 await)。 */
|
|
70
|
+
const callTool = (id, params) => {
|
|
71
|
+
if (typeof params !== 'object' || params === null || Array.isArray(params)) {
|
|
72
|
+
return jsonError(id, -32602, 'Invalid params');
|
|
73
|
+
}
|
|
74
|
+
const { name, arguments: rawArgs, _meta: meta } = params;
|
|
75
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
76
|
+
return jsonError(id, -32602, 'Invalid params: missing tool name');
|
|
77
|
+
}
|
|
78
|
+
if (rawArgs !== undefined && (typeof rawArgs !== 'object' || rawArgs === null || Array.isArray(rawArgs))) {
|
|
79
|
+
return jsonError(id, -32602, 'Invalid params: arguments must be an object');
|
|
80
|
+
}
|
|
81
|
+
// 未知 / 未准入工具一律 -32602(不区分,避免泄露被隐藏工具的存在)
|
|
82
|
+
if (!visibleByName.has(name))
|
|
83
|
+
return jsonError(id, -32602, `Unknown tool: ${name}`);
|
|
84
|
+
if (!options.dispatch)
|
|
85
|
+
return jsonError(id, -32603, 'Tool dispatch not configured');
|
|
86
|
+
// W3C traceparent(M21 关联维):严格解析,非法即按未携带;traceId 优先级:显式 > 派生
|
|
87
|
+
const traceparent = typeof meta?.traceparent === 'string' ? parseTraceparent(meta.traceparent) : undefined;
|
|
88
|
+
const ctx = {
|
|
89
|
+
toolName: name,
|
|
90
|
+
args: rawArgs ?? {},
|
|
91
|
+
traceId: typeof meta?.traceId === 'string' && meta.traceId.length > 0
|
|
92
|
+
? meta.traceId
|
|
93
|
+
: (traceparent?.traceId ?? undefined),
|
|
94
|
+
actor: typeof meta?.actor === 'string' ? meta.actor : undefined,
|
|
95
|
+
...(traceparent ? { traceparent } : {}),
|
|
96
|
+
};
|
|
97
|
+
const verdict = options.policy?.(ctx);
|
|
98
|
+
if (verdict && !verdict.admitted) {
|
|
99
|
+
return JSON.stringify({
|
|
100
|
+
jsonrpc: '2.0',
|
|
101
|
+
id,
|
|
102
|
+
result: toolResult(verdict.reason ?? `Policy denied: ${name}`, true),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const output = options.dispatch(ctx);
|
|
107
|
+
// 同步分派走快速路径(既有消费者零变化);异步分派(LLM 臂等)自动 await
|
|
108
|
+
if (!isThenable(output))
|
|
109
|
+
return okResponse(id, output);
|
|
110
|
+
return output.then((resolved) => okResponse(id, resolved), (error) => errResponse(id, error));
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// 工具执行失败按 MCP 语义返回 isError 结果(不炸协议层)
|
|
114
|
+
return errResponse(id, error);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
handle(raw) {
|
|
119
|
+
let msg;
|
|
120
|
+
try {
|
|
121
|
+
msg = JSON.parse(raw);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return jsonError(null, -32700, 'Parse error');
|
|
125
|
+
}
|
|
126
|
+
if (typeof msg !== 'object' || msg === null || Array.isArray(msg) || typeof msg.method !== 'string') {
|
|
127
|
+
return jsonError(null, -32600, 'Invalid Request');
|
|
128
|
+
}
|
|
129
|
+
const { method, id, params } = msg;
|
|
130
|
+
const isRequest = 'id' in msg && id !== undefined && id !== null;
|
|
131
|
+
const respond = (result) => isRequest ? JSON.stringify({ jsonrpc: '2.0', id, result }) : null;
|
|
132
|
+
switch (method) {
|
|
133
|
+
case 'initialize':
|
|
134
|
+
return respond(initializeResult);
|
|
135
|
+
case 'ping':
|
|
136
|
+
return respond({});
|
|
137
|
+
case 'tools/list':
|
|
138
|
+
return respond(toolsResult);
|
|
139
|
+
case 'tools/call':
|
|
140
|
+
// 通知类不执行(无 id 的调用无响应通道,避免静默副作用)
|
|
141
|
+
return isRequest ? callTool(id, params) : null;
|
|
142
|
+
default:
|
|
143
|
+
// 请求类未知方法回 -32601;通知类按 JSON-RPC 规范静默
|
|
144
|
+
return isRequest ? jsonError(id, -32601, 'Method not found') : null;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本地 stdio 传输(stdio-transport)—— P1-T3。
|
|
3
|
+
* 职责:以子进程 stdin/stdout 承载 MCP JSON-RPC 2.0(换行分帧)。
|
|
4
|
+
* 边界:只做分帧、请求-响应关联、错误上报与优雅关闭;不解析业务语义。
|
|
5
|
+
*
|
|
6
|
+
* 约定:
|
|
7
|
+
* - 每条消息一行 JSON(`\n` 分帧,容忍 `\r\n`);
|
|
8
|
+
* - 带 `id` 且含 `result` / `error` 的消息视为响应,按 id 关联到挂起请求;
|
|
9
|
+
* - 其余消息交给 onMessage(如服务端通知);
|
|
10
|
+
* - 单行超限、JSON 解析失败、子进程异常退出 → onError(不抛出到调用方)。
|
|
11
|
+
*/
|
|
12
|
+
import type { McpMessageHandler, McpStderrHandler, McpTransport, StdioTransportOptions } from './types.js';
|
|
13
|
+
/** stdio 传输实现。 */
|
|
14
|
+
export declare class StdioMcpTransport implements McpTransport {
|
|
15
|
+
readonly kind = "stdio";
|
|
16
|
+
readonly pid: number | undefined;
|
|
17
|
+
private readonly child;
|
|
18
|
+
private readonly pending;
|
|
19
|
+
private readonly messageHandlers;
|
|
20
|
+
private readonly errorHandlers;
|
|
21
|
+
private readonly stderrHandlers;
|
|
22
|
+
private readonly requestTimeoutMs;
|
|
23
|
+
private readonly maxLineBytes;
|
|
24
|
+
private readonly shutdownGraceMs;
|
|
25
|
+
private readonly exited;
|
|
26
|
+
private buffer;
|
|
27
|
+
private seq;
|
|
28
|
+
private closing;
|
|
29
|
+
private closed;
|
|
30
|
+
constructor(options: StdioTransportOptions);
|
|
31
|
+
/** 发送一条消息。 */
|
|
32
|
+
send(message: unknown): void;
|
|
33
|
+
/** 发起请求并按 id 等待响应。 */
|
|
34
|
+
request(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
|
|
35
|
+
onMessage(handler: McpMessageHandler): () => void;
|
|
36
|
+
onError(handler: (error: Error) => void): () => void;
|
|
37
|
+
onStderr(handler: McpStderrHandler): () => void;
|
|
38
|
+
/** 优雅关闭:结束 stdin → 等待退出(宽限期后 SIGTERM)。 */
|
|
39
|
+
close(): Promise<void>;
|
|
40
|
+
/** 分帧:按换行切分并逐行处理。 */
|
|
41
|
+
private consume;
|
|
42
|
+
private handleLine;
|
|
43
|
+
private emitError;
|
|
44
|
+
private emitStderr;
|
|
45
|
+
private rejectAll;
|
|
46
|
+
private failAll;
|
|
47
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* 本地 stdio 传输(stdio-transport)—— P1-T3。
|
|
4
|
+
* 职责:以子进程 stdin/stdout 承载 MCP JSON-RPC 2.0(换行分帧)。
|
|
5
|
+
* 边界:只做分帧、请求-响应关联、错误上报与优雅关闭;不解析业务语义。
|
|
6
|
+
*
|
|
7
|
+
* 约定:
|
|
8
|
+
* - 每条消息一行 JSON(`\n` 分帧,容忍 `\r\n`);
|
|
9
|
+
* - 带 `id` 且含 `result` / `error` 的消息视为响应,按 id 关联到挂起请求;
|
|
10
|
+
* - 其余消息交给 onMessage(如服务端通知);
|
|
11
|
+
* - 单行超限、JSON 解析失败、子进程异常退出 → onError(不抛出到调用方)。
|
|
12
|
+
*/
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
|
+
/** stdio 传输实现。 */
|
|
15
|
+
export class StdioMcpTransport {
|
|
16
|
+
kind = 'stdio';
|
|
17
|
+
pid;
|
|
18
|
+
child;
|
|
19
|
+
pending = new Map();
|
|
20
|
+
messageHandlers = new Set();
|
|
21
|
+
errorHandlers = new Set();
|
|
22
|
+
stderrHandlers = new Set();
|
|
23
|
+
requestTimeoutMs;
|
|
24
|
+
maxLineBytes;
|
|
25
|
+
shutdownGraceMs;
|
|
26
|
+
exited;
|
|
27
|
+
buffer = '';
|
|
28
|
+
seq = 0;
|
|
29
|
+
closing = false;
|
|
30
|
+
closed = false;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.requestTimeoutMs = Math.max(1, options.requestTimeoutMs ?? 5_000);
|
|
33
|
+
this.maxLineBytes = Math.max(1_024, options.maxLineBytes ?? 1_048_576);
|
|
34
|
+
this.shutdownGraceMs = Math.max(0, options.shutdownGraceMs ?? 1_000);
|
|
35
|
+
this.child = spawn(options.command, [...(options.args ?? [])], {
|
|
36
|
+
cwd: options.cwd,
|
|
37
|
+
env: { ...process.env, ...(options.env ?? {}) },
|
|
38
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
39
|
+
});
|
|
40
|
+
this.pid = this.child.pid;
|
|
41
|
+
this.exited = new Promise((resolve) => {
|
|
42
|
+
this.child.once('exit', (code, signal) => {
|
|
43
|
+
if (!this.closing) {
|
|
44
|
+
this.failAll(new Error(`MCP 子进程退出(code=${String(code)} signal=${String(signal)})`));
|
|
45
|
+
}
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
this.child.stdout.setEncoding('utf8');
|
|
50
|
+
this.child.stdout.on('data', (chunk) => this.consume(chunk));
|
|
51
|
+
this.child.stderr.setEncoding('utf8');
|
|
52
|
+
this.child.stderr.on('data', (chunk) => this.emitStderr(chunk));
|
|
53
|
+
this.child.on('error', (error) => this.failAll(error));
|
|
54
|
+
}
|
|
55
|
+
/** 发送一条消息。 */
|
|
56
|
+
send(message) {
|
|
57
|
+
if (this.closed)
|
|
58
|
+
throw new Error('MCP 传输已关闭,无法发送');
|
|
59
|
+
this.child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
60
|
+
}
|
|
61
|
+
/** 发起请求并按 id 等待响应。 */
|
|
62
|
+
request(method, params, timeoutMs = this.requestTimeoutMs) {
|
|
63
|
+
this.seq += 1;
|
|
64
|
+
const id = this.seq;
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const timer = setTimeout(() => {
|
|
67
|
+
this.pending.delete(id);
|
|
68
|
+
reject(new Error(`MCP 请求超时:${method}(${timeoutMs}ms)`));
|
|
69
|
+
}, timeoutMs);
|
|
70
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
71
|
+
try {
|
|
72
|
+
this.send(params === undefined ? { jsonrpc: '2.0', id, method } : { jsonrpc: '2.0', id, method, params });
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
this.pending.delete(id);
|
|
77
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
onMessage(handler) {
|
|
82
|
+
this.messageHandlers.add(handler);
|
|
83
|
+
return () => this.messageHandlers.delete(handler);
|
|
84
|
+
}
|
|
85
|
+
onError(handler) {
|
|
86
|
+
this.errorHandlers.add(handler);
|
|
87
|
+
return () => this.errorHandlers.delete(handler);
|
|
88
|
+
}
|
|
89
|
+
onStderr(handler) {
|
|
90
|
+
this.stderrHandlers.add(handler);
|
|
91
|
+
return () => this.stderrHandlers.delete(handler);
|
|
92
|
+
}
|
|
93
|
+
/** 优雅关闭:结束 stdin → 等待退出(宽限期后 SIGTERM)。 */
|
|
94
|
+
async close() {
|
|
95
|
+
if (this.closing)
|
|
96
|
+
return;
|
|
97
|
+
this.closing = true;
|
|
98
|
+
this.rejectAll(new Error('MCP 传输已关闭'));
|
|
99
|
+
this.child.stdin.end();
|
|
100
|
+
const grace = new Promise((resolve) => setTimeout(resolve, this.shutdownGraceMs));
|
|
101
|
+
await Promise.race([this.exited, grace]);
|
|
102
|
+
if (this.child.exitCode === null && !this.child.killed)
|
|
103
|
+
this.child.kill('SIGTERM');
|
|
104
|
+
this.closed = true;
|
|
105
|
+
}
|
|
106
|
+
/** 分帧:按换行切分并逐行处理。 */
|
|
107
|
+
consume(chunk) {
|
|
108
|
+
this.buffer += chunk;
|
|
109
|
+
let index = this.buffer.indexOf('\n');
|
|
110
|
+
while (index >= 0) {
|
|
111
|
+
const line = this.buffer.slice(0, index).replace(/\r$/, '');
|
|
112
|
+
this.buffer = this.buffer.slice(index + 1);
|
|
113
|
+
if (line.trim() !== '')
|
|
114
|
+
this.handleLine(line);
|
|
115
|
+
index = this.buffer.indexOf('\n');
|
|
116
|
+
}
|
|
117
|
+
if (this.buffer.length > this.maxLineBytes) {
|
|
118
|
+
this.buffer = '';
|
|
119
|
+
this.emitError(new Error(`MCP 单行超过 ${this.maxLineBytes} 字节上限,缓冲已重置`));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
handleLine(line) {
|
|
123
|
+
let message;
|
|
124
|
+
try {
|
|
125
|
+
message = JSON.parse(line);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
this.emitError(new Error(`MCP 消息解析失败:${error instanceof Error ? error.message : String(error)}`));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (isResponse(message)) {
|
|
132
|
+
const pending = this.pending.get(Number(message.id));
|
|
133
|
+
if (!pending)
|
|
134
|
+
return; // 迟到的响应:丢弃,不影响总线
|
|
135
|
+
this.pending.delete(Number(message.id));
|
|
136
|
+
clearTimeout(pending.timer);
|
|
137
|
+
if (message.error) {
|
|
138
|
+
pending.reject(new Error(`MCP 错误 ${message.error.code}:${message.error.message}`));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
pending.resolve(message.result ?? null);
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
for (const handler of [...this.messageHandlers])
|
|
146
|
+
handler(message);
|
|
147
|
+
}
|
|
148
|
+
emitError(error) {
|
|
149
|
+
for (const handler of [...this.errorHandlers])
|
|
150
|
+
handler(error);
|
|
151
|
+
}
|
|
152
|
+
emitStderr(chunk) {
|
|
153
|
+
for (const line of chunk.split('\n')) {
|
|
154
|
+
if (line.trim() === '')
|
|
155
|
+
continue;
|
|
156
|
+
for (const handler of [...this.stderrHandlers])
|
|
157
|
+
handler(line);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
rejectAll(error) {
|
|
161
|
+
for (const [id, pending] of this.pending) {
|
|
162
|
+
clearTimeout(pending.timer);
|
|
163
|
+
pending.reject(error);
|
|
164
|
+
this.pending.delete(id);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
failAll(error) {
|
|
168
|
+
this.rejectAll(error);
|
|
169
|
+
this.emitError(error);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function isResponse(value) {
|
|
173
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
174
|
+
return false;
|
|
175
|
+
const record = value;
|
|
176
|
+
const hasId = typeof record.id === 'string' || typeof record.id === 'number';
|
|
177
|
+
return hasId && ('result' in record || 'error' in record);
|
|
178
|
+
}
|