hyacinth-ai 0.9.6
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/LICENSE +21 -0
- package/README.md +205 -0
- package/commands.json +25 -0
- package/dist/agents/builtins.d.ts +8 -0
- package/dist/agents/builtins.js +50 -0
- package/dist/agents/config-loader.d.ts +15 -0
- package/dist/agents/config-loader.js +75 -0
- package/dist/agents/delegate-tool.d.ts +109 -0
- package/dist/agents/delegate-tool.js +407 -0
- package/dist/agents/index.d.ts +5 -0
- package/dist/agents/index.js +5 -0
- package/dist/agents/registry.d.ts +2 -0
- package/dist/agents/registry.js +2 -0
- package/dist/bypass/agents/companion/index.d.ts +57 -0
- package/dist/bypass/agents/companion/index.js +487 -0
- package/dist/bypass/agents/orchestrator/index.d.ts +17 -0
- package/dist/bypass/agents/orchestrator/index.js +414 -0
- package/dist/bypass/agents/orchestrator.d.ts +16 -0
- package/dist/bypass/agents/orchestrator.js +377 -0
- package/dist/bypass/agents/world-engine/agent.d.ts +41 -0
- package/dist/bypass/agents/world-engine/agent.js +385 -0
- package/dist/bypass/agents/world-engine/index.d.ts +52 -0
- package/dist/bypass/agents/world-engine/index.js +198 -0
- package/dist/bypass/agents/world-engine/sim.d.ts +14 -0
- package/dist/bypass/agents/world-engine/sim.js +120 -0
- package/dist/bypass/agents/world-engine/store.d.ts +110 -0
- package/dist/bypass/agents/world-engine/store.js +519 -0
- package/dist/bypass/agents/world-engine/ticker.d.ts +37 -0
- package/dist/bypass/agents/world-engine/ticker.js +214 -0
- package/dist/bypass/agents/world-engine/tools.d.ts +6 -0
- package/dist/bypass/agents/world-engine/tools.js +380 -0
- package/dist/bypass/agents/world-engine/types.d.ts +202 -0
- package/dist/bypass/agents/world-engine/types.js +56 -0
- package/dist/bypass/agents/world-engine.d.ts +20 -0
- package/dist/bypass/agents/world-engine.js +63 -0
- package/dist/bypass/base.d.ts +48 -0
- package/dist/bypass/base.js +126 -0
- package/dist/bypass/index.d.ts +5 -0
- package/dist/bypass/index.js +6 -0
- package/dist/bypass/manager.d.ts +41 -0
- package/dist/bypass/manager.js +179 -0
- package/dist/bypass/types.d.ts +63 -0
- package/dist/bypass/types.js +14 -0
- package/dist/channels/auto-detect.d.ts +25 -0
- package/dist/channels/auto-detect.js +77 -0
- package/dist/channels/builtin/http-webhook.d.ts +25 -0
- package/dist/channels/builtin/http-webhook.js +287 -0
- package/dist/channels/builtin/tui-channel.d.ts +33 -0
- package/dist/channels/builtin/tui-channel.js +61 -0
- package/dist/channels/builtin/tui-ws-session.d.ts +16 -0
- package/dist/channels/builtin/tui-ws-session.js +90 -0
- package/dist/channels/builtin/webui-output-handler.d.ts +30 -0
- package/dist/channels/builtin/webui-output-handler.js +93 -0
- package/dist/channels/index.d.ts +5 -0
- package/dist/channels/index.js +3 -0
- package/dist/channels/interface.d.ts +148 -0
- package/dist/channels/interface.js +15 -0
- package/dist/channels/manager.d.ts +43 -0
- package/dist/channels/manager.js +156 -0
- package/dist/channels/message-queue.d.ts +36 -0
- package/dist/channels/message-queue.js +91 -0
- package/dist/channels/plugins/clawbot/clawbot-auth.d.ts +50 -0
- package/dist/channels/plugins/clawbot/clawbot-auth.js +235 -0
- package/dist/channels/plugins/clawbot/clawbot-channel.d.ts +76 -0
- package/dist/channels/plugins/clawbot/clawbot-channel.js +566 -0
- package/dist/channels/plugins/clawbot/clawbot-client.d.ts +180 -0
- package/dist/channels/plugins/clawbot/clawbot-client.js +312 -0
- package/dist/channels/plugins/clawbot/clawbot-config.d.ts +30 -0
- package/dist/channels/plugins/clawbot/clawbot-config.js +28 -0
- package/dist/channels/plugins/clawbot/clawbot-message-queue.d.ts +27 -0
- package/dist/channels/plugins/clawbot/clawbot-message-queue.js +114 -0
- package/dist/channels/plugins/clawbot/clawbot-session.d.ts +10 -0
- package/dist/channels/plugins/clawbot/clawbot-session.js +26 -0
- package/dist/channels/plugins/clawbot/index.d.ts +17 -0
- package/dist/channels/plugins/clawbot/index.js +58 -0
- package/dist/channels/plugins/feishu/feishu-channel.d.ts +57 -0
- package/dist/channels/plugins/feishu/feishu-channel.js +602 -0
- package/dist/channels/plugins/feishu/feishu-client.d.ts +23 -0
- package/dist/channels/plugins/feishu/feishu-client.js +86 -0
- package/dist/channels/plugins/feishu/feishu-config.d.ts +53 -0
- package/dist/channels/plugins/feishu/feishu-config.js +35 -0
- package/dist/channels/plugins/feishu/feishu-event.d.ts +102 -0
- package/dist/channels/plugins/feishu/feishu-event.js +257 -0
- package/dist/channels/plugins/feishu/feishu-log-suppressor.d.ts +7 -0
- package/dist/channels/plugins/feishu/feishu-log-suppressor.js +34 -0
- package/dist/channels/plugins/feishu/feishu-message-queue.d.ts +27 -0
- package/dist/channels/plugins/feishu/feishu-message-queue.js +112 -0
- package/dist/channels/plugins/feishu/feishu-send.d.ts +44 -0
- package/dist/channels/plugins/feishu/feishu-send.js +232 -0
- package/dist/channels/plugins/feishu/feishu-session.d.ts +44 -0
- package/dist/channels/plugins/feishu/feishu-session.js +84 -0
- package/dist/channels/plugins/feishu/feishu-streaming.d.ts +49 -0
- package/dist/channels/plugins/feishu/feishu-streaming.js +185 -0
- package/dist/channels/plugins/feishu/feishu-transport.d.ts +29 -0
- package/dist/channels/plugins/feishu/feishu-transport.js +99 -0
- package/dist/channels/plugins/feishu/index.d.ts +22 -0
- package/dist/channels/plugins/feishu/index.js +68 -0
- package/dist/cli/doctor.d.ts +20 -0
- package/dist/cli/doctor.js +317 -0
- package/dist/context/cache-strategy.d.ts +76 -0
- package/dist/context/cache-strategy.js +123 -0
- package/dist/context/composer.d.ts +77 -0
- package/dist/context/composer.js +318 -0
- package/dist/context/compressor.d.ts +218 -0
- package/dist/context/compressor.js +909 -0
- package/dist/context/index.d.ts +14 -0
- package/dist/context/index.js +8 -0
- package/dist/context/interface.d.ts +33 -0
- package/dist/context/interface.js +2 -0
- package/dist/context/manifest-defaults.d.ts +51 -0
- package/dist/context/manifest-defaults.js +133 -0
- package/dist/context/manifest-loader.d.ts +16 -0
- package/dist/context/manifest-loader.js +103 -0
- package/dist/context/manifest-types.d.ts +26 -0
- package/dist/context/manifest-types.js +2 -0
- package/dist/context/precision/analyzer.d.ts +31 -0
- package/dist/context/precision/analyzer.js +131 -0
- package/dist/context/precision/companion.d.ts +27 -0
- package/dist/context/precision/companion.js +144 -0
- package/dist/context/precision/default.d.ts +14 -0
- package/dist/context/precision/default.js +17 -0
- package/dist/context/precision/index.d.ts +9 -0
- package/dist/context/precision/index.js +7 -0
- package/dist/context/precision/keyword-pool.d.ts +27 -0
- package/dist/context/precision/keyword-pool.js +66 -0
- package/dist/context/precision/strategy.d.ts +18 -0
- package/dist/context/precision/strategy.js +51 -0
- package/dist/context/precision/summary-store.d.ts +18 -0
- package/dist/context/precision/summary-store.js +67 -0
- package/dist/context/precision/types.d.ts +23 -0
- package/dist/context/precision/types.js +2 -0
- package/dist/context/profiles.d.ts +45 -0
- package/dist/context/profiles.js +92 -0
- package/dist/context/prompt-builder.d.ts +76 -0
- package/dist/context/prompt-builder.js +133 -0
- package/dist/context/retriever.d.ts +44 -0
- package/dist/context/retriever.js +203 -0
- package/dist/context/router.d.ts +122 -0
- package/dist/context/router.js +291 -0
- package/dist/context/section-resolver.d.ts +38 -0
- package/dist/context/section-resolver.js +398 -0
- package/dist/context/tokenizer.d.ts +23 -0
- package/dist/context/tokenizer.js +78 -0
- package/dist/dependency/analyzer.d.ts +33 -0
- package/dist/dependency/analyzer.js +242 -0
- package/dist/dependency/data-flow-tracker.d.ts +12 -0
- package/dist/dependency/data-flow-tracker.js +97 -0
- package/dist/dependency/function-parser.d.ts +34 -0
- package/dist/dependency/function-parser.js +295 -0
- package/dist/dependency/index.d.ts +14 -0
- package/dist/dependency/index.js +20 -0
- package/dist/dependency/parser.d.ts +10 -0
- package/dist/dependency/parser.js +93 -0
- package/dist/dependency/types.d.ts +57 -0
- package/dist/dependency/types.js +2 -0
- package/dist/env/env-collector.d.ts +45 -0
- package/dist/env/env-collector.js +221 -0
- package/dist/env/index.d.ts +3 -0
- package/dist/env/index.js +2 -0
- package/dist/event-store.d.ts +27 -0
- package/dist/event-store.js +71 -0
- package/dist/evolution/git-manager.d.ts +46 -0
- package/dist/evolution/git-manager.js +276 -0
- package/dist/evolution/index.d.ts +3 -0
- package/dist/evolution/index.js +2 -0
- package/dist/flow/bootstrap-flow.d.ts +19 -0
- package/dist/flow/bootstrap-flow.js +72 -0
- package/dist/flow/flow-registry.d.ts +12 -0
- package/dist/flow/flow-registry.js +74 -0
- package/dist/flow/flow-tools.d.ts +8 -0
- package/dist/flow/flow-tools.js +106 -0
- package/dist/flow/index.d.ts +6 -0
- package/dist/flow/index.js +8 -0
- package/dist/flow/todo-flow.d.ts +25 -0
- package/dist/flow/todo-flow.js +107 -0
- package/dist/flow/types.d.ts +78 -0
- package/dist/flow/types.js +12 -0
- package/dist/flows/bootstrap.d.ts +18 -0
- package/dist/flows/bootstrap.js +119 -0
- package/dist/flows/index.d.ts +6 -0
- package/dist/flows/index.js +11 -0
- package/dist/flows/todo.d.ts +26 -0
- package/dist/flows/todo.js +174 -0
- package/dist/flows/tools.d.ts +8 -0
- package/dist/flows/tools.js +119 -0
- package/dist/flows/types.d.ts +27 -0
- package/dist/flows/types.js +10 -0
- package/dist/gateway/cli.d.ts +5 -0
- package/dist/gateway/cli.js +1027 -0
- package/dist/gateway/factory.d.ts +80 -0
- package/dist/gateway/factory.js +832 -0
- package/dist/gateway/guardian.d.ts +8 -0
- package/dist/gateway/guardian.js +30 -0
- package/dist/gateway/index.d.ts +3 -0
- package/dist/gateway/index.js +3 -0
- package/dist/gateway/server.d.ts +17 -0
- package/dist/gateway/server.js +96 -0
- package/dist/gateway/tui.d.ts +16 -0
- package/dist/gateway/tui.js +3273 -0
- package/dist/hot-reload/agent-watcher.d.ts +24 -0
- package/dist/hot-reload/agent-watcher.js +175 -0
- package/dist/hot-reload/bundle-watcher.d.ts +12 -0
- package/dist/hot-reload/bundle-watcher.js +35 -0
- package/dist/hot-reload/channel-watcher.d.ts +19 -0
- package/dist/hot-reload/channel-watcher.js +54 -0
- package/dist/hot-reload/command-watcher.d.ts +14 -0
- package/dist/hot-reload/command-watcher.js +54 -0
- package/dist/hot-reload/config-watcher.d.ts +20 -0
- package/dist/hot-reload/config-watcher.js +58 -0
- package/dist/hot-reload/index.d.ts +12 -0
- package/dist/hot-reload/index.js +12 -0
- package/dist/hot-reload/manager.d.ts +58 -0
- package/dist/hot-reload/manager.js +243 -0
- package/dist/hot-reload/manifest-watcher.d.ts +9 -0
- package/dist/hot-reload/manifest-watcher.js +42 -0
- package/dist/hot-reload/mcp-watcher.d.ts +18 -0
- package/dist/hot-reload/mcp-watcher.js +64 -0
- package/dist/hot-reload/model-catalog-watcher.d.ts +18 -0
- package/dist/hot-reload/model-catalog-watcher.js +62 -0
- package/dist/hot-reload/plugin-watcher.d.ts +20 -0
- package/dist/hot-reload/plugin-watcher.js +56 -0
- package/dist/hot-reload/prompt-watcher.d.ts +6 -0
- package/dist/hot-reload/prompt-watcher.js +38 -0
- package/dist/hot-reload/provider-watcher.d.ts +16 -0
- package/dist/hot-reload/provider-watcher.js +45 -0
- package/dist/hot-reload/skill-watcher.d.ts +19 -0
- package/dist/hot-reload/skill-watcher.js +82 -0
- package/dist/hot-reload/tool-watcher.d.ts +16 -0
- package/dist/hot-reload/tool-watcher.js +168 -0
- package/dist/hot-reload/workflow-watcher.d.ts +19 -0
- package/dist/hot-reload/workflow-watcher.js +84 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/knowledge/fts5-retriever.d.ts +30 -0
- package/dist/knowledge/fts5-retriever.js +223 -0
- package/dist/knowledge/index.d.ts +11 -0
- package/dist/knowledge/index.js +14 -0
- package/dist/knowledge/indexer.d.ts +41 -0
- package/dist/knowledge/indexer.js +186 -0
- package/dist/knowledge/query-preprocessor.d.ts +13 -0
- package/dist/knowledge/query-preprocessor.js +63 -0
- package/dist/knowledge/retriever.d.ts +45 -0
- package/dist/knowledge/retriever.js +9 -0
- package/dist/knowledge/store.d.ts +27 -0
- package/dist/knowledge/store.js +61 -0
- package/dist/knowledge/structured-store.d.ts +78 -0
- package/dist/knowledge/structured-store.js +280 -0
- package/dist/knowledge/structured-tools.d.ts +12 -0
- package/dist/knowledge/structured-tools.js +151 -0
- package/dist/knowledge/tools.d.ts +20 -0
- package/dist/knowledge/tools.js +238 -0
- package/dist/knowledge/watcher.d.ts +28 -0
- package/dist/knowledge/watcher.js +113 -0
- package/dist/lifecycle/index.d.ts +12 -0
- package/dist/lifecycle/index.js +14 -0
- package/dist/lifecycle/interface.d.ts +94 -0
- package/dist/lifecycle/interface.js +2 -0
- package/dist/lifecycle/local-model.d.ts +62 -0
- package/dist/lifecycle/local-model.js +331 -0
- package/dist/lifecycle/manager.d.ts +70 -0
- package/dist/lifecycle/manager.js +374 -0
- package/dist/lifecycle/supervisor.d.ts +89 -0
- package/dist/lifecycle/supervisor.js +277 -0
- package/dist/lifecycle-integration-test.d.ts +2 -0
- package/dist/lifecycle-integration-test.js +72 -0
- package/dist/local-model/download-manager.d.ts +59 -0
- package/dist/local-model/download-manager.js +517 -0
- package/dist/local-model/index.d.ts +109 -0
- package/dist/local-model/index.js +233 -0
- package/dist/local-model/llamacpp-provider.d.ts +95 -0
- package/dist/local-model/llamacpp-provider.js +379 -0
- package/dist/local-model/model-bridge.d.ts +48 -0
- package/dist/local-model/model-bridge.js +256 -0
- package/dist/local-model/model-registry.d.ts +47 -0
- package/dist/local-model/model-registry.js +188 -0
- package/dist/local-model/types.d.ts +49 -0
- package/dist/local-model/types.js +2 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/logger.d.ts +56 -0
- package/dist/logging/logger.js +94 -0
- package/dist/machine/flows/bootstrap.d.ts +18 -0
- package/dist/machine/flows/bootstrap.js +119 -0
- package/dist/machine/flows/index.d.ts +6 -0
- package/dist/machine/flows/index.js +11 -0
- package/dist/machine/flows/spec.d.ts +17 -0
- package/dist/machine/flows/spec.js +176 -0
- package/dist/machine/flows/todo.d.ts +26 -0
- package/dist/machine/flows/todo.js +175 -0
- package/dist/machine/flows/tools.d.ts +8 -0
- package/dist/machine/flows/tools.js +119 -0
- package/dist/machine/flows/types.d.ts +33 -0
- package/dist/machine/flows/types.js +10 -0
- package/dist/machine/index.d.ts +8 -0
- package/dist/machine/index.js +9 -0
- package/dist/machine/registry.d.ts +34 -0
- package/dist/machine/registry.js +98 -0
- package/dist/machine/runner.d.ts +41 -0
- package/dist/machine/runner.js +177 -0
- package/dist/machine/types.d.ts +121 -0
- package/dist/machine/types.js +9 -0
- package/dist/mcp/bridge.d.ts +33 -0
- package/dist/mcp/bridge.js +99 -0
- package/dist/mcp/client.d.ts +37 -0
- package/dist/mcp/client.js +161 -0
- package/dist/mcp/config.d.ts +15 -0
- package/dist/mcp/config.js +85 -0
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.js +7 -0
- package/dist/mcp/install-manager.d.ts +31 -0
- package/dist/mcp/install-manager.js +158 -0
- package/dist/mcp/lifecycle.d.ts +41 -0
- package/dist/mcp/lifecycle.js +175 -0
- package/dist/mcp/process-transport.d.ts +21 -0
- package/dist/mcp/process-transport.js +59 -0
- package/dist/mcp/side-effect.d.ts +5 -0
- package/dist/mcp/side-effect.js +21 -0
- package/dist/mcp/system.d.ts +95 -0
- package/dist/mcp/system.js +279 -0
- package/dist/memory/companion-session.d.ts +22 -0
- package/dist/memory/companion-session.js +77 -0
- package/dist/memory/compression-boundary.d.ts +20 -0
- package/dist/memory/compression-boundary.js +40 -0
- package/dist/memory/conversation.d.ts +34 -0
- package/dist/memory/conversation.js +107 -0
- package/dist/memory/events.d.ts +42 -0
- package/dist/memory/events.js +56 -0
- package/dist/memory/index.d.ts +7 -0
- package/dist/memory/index.js +6 -0
- package/dist/memory/memory-store.d.ts +11 -0
- package/dist/memory/memory-store.js +51 -0
- package/dist/memory/session-allowlist.d.ts +11 -0
- package/dist/memory/session-allowlist.js +50 -0
- package/dist/memory/session.d.ts +48 -0
- package/dist/memory/session.js +275 -0
- package/dist/memory/stats.d.ts +23 -0
- package/dist/memory/stats.js +59 -0
- package/dist/memory/summary.d.ts +7 -0
- package/dist/memory/summary.js +23 -0
- package/dist/multimodal/index.d.ts +66 -0
- package/dist/multimodal/index.js +210 -0
- package/dist/orchestrator/index.d.ts +5 -0
- package/dist/orchestrator/index.js +4 -0
- package/dist/orchestrator/loop.d.ts +331 -0
- package/dist/orchestrator/loop.js +2443 -0
- package/dist/orchestrator/plan-store.d.ts +81 -0
- package/dist/orchestrator/plan-store.js +167 -0
- package/dist/orchestrator/planner.d.ts +20 -0
- package/dist/orchestrator/planner.js +34 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.js +2 -0
- package/dist/parser/router.d.ts +30 -0
- package/dist/parser/router.js +61 -0
- package/dist/plugins/api.d.ts +39 -0
- package/dist/plugins/api.js +85 -0
- package/dist/plugins/define.d.ts +27 -0
- package/dist/plugins/define.js +32 -0
- package/dist/plugins/index.d.ts +9 -0
- package/dist/plugins/index.js +5 -0
- package/dist/plugins/loader.d.ts +39 -0
- package/dist/plugins/loader.js +128 -0
- package/dist/plugins/manager.d.ts +61 -0
- package/dist/plugins/manager.js +257 -0
- package/dist/plugins/types.d.ts +82 -0
- package/dist/plugins/types.js +2 -0
- package/dist/prompts/agents/code-reviewer.md +16 -0
- package/dist/prompts/agents/security-auditor.md +17 -0
- package/dist/prompts/agents/test-writer.md +15 -0
- package/dist/prompts/attention/attention.md +12 -0
- package/dist/prompts/environment/environment.md +18 -0
- package/dist/prompts/environment/feishu.md +107 -0
- package/dist/prompts/flows/bootstrap-confirm.md +14 -0
- package/dist/prompts/flows/bootstrap-identity.md +11 -0
- package/dist/prompts/flows/bootstrap-soul.md +19 -0
- package/dist/prompts/flows/bootstrap-user.md +11 -0
- package/dist/prompts/flows/spec-checklist.md +27 -0
- package/dist/prompts/flows/spec-define.md +64 -0
- package/dist/prompts/flows/spec-executing-checklist.md +15 -0
- package/dist/prompts/flows/spec-executing-tasks.md +15 -0
- package/dist/prompts/flows/spec-spec.md +51 -0
- package/dist/prompts/flows/spec-tasks.md +32 -0
- package/dist/prompts/flows/todo-execution.md +7 -0
- package/dist/prompts/flows/todo-planning.md +18 -0
- package/dist/prompts/framework/architecture.md +131 -0
- package/dist/prompts/identity/identity.md +2 -0
- package/dist/prompts/loader.d.ts +24 -0
- package/dist/prompts/loader.js +102 -0
- package/dist/prompts/loader.ts +119 -0
- package/dist/prompts/orchestration/summary.md +14 -0
- package/dist/prompts/persona/BOOTSTRAP.md +5 -0
- package/dist/prompts/persona/IDENTITY.md +16 -0
- package/dist/prompts/persona/PartnerMemory.md +5 -0
- package/dist/prompts/persona/PartnerSoul.md +7 -0
- package/dist/prompts/persona/SOUL.md +30 -0
- package/dist/prompts/persona/USER.md +16 -0
- package/dist/prompts/precise/analyze.md +23 -0
- package/dist/prompts/precise/persona.md +18 -0
- package/dist/prompts/safety/coding-standards.md +5 -0
- package/dist/prompts/safety/safety.md +4 -0
- package/dist/prompts/skills/code-review.md +4 -0
- package/dist/prompts/skills/debug.md +7 -0
- package/dist/prompts/skills/framework-reference.md +131 -0
- package/dist/prompts/skills/refactor.md +6 -0
- package/dist/prompts/summary.md +22 -0
- package/dist/prompts/tools/framework-capabilities.md +241 -0
- package/dist/prompts/tools/tool-rules.md +15 -0
- package/dist/provider/anthropic.d.ts +62 -0
- package/dist/provider/anthropic.js +361 -0
- package/dist/provider/catalog.d.ts +58 -0
- package/dist/provider/catalog.js +97 -0
- package/dist/provider/compatible.d.ts +89 -0
- package/dist/provider/compatible.js +328 -0
- package/dist/provider/config.d.ts +23 -0
- package/dist/provider/config.js +158 -0
- package/dist/provider/deepseek.d.ts +25 -0
- package/dist/provider/deepseek.js +37 -0
- package/dist/provider/fallback.d.ts +51 -0
- package/dist/provider/fallback.js +113 -0
- package/dist/provider/gemini.d.ts +27 -0
- package/dist/provider/gemini.js +170 -0
- package/dist/provider/index.d.ts +36 -0
- package/dist/provider/index.js +42 -0
- package/dist/provider/interface.d.ts +62 -0
- package/dist/provider/interface.js +2 -0
- package/dist/provider/local-config.d.ts +37 -0
- package/dist/provider/local-config.js +146 -0
- package/dist/provider/local.d.ts +45 -0
- package/dist/provider/local.js +248 -0
- package/dist/provider/manager.d.ts +67 -0
- package/dist/provider/manager.js +355 -0
- package/dist/provider/mimo.d.ts +19 -0
- package/dist/provider/mimo.js +30 -0
- package/dist/provider/minimax.d.ts +22 -0
- package/dist/provider/minimax.js +33 -0
- package/dist/provider/model-catalog-loader.d.ts +42 -0
- package/dist/provider/model-catalog-loader.js +89 -0
- package/dist/provider/model-channel-registry.d.ts +130 -0
- package/dist/provider/model-channel-registry.js +488 -0
- package/dist/provider/model-router.d.ts +60 -0
- package/dist/provider/model-router.js +87 -0
- package/dist/provider/openai.d.ts +54 -0
- package/dist/provider/openai.js +274 -0
- package/dist/provider/qwen.d.ts +19 -0
- package/dist/provider/qwen.js +30 -0
- package/dist/provider/resilient.d.ts +46 -0
- package/dist/provider/resilient.js +181 -0
- package/dist/provider/retry.d.ts +16 -0
- package/dist/provider/retry.js +78 -0
- package/dist/provider/router.d.ts +68 -0
- package/dist/provider/router.js +145 -0
- package/dist/provider/tool-args-recovery.d.ts +36 -0
- package/dist/provider/tool-args-recovery.js +91 -0
- package/dist/provider/user-id.d.ts +13 -0
- package/dist/provider/user-id.js +53 -0
- package/dist/provider/zhipu.d.ts +19 -0
- package/dist/provider/zhipu.js +32 -0
- package/dist/registry/agent.registry.d.ts +57 -0
- package/dist/registry/agent.registry.js +224 -0
- package/dist/registry/base.d.ts +54 -0
- package/dist/registry/base.js +99 -0
- package/dist/registry/channel.registry.d.ts +53 -0
- package/dist/registry/channel.registry.js +87 -0
- package/dist/registry/index.d.ts +9 -0
- package/dist/registry/index.js +10 -0
- package/dist/registry/mcp.registry.d.ts +2 -0
- package/dist/registry/mcp.registry.js +2 -0
- package/dist/registry/plugin.registry.d.ts +33 -0
- package/dist/registry/plugin.registry.js +66 -0
- package/dist/registry/provider.registry.d.ts +51 -0
- package/dist/registry/provider.registry.js +104 -0
- package/dist/registry/skill.registry.d.ts +33 -0
- package/dist/registry/skill.registry.js +95 -0
- package/dist/registry/tool.registry.d.ts +68 -0
- package/dist/registry/tool.registry.js +185 -0
- package/dist/repair/loop-guard.d.ts +98 -0
- package/dist/repair/loop-guard.js +217 -0
- package/dist/repair/scavenge.d.ts +19 -0
- package/dist/repair/scavenge.js +81 -0
- package/dist/repair/storm.d.ts +7 -0
- package/dist/repair/storm.js +7 -0
- package/dist/rollback/index.d.ts +5 -0
- package/dist/rollback/index.js +4 -0
- package/dist/rollback/rollback-tool.d.ts +13 -0
- package/dist/rollback/rollback-tool.js +167 -0
- package/dist/rollback/turn-recorder.d.ts +37 -0
- package/dist/rollback/turn-recorder.js +183 -0
- package/dist/rollback/turn-store.d.ts +29 -0
- package/dist/rollback/turn-store.js +114 -0
- package/dist/rollback/types.d.ts +51 -0
- package/dist/rollback/types.js +9 -0
- package/dist/runtime/config-center.d.ts +92 -0
- package/dist/runtime/config-center.js +467 -0
- package/dist/runtime/config-schema.d.ts +201 -0
- package/dist/runtime/config-schema.js +2 -0
- package/dist/runtime/defaults.d.ts +3 -0
- package/dist/runtime/defaults.js +146 -0
- package/dist/schedule/cron.d.ts +24 -0
- package/dist/schedule/cron.js +145 -0
- package/dist/schedule/index.d.ts +6 -0
- package/dist/schedule/index.js +4 -0
- package/dist/schedule/persistence.d.ts +33 -0
- package/dist/schedule/persistence.js +106 -0
- package/dist/schedule/scheduler.d.ts +85 -0
- package/dist/schedule/scheduler.js +630 -0
- package/dist/schedule/types.d.ts +185 -0
- package/dist/schedule/types.js +2 -0
- package/dist/setup/config.d.ts +189 -0
- package/dist/setup/config.js +253 -0
- package/dist/setup/index.d.ts +3 -0
- package/dist/setup/index.js +3 -0
- package/dist/setup/model-defaults.d.ts +13 -0
- package/dist/setup/model-defaults.js +87 -0
- package/dist/setup/persona-bootstrap.d.ts +42 -0
- package/dist/setup/persona-bootstrap.js +379 -0
- package/dist/setup/wizard.d.ts +32 -0
- package/dist/setup/wizard.js +384 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +4 -0
- package/dist/skills/loader.d.ts +12 -0
- package/dist/skills/loader.js +83 -0
- package/dist/skills/registry.d.ts +2 -0
- package/dist/skills/registry.js +2 -0
- package/dist/skills/skill-tool.d.ts +20 -0
- package/dist/skills/skill-tool.js +49 -0
- package/dist/tools/archive.d.ts +17 -0
- package/dist/tools/archive.js +131 -0
- package/dist/tools/ask-user.d.ts +9 -0
- package/dist/tools/ask-user.js +62 -0
- package/dist/tools/background-registry.d.ts +45 -0
- package/dist/tools/background-registry.js +164 -0
- package/dist/tools/bash.d.ts +56 -0
- package/dist/tools/bash.js +391 -0
- package/dist/tools/bundle-registry.d.ts +42 -0
- package/dist/tools/bundle-registry.js +239 -0
- package/dist/tools/bundle-tools.d.ts +11 -0
- package/dist/tools/bundle-tools.js +168 -0
- package/dist/tools/channel-info.d.ts +5 -0
- package/dist/tools/channel-info.js +38 -0
- package/dist/tools/compression.d.ts +7 -0
- package/dist/tools/compression.js +21 -0
- package/dist/tools/config.d.ts +23 -0
- package/dist/tools/config.js +255 -0
- package/dist/tools/db-query.d.ts +12 -0
- package/dist/tools/db-query.js +107 -0
- package/dist/tools/diagnostics.d.ts +30 -0
- package/dist/tools/diagnostics.js +111 -0
- package/dist/tools/diff-channel.d.ts +9 -0
- package/dist/tools/diff-channel.js +17 -0
- package/dist/tools/diff-files.d.ts +17 -0
- package/dist/tools/diff-files.js +88 -0
- package/dist/tools/disk-usage.d.ts +34 -0
- package/dist/tools/disk-usage.js +258 -0
- package/dist/tools/edit.d.ts +30 -0
- package/dist/tools/edit.js +235 -0
- package/dist/tools/executor.d.ts +32 -0
- package/dist/tools/executor.js +66 -0
- package/dist/tools/file-tracker.d.ts +20 -0
- package/dist/tools/file-tracker.js +44 -0
- package/dist/tools/filtered-registry.d.ts +29 -0
- package/dist/tools/filtered-registry.js +50 -0
- package/dist/tools/flow.d.ts +10 -0
- package/dist/tools/flow.js +180 -0
- package/dist/tools/git-tool.d.ts +24 -0
- package/dist/tools/git-tool.js +113 -0
- package/dist/tools/glob.d.ts +29 -0
- package/dist/tools/glob.js +152 -0
- package/dist/tools/grep.d.ts +14 -0
- package/dist/tools/grep.js +325 -0
- package/dist/tools/http-request.d.ts +14 -0
- package/dist/tools/http-request.js +126 -0
- package/dist/tools/index.d.ts +43 -0
- package/dist/tools/index.js +76 -0
- package/dist/tools/injection-filter.d.ts +6 -0
- package/dist/tools/injection-filter.js +71 -0
- package/dist/tools/insert.d.ts +13 -0
- package/dist/tools/insert.js +61 -0
- package/dist/tools/interface.d.ts +30 -0
- package/dist/tools/interface.js +2 -0
- package/dist/tools/json-edit.d.ts +15 -0
- package/dist/tools/json-edit.js +122 -0
- package/dist/tools/multi-edit.d.ts +9 -0
- package/dist/tools/multi-edit.js +146 -0
- package/dist/tools/path-sandbox.d.ts +14 -0
- package/dist/tools/path-sandbox.js +60 -0
- package/dist/tools/process-tools.d.ts +15 -0
- package/dist/tools/process-tools.js +95 -0
- package/dist/tools/python-bridge/bridge.d.ts +24 -0
- package/dist/tools/python-bridge/bridge.js +39 -0
- package/dist/tools/python-bridge/executor.d.ts +6 -0
- package/dist/tools/python-bridge/executor.js +69 -0
- package/dist/tools/python-bridge/index.d.ts +5 -0
- package/dist/tools/python-bridge/index.js +4 -0
- package/dist/tools/python-bridge/parser.d.ts +21 -0
- package/dist/tools/python-bridge/parser.js +258 -0
- package/dist/tools/read.d.ts +16 -0
- package/dist/tools/read.js +276 -0
- package/dist/tools/registry.d.ts +2 -0
- package/dist/tools/registry.js +2 -0
- package/dist/tools/restart.d.ts +10 -0
- package/dist/tools/restart.js +46 -0
- package/dist/tools/result-buffer.d.ts +66 -0
- package/dist/tools/result-buffer.js +146 -0
- package/dist/tools/runtime-control.d.ts +163 -0
- package/dist/tools/runtime-control.js +1780 -0
- package/dist/tools/symbol-references.d.ts +5 -0
- package/dist/tools/symbol-references.js +331 -0
- package/dist/tools/system-info.d.ts +3 -0
- package/dist/tools/system-info.js +55 -0
- package/dist/tools/write.d.ts +18 -0
- package/dist/tools/write.js +118 -0
- package/dist/tools/xref/index.d.ts +25 -0
- package/dist/tools/xref/index.js +25 -0
- package/dist/tools/xref/manager.d.ts +85 -0
- package/dist/tools/xref/manager.js +948 -0
- package/dist/tools/xref/parser.d.ts +34 -0
- package/dist/tools/xref/parser.js +64 -0
- package/dist/tools/xref/regex-parser.d.ts +26 -0
- package/dist/tools/xref/regex-parser.js +446 -0
- package/dist/tools/xref/schema.d.ts +104 -0
- package/dist/tools/xref/schema.js +68 -0
- package/dist/tools/xref/ts-parser.d.ts +20 -0
- package/dist/tools/xref/ts-parser.js +403 -0
- package/dist/tools/xref/xref-build.d.ts +20 -0
- package/dist/tools/xref/xref-build.js +128 -0
- package/dist/tools/xref/xref-graph.d.ts +24 -0
- package/dist/tools/xref/xref-graph.js +88 -0
- package/dist/tools/xref/xref-query.d.ts +30 -0
- package/dist/tools/xref/xref-query.js +123 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.js +2 -0
- package/dist/ui/assistant-message.d.ts +7 -0
- package/dist/ui/assistant-message.js +18 -0
- package/dist/ui/chat-log.d.ts +52 -0
- package/dist/ui/chat-log.js +246 -0
- package/dist/ui/command-registry.d.ts +73 -0
- package/dist/ui/command-registry.js +838 -0
- package/dist/ui/diff-component.d.ts +14 -0
- package/dist/ui/diff-component.js +42 -0
- package/dist/ui/hyperlink-markdown.d.ts +10 -0
- package/dist/ui/hyperlink-markdown.js +21 -0
- package/dist/ui/markdown-message.d.ts +10 -0
- package/dist/ui/markdown-message.js +16 -0
- package/dist/ui/osc8-hyperlinks.d.ts +4 -0
- package/dist/ui/osc8-hyperlinks.js +142 -0
- package/dist/ui/pi-tui-editor.d.ts +35 -0
- package/dist/ui/pi-tui-editor.js +79 -0
- package/dist/ui/slash-commands.d.ts +16 -0
- package/dist/ui/slash-commands.js +29 -0
- package/dist/ui/slash-panel.d.ts +54 -0
- package/dist/ui/slash-panel.js +199 -0
- package/dist/ui/theme.d.ts +120 -0
- package/dist/ui/theme.js +154 -0
- package/dist/ui/tool-display.d.ts +13 -0
- package/dist/ui/tool-display.js +85 -0
- package/dist/ui/tool-execution.d.ts +22 -0
- package/dist/ui/tool-execution.js +87 -0
- package/dist/ui/tui-formatters.d.ts +2 -0
- package/dist/ui/tui-formatters.js +145 -0
- package/dist/ui/user-message.d.ts +5 -0
- package/dist/ui/user-message.js +11 -0
- package/dist/update/check.d.ts +8 -0
- package/dist/update/check.js +28 -0
- package/dist/update/config.d.ts +6 -0
- package/dist/update/config.js +18 -0
- package/dist/update/download.d.ts +3 -0
- package/dist/update/download.js +27 -0
- package/dist/update/index.d.ts +6 -0
- package/dist/update/index.js +5 -0
- package/dist/update/install.d.ts +3 -0
- package/dist/update/install.js +33 -0
- package/dist/update/types.d.ts +16 -0
- package/dist/update/types.js +2 -0
- package/dist/utils/diff.d.ts +9 -0
- package/dist/utils/diff.js +45 -0
- package/dist/utils/misc.d.ts +12 -0
- package/dist/utils/misc.js +34 -0
- package/dist/world-engine/agent.d.ts +41 -0
- package/dist/world-engine/agent.js +385 -0
- package/dist/world-engine/index.d.ts +45 -0
- package/dist/world-engine/index.js +160 -0
- package/dist/world-engine/sim.d.ts +14 -0
- package/dist/world-engine/sim.js +120 -0
- package/dist/world-engine/store.d.ts +110 -0
- package/dist/world-engine/store.js +519 -0
- package/dist/world-engine/ticker.d.ts +37 -0
- package/dist/world-engine/ticker.js +214 -0
- package/dist/world-engine/tools.d.ts +6 -0
- package/dist/world-engine/tools.js +380 -0
- package/dist/world-engine/types.d.ts +202 -0
- package/dist/world-engine/types.js +56 -0
- package/docs/api.md +180 -0
- package/docs/architecture.md +206 -0
- package/docs/diagnostics/2026-06-08-config-prompt-guidance.md +67 -0
- package/docs/superpowers/plans/2026-06-08-global-bootstrap-mode.md +89 -0
- package/docs/superpowers/specs/2026-06-08-global-bootstrap-mode-design.md +174 -0
- package/docs/user-guide.md +226 -0
- package/package.json +63 -0
- package/plugins/example-greeter/index.js +55 -0
- package/plugins/example-greeter/plugin.json +8 -0
- package/pnpm-workspace.yaml +5 -0
- package/provider_arch.md +179 -0
- package/start-webui.sh +27 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/webui-channel-design.md +789 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// bypass/manager — BypassManager
|
|
3
|
+
// ============================================================
|
|
4
|
+
//
|
|
5
|
+
// 管理所有旁路Agent的生命周期和调度。
|
|
6
|
+
// 由 Loop 在每轮对话前后调用 preTurn/postTurn。
|
|
7
|
+
//
|
|
8
|
+
// 职责:
|
|
9
|
+
// - Agent 注册与启停
|
|
10
|
+
// - preTurn:收集所有活跃Agent的注入内容(阻塞,等旁路LLM完成)
|
|
11
|
+
// - postTurn:并行调度所有Agent的后台观察(不阻塞主流程)
|
|
12
|
+
// - 异常隔离:单个Agent失败不影响其他Agent和主流程
|
|
13
|
+
// ============================================================
|
|
14
|
+
import { createLogger } from '../logging/logger.js';
|
|
15
|
+
const logger = createLogger('bypass-manager');
|
|
16
|
+
export class BypassManager {
|
|
17
|
+
/** 所有已注册的Agent */
|
|
18
|
+
registry = new Map();
|
|
19
|
+
/** 当前激活的Agent列表 */
|
|
20
|
+
active = [];
|
|
21
|
+
/** 模型路由引用(注入后所有Agent共享) */
|
|
22
|
+
modelRouter = null;
|
|
23
|
+
/** 注入模型路由(factory 初始化后调用) */
|
|
24
|
+
setModelRouter(router) {
|
|
25
|
+
this.modelRouter = router;
|
|
26
|
+
for (const agent of this.registry.values()) {
|
|
27
|
+
if ('setModelRouter' in agent) {
|
|
28
|
+
agent.setModelRouter(router);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** 注册一个旁路Agent */
|
|
33
|
+
register(agent) {
|
|
34
|
+
this.registry.set(agent.name, agent);
|
|
35
|
+
if (this.modelRouter && 'setModelRouter' in agent) {
|
|
36
|
+
agent.setModelRouter(this.modelRouter);
|
|
37
|
+
}
|
|
38
|
+
// 注入 BypassManager 引用(供 postTurn 中调 inject() 用)
|
|
39
|
+
if ('_manager' in agent) {
|
|
40
|
+
agent._manager = this;
|
|
41
|
+
}
|
|
42
|
+
logger.info(`BypassAgent registered: ${agent.name} (modes: ${agent.modes.join(', ')})`);
|
|
43
|
+
}
|
|
44
|
+
/** 取消注册 */
|
|
45
|
+
unregister(name) {
|
|
46
|
+
this.registry.delete(name);
|
|
47
|
+
this.active = this.active.filter(a => a.name !== name);
|
|
48
|
+
}
|
|
49
|
+
/** 根据模式名激活对应的旁路Agent */
|
|
50
|
+
async activateForMode(modeName) {
|
|
51
|
+
// 先停用当前活跃的
|
|
52
|
+
await this.deactivateAll();
|
|
53
|
+
const toActivate = [];
|
|
54
|
+
for (const agent of this.registry.values()) {
|
|
55
|
+
if (agent.modes.includes('*') || agent.modes.includes(modeName)) {
|
|
56
|
+
toActivate.push(agent);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const agent of toActivate) {
|
|
60
|
+
try {
|
|
61
|
+
await agent.start();
|
|
62
|
+
this.active.push(agent);
|
|
63
|
+
logger.info(`BypassAgent started: ${agent.name} (mode: ${modeName})`);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
logger.warn(`BypassAgent start failed: ${agent.name}`, { error: err.message });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** 手动激活指定Agent(TUI命令用) */
|
|
71
|
+
async activateAgent(name) {
|
|
72
|
+
const agent = this.registry.get(name);
|
|
73
|
+
if (!agent) {
|
|
74
|
+
logger.warn(`BypassAgent not found: ${name}`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (this.active.includes(agent))
|
|
78
|
+
return;
|
|
79
|
+
try {
|
|
80
|
+
await agent.start();
|
|
81
|
+
this.active.push(agent);
|
|
82
|
+
logger.info(`BypassAgent manually activated: ${name}`);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
logger.warn(`BypassAgent start failed: ${name}`, { error: err.message });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** 手动停用指定Agent(TUI命令用) */
|
|
89
|
+
async deactivateAgent(name) {
|
|
90
|
+
const agent = this.registry.get(name);
|
|
91
|
+
if (!agent)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
await agent.stop();
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
logger.warn(`BypassAgent stop failed: ${name}`, { error: err.message });
|
|
98
|
+
}
|
|
99
|
+
this.active = this.active.filter(a => a !== agent);
|
|
100
|
+
logger.info(`BypassAgent deactivated: ${name}`);
|
|
101
|
+
}
|
|
102
|
+
/** 停用所有Agent */
|
|
103
|
+
async deactivateAll() {
|
|
104
|
+
for (const agent of this.active) {
|
|
105
|
+
try {
|
|
106
|
+
await agent.stop();
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
logger.warn(`BypassAgent stop failed: ${agent.name}`, { error: err.message });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
this.active = [];
|
|
113
|
+
}
|
|
114
|
+
/** 某Agent是否激活 */
|
|
115
|
+
isActive(name) {
|
|
116
|
+
return this.active.some(a => a.name === name);
|
|
117
|
+
}
|
|
118
|
+
/** 获取已注册的Agent(用于直接访问Agent特有方法,如 setPendingNarration) */
|
|
119
|
+
getAgent(name) {
|
|
120
|
+
return this.registry.get(name);
|
|
121
|
+
}
|
|
122
|
+
/** 获取激活列表 */
|
|
123
|
+
getActiveNames() {
|
|
124
|
+
return this.active.map(a => a.name);
|
|
125
|
+
}
|
|
126
|
+
/** 运行时注入:旁路Agent 在 postTurn 中可调用此方法写入纠正内容 */
|
|
127
|
+
_pendingInjections = [];
|
|
128
|
+
inject(agentName, injection) {
|
|
129
|
+
// 清除同一 agent 的旧注入,只保留最新
|
|
130
|
+
this._pendingInjections = this._pendingInjections.filter(ij => ij.section !== injection.section);
|
|
131
|
+
this._pendingInjections.push(injection);
|
|
132
|
+
logger.info(`BypassAgent injected: ${agentName} → ${injection.section}`);
|
|
133
|
+
}
|
|
134
|
+
/** 消费待注入内容(由 Loop 在 compose 前调用) */
|
|
135
|
+
consumeInjections() {
|
|
136
|
+
const injs = [...this._pendingInjections];
|
|
137
|
+
this._pendingInjections = [];
|
|
138
|
+
return injs;
|
|
139
|
+
}
|
|
140
|
+
// ── preTurn:阻塞,等所有旁路Agent完成 ──────────────────────
|
|
141
|
+
async preTurn(ctx) {
|
|
142
|
+
if (this.active.length === 0) {
|
|
143
|
+
return { injections: [] };
|
|
144
|
+
}
|
|
145
|
+
const allInjections = [];
|
|
146
|
+
let transformedInput;
|
|
147
|
+
for (const agent of this.active) {
|
|
148
|
+
if (!agent.preTurn)
|
|
149
|
+
continue;
|
|
150
|
+
try {
|
|
151
|
+
const result = await agent.preTurn(ctx);
|
|
152
|
+
if (result.transformedInput !== undefined) {
|
|
153
|
+
transformedInput = result.transformedInput;
|
|
154
|
+
}
|
|
155
|
+
allInjections.push(...result.injections);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
logger.warn(`BypassAgent preTurn failed: ${agent.name}`, { error: err.message });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return { transformedInput, injections: allInjections };
|
|
162
|
+
}
|
|
163
|
+
// ── postTurn:后台并行,不阻塞 ──────────────────────────────
|
|
164
|
+
postTurn(ctx) {
|
|
165
|
+
if (this.active.length === 0)
|
|
166
|
+
return;
|
|
167
|
+
Promise.allSettled(this.active.map(async (agent) => {
|
|
168
|
+
if (!agent.postTurn)
|
|
169
|
+
return;
|
|
170
|
+
try {
|
|
171
|
+
await agent.postTurn(ctx);
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
logger.warn(`BypassAgent postTurn failed: ${agent.name}`, { error: err.message });
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Message } from '../types.js';
|
|
2
|
+
/** preTurn 上下文:旁路Agent在每轮对话前的输入 */
|
|
3
|
+
export interface PreTurnContext {
|
|
4
|
+
/** 当前用户输入(原始文本) */
|
|
5
|
+
userInput: string;
|
|
6
|
+
/** 最近 N 轮对话原始消息 */
|
|
7
|
+
recentHistory: Message[];
|
|
8
|
+
/** 当前上下文预算 { used, total } */
|
|
9
|
+
contextBudget: {
|
|
10
|
+
used: number;
|
|
11
|
+
total: number;
|
|
12
|
+
};
|
|
13
|
+
/** 最近几轮的工具调用名称 */
|
|
14
|
+
recentToolCalls: string[];
|
|
15
|
+
}
|
|
16
|
+
/** postTurn 上下文:旁路Agent在每轮对话后的输入 */
|
|
17
|
+
export interface PostTurnContext {
|
|
18
|
+
/** 当前用户输入 */
|
|
19
|
+
userInput: string;
|
|
20
|
+
/** 主Agent的回复文本 */
|
|
21
|
+
assistantOutput: string;
|
|
22
|
+
/** 本轮对话历史(含用户输入和模型回复) */
|
|
23
|
+
history: Message[];
|
|
24
|
+
/** 本轮调用的工具名称 */
|
|
25
|
+
toolCallsThisTurn: string[];
|
|
26
|
+
/** 是否为本轮用户消息的最后一次迭代(loop 结束) */
|
|
27
|
+
isLastIteration: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** 注入到上下文中的 section */
|
|
30
|
+
export interface Injection {
|
|
31
|
+
/** 目标 section 名称(如 'timestamp', 'persona_soul') */
|
|
32
|
+
section: string;
|
|
33
|
+
/** 注入内容 */
|
|
34
|
+
content: string;
|
|
35
|
+
/** 消息角色 */
|
|
36
|
+
role: 'system' | 'assistant' | 'user';
|
|
37
|
+
/** 替换模式:replace=替换整个section, append=追加到末尾 */
|
|
38
|
+
mode: 'replace' | 'append';
|
|
39
|
+
}
|
|
40
|
+
/** preTurn 的返回结果 */
|
|
41
|
+
export interface PreTurnResult {
|
|
42
|
+
/** 变换后的用户输入(可选,World Engine 用于剥离 [[...]]) */
|
|
43
|
+
transformedInput?: string;
|
|
44
|
+
/** 要注入到上下文的 section 列表 */
|
|
45
|
+
injections: Injection[];
|
|
46
|
+
}
|
|
47
|
+
export interface BypassAgent {
|
|
48
|
+
/** 唯一标识 */
|
|
49
|
+
readonly name: string;
|
|
50
|
+
/** 声明适用的模式(如 ['companion'] 或 ['*'] 表示全部) */
|
|
51
|
+
readonly modes: string[];
|
|
52
|
+
/** 使用的模型通道名(对应 model-channels.json 中的通道) */
|
|
53
|
+
readonly modelChannel: string;
|
|
54
|
+
/** 启动(创建内部状态、启动定时器等) */
|
|
55
|
+
start(): Promise<void>;
|
|
56
|
+
/** 停止(清理资源、落盘) */
|
|
57
|
+
stop(): Promise<void>;
|
|
58
|
+
/** 前置介入:在 composer 组装之前调用 */
|
|
59
|
+
preTurn?(ctx: PreTurnContext): Promise<PreTurnResult>;
|
|
60
|
+
/** 后置观察:在主Agent回复之后调用(后台,不影响主流程) */
|
|
61
|
+
postTurn?(ctx: PostTurnContext): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// bypass/types — 旁路Agent 接口定义
|
|
3
|
+
// ============================================================
|
|
4
|
+
//
|
|
5
|
+
// 旁路Agent 是独立于主Agent运行的后台观察者。
|
|
6
|
+
// 在主对话流的前后介入:preTurn 产出注入内容,postTurn 观察并更新内部状态。
|
|
7
|
+
//
|
|
8
|
+
// 与主Agent的差异:
|
|
9
|
+
// - 独立模型通道(不抢占主Agent的上下文预算)
|
|
10
|
+
// - 异常隔离(任何错误不影响主流程)
|
|
11
|
+
// - 状态持久化(跨轮保持内部状态)
|
|
12
|
+
// ============================================================
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ChannelManager } from './manager.js';
|
|
2
|
+
import type { ChannelsInfo } from '../env/index.js';
|
|
3
|
+
export interface ChannelPlugin {
|
|
4
|
+
/** 配置 key 名(对应 config.json 中 channels 下的键名) */
|
|
5
|
+
configKey: string;
|
|
6
|
+
/** 自动注册渠道 */
|
|
7
|
+
autoRegister(channelManager: ChannelManager, config: unknown, channelsInfo: ChannelsInfo[]): Promise<void>;
|
|
8
|
+
/** Gateway 启动时执行全局设置(如日志拦截),返回清理函数 */
|
|
9
|
+
onGatewayInit?(): (() => void) | void;
|
|
10
|
+
}
|
|
11
|
+
export declare function registerChannelPlugin(plugin: ChannelPlugin): void;
|
|
12
|
+
export declare function getChannelPlugins(): ChannelPlugin[];
|
|
13
|
+
/**
|
|
14
|
+
* 自动发现渠道插件。
|
|
15
|
+
* 扫描 channels/plugins 下的子目录中导出的 channelPlugin 常量。
|
|
16
|
+
*/
|
|
17
|
+
export declare function discoverPlugins(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* 根据 config.json 注册所有配置驱动渠道。
|
|
20
|
+
* 不负责启动——由调用方通过 channelManager.startAll() 统一启动。
|
|
21
|
+
*
|
|
22
|
+
* @returns 已注册的渠道信息列表(用于注入到 System Prompt)
|
|
23
|
+
*/
|
|
24
|
+
export declare function registerConfigChannels(channelManager: ChannelManager, cwd: string): Promise<ChannelsInfo[]>;
|
|
25
|
+
//# sourceMappingURL=auto-detect.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// auto-detect.ts — 渠道自动检测(插件注册表模式)
|
|
3
|
+
// ============================================================
|
|
4
|
+
//
|
|
5
|
+
// 职责:
|
|
6
|
+
// 根据 config.json 自动检测并注册配置驱动渠道
|
|
7
|
+
// 通过 ChannelPlugin 注册表实现可扩展的渠道自动注册
|
|
8
|
+
// TUI 渠道始终默认允许,由调用方手动注册和启动
|
|
9
|
+
// HTTP 渠道由 serve 模式负责
|
|
10
|
+
//
|
|
11
|
+
// 使用方式:
|
|
12
|
+
// import { registerConfigChannels, registerChannelPlugin } from './channels/auto-detect.js';
|
|
13
|
+
// registerChannelPlugin(feishuChannelPlugin);
|
|
14
|
+
// const channelsInfo = await registerConfigChannels(channelManager, cwd);
|
|
15
|
+
// await channelManager.startAll(messageProcessor);
|
|
16
|
+
// ============================================================
|
|
17
|
+
import { ConfigManager } from '../setup/config.js';
|
|
18
|
+
// ─── 插件注册表 ─────────────────────────────────────────────────
|
|
19
|
+
const channelPlugins = [];
|
|
20
|
+
export function registerChannelPlugin(plugin) {
|
|
21
|
+
channelPlugins.push(plugin);
|
|
22
|
+
}
|
|
23
|
+
export function getChannelPlugins() {
|
|
24
|
+
return [...channelPlugins];
|
|
25
|
+
}
|
|
26
|
+
// ─── 自动注册入口 ───────────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* 自动发现渠道插件。
|
|
29
|
+
* 扫描 channels/plugins 下的子目录中导出的 channelPlugin 常量。
|
|
30
|
+
*/
|
|
31
|
+
export async function discoverPlugins() {
|
|
32
|
+
const fs = await import('node:fs/promises');
|
|
33
|
+
const path = await import('node:path');
|
|
34
|
+
const fileUrl = await import('node:url');
|
|
35
|
+
const pluginsDir = path.join(path.dirname(fileUrl.fileURLToPath(import.meta.url)), 'plugins');
|
|
36
|
+
try {
|
|
37
|
+
const entries = await fs.readdir(pluginsDir, { withFileTypes: true });
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
if (!entry.isDirectory())
|
|
40
|
+
continue;
|
|
41
|
+
try {
|
|
42
|
+
const mod = await import(`./plugins/${entry.name}/index.js`);
|
|
43
|
+
if (mod.channelPlugin && typeof mod.channelPlugin.autoRegister === 'function') {
|
|
44
|
+
channelPlugins.push(mod.channelPlugin);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// 插件加载失败,跳过
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// plugins 目录不存在,跳过
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 根据 config.json 注册所有配置驱动渠道。
|
|
58
|
+
* 不负责启动——由调用方通过 channelManager.startAll() 统一启动。
|
|
59
|
+
*
|
|
60
|
+
* @returns 已注册的渠道信息列表(用于注入到 System Prompt)
|
|
61
|
+
*/
|
|
62
|
+
export async function registerConfigChannels(channelManager, cwd) {
|
|
63
|
+
// 自动发现插件(如果尚未手动注册)
|
|
64
|
+
if (channelPlugins.length === 0) {
|
|
65
|
+
await discoverPlugins();
|
|
66
|
+
}
|
|
67
|
+
const channelsInfo = [];
|
|
68
|
+
const configManager = new ConfigManager(cwd);
|
|
69
|
+
await configManager.loadEnvKeys();
|
|
70
|
+
const agentConfig = await configManager.load();
|
|
71
|
+
for (const plugin of channelPlugins) {
|
|
72
|
+
const config = agentConfig.channels?.[plugin.configKey];
|
|
73
|
+
await plugin.autoRegister(channelManager, config, channelsInfo);
|
|
74
|
+
}
|
|
75
|
+
return channelsInfo;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=auto-detect.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ChannelHandler, ChannelEvent, ChannelReply, ChannelConfig, ChannelStatus } from '../interface.js';
|
|
2
|
+
export declare class HttpWebhookChannel implements ChannelHandler {
|
|
3
|
+
readonly id = "http-webhook";
|
|
4
|
+
readonly name = "HTTP Webhook";
|
|
5
|
+
readonly description = "\u5185\u5EFA HTTP REST API \u6E20\u9053\uFF0C\u652F\u6301 POST /api/chat webhook \u63A5\u5165\uFF08Bearer Token \u8BA4\u8BC1\uFF09";
|
|
6
|
+
readonly pluginId: undefined;
|
|
7
|
+
private app;
|
|
8
|
+
private status;
|
|
9
|
+
private eventHandler;
|
|
10
|
+
private provider;
|
|
11
|
+
private sessionManager;
|
|
12
|
+
private cwd;
|
|
13
|
+
private maxTurns;
|
|
14
|
+
private maxContext;
|
|
15
|
+
private activeComponents;
|
|
16
|
+
private wsAgentFactory;
|
|
17
|
+
start(config: ChannelConfig): Promise<void>;
|
|
18
|
+
stop(): Promise<void>;
|
|
19
|
+
onEvent(handler: (event: ChannelEvent) => Promise<void>): void;
|
|
20
|
+
reply(_sessionId: string, _reply: ChannelReply): Promise<void>;
|
|
21
|
+
getStatus(): ChannelStatus;
|
|
22
|
+
handleMessage(): Promise<void>;
|
|
23
|
+
private ensureComponents;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=http-webhook.d.ts.map
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// HttpWebhookChannel — 内建 HTTP REST API 渠道(企业加固版)
|
|
3
|
+
// ============================================================
|
|
4
|
+
//
|
|
5
|
+
// 端点:/api/health, /api/chat, /api/sessions, /api/tools, /api/skills
|
|
6
|
+
// 认证:Bearer Token(HYACINTH_API_KEY 环境变量或 --api-key 参数)
|
|
7
|
+
// Chat 为同步 request-response 模式。
|
|
8
|
+
// ============================================================
|
|
9
|
+
import { createLogger } from '../../logging/logger.js';
|
|
10
|
+
import { getModelContextWindow } from '../../setup/model-defaults.js';
|
|
11
|
+
import { getDefaultConfig } from '../../runtime/defaults.js';
|
|
12
|
+
const logger = createLogger('http-webhook');
|
|
13
|
+
// ── 认证 ────────────────────────────────────────────────────────────
|
|
14
|
+
function getApiKey(config) {
|
|
15
|
+
return config.apiKey
|
|
16
|
+
|| process.env.HYACINTH_API_KEY
|
|
17
|
+
|| process.env.AGENT_API_KEY
|
|
18
|
+
|| null;
|
|
19
|
+
}
|
|
20
|
+
function authHook(apiKey) {
|
|
21
|
+
return async (req, reply) => {
|
|
22
|
+
// /api/health 无需认证
|
|
23
|
+
if (req.url === '/api/health')
|
|
24
|
+
return;
|
|
25
|
+
if (!apiKey) {
|
|
26
|
+
return reply.status(401).send({
|
|
27
|
+
error: 'API key not configured. Set HYACINTH_API_KEY environment variable or pass --api-key.',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const auth = req.headers['authorization'] ?? '';
|
|
31
|
+
const bearer = auth.startsWith('Bearer ') ? auth.slice(7) : '';
|
|
32
|
+
if (bearer !== apiKey) {
|
|
33
|
+
return reply.status(401).send({ error: 'Invalid or missing API key. Use Authorization: Bearer <key>' });
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// ── CollectHandler ────────────────────────────────────────────────
|
|
38
|
+
/** 收集 agent 输出的 handler */
|
|
39
|
+
class CollectHandler {
|
|
40
|
+
texts = [];
|
|
41
|
+
toolCalls = [];
|
|
42
|
+
statusMessages = [];
|
|
43
|
+
onText(content) { this.texts.push(content); }
|
|
44
|
+
onThinking(_content) { }
|
|
45
|
+
onToolUse(name, inputSummary) {
|
|
46
|
+
this.toolCalls.push({ name, input: inputSummary, isError: false, result: '' });
|
|
47
|
+
}
|
|
48
|
+
onToolResult(content, isError) {
|
|
49
|
+
const last = this.toolCalls.length > 0 ? this.toolCalls[this.toolCalls.length - 1] : undefined;
|
|
50
|
+
if (last && !last.result) {
|
|
51
|
+
last.isError = isError;
|
|
52
|
+
last.result = content;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
onStatus(message, _level) { this.statusMessages.push(message); }
|
|
56
|
+
onTurnStart() { }
|
|
57
|
+
onFlush() { }
|
|
58
|
+
onInterrupt() { }
|
|
59
|
+
onPermissionRequest(toolName, input) {
|
|
60
|
+
void toolName;
|
|
61
|
+
void input;
|
|
62
|
+
return Promise.resolve(true);
|
|
63
|
+
}
|
|
64
|
+
getFullText() {
|
|
65
|
+
return this.texts.join('\n');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// ── HttpWebhookChannel ───────────────────────────────────────────
|
|
69
|
+
export class HttpWebhookChannel {
|
|
70
|
+
id = 'http-webhook';
|
|
71
|
+
name = 'HTTP Webhook';
|
|
72
|
+
description = '内建 HTTP REST API 渠道,支持 POST /api/chat webhook 接入(Bearer Token 认证)';
|
|
73
|
+
pluginId = undefined;
|
|
74
|
+
app = null;
|
|
75
|
+
status = 'registered';
|
|
76
|
+
eventHandler = null;
|
|
77
|
+
provider;
|
|
78
|
+
sessionManager;
|
|
79
|
+
cwd;
|
|
80
|
+
maxTurns;
|
|
81
|
+
maxContext;
|
|
82
|
+
activeComponents = null;
|
|
83
|
+
wsAgentFactory = null;
|
|
84
|
+
async start(config) {
|
|
85
|
+
const { port = 3000, host = '0.0.0.0' } = config;
|
|
86
|
+
// 从 config 获取 agentFactory(由 ChannelManager.startChannel 注入)
|
|
87
|
+
this.wsAgentFactory = config.agentFactory ?? null;
|
|
88
|
+
this.provider = config.provider;
|
|
89
|
+
this.sessionManager = config.sessionManager;
|
|
90
|
+
this.cwd = config.cwd;
|
|
91
|
+
this.maxTurns = config.maxTurns ?? getDefaultConfig().session.maxTurns;
|
|
92
|
+
this.maxContext = config.maxContext ?? getModelContextWindow(this.provider.getProviderType(), this.provider.getModel());
|
|
93
|
+
const apiKey = getApiKey(config);
|
|
94
|
+
if (!apiKey) {
|
|
95
|
+
logger.warn('No HYACINTH_API_KEY set — HTTP API will reject all requests except /api/health. Set the environment variable or use --api-key.');
|
|
96
|
+
}
|
|
97
|
+
const fastify = (await import('fastify')).default;
|
|
98
|
+
this.app = fastify({ logger: false });
|
|
99
|
+
// ── 安全加固(全路由)───────────────────────────────────────────
|
|
100
|
+
this.app.addHook('preHandler', authHook(apiKey));
|
|
101
|
+
this.app.addHook('onSend', async (_req, reply) => {
|
|
102
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
103
|
+
reply.header('X-Frame-Options', 'DENY');
|
|
104
|
+
reply.header('X-XSS-Protection', '1; mode=block');
|
|
105
|
+
reply.header('Access-Control-Allow-Origin', config.corsOrigin || '*');
|
|
106
|
+
reply.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
107
|
+
reply.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
108
|
+
});
|
|
109
|
+
// OPTIONS preflight
|
|
110
|
+
this.app.options('*', async (_req, reply) => {
|
|
111
|
+
return reply.status(204).send();
|
|
112
|
+
});
|
|
113
|
+
// ── Health ──────────────────────────────────────────────────
|
|
114
|
+
this.app.get('/api/health', async (_req, reply) => {
|
|
115
|
+
return reply.send({ status: 'ok', version: '1.0.0', auth: !!apiKey });
|
|
116
|
+
});
|
|
117
|
+
// ── Chat ────────────────────────────────────────────────────
|
|
118
|
+
this.app.post('/api/chat', async (req, reply) => {
|
|
119
|
+
const body = req.body;
|
|
120
|
+
if (!body.message) {
|
|
121
|
+
return reply.status(400).send({ error: 'message is required' });
|
|
122
|
+
}
|
|
123
|
+
const handler = new CollectHandler();
|
|
124
|
+
try {
|
|
125
|
+
const { createAgent } = await import('../../gateway/factory.js');
|
|
126
|
+
const { loop, sessionDir } = await createAgent({
|
|
127
|
+
cwd: this.cwd,
|
|
128
|
+
provider: this.provider,
|
|
129
|
+
maxTurns: this.maxTurns,
|
|
130
|
+
maxContext: this.maxContext,
|
|
131
|
+
outputHandler: handler,
|
|
132
|
+
sessionId: body.sessionId,
|
|
133
|
+
shouldContinue: !body.sessionId,
|
|
134
|
+
});
|
|
135
|
+
if (body.images?.length)
|
|
136
|
+
loop.channelImages = body.images;
|
|
137
|
+
await loop.run(body.message);
|
|
138
|
+
const sessionId = sessionDir.split(/[\\/]/).pop() ?? '';
|
|
139
|
+
if (this.eventHandler) {
|
|
140
|
+
this.eventHandler({
|
|
141
|
+
type: 'message',
|
|
142
|
+
sessionId,
|
|
143
|
+
userId: 'http-user',
|
|
144
|
+
content: body.message,
|
|
145
|
+
channel: this.id,
|
|
146
|
+
metadata: { source: 'http-webhook' },
|
|
147
|
+
}).catch(() => { });
|
|
148
|
+
}
|
|
149
|
+
return reply.send({
|
|
150
|
+
sessionId,
|
|
151
|
+
content: handler.getFullText(),
|
|
152
|
+
turns: handler.toolCalls.length,
|
|
153
|
+
toolCalls: handler.toolCalls.map(t => ({ name: t.name, input: t.input })),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
158
|
+
logger.error('Chat error', undefined, { error: message });
|
|
159
|
+
return reply.status(500).send({ error: message });
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
// ── Sessions ────────────────────────────────────────────────
|
|
163
|
+
this.app.get('/api/sessions', async (_req, reply) => {
|
|
164
|
+
const sessions = await this.sessionManager.list();
|
|
165
|
+
return reply.send(sessions);
|
|
166
|
+
});
|
|
167
|
+
this.app.post('/api/sessions', async (_req, reply) => {
|
|
168
|
+
const session = await this.sessionManager.create('normal', 'http-webhook');
|
|
169
|
+
return reply.send({ id: session.id, createdAt: session.createdAt });
|
|
170
|
+
});
|
|
171
|
+
this.app.get('/api/sessions/:id', async (req, reply) => {
|
|
172
|
+
const { id } = req.params;
|
|
173
|
+
try {
|
|
174
|
+
const session = await this.sessionManager.resume(id);
|
|
175
|
+
return reply.send({ id: session.id, createdAt: session.createdAt });
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return reply.status(404).send({ error: 'Session not found' });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
this.app.delete('/api/sessions/:id', async (req, reply) => {
|
|
182
|
+
const { id } = req.params;
|
|
183
|
+
try {
|
|
184
|
+
const fs = await import('node:fs/promises');
|
|
185
|
+
const path = await import('node:path');
|
|
186
|
+
const os = await import('node:os');
|
|
187
|
+
const sessionDir = path.join(os.homedir(), '.agent', 'sessions', id);
|
|
188
|
+
await fs.rm(sessionDir, { recursive: true, force: true });
|
|
189
|
+
return reply.send({ ok: true });
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return reply.status(404).send({ error: 'Session not found' });
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
// ── Tools & Skills ──────────────────────────────────────────
|
|
196
|
+
this.app.get('/api/tools', async (_req, reply) => {
|
|
197
|
+
const components = await this.ensureComponents();
|
|
198
|
+
const tools = components.toolRegistry.getAll().map(t => ({
|
|
199
|
+
name: t.name,
|
|
200
|
+
description: t.description,
|
|
201
|
+
}));
|
|
202
|
+
return reply.send(tools);
|
|
203
|
+
});
|
|
204
|
+
this.app.get('/api/skills', async (_req, reply) => {
|
|
205
|
+
const components = await this.ensureComponents();
|
|
206
|
+
const skills = components.skillRegistry.getAll().map(s => ({
|
|
207
|
+
name: s.name,
|
|
208
|
+
description: s.description,
|
|
209
|
+
source: s.source,
|
|
210
|
+
}));
|
|
211
|
+
return reply.send(skills);
|
|
212
|
+
});
|
|
213
|
+
// ── TUI WebSocket 端点(让 TUI 客户端通过 ws://host:port/tui 连接统一后端) ─
|
|
214
|
+
const { WebSocketServer } = await import('ws');
|
|
215
|
+
const { TuiWsSession } = await import('./tui-ws-session.js');
|
|
216
|
+
const { randomBytes } = await import('node:crypto');
|
|
217
|
+
const tuiWss = new WebSocketServer({ noServer: true });
|
|
218
|
+
this.app.server.on('upgrade', (request, socket, head) => {
|
|
219
|
+
if (request.url === '/tui') {
|
|
220
|
+
tuiWss.handleUpgrade(request, socket, head, (ws) => {
|
|
221
|
+
tuiWss.emit('connection', ws, request);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
socket.destroy();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
tuiWss.on('connection', (ws) => {
|
|
229
|
+
const sessionId = `tui_${Date.now().toString(36)}-${randomBytes(3).toString('hex')}`;
|
|
230
|
+
const session = new TuiWsSession(ws, sessionId);
|
|
231
|
+
logger.info('TUI WS client connected', { sessionId });
|
|
232
|
+
if (this.wsAgentFactory) {
|
|
233
|
+
session.initialize(this.wsAgentFactory).catch((err) => {
|
|
234
|
+
logger.error('TUI WS init failed', err instanceof Error ? err : new Error(String(err)));
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
logger.warn('TUI WS agentFactory not available');
|
|
239
|
+
}
|
|
240
|
+
ws.on('message', (data) => {
|
|
241
|
+
session.handleMessage(data).catch((err) => {
|
|
242
|
+
logger.error('TUI WS msg error', err instanceof Error ? err : new Error(String(err)));
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
ws.on('close', () => {
|
|
246
|
+
session.close().catch(() => { });
|
|
247
|
+
logger.info('TUI WS client disconnected', { sessionId });
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
// ── Start ───────────────────────────────────────────────────
|
|
251
|
+
await this.app.listen({ port: port, host: host });
|
|
252
|
+
this.status = 'active';
|
|
253
|
+
logger.info(`HTTP API listening on ${host}:${port}${apiKey ? ' (auth enabled)' : ' (auth: only /api/health)'}`);
|
|
254
|
+
}
|
|
255
|
+
async stop() {
|
|
256
|
+
if (this.app) {
|
|
257
|
+
await this.app.close();
|
|
258
|
+
this.app = null;
|
|
259
|
+
}
|
|
260
|
+
this.status = 'stopped';
|
|
261
|
+
}
|
|
262
|
+
onEvent(handler) {
|
|
263
|
+
this.eventHandler = handler;
|
|
264
|
+
}
|
|
265
|
+
async reply(_sessionId, _reply) {
|
|
266
|
+
// HTTP webhook 模式下回复已在 POST /api/chat 响应中同步返回
|
|
267
|
+
}
|
|
268
|
+
getStatus() { return this.status; }
|
|
269
|
+
async handleMessage() {
|
|
270
|
+
throw new Error('HTTP webhook channel does not support handleMessage');
|
|
271
|
+
}
|
|
272
|
+
async ensureComponents() {
|
|
273
|
+
if (!this.activeComponents) {
|
|
274
|
+
const { createAgent } = await import('../../gateway/factory.js');
|
|
275
|
+
const handler = new CollectHandler();
|
|
276
|
+
this.activeComponents = await createAgent({
|
|
277
|
+
cwd: this.cwd,
|
|
278
|
+
provider: this.provider,
|
|
279
|
+
maxTurns: this.maxTurns,
|
|
280
|
+
maxContext: this.maxContext,
|
|
281
|
+
outputHandler: handler,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return this.activeComponents;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=http-webhook.js.map
|