@cicctencent/agent-core 0.1.1 → 0.1.3
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/dist/cjs/agent/engine.d.ts.map +1 -0
- package/dist/cjs/agent/engine.js +766 -0
- package/dist/cjs/agent/engine.js.map +1 -0
- package/dist/cjs/agent/history-manager.d.ts.map +1 -0
- package/dist/cjs/agent/history-manager.js +271 -0
- package/dist/cjs/agent/history-manager.js.map +1 -0
- package/dist/cjs/agent/llm-caller.d.ts.map +1 -0
- package/dist/cjs/agent/llm-caller.js +307 -0
- package/dist/cjs/agent/llm-caller.js.map +1 -0
- package/dist/cjs/agent/tool-executor.d.ts.map +1 -0
- package/dist/cjs/agent/tool-executor.js +568 -0
- package/dist/cjs/agent/tool-executor.js.map +1 -0
- package/dist/cjs/agent/types.d.ts.map +1 -0
- package/dist/cjs/agent/types.js +6 -0
- package/dist/cjs/agent/types.js.map +1 -0
- package/dist/cjs/agent/workflow.d.ts.map +1 -0
- package/dist/cjs/agent/workflow.js +262 -0
- package/dist/cjs/agent/workflow.js.map +1 -0
- package/dist/cjs/context/collector.d.ts.map +1 -0
- package/dist/cjs/context/collector.js +94 -0
- package/dist/cjs/context/collector.js.map +1 -0
- package/dist/cjs/context/manager.d.ts.map +1 -0
- package/dist/cjs/context/manager.js +36 -0
- package/dist/cjs/context/manager.js.map +1 -0
- package/dist/cjs/context/types.d.ts.map +1 -0
- package/dist/cjs/context/types.js +6 -0
- package/dist/cjs/context/types.js.map +1 -0
- package/dist/cjs/hooks/types.d.ts.map +1 -0
- package/dist/cjs/hooks/types.js +6 -0
- package/dist/cjs/hooks/types.js.map +1 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +98 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/llm/anthropic-provider.d.ts.map +1 -0
- package/dist/cjs/llm/anthropic-provider.js +356 -0
- package/dist/cjs/llm/anthropic-provider.js.map +1 -0
- package/dist/cjs/llm/factory.d.ts.map +1 -0
- package/dist/cjs/llm/factory.js +34 -0
- package/dist/cjs/llm/factory.js.map +1 -0
- package/dist/cjs/llm/ollama-provider.d.ts.map +1 -0
- package/dist/cjs/llm/ollama-provider.js +34 -0
- package/dist/cjs/llm/ollama-provider.js.map +1 -0
- package/dist/cjs/llm/openai-provider.d.ts.map +1 -0
- package/dist/cjs/llm/openai-provider.js +186 -0
- package/dist/cjs/llm/openai-provider.js.map +1 -0
- package/dist/cjs/llm/provider.d.ts.map +1 -0
- package/dist/cjs/llm/provider.js +18 -0
- package/dist/cjs/llm/provider.js.map +1 -0
- package/dist/cjs/llm/types.d.ts.map +1 -0
- package/dist/cjs/llm/types.js +6 -0
- package/dist/cjs/llm/types.js.map +1 -0
- package/dist/cjs/mcp/base-client.d.ts.map +1 -0
- package/dist/cjs/mcp/base-client.js +112 -0
- package/dist/cjs/mcp/base-client.js.map +1 -0
- package/dist/cjs/mcp/client.d.ts.map +1 -0
- package/dist/cjs/mcp/client.js +76 -0
- package/dist/cjs/mcp/client.js.map +1 -0
- package/dist/cjs/mcp/factory.d.ts.map +1 -0
- package/dist/cjs/mcp/factory.js +43 -0
- package/dist/cjs/mcp/factory.js.map +1 -0
- package/dist/cjs/mcp/http-client.d.ts.map +1 -0
- package/dist/cjs/mcp/http-client.js +142 -0
- package/dist/cjs/mcp/http-client.js.map +1 -0
- package/dist/cjs/mcp/proxy-agent.d.ts.map +1 -0
- package/dist/cjs/mcp/proxy-agent.js +195 -0
- package/dist/cjs/mcp/proxy-agent.js.map +1 -0
- package/dist/cjs/mcp/stdio-client.d.ts.map +1 -0
- package/dist/cjs/mcp/stdio-client.js +95 -0
- package/dist/cjs/mcp/stdio-client.js.map +1 -0
- package/dist/cjs/mcp/types.d.ts.map +1 -0
- package/dist/cjs/mcp/types.js +6 -0
- package/dist/cjs/mcp/types.js.map +1 -0
- package/dist/cjs/memory/checkpoint.d.ts.map +1 -0
- package/dist/cjs/memory/checkpoint.js +160 -0
- package/dist/cjs/memory/checkpoint.js.map +1 -0
- package/dist/cjs/memory/extractor.d.ts.map +1 -0
- package/dist/cjs/memory/extractor.js +121 -0
- package/dist/cjs/memory/extractor.js.map +1 -0
- package/dist/cjs/memory/persona.d.ts.map +1 -0
- package/dist/cjs/memory/persona.js +79 -0
- package/dist/cjs/memory/persona.js.map +1 -0
- package/dist/cjs/memory/pipeline.d.ts.map +1 -0
- package/dist/cjs/memory/pipeline.js +148 -0
- package/dist/cjs/memory/pipeline.js.map +1 -0
- package/dist/cjs/memory/prompts.d.ts.map +1 -0
- package/dist/cjs/memory/prompts.js +70 -0
- package/dist/cjs/memory/prompts.js.map +1 -0
- package/dist/cjs/memory/recall.d.ts.map +1 -0
- package/dist/cjs/memory/recall.js +164 -0
- package/dist/cjs/memory/recall.js.map +1 -0
- package/dist/cjs/memory/scene.d.ts.map +1 -0
- package/dist/cjs/memory/scene.js +101 -0
- package/dist/cjs/memory/scene.js.map +1 -0
- package/dist/cjs/memory/types.d.ts.map +1 -0
- package/dist/cjs/memory/types.js +6 -0
- package/dist/cjs/memory/types.js.map +1 -0
- package/dist/cjs/middleware/types.d.ts.map +1 -0
- package/dist/cjs/middleware/types.js +6 -0
- package/dist/cjs/middleware/types.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/sandbox/types.d.ts.map +1 -0
- package/dist/cjs/sandbox/types.js +128 -0
- package/dist/cjs/sandbox/types.js.map +1 -0
- package/dist/cjs/security/guard.d.ts.map +1 -0
- package/dist/cjs/security/guard.js +229 -0
- package/dist/cjs/security/guard.js.map +1 -0
- package/dist/cjs/security/types.d.ts.map +1 -0
- package/dist/cjs/security/types.js +6 -0
- package/dist/cjs/security/types.js.map +1 -0
- package/dist/cjs/skill/manager.d.ts.map +1 -0
- package/dist/cjs/skill/manager.js +413 -0
- package/dist/cjs/skill/manager.js.map +1 -0
- package/dist/cjs/skill/router.d.ts.map +1 -0
- package/dist/cjs/skill/router.js +139 -0
- package/dist/cjs/skill/router.js.map +1 -0
- package/dist/cjs/skill/types.d.ts.map +1 -0
- package/dist/cjs/skill/types.js +6 -0
- package/dist/cjs/skill/types.js.map +1 -0
- package/dist/cjs/tool/delegate.d.ts.map +1 -0
- package/dist/cjs/tool/delegate.js +78 -0
- package/dist/cjs/tool/delegate.js.map +1 -0
- package/dist/cjs/tool/registry.d.ts.map +1 -0
- package/dist/cjs/tool/registry.js +57 -0
- package/dist/cjs/tool/registry.js.map +1 -0
- package/dist/cjs/tool/types.d.ts.map +1 -0
- package/dist/cjs/tool/types.js +6 -0
- package/dist/cjs/tool/types.js.map +1 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/token-counter.d.ts.map +1 -0
- package/dist/cjs/utils/token-counter.js +104 -0
- package/dist/cjs/utils/token-counter.js.map +1 -0
- package/dist/esm/agent/engine.d.ts +113 -0
- package/dist/esm/agent/engine.d.ts.map +1 -0
- package/dist/esm/agent/engine.js +762 -0
- package/dist/esm/agent/engine.js.map +1 -0
- package/dist/esm/agent/history-manager.d.ts +78 -0
- package/dist/esm/agent/history-manager.d.ts.map +1 -0
- package/dist/esm/agent/history-manager.js +267 -0
- package/dist/esm/agent/history-manager.js.map +1 -0
- package/dist/esm/agent/llm-caller.d.ts +58 -0
- package/dist/esm/agent/llm-caller.d.ts.map +1 -0
- package/dist/esm/agent/llm-caller.js +303 -0
- package/dist/esm/agent/llm-caller.js.map +1 -0
- package/dist/esm/agent/tool-executor.d.ts +95 -0
- package/dist/esm/agent/tool-executor.d.ts.map +1 -0
- package/dist/esm/agent/tool-executor.js +564 -0
- package/dist/esm/agent/tool-executor.js.map +1 -0
- package/dist/esm/agent/types.d.ts +128 -0
- package/dist/esm/agent/types.d.ts.map +1 -0
- package/dist/esm/agent/types.js +5 -0
- package/dist/esm/agent/types.js.map +1 -0
- package/dist/esm/agent/workflow.d.ts +74 -0
- package/dist/esm/agent/workflow.d.ts.map +1 -0
- package/dist/esm/agent/workflow.js +248 -0
- package/dist/esm/agent/workflow.js.map +1 -0
- package/dist/esm/context/collector.d.ts +12 -0
- package/dist/esm/context/collector.d.ts.map +1 -0
- package/dist/esm/context/collector.js +57 -0
- package/dist/esm/context/collector.js.map +1 -0
- package/dist/esm/context/manager.d.ts +16 -0
- package/dist/esm/context/manager.d.ts.map +1 -0
- package/dist/esm/context/manager.js +32 -0
- package/dist/esm/context/manager.js.map +1 -0
- package/dist/esm/context/types.d.ts +39 -0
- package/dist/esm/context/types.d.ts.map +1 -0
- package/dist/esm/context/types.js +5 -0
- package/dist/esm/context/types.js.map +1 -0
- package/dist/esm/hooks/types.d.ts +47 -0
- package/dist/esm/hooks/types.d.ts.map +1 -0
- package/dist/esm/hooks/types.js +5 -0
- package/dist/esm/hooks/types.js.map +1 -0
- package/{src/index.ts → dist/esm/index.d.ts} +15 -140
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +39 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/llm/anthropic-provider.d.ts +28 -0
- package/dist/esm/llm/anthropic-provider.d.ts.map +1 -0
- package/dist/esm/llm/anthropic-provider.js +352 -0
- package/dist/esm/llm/anthropic-provider.js.map +1 -0
- package/{src/llm/factory.ts → dist/esm/llm/factory.d.ts} +3 -18
- package/dist/esm/llm/factory.d.ts.map +1 -0
- package/dist/esm/llm/factory.js +30 -0
- package/dist/esm/llm/factory.js.map +1 -0
- package/dist/esm/llm/ollama-provider.d.ts +13 -0
- package/dist/esm/llm/ollama-provider.d.ts.map +1 -0
- package/dist/esm/llm/ollama-provider.js +30 -0
- package/dist/esm/llm/ollama-provider.js.map +1 -0
- package/dist/esm/llm/openai-provider.d.ts +18 -0
- package/dist/esm/llm/openai-provider.d.ts.map +1 -0
- package/dist/esm/llm/openai-provider.js +182 -0
- package/dist/esm/llm/openai-provider.js.map +1 -0
- package/{src/llm/provider.ts → dist/esm/llm/provider.d.ts} +1 -9
- package/dist/esm/llm/provider.d.ts.map +1 -0
- package/dist/esm/llm/provider.js +10 -0
- package/dist/esm/llm/provider.js.map +1 -0
- package/dist/esm/llm/types.d.ts +78 -0
- package/dist/esm/llm/types.d.ts.map +1 -0
- package/dist/esm/llm/types.js +5 -0
- package/dist/esm/llm/types.js.map +1 -0
- package/dist/esm/mcp/base-client.d.ts +50 -0
- package/dist/esm/mcp/base-client.d.ts.map +1 -0
- package/dist/esm/mcp/base-client.js +108 -0
- package/dist/esm/mcp/base-client.js.map +1 -0
- package/dist/esm/mcp/client.d.ts +27 -0
- package/dist/esm/mcp/client.d.ts.map +1 -0
- package/dist/esm/mcp/client.js +70 -0
- package/dist/esm/mcp/client.js.map +1 -0
- package/dist/esm/mcp/factory.d.ts +16 -0
- package/dist/esm/mcp/factory.d.ts.map +1 -0
- package/dist/esm/mcp/factory.js +39 -0
- package/dist/esm/mcp/factory.js.map +1 -0
- package/dist/esm/mcp/http-client.d.ts +24 -0
- package/dist/esm/mcp/http-client.d.ts.map +1 -0
- package/dist/esm/mcp/http-client.js +138 -0
- package/dist/esm/mcp/http-client.js.map +1 -0
- package/dist/esm/mcp/proxy-agent.d.ts +49 -0
- package/dist/esm/mcp/proxy-agent.d.ts.map +1 -0
- package/dist/esm/mcp/proxy-agent.js +187 -0
- package/dist/esm/mcp/proxy-agent.js.map +1 -0
- package/dist/esm/mcp/stdio-client.d.ts +16 -0
- package/dist/esm/mcp/stdio-client.d.ts.map +1 -0
- package/dist/esm/mcp/stdio-client.js +91 -0
- package/dist/esm/mcp/stdio-client.js.map +1 -0
- package/dist/esm/mcp/types.d.ts +60 -0
- package/dist/esm/mcp/types.d.ts.map +1 -0
- package/dist/esm/mcp/types.js +5 -0
- package/dist/esm/mcp/types.js.map +1 -0
- package/dist/esm/memory/checkpoint.d.ts +62 -0
- package/dist/esm/memory/checkpoint.d.ts.map +1 -0
- package/dist/esm/memory/checkpoint.js +121 -0
- package/dist/esm/memory/checkpoint.js.map +1 -0
- package/dist/esm/memory/extractor.d.ts +59 -0
- package/dist/esm/memory/extractor.d.ts.map +1 -0
- package/dist/esm/memory/extractor.js +117 -0
- package/dist/esm/memory/extractor.js.map +1 -0
- package/dist/esm/memory/persona.d.ts +38 -0
- package/dist/esm/memory/persona.d.ts.map +1 -0
- package/dist/esm/memory/persona.js +75 -0
- package/dist/esm/memory/persona.js.map +1 -0
- package/dist/esm/memory/pipeline.d.ts +50 -0
- package/dist/esm/memory/pipeline.d.ts.map +1 -0
- package/dist/esm/memory/pipeline.js +144 -0
- package/dist/esm/memory/pipeline.js.map +1 -0
- package/dist/esm/memory/prompts.d.ts +9 -0
- package/dist/esm/memory/prompts.d.ts.map +1 -0
- package/{src/memory/prompts.ts → dist/esm/memory/prompts.js} +6 -13
- package/dist/esm/memory/prompts.js.map +1 -0
- package/dist/esm/memory/recall.d.ts +66 -0
- package/dist/esm/memory/recall.d.ts.map +1 -0
- package/dist/esm/memory/recall.js +159 -0
- package/dist/esm/memory/recall.js.map +1 -0
- package/dist/esm/memory/scene.d.ts +49 -0
- package/dist/esm/memory/scene.d.ts.map +1 -0
- package/dist/esm/memory/scene.js +97 -0
- package/dist/esm/memory/scene.js.map +1 -0
- package/dist/esm/memory/types.d.ts +43 -0
- package/dist/esm/memory/types.d.ts.map +1 -0
- package/dist/esm/memory/types.js +5 -0
- package/dist/esm/memory/types.js.map +1 -0
- package/dist/esm/middleware/types.d.ts +52 -0
- package/dist/esm/middleware/types.d.ts.map +1 -0
- package/dist/esm/middleware/types.js +5 -0
- package/dist/esm/middleware/types.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/sandbox/types.d.ts +59 -0
- package/dist/esm/sandbox/types.d.ts.map +1 -0
- package/dist/esm/sandbox/types.js +125 -0
- package/dist/esm/sandbox/types.js.map +1 -0
- package/dist/esm/security/guard.d.ts +41 -0
- package/dist/esm/security/guard.d.ts.map +1 -0
- package/dist/esm/security/guard.js +225 -0
- package/dist/esm/security/guard.js.map +1 -0
- package/dist/esm/security/types.d.ts +36 -0
- package/dist/esm/security/types.d.ts.map +1 -0
- package/dist/esm/security/types.js +5 -0
- package/dist/esm/security/types.js.map +1 -0
- package/dist/esm/skill/manager.d.ts +95 -0
- package/dist/esm/skill/manager.d.ts.map +1 -0
- package/dist/esm/skill/manager.js +376 -0
- package/dist/esm/skill/manager.js.map +1 -0
- package/dist/esm/skill/router.d.ts +26 -0
- package/dist/esm/skill/router.d.ts.map +1 -0
- package/dist/esm/skill/router.js +135 -0
- package/dist/esm/skill/router.js.map +1 -0
- package/dist/esm/skill/types.d.ts +55 -0
- package/dist/esm/skill/types.d.ts.map +1 -0
- package/dist/esm/skill/types.js +5 -0
- package/dist/esm/skill/types.js.map +1 -0
- package/dist/esm/tool/delegate.d.ts +34 -0
- package/dist/esm/tool/delegate.d.ts.map +1 -0
- package/dist/esm/tool/delegate.js +75 -0
- package/dist/esm/tool/delegate.js.map +1 -0
- package/dist/esm/tool/registry.d.ts +24 -0
- package/dist/esm/tool/registry.d.ts.map +1 -0
- package/dist/esm/tool/registry.js +53 -0
- package/dist/esm/tool/registry.js.map +1 -0
- package/dist/esm/tool/types.d.ts +101 -0
- package/dist/esm/tool/types.d.ts.map +1 -0
- package/dist/esm/tool/types.js +5 -0
- package/dist/esm/tool/types.js.map +1 -0
- package/dist/esm/types.d.ts +150 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/token-counter.d.ts +22 -0
- package/dist/esm/utils/token-counter.d.ts.map +1 -0
- package/dist/esm/utils/token-counter.js +99 -0
- package/dist/esm/utils/token-counter.js.map +1 -0
- package/package.json +16 -10
- package/dist/agent/engine.d.ts.map +0 -1
- package/dist/agent/history-manager.d.ts.map +0 -1
- package/dist/agent/llm-caller.d.ts.map +0 -1
- package/dist/agent/tool-executor.d.ts.map +0 -1
- package/dist/agent/types.d.ts.map +0 -1
- package/dist/agent/workflow.d.ts.map +0 -1
- package/dist/context/collector.d.ts.map +0 -1
- package/dist/context/manager.d.ts.map +0 -1
- package/dist/context/types.d.ts.map +0 -1
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/llm/anthropic-provider.d.ts.map +0 -1
- package/dist/llm/factory.d.ts.map +0 -1
- package/dist/llm/ollama-provider.d.ts.map +0 -1
- package/dist/llm/openai-provider.d.ts.map +0 -1
- package/dist/llm/provider.d.ts.map +0 -1
- package/dist/llm/types.d.ts.map +0 -1
- package/dist/mcp/base-client.d.ts.map +0 -1
- package/dist/mcp/client.d.ts.map +0 -1
- package/dist/mcp/factory.d.ts.map +0 -1
- package/dist/mcp/http-client.d.ts.map +0 -1
- package/dist/mcp/proxy-agent.d.ts.map +0 -1
- package/dist/mcp/stdio-client.d.ts.map +0 -1
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/memory/checkpoint.d.ts.map +0 -1
- package/dist/memory/extractor.d.ts.map +0 -1
- package/dist/memory/persona.d.ts.map +0 -1
- package/dist/memory/pipeline.d.ts.map +0 -1
- package/dist/memory/prompts.d.ts.map +0 -1
- package/dist/memory/recall.d.ts.map +0 -1
- package/dist/memory/scene.d.ts.map +0 -1
- package/dist/memory/types.d.ts.map +0 -1
- package/dist/middleware/types.d.ts.map +0 -1
- package/dist/sandbox/types.d.ts.map +0 -1
- package/dist/security/guard.d.ts.map +0 -1
- package/dist/security/types.d.ts.map +0 -1
- package/dist/skill/manager.d.ts.map +0 -1
- package/dist/skill/router.d.ts.map +0 -1
- package/dist/skill/types.d.ts.map +0 -1
- package/dist/tool/delegate.d.ts.map +0 -1
- package/dist/tool/registry.d.ts.map +0 -1
- package/dist/tool/types.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/token-counter.d.ts.map +0 -1
- package/src/agent/engine.ts +0 -875
- package/src/agent/history-manager.ts +0 -323
- package/src/agent/llm-caller.ts +0 -383
- package/src/agent/tool-executor.ts +0 -713
- package/src/agent/types.ts +0 -136
- package/src/agent/workflow.ts +0 -339
- package/src/context/collector.ts +0 -59
- package/src/context/manager.ts +0 -40
- package/src/context/types.ts +0 -51
- package/src/hooks/types.ts +0 -77
- package/src/llm/anthropic-provider.ts +0 -412
- package/src/llm/ollama-provider.ts +0 -39
- package/src/llm/openai-provider.ts +0 -200
- package/src/llm/types.ts +0 -91
- package/src/mcp/base-client.ts +0 -159
- package/src/mcp/client.ts +0 -81
- package/src/mcp/factory.ts +0 -45
- package/src/mcp/http-client.ts +0 -149
- package/src/mcp/proxy-agent.ts +0 -227
- package/src/mcp/stdio-client.ts +0 -104
- package/src/mcp/types.ts +0 -65
- package/src/memory/checkpoint.ts +0 -146
- package/src/memory/extractor.ts +0 -164
- package/src/memory/persona.ts +0 -106
- package/src/memory/pipeline.ts +0 -192
- package/src/memory/recall.ts +0 -217
- package/src/memory/scene.ts +0 -137
- package/src/memory/types.ts +0 -54
- package/src/middleware/types.ts +0 -62
- package/src/sandbox/types.ts +0 -185
- package/src/security/guard.ts +0 -249
- package/src/security/types.ts +0 -46
- package/src/skill/manager.ts +0 -420
- package/src/skill/router.ts +0 -158
- package/src/skill/types.ts +0 -67
- package/src/tool/delegate.ts +0 -105
- package/src/tool/registry.ts +0 -64
- package/src/tool/types.ts +0 -124
- package/src/types.ts +0 -188
- package/src/utils/token-counter.ts +0 -108
- /package/dist/{agent → cjs/agent}/engine.d.ts +0 -0
- /package/dist/{agent → cjs/agent}/history-manager.d.ts +0 -0
- /package/dist/{agent → cjs/agent}/llm-caller.d.ts +0 -0
- /package/dist/{agent → cjs/agent}/tool-executor.d.ts +0 -0
- /package/dist/{agent → cjs/agent}/types.d.ts +0 -0
- /package/dist/{agent → cjs/agent}/workflow.d.ts +0 -0
- /package/dist/{context → cjs/context}/collector.d.ts +0 -0
- /package/dist/{context → cjs/context}/manager.d.ts +0 -0
- /package/dist/{context → cjs/context}/types.d.ts +0 -0
- /package/dist/{hooks → cjs/hooks}/types.d.ts +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{llm → cjs/llm}/anthropic-provider.d.ts +0 -0
- /package/dist/{llm → cjs/llm}/factory.d.ts +0 -0
- /package/dist/{llm → cjs/llm}/ollama-provider.d.ts +0 -0
- /package/dist/{llm → cjs/llm}/openai-provider.d.ts +0 -0
- /package/dist/{llm → cjs/llm}/provider.d.ts +0 -0
- /package/dist/{llm → cjs/llm}/types.d.ts +0 -0
- /package/dist/{mcp → cjs/mcp}/base-client.d.ts +0 -0
- /package/dist/{mcp → cjs/mcp}/client.d.ts +0 -0
- /package/dist/{mcp → cjs/mcp}/factory.d.ts +0 -0
- /package/dist/{mcp → cjs/mcp}/http-client.d.ts +0 -0
- /package/dist/{mcp → cjs/mcp}/proxy-agent.d.ts +0 -0
- /package/dist/{mcp → cjs/mcp}/stdio-client.d.ts +0 -0
- /package/dist/{mcp → cjs/mcp}/types.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/checkpoint.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/extractor.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/persona.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/pipeline.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/prompts.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/recall.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/scene.d.ts +0 -0
- /package/dist/{memory → cjs/memory}/types.d.ts +0 -0
- /package/dist/{middleware → cjs/middleware}/types.d.ts +0 -0
- /package/dist/{sandbox → cjs/sandbox}/types.d.ts +0 -0
- /package/dist/{security → cjs/security}/guard.d.ts +0 -0
- /package/dist/{security → cjs/security}/types.d.ts +0 -0
- /package/dist/{skill → cjs/skill}/manager.d.ts +0 -0
- /package/dist/{skill → cjs/skill}/router.d.ts +0 -0
- /package/dist/{skill → cjs/skill}/types.d.ts +0 -0
- /package/dist/{tool → cjs/tool}/delegate.d.ts +0 -0
- /package/dist/{tool → cjs/tool}/registry.d.ts +0 -0
- /package/dist/{tool → cjs/tool}/types.d.ts +0 -0
- /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/dist/{utils → cjs/utils}/token-counter.d.ts +0 -0
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// AgentEngine — Agent Loop 执行引擎(编排层)
|
|
4
|
+
// ============================================================
|
|
5
|
+
// 职责:编排 HistoryManager、LLMCaller、ToolExecutor 完成 ReAct 循环
|
|
6
|
+
// 历史管理、LLM 调用、工具执行已分别抽离到独立模块
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AgentEngine = void 0;
|
|
9
|
+
const history_manager_ts_1 = require("./history-manager.js");
|
|
10
|
+
const llm_caller_ts_1 = require("./llm-caller.js");
|
|
11
|
+
const tool_executor_ts_1 = require("./tool-executor.js");
|
|
12
|
+
/** 默认系统提示词 */
|
|
13
|
+
const DEFAULT_BASE_PROMPT = `You are a helpful AI assistant with access to tools. Use tools when needed to accomplish tasks. Always explain your actions clearly.`;
|
|
14
|
+
/** 进度叙述规则(追加到 system prompt,引导 LLM 在工具调用间输出可见文本) */
|
|
15
|
+
const PROGRESS_NARRATION_RULES = `
|
|
16
|
+
|
|
17
|
+
## Progress Narration Rules
|
|
18
|
+
|
|
19
|
+
When using tools, you MUST provide brief visible narration for the user:
|
|
20
|
+
- **Before** each tool call: write ONE short sentence (in the user's language) describing what you are about to do. Example: "Let me query the latest sales data..."
|
|
21
|
+
- **After** each tool result: write ONE short sentence summarizing the key finding or outcome. Example: "Found 3 quarters of data, revenue grew 15% YoY."
|
|
22
|
+
- Keep narration **brief and informative** — no filler words.
|
|
23
|
+
- For multi-step tasks, use a numbered list or checklist at the start.
|
|
24
|
+
- When the task is complete, always end with a clear summary of what was accomplished.
|
|
25
|
+
- DO NOT output tool calls without accompanying text narration.
|
|
26
|
+
`;
|
|
27
|
+
/**
|
|
28
|
+
* 构建 Skill 目录(当 SkillRouter 未命中时注入到 system prompt)
|
|
29
|
+
* 让 Agent 通过 load_skill 工具按需加载 skill 全量内容
|
|
30
|
+
*
|
|
31
|
+
* 权限隔离:skillManager 是当前 Agent 专属实例(在 agent.service.ts 中构建),
|
|
32
|
+
* 仅包含该 Agent 有权访问的 Skill,确保不会泄露其他 Agent 的私有 Skill。
|
|
33
|
+
*/
|
|
34
|
+
function buildSkillCatalog(skillManager) {
|
|
35
|
+
const manifests = skillManager.getAllManifests();
|
|
36
|
+
if (manifests.length === 0)
|
|
37
|
+
return null;
|
|
38
|
+
const lines = manifests.map(m => `- \`${m.id}\`: ${m.name} — ${m.description || '(no description)'}`);
|
|
39
|
+
return `## Available Skills\n\nYou have access to the following skills. Use \`load_skill(skill_id="<id>")\` to load full instructions when a task matches a skill's purpose.\n\n${lines.join('\n')}`;
|
|
40
|
+
}
|
|
41
|
+
class AgentEngine {
|
|
42
|
+
config;
|
|
43
|
+
/** sessionId → AgentStatus */
|
|
44
|
+
statusMap = new Map();
|
|
45
|
+
/** sessionId → AbortController (internal) */
|
|
46
|
+
abortMap = new Map();
|
|
47
|
+
/** sessionId → steering messages(实时转向队列) */
|
|
48
|
+
steeringMap = new Map();
|
|
49
|
+
/** 子模块:历史管理器 */
|
|
50
|
+
historyManager;
|
|
51
|
+
/** 子模块:LLM 调用器 */
|
|
52
|
+
llmCaller;
|
|
53
|
+
/** 子模块:工具执行器 */
|
|
54
|
+
toolExecutor;
|
|
55
|
+
/** 数据获取类工具集合(用于循环检测) */
|
|
56
|
+
dataFetchTools;
|
|
57
|
+
/** 产出型工具集合(有这些调用时不触发数据获取循环检测) */
|
|
58
|
+
outputTools;
|
|
59
|
+
constructor(config) {
|
|
60
|
+
this.config = {
|
|
61
|
+
...config,
|
|
62
|
+
maxIterations: config.maxIterations ?? 15,
|
|
63
|
+
maxMessages: config.maxMessages ?? 50,
|
|
64
|
+
toolTimeout: config.toolTimeout ?? 30000,
|
|
65
|
+
llmTimeout: config.llmTimeout ?? 120000,
|
|
66
|
+
basePrompt: config.basePrompt ?? DEFAULT_BASE_PROMPT,
|
|
67
|
+
};
|
|
68
|
+
// 初始化子模块
|
|
69
|
+
this.historyManager = new history_manager_ts_1.HistoryManager({
|
|
70
|
+
maxMessages: this.config.maxMessages,
|
|
71
|
+
contextBudget: this.config.contextBudget,
|
|
72
|
+
toolResultStore: this.config.toolResultStore,
|
|
73
|
+
});
|
|
74
|
+
this.llmCaller = new llm_caller_ts_1.LLMCaller({
|
|
75
|
+
llmProvider: this.config.llmProvider,
|
|
76
|
+
fallbackProvider: this.config.fallbackProvider,
|
|
77
|
+
retryPolicy: this.config.retryPolicy,
|
|
78
|
+
llmTimeout: this.config.llmTimeout,
|
|
79
|
+
runHooks: this.runHooks.bind(this),
|
|
80
|
+
createEvent: this.createEvent.bind(this),
|
|
81
|
+
historyManager: this.historyManager,
|
|
82
|
+
});
|
|
83
|
+
this.toolExecutor = new tool_executor_ts_1.AgentToolExecutor({
|
|
84
|
+
toolRegistry: this.config.toolRegistry,
|
|
85
|
+
securityGuard: this.config.securityGuard,
|
|
86
|
+
toolTimeout: this.config.toolTimeout,
|
|
87
|
+
runHooks: this.runHooks.bind(this),
|
|
88
|
+
runMiddlewareToolPhase: this.runMiddlewareToolPhase.bind(this),
|
|
89
|
+
createEvent: this.createEvent.bind(this),
|
|
90
|
+
historyManager: this.historyManager,
|
|
91
|
+
getMiddleware: () => this.config.middleware,
|
|
92
|
+
});
|
|
93
|
+
// 初始化工具分类集合(可通过 config 覆盖默认值)
|
|
94
|
+
this.dataFetchTools = new Set(config.dataFetchTools ?? [
|
|
95
|
+
'web_fetch', 'execute_command', 'write_file', 'append_file',
|
|
96
|
+
'run_script', 'read_file', 'read_tool_doc',
|
|
97
|
+
]);
|
|
98
|
+
this.outputTools = new Set(config.outputTools ?? [
|
|
99
|
+
'delegate_task', 'create_presentation', 'create_document',
|
|
100
|
+
'create_pdf', 'show_widget', 'save_artifact',
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
/** 获取当前 Agent 的 ToolRegistry(供 read_tool_doc 等内置工具使用) */
|
|
104
|
+
getToolRegistry() {
|
|
105
|
+
return this.config.toolRegistry;
|
|
106
|
+
}
|
|
107
|
+
/** 动态调整最大迭代上限(用于子 Agent 场景,避免子任务消耗过多迭代) */
|
|
108
|
+
setMaxIterations(max) {
|
|
109
|
+
this.config.maxIterations = max;
|
|
110
|
+
}
|
|
111
|
+
/** 获取当前 Agent 的 SkillManager(供 load_skill 等内置工具使用,确保 scope 内操作) */
|
|
112
|
+
getSkillManager() {
|
|
113
|
+
return this.config.skillManager;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 注入会话历史(从外部恢复,如持久化存储)
|
|
117
|
+
* 用于跨引擎实例保持对话上下文
|
|
118
|
+
*/
|
|
119
|
+
setHistory(sessionId, messages) {
|
|
120
|
+
this.historyManager.setHistory(sessionId, messages);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 获取会话历史副本(用于持久化保存)
|
|
124
|
+
*/
|
|
125
|
+
getHistorySnapshot(sessionId) {
|
|
126
|
+
return this.historyManager.getHistorySnapshot(sessionId);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 执行 Agent 任务(流式推送事件)
|
|
130
|
+
* 上层通过 for-await-of 消费事件流
|
|
131
|
+
*/
|
|
132
|
+
async *run(options) {
|
|
133
|
+
const { sessionId, abortSignal } = options;
|
|
134
|
+
// ① Abort 控制
|
|
135
|
+
const internalAbort = new AbortController();
|
|
136
|
+
this.abortMap.set(sessionId, internalAbort);
|
|
137
|
+
const onExternalAbort = () => internalAbort.abort();
|
|
138
|
+
if (abortSignal) {
|
|
139
|
+
if (abortSignal.aborted)
|
|
140
|
+
internalAbort.abort();
|
|
141
|
+
else
|
|
142
|
+
abortSignal.addEventListener('abort', onExternalAbort, { once: true });
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
// ② 准备阶段:Skill 路由 → 上下文 → 工具 → LoopState
|
|
146
|
+
const state = await this.prepareRun(options, internalAbort);
|
|
147
|
+
// ③ Agent Loop
|
|
148
|
+
yield* this.agentLoop(state);
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
const errorMsg = `Agent execution failed: ${err.message || err}`;
|
|
152
|
+
await this.runHooks('on_error', { sessionId, iteration: 0, error: errorMsg, recoverable: false });
|
|
153
|
+
yield this.createEvent(sessionId, {
|
|
154
|
+
type: 'error',
|
|
155
|
+
error: errorMsg,
|
|
156
|
+
recoverable: false,
|
|
157
|
+
});
|
|
158
|
+
this.statusMap.set(sessionId, 'idle');
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
if (abortSignal)
|
|
162
|
+
abortSignal.removeEventListener('abort', onExternalAbort);
|
|
163
|
+
this.abortMap.delete(sessionId);
|
|
164
|
+
this.steeringMap.delete(sessionId);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// ---- 准备阶段 ----
|
|
168
|
+
/** 解析 Skill 路由,返回 Skill 内容、实际消息和路由命中状态 */
|
|
169
|
+
async resolveSkill(options, sessionId) {
|
|
170
|
+
if (options.skillId && this.config.skillManager) {
|
|
171
|
+
const skill = this.config.skillManager.get(options.skillId);
|
|
172
|
+
return { skillContent: skill?.content, actualMessage: options.message, skillMatched: !!skill };
|
|
173
|
+
}
|
|
174
|
+
if (this.config.skillRouter) {
|
|
175
|
+
this.statusMap.set(sessionId, 'thinking');
|
|
176
|
+
const routeResult = await this.config.skillRouter.route(options.message);
|
|
177
|
+
if (routeResult.skill) {
|
|
178
|
+
return { skillContent: routeResult.skill.content, actualMessage: routeResult.message, skillMatched: true };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return { actualMessage: options.message, skillMatched: false };
|
|
182
|
+
}
|
|
183
|
+
/** 构建初始消息列表(system + history + user) */
|
|
184
|
+
buildInitialMessages(options, skillContent, actualMessage, skillMatched) {
|
|
185
|
+
const { sessionId } = options;
|
|
186
|
+
let systemPrompt = this.config.basePrompt || '';
|
|
187
|
+
if (options.systemPromptOverride) {
|
|
188
|
+
systemPrompt += `\n\n${options.systemPromptOverride}`;
|
|
189
|
+
}
|
|
190
|
+
// 注入当前运行时环境
|
|
191
|
+
const now = new Date();
|
|
192
|
+
systemPrompt += `\n\n## Current Runtime\n\n- Date: ${now.toLocaleDateString('en-CA')} (${['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][now.getDay()]})\n- Time: ${now.toLocaleTimeString('en-GB')}\n- Timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone} (UTC${now.getTimezoneOffset() <= 0 ? '+' : '-'}${String(Math.abs(Math.floor(now.getTimezoneOffset() / 60))).padStart(2, '0')}:${String(Math.abs(now.getTimezoneOffset() % 60)).padStart(2, '0')})`;
|
|
193
|
+
if (options.context?.env) {
|
|
194
|
+
systemPrompt += `\n- OS: ${options.context.env.os}\n- Shell: ${options.context.env.shell}`;
|
|
195
|
+
if (options.context.env.platform)
|
|
196
|
+
systemPrompt += `\n- Platform: ${options.context.env.platform}`;
|
|
197
|
+
if (options.context.env.hostname)
|
|
198
|
+
systemPrompt += `\n- Hostname: ${options.context.env.hostname}`;
|
|
199
|
+
if (options.context.env.user)
|
|
200
|
+
systemPrompt += `\n- User: ${options.context.env.user}`;
|
|
201
|
+
if (options.context.env.custom) {
|
|
202
|
+
for (const [key, value] of Object.entries(options.context.env.custom)) {
|
|
203
|
+
systemPrompt += `\n- ${key}: ${value}`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (skillContent) {
|
|
208
|
+
systemPrompt += `\n\n## Current Skill Instructions\n\n${skillContent}`;
|
|
209
|
+
}
|
|
210
|
+
else if (!skillMatched && this.config.skillManager) {
|
|
211
|
+
// 未命中 skill → 注入 catalog 供 agent 自主调用 load_skill
|
|
212
|
+
const catalog = buildSkillCatalog(this.config.skillManager);
|
|
213
|
+
if (catalog) {
|
|
214
|
+
systemPrompt += `\n\n${catalog}`;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (options.context?.terminalOutput) {
|
|
218
|
+
systemPrompt += `\n\n## Recent Terminal Output\n\n\`\`\`\n${options.context.terminalOutput}\n\`\`\``;
|
|
219
|
+
}
|
|
220
|
+
// 注入进度叙述规则(仅在有工具可用时)
|
|
221
|
+
if (this.config.toolRegistry) {
|
|
222
|
+
const toolCount = this.config.toolRegistry.getDefinitions().length;
|
|
223
|
+
if (toolCount > 0) {
|
|
224
|
+
systemPrompt += PROGRESS_NARRATION_RULES;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return this.config.contextManager.buildMessages({
|
|
228
|
+
systemPrompt,
|
|
229
|
+
history: this.historyManager.getHistory(sessionId),
|
|
230
|
+
userMessage: actualMessage,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
// ---- 工具定义 ----
|
|
234
|
+
/** 获取工具定义列表(含预过滤 + 渐进式发现) */
|
|
235
|
+
resolveToolDefs(options) {
|
|
236
|
+
const toolNames = [...(this.config.defaultTools || []), ...(options.extraTools || [])];
|
|
237
|
+
let defs = toolNames.length > 0
|
|
238
|
+
? this.config.toolRegistry.getDefinitions({ names: toolNames })
|
|
239
|
+
: this.config.toolRegistry.getDefinitions();
|
|
240
|
+
if (this.config.deniedTools?.length) {
|
|
241
|
+
const denied = new Set(this.config.deniedTools);
|
|
242
|
+
defs = defs.filter(d => !denied.has(d.function.name));
|
|
243
|
+
}
|
|
244
|
+
if (this.config.toolDiscovery === 'summary') {
|
|
245
|
+
defs = defs.map(d => {
|
|
246
|
+
const tool = this.config.toolRegistry.get(d.function.name);
|
|
247
|
+
if (tool?.category === 'mcp') {
|
|
248
|
+
const maxDesc = this.config.toolSummaryMaxDesc ?? 100;
|
|
249
|
+
const desc = d.function.description.length > maxDesc
|
|
250
|
+
? d.function.description.slice(0, maxDesc) + '...'
|
|
251
|
+
: d.function.description;
|
|
252
|
+
return {
|
|
253
|
+
type: 'function',
|
|
254
|
+
function: {
|
|
255
|
+
name: d.function.name,
|
|
256
|
+
description: desc + ` (use read_tool_doc to get full schema before calling; use read_tool_doc(tool_name="list") to see all available tools)`,
|
|
257
|
+
parameters: {
|
|
258
|
+
type: 'object',
|
|
259
|
+
properties: {},
|
|
260
|
+
required: [],
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return d;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return defs;
|
|
269
|
+
}
|
|
270
|
+
// ---- 准备阶段(续) ----
|
|
271
|
+
/** 构建 ToolContext */
|
|
272
|
+
buildToolContext(options, internalAbort) {
|
|
273
|
+
const custom = options.context?.custom;
|
|
274
|
+
return {
|
|
275
|
+
sessionId: options.sessionId,
|
|
276
|
+
shell: custom?.shell || this.createNoopShell(),
|
|
277
|
+
fs: custom?.fs,
|
|
278
|
+
env: options.context?.env,
|
|
279
|
+
abortSignal: internalAbort.signal,
|
|
280
|
+
custom: {
|
|
281
|
+
...custom,
|
|
282
|
+
toolRegistry: custom?.toolRegistry ?? this.config.toolRegistry,
|
|
283
|
+
skillManager: custom?.skillManager ?? this.config.skillManager,
|
|
284
|
+
},
|
|
285
|
+
emitSubEvent: custom?.emitSubEvent,
|
|
286
|
+
emitWidget: custom?.emitWidget,
|
|
287
|
+
emitArtifact: custom?.emitArtifact,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/** 汇总准备阶段,生成 LoopState */
|
|
291
|
+
async prepareRun(options, internalAbort) {
|
|
292
|
+
const { skillContent, actualMessage, skillMatched } = await this.resolveSkill(options, options.sessionId);
|
|
293
|
+
const toolDefs = this.resolveToolDefs(options);
|
|
294
|
+
console.log(`[Engine] session=${options.sessionId} tools(${toolDefs.length}): ${toolDefs.map(t => t.function.name).join(', ') || '(none)'}`);
|
|
295
|
+
return {
|
|
296
|
+
sessionId: options.sessionId,
|
|
297
|
+
messages: this.buildInitialMessages(options, skillContent, actualMessage, skillMatched),
|
|
298
|
+
toolDefs,
|
|
299
|
+
toolContext: this.buildToolContext(options, internalAbort),
|
|
300
|
+
internalAbort,
|
|
301
|
+
iteration: 0,
|
|
302
|
+
lastContent: '',
|
|
303
|
+
toolCallRecords: [],
|
|
304
|
+
consecutiveToolFailures: new Map(),
|
|
305
|
+
iterationGuardInjected: false,
|
|
306
|
+
consecutiveSilentIterations: 0,
|
|
307
|
+
lastIterationHadToolCalls: false,
|
|
308
|
+
continuationNudges: 0,
|
|
309
|
+
dataFetchGuardInjected: false,
|
|
310
|
+
consecutiveAllFailIterations: 0,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
// ---- Agent Loop ----
|
|
314
|
+
/** 主循环:迭代调用 LLM → 执行工具 → 直到完成或达到上限 */
|
|
315
|
+
async *agentLoop(state) {
|
|
316
|
+
while (state.iteration < this.config.maxIterations) {
|
|
317
|
+
state.iteration++;
|
|
318
|
+
state.lastIterationHadToolCalls = false; // 每轮迭代重置,工具执行后才置 true
|
|
319
|
+
// 中断检查
|
|
320
|
+
if (state.internalAbort.signal.aborted) {
|
|
321
|
+
yield this.emitDone(state);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
// Middleware.before + Hook: on_iteration_start
|
|
325
|
+
await this.runMiddlewarePhase('before', state);
|
|
326
|
+
await this.runHooks('on_iteration_start', {
|
|
327
|
+
sessionId: state.sessionId,
|
|
328
|
+
iteration: state.iteration,
|
|
329
|
+
});
|
|
330
|
+
// Live Steering
|
|
331
|
+
const steeringResult = this.drainSteering(state);
|
|
332
|
+
if (steeringResult) {
|
|
333
|
+
yield this.createEvent(state.sessionId, {
|
|
334
|
+
type: 'steering',
|
|
335
|
+
messages: steeringResult.messages,
|
|
336
|
+
count: steeringResult.count,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
// 迭代预算提醒:接近上限时注入提醒,防止 agent 耗尽迭代仍在收集数据
|
|
340
|
+
this.injectIterationGuard(state);
|
|
341
|
+
// 数据获取循环检测:连续多轮只调用数据获取工具时注入强制提示
|
|
342
|
+
// 首次触发:注入 guard 消息让 LLM 下轮产出总结;不立即终止,给 LLM 一次产出机会
|
|
343
|
+
// 若 LLM 继续失败,全局连续失败熔断器(consecutiveAllFailIterations >= 3)会兜底
|
|
344
|
+
this.checkDataFetchLoop(state);
|
|
345
|
+
// 调用 LLM(流式,含重试与降级)
|
|
346
|
+
this.statusMap.set(state.sessionId, 'thinking');
|
|
347
|
+
const assistant = yield* this.llmCaller.callWithRetry(state.sessionId, state.messages, state.toolDefs, state.internalAbort.signal);
|
|
348
|
+
// 从 LLMCaller 流中提取 usage(通过 last event 的 usage)
|
|
349
|
+
// 注意:usage 在 chunk 级别,这里通过 callWithRetry 的返回无法直接获取
|
|
350
|
+
// 保持原有逻辑:usage 累加在 LLMCaller 内部暂不可见,后续可优化
|
|
351
|
+
if (!assistant) {
|
|
352
|
+
// LLM 返回 null(上下文过长/错误)后,如果上一轮有工具调用,注入提示重试
|
|
353
|
+
if (state.lastIterationHadToolCalls && state.continuationNudges < 2) {
|
|
354
|
+
state.continuationNudges++;
|
|
355
|
+
console.log(`[Engine] LLM returned null after tool calls, injecting continuation nudge #${state.continuationNudges} at iteration ${state.iteration}`);
|
|
356
|
+
this.injectContinuationNudge(state);
|
|
357
|
+
}
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
// Hook: after_ll_call
|
|
361
|
+
await this.runHooks('after_ll_call', {
|
|
362
|
+
sessionId: state.sessionId,
|
|
363
|
+
iteration: state.iteration,
|
|
364
|
+
response: assistant,
|
|
365
|
+
});
|
|
366
|
+
// 处理 LLM 响应
|
|
367
|
+
state.messages.push(assistant);
|
|
368
|
+
// 保存原始 tool_call arguments 长度(addHistory 可能触发压缩,原地替换 arguments 为占位符)
|
|
369
|
+
// tool-executor 使用此信息判断截断(而非占位符的长度)
|
|
370
|
+
if (assistant.tool_calls?.length) {
|
|
371
|
+
for (const tc of assistant.tool_calls) {
|
|
372
|
+
tc._rawArgLength = tc.function.arguments?.length ?? 0;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
this.historyManager.addHistory(state.sessionId, assistant);
|
|
376
|
+
if (assistant.content) {
|
|
377
|
+
state.lastContent = assistant.content;
|
|
378
|
+
state.consecutiveSilentIterations = 0;
|
|
379
|
+
}
|
|
380
|
+
// 无 tool_calls → 检查是否提前停止(上一轮有工具调用,说明任务可能未完成)
|
|
381
|
+
if (!assistant.tool_calls?.length) {
|
|
382
|
+
if (state.lastIterationHadToolCalls && state.continuationNudges < 2) {
|
|
383
|
+
state.continuationNudges++;
|
|
384
|
+
console.log(`[Engine] LLM stopped after tool calls without new tool_calls, injecting continuation nudge #${state.continuationNudges} at iteration ${state.iteration}`);
|
|
385
|
+
this.injectContinuationNudge(state);
|
|
386
|
+
// 不退出,继续下一轮迭代让 LLM 继续执行任务
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
yield this.emitDone(state);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
// 重置继续提示计数(LLM 仍在生成工具调用,说明任务在推进)
|
|
393
|
+
state.continuationNudges = 0;
|
|
394
|
+
// 检测连续静默迭代(有 tool_calls 但无 content),超过阈值自动注入提醒
|
|
395
|
+
if (!assistant.content) {
|
|
396
|
+
state.consecutiveSilentIterations++;
|
|
397
|
+
if (state.consecutiveSilentIterations >= 2) {
|
|
398
|
+
this.injectProgressNudge(state);
|
|
399
|
+
state.consecutiveSilentIterations = 0;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// 执行工具
|
|
403
|
+
const prevRecordCount = state.toolCallRecords.length;
|
|
404
|
+
yield* this.toolExecutor.executeToolCalls(state, assistant.tool_calls);
|
|
405
|
+
// ---- 全局连续失败熔断 ----
|
|
406
|
+
const newRecords = state.toolCallRecords.slice(prevRecordCount);
|
|
407
|
+
if (newRecords.length > 0) {
|
|
408
|
+
const allFailed = newRecords.every(r => r.isError);
|
|
409
|
+
if (allFailed) {
|
|
410
|
+
state.consecutiveAllFailIterations++;
|
|
411
|
+
if (state.consecutiveAllFailIterations >= 3) {
|
|
412
|
+
console.warn(`[Engine] Global early stop: ${state.consecutiveAllFailIterations} consecutive all-fail iterations at iteration ${state.iteration}`);
|
|
413
|
+
yield this.emitDone(state);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
state.consecutiveAllFailIterations = 0;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// 渐进式结果交付:并行分发多个 delegate_task 后,提示 LLM 逐步呈现结果
|
|
422
|
+
this.injectProgressiveNudge(state, assistant.tool_calls);
|
|
423
|
+
// 标记本轮有工具调用(用于下一轮检测 LLM 是否提前停止)
|
|
424
|
+
state.lastIterationHadToolCalls = true;
|
|
425
|
+
// Middleware.after
|
|
426
|
+
await this.runMiddlewarePhase('after', state);
|
|
427
|
+
}
|
|
428
|
+
// 达到最大迭代
|
|
429
|
+
yield this.emitDone(state);
|
|
430
|
+
}
|
|
431
|
+
// ---- Live Steering(实时转向)----
|
|
432
|
+
/**
|
|
433
|
+
* 向运行中的 Agent 注入 steering 消息
|
|
434
|
+
* 消息将在下次 LLM 调用前注入对话上下文
|
|
435
|
+
*/
|
|
436
|
+
steer(sessionId, message) {
|
|
437
|
+
if (!this.abortMap.has(sessionId))
|
|
438
|
+
return false;
|
|
439
|
+
if (!this.steeringMap.has(sessionId)) {
|
|
440
|
+
this.steeringMap.set(sessionId, []);
|
|
441
|
+
}
|
|
442
|
+
this.steeringMap.get(sessionId).push(message);
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
/** 消费当前会话的 steering 消息,注入到 messages 中 */
|
|
446
|
+
drainSteering(state) {
|
|
447
|
+
const msgs = this.steeringMap.get(state.sessionId);
|
|
448
|
+
if (!msgs || msgs.length === 0)
|
|
449
|
+
return null;
|
|
450
|
+
const drained = [...msgs];
|
|
451
|
+
msgs.length = 0;
|
|
452
|
+
for (const msg of drained) {
|
|
453
|
+
const userMsg = { role: 'user', content: msg };
|
|
454
|
+
state.messages.push(userMsg);
|
|
455
|
+
this.historyManager.addHistory(state.sessionId, userMsg);
|
|
456
|
+
}
|
|
457
|
+
return { messages: drained, count: drained.length };
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* 进度叙述提醒
|
|
461
|
+
* 当 LLM 连续 2 次迭代仅发出 tool_calls 而无 content 时,注入 user 消息提醒输出进度说明。
|
|
462
|
+
* 确保用户在对话中有可见的文字输出,而不是所有内容都收在执行步骤中。
|
|
463
|
+
*/
|
|
464
|
+
injectProgressNudge(state) {
|
|
465
|
+
const msg = {
|
|
466
|
+
role: 'user',
|
|
467
|
+
content: [
|
|
468
|
+
'[SYSTEM: PROGRESS NARRATION]',
|
|
469
|
+
'',
|
|
470
|
+
'You have been calling tools without providing visible text to the user.',
|
|
471
|
+
'Please provide a brief progress update in the user\'s language:',
|
|
472
|
+
'- What have you accomplished so far?',
|
|
473
|
+
'- What are you working on next?',
|
|
474
|
+
'- If you found important data, summarize the key findings.',
|
|
475
|
+
'',
|
|
476
|
+
'Keep it to 1-3 sentences. This text is displayed directly to the user.',
|
|
477
|
+
].join('\n'),
|
|
478
|
+
};
|
|
479
|
+
state.messages.push(msg);
|
|
480
|
+
this.historyManager.addHistory(state.sessionId, msg);
|
|
481
|
+
console.log(`[Engine] Progress nudge injected at iteration ${state.iteration}`);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* 迭代预算提醒
|
|
485
|
+
* 当剩余迭代不足 30% 时,注入 user 消息提醒 LLM 停止数据收集、转向完成任务。
|
|
486
|
+
* 解决 agent 在数据查询循环中耗尽迭代、永远无法进入文档生成/委托阶段的问题。
|
|
487
|
+
*/
|
|
488
|
+
injectIterationGuard(state) {
|
|
489
|
+
if (state.iterationGuardInjected)
|
|
490
|
+
return;
|
|
491
|
+
const max = this.config.maxIterations;
|
|
492
|
+
const cur = state.iteration;
|
|
493
|
+
const remaining = max - cur;
|
|
494
|
+
const ratio = cur / max;
|
|
495
|
+
if (ratio >= 0.35 && remaining > 0) {
|
|
496
|
+
state.iterationGuardInjected = true;
|
|
497
|
+
const toolCallCount = state.toolCallRecords.length;
|
|
498
|
+
const msg = {
|
|
499
|
+
role: 'user',
|
|
500
|
+
content: [
|
|
501
|
+
`[SYSTEM ITERATION BUDGET: iteration ${cur}/${max}, ${remaining} remaining]`,
|
|
502
|
+
'',
|
|
503
|
+
`⚠️ You have used ${cur} of ${max} iterations (${toolCallCount} tool calls). Budget is running low.`,
|
|
504
|
+
'',
|
|
505
|
+
'**MANDATORY rules for remaining iterations — violating these will result in task failure:**',
|
|
506
|
+
'1. **STOP all data gathering immediately.** You already have enough data from previous tool calls.',
|
|
507
|
+
'2. **DO NOT call web_fetch, execute_command, write_file, or run_script again.**',
|
|
508
|
+
'3. **NOW delegate remaining work:**',
|
|
509
|
+
' - For reports/dashboards: call `delegate_task` with agent "报表创作助手".',
|
|
510
|
+
' - For documents: call `delegate_task` with agent "文档创作助手".',
|
|
511
|
+
' - For PPT: call `delegate_task` with agent "文档创作助手".',
|
|
512
|
+
' - For direct output: call `create_presentation`/`create_document`/`show_widget` directly.',
|
|
513
|
+
'4. If you cannot delegate, produce the final output NOW with the data you have.',
|
|
514
|
+
'',
|
|
515
|
+
'Do NOT write any more scripts or fetch any more data. Your data collection phase is OVER.',
|
|
516
|
+
].join('\n'),
|
|
517
|
+
};
|
|
518
|
+
state.messages.push(msg);
|
|
519
|
+
this.historyManager.addHistory(state.sessionId, msg);
|
|
520
|
+
console.log(`[Engine] Iteration guard injected at ${cur}/${max}`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* 数据获取循环检测 + 连续失败熔断
|
|
525
|
+
*
|
|
526
|
+
* 两类触发条件:
|
|
527
|
+
* 1. 数据获取循环:最近 3+ 条工具调用全部是数据获取类且无产出型工具
|
|
528
|
+
* 2. 连续失败熔断:最近 5+ 条工具调用中 4+ 条失败,强制停止试错、转向产出
|
|
529
|
+
*/
|
|
530
|
+
checkDataFetchLoop(state) {
|
|
531
|
+
if (state.dataFetchGuardInjected)
|
|
532
|
+
return;
|
|
533
|
+
// 数据获取类工具(非产出型)— 使用实例配置
|
|
534
|
+
const DATA_FETCH_TOOLS = this.dataFetchTools;
|
|
535
|
+
// 产出型工具(有这些就不算数据获取循环)— 使用实例配置
|
|
536
|
+
const OUTPUT_TOOLS = this.outputTools;
|
|
537
|
+
const hasOutput = state.toolCallRecords.some(r => OUTPUT_TOOLS.has(r.tool));
|
|
538
|
+
if (hasOutput)
|
|
539
|
+
return; // 已调用过产出型工具,不再干预
|
|
540
|
+
const recent = state.toolCallRecords.slice(-6);
|
|
541
|
+
// --- 条件 1:数据获取循环(最近 3+ 条全是数据获取类) ---
|
|
542
|
+
if (recent.length >= 3) {
|
|
543
|
+
const last3 = recent.slice(-3);
|
|
544
|
+
const allDataFetch = last3.every(r => DATA_FETCH_TOOLS.has(r.tool));
|
|
545
|
+
if (allDataFetch) {
|
|
546
|
+
this.injectDataFetchGuard(state, recent, 'loop');
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// --- 条件 2:连续失败熔断(最近 5+ 条中 4+ 条失败) ---
|
|
551
|
+
if (recent.length >= 5) {
|
|
552
|
+
const errorCount = recent.filter(r => r.isError).length;
|
|
553
|
+
if (errorCount >= 4) {
|
|
554
|
+
this.injectDataFetchGuard(state, recent, 'failures');
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
/** 注入数据获取循环/连续失败熔断提示 */
|
|
560
|
+
injectDataFetchGuard(state, recent, reason) {
|
|
561
|
+
state.dataFetchGuardInjected = true;
|
|
562
|
+
const toolSummary = recent.map(r => `${r.tool}(${r.isError ? 'err' : 'ok'})`).join(', ');
|
|
563
|
+
const errorCount = recent.filter(r => r.isError).length;
|
|
564
|
+
const reasonText = reason === 'loop'
|
|
565
|
+
? `Your last ${recent.length} tool calls are all data-fetching without any output: ${toolSummary}`
|
|
566
|
+
: `${errorCount} of your last ${recent.length} tool calls FAILED: ${toolSummary}`;
|
|
567
|
+
const msg = {
|
|
568
|
+
role: 'user',
|
|
569
|
+
content: [
|
|
570
|
+
`[SYSTEM: ${reason === 'loop' ? 'DATA GATHERING LOOP' : 'CONSECUTIVE FAILURES'} DETECTED]`,
|
|
571
|
+
'',
|
|
572
|
+
reasonText,
|
|
573
|
+
'',
|
|
574
|
+
'⛔ **You MUST stop trying to fetch more data NOW.**',
|
|
575
|
+
'',
|
|
576
|
+
'**Required action — do ONE of the following immediately:**',
|
|
577
|
+
'1. Call `delegate_task` with whatever data/context you have to let a specialist generate the output.',
|
|
578
|
+
'2. If delegation is not suitable, produce the final output NOW with available data.',
|
|
579
|
+
'3. At minimum, provide a clear text summary to the user explaining what you found and what failed.',
|
|
580
|
+
'',
|
|
581
|
+
'**Do NOT:**',
|
|
582
|
+
'- Write another script to fetch data',
|
|
583
|
+
'- Try another API, URL, or npm package',
|
|
584
|
+
'- Debug the current failure — accept it and move on',
|
|
585
|
+
'',
|
|
586
|
+
'The user is waiting for OUTPUT, not more failed attempts.',
|
|
587
|
+
].join('\n'),
|
|
588
|
+
};
|
|
589
|
+
state.messages.push(msg);
|
|
590
|
+
this.historyManager.addHistory(state.sessionId, msg);
|
|
591
|
+
console.log(`[Engine] Data-fetch guard (${reason}) injected at iteration ${state.iteration}, recent: ${toolSummary}`);
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* 任务继续提示
|
|
595
|
+
* 当 LLM 在工具调用后提前停止(无新工具调用也无明确总结)时,注入提示让其继续完成剩余任务。
|
|
596
|
+
* 典型场景:多步委托任务中,第一步数据采集完成后 LLM 未生成后续步骤的 delegate_task。
|
|
597
|
+
*/
|
|
598
|
+
injectContinuationNudge(state) {
|
|
599
|
+
const toolCallCount = state.toolCallRecords.length;
|
|
600
|
+
const msg = {
|
|
601
|
+
role: 'user',
|
|
602
|
+
content: [
|
|
603
|
+
'[SYSTEM: TASK CONTINUATION]',
|
|
604
|
+
'',
|
|
605
|
+
`You have completed ${toolCallCount} tool call(s) so far, but the original user request has NOT been fully fulfilled.`,
|
|
606
|
+
'',
|
|
607
|
+
'Please review the original request and continue with the remaining steps:',
|
|
608
|
+
'- If you planned multi-step tasks (e.g., data gathering → PPT/report generation), **NOW execute the remaining steps**.',
|
|
609
|
+
'- Use `delegate_task` to delegate remaining work to appropriate specialists.',
|
|
610
|
+
'- If document/PPT/report generation is needed, call the relevant tools immediately.',
|
|
611
|
+
'- Do NOT re-gather data you already have. Use the results from previous tool calls.',
|
|
612
|
+
'',
|
|
613
|
+
'Continue your work now.',
|
|
614
|
+
].join('\n'),
|
|
615
|
+
};
|
|
616
|
+
state.messages.push(msg);
|
|
617
|
+
this.historyManager.addHistory(state.sessionId, msg);
|
|
618
|
+
console.log(`[Engine] Continuation nudge injected at iteration ${state.iteration} (nudge #${state.continuationNudges})`);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* 渐进式结果交付
|
|
622
|
+
* 当主 Agent 并行分发了多个 delegate_task 后,注入提示让 LLM 逐步呈现每个子任务的结果,
|
|
623
|
+
* 而不是等所有结果全部返回后才开始输出。减少用户感知等待时间。
|
|
624
|
+
*/
|
|
625
|
+
injectProgressiveNudge(state, toolCalls) {
|
|
626
|
+
const delegateCalls = toolCalls.filter(tc => tc.function.name === 'delegate_task');
|
|
627
|
+
if (delegateCalls.length < 2)
|
|
628
|
+
return;
|
|
629
|
+
const msg = {
|
|
630
|
+
role: 'user',
|
|
631
|
+
content: [
|
|
632
|
+
'[SYSTEM: PROGRESSIVE DELIVERY]',
|
|
633
|
+
'',
|
|
634
|
+
`You dispatched ${delegateCalls.length} sub-tasks in parallel. Some may succeed while others fail or take longer.`,
|
|
635
|
+
'',
|
|
636
|
+
'When presenting results to the user:',
|
|
637
|
+
'1. **Present each completed result as it becomes available** — do NOT wait for all tasks to finish.',
|
|
638
|
+
'2. If a sub-agent reports network/sandbox restrictions or fails, **acknowledge it briefly and move on** with available data.',
|
|
639
|
+
'3. **Do NOT re-dispatch** a failed task to the same or different agent — use what you already have.',
|
|
640
|
+
'4. Start your final analysis/report with whatever data is available, noting which parts are missing.',
|
|
641
|
+
'',
|
|
642
|
+
'The user values SPEED over COMPLETENESS. A partial result delivered in 2 minutes is better than a perfect result delivered in 15 minutes.',
|
|
643
|
+
].join('\n'),
|
|
644
|
+
};
|
|
645
|
+
state.messages.push(msg);
|
|
646
|
+
this.historyManager.addHistory(state.sessionId, msg);
|
|
647
|
+
console.log(`[Engine] Progressive delivery nudge injected at iteration ${state.iteration} (${delegateCalls.length} parallel delegates)`);
|
|
648
|
+
}
|
|
649
|
+
// ---- Hooks ----
|
|
650
|
+
/** 执行指定事件类型的所有 Hook */
|
|
651
|
+
async runHooks(event, ctx) {
|
|
652
|
+
const hooks = this.config.hooks?.filter(h => h.event === event) || [];
|
|
653
|
+
if (hooks.length === 0)
|
|
654
|
+
return [];
|
|
655
|
+
const results = [];
|
|
656
|
+
for (const hook of hooks) {
|
|
657
|
+
try {
|
|
658
|
+
const result = await hook.handler(ctx);
|
|
659
|
+
if (result)
|
|
660
|
+
results.push(result);
|
|
661
|
+
}
|
|
662
|
+
catch (e) {
|
|
663
|
+
console.warn(`[Hook] ${hook.name} (${event}) failed:`, e?.message || e);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return results;
|
|
667
|
+
}
|
|
668
|
+
// ---- Middleware ----
|
|
669
|
+
/** 执行中间件的 before/after 阶段 */
|
|
670
|
+
async runMiddlewarePhase(phase, state) {
|
|
671
|
+
const middlewares = this.config.middleware;
|
|
672
|
+
if (!middlewares || middlewares.length === 0)
|
|
673
|
+
return;
|
|
674
|
+
const ctx = {
|
|
675
|
+
sessionId: state.sessionId,
|
|
676
|
+
iteration: state.iteration,
|
|
677
|
+
messages: state.messages,
|
|
678
|
+
toolCount: state.toolDefs.length,
|
|
679
|
+
};
|
|
680
|
+
for (const mw of middlewares) {
|
|
681
|
+
try {
|
|
682
|
+
if (phase === 'before' && mw.before) {
|
|
683
|
+
await mw.before(ctx);
|
|
684
|
+
}
|
|
685
|
+
else if (phase === 'after' && mw.after) {
|
|
686
|
+
await mw.after(ctx);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
catch (e) {
|
|
690
|
+
console.warn(`[Middleware] ${mw.name} (${phase}) failed:`, e?.message || e);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
/** 执行中间件的 onToolBefore/onToolAfter 阶段 */
|
|
695
|
+
async runMiddlewareToolPhase(phase, ctx) {
|
|
696
|
+
const middlewares = this.config.middleware;
|
|
697
|
+
if (!middlewares || middlewares.length === 0)
|
|
698
|
+
return [];
|
|
699
|
+
const results = [];
|
|
700
|
+
for (const mw of middlewares) {
|
|
701
|
+
try {
|
|
702
|
+
const handler = mw[phase];
|
|
703
|
+
if (handler) {
|
|
704
|
+
const result = await handler.call(mw, ctx);
|
|
705
|
+
if (result)
|
|
706
|
+
results.push(result);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
catch (e) {
|
|
710
|
+
console.warn(`[Middleware] ${mw.name} (${phase}) failed:`, e?.message || e);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return results;
|
|
714
|
+
}
|
|
715
|
+
// ---- 辅助 ----
|
|
716
|
+
emitDone(state) {
|
|
717
|
+
this.statusMap.set(state.sessionId, 'idle');
|
|
718
|
+
this.runHooks('on_complete', {
|
|
719
|
+
sessionId: state.sessionId,
|
|
720
|
+
iteration: state.iteration,
|
|
721
|
+
totalIterations: state.iteration,
|
|
722
|
+
usage: state.totalUsage,
|
|
723
|
+
}).catch(() => { });
|
|
724
|
+
return this.createEvent(state.sessionId, {
|
|
725
|
+
type: 'done',
|
|
726
|
+
content: state.lastContent || 'Max iterations reached',
|
|
727
|
+
iterations: state.iteration,
|
|
728
|
+
usage: state.totalUsage,
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
/** 中断指定会话的 Agent 执行 */
|
|
732
|
+
abort(sessionId) {
|
|
733
|
+
const controller = this.abortMap.get(sessionId);
|
|
734
|
+
if (controller) {
|
|
735
|
+
controller.abort();
|
|
736
|
+
this.statusMap.set(sessionId, 'aborting');
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
/** 查询指定会话的 Agent 状态 */
|
|
740
|
+
getStatus(sessionId) {
|
|
741
|
+
return this.statusMap.get(sessionId) || 'idle';
|
|
742
|
+
}
|
|
743
|
+
/** 销毁引擎,释放所有会话资源 */
|
|
744
|
+
destroy() {
|
|
745
|
+
for (const controller of Array.from(this.abortMap.values())) {
|
|
746
|
+
controller.abort();
|
|
747
|
+
}
|
|
748
|
+
this.abortMap.clear();
|
|
749
|
+
this.statusMap.clear();
|
|
750
|
+
this.steeringMap.clear();
|
|
751
|
+
this.historyManager.clearAll();
|
|
752
|
+
}
|
|
753
|
+
// ---- 内部辅助 ----
|
|
754
|
+
createEvent(sessionId, event) {
|
|
755
|
+
return { ...event, timestamp: Date.now(), sessionId };
|
|
756
|
+
}
|
|
757
|
+
createNoopShell() {
|
|
758
|
+
return {
|
|
759
|
+
exec: async () => 'Error: Shell executor not configured',
|
|
760
|
+
write: () => { },
|
|
761
|
+
read: () => '',
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
exports.AgentEngine = AgentEngine;
|
|
766
|
+
//# sourceMappingURL=engine.js.map
|