@qodo/sdk 0.13.4 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +31 -118
- package/README.md +133 -121
- package/bin/qodo-skills.mjs +13 -0
- package/bundled-skills/code-review/SKILL.md +41 -0
- package/bundled-skills/pr-summary/SKILL.md +59 -0
- package/bundled-skills/test-gen/SKILL.md +47 -0
- package/dist/auth/index.browser.d.ts +38 -0
- package/dist/auth/index.browser.d.ts.map +1 -0
- package/dist/auth/index.browser.js +62 -0
- package/dist/auth/index.browser.js.map +1 -0
- package/dist/auth/index.d.ts +44 -30
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +57 -110
- package/dist/auth/index.js.map +1 -1
- package/dist/client/AgentsClient.d.ts +33 -0
- package/dist/client/AgentsClient.d.ts.map +1 -0
- package/dist/client/AgentsClient.js +40 -0
- package/dist/client/AgentsClient.js.map +1 -0
- package/dist/client/ArtifactsClient.d.ts +43 -0
- package/dist/client/ArtifactsClient.d.ts.map +1 -0
- package/dist/client/ArtifactsClient.js +54 -0
- package/dist/client/ArtifactsClient.js.map +1 -0
- package/dist/client/BulletinClient.d.ts +45 -0
- package/dist/client/BulletinClient.d.ts.map +1 -0
- package/dist/client/BulletinClient.js +51 -0
- package/dist/client/BulletinClient.js.map +1 -0
- package/dist/client/InfoClient.d.ts +58 -0
- package/dist/client/InfoClient.d.ts.map +1 -0
- package/dist/client/InfoClient.js +135 -0
- package/dist/client/InfoClient.js.map +1 -0
- package/dist/client/PipelineClient.d.ts +162 -0
- package/dist/client/PipelineClient.d.ts.map +1 -0
- package/dist/client/PipelineClient.js +340 -0
- package/dist/client/PipelineClient.js.map +1 -0
- package/dist/client/QarRegistryClient.d.ts +396 -0
- package/dist/client/QarRegistryClient.d.ts.map +1 -0
- package/dist/client/QarRegistryClient.js +536 -0
- package/dist/client/QarRegistryClient.js.map +1 -0
- package/dist/client/QodoClient.d.ts +296 -0
- package/dist/client/QodoClient.d.ts.map +1 -0
- package/dist/client/QodoClient.js +803 -0
- package/dist/client/QodoClient.js.map +1 -0
- package/dist/client/SpecsClient.d.ts +121 -0
- package/dist/client/SpecsClient.d.ts.map +1 -0
- package/dist/client/SpecsClient.js +252 -0
- package/dist/client/SpecsClient.js.map +1 -0
- package/dist/client/StateClient.d.ts +35 -0
- package/dist/client/StateClient.d.ts.map +1 -0
- package/dist/client/StateClient.js +36 -0
- package/dist/client/StateClient.js.map +1 -0
- package/dist/client/TaskClient.d.ts +706 -0
- package/dist/client/TaskClient.d.ts.map +1 -0
- package/dist/client/TaskClient.js +2522 -0
- package/dist/client/TaskClient.js.map +1 -0
- package/dist/client/ToolClient.d.ts +278 -0
- package/dist/client/ToolClient.d.ts.map +1 -0
- package/dist/client/ToolClient.js +1115 -0
- package/dist/client/ToolClient.js.map +1 -0
- package/dist/client/a2a/index.d.ts +10 -0
- package/dist/client/a2a/index.d.ts.map +1 -0
- package/dist/client/a2a/index.js +9 -0
- package/dist/client/a2a/index.js.map +1 -0
- package/dist/client/a2a/registerA2A.d.ts +170 -0
- package/dist/client/a2a/registerA2A.d.ts.map +1 -0
- package/dist/client/a2a/registerA2A.js +85 -0
- package/dist/client/a2a/registerA2A.js.map +1 -0
- package/dist/client/connection.d.ts +800 -0
- package/dist/client/connection.d.ts.map +1 -0
- package/dist/client/connection.js +2020 -0
- package/dist/client/connection.js.map +1 -0
- package/dist/client/errors.d.ts +735 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +921 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/index.d.ts +26 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +20 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/inlineGraph.d.ts +66 -0
- package/dist/client/inlineGraph.d.ts.map +1 -0
- package/dist/client/inlineGraph.js +500 -0
- package/dist/client/inlineGraph.js.map +1 -0
- package/dist/client/internal/thenable.d.ts +27 -0
- package/dist/client/internal/thenable.d.ts.map +1 -0
- package/dist/client/internal/thenable.js +31 -0
- package/dist/client/internal/thenable.js.map +1 -0
- package/dist/client/iterator.d.ts +32 -0
- package/dist/client/iterator.d.ts.map +1 -0
- package/dist/client/iterator.js +73 -0
- package/dist/client/iterator.js.map +1 -0
- package/dist/client/mcp/McpClientPool.browser.d.ts +76 -0
- package/dist/client/mcp/McpClientPool.browser.d.ts.map +1 -0
- package/dist/client/mcp/McpClientPool.browser.js +78 -0
- package/dist/client/mcp/McpClientPool.browser.js.map +1 -0
- package/dist/client/mcp/McpClientPool.d.ts +236 -0
- package/dist/client/mcp/McpClientPool.d.ts.map +1 -0
- package/dist/client/mcp/McpClientPool.js +585 -0
- package/dist/client/mcp/McpClientPool.js.map +1 -0
- package/dist/client/mcp/projection.d.ts +109 -0
- package/dist/client/mcp/projection.d.ts.map +1 -0
- package/dist/client/mcp/projection.js +446 -0
- package/dist/client/mcp/projection.js.map +1 -0
- package/dist/client/mcp/substituteEnv.browser.d.ts +18 -0
- package/dist/client/mcp/substituteEnv.browser.d.ts.map +1 -0
- package/dist/client/mcp/substituteEnv.browser.js +20 -0
- package/dist/client/mcp/substituteEnv.browser.js.map +1 -0
- package/dist/client/mcp/substituteEnv.d.ts +45 -0
- package/dist/client/mcp/substituteEnv.d.ts.map +1 -0
- package/dist/client/mcp/substituteEnv.js +63 -0
- package/dist/client/mcp/substituteEnv.js.map +1 -0
- package/dist/client/observers.d.ts +57 -0
- package/dist/client/observers.d.ts.map +1 -0
- package/dist/client/observers.js +203 -0
- package/dist/client/observers.js.map +1 -0
- package/dist/client/options.d.ts +269 -0
- package/dist/client/options.d.ts.map +1 -0
- package/dist/client/options.js +9 -0
- package/dist/client/options.js.map +1 -0
- package/dist/client/tools/_readlineApprovalPrompt.browser.d.ts +17 -0
- package/dist/client/tools/_readlineApprovalPrompt.browser.d.ts.map +1 -0
- package/dist/client/tools/_readlineApprovalPrompt.browser.js +24 -0
- package/dist/client/tools/_readlineApprovalPrompt.browser.js.map +1 -0
- package/dist/client/tools/_readlineApprovalPrompt.d.ts +33 -0
- package/dist/client/tools/_readlineApprovalPrompt.d.ts.map +1 -0
- package/dist/client/tools/_readlineApprovalPrompt.js +90 -0
- package/dist/client/tools/_readlineApprovalPrompt.js.map +1 -0
- package/dist/client/tools/approval.d.ts +280 -0
- package/dist/client/tools/approval.d.ts.map +1 -0
- package/dist/client/tools/approval.js +229 -0
- package/dist/client/tools/approval.js.map +1 -0
- package/dist/client/tools/bindFunctionToolDefs.d.ts +156 -0
- package/dist/client/tools/bindFunctionToolDefs.d.ts.map +1 -0
- package/dist/client/tools/bindFunctionToolDefs.js +360 -0
- package/dist/client/tools/bindFunctionToolDefs.js.map +1 -0
- package/dist/client/tools/defineFunctionTool.d.ts +277 -0
- package/dist/client/tools/defineFunctionTool.d.ts.map +1 -0
- package/dist/client/tools/defineFunctionTool.js +190 -0
- package/dist/client/tools/defineFunctionTool.js.map +1 -0
- package/dist/client/transport.browser.d.ts +20 -0
- package/dist/client/transport.browser.d.ts.map +1 -0
- package/dist/client/transport.browser.js +29 -0
- package/dist/client/transport.browser.js.map +1 -0
- package/dist/client/transport.d.ts +47 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +102 -0
- package/dist/client/transport.js.map +1 -0
- package/dist/client/transport.shared.d.ts +30 -0
- package/dist/client/transport.shared.d.ts.map +1 -0
- package/dist/client/transport.shared.js +40 -0
- package/dist/client/transport.shared.js.map +1 -0
- package/dist/client/uuid.d.ts +32 -0
- package/dist/client/uuid.d.ts.map +1 -0
- package/dist/client/uuid.js +65 -0
- package/dist/client/uuid.js.map +1 -0
- package/dist/index.d.ts +88 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +166 -43
- package/dist/index.js.map +1 -1
- package/dist/observability/attributes.d.ts +136 -0
- package/dist/observability/attributes.d.ts.map +1 -0
- package/dist/observability/attributes.js +184 -0
- package/dist/observability/attributes.js.map +1 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +11 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/resolveOTel.browser.d.ts +13 -0
- package/dist/observability/resolveOTel.browser.d.ts.map +1 -0
- package/dist/observability/resolveOTel.browser.js +14 -0
- package/dist/observability/resolveOTel.browser.js.map +1 -0
- package/dist/observability/resolveOTel.d.ts +28 -0
- package/dist/observability/resolveOTel.d.ts.map +1 -0
- package/dist/observability/resolveOTel.js +74 -0
- package/dist/observability/resolveOTel.js.map +1 -0
- package/dist/observability/spans.d.ts +198 -0
- package/dist/observability/spans.d.ts.map +1 -0
- package/dist/observability/spans.js +300 -0
- package/dist/observability/spans.js.map +1 -0
- package/dist/observability/traceContext.d.ts +51 -0
- package/dist/observability/traceContext.d.ts.map +1 -0
- package/dist/observability/traceContext.js +151 -0
- package/dist/observability/traceContext.js.map +1 -0
- package/dist/observability/transportMetrics.d.ts +58 -0
- package/dist/observability/transportMetrics.d.ts.map +1 -0
- package/dist/observability/transportMetrics.js +55 -0
- package/dist/observability/transportMetrics.js.map +1 -0
- package/dist/qar/agentSpec.d.ts +93 -0
- package/dist/qar/agentSpec.d.ts.map +1 -0
- package/dist/qar/agentSpec.js +184 -0
- package/dist/qar/agentSpec.js.map +1 -0
- package/dist/qar/clientEvents.d.ts +86 -0
- package/dist/qar/clientEvents.d.ts.map +1 -0
- package/dist/qar/clientEvents.js +36 -0
- package/dist/qar/clientEvents.js.map +1 -0
- package/dist/qar/envelopes.d.ts +227 -0
- package/dist/qar/envelopes.d.ts.map +1 -0
- package/dist/qar/envelopes.js +67 -0
- package/dist/qar/envelopes.js.map +1 -0
- package/dist/qar/generated/envelope.d.ts +332 -0
- package/dist/qar/generated/envelope.d.ts.map +1 -0
- package/dist/qar/generated/envelope.js +15 -0
- package/dist/qar/generated/envelope.js.map +1 -0
- package/dist/qar/generated/qar-info.d.ts +76 -0
- package/dist/qar/generated/qar-info.d.ts.map +1 -0
- package/dist/qar/generated/qar-info.js +15 -0
- package/dist/qar/generated/qar-info.js.map +1 -0
- package/dist/qar/generated/qodo-task-start-payload.d.ts +54 -0
- package/dist/qar/generated/qodo-task-start-payload.d.ts.map +1 -0
- package/dist/qar/generated/qodo-task-start-payload.js +15 -0
- package/dist/qar/generated/qodo-task-start-payload.js.map +1 -0
- package/dist/qar/ids.d.ts +19 -0
- package/dist/qar/ids.d.ts.map +1 -0
- package/dist/qar/ids.js +11 -0
- package/dist/qar/ids.js.map +1 -0
- package/dist/qar/index.d.ts +24 -0
- package/dist/qar/index.d.ts.map +1 -0
- package/dist/qar/index.js +16 -0
- package/dist/qar/index.js.map +1 -0
- package/dist/qar/info.d.ts +37 -0
- package/dist/qar/info.d.ts.map +1 -0
- package/dist/qar/info.js +17 -0
- package/dist/qar/info.js.map +1 -0
- package/dist/qar/json.d.ts +14 -0
- package/dist/qar/json.d.ts.map +1 -0
- package/dist/qar/json.js +9 -0
- package/dist/qar/json.js.map +1 -0
- package/dist/qar/payloads.d.ts +480 -0
- package/dist/qar/payloads.d.ts.map +1 -0
- package/dist/qar/payloads.js +37 -0
- package/dist/qar/payloads.js.map +1 -0
- package/dist/qar/specs.d.ts +604 -0
- package/dist/qar/specs.d.ts.map +1 -0
- package/dist/qar/specs.js +29 -0
- package/dist/qar/specs.js.map +1 -0
- package/dist/qar/taskEvents.d.ts +25 -0
- package/dist/qar/taskEvents.d.ts.map +1 -0
- package/dist/qar/taskEvents.js +22 -0
- package/dist/qar/taskEvents.js.map +1 -0
- package/dist/qar/trace.d.ts +12 -0
- package/dist/qar/trace.d.ts.map +1 -0
- package/dist/qar/trace.js +12 -0
- package/dist/qar/trace.js.map +1 -0
- package/dist/skills/activation.d.ts +177 -0
- package/dist/skills/activation.d.ts.map +1 -0
- package/dist/skills/activation.js +428 -0
- package/dist/skills/activation.js.map +1 -0
- package/dist/skills/cli/index.browser.d.ts +18 -0
- package/dist/skills/cli/index.browser.d.ts.map +1 -0
- package/dist/skills/cli/index.browser.js +27 -0
- package/dist/skills/cli/index.browser.js.map +1 -0
- package/dist/skills/cli/index.d.ts +37 -0
- package/dist/skills/cli/index.d.ts.map +1 -0
- package/dist/skills/cli/index.js +494 -0
- package/dist/skills/cli/index.js.map +1 -0
- package/dist/skills/events.d.ts +255 -0
- package/dist/skills/events.d.ts.map +1 -0
- package/dist/skills/events.js +224 -0
- package/dist/skills/events.js.map +1 -0
- package/dist/skills/index.d.ts +45 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +34 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/inject.d.ts +57 -0
- package/dist/skills/inject.d.ts.map +1 -0
- package/dist/skills/inject.js +162 -0
- package/dist/skills/inject.js.map +1 -0
- package/dist/skills/lockfile.browser.d.ts +56 -0
- package/dist/skills/lockfile.browser.d.ts.map +1 -0
- package/dist/skills/lockfile.browser.js +55 -0
- package/dist/skills/lockfile.browser.js.map +1 -0
- package/dist/skills/lockfile.d.ts +137 -0
- package/dist/skills/lockfile.d.ts.map +1 -0
- package/dist/skills/lockfile.js +423 -0
- package/dist/skills/lockfile.js.map +1 -0
- package/dist/skills/manager.browser.d.ts +94 -0
- package/dist/skills/manager.browser.d.ts.map +1 -0
- package/dist/skills/manager.browser.js +159 -0
- package/dist/skills/manager.browser.js.map +1 -0
- package/dist/skills/manager.d.ts +362 -0
- package/dist/skills/manager.d.ts.map +1 -0
- package/dist/skills/manager.js +1386 -0
- package/dist/skills/manager.js.map +1 -0
- package/dist/skills/mcp/index.d.ts +15 -0
- package/dist/skills/mcp/index.d.ts.map +1 -0
- package/dist/skills/mcp/index.js +12 -0
- package/dist/skills/mcp/index.js.map +1 -0
- package/dist/skills/mcp/path.browser.d.ts +27 -0
- package/dist/skills/mcp/path.browser.d.ts.map +1 -0
- package/dist/skills/mcp/path.browser.js +33 -0
- package/dist/skills/mcp/path.browser.js.map +1 -0
- package/dist/skills/mcp/path.d.ts +57 -0
- package/dist/skills/mcp/path.d.ts.map +1 -0
- package/dist/skills/mcp/path.js +150 -0
- package/dist/skills/mcp/path.js.map +1 -0
- package/dist/skills/mcp/server.browser.d.ts +32 -0
- package/dist/skills/mcp/server.browser.d.ts.map +1 -0
- package/dist/skills/mcp/server.browser.js +53 -0
- package/dist/skills/mcp/server.browser.js.map +1 -0
- package/dist/skills/mcp/server.d.ts +144 -0
- package/dist/skills/mcp/server.d.ts.map +1 -0
- package/dist/skills/mcp/server.js +841 -0
- package/dist/skills/mcp/server.js.map +1 -0
- package/dist/skills/mcp/types.d.ts +72 -0
- package/dist/skills/mcp/types.d.ts.map +1 -0
- package/dist/skills/mcp/types.js +20 -0
- package/dist/skills/mcp/types.js.map +1 -0
- package/dist/skills/mcp/wireDefs.d.ts +58 -0
- package/dist/skills/mcp/wireDefs.d.ts.map +1 -0
- package/dist/skills/mcp/wireDefs.js +141 -0
- package/dist/skills/mcp/wireDefs.js.map +1 -0
- package/dist/skills/parser.d.ts +63 -0
- package/dist/skills/parser.d.ts.map +1 -0
- package/dist/skills/parser.js +755 -0
- package/dist/skills/parser.js.map +1 -0
- package/dist/skills/prefilter.d.ts +104 -0
- package/dist/skills/prefilter.d.ts.map +1 -0
- package/dist/skills/prefilter.js +398 -0
- package/dist/skills/prefilter.js.map +1 -0
- package/dist/skills/preprocess.d.ts +169 -0
- package/dist/skills/preprocess.d.ts.map +1 -0
- package/dist/skills/preprocess.js +535 -0
- package/dist/skills/preprocess.js.map +1 -0
- package/dist/skills/render.d.ts +83 -0
- package/dist/skills/render.d.ts.map +1 -0
- package/dist/skills/render.js +397 -0
- package/dist/skills/render.js.map +1 -0
- package/dist/skills/sources/index.browser.d.ts +29 -0
- package/dist/skills/sources/index.browser.d.ts.map +1 -0
- package/dist/skills/sources/index.browser.js +16 -0
- package/dist/skills/sources/index.browser.js.map +1 -0
- package/dist/skills/sources/index.d.ts +59 -0
- package/dist/skills/sources/index.d.ts.map +1 -0
- package/dist/skills/sources/index.js +471 -0
- package/dist/skills/sources/index.js.map +1 -0
- package/dist/skills/sources/walk.browser.d.ts +17 -0
- package/dist/skills/sources/walk.browser.d.ts.map +1 -0
- package/dist/skills/sources/walk.browser.js +19 -0
- package/dist/skills/sources/walk.browser.js.map +1 -0
- package/dist/skills/sources/walk.d.ts +68 -0
- package/dist/skills/sources/walk.d.ts.map +1 -0
- package/dist/skills/sources/walk.js +264 -0
- package/dist/skills/sources/walk.js.map +1 -0
- package/dist/skills/substitute.d.ts +87 -0
- package/dist/skills/substitute.d.ts.map +1 -0
- package/dist/skills/substitute.js +322 -0
- package/dist/skills/substitute.js.map +1 -0
- package/dist/skills/testing/SkillKit.browser.d.ts +62 -0
- package/dist/skills/testing/SkillKit.browser.d.ts.map +1 -0
- package/dist/skills/testing/SkillKit.browser.js +41 -0
- package/dist/skills/testing/SkillKit.browser.js.map +1 -0
- package/dist/skills/testing/SkillKit.d.ts +130 -0
- package/dist/skills/testing/SkillKit.d.ts.map +1 -0
- package/dist/skills/testing/SkillKit.js +316 -0
- package/dist/skills/testing/SkillKit.js.map +1 -0
- package/dist/skills/testing/index.d.ts +9 -0
- package/dist/skills/testing/index.d.ts.map +1 -0
- package/dist/skills/testing/index.js +8 -0
- package/dist/skills/testing/index.js.map +1 -0
- package/dist/skills/trust.d.ts +72 -0
- package/dist/skills/trust.d.ts.map +1 -0
- package/dist/skills/trust.js +183 -0
- package/dist/skills/trust.js.map +1 -0
- package/dist/skills/types.d.ts +627 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +85 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/skills/validator.d.ts +95 -0
- package/dist/skills/validator.d.ts.map +1 -0
- package/dist/skills/validator.js +486 -0
- package/dist/skills/validator.js.map +1 -0
- package/dist/tracing/PipelineTracer.d.ts +35 -22
- package/dist/tracing/PipelineTracer.d.ts.map +1 -1
- package/dist/tracing/PipelineTracer.js +106 -61
- package/dist/tracing/PipelineTracer.js.map +1 -1
- package/dist/tracing/SdkTracer.d.ts +63 -61
- package/dist/tracing/SdkTracer.d.ts.map +1 -1
- package/dist/tracing/SdkTracer.js +185 -177
- package/dist/tracing/SdkTracer.js.map +1 -1
- package/dist/tracing/index.d.ts +10 -1
- package/dist/tracing/index.d.ts.map +1 -1
- package/dist/tracing/index.js +9 -0
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/types.d.ts +89 -16
- package/dist/tracing/types.d.ts.map +1 -1
- package/dist/tracing/types.js +17 -4
- package/dist/tracing/types.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +10 -20
- package/dist/version.js.map +1 -1
- package/package.json +53 -39
- package/.claude/skills/qodo-agent/SKILL.md +0 -974
- package/.claude/skills/qodo-agent/assets/programmatic-agent.ts +0 -407
- package/.claude/skills/qodo-agent/references/builtin-tools.md +0 -342
- package/.claude/skills/qodo-agent/references/common-issues.md +0 -537
- package/bin/rg +0 -0
- package/dist/api/agent.d.ts +0 -105
- package/dist/api/agent.d.ts.map +0 -1
- package/dist/api/agent.js +0 -963
- package/dist/api/agent.js.map +0 -1
- package/dist/api/analytics.d.ts +0 -43
- package/dist/api/analytics.d.ts.map +0 -1
- package/dist/api/analytics.js +0 -163
- package/dist/api/analytics.js.map +0 -1
- package/dist/api/http.d.ts +0 -5
- package/dist/api/http.d.ts.map +0 -1
- package/dist/api/http.js +0 -62
- package/dist/api/http.js.map +0 -1
- package/dist/api/index.d.ts +0 -12
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -17
- package/dist/api/index.js.map +0 -1
- package/dist/api/taskTracking.d.ts +0 -54
- package/dist/api/taskTracking.d.ts.map +0 -1
- package/dist/api/taskTracking.js +0 -208
- package/dist/api/taskTracking.js.map +0 -1
- package/dist/api/types.d.ts +0 -93
- package/dist/api/types.d.ts.map +0 -1
- package/dist/api/types.js +0 -2
- package/dist/api/types.js.map +0 -1
- package/dist/api/utils.d.ts +0 -8
- package/dist/api/utils.d.ts.map +0 -1
- package/dist/api/utils.js +0 -63
- package/dist/api/utils.js.map +0 -1
- package/dist/api/websocket.d.ts +0 -203
- package/dist/api/websocket.d.ts.map +0 -1
- package/dist/api/websocket.js +0 -1166
- package/dist/api/websocket.js.map +0 -1
- package/dist/bin/install-skill.d.ts +0 -14
- package/dist/bin/install-skill.d.ts.map +0 -1
- package/dist/bin/install-skill.js +0 -125
- package/dist/bin/install-skill.js.map +0 -1
- package/dist/bin/run-helpers.d.ts +0 -34
- package/dist/bin/run-helpers.d.ts.map +0 -1
- package/dist/bin/run-helpers.js +0 -186
- package/dist/bin/run-helpers.js.map +0 -1
- package/dist/bin/run.d.ts +0 -13
- package/dist/bin/run.d.ts.map +0 -1
- package/dist/bin/run.js +0 -57
- package/dist/bin/run.js.map +0 -1
- package/dist/clients/index.d.ts +0 -10
- package/dist/clients/index.d.ts.map +0 -1
- package/dist/clients/index.js +0 -8
- package/dist/clients/index.js.map +0 -1
- package/dist/clients/info/InfoClient.d.ts +0 -37
- package/dist/clients/info/InfoClient.d.ts.map +0 -1
- package/dist/clients/info/InfoClient.js +0 -69
- package/dist/clients/info/InfoClient.js.map +0 -1
- package/dist/clients/info/index.d.ts +0 -4
- package/dist/clients/info/index.d.ts.map +0 -1
- package/dist/clients/info/index.js +0 -2
- package/dist/clients/info/index.js.map +0 -1
- package/dist/clients/info/types.d.ts +0 -21
- package/dist/clients/info/types.d.ts.map +0 -1
- package/dist/clients/info/types.js +0 -2
- package/dist/clients/info/types.js.map +0 -1
- package/dist/clients/sessions/SessionsClient.d.ts +0 -34
- package/dist/clients/sessions/SessionsClient.d.ts.map +0 -1
- package/dist/clients/sessions/SessionsClient.js +0 -71
- package/dist/clients/sessions/SessionsClient.js.map +0 -1
- package/dist/clients/sessions/index.d.ts +0 -4
- package/dist/clients/sessions/index.d.ts.map +0 -1
- package/dist/clients/sessions/index.js +0 -2
- package/dist/clients/sessions/index.js.map +0 -1
- package/dist/clients/sessions/types.d.ts +0 -20
- package/dist/clients/sessions/types.d.ts.map +0 -1
- package/dist/clients/sessions/types.js +0 -2
- package/dist/clients/sessions/types.js.map +0 -1
- package/dist/clients/tools/ToolsClient.d.ts +0 -39
- package/dist/clients/tools/ToolsClient.d.ts.map +0 -1
- package/dist/clients/tools/ToolsClient.js +0 -95
- package/dist/clients/tools/ToolsClient.js.map +0 -1
- package/dist/clients/tools/index.d.ts +0 -4
- package/dist/clients/tools/index.d.ts.map +0 -1
- package/dist/clients/tools/index.js +0 -2
- package/dist/clients/tools/index.js.map +0 -1
- package/dist/clients/tools/types.d.ts +0 -14
- package/dist/clients/tools/types.d.ts.map +0 -1
- package/dist/clients/tools/types.js +0 -2
- package/dist/clients/tools/types.js.map +0 -1
- package/dist/config/ConfigManager.d.ts +0 -43
- package/dist/config/ConfigManager.d.ts.map +0 -1
- package/dist/config/ConfigManager.js +0 -472
- package/dist/config/ConfigManager.js.map +0 -1
- package/dist/config/index.d.ts +0 -6
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -7
- package/dist/config/index.js.map +0 -1
- package/dist/config/urlConfig.d.ts +0 -15
- package/dist/config/urlConfig.d.ts.map +0 -1
- package/dist/config/urlConfig.js +0 -75
- package/dist/config/urlConfig.js.map +0 -1
- package/dist/constants/errors.d.ts +0 -2
- package/dist/constants/errors.d.ts.map +0 -1
- package/dist/constants/errors.js +0 -2
- package/dist/constants/errors.js.map +0 -1
- package/dist/constants/index.d.ts +0 -7
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js +0 -11
- package/dist/constants/index.js.map +0 -1
- package/dist/constants/tools.d.ts +0 -4
- package/dist/constants/tools.d.ts.map +0 -1
- package/dist/constants/tools.js +0 -4
- package/dist/constants/tools.js.map +0 -1
- package/dist/constants/versions.d.ts +0 -2
- package/dist/constants/versions.d.ts.map +0 -1
- package/dist/constants/versions.js +0 -2
- package/dist/constants/versions.js.map +0 -1
- package/dist/context/buildUserContext.d.ts +0 -18
- package/dist/context/buildUserContext.d.ts.map +0 -1
- package/dist/context/buildUserContext.js +0 -34
- package/dist/context/buildUserContext.js.map +0 -1
- package/dist/context/index.d.ts +0 -9
- package/dist/context/index.d.ts.map +0 -1
- package/dist/context/index.js +0 -9
- package/dist/context/index.js.map +0 -1
- package/dist/context/messageManager.d.ts +0 -42
- package/dist/context/messageManager.d.ts.map +0 -1
- package/dist/context/messageManager.js +0 -322
- package/dist/context/messageManager.js.map +0 -1
- package/dist/context/taskFocus.d.ts +0 -2
- package/dist/context/taskFocus.d.ts.map +0 -1
- package/dist/context/taskFocus.js +0 -26
- package/dist/context/taskFocus.js.map +0 -1
- package/dist/context/userInput.d.ts +0 -3
- package/dist/context/userInput.d.ts.map +0 -1
- package/dist/context/userInput.js +0 -20
- package/dist/context/userInput.js.map +0 -1
- package/dist/mcp/MCPManager.d.ts +0 -109
- package/dist/mcp/MCPManager.d.ts.map +0 -1
- package/dist/mcp/MCPManager.js +0 -592
- package/dist/mcp/MCPManager.js.map +0 -1
- package/dist/mcp/approvedTools.d.ts +0 -4
- package/dist/mcp/approvedTools.d.ts.map +0 -1
- package/dist/mcp/approvedTools.js +0 -19
- package/dist/mcp/approvedTools.js.map +0 -1
- package/dist/mcp/baseServer.d.ts +0 -75
- package/dist/mcp/baseServer.d.ts.map +0 -1
- package/dist/mcp/baseServer.js +0 -107
- package/dist/mcp/baseServer.js.map +0 -1
- package/dist/mcp/builtinServers.d.ts +0 -15
- package/dist/mcp/builtinServers.d.ts.map +0 -1
- package/dist/mcp/builtinServers.js +0 -141
- package/dist/mcp/builtinServers.js.map +0 -1
- package/dist/mcp/dynamicBEServer.d.ts +0 -20
- package/dist/mcp/dynamicBEServer.d.ts.map +0 -1
- package/dist/mcp/dynamicBEServer.js +0 -52
- package/dist/mcp/dynamicBEServer.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -18
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -23
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/mcpInitialization.d.ts +0 -2
- package/dist/mcp/mcpInitialization.d.ts.map +0 -1
- package/dist/mcp/mcpInitialization.js +0 -56
- package/dist/mcp/mcpInitialization.js.map +0 -1
- package/dist/mcp/servers/filesystem.d.ts +0 -44
- package/dist/mcp/servers/filesystem.d.ts.map +0 -1
- package/dist/mcp/servers/filesystem.js +0 -776
- package/dist/mcp/servers/filesystem.js.map +0 -1
- package/dist/mcp/servers/git.d.ts +0 -18
- package/dist/mcp/servers/git.d.ts.map +0 -1
- package/dist/mcp/servers/git.js +0 -441
- package/dist/mcp/servers/git.js.map +0 -1
- package/dist/mcp/servers/ripgrep.d.ts +0 -39
- package/dist/mcp/servers/ripgrep.d.ts.map +0 -1
- package/dist/mcp/servers/ripgrep.js +0 -550
- package/dist/mcp/servers/ripgrep.js.map +0 -1
- package/dist/mcp/servers/shell.d.ts +0 -20
- package/dist/mcp/servers/shell.d.ts.map +0 -1
- package/dist/mcp/servers/shell.js +0 -519
- package/dist/mcp/servers/shell.js.map +0 -1
- package/dist/mcp/serversRegistry.d.ts +0 -55
- package/dist/mcp/serversRegistry.d.ts.map +0 -1
- package/dist/mcp/serversRegistry.js +0 -416
- package/dist/mcp/serversRegistry.js.map +0 -1
- package/dist/mcp/toolProcessor.d.ts +0 -82
- package/dist/mcp/toolProcessor.d.ts.map +0 -1
- package/dist/mcp/toolProcessor.js +0 -392
- package/dist/mcp/toolProcessor.js.map +0 -1
- package/dist/mcp/types.d.ts +0 -29
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/mcp/types.js +0 -2
- package/dist/mcp/types.js.map +0 -1
- package/dist/messages/index.d.ts +0 -8
- package/dist/messages/index.d.ts.map +0 -1
- package/dist/messages/index.js +0 -7
- package/dist/messages/index.js.map +0 -1
- package/dist/messages/openai.d.ts +0 -26
- package/dist/messages/openai.d.ts.map +0 -1
- package/dist/messages/openai.js +0 -55
- package/dist/messages/openai.js.map +0 -1
- package/dist/messages/types.d.ts +0 -73
- package/dist/messages/types.d.ts.map +0 -1
- package/dist/messages/types.js +0 -78
- package/dist/messages/types.js.map +0 -1
- package/dist/parser/index.d.ts +0 -72
- package/dist/parser/index.d.ts.map +0 -1
- package/dist/parser/index.js +0 -967
- package/dist/parser/index.js.map +0 -1
- package/dist/parser/types.d.ts +0 -153
- package/dist/parser/types.d.ts.map +0 -1
- package/dist/parser/types.js +0 -6
- package/dist/parser/types.js.map +0 -1
- package/dist/parser/utils.d.ts +0 -18
- package/dist/parser/utils.d.ts.map +0 -1
- package/dist/parser/utils.js +0 -64
- package/dist/parser/utils.js.map +0 -1
- package/dist/sdk/QodoSDK.d.ts +0 -218
- package/dist/sdk/QodoSDK.d.ts.map +0 -1
- package/dist/sdk/QodoSDK.js +0 -1115
- package/dist/sdk/QodoSDK.js.map +0 -1
- package/dist/sdk/artifacts.d.ts +0 -156
- package/dist/sdk/artifacts.d.ts.map +0 -1
- package/dist/sdk/artifacts.js +0 -166
- package/dist/sdk/artifacts.js.map +0 -1
- package/dist/sdk/bootstrap.d.ts +0 -16
- package/dist/sdk/bootstrap.d.ts.map +0 -1
- package/dist/sdk/bootstrap.js +0 -28
- package/dist/sdk/bootstrap.js.map +0 -1
- package/dist/sdk/builders.d.ts +0 -54
- package/dist/sdk/builders.d.ts.map +0 -1
- package/dist/sdk/builders.js +0 -117
- package/dist/sdk/builders.js.map +0 -1
- package/dist/sdk/defaults.d.ts +0 -11
- package/dist/sdk/defaults.d.ts.map +0 -1
- package/dist/sdk/defaults.js +0 -39
- package/dist/sdk/defaults.js.map +0 -1
- package/dist/sdk/discovery.d.ts +0 -2
- package/dist/sdk/discovery.d.ts.map +0 -1
- package/dist/sdk/discovery.js +0 -25
- package/dist/sdk/discovery.js.map +0 -1
- package/dist/sdk/events.d.ts +0 -269
- package/dist/sdk/events.d.ts.map +0 -1
- package/dist/sdk/events.js +0 -69
- package/dist/sdk/events.js.map +0 -1
- package/dist/sdk/exit-expression.d.ts +0 -13
- package/dist/sdk/exit-expression.d.ts.map +0 -1
- package/dist/sdk/exit-expression.js +0 -35
- package/dist/sdk/exit-expression.js.map +0 -1
- package/dist/sdk/index.d.ts +0 -17
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js +0 -17
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/middleware.d.ts +0 -59
- package/dist/sdk/middleware.d.ts.map +0 -1
- package/dist/sdk/middleware.js +0 -69
- package/dist/sdk/middleware.js.map +0 -1
- package/dist/sdk/pipeline/PipelineBuilder.d.ts +0 -79
- package/dist/sdk/pipeline/PipelineBuilder.d.ts.map +0 -1
- package/dist/sdk/pipeline/PipelineBuilder.js +0 -129
- package/dist/sdk/pipeline/PipelineBuilder.js.map +0 -1
- package/dist/sdk/pipeline/PipelineRunner.d.ts +0 -28
- package/dist/sdk/pipeline/PipelineRunner.d.ts.map +0 -1
- package/dist/sdk/pipeline/PipelineRunner.js +0 -326
- package/dist/sdk/pipeline/PipelineRunner.js.map +0 -1
- package/dist/sdk/pipeline/compiler.d.ts +0 -24
- package/dist/sdk/pipeline/compiler.d.ts.map +0 -1
- package/dist/sdk/pipeline/compiler.js +0 -199
- package/dist/sdk/pipeline/compiler.js.map +0 -1
- package/dist/sdk/pipeline/declarative.d.ts +0 -34
- package/dist/sdk/pipeline/declarative.d.ts.map +0 -1
- package/dist/sdk/pipeline/declarative.js +0 -9
- package/dist/sdk/pipeline/declarative.js.map +0 -1
- package/dist/sdk/pipeline/index.d.ts +0 -20
- package/dist/sdk/pipeline/index.d.ts.map +0 -1
- package/dist/sdk/pipeline/index.js +0 -19
- package/dist/sdk/pipeline/index.js.map +0 -1
- package/dist/sdk/pipeline/types.d.ts +0 -93
- package/dist/sdk/pipeline/types.d.ts.map +0 -1
- package/dist/sdk/pipeline/types.js +0 -10
- package/dist/sdk/pipeline/types.js.map +0 -1
- package/dist/sdk/policies.d.ts +0 -163
- package/dist/sdk/policies.d.ts.map +0 -1
- package/dist/sdk/policies.js +0 -243
- package/dist/sdk/policies.js.map +0 -1
- package/dist/sdk/runner/AgentRunner.d.ts +0 -22
- package/dist/sdk/runner/AgentRunner.d.ts.map +0 -1
- package/dist/sdk/runner/AgentRunner.js +0 -222
- package/dist/sdk/runner/AgentRunner.js.map +0 -1
- package/dist/sdk/runner/finalize.d.ts +0 -56
- package/dist/sdk/runner/finalize.d.ts.map +0 -1
- package/dist/sdk/runner/finalize.js +0 -155
- package/dist/sdk/runner/finalize.js.map +0 -1
- package/dist/sdk/runner/formats.d.ts +0 -7
- package/dist/sdk/runner/formats.d.ts.map +0 -1
- package/dist/sdk/runner/formats.js +0 -76
- package/dist/sdk/runner/formats.js.map +0 -1
- package/dist/sdk/runner/index.d.ts +0 -9
- package/dist/sdk/runner/index.d.ts.map +0 -1
- package/dist/sdk/runner/index.js +0 -9
- package/dist/sdk/runner/index.js.map +0 -1
- package/dist/sdk/runner/progress.d.ts +0 -3
- package/dist/sdk/runner/progress.d.ts.map +0 -1
- package/dist/sdk/runner/progress.js +0 -16
- package/dist/sdk/runner/progress.js.map +0 -1
- package/dist/sdk/schemas.d.ts +0 -72
- package/dist/sdk/schemas.d.ts.map +0 -1
- package/dist/sdk/schemas.js +0 -282
- package/dist/sdk/schemas.js.map +0 -1
- package/dist/sdk/trigger-context.d.ts +0 -24
- package/dist/sdk/trigger-context.d.ts.map +0 -1
- package/dist/sdk/trigger-context.js +0 -136
- package/dist/sdk/trigger-context.js.map +0 -1
- package/dist/session/SessionContext.d.ts +0 -89
- package/dist/session/SessionContext.d.ts.map +0 -1
- package/dist/session/SessionContext.js +0 -410
- package/dist/session/SessionContext.js.map +0 -1
- package/dist/session/environment.d.ts +0 -52
- package/dist/session/environment.d.ts.map +0 -1
- package/dist/session/environment.js +0 -27
- package/dist/session/environment.js.map +0 -1
- package/dist/session/history.d.ts +0 -18
- package/dist/session/history.d.ts.map +0 -1
- package/dist/session/history.js +0 -68
- package/dist/session/history.js.map +0 -1
- package/dist/session/index.d.ts +0 -10
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -9
- package/dist/session/index.js.map +0 -1
- package/dist/session/serverData.d.ts +0 -38
- package/dist/session/serverData.d.ts.map +0 -1
- package/dist/session/serverData.js +0 -261
- package/dist/session/serverData.js.map +0 -1
- package/dist/tracing/pipelineHelpers.d.ts +0 -29
- package/dist/tracing/pipelineHelpers.d.ts.map +0 -1
- package/dist/tracing/pipelineHelpers.js +0 -224
- package/dist/tracing/pipelineHelpers.js.map +0 -1
- package/dist/tracking/Tracker.d.ts +0 -55
- package/dist/tracking/Tracker.d.ts.map +0 -1
- package/dist/tracking/Tracker.js +0 -217
- package/dist/tracking/Tracker.js.map +0 -1
- package/dist/tracking/index.d.ts +0 -8
- package/dist/tracking/index.d.ts.map +0 -1
- package/dist/tracking/index.js +0 -8
- package/dist/tracking/index.js.map +0 -1
- package/dist/tracking/schemas.d.ts +0 -292
- package/dist/tracking/schemas.d.ts.map +0 -1
- package/dist/tracking/schemas.js +0 -91
- package/dist/tracking/schemas.js.map +0 -1
- package/dist/utils/extractSetFlags.d.ts +0 -6
- package/dist/utils/extractSetFlags.d.ts.map +0 -1
- package/dist/utils/extractSetFlags.js +0 -16
- package/dist/utils/extractSetFlags.js.map +0 -1
- package/dist/utils/formatTimeAgo.d.ts +0 -2
- package/dist/utils/formatTimeAgo.d.ts.map +0 -1
- package/dist/utils/formatTimeAgo.js +0 -20
- package/dist/utils/formatTimeAgo.js.map +0 -1
- package/dist/utils/index.d.ts +0 -12
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -12
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/machineId.d.ts +0 -14
- package/dist/utils/machineId.d.ts.map +0 -1
- package/dist/utils/machineId.js +0 -66
- package/dist/utils/machineId.js.map +0 -1
- package/dist/utils/pathUtils.d.ts +0 -22
- package/dist/utils/pathUtils.d.ts.map +0 -1
- package/dist/utils/pathUtils.js +0 -54
- package/dist/utils/pathUtils.js.map +0 -1
- package/scripts/download-ripgrep.js +0 -269
package/dist/api/agent.js
DELETED
|
@@ -1,963 +0,0 @@
|
|
|
1
|
-
import { v4 as uuid } from "uuid";
|
|
2
|
-
import { EventEmitter } from "events";
|
|
3
|
-
import { MCPManager } from "../mcp/index.js";
|
|
4
|
-
import { SERVER_ERROR_MESSAGE } from "../constants/errors.js";
|
|
5
|
-
import { getUserData, getCurrentGitSha1 } from "./utils.js";
|
|
6
|
-
import { EndNode, UserResponse } from "../constants/tools.js";
|
|
7
|
-
import { SessionContext } from "../session/index.js";
|
|
8
|
-
import { TaskTracker } from "./taskTracking.js";
|
|
9
|
-
import { ToolProcessorManager } from "../mcp/index.js";
|
|
10
|
-
import process from "node:process";
|
|
11
|
-
import { ServerData } from "../session/index.js";
|
|
12
|
-
import { httpRequest } from "./http.js";
|
|
13
|
-
import { WebSocketClient, ConnectionState } from "./websocket.js";
|
|
14
|
-
import { getCurrentEnvironment } from "../session/index.js";
|
|
15
|
-
// Enhanced configuration with robust defaults
|
|
16
|
-
const CONFIG = {
|
|
17
|
-
REQUEST_TIMEOUT: 210000,
|
|
18
|
-
DELIMITER: "\n\n",
|
|
19
|
-
RECONNECT_ATTEMPTS: 5, // Increased from 3
|
|
20
|
-
INITIAL_RECONNECT_DELAY: 1000,
|
|
21
|
-
MAX_RECONNECT_DELAY: 30000, // Maximum 30 seconds
|
|
22
|
-
RECONNECT_BACKOFF_FACTOR: 1.5, // Exponential backoff multiplier
|
|
23
|
-
HEARTBEAT_INTERVAL: 30000,
|
|
24
|
-
HEARTBEAT_TIMEOUT: 60000, // 2x heartbeat interval
|
|
25
|
-
CONNECTION_TIMEOUT: 15000, // Increased from 10s
|
|
26
|
-
MESSAGE_QUEUE_MAX_SIZE: 1000,
|
|
27
|
-
MAX_PENDING_TOOLS: 50,
|
|
28
|
-
CIRCUIT_BREAKER_THRESHOLD: 5, // Failures before opening circuit
|
|
29
|
-
CIRCUIT_BREAKER_TIMEOUT: 60000, // 1 minute before trying again
|
|
30
|
-
IDLE_TIMEOUT: 60000, // 1 minute idle timeout before disconnecting
|
|
31
|
-
SUMMARIZATION_PREFETCH_TIMEOUT: 60000, // 60 seconds for summarization prefetch
|
|
32
|
-
};
|
|
33
|
-
export class AgentAPI extends EventEmitter {
|
|
34
|
-
sessionContext;
|
|
35
|
-
wsClient;
|
|
36
|
-
shouldDebugLog() {
|
|
37
|
-
const env = getCurrentEnvironment();
|
|
38
|
-
if (env?.sdkMode) {
|
|
39
|
-
return !!env.sdkDebug || process.env.QODO_DEBUG === 'true';
|
|
40
|
-
}
|
|
41
|
-
return this.sessionContext?.isDebugMode?.() || process.env.QODO_DEBUG === 'true';
|
|
42
|
-
}
|
|
43
|
-
debug(...args) {
|
|
44
|
-
if (this.shouldDebugLog()) {
|
|
45
|
-
// eslint-disable-next-line no-console
|
|
46
|
-
console.debug(...args);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
currentSession;
|
|
50
|
-
pendingToolRequests = new Map();
|
|
51
|
-
// Tracks tool executions that are currently running (mainly relevant for auto-approved tools).
|
|
52
|
-
// Without this, the backend "Ready" signal can be misinterpreted as end-of-turn and we may
|
|
53
|
-
// emit forceStop early, which causes the CLI loading spinner to disappear while tools are still running.
|
|
54
|
-
inFlightToolCalls = new Set();
|
|
55
|
-
// Tracks tool_call_ids whose `IDERetrievalAnswer` has already been sent (or at
|
|
56
|
-
// least queued to the outbox). Used to dedupe backend re-emits of the same
|
|
57
|
-
// `ToolRequested` on Resume: if the original envelope survived the drop, the
|
|
58
|
-
// client already executed the tool; re-executing a non-idempotent MCP tool
|
|
59
|
-
// (e.g. `create_pull_request`) a second time would be a real bug.
|
|
60
|
-
answeredToolCalls = new Set();
|
|
61
|
-
latestSessionId = "";
|
|
62
|
-
lastToolId = "";
|
|
63
|
-
mcpManager;
|
|
64
|
-
taskTracker;
|
|
65
|
-
pendingResumeError = null;
|
|
66
|
-
userHasControl = false; // Track if user has control (editor is shown)
|
|
67
|
-
// Tracks the current message processing promise to avoid race conditions between
|
|
68
|
-
// message processing and Ready signal handling. Without this, the Ready signal can
|
|
69
|
-
// trigger finalization before structured_output messages are fully processed.
|
|
70
|
-
currentMessageProcessing = null;
|
|
71
|
-
constructor(sessionContext) {
|
|
72
|
-
super();
|
|
73
|
-
this.sessionContext = sessionContext;
|
|
74
|
-
this.sessionContext = sessionContext || SessionContext.getInstance();
|
|
75
|
-
// MCPManager may not be initialized when MCP is disabled via config (tools = []).
|
|
76
|
-
// In that case, gracefully operate without tools by leaving mcpManager undefined.
|
|
77
|
-
try {
|
|
78
|
-
this.mcpManager = MCPManager.getInstance();
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
this.mcpManager = undefined;
|
|
82
|
-
}
|
|
83
|
-
this.taskTracker = new TaskTracker(this.sessionContext, this.mcpManager);
|
|
84
|
-
// Initialize WebSocket client
|
|
85
|
-
this.wsClient = new WebSocketClient();
|
|
86
|
-
this.setupWebSocketHandlers();
|
|
87
|
-
// Don't pre-fetch session ID - use the session ID provided by operations
|
|
88
|
-
// Listen for network connectivity changes if available
|
|
89
|
-
this.setupNetworkListeners();
|
|
90
|
-
}
|
|
91
|
-
async ensureConnected(sessionId, requestId) {
|
|
92
|
-
try {
|
|
93
|
-
let finalSessionId = sessionId;
|
|
94
|
-
// Only fetch a session ID from server if none is provided
|
|
95
|
-
if (!finalSessionId) {
|
|
96
|
-
if (!this.latestSessionId) {
|
|
97
|
-
const serverData = ServerData.getInstance();
|
|
98
|
-
this.latestSessionId = await serverData.fetchNewSessionId();
|
|
99
|
-
this.debug(`Fetched new session ID from server: ${this.latestSessionId}`);
|
|
100
|
-
}
|
|
101
|
-
finalSessionId = this.latestSessionId;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// Update stored session ID with the provided one
|
|
105
|
-
this.latestSessionId = sessionId;
|
|
106
|
-
}
|
|
107
|
-
await this.wsClient.connect(finalSessionId, requestId);
|
|
108
|
-
this.debug('WebSocket connected for session:', finalSessionId);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
this.debug('WebSocket connection failed:', error);
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
setupWebSocketHandlers() {
|
|
116
|
-
// Handle incoming messages
|
|
117
|
-
// IMPORTANT: Track the promise to ensure message processing completes before
|
|
118
|
-
// Ready signal triggers finalization. This prevents race conditions where
|
|
119
|
-
// structured_output messages are received but not yet processed when Ready arrives.
|
|
120
|
-
this.wsClient.on('message', (message) => {
|
|
121
|
-
this.currentMessageProcessing = this.handleWebSocketMessage(message).finally(() => {
|
|
122
|
-
this.currentMessageProcessing = null;
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
// Handle connection state changes
|
|
126
|
-
this.wsClient.on('stateChanged', (newState) => {
|
|
127
|
-
this.debug('WebSocket state changed to:', newState);
|
|
128
|
-
this.emit('connectionStateChanged', newState);
|
|
129
|
-
});
|
|
130
|
-
this.wsClient.on('disconnected', (info) => {
|
|
131
|
-
this.debug('WebSocket disconnected:', info.reason);
|
|
132
|
-
// Handle pending operations
|
|
133
|
-
if (info.reason !== 'idle' && info.reason !== 'normal') {
|
|
134
|
-
this.handleUnexpectedDisconnection();
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
this.wsClient.on('error', (error) => {
|
|
138
|
-
this.debug('WebSocket error:', error);
|
|
139
|
-
this.handleWebSocketError(error);
|
|
140
|
-
});
|
|
141
|
-
// Handle Ready protocol events
|
|
142
|
-
this.wsClient.on('readyReceived', async (checkpointId, previousReadyState) => {
|
|
143
|
-
this.debug('[AgentAPI] Server ready for next message', checkpointId ? `| Checkpoint: ${checkpointId.substring(0, 8)}` : '');
|
|
144
|
-
// IMPORTANT:
|
|
145
|
-
// Some backend flows may not emit an explicit EndNode/forceStop message.
|
|
146
|
-
// Historically we treated the WebSocket "Ready" signal as an end-of-turn indicator.
|
|
147
|
-
// However, during tool-use the backend may send "Ready" to signal it is ready to receive
|
|
148
|
-
// tool answers (IDERetrievalAnswer) rather than the assistant being done producing output.
|
|
149
|
-
//
|
|
150
|
-
// To avoid prematurely finalizing runs (especially with YOLO/always where tools are auto-approved),
|
|
151
|
-
// we apply a stricter heuristic:
|
|
152
|
-
// - only finalize when Ready arrives after a UserQuery (MESSAGE_SENT)
|
|
153
|
-
// - AND there are no approval prompts pending
|
|
154
|
-
// - AND there are no tool executions currently in-flight (auto-approved tools)
|
|
155
|
-
// - AND the WebSocket client has observed at least one non-Ready response since the UserQuery
|
|
156
|
-
// (otherwise this Ready can be part of an intermediate tool handshake)
|
|
157
|
-
try {
|
|
158
|
-
// Wait for any in-flight message processing to complete before checking finalization.
|
|
159
|
-
// This prevents race conditions where structured_output messages are received but
|
|
160
|
-
// haven't been processed yet when the Ready signal arrives.
|
|
161
|
-
if (this.currentMessageProcessing) {
|
|
162
|
-
this.debug('[AgentAPI] Waiting for in-flight message processing before handling Ready');
|
|
163
|
-
await this.currentMessageProcessing;
|
|
164
|
-
}
|
|
165
|
-
// After awaiting in-flight processing, re-check the WebSocket ready state.
|
|
166
|
-
// If a tool response (IDERetrievalAnswer) was sent while we waited, the state
|
|
167
|
-
// will have transitioned back to MESSAGE_SENT — meaning we're now waiting for
|
|
168
|
-
// the backend to process the tool result and should NOT finalize.
|
|
169
|
-
const currentReadyState = this.wsClient.getReadyState?.();
|
|
170
|
-
if (currentReadyState === 'MESSAGE_SENT') {
|
|
171
|
-
this.debug('[AgentAPI] Tool response sent during wait — skipping finalization, awaiting backend response');
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const hasResponses = this.wsClient.hasReceivedResponsesSinceLastMessage?.() === true;
|
|
175
|
-
if (this.currentSession?.waitingForResponse &&
|
|
176
|
-
this.pendingToolRequests.size === 0 &&
|
|
177
|
-
this.inFlightToolCalls.size === 0 &&
|
|
178
|
-
previousReadyState === 'MESSAGE_SENT' &&
|
|
179
|
-
hasResponses) {
|
|
180
|
-
this.currentSession.waitingForResponse = false;
|
|
181
|
-
await this.responseCallback({ forceStop: true });
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
catch (readyErr) {
|
|
185
|
-
this.debug('[AgentAPI] Error during Ready handler finalization check:', readyErr);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
this.wsClient.on('checkpointRecovery', (info) => {
|
|
189
|
-
this.debug('[AgentAPI] Checkpoint recovery initiated', `| Reason: ${info.reason}`, info.checkpoint ? `| Checkpoint: ${info.checkpoint.substring(0, 8)}` : '');
|
|
190
|
-
});
|
|
191
|
-
this.wsClient.on('readyStateChanged', (info) => {
|
|
192
|
-
if (this.sessionContext?.isDebugMode()) {
|
|
193
|
-
this.debug('[AgentAPI] Ready state changed:', info);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
setupNetworkListeners() {
|
|
198
|
-
// Node.js doesn't have built-in network change detection
|
|
199
|
-
// This could be enhanced with platform-specific implementations
|
|
200
|
-
if (typeof window !== 'undefined') {
|
|
201
|
-
window.addEventListener('online', () => this.handleNetworkOnline());
|
|
202
|
-
window.addEventListener('offline', () => this.handleNetworkOffline());
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
handleNetworkOnline() {
|
|
206
|
-
this.debug('Network connectivity restored');
|
|
207
|
-
if (this.wsClient.getState() === ConnectionState.FAILED && this.currentSession) {
|
|
208
|
-
// WebSocket client will handle reconnection automatically
|
|
209
|
-
this.debug('Network restored, WebSocket client will auto-reconnect');
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
handleNetworkOffline() {
|
|
213
|
-
this.debug('Network connectivity lost');
|
|
214
|
-
// WebSocket client will detect and handle the disconnection
|
|
215
|
-
}
|
|
216
|
-
getConnectionState() {
|
|
217
|
-
return this.wsClient.getState();
|
|
218
|
-
}
|
|
219
|
-
onConnectionStateChange(callback) {
|
|
220
|
-
this.on('connectionStateChanged', callback);
|
|
221
|
-
return () => this.off('connectionStateChanged', callback);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Protocol-v2 transport metrics. Delegates to the underlying WebSocket client.
|
|
225
|
-
* Safe to call at any time; values are a point-in-time snapshot.
|
|
226
|
-
*/
|
|
227
|
-
getTransportMetrics() {
|
|
228
|
-
try {
|
|
229
|
-
return { ...(this.wsClient.getMetrics?.() ?? {}) };
|
|
230
|
-
}
|
|
231
|
-
catch {
|
|
232
|
-
return {};
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Subscribe to protocol-v2 transport lifecycle events.
|
|
237
|
-
*
|
|
238
|
-
* The SDK's own stream layer uses this to surface `Reconnecting`,
|
|
239
|
-
* `Reconnected`, `ResumeReconciled`, `ReconcileFailed`, and `StallDetected`
|
|
240
|
-
* events with proper envelopes. External callers can also subscribe for
|
|
241
|
-
* fine-grained observability without touching the WebSocketClient directly.
|
|
242
|
-
*/
|
|
243
|
-
onTransportEvent(handlers) {
|
|
244
|
-
const cleanups = [];
|
|
245
|
-
const bind = (name, fn) => {
|
|
246
|
-
if (!fn)
|
|
247
|
-
return;
|
|
248
|
-
const wrapped = (...args) => { try {
|
|
249
|
-
fn(...args);
|
|
250
|
-
}
|
|
251
|
-
catch { /* listener errors must not bubble */ } };
|
|
252
|
-
this.wsClient.on(name, wrapped);
|
|
253
|
-
cleanups.push(() => this.wsClient.off(name, wrapped));
|
|
254
|
-
};
|
|
255
|
-
bind('reconnecting', handlers.reconnecting);
|
|
256
|
-
bind('reconnected', handlers.reconnected);
|
|
257
|
-
bind('resumeAck', handlers.resumeAck);
|
|
258
|
-
bind('reconcileFailed', handlers.reconcileFailed);
|
|
259
|
-
bind('stallDetected', handlers.stallDetected);
|
|
260
|
-
return () => { for (const c of cleanups)
|
|
261
|
-
c(); };
|
|
262
|
-
}
|
|
263
|
-
handleWebSocketError(error) {
|
|
264
|
-
// Handle WebSocket errors
|
|
265
|
-
this.debug('WebSocket error handled:', error);
|
|
266
|
-
// Forward all errors during an active session - including connection failures
|
|
267
|
-
// during initial handshake (before waitingForResponse is set)
|
|
268
|
-
if (this.currentSession) {
|
|
269
|
-
this.handleError(error);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async handleUnexpectedDisconnection() {
|
|
273
|
-
try {
|
|
274
|
-
// If a tool approval is pending, keep the approval prompt active and do nothing here
|
|
275
|
-
if (this.pendingToolRequests.size > 0) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (this.currentSession?.waitingForResponse) {
|
|
279
|
-
this.currentSession.waitingForResponse = false;
|
|
280
|
-
// Finish task when returning control due to WebSocket close
|
|
281
|
-
await this.taskTracker.trackTaskFinish(false);
|
|
282
|
-
await this.responseCallback({ forceStop: true });
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
catch (e) {
|
|
286
|
-
// Best-effort; ignore errors here
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
setUserHasControl(hasControl) {
|
|
290
|
-
const previousControl = this.userHasControl;
|
|
291
|
-
this.userHasControl = hasControl;
|
|
292
|
-
if (hasControl && !previousControl) {
|
|
293
|
-
// User is getting control back - finish the current task only if there's an active tracking
|
|
294
|
-
if (this.taskTracker.hasActiveTracking()) {
|
|
295
|
-
this.taskTracker.trackTaskFinish(false).catch(error => {
|
|
296
|
-
this.debug('Error finishing task:', error);
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
// Keep WebSocket alive when user has control
|
|
300
|
-
this.wsClient.keepAlive();
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
resetActivityTimer() {
|
|
304
|
-
// Public method to keep the connection alive when user is active
|
|
305
|
-
this.wsClient.keepAlive();
|
|
306
|
-
}
|
|
307
|
-
async toolApproval(identifier, approved) {
|
|
308
|
-
const pendingToolData = this.pendingToolRequests.get(identifier);
|
|
309
|
-
if (!pendingToolData) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
// Check pending tool limits
|
|
313
|
-
if (this.pendingToolRequests.size > CONFIG.MAX_PENDING_TOOLS) {
|
|
314
|
-
this.debug(`Too many pending tools (${this.pendingToolRequests.size}), cleaning up oldest`);
|
|
315
|
-
this.cleanupOldestPendingTools();
|
|
316
|
-
}
|
|
317
|
-
this.currentSession = pendingToolData.agentSession;
|
|
318
|
-
this.currentSession.abortController = new AbortController();
|
|
319
|
-
if (approved) {
|
|
320
|
-
await this.callTool(pendingToolData.toolData);
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
await this.handleToolDecline(pendingToolData.toolData);
|
|
324
|
-
}
|
|
325
|
-
this.pendingToolRequests.delete(identifier);
|
|
326
|
-
}
|
|
327
|
-
cleanupOldestPendingTools() {
|
|
328
|
-
// Remove oldest pending tools if we exceed the limit
|
|
329
|
-
const entries = Array.from(this.pendingToolRequests.entries());
|
|
330
|
-
const toRemove = entries.slice(0, entries.length - CONFIG.MAX_PENDING_TOOLS + 10); // Remove 10 extra
|
|
331
|
-
for (const [id] of toRemove) {
|
|
332
|
-
this.pendingToolRequests.delete(id);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
async tryPrefetchSummarization(sessionIds, taskFocus) {
|
|
336
|
-
const summaries = {};
|
|
337
|
-
try {
|
|
338
|
-
if (!Array.isArray(sessionIds) || sessionIds.length === 0) {
|
|
339
|
-
return summaries;
|
|
340
|
-
}
|
|
341
|
-
await Promise.allSettled(sessionIds.map(async (sid) => {
|
|
342
|
-
try {
|
|
343
|
-
const res = await httpRequest({
|
|
344
|
-
method: "POST",
|
|
345
|
-
url: "v2/agentic/get-session-summarization",
|
|
346
|
-
data: { session_id: sid, request_id: uuid(), agent_type: "sdk", ...(taskFocus ? { task_focus: taskFocus } : {}) },
|
|
347
|
-
timeout: CONFIG.SUMMARIZATION_PREFETCH_TIMEOUT * 2
|
|
348
|
-
});
|
|
349
|
-
const summary = typeof res?.summary === 'string' ? res.summary.trim() : '';
|
|
350
|
-
if (summary) {
|
|
351
|
-
summaries[sid] = summary;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
catch (e) {
|
|
355
|
-
if (this.sessionContext?.isDebugMode()) {
|
|
356
|
-
this.debug('Summarization prefetch failed for', sid, e instanceof Error ? e.message : e);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}));
|
|
360
|
-
return summaries;
|
|
361
|
-
}
|
|
362
|
-
catch (e) {
|
|
363
|
-
if (this.sessionContext?.isDebugMode()) {
|
|
364
|
-
this.debug('Summarization prefetch failed:', e instanceof Error ? e.message : e);
|
|
365
|
-
}
|
|
366
|
-
return summaries;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
async resumeTask(agentSession) {
|
|
370
|
-
try {
|
|
371
|
-
this.latestSessionId = agentSession.sessionId;
|
|
372
|
-
await this.initializeTask(agentSession);
|
|
373
|
-
// Ensure connected with correct session ID
|
|
374
|
-
await this.ensureConnected(agentSession.sessionId, agentSession.requestId);
|
|
375
|
-
await this.sendUserQuery();
|
|
376
|
-
}
|
|
377
|
-
catch (error) {
|
|
378
|
-
await this.handleError(error);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
async startTask(agentSession) {
|
|
382
|
-
try {
|
|
383
|
-
// Reset idle timer when starting a new task
|
|
384
|
-
this.resetActivityTimer();
|
|
385
|
-
this.latestSessionId = agentSession.sessionId;
|
|
386
|
-
await this.initializeTask(agentSession);
|
|
387
|
-
// Ensure connected with correct session ID
|
|
388
|
-
await this.ensureConnected(agentSession.sessionId, agentSession.requestId);
|
|
389
|
-
// Send the task request
|
|
390
|
-
await this.sendUserQuery();
|
|
391
|
-
}
|
|
392
|
-
catch (error) {
|
|
393
|
-
await this.handleError(error);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
async finishCurrentTask(isError = false) {
|
|
397
|
-
await this.taskTracker.trackTaskFinish(isError);
|
|
398
|
-
}
|
|
399
|
-
collectBaseData() {
|
|
400
|
-
// Get accessible paths from session context
|
|
401
|
-
const accessiblePaths = this.sessionContext.getAccessiblePaths();
|
|
402
|
-
const command = this.currentSession?.command || this.sessionContext.getCommand();
|
|
403
|
-
const execCwd = this.sessionContext?.getExecutionCwd?.();
|
|
404
|
-
const baseData = {
|
|
405
|
-
projects_root_path: accessiblePaths,
|
|
406
|
-
cwd: execCwd || accessiblePaths[0],
|
|
407
|
-
};
|
|
408
|
-
const prev = this.sessionContext.getPreviousSessionsSummarization();
|
|
409
|
-
if (prev && prev.length > 0) {
|
|
410
|
-
const sections = prev.map((item, i) => {
|
|
411
|
-
const sessionId = typeof item === 'string' ? String(i + 1) : item.sessionId;
|
|
412
|
-
const summary = typeof item === 'string' ? item : item.summary;
|
|
413
|
-
return `### Session ${sessionId}\n${(summary || '').trim()}`;
|
|
414
|
-
});
|
|
415
|
-
baseData.previous_sessions_summarization = sections.join('\n\n---\n\n');
|
|
416
|
-
}
|
|
417
|
-
if (command.instructions || this.sessionContext.getGeneralInstructions()) {
|
|
418
|
-
baseData.instructions = command.instructions || this.sessionContext.getGeneralInstructions();
|
|
419
|
-
}
|
|
420
|
-
if (this.sessionContext.getSystemPrompt()) {
|
|
421
|
-
baseData.system_prompt = this.sessionContext.getSystemPrompt();
|
|
422
|
-
}
|
|
423
|
-
return baseData;
|
|
424
|
-
}
|
|
425
|
-
async initializeTask(agentSession) {
|
|
426
|
-
this.currentSession = agentSession;
|
|
427
|
-
this.currentSession.abortController = new AbortController();
|
|
428
|
-
}
|
|
429
|
-
cancelCurrentSession() {
|
|
430
|
-
this.requestCancellation();
|
|
431
|
-
}
|
|
432
|
-
requestCancellation() {
|
|
433
|
-
this.debug('requestCancellation called - aborting session and disconnecting WebSocket');
|
|
434
|
-
// Use AbortController for atomic cancellation state management
|
|
435
|
-
if (this.currentSession?.abortController && !this.currentSession?.abortController.signal.aborted) {
|
|
436
|
-
this.currentSession?.abortController.abort();
|
|
437
|
-
this.debug('AbortController signal sent');
|
|
438
|
-
}
|
|
439
|
-
// Disconnect and reconnect WebSocket to stop any ongoing communication
|
|
440
|
-
this.disconnectAndReconnect();
|
|
441
|
-
}
|
|
442
|
-
disconnectAndReconnect() {
|
|
443
|
-
try {
|
|
444
|
-
this.debug('Disconnecting and reconnecting WebSocket due to cancellation');
|
|
445
|
-
this.wsClient.disconnect();
|
|
446
|
-
// Reconnect will happen automatically when the next request is made
|
|
447
|
-
}
|
|
448
|
-
catch (error) {
|
|
449
|
-
this.debug('Error during disconnect/reconnect:', error);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
async checkCancellation() {
|
|
453
|
-
// Use AbortController signal for atomic cancellation state checking
|
|
454
|
-
if (this.currentSession?.abortController?.signal.aborted) {
|
|
455
|
-
await this.handleCancellation();
|
|
456
|
-
return true;
|
|
457
|
-
}
|
|
458
|
-
return false;
|
|
459
|
-
}
|
|
460
|
-
async handleCancellation() {
|
|
461
|
-
// Finish task tracking before sending stop signal
|
|
462
|
-
await this.taskTracker.trackTaskFinish(true);
|
|
463
|
-
// Send stop signal
|
|
464
|
-
await this.responseCallback({
|
|
465
|
-
forceStop: true
|
|
466
|
-
});
|
|
467
|
-
// WebSocket stays connected for potential new requests
|
|
468
|
-
}
|
|
469
|
-
async sendUserQuery() {
|
|
470
|
-
if (!this.currentSession)
|
|
471
|
-
return;
|
|
472
|
-
const data = this.currentSession.data || {};
|
|
473
|
-
// Track task start when actually sending user request to backend
|
|
474
|
-
if (this.taskTracker.shouldTrackUserRequest(data)) {
|
|
475
|
-
// Initialize tracking for this user turn
|
|
476
|
-
this.taskTracker.initializeTaskTracking(this.currentSession);
|
|
477
|
-
}
|
|
478
|
-
// Prepare base data first so we can merge/inject instructions properly
|
|
479
|
-
const baseData = this.collectBaseData();
|
|
480
|
-
const command = this.currentSession.command || this.sessionContext.getCommand();
|
|
481
|
-
if (command?.output_schema) {
|
|
482
|
-
data.output_schema = command.output_schema;
|
|
483
|
-
}
|
|
484
|
-
const flags = this.sessionContext.getFlags();
|
|
485
|
-
if (flags?.max_iterations) {
|
|
486
|
-
data.max_iterations = flags.max_iterations;
|
|
487
|
-
}
|
|
488
|
-
if (this.sessionContext.getExecutionStrategy()) {
|
|
489
|
-
data.execution_strategy = this.sessionContext.getExecutionStrategy();
|
|
490
|
-
}
|
|
491
|
-
if (this.sessionContext.getQodoMd()) {
|
|
492
|
-
data.qodomd = this.sessionContext.getQodoMd();
|
|
493
|
-
}
|
|
494
|
-
data.custom_model = this.sessionContext.getModel();
|
|
495
|
-
const enabledToolsMap = this.mcpManager?.getEnabledTools(this.sessionContext.getAvailableTools(), this.sessionContext.getIgnoreTools());
|
|
496
|
-
// SDK client always uses agent_type: "sdk"
|
|
497
|
-
// Interactive mode is opt-in via flags
|
|
498
|
-
const interactiveMode = flags?.interactiveMode === true;
|
|
499
|
-
const requestData = {
|
|
500
|
-
agent_type: "sdk",
|
|
501
|
-
session_id: this.currentSession.sessionId,
|
|
502
|
-
user_data: getUserData(),
|
|
503
|
-
git_sha1: await getCurrentGitSha1(),
|
|
504
|
-
tools: this.mcpManager && enabledToolsMap ? Object.fromEntries(enabledToolsMap) : {},
|
|
505
|
-
permissions: this.sessionContext.getPermissions(),
|
|
506
|
-
interactive_mode: interactiveMode,
|
|
507
|
-
...baseData,
|
|
508
|
-
...data,
|
|
509
|
-
};
|
|
510
|
-
// Debug snapshot for UserQuery tools
|
|
511
|
-
try {
|
|
512
|
-
const perServerCounts = Object.fromEntries(Object.entries(requestData.tools || {}).map(([srv, arr]) => [srv, Array.isArray(arr) ? arr.length : 0]));
|
|
513
|
-
const totalTools = Object.values(requestData.tools || {}).reduce((acc, v) => acc + (Array.isArray(v) ? v.length : 0), 0);
|
|
514
|
-
this.debug('[AgentAPI] UserQuery tools snapshot:', { servers: Object.keys(requestData.tools || {}), perServerCounts, totalTools });
|
|
515
|
-
}
|
|
516
|
-
catch (e) {
|
|
517
|
-
this.debug('[AgentAPI] Failed to log UserQuery tools snapshot:', e instanceof Error ? e.message : e);
|
|
518
|
-
}
|
|
519
|
-
this.currentSession.waitingForResponse = true;
|
|
520
|
-
this.currentSession.lastPacketTimestamp = Date.now();
|
|
521
|
-
// Send via WebSocket client with new protocol format
|
|
522
|
-
try {
|
|
523
|
-
await this.wsClient.sendMessage('UserQuery', requestData);
|
|
524
|
-
}
|
|
525
|
-
catch (error) {
|
|
526
|
-
console.error('Error sending UserQuery message:', error);
|
|
527
|
-
await this.handleError(error);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
async handleWebSocketMessage(message) {
|
|
531
|
-
try {
|
|
532
|
-
await this.processMessage(message);
|
|
533
|
-
}
|
|
534
|
-
catch (error) {
|
|
535
|
-
console.error('Error processing WebSocket message:', error);
|
|
536
|
-
await this.handleError(error);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
async processMessage(message) {
|
|
540
|
-
if (await this.checkCancellation()) {
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
// Update last packet timestamp
|
|
544
|
-
if (this.currentSession) {
|
|
545
|
-
this.currentSession.lastPacketTimestamp = Date.now();
|
|
546
|
-
}
|
|
547
|
-
try {
|
|
548
|
-
const data = JSON.parse(message);
|
|
549
|
-
// Handle backend error envelope: { error: string, message: string }
|
|
550
|
-
if (data && typeof data === 'object' && 'error' in data && 'message' in data) {
|
|
551
|
-
try {
|
|
552
|
-
await this.responseCallback({ error: String(data.message) });
|
|
553
|
-
// Only force return to input if no tool approvals are pending
|
|
554
|
-
if (this.pendingToolRequests.size === 0) {
|
|
555
|
-
await this.taskTracker.trackTaskFinish(true);
|
|
556
|
-
await this.responseCallback({ forceStop: true });
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
catch (e) {
|
|
560
|
-
console.error('Error handling backend error message:', e);
|
|
561
|
-
}
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
this.wsClient.startReadyTimer();
|
|
565
|
-
await this.handleTaskResponse(data);
|
|
566
|
-
}
|
|
567
|
-
catch (error) {
|
|
568
|
-
// Don't process errors if we have a pending resume error
|
|
569
|
-
if (this.pendingResumeError) {
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
throw new Error("Failed to process message");
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
async handleTaskResponseError(response) {
|
|
576
|
-
if (response.type === "error" && this.currentSession) {
|
|
577
|
-
// Extract error message from either response.message or response.data.tool_args.content
|
|
578
|
-
let errorMessage;
|
|
579
|
-
if (response.message) {
|
|
580
|
-
errorMessage = response.message;
|
|
581
|
-
}
|
|
582
|
-
else if (response.data && typeof response.data === 'object') {
|
|
583
|
-
const data = response.data;
|
|
584
|
-
if (data.tool === "UserResponse" && data.tool_args?.content) {
|
|
585
|
-
errorMessage = data.tool_args.content;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
if (errorMessage) {
|
|
589
|
-
// Check if this is a "resume" error that should be retried
|
|
590
|
-
if (errorMessage.toLowerCase().includes("resume")) {
|
|
591
|
-
// Store the error to be thrown after stream completes
|
|
592
|
-
this.pendingResumeError = new Error(errorMessage);
|
|
593
|
-
return true;
|
|
594
|
-
}
|
|
595
|
-
// Send the error message
|
|
596
|
-
await this.responseCallback({
|
|
597
|
-
error: errorMessage,
|
|
598
|
-
});
|
|
599
|
-
// Track task finish with error before sending stop signal
|
|
600
|
-
await this.taskTracker.trackTaskFinish(true);
|
|
601
|
-
// Send stop signal
|
|
602
|
-
await this.responseCallback({
|
|
603
|
-
forceStop: true,
|
|
604
|
-
});
|
|
605
|
-
return true;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
return false;
|
|
609
|
-
}
|
|
610
|
-
async handleTaskResponse(response) {
|
|
611
|
-
// Check for cancellation at the start of processing each response
|
|
612
|
-
this.debug("Processing task response:", response);
|
|
613
|
-
if (await this.checkCancellation()) {
|
|
614
|
-
return;
|
|
615
|
-
}
|
|
616
|
-
if (await this.handleTaskResponseError(response)) {
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
if (!this.isValidTaskResponse(response)) {
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
const toolData = response.data;
|
|
623
|
-
// Ensure identifier is always set
|
|
624
|
-
if (!toolData.identifier) {
|
|
625
|
-
if (toolData.tool === UserResponse && this.lastToolId) {
|
|
626
|
-
toolData.identifier = this.lastToolId;
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
const newId = uuid();
|
|
630
|
-
toolData.identifier = newId;
|
|
631
|
-
if (toolData.tool === UserResponse) {
|
|
632
|
-
this.lastToolId = newId;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
else if (toolData.tool !== UserResponse) {
|
|
637
|
-
this.lastToolId = "";
|
|
638
|
-
}
|
|
639
|
-
switch (toolData.tool) {
|
|
640
|
-
case UserResponse:
|
|
641
|
-
await this.responseCallback({ toolData });
|
|
642
|
-
break;
|
|
643
|
-
case EndNode:
|
|
644
|
-
await this.handleEndNode();
|
|
645
|
-
break;
|
|
646
|
-
default:
|
|
647
|
-
await this.handleToolExecution(toolData);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
isValidTaskResponse(response) {
|
|
651
|
-
return Boolean(response?.session_id && response?.data && response.data?.tool);
|
|
652
|
-
}
|
|
653
|
-
async responseCallback(response) {
|
|
654
|
-
if (!this.currentSession) {
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
try {
|
|
658
|
-
this.currentSession.userEngagementCallback(response);
|
|
659
|
-
}
|
|
660
|
-
catch (error) {
|
|
661
|
-
console.error("Error in responseCallback:", error);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
async handleEndNode() {
|
|
665
|
-
// Track task finish before sending stop signal
|
|
666
|
-
await this.taskTracker.trackTaskFinish(false);
|
|
667
|
-
// Notify UI layer to finalize any accumulated responses
|
|
668
|
-
await this.responseCallback({
|
|
669
|
-
forceStop: true
|
|
670
|
-
});
|
|
671
|
-
// Don't automatically start idle timer here - it will be started when user gets control
|
|
672
|
-
// This allows the connection to stay open for potential new requests
|
|
673
|
-
}
|
|
674
|
-
async handleToolExecution(toolData) {
|
|
675
|
-
// Check for cancellation before executing tools
|
|
676
|
-
if (await this.checkCancellation()) {
|
|
677
|
-
return;
|
|
678
|
-
}
|
|
679
|
-
if (!toolData.server_name) {
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
// Ensure identifier is set for all tool executions
|
|
683
|
-
toolData.identifier ??= uuid();
|
|
684
|
-
toolData.session_id ??= this.currentSession?.sessionId || "";
|
|
685
|
-
if (toolData.tool_result) {
|
|
686
|
-
await this.processToolResponse(toolData, toolData.tool_result);
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
// Dedupe against backend re-emits of the same ToolRequested on Resume.
|
|
690
|
-
// The backend replays the pending tool call on reconnect so clients that
|
|
691
|
-
// missed the original streamed event can still execute it. If the original
|
|
692
|
-
// did survive, running it a second time would double-fire non-idempotent
|
|
693
|
-
// MCP tools. `pendingToolRequests` covers manual-approval tools waiting
|
|
694
|
-
// for user input, `inFlightToolCalls` covers auto-approved tools mid-exec,
|
|
695
|
-
// and `answeredToolCalls` covers tools whose result has already been sent.
|
|
696
|
-
const id = toolData.identifier;
|
|
697
|
-
if (this.pendingToolRequests.has(id) || this.inFlightToolCalls.has(id) || this.answeredToolCalls.has(id)) {
|
|
698
|
-
this.debug('[AgentAPI] Duplicate ToolRequested ignored (already pending/in-flight/answered):', id);
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
const { tool_reasoning, ...restArgs } = toolData.tool_args;
|
|
702
|
-
toolData.tool_args = restArgs;
|
|
703
|
-
toolData.tool_reasoning = tool_reasoning ? tool_reasoning : "";
|
|
704
|
-
try {
|
|
705
|
-
// If MCP is disabled entirely, decline tool execution immediately with a friendly message.
|
|
706
|
-
if (!this.mcpManager) {
|
|
707
|
-
await this.handleToolDecline(toolData, 'This agent was configured with `tools = []`, so no MCP tools are available.');
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
const isAutoApprovedTool = this.mcpManager.isAutoApprovedTool(toolData.server_name, toolData.tool, toolData.tool_args);
|
|
711
|
-
const processedToolData = await ToolProcessorManager.getInstance().preProcessTool(toolData, this.sessionContext);
|
|
712
|
-
await this.processToolReasoning(processedToolData, isAutoApprovedTool);
|
|
713
|
-
// Dry run: simulate tool execution without side effects
|
|
714
|
-
if (this.sessionContext?.isDryRun()) {
|
|
715
|
-
const dryResult = await ToolProcessorManager.getInstance().dryRunTool(processedToolData, this.sessionContext);
|
|
716
|
-
await this.processToolResponse(processedToolData, dryResult);
|
|
717
|
-
await this.sendToolResponse(processedToolData, dryResult);
|
|
718
|
-
}
|
|
719
|
-
else if (isAutoApprovedTool) {
|
|
720
|
-
await this.callTool(processedToolData);
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
this.setUserHasControl(true);
|
|
724
|
-
this.pendingToolRequests.set(processedToolData.identifier, {
|
|
725
|
-
agentSession: this.currentSession,
|
|
726
|
-
toolData: processedToolData,
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
catch (error) {
|
|
731
|
-
console.error("Error in tool execution:", error);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
async handleToolDecline(toolData, reason = 'User declined tool execution') {
|
|
735
|
-
const answer = {
|
|
736
|
-
isError: true,
|
|
737
|
-
content: [{ type: "text", text: reason }],
|
|
738
|
-
};
|
|
739
|
-
if (this.currentSession) {
|
|
740
|
-
await this.processToolResponse(toolData, answer);
|
|
741
|
-
// Send tool response via WebSocket
|
|
742
|
-
await this.sendToolResponse(toolData, answer);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
async callTool(toolData) {
|
|
746
|
-
// Check for cancellation before calling tool
|
|
747
|
-
if (await this.checkCancellation()) {
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
const toolCallId = toolData.identifier ?? uuid();
|
|
751
|
-
toolData.identifier = toolCallId;
|
|
752
|
-
this.inFlightToolCalls.add(toolCallId);
|
|
753
|
-
try {
|
|
754
|
-
this.debug("Calling tool:", toolData.tool, "on server:", toolData.server_name);
|
|
755
|
-
// Track the tool execution
|
|
756
|
-
this.taskTracker.trackToolExecution(toolData.server_name, toolData.tool);
|
|
757
|
-
// If shell_execute or ripgrep_search without cwd, default to session execution CWD if configured.
|
|
758
|
-
// Also, for git tools, default repo_path to execution CWD when not provided. This gives
|
|
759
|
-
// in-process SDK sessions (which set an explicit cwd) consistent behavior across built-ins.
|
|
760
|
-
let patchedArgs = toolData.tool_args;
|
|
761
|
-
try {
|
|
762
|
-
const execCwd = this.sessionContext?.getExecutionCwd?.();
|
|
763
|
-
if (execCwd) {
|
|
764
|
-
const hasCwd = patchedArgs && typeof patchedArgs === 'object' && 'cwd' in patchedArgs && patchedArgs.cwd;
|
|
765
|
-
const isShell = toolData.server_name === 'shell' && toolData.tool === 'shell_execute';
|
|
766
|
-
const isRipgrep = toolData.server_name === 'ripgrep' && toolData.tool === 'ripgrep_search';
|
|
767
|
-
if (!hasCwd && (isShell || isRipgrep)) {
|
|
768
|
-
patchedArgs = { ...(patchedArgs || {}), cwd: execCwd };
|
|
769
|
-
}
|
|
770
|
-
// Git tools expect a repo_path; when omitted, treat the execution CWD as the repo root.
|
|
771
|
-
const needsRepoPath = toolData.server_name === 'git'
|
|
772
|
-
&& (!patchedArgs || typeof patchedArgs.repo_path !== 'string' || !patchedArgs.repo_path);
|
|
773
|
-
if (needsRepoPath) {
|
|
774
|
-
patchedArgs = { ...(patchedArgs || {}), repo_path: execCwd };
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
catch { /* best-effort: tool arg patching should not block tool execution */ }
|
|
779
|
-
if (!this.mcpManager) {
|
|
780
|
-
// Should not be reachable because we guard earlier, but keep a safe fallback
|
|
781
|
-
// that gracefully declines the tool call instead of throwing.
|
|
782
|
-
await this.handleToolDecline(toolData, 'This agent was configured with `tools = []`, so no MCP tools are available.');
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
const result = await this.mcpManager.callTool(toolData.server_name, toolData.tool, patchedArgs);
|
|
786
|
-
this.debug("Tool execution result:", result?.isError ? "Error" : "Success");
|
|
787
|
-
// Track code blocks for filesystem modifications
|
|
788
|
-
if (toolData.server_name.toLowerCase() === "filesystem" && result && !result.isError) {
|
|
789
|
-
this.taskTracker.trackFileSystemChanges(toolData.tool, toolData.tool_args, result);
|
|
790
|
-
}
|
|
791
|
-
if (result && this.currentSession) {
|
|
792
|
-
try {
|
|
793
|
-
const response = result
|
|
794
|
-
? result
|
|
795
|
-
: { isError: true, content: [{ type: "text", text: "Unknown error occurred" }] };
|
|
796
|
-
if (await this.checkCancellation()) {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
// Post-process the tool result
|
|
800
|
-
const processedResponse = await ToolProcessorManager.getInstance().postProcessTool(toolData, response);
|
|
801
|
-
await this.processToolResponse(toolData, processedResponse);
|
|
802
|
-
// Send tool response via WebSocket
|
|
803
|
-
await this.sendToolResponse(toolData, processedResponse);
|
|
804
|
-
}
|
|
805
|
-
catch (error) {
|
|
806
|
-
const errorResponse = {
|
|
807
|
-
isError: true,
|
|
808
|
-
content: [{ type: "text", text: "Unknown error occurred" }],
|
|
809
|
-
};
|
|
810
|
-
await this.processToolResponse(toolData, errorResponse);
|
|
811
|
-
await this.sendToolResponse(toolData, errorResponse);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
catch (error) {
|
|
816
|
-
this.debug("Error in tool execution:", error);
|
|
817
|
-
const errorResponse = {
|
|
818
|
-
isError: true,
|
|
819
|
-
content: [{ type: "text", text: error instanceof Error ? error.message : "Unknown error occurred" }],
|
|
820
|
-
};
|
|
821
|
-
await this.processToolResponse(toolData, errorResponse);
|
|
822
|
-
await this.sendToolResponse(toolData, errorResponse);
|
|
823
|
-
}
|
|
824
|
-
finally {
|
|
825
|
-
this.inFlightToolCalls.delete(toolCallId);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
async sendToolResponse(toolData, response) {
|
|
829
|
-
try {
|
|
830
|
-
if (!this.currentSession) {
|
|
831
|
-
console.error('No current session available for tool response');
|
|
832
|
-
return;
|
|
833
|
-
}
|
|
834
|
-
this.setUserHasControl(false);
|
|
835
|
-
// Create IDERetrievalAnswer format - SDK client always uses agent_type: "sdk"
|
|
836
|
-
const ideAnswer = {
|
|
837
|
-
tool: toolData.tool,
|
|
838
|
-
tool_id: toolData.identifier,
|
|
839
|
-
answer: response,
|
|
840
|
-
tools: this.convertToolsForIDE(),
|
|
841
|
-
user_data: getUserData(),
|
|
842
|
-
agent_type: "sdk"
|
|
843
|
-
};
|
|
844
|
-
// Debug snapshot for IDERetrievalAnswer tools
|
|
845
|
-
try {
|
|
846
|
-
const toolsAny = ideAnswer.tools;
|
|
847
|
-
if (Array.isArray(toolsAny?.IDETool)) {
|
|
848
|
-
const arr = toolsAny.IDETool;
|
|
849
|
-
const sample = arr.slice(0, 3).map((t) => t?.name || t?.tool || '[unknown]');
|
|
850
|
-
this.debug('[AgentAPI] IDERetrievalAnswer tools snapshot (array form):', { count: arr.length, sample });
|
|
851
|
-
}
|
|
852
|
-
else if (toolsAny && typeof toolsAny === 'object') {
|
|
853
|
-
const perServerCounts = Object.fromEntries(Object.entries(toolsAny).map(([srv, arr]) => [srv, Array.isArray(arr) ? arr.length : 0]));
|
|
854
|
-
const totalTools = Object.values(toolsAny).reduce((acc, v) => acc + (Array.isArray(v) ? v.length : 0), 0);
|
|
855
|
-
this.debug('[AgentAPI] IDERetrievalAnswer tools snapshot (map form):', { servers: Object.keys(toolsAny), perServerCounts, totalTools });
|
|
856
|
-
}
|
|
857
|
-
else {
|
|
858
|
-
this.debug('[AgentAPI] IDERetrievalAnswer tools snapshot: tools is empty or invalid');
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
catch (e) {
|
|
862
|
-
this.debug('[AgentAPI] Failed to log IDERetrievalAnswer tools snapshot:', e instanceof Error ? e.message : e);
|
|
863
|
-
}
|
|
864
|
-
// Send via WebSocket client with new protocol format
|
|
865
|
-
await this.wsClient.sendMessage('IDERetrievalAnswer', ideAnswer);
|
|
866
|
-
// Record the answered tool_call so a backend Resume-time re-emit of
|
|
867
|
-
// the same ToolRequested doesn't trigger a second execution.
|
|
868
|
-
if (toolData.identifier) {
|
|
869
|
-
this.answeredToolCalls.add(toolData.identifier);
|
|
870
|
-
}
|
|
871
|
-
this.debug('Tool response sent via WebSocket client');
|
|
872
|
-
}
|
|
873
|
-
catch (error) {
|
|
874
|
-
console.error('Error sending tool response:', error);
|
|
875
|
-
// Only handle error if we're not already in an error state
|
|
876
|
-
if (this.currentSession?.waitingForResponse) {
|
|
877
|
-
await this.handleError(error);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
convertToolsForIDE() {
|
|
882
|
-
// For IDERetrievalAnswer the backend expects a ToolType-keyed dict.
|
|
883
|
-
// Use 'IDETool' with a flat array of tools.
|
|
884
|
-
const enabledTools = this.mcpManager?.getEnabledTools(this.sessionContext.getAvailableTools(), this.sessionContext.getIgnoreTools());
|
|
885
|
-
// Debug: inspect enabled tools map content before conversion
|
|
886
|
-
try {
|
|
887
|
-
const isMap = enabledTools instanceof Map;
|
|
888
|
-
const serverCount = isMap ? enabledTools.size : 0;
|
|
889
|
-
const serverNames = isMap ? Array.from(enabledTools.keys()) : [];
|
|
890
|
-
const perServerCounts = isMap ? Object.fromEntries(Array.from(enabledTools.entries()).map(([k, v]) => [k, Array.isArray(v) ? v.length : 0])) : {};
|
|
891
|
-
const flattenedCount = isMap ? Array.from(enabledTools.values()).flat().length : 0;
|
|
892
|
-
this.debug('[AgentAPI] convertToolsForIDE (to IDETool array):', { isMap, serverCount, serverNames, perServerCounts, flattenedCount });
|
|
893
|
-
}
|
|
894
|
-
catch (e) {
|
|
895
|
-
this.debug('[AgentAPI] convertToolsForIDE: failed to log enabled tools map:', e instanceof Error ? e.message : e);
|
|
896
|
-
}
|
|
897
|
-
const ideTools = enabledTools ? Array.from(enabledTools.values()).flat() : [];
|
|
898
|
-
return { IDETool: ideTools };
|
|
899
|
-
}
|
|
900
|
-
async processToolReasoning(toolData, isAutoApprovedTool) {
|
|
901
|
-
if (!this.currentSession) {
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
await this.responseCallback({
|
|
905
|
-
toolData: {
|
|
906
|
-
...toolData,
|
|
907
|
-
...(!isAutoApprovedTool ? { pending_approval: true } : {}),
|
|
908
|
-
}
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
async processToolResponse(toolData, toolResult) {
|
|
912
|
-
await this.responseCallback({
|
|
913
|
-
toolData: { ...toolData, tool_result: toolResult },
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
async handleError(error) {
|
|
917
|
-
if (this.currentSession) {
|
|
918
|
-
this.currentSession.waitingForResponse = false;
|
|
919
|
-
}
|
|
920
|
-
let message = error instanceof Error ? error.message : "Unknown error occurred";
|
|
921
|
-
// Handle different types of cancellation/abort errors
|
|
922
|
-
if (error instanceof Error) {
|
|
923
|
-
if (error.name === "AbortError" || error.name === "CanceledError") {
|
|
924
|
-
// Check if this was a user-initiated cancellation vs timeout
|
|
925
|
-
if (this.currentSession?.abortController?.signal.aborted) {
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
else {
|
|
929
|
-
message = "Request Timeout";
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
await this.responseCallback({
|
|
934
|
-
error: message || SERVER_ERROR_MESSAGE,
|
|
935
|
-
});
|
|
936
|
-
// Finish task tracking before terminating session
|
|
937
|
-
await this.taskTracker.trackTaskFinish(true);
|
|
938
|
-
// Terminate session after error
|
|
939
|
-
await this.responseCallback({
|
|
940
|
-
forceStop: true,
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
// Enhanced cleanup method with comprehensive resource management
|
|
944
|
-
cleanupConnections() {
|
|
945
|
-
this.wsClient.cleanup();
|
|
946
|
-
}
|
|
947
|
-
// Complete cleanup method
|
|
948
|
-
cleanup() {
|
|
949
|
-
try {
|
|
950
|
-
this.cleanupConnections();
|
|
951
|
-
}
|
|
952
|
-
catch { /* cleanup: connection teardown must not throw */ }
|
|
953
|
-
this.pendingToolRequests.clear();
|
|
954
|
-
this.answeredToolCalls.clear();
|
|
955
|
-
this.currentSession = undefined;
|
|
956
|
-
this.latestSessionId = "";
|
|
957
|
-
}
|
|
958
|
-
// Get the task tracker instance
|
|
959
|
-
getTaskTracker() {
|
|
960
|
-
return this.taskTracker;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
//# sourceMappingURL=agent.js.map
|