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,789 @@
|
|
|
1
|
+
# WebUI 渠道层架构设计
|
|
2
|
+
|
|
3
|
+
> 从 Channel 抽象层出发,设计 Hyacinth 的 Web 前端。
|
|
4
|
+
> WebUI 不是独立的应用——它只是框架的又一个 **Channel**,与 TUI、HTTP Webhook、飞书平级。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. 架构总览
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
┌────────────────────────────────────────────────────────────┐
|
|
12
|
+
│ Gateway (gateway/) │
|
|
13
|
+
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────────┐ │
|
|
14
|
+
│ │ TUI │ │ HTTP │ │ Feishu │ │ WebUI │ │
|
|
15
|
+
│ │ Channel │ │ Webhook │ │ Channel │ │ Channel │ │
|
|
16
|
+
│ │ (blessed)│ │ (fastify)│ │ (lark) │ │ (fastify │ │
|
|
17
|
+
│ │ │ │ │ │ │ │ + WS) │ │
|
|
18
|
+
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └─────┬─────┘ │
|
|
19
|
+
│ │ │ │ │ │
|
|
20
|
+
│ └─────────────┴─────────────┴──────────────┘ │
|
|
21
|
+
│ │ │
|
|
22
|
+
│ ChannelManager │
|
|
23
|
+
│ │ │
|
|
24
|
+
│ AgentFactory │
|
|
25
|
+
│ │ │
|
|
26
|
+
│ AgentLoop │
|
|
27
|
+
└────────────────────────────────────────────────────────────┘
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**核心原则:**
|
|
31
|
+
|
|
32
|
+
1. **WebUI 是一个 Channel,不是独立应用。** 实现 `ChannelHandler` 接口,通过 `ChannelManager` 管理生命周期。
|
|
33
|
+
2. **WebSocket 是主力传输层。** LLM 输出是流式的——不能用 HTTP request-response(那是 HTTP Webhook 的局限),必须用 WebSocket 做双向流。
|
|
34
|
+
3. **前端无状态,服务端有状态。** Session、AgentLoop、Turn 全部由服务端管理,前端只负责渲染和输入。
|
|
35
|
+
4. **OutputHandler → WebSocket 消息是一一映射。** 每个 `OutputHandler` 回调对应一个 WebSocket 消息类型。
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 2. WebUIChannel — 渠道实现
|
|
40
|
+
|
|
41
|
+
### 2.1 接口实现
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// src/channels/builtin/webui-channel.ts
|
|
45
|
+
|
|
46
|
+
export class WebuiChannel implements ChannelHandler {
|
|
47
|
+
readonly id = 'webui';
|
|
48
|
+
readonly name = 'Web UI';
|
|
49
|
+
readonly description = '内建 Web 前端,通过浏览器访问,支持 WebSocket 实时流式输出';
|
|
50
|
+
readonly pluginId = undefined;
|
|
51
|
+
|
|
52
|
+
private app: FastifyInstance | null = null;
|
|
53
|
+
private wss: WebSocketServer | null = null;
|
|
54
|
+
private status: ChannelStatus = 'registered';
|
|
55
|
+
private eventHandler: ((event: ChannelEvent) => Promise<void>) | null = null;
|
|
56
|
+
|
|
57
|
+
// 每个 WebSocket 连接对应一个 AgentLoop 会话
|
|
58
|
+
private connections = new Map<string, WebSocketSession>();
|
|
59
|
+
|
|
60
|
+
async start(config: ChannelConfig): Promise<void> { ... }
|
|
61
|
+
async stop(): Promise<void> { ... }
|
|
62
|
+
onEvent(handler: (event: ChannelEvent) => Promise<void>): void { ... }
|
|
63
|
+
reply(sessionId: string, reply: ChannelReply): Promise<void> { ... }
|
|
64
|
+
handleMessage(event: ChannelMessageEvent, replyFn: ReplyFn, agentFactory: AgentFactory): Promise<void> { ... }
|
|
65
|
+
getStatus(): ChannelStatus { ... }
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2.2 生命周期
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
start()
|
|
73
|
+
├── 创建 Fastify 实例
|
|
74
|
+
├── 注册 REST API 路由(/api/*)
|
|
75
|
+
├── 挂载 WebSocket(/ws)
|
|
76
|
+
├── 配置静态文件服务(前端构建产物)
|
|
77
|
+
└── 监听端口(默认 3100)
|
|
78
|
+
|
|
79
|
+
stop()
|
|
80
|
+
├── 关闭所有 WebSocket 连接
|
|
81
|
+
├── 关闭 Fastify
|
|
82
|
+
└── 清理 connections Map
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 2.3 WebSocket 会话模型
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
interface WebSocketSession {
|
|
89
|
+
ws: WebSocket;
|
|
90
|
+
loop: ChannelSessionRunner; // AgentLoop 实例
|
|
91
|
+
outputHandler: WebUIOutputHandler; // 桥接 OutputHandler → WS 消息
|
|
92
|
+
sessionId: string;
|
|
93
|
+
createdAt: number;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
每个浏览器标签页 = 一个 WebSocket 连接 = 一个 AgentLoop 实例。这与 TUI 的模型一致(一个终端窗口 = 一个 AgentLoop)。
|
|
98
|
+
|
|
99
|
+
### 2.4 静态文件服务
|
|
100
|
+
|
|
101
|
+
前端构建产物目录:`.agent/webui/dist/`(开发时可由 Vite dev server 独立运行)
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
生产模式:Fastify 直接 serve dist/
|
|
105
|
+
开发模式:Fastify 代理到 Vite dev server (localhost:5173)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
通过 config 控制:
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"channels": {
|
|
112
|
+
"webui": {
|
|
113
|
+
"enabled": true,
|
|
114
|
+
"port": 3100,
|
|
115
|
+
"host": "0.0.0.0",
|
|
116
|
+
"devMode": false,
|
|
117
|
+
"devServerUrl": "http://localhost:5173"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 3. WebSocket 协议
|
|
126
|
+
|
|
127
|
+
### 3.1 消息类型定义
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
Client → Server:
|
|
131
|
+
┌──────────────┬──────────────────────────────────────────┐
|
|
132
|
+
│ type │ payload │
|
|
133
|
+
├──────────────┼──────────────────────────────────────────┤
|
|
134
|
+
│ chat │ { content: string, images?: [...] } │
|
|
135
|
+
│ stop │ {} │
|
|
136
|
+
│ permission │ { result: "yes" | "no" | "always" } │
|
|
137
|
+
│ set_mode │ { mode: "normal" | "precise" } │
|
|
138
|
+
└──────────────┴──────────────────────────────────────────┘
|
|
139
|
+
|
|
140
|
+
Server → Client:
|
|
141
|
+
┌──────────────┬──────────────────────────────────────────┐
|
|
142
|
+
│ type │ payload │
|
|
143
|
+
├──────────────┼──────────────────────────────────────────┤
|
|
144
|
+
│ text │ { content: string } │
|
|
145
|
+
│ thinking │ { content: string } │
|
|
146
|
+
│ tool_use │ { id, name, inputSummary: string } │
|
|
147
|
+
│ tool_result │ { id, content, isError: bool } │
|
|
148
|
+
│ diff │ { id, filePath, diffLines } │
|
|
149
|
+
│ status │ { message, level: "info"|"warn"|"error" }│
|
|
150
|
+
│ turn_start │ {} │
|
|
151
|
+
│ flush │ {} │
|
|
152
|
+
│ interrupt │ {} │
|
|
153
|
+
│ turn_info │ { turnCount, maxTurns, tokensUsed, ... } │
|
|
154
|
+
│ permission │ { toolName, input } │
|
|
155
|
+
│ error │ { message: string } │
|
|
156
|
+
│ connected │ { sessionId, config: SessionConfig } │
|
|
157
|
+
└──────────────┴──────────────────────────────────────────┘
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 3.2 OutputHandler → WS 消息映射
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
class WebUIOutputHandler implements OutputHandler {
|
|
164
|
+
constructor(private ws: WebSocket) {}
|
|
165
|
+
|
|
166
|
+
onText(content: string) {
|
|
167
|
+
this.send({ type: 'text', content });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
onThinking(content: string) {
|
|
171
|
+
this.send({ type: 'thinking', content });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
onToolUse(name: string, inputSummary: string, toolId?: string) {
|
|
175
|
+
this.send({ type: 'tool_use', id: toolId, name, inputSummary });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
onToolResult(content: string, isError: boolean, toolId?: string) {
|
|
179
|
+
this.send({ type: 'tool_result', id: toolId, content, isError });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
onDiff(toolId: string, filePath: string, diffLines: Array<{ kind: string; text: string }>) {
|
|
183
|
+
this.send({ type: 'diff', id: toolId, filePath, diffLines });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
onStatus(message: string, level: 'info' | 'warn' | 'error') {
|
|
187
|
+
this.send({ type: 'status', message, level });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
onTurnStart() {
|
|
191
|
+
this.send({ type: 'turn_start' });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
onFlush() {
|
|
195
|
+
this.send({ type: 'flush' });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
onInterrupt() {
|
|
199
|
+
this.send({ type: 'interrupt' });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async onPermissionRequest(toolName: string, input: Record<string, unknown>): Promise<'yes' | 'no' | 'always'> {
|
|
203
|
+
// 发送权限请求 → 等待用户响应
|
|
204
|
+
this.send({ type: 'permission', toolName, input });
|
|
205
|
+
return new Promise(resolve => {
|
|
206
|
+
this.permissionResolve = resolve;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 额外的 WebUI 专属方法
|
|
211
|
+
sendTurnInfo(info: TurnInfo) {
|
|
212
|
+
this.send({ type: 'turn_info', ...info });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private send(msg: Record<string, unknown>) {
|
|
216
|
+
if (this.ws.readyState === WebSocket.OPEN) {
|
|
217
|
+
this.ws.send(JSON.stringify(msg));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 3.3 时序示例
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
Client Server (WebUIChannel) AgentLoop
|
|
227
|
+
│ │ │
|
|
228
|
+
│── chat {content:"写一个"}────▶│ │
|
|
229
|
+
│ │── run("写一个")──────────────▶│
|
|
230
|
+
│ │ │── compose context
|
|
231
|
+
│ │◀── onTurnStart() ────────────│
|
|
232
|
+
│◀── turn_start ──────────────│ │
|
|
233
|
+
│ │ │── call LLM (streaming)
|
|
234
|
+
│◀── thinking "让我想想..." ───│◀── onThinking() ─────────────│
|
|
235
|
+
│◀── text "好的,我来写..." ───│◀── onText() ──────────────────│
|
|
236
|
+
│◀── tool_use {write,...} ────│◀── onToolUse() ──────────────│
|
|
237
|
+
│ │ │── execute tool
|
|
238
|
+
│ │ │── recordPreState
|
|
239
|
+
│◀── tool_result {ok} ────────│◀── onToolResult() ───────────│
|
|
240
|
+
│◀── diff {file,lines} ───────│◀── onDiff() ─────────────────│
|
|
241
|
+
│◀── text "完成了!" ─────────│◀── onText() ──────────────────│
|
|
242
|
+
│◀── flush ──────────────────│◀── onFlush() ────────────────│
|
|
243
|
+
│◀── turn_info {...} ────────│ │
|
|
244
|
+
│ │ │── endTurn → save record
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 3.4 权限请求流
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
Client Server
|
|
251
|
+
│ │
|
|
252
|
+
│◀── permission {toolName, input} ──│ (AgentLoop 阻塞等待)
|
|
253
|
+
│ │
|
|
254
|
+
│ [用户点击 Yes / Always / No] │
|
|
255
|
+
│ │
|
|
256
|
+
│── permission {result:"yes"} ──────▶│
|
|
257
|
+
│ │── resolve("yes") → AgentLoop 继续
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
与 TUI 的 `permissionQueue` 机制等价——但 WebUI 用 popup modal 代替终端内联选择。
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 4. REST API 表面
|
|
265
|
+
|
|
266
|
+
这些端点在 `start()` 中注册到 Fastify,用于前端查询数据(非流式)。
|
|
267
|
+
|
|
268
|
+
### 4.1 基础设施
|
|
269
|
+
|
|
270
|
+
| 方法 | 路径 | 说明 |
|
|
271
|
+
|------|------|------|
|
|
272
|
+
| GET | `/api/health` | 健康检查 + 版本 |
|
|
273
|
+
| GET | `/api/status` | Agent 运行状态(当前 session、turn、provider、context 用量等) |
|
|
274
|
+
|
|
275
|
+
### 4.2 Session 管理
|
|
276
|
+
|
|
277
|
+
| 方法 | 路径 | 说明 |
|
|
278
|
+
|------|------|------|
|
|
279
|
+
| GET | `/api/sessions` | 列出所有 session |
|
|
280
|
+
| POST | `/api/sessions` | 创建新 session |
|
|
281
|
+
| GET | `/api/sessions/:id` | 获取 session 详情 |
|
|
282
|
+
| DELETE | `/api/sessions/:id` | 删除 session |
|
|
283
|
+
| POST | `/api/sessions/:id/switch` | 切换到指定 session |
|
|
284
|
+
|
|
285
|
+
### 4.3 能力发现
|
|
286
|
+
|
|
287
|
+
| 方法 | 路径 | 说明 |
|
|
288
|
+
|------|------|------|
|
|
289
|
+
| GET | `/api/tools` | 列出所有工具(name + description + schema) |
|
|
290
|
+
| GET | `/api/skills` | 列出所有 Skill |
|
|
291
|
+
| GET | `/api/agents` | 列出所有子 Agent |
|
|
292
|
+
| GET | `/api/workflows` | 列出所有 Workflow |
|
|
293
|
+
| GET | `/api/channels` | 列出所有渠道及状态 |
|
|
294
|
+
|
|
295
|
+
### 4.4 配置
|
|
296
|
+
|
|
297
|
+
| 方法 | 路径 | 说明 |
|
|
298
|
+
|------|------|------|
|
|
299
|
+
| GET | `/api/config` | 读取当前配置(脱敏) |
|
|
300
|
+
| PATCH | `/api/config` | 部分更新配置 |
|
|
301
|
+
|
|
302
|
+
### 4.5 回滚 & 知识库
|
|
303
|
+
|
|
304
|
+
| 方法 | 路径 | 说明 |
|
|
305
|
+
|------|------|------|
|
|
306
|
+
| GET | `/api/rollback/status` | 可回滚的回合列表 |
|
|
307
|
+
| POST | `/api/rollback` | 执行回滚 `{ turns: N }` |
|
|
308
|
+
| GET | `/api/kb/query?q=...` | 知识库搜索 |
|
|
309
|
+
| GET | `/api/kb/stats` | 知识库统计 |
|
|
310
|
+
|
|
311
|
+
### 4.6 后台进程 & 事件
|
|
312
|
+
|
|
313
|
+
| 方法 | 路径 | 说明 |
|
|
314
|
+
|------|------|------|
|
|
315
|
+
| GET | `/api/processes` | 后台进程列表 |
|
|
316
|
+
| POST | `/api/processes/:id/kill` | 终止后台进程 |
|
|
317
|
+
| GET | `/api/sessions/:id/events` | 获取 session 的历史事件(用于重放) |
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## 5. 前端组件架构
|
|
322
|
+
|
|
323
|
+
### 5.1 技术选型
|
|
324
|
+
|
|
325
|
+
| 层 | 选择 | 理由 |
|
|
326
|
+
|----|------|------|
|
|
327
|
+
| 框架 | **React 18** + TypeScript | 生态最大,流式 UI 更新模式成熟 |
|
|
328
|
+
| 构建 | **Vite** | 快速 HMR,开发体验好 |
|
|
329
|
+
| 样式 | **Tailwind CSS** | 零运行时,组件级样式隔离 |
|
|
330
|
+
| 状态 | **Zustand** | 轻量,适合 WebSocket 事件驱动 |
|
|
331
|
+
| 编辑器 | **CodeMirror 6** | 支持语法高亮 + slash-command 补全 |
|
|
332
|
+
| Diff 展示 | **react-diff-viewer** 或自研 | 与 TUI 的 diff-component 对齐 |
|
|
333
|
+
|
|
334
|
+
### 5.2 组件树
|
|
335
|
+
|
|
336
|
+
```
|
|
337
|
+
<App>
|
|
338
|
+
<WebSocketProvider> ← WebSocket 连接管理
|
|
339
|
+
<Layout>
|
|
340
|
+
<Sidebar>
|
|
341
|
+
<SessionList /> ← 会话列表 + 切换 + 新建
|
|
342
|
+
<ChannelStatusBar /> ← 各渠道状态指示灯
|
|
343
|
+
<ModelInfo /> ← 当前 Provider / Model
|
|
344
|
+
<WorkflowPanel /> ← 当前工作流 + 进度
|
|
345
|
+
</Sidebar>
|
|
346
|
+
|
|
347
|
+
<MainPanel>
|
|
348
|
+
<Header>
|
|
349
|
+
<Breadcrumb /> ← Session > Turn #N
|
|
350
|
+
<TurnCounter /> ← Turns: 3/20
|
|
351
|
+
<ProviderBadge /> ← deepseek / claude-opus-4-8
|
|
352
|
+
<ModeIndicator /> ← 普通 / 精确 / Workflow
|
|
353
|
+
<ContextBar /> ← ████░░ 45% (45K / 100K) Cache: 78%
|
|
354
|
+
</Header>
|
|
355
|
+
|
|
356
|
+
<ChatLog> ← 虚拟滚动(支持大量历史)
|
|
357
|
+
<MessageGroup> ← 一组连续的 user/assistant 消息
|
|
358
|
+
<UserBubble />
|
|
359
|
+
<AssistantSection>
|
|
360
|
+
<ThinkingBlock /> ← 可折叠的 thinking 内容
|
|
361
|
+
<TextBlock /> ← Markdown 渲染
|
|
362
|
+
<ToolCallCard> ← 可展开/折叠
|
|
363
|
+
<ToolHeader /> ← name + input summary
|
|
364
|
+
<ToolResult /> ← 输出内容
|
|
365
|
+
<DiffView /> ← 代码 diff(side-by-side 或 unified)
|
|
366
|
+
</ToolCallCard>
|
|
367
|
+
</AssistantSection>
|
|
368
|
+
</MessageGroup>
|
|
369
|
+
</ChatLog>
|
|
370
|
+
|
|
371
|
+
<PermissionModal /> ← 危险工具确认弹窗
|
|
372
|
+
|
|
373
|
+
<InputArea>
|
|
374
|
+
<ContextIndicator /> ← 当前已附着文件/图片
|
|
375
|
+
<ImageUpload />
|
|
376
|
+
<SlashCommandPopup /> ← / 触发命令补全
|
|
377
|
+
<CodeEditor /> ← 主输入区(支持多行)
|
|
378
|
+
<SendButton />
|
|
379
|
+
<StopButton /> ← 仅在 processing 时显示
|
|
380
|
+
</InputArea>
|
|
381
|
+
</MainPanel>
|
|
382
|
+
|
|
383
|
+
<StatusBar>
|
|
384
|
+
<ConnectionDot /> ← 🟢 WebSocket 已连接
|
|
385
|
+
<BgProcessCount /> ← ⚙ 2 bg
|
|
386
|
+
<TokenEstimate /> ← ~256 tokens
|
|
387
|
+
</StatusBar>
|
|
388
|
+
</Layout>
|
|
389
|
+
</WebSocketProvider>
|
|
390
|
+
</App>
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### 5.3 状态管理(Zustand Store)
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
interface WebUIState {
|
|
397
|
+
// ── 连接 ──
|
|
398
|
+
connected: boolean;
|
|
399
|
+
sessionId: string | null;
|
|
400
|
+
|
|
401
|
+
// ── 消息流 ──
|
|
402
|
+
messages: MessageNode[]; // 完整消息树(含 thinking / tool / diff)
|
|
403
|
+
currentText: string; // 正在流式输出的文本
|
|
404
|
+
currentThinking: string; // 正在流式输出的 thinking
|
|
405
|
+
|
|
406
|
+
// ── 工具状态 ──
|
|
407
|
+
activeToolCalls: Map<string, ToolCallState>; // 进行中的工具调用
|
|
408
|
+
|
|
409
|
+
// ── 回合状态 ──
|
|
410
|
+
isProcessing: boolean;
|
|
411
|
+
turnCount: number;
|
|
412
|
+
maxTurns: number;
|
|
413
|
+
tokensUsed: number;
|
|
414
|
+
maxTokens: number;
|
|
415
|
+
cacheHitRate: number | null;
|
|
416
|
+
|
|
417
|
+
// ── 权限 ──
|
|
418
|
+
permissionRequest: PermissionRequest | null;
|
|
419
|
+
|
|
420
|
+
// ── Session 列表 ──
|
|
421
|
+
sessions: SessionInfo[];
|
|
422
|
+
|
|
423
|
+
// ── 能力注册表 ──
|
|
424
|
+
tools: ToolInfo[];
|
|
425
|
+
skills: SkillInfo[];
|
|
426
|
+
agents: AgentInfo[];
|
|
427
|
+
workflows: WorkflowInfo[];
|
|
428
|
+
|
|
429
|
+
// ── Actions ──
|
|
430
|
+
sendChat: (content: string, images?: ImageInput[]) => void;
|
|
431
|
+
sendStop: () => void;
|
|
432
|
+
respondPermission: (result: 'yes' | 'no' | 'always') => void;
|
|
433
|
+
loadSessions: () => Promise<void>;
|
|
434
|
+
switchSession: (id: string) => Promise<void>;
|
|
435
|
+
createSession: () => Promise<void>;
|
|
436
|
+
deleteSession: (id: string) => Promise<void>;
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### 5.4 WebSocket 事件 → Store 更新
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
// useWebSocket.ts — 核心 hook
|
|
444
|
+
function useWebSocket(url: string) {
|
|
445
|
+
const store = useStore();
|
|
446
|
+
|
|
447
|
+
useEffect(() => {
|
|
448
|
+
const ws = new WebSocket(url);
|
|
449
|
+
|
|
450
|
+
ws.onmessage = (event) => {
|
|
451
|
+
const msg = JSON.parse(event.data);
|
|
452
|
+
|
|
453
|
+
switch (msg.type) {
|
|
454
|
+
case 'connected':
|
|
455
|
+
store.setConnected(msg.sessionId, msg.config);
|
|
456
|
+
store.loadSessions();
|
|
457
|
+
break;
|
|
458
|
+
|
|
459
|
+
case 'text':
|
|
460
|
+
store.appendText(msg.content);
|
|
461
|
+
break;
|
|
462
|
+
|
|
463
|
+
case 'thinking':
|
|
464
|
+
store.appendThinking(msg.content);
|
|
465
|
+
break;
|
|
466
|
+
|
|
467
|
+
case 'tool_use':
|
|
468
|
+
store.addToolCall(msg.id, msg.name, msg.inputSummary);
|
|
469
|
+
break;
|
|
470
|
+
|
|
471
|
+
case 'tool_result':
|
|
472
|
+
store.completeToolCall(msg.id, msg.content, msg.isError);
|
|
473
|
+
break;
|
|
474
|
+
|
|
475
|
+
case 'diff':
|
|
476
|
+
store.showDiff(msg.id, msg.filePath, msg.diffLines);
|
|
477
|
+
break;
|
|
478
|
+
|
|
479
|
+
case 'status':
|
|
480
|
+
store.addStatusMessage(msg.message, msg.level);
|
|
481
|
+
break;
|
|
482
|
+
|
|
483
|
+
case 'turn_start':
|
|
484
|
+
store.startTurn();
|
|
485
|
+
break;
|
|
486
|
+
|
|
487
|
+
case 'flush':
|
|
488
|
+
store.flushCurrentMessage();
|
|
489
|
+
break;
|
|
490
|
+
|
|
491
|
+
case 'turn_info':
|
|
492
|
+
store.updateTurnInfo(msg);
|
|
493
|
+
break;
|
|
494
|
+
|
|
495
|
+
case 'permission':
|
|
496
|
+
store.showPermission(msg.toolName, msg.input);
|
|
497
|
+
break;
|
|
498
|
+
|
|
499
|
+
case 'error':
|
|
500
|
+
store.showError(msg.message);
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
return () => ws.close();
|
|
506
|
+
}, [url]);
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## 6. 数据流
|
|
513
|
+
|
|
514
|
+
### 6.1 完整对话流程
|
|
515
|
+
|
|
516
|
+
```
|
|
517
|
+
1. 用户打开浏览器 → http://localhost:3100
|
|
518
|
+
2. Fastify 返回 index.html → React SPA 加载
|
|
519
|
+
3. React 建立 WebSocket 连接 → ws://localhost:3100/ws
|
|
520
|
+
4. WebUIChannel 接受连接 → 创建 AgentLoop → 创建 WebUIOutputHandler
|
|
521
|
+
5. Server → Client: { type: "connected", sessionId, config }
|
|
522
|
+
6. Client 调用 GET /api/sessions, GET /api/tools, GET /api/skills 等初始化
|
|
523
|
+
7. ── 用户输入消息 ──
|
|
524
|
+
8. Client → Server: { type: "chat", content: "写一个 React 组件" }
|
|
525
|
+
9. Server → AgentLoop.run("写一个 React 组件")
|
|
526
|
+
10. AgentLoop 调用 LLM → 流式输出
|
|
527
|
+
11. OutputHandler 回调 → WebSocket 消息 → Client 渲染
|
|
528
|
+
12. 回合结束 → turn_info 更新 header/context bar
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
### 6.2 Session 切换
|
|
532
|
+
|
|
533
|
+
```
|
|
534
|
+
1. Client: POST /api/sessions/{id}/switch
|
|
535
|
+
2. Server: 保存旧 session → 创建新 AgentLoop → 切换
|
|
536
|
+
3. Server → Client: { type: "connected", sessionId: newId, config }
|
|
537
|
+
4. Client: 清空 ChatLog → GET /api/sessions/{id}/events 重放历史
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### 6.3 多标签页
|
|
541
|
+
|
|
542
|
+
每个标签页维护独立的 WebSocket 连接和 AgentLoop。服务端通过 `connections` Map 管理:
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
// 标签页 ID = sessionId(浏览器端生成或服务端分配)
|
|
546
|
+
// 关闭标签页 → ws.onclose → 清理 AgentLoop
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
551
|
+
## 7. 与其他渠道的关系
|
|
552
|
+
|
|
553
|
+
```
|
|
554
|
+
┌──────────┐
|
|
555
|
+
│ Feishu │ ← 企业微信消息
|
|
556
|
+
└────┬─────┘
|
|
557
|
+
│
|
|
558
|
+
┌──────────┐ ┌────┴─────┐ ┌──────────┐
|
|
559
|
+
│ TUI │───────│ Channel │───────│ WebUI │
|
|
560
|
+
│ (终端) │ │ Manager │ │ (浏览器) │
|
|
561
|
+
└──────────┘ └────┬─────┘ └──────────┘
|
|
562
|
+
│
|
|
563
|
+
┌────┴─────┐
|
|
564
|
+
│ HTTP │ ← REST API(第三方集成)
|
|
565
|
+
│ Webhook │
|
|
566
|
+
└──────────┘
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
**关键规则:**
|
|
570
|
+
- 每个渠道可以独立启用/禁用(`config.json` 中的 `channels.<id>.enabled`)
|
|
571
|
+
- 多个渠道可以同时运行(TUI + WebUI + 飞书)
|
|
572
|
+
- **每个渠道创建自己的 AgentLoop 实例**(不同的 session,互不干扰)
|
|
573
|
+
- 如果用户想让 WebUI 和 TUI 共享 session,需要实现 session 级别的消息同步(v2 考虑)
|
|
574
|
+
|
|
575
|
+
---
|
|
576
|
+
|
|
577
|
+
## 8. 与现有系统的集成点
|
|
578
|
+
|
|
579
|
+
### 8.1 需要修改的文件
|
|
580
|
+
|
|
581
|
+
| 文件 | 操作 | 说明 |
|
|
582
|
+
|------|------|------|
|
|
583
|
+
| `src/channels/builtin/webui-channel.ts` | **新建** | WebUIChannel 主体 |
|
|
584
|
+
| `src/channels/builtin/webui-ws-session.ts` | **新建** | WebSocket 会话管理 |
|
|
585
|
+
| `src/channels/builtin/webui-output-handler.ts` | **新建** | OutputHandler → WS 适配器 |
|
|
586
|
+
| `src/channels/index.ts` | 修改 | 导出 WebUIChannel |
|
|
587
|
+
| `src/gateway/server.ts` | 修改 | 注册 WebUIChannel,配置驱动启用 |
|
|
588
|
+
| `src/gateway/factory.ts` | 修改 | 导出更多组件供 REST API 使用(toolRegistry, skillRegistry, turnStore 等) |
|
|
589
|
+
| `webui/` | **新建目录** | 前端项目(React + Vite + Tailwind) |
|
|
590
|
+
|
|
591
|
+
### 8.2 依赖新增
|
|
592
|
+
|
|
593
|
+
```json
|
|
594
|
+
{
|
|
595
|
+
"dependencies": {
|
|
596
|
+
"ws": "^8.x", // WebSocket 服务端
|
|
597
|
+
"@fastify/websocket": "^x.x", // 或直接用 ws
|
|
598
|
+
"@fastify/static": "^x.x" // 静态文件服务
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
前端依赖独立管理(`webui/package.json`)。
|
|
604
|
+
|
|
605
|
+
### 8.3 配置扩展
|
|
606
|
+
|
|
607
|
+
```json
|
|
608
|
+
{
|
|
609
|
+
"channels": {
|
|
610
|
+
"webui": {
|
|
611
|
+
"enabled": true,
|
|
612
|
+
"port": 3100,
|
|
613
|
+
"host": "0.0.0.0",
|
|
614
|
+
"devMode": false,
|
|
615
|
+
"devServerUrl": "http://localhost:5173",
|
|
616
|
+
"auth": {
|
|
617
|
+
"enabled": false,
|
|
618
|
+
"password": ""
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
### 8.4 与 TurnRecorder 集成
|
|
626
|
+
|
|
627
|
+
WebUIChannel 的 AgentLoop 同样会被 TurnRecorder 追踪——回滚机制开箱即用,无需额外开发。
|
|
628
|
+
|
|
629
|
+
### 8.5 与 Workflow 集成
|
|
630
|
+
|
|
631
|
+
`WebUIOutputHandler.sendTurnInfo()` 包含 workflow 状态(active workflow name, step progress),前端在 Header 中展示工作流进度条。
|
|
632
|
+
|
|
633
|
+
---
|
|
634
|
+
|
|
635
|
+
## 9. 前端路由
|
|
636
|
+
|
|
637
|
+
```
|
|
638
|
+
/ → 主界面(需 WebSocket 连接)
|
|
639
|
+
/sessions → 会话管理
|
|
640
|
+
/settings → 配置面板
|
|
641
|
+
/workflows → 工作流列表 + 创建
|
|
642
|
+
/logs → 历史日志查看
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
前端使用 React Router(hash 模式,因为 Fastify 只 serve 一个 index.html)。
|
|
646
|
+
|
|
647
|
+
---
|
|
648
|
+
|
|
649
|
+
## 10. 安全考虑
|
|
650
|
+
|
|
651
|
+
| 层面 | 措施 |
|
|
652
|
+
|------|------|
|
|
653
|
+
| 传输 | 生产环境建议反代到 Nginx + TLS |
|
|
654
|
+
| 认证 | 可选密码认证(与 HTTP Webhook 的 Bearer Token 机制对齐) |
|
|
655
|
+
| CORS | 默认 `*`,可通过配置收紧 |
|
|
656
|
+
| 工具权限 | 通过 WebSocket 的 `permission` 流实现——与 TUI 完全相同的安全检查 |
|
|
657
|
+
| 路径隔离 | WebUI 只能访问 `cwd` 指定的项目目录 |
|
|
658
|
+
| 速率限制 | WebSocket 消息速率限制(防止刷屏) |
|
|
659
|
+
|
|
660
|
+
---
|
|
661
|
+
|
|
662
|
+
## 11. 实施阶段
|
|
663
|
+
|
|
664
|
+
### Phase 1:最小可用(1-2 周)
|
|
665
|
+
|
|
666
|
+
- [ ] 创建 `WebUIChannel` 骨架(start/stop/onEvent/handleMessage)
|
|
667
|
+
- [ ] 实现 `WebUIOutputHandler`(OutputHandler → JSON 序列化)
|
|
668
|
+
- [ ] 实现 WebSocket 服务端(`ws` 库,挂载到 Fastify)
|
|
669
|
+
- [ ] 实现基础 REST API(health, sessions CRUD, tools/skills list)
|
|
670
|
+
- [ ] 创建前端骨架(Vite + React + Tailwind + Zustand)
|
|
671
|
+
- [ ] 实现基础 ChatLog(user message + assistant text)
|
|
672
|
+
- [ ] 实现 InputArea(发送消息)
|
|
673
|
+
|
|
674
|
+
### Phase 2:流式体验(1 周)
|
|
675
|
+
|
|
676
|
+
- [ ] thinking 流式渲染 + 折叠
|
|
677
|
+
- [ ] 工具调用卡片(展开/折叠)
|
|
678
|
+
- [ ] Diff 展示
|
|
679
|
+
- [ ] Header(turn counter, context bar, provider badge)
|
|
680
|
+
- [ ] Permission 弹窗
|
|
681
|
+
- [ ] 停止按钮
|
|
682
|
+
|
|
683
|
+
### Phase 3:完整功能(1-2 周)
|
|
684
|
+
|
|
685
|
+
- [ ] Session 管理 UI(列表、切换、新建、删除)
|
|
686
|
+
- [ ] Slash 命令补全(复用 CommandRegistry)
|
|
687
|
+
- [ ] 配置面板
|
|
688
|
+
- [ ] 工作流面板
|
|
689
|
+
- [ ] 回滚操作 UI
|
|
690
|
+
- [ ] 知识库查询 UI
|
|
691
|
+
- [ ] 后台进程管理
|
|
692
|
+
- [ ] 移动端响应式
|
|
693
|
+
|
|
694
|
+
### Phase 4:进阶(后续)
|
|
695
|
+
|
|
696
|
+
- [ ] 多标签页 session 同步
|
|
697
|
+
- [ ] 会话历史搜索
|
|
698
|
+
- [ ] 暗色/亮色主题
|
|
699
|
+
- [ ] 国际化
|
|
700
|
+
- [ ] 快捷键系统(vim 模式?)
|
|
701
|
+
- [ ] 插件扩展 API
|
|
702
|
+
|
|
703
|
+
---
|
|
704
|
+
|
|
705
|
+
## 12. 与前端的通信效率
|
|
706
|
+
|
|
707
|
+
### 12.1 消息粒度
|
|
708
|
+
|
|
709
|
+
| OutputHandler 回调 | 频率 | WS 消息大小 |
|
|
710
|
+
|---------------------|------|-------------|
|
|
711
|
+
| onThinking | 极高(每 token) | ~50B |
|
|
712
|
+
| onText | 高(每 chunk) | ~200B |
|
|
713
|
+
| onToolUse | 低(每工具调用 1 次) | ~300B |
|
|
714
|
+
| onToolResult | 中(每工具调用 1 次) | 1KB-50KB |
|
|
715
|
+
| onDiff | 低 | 1-10KB |
|
|
716
|
+
| onStatus | 低 | ~200B |
|
|
717
|
+
| onTurnStart/Flush | 极低 | ~50B |
|
|
718
|
+
|
|
719
|
+
总带宽估计:一轮典型对话 ~100KB-500KB(主要来自 tool result)。
|
|
720
|
+
|
|
721
|
+
### 12.2 优化措施
|
|
722
|
+
|
|
723
|
+
- **虚拟滚动**:ChatLog 超过 1000 条消息时启用,只渲染可视区域
|
|
724
|
+
- **工具结果截断**:与 TUI 一致,大结果截断 + "Show more" 按钮
|
|
725
|
+
- **历史重放分页**:`GET /api/sessions/:id/events?offset=N&limit=50`
|
|
726
|
+
- **WebSocket 消息合并**:高频的 onThinking/onText 可在服务端合并(每 16ms flush 一次)
|
|
727
|
+
|
|
728
|
+
---
|
|
729
|
+
|
|
730
|
+
## 13. 关键设计决策记录
|
|
731
|
+
|
|
732
|
+
| 决策 | 选择 | 原因 |
|
|
733
|
+
|------|------|------|
|
|
734
|
+
| WebSocket vs SSE | WebSocket | 需要双向通信(chat + stop + permission) |
|
|
735
|
+
| Fastify vs Express | Fastify | 与 HTTP Webhook 统一技术栈 |
|
|
736
|
+
| React vs Vue | React | 生态更大,流式 UI 模式更成熟 |
|
|
737
|
+
| 每个标签页独立 AgentLoop vs 共享 | 独立 | 与 TUI 模型一致,避免状态竞争 |
|
|
738
|
+
| 前端构建产物位置 | `.agent/webui/dist/` | 不污染项目目录 |
|
|
739
|
+
| 配置文件方式 vs 命令行参数 | 配置文件 | 与现有渠道配置体系一致 |
|
|
740
|
+
|
|
741
|
+
---
|
|
742
|
+
|
|
743
|
+
## 附录 A:与 TUI 的功能对等表
|
|
744
|
+
|
|
745
|
+
| 功能 | TUI | WebUI |
|
|
746
|
+
|------|-----|-------|
|
|
747
|
+
| 流式文本输出 | ✅ blessed Text | ✅ WebSocket text |
|
|
748
|
+
| Thinking 显示 | ✅ 可折叠 | ✅ 可折叠 |
|
|
749
|
+
| 工具调用展示 | ✅ 行内卡片 | ✅ 可展开卡片 |
|
|
750
|
+
| Diff 展示 | ✅ unified diff | ✅ side-by-side + unified |
|
|
751
|
+
| 权限确认 | ✅ 终端内联选择 | ✅ Modal 弹窗 |
|
|
752
|
+
| Session 管理 | ✅ /session 命令 | ✅ REST API + Sidebar |
|
|
753
|
+
| Provider 切换 | ✅ /model provider | ✅ 下拉菜单 + API |
|
|
754
|
+
| 上下文用量 | ✅ ContextBar | ✅ ContextBar (同) |
|
|
755
|
+
| 工作流进度 | ✅ Header | ✅ Header + 面板 |
|
|
756
|
+
| 回滚 | ✅ /rollback 命令 | ✅ REST API + UI 按钮 |
|
|
757
|
+
| 命令补全 | ✅ SlashSubPanel | ✅ 下拉菜单 |
|
|
758
|
+
| 图片粘贴 | ✅ 终端不支持 | ✅ 剪贴板粘贴 + 拖拽 |
|
|
759
|
+
| 多行输入 | ✅ | ✅ |
|
|
760
|
+
| 历史重放 | ✅ 启动时 | ✅ Session 切换时 |
|
|
761
|
+
|
|
762
|
+
## 附录 B:消息类型 TypeScript 定义
|
|
763
|
+
|
|
764
|
+
```typescript
|
|
765
|
+
// 共享类型定义(可放在 src/channels/builtin/webui-types.ts)
|
|
766
|
+
|
|
767
|
+
// Client → Server
|
|
768
|
+
export type WebUIClientMessage =
|
|
769
|
+
| { type: 'chat'; content: string; images?: Array<{ data: string; media_type: string }> }
|
|
770
|
+
| { type: 'stop' }
|
|
771
|
+
| { type: 'permission'; result: 'yes' | 'no' | 'always' }
|
|
772
|
+
| { type: 'set_mode'; mode: 'normal' | 'precise' };
|
|
773
|
+
|
|
774
|
+
// Server → Client
|
|
775
|
+
export type WebUIServerMessage =
|
|
776
|
+
| { type: 'text'; content: string }
|
|
777
|
+
| { type: 'thinking'; content: string }
|
|
778
|
+
| { type: 'tool_use'; id: string; name: string; inputSummary: string }
|
|
779
|
+
| { type: 'tool_result'; id: string; content: string; isError: boolean }
|
|
780
|
+
| { type: 'diff'; id: string; filePath: string; diffLines: Array<{ kind: string; text: string }> }
|
|
781
|
+
| { type: 'status'; message: string; level: 'info' | 'warn' | 'error' }
|
|
782
|
+
| { type: 'turn_start' }
|
|
783
|
+
| { type: 'flush' }
|
|
784
|
+
| { type: 'interrupt' }
|
|
785
|
+
| { type: 'turn_info'; turnCount: number; maxTurns: number; tokensUsed: number; /* ... more */ }
|
|
786
|
+
| { type: 'permission'; toolName: string; input: Record<string, unknown> }
|
|
787
|
+
| { type: 'error'; message: string }
|
|
788
|
+
| { type: 'connected'; sessionId: string; config: SessionConfig };
|
|
789
|
+
```
|