open-multi-agent-kit 0.98.5 → 1.0.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/CHANGELOG.md +48 -0
- package/README.md +4 -3
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +1 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/register-bundled-coding-agent.d.ts +10 -0
- package/dist/bun/register-bundled-coding-agent.d.ts.map +1 -0
- package/dist/bun/register-bundled-coding-agent.js +12 -0
- package/dist/bun/register-bundled-coding-agent.js.map +1 -0
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -1
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/neo-cli.d.ts +9 -0
- package/dist/commands/neo-cli.d.ts.map +1 -0
- package/dist/commands/neo-cli.js +61 -0
- package/dist/commands/neo-cli.js.map +1 -0
- package/dist/commands/verified-run-cli.d.ts.map +1 -1
- package/dist/commands/verified-run-cli.js +2 -2
- package/dist/commands/verified-run-cli.js.map +1 -1
- package/dist/core/agent-session.d.ts +29 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +126 -32
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bundled-skills.d.ts +4 -0
- package/dist/core/bundled-skills.d.ts.map +1 -0
- package/dist/core/bundled-skills.js +32 -0
- package/dist/core/bundled-skills.js.map +1 -0
- package/dist/core/cli-diagnostics.d.ts +6 -0
- package/dist/core/cli-diagnostics.d.ts.map +1 -0
- package/dist/core/cli-diagnostics.js +20 -0
- package/dist/core/cli-diagnostics.js.map +1 -0
- package/dist/core/context-budget-headroom.d.ts +12 -0
- package/dist/core/context-budget-headroom.d.ts.map +1 -1
- package/dist/core/context-budget-headroom.js +35 -0
- package/dist/core/context-budget-headroom.js.map +1 -1
- package/dist/core/context-budget-v2-input-validation.d.ts +4 -0
- package/dist/core/context-budget-v2-input-validation.d.ts.map +1 -0
- package/dist/core/context-budget-v2-input-validation.js +79 -0
- package/dist/core/context-budget-v2-input-validation.js.map +1 -0
- package/dist/core/context-budget-v2-observability.d.ts +15 -0
- package/dist/core/context-budget-v2-observability.d.ts.map +1 -0
- package/dist/core/context-budget-v2-observability.js +35 -0
- package/dist/core/context-budget-v2-observability.js.map +1 -0
- package/dist/core/context-budget-v2-planned-items.d.ts +5 -0
- package/dist/core/context-budget-v2-planned-items.d.ts.map +1 -0
- package/dist/core/context-budget-v2-planned-items.js +40 -0
- package/dist/core/context-budget-v2-planned-items.js.map +1 -0
- package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planner.js +57 -38
- package/dist/core/context-budget-v2-planner.js.map +1 -1
- package/dist/core/context-budget-v2-selection.d.ts +19 -3
- package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
- package/dist/core/context-budget-v2-selection.js +35 -57
- package/dist/core/context-budget-v2-selection.js.map +1 -1
- package/dist/core/context-budget-v2-tiers.d.ts.map +1 -1
- package/dist/core/context-budget-v2-tiers.js +9 -42
- package/dist/core/context-budget-v2-tiers.js.map +1 -1
- package/dist/core/context-budget-v2-types.d.ts +8 -1
- package/dist/core/context-budget-v2-types.d.ts.map +1 -1
- package/dist/core/context-budget-v2-types.js.map +1 -1
- package/dist/core/devin-harness-dispatch.d.ts +12 -0
- package/dist/core/devin-harness-dispatch.d.ts.map +1 -0
- package/dist/core/devin-harness-dispatch.js +12 -0
- package/dist/core/devin-harness-dispatch.js.map +1 -0
- package/dist/core/devin-harness.d.ts +53 -0
- package/dist/core/devin-harness.d.ts.map +1 -0
- package/dist/core/devin-harness.js +112 -0
- package/dist/core/devin-harness.js.map +1 -0
- package/dist/core/domain-dispatch.d.ts +4 -1
- package/dist/core/domain-dispatch.d.ts.map +1 -1
- package/dist/core/domain-dispatch.js +5 -0
- package/dist/core/domain-dispatch.js.map +1 -1
- package/dist/core/domain-loadouts-provider-harness.d.ts +12 -0
- package/dist/core/domain-loadouts-provider-harness.d.ts.map +1 -0
- package/dist/core/domain-loadouts-provider-harness.js +122 -0
- package/dist/core/domain-loadouts-provider-harness.js.map +1 -0
- package/dist/core/domain-loadouts.d.ts +2 -33
- package/dist/core/domain-loadouts.d.ts.map +1 -1
- package/dist/core/domain-loadouts.js +3 -56
- package/dist/core/domain-loadouts.js.map +1 -1
- package/dist/core/domain-profile.d.ts +40 -0
- package/dist/core/domain-profile.d.ts.map +1 -0
- package/dist/core/domain-profile.js +7 -0
- package/dist/core/domain-profile.js.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts +15 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.js +63 -0
- package/dist/core/extensions/bundled-virtual-modules.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +2 -42
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +10 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/grok-harness-dispatch.d.ts +6 -20
- package/dist/core/grok-harness-dispatch.d.ts.map +1 -1
- package/dist/core/grok-harness-dispatch.js +6 -55
- package/dist/core/grok-harness-dispatch.js.map +1 -1
- package/dist/core/grok-harness.d.ts +7 -9
- package/dist/core/grok-harness.d.ts.map +1 -1
- package/dist/core/grok-harness.js +9 -23
- package/dist/core/grok-harness.js.map +1 -1
- package/dist/core/harness-skills.d.ts +20 -0
- package/dist/core/harness-skills.d.ts.map +1 -0
- package/dist/core/harness-skills.js +36 -0
- package/dist/core/harness-skills.js.map +1 -0
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/loadout-runtime-state.d.ts +25 -0
- package/dist/core/loadout-runtime-state.d.ts.map +1 -0
- package/dist/core/loadout-runtime-state.js +39 -0
- package/dist/core/loadout-runtime-state.js.map +1 -0
- package/dist/core/loadout-runtime.d.ts +4 -20
- package/dist/core/loadout-runtime.d.ts.map +1 -1
- package/dist/core/loadout-runtime.js +6 -13
- package/dist/core/loadout-runtime.js.map +1 -1
- package/dist/core/mcp/client.d.ts +27 -6
- package/dist/core/mcp/client.d.ts.map +1 -1
- package/dist/core/mcp/client.js +80 -20
- package/dist/core/mcp/client.js.map +1 -1
- package/dist/core/mcp/manager.d.ts +10 -1
- package/dist/core/mcp/manager.d.ts.map +1 -1
- package/dist/core/mcp/manager.js +68 -9
- package/dist/core/mcp/manager.js.map +1 -1
- package/dist/core/mcp/protocol.d.ts +9 -3
- package/dist/core/mcp/protocol.d.ts.map +1 -1
- package/dist/core/mcp/protocol.js +61 -15
- package/dist/core/mcp/protocol.js.map +1 -1
- package/dist/core/mcp/stdio-transport.d.ts +12 -1
- package/dist/core/mcp/stdio-transport.d.ts.map +1 -1
- package/dist/core/mcp/stdio-transport.js +30 -2
- package/dist/core/mcp/stdio-transport.js.map +1 -1
- package/dist/core/mcp-descriptor-injection.d.ts +26 -0
- package/dist/core/mcp-descriptor-injection.d.ts.map +1 -0
- package/dist/core/mcp-descriptor-injection.js +25 -0
- package/dist/core/mcp-descriptor-injection.js.map +1 -0
- package/dist/core/mcp-public-presets.d.ts +1 -3
- package/dist/core/mcp-public-presets.d.ts.map +1 -1
- package/dist/core/mcp-public-presets.js +3 -15
- package/dist/core/mcp-public-presets.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +24 -3
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -41
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +2 -49
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/neo/catalog.d.ts +20 -0
- package/dist/core/neo/catalog.d.ts.map +1 -0
- package/dist/core/neo/catalog.js +50 -0
- package/dist/core/neo/catalog.js.map +1 -0
- package/dist/core/neo/setup.d.ts +3 -0
- package/dist/core/neo/setup.d.ts.map +1 -0
- package/dist/core/neo/setup.js +47 -0
- package/dist/core/neo/setup.js.map +1 -0
- package/dist/core/provider-default-models.d.ts +43 -0
- package/dist/core/provider-default-models.d.ts.map +1 -0
- package/dist/core/provider-default-models.js +51 -0
- package/dist/core/provider-default-models.js.map +1 -0
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +2 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/provider-error-classification.d.ts +57 -0
- package/dist/core/provider-error-classification.d.ts.map +1 -0
- package/dist/core/provider-error-classification.js +103 -0
- package/dist/core/provider-error-classification.js.map +1 -0
- package/dist/core/provider-harness-dispatch.d.ts +63 -0
- package/dist/core/provider-harness-dispatch.d.ts.map +1 -0
- package/dist/core/provider-harness-dispatch.js +60 -0
- package/dist/core/provider-harness-dispatch.js.map +1 -0
- package/dist/core/provider-resilience.d.ts +10 -0
- package/dist/core/provider-resilience.d.ts.map +1 -1
- package/dist/core/provider-resilience.js +36 -3
- package/dist/core/provider-resilience.js.map +1 -1
- package/dist/core/provider-usage-commandcode.d.ts +9 -0
- package/dist/core/provider-usage-commandcode.d.ts.map +1 -0
- package/dist/core/provider-usage-commandcode.js +198 -0
- package/dist/core/provider-usage-commandcode.js.map +1 -0
- package/dist/core/provider-usage-devin.d.ts +18 -0
- package/dist/core/provider-usage-devin.d.ts.map +1 -0
- package/dist/core/provider-usage-devin.js +71 -0
- package/dist/core/provider-usage-devin.js.map +1 -0
- package/dist/core/provider-usage-text.d.ts +5 -0
- package/dist/core/provider-usage-text.d.ts.map +1 -0
- package/dist/core/provider-usage-text.js +15 -0
- package/dist/core/provider-usage-text.js.map +1 -0
- package/dist/core/provider-usage-types.d.ts +2 -1
- package/dist/core/provider-usage-types.d.ts.map +1 -1
- package/dist/core/provider-usage-types.js.map +1 -1
- package/dist/core/provider-usage.d.ts +1 -2
- package/dist/core/provider-usage.d.ts.map +1 -1
- package/dist/core/provider-usage.js +18 -7
- package/dist/core/provider-usage.js.map +1 -1
- package/dist/core/resource-admission.d.ts +36 -0
- package/dist/core/resource-admission.d.ts.map +1 -1
- package/dist/core/resource-admission.js +59 -0
- package/dist/core/resource-admission.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/run-execution-api.d.ts +1 -1
- package/dist/core/run-execution-api.d.ts.map +1 -1
- package/dist/core/run-execution-api.js.map +1 -1
- package/dist/core/run-usage-ledger.d.ts +47 -0
- package/dist/core/run-usage-ledger.d.ts.map +1 -0
- package/dist/core/run-usage-ledger.js +162 -0
- package/dist/core/run-usage-ledger.js.map +1 -0
- package/dist/core/run-usage-operation.d.ts +8 -0
- package/dist/core/run-usage-operation.d.ts.map +1 -0
- package/dist/core/run-usage-operation.js +12 -0
- package/dist/core/run-usage-operation.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +20 -16
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-failure-cause.d.ts.map +1 -1
- package/dist/core/session-failure-cause.js +14 -5
- package/dist/core/session-failure-cause.js.map +1 -1
- package/dist/core/session-prompt-lifecycle.d.ts +6 -0
- package/dist/core/session-prompt-lifecycle.d.ts.map +1 -1
- package/dist/core/session-prompt-lifecycle.js +47 -2
- package/dist/core/session-prompt-lifecycle.js.map +1 -1
- package/dist/core/session-termination.d.ts.map +1 -1
- package/dist/core/session-termination.js +4 -2
- package/dist/core/session-termination.js.map +1 -1
- package/dist/core/subagent-lane-authority.d.ts +28 -0
- package/dist/core/subagent-lane-authority.d.ts.map +1 -0
- package/dist/core/subagent-lane-authority.js +119 -0
- package/dist/core/subagent-lane-authority.js.map +1 -0
- package/dist/core/subagent-lane-contract.d.ts +114 -0
- package/dist/core/subagent-lane-contract.d.ts.map +1 -0
- package/dist/core/subagent-lane-contract.js +18 -0
- package/dist/core/subagent-lane-contract.js.map +1 -0
- package/dist/core/subagent-lane-launcher.d.ts +3 -6
- package/dist/core/subagent-lane-launcher.d.ts.map +1 -1
- package/dist/core/subagent-lane-launcher.js +53 -12
- package/dist/core/subagent-lane-launcher.js.map +1 -1
- package/dist/core/subagent-orchestration.d.ts +4 -17
- package/dist/core/subagent-orchestration.d.ts.map +1 -1
- package/dist/core/subagent-orchestration.js.map +1 -1
- package/dist/core/verified-run/broker.d.ts.map +1 -1
- package/dist/core/verified-run/broker.js +4 -1
- package/dist/core/verified-run/broker.js.map +1 -1
- package/dist/core/verified-run/dag-phase.d.ts +1 -1
- package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
- package/dist/core/verified-run/dag-phase.js +46 -8
- package/dist/core/verified-run/dag-phase.js.map +1 -1
- package/dist/core/verified-run/dag-projection.d.ts.map +1 -1
- package/dist/core/verified-run/dag-projection.js +25 -12
- package/dist/core/verified-run/dag-projection.js.map +1 -1
- package/dist/core/verified-run/dag-types.d.ts +11 -0
- package/dist/core/verified-run/dag-types.d.ts.map +1 -1
- package/dist/core/verified-run/dag-types.js.map +1 -1
- package/dist/core/verified-run/event-parser.d.ts.map +1 -1
- package/dist/core/verified-run/event-parser.js +1 -0
- package/dist/core/verified-run/event-parser.js.map +1 -1
- package/dist/core/verified-run/owned-execution.d.ts +1 -0
- package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
- package/dist/core/verified-run/owned-execution.js +7 -1
- package/dist/core/verified-run/owned-execution.js.map +1 -1
- package/dist/core/verified-run/process-projection.d.ts +13 -0
- package/dist/core/verified-run/process-projection.d.ts.map +1 -0
- package/dist/core/verified-run/process-projection.js +82 -0
- package/dist/core/verified-run/process-projection.js.map +1 -0
- package/dist/core/verified-run/projection.d.ts.map +1 -1
- package/dist/core/verified-run/projection.js +11 -55
- package/dist/core/verified-run/projection.js.map +1 -1
- package/dist/core/verified-run/run-types.d.ts +1 -0
- package/dist/core/verified-run/run-types.d.ts.map +1 -1
- package/dist/core/verified-run/run-types.js.map +1 -1
- package/dist/core/verified-run/task-execution.d.ts +9 -0
- package/dist/core/verified-run/task-execution.d.ts.map +1 -0
- package/dist/core/verified-run/task-execution.js +29 -0
- package/dist/core/verified-run/task-execution.js.map +1 -0
- package/dist/core/verified-run/writer-projection.d.ts.map +1 -1
- package/dist/core/verified-run/writer-projection.js +6 -5
- package/dist/core/verified-run/writer-projection.js.map +1 -1
- package/dist/core/workload-permit-pool.d.ts +1 -1
- package/dist/core/workload-permit-pool.d.ts.map +1 -1
- package/dist/core/workload-permit-pool.js +3 -0
- package/dist/core/workload-permit-pool.js.map +1 -1
- package/dist/guardrails/strict-evidence-approval-adapter.d.ts +34 -0
- package/dist/guardrails/strict-evidence-approval-adapter.d.ts.map +1 -0
- package/dist/guardrails/strict-evidence-approval-adapter.js +70 -0
- package/dist/guardrails/strict-evidence-approval-adapter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -18
- package/dist/main.js.map +1 -1
- package/dist/modes/acp/acp-agent.d.ts +24 -0
- package/dist/modes/acp/acp-agent.d.ts.map +1 -0
- package/dist/modes/acp/acp-agent.js +133 -0
- package/dist/modes/acp/acp-agent.js.map +1 -0
- package/dist/modes/acp/acp-mode.d.ts +4 -0
- package/dist/modes/acp/acp-mode.d.ts.map +1 -0
- package/dist/modes/acp/acp-mode.js +34 -0
- package/dist/modes/acp/acp-mode.js.map +1 -0
- package/dist/modes/acp/acp-session.d.ts +4 -0
- package/dist/modes/acp/acp-session.d.ts.map +1 -0
- package/dist/modes/acp/acp-session.js +76 -0
- package/dist/modes/acp/acp-session.js.map +1 -0
- package/dist/modes/acp/acp-transport.d.ts +5 -0
- package/dist/modes/acp/acp-transport.d.ts.map +1 -0
- package/dist/modes/acp/acp-transport.js +90 -0
- package/dist/modes/acp/acp-transport.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +3 -5
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/resource-description.d.ts +3 -0
- package/dist/modes/interactive/resource-description.d.ts.map +1 -0
- package/dist/modes/interactive/resource-description.js +15 -0
- package/dist/modes/interactive/resource-description.js.map +1 -0
- package/docs/audit-revalidation-2026-09-17.md +77 -0
- package/docs/devin-harness.md +150 -0
- package/docs/docs.json +4 -0
- package/docs/ecraf-normalization.md +83 -0
- package/docs/environment-variables.md +2 -1
- package/docs/index.md +1 -0
- package/docs/loadout-domains/README.md +2 -1
- package/docs/loadout-domains/devin-harness.md +72 -0
- package/docs/metrics.md +57 -16
- package/docs/model-catalog-refresh.md +51 -1
- package/docs/models.md +1 -1
- package/docs/neo.md +134 -0
- package/docs/providers.md +143 -1
- package/docs/release-audit-0.98.5.md +17 -0
- package/docs/release-audit-0.99.0.md +68 -0
- package/docs/run-protocol.md +4 -3
- package/docs/run-usage-ledger.md +56 -0
- package/docs/runtime-algorithms.md +48 -1
- package/docs/sdk.md +9 -5
- package/docs/settings.md +1 -1
- package/docs/skills.md +1 -1
- package/docs/startup-resource-labels-testing.md +47 -0
- package/docs/tb21-audit.md +18 -4
- package/docs/usage.md +7 -1
- package/docs/verified-run-remaining-design.md +881 -0
- package/docs/verified-run-testing.md +91 -0
- package/docs/verified-run.md +30 -9
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/adaptive-agent-runtime.ts +14 -1
- package/examples/extensions/subagent/graph-result.ts +48 -0
- package/examples/extensions/subagent/index.ts +246 -111
- package/examples/extensions/subagent/managed-process-tree.ts +42 -0
- package/examples/extensions/subagent/managed-process.test.ts +24 -0
- package/examples/extensions/subagent/managed-process.ts +93 -112
- package/examples/extensions/subagent/subagent-runtime-types.ts +17 -1
- package/examples/extensions/subagent/subagent-stream.ts +161 -0
- package/examples/extensions/terminal-browser/README.md +54 -0
- package/examples/extensions/terminal-browser/bridge-protocol.ts +29 -0
- package/examples/extensions/terminal-browser/bridge.ts +219 -0
- package/examples/extensions/terminal-browser/browser-surface.ts +288 -0
- package/examples/extensions/terminal-browser/index.ts +215 -0
- package/examples/extensions/terminal-browser/placeholders.ts +49 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +18 -18
- package/package.json +8 -7
- package/resources/neo/skills/omk-browser/SKILL.md +32 -0
- package/resources/neo/skills/omk-code-review/SKILL.md +24 -0
- package/resources/neo/skills/omk-computeruse/SKILL.md +34 -0
- package/resources/neo/skills/omk-mcp-setup/SKILL.md +48 -0
- package/resources/neo/skills/omk-research/SKILL.md +24 -0
- package/resources/neo/skills/omk-site/SKILL.md +28 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getAgentDir } from "../../config.js";
|
|
4
|
+
import { AuthStorage } from "../../core/auth-storage.js";
|
|
5
|
+
import { createExtensionRuntime } from "../../core/extensions/loader.js";
|
|
6
|
+
import { ModelRegistry } from "../../core/model-registry.js";
|
|
7
|
+
import { resolveCliModel } from "../../core/model-resolver.js";
|
|
8
|
+
import { createAgentSession } from "../../core/sdk.js";
|
|
9
|
+
import { SessionManager } from "../../core/session-manager.js";
|
|
10
|
+
import { SettingsManager } from "../../core/settings-manager.js";
|
|
11
|
+
import { AcpError } from "./acp-agent.js";
|
|
12
|
+
/** No discovery or client-requested executables in the restricted ACP profile. */
|
|
13
|
+
function emptyResources() {
|
|
14
|
+
return {
|
|
15
|
+
getExtensions: () => ({ extensions: [], errors: [], runtime: createExtensionRuntime() }),
|
|
16
|
+
getSkills: () => ({ skills: [], diagnostics: [] }),
|
|
17
|
+
getPrompts: () => ({ prompts: [], diagnostics: [] }),
|
|
18
|
+
getThemes: () => ({ themes: [], diagnostics: [] }),
|
|
19
|
+
getAgentsFiles: () => ({ agentsFiles: [] }),
|
|
20
|
+
getSystemPrompt: () => "You are OMK, a conversational coding assistant. No tools are available in this ACP profile.",
|
|
21
|
+
getAppendSystemPrompt: () => [],
|
|
22
|
+
extendResources: () => { },
|
|
23
|
+
reload: async () => { },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function createAcpSession(cwd, args) {
|
|
27
|
+
if (!(await stat(cwd)).isDirectory())
|
|
28
|
+
throw new AcpError(-32602, "cwd must be a directory");
|
|
29
|
+
const agentDir = getAgentDir();
|
|
30
|
+
const authStorage = AuthStorage.create(join(agentDir, "auth.json"));
|
|
31
|
+
const modelRegistry = ModelRegistry.create(authStorage, join(agentDir, "models.json"));
|
|
32
|
+
const selected = resolveCliModel({ cliModel: args.model, cliProvider: args.provider, modelRegistry });
|
|
33
|
+
if (selected.error)
|
|
34
|
+
throw new AcpError(-32602, "Model selection failed; check --model and --provider");
|
|
35
|
+
const model = selected.model ?? modelRegistry.getAvailable().find((m) => !args.provider || m.provider === args.provider);
|
|
36
|
+
if (!model)
|
|
37
|
+
throw new AcpError(-32000, "No model available; configure credentials using omk /login first");
|
|
38
|
+
const { session } = await createAgentSession({
|
|
39
|
+
cwd,
|
|
40
|
+
agentDir,
|
|
41
|
+
authStorage,
|
|
42
|
+
modelRegistry,
|
|
43
|
+
model,
|
|
44
|
+
modelPinned: true,
|
|
45
|
+
thinkingLevel: args.thinking ?? selected.thinkingLevel,
|
|
46
|
+
tools: [],
|
|
47
|
+
noTools: "all",
|
|
48
|
+
resourceLoader: emptyResources(),
|
|
49
|
+
sessionManager: SessionManager.inMemory(cwd),
|
|
50
|
+
settingsManager: SettingsManager.inMemory({ retry: { enabled: false } }),
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
async prompt(text, emit) {
|
|
54
|
+
const unsubscribe = session.subscribe((event) => {
|
|
55
|
+
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
56
|
+
emit(event.assistantMessageEvent.delta);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
try {
|
|
60
|
+
await session.prompt(text, { source: "rpc", expandPromptTemplates: false });
|
|
61
|
+
const kind = session.lastTermination?.kind;
|
|
62
|
+
if (kind === "user_abort" || kind === "provider_abort")
|
|
63
|
+
return "cancelled";
|
|
64
|
+
if (kind !== "completed")
|
|
65
|
+
throw new AcpError(-32603, "Prompt did not complete successfully");
|
|
66
|
+
return "end_turn";
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
unsubscribe();
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
cancel: () => session.abort(),
|
|
73
|
+
dispose: () => session.dispose(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=acp-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-session.js","sourceRoot":"","sources":["../../../src/modes/acp/acp-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC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,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC;QAC5C,eAAe,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;KACxE,CAAC,CAAC;IACH,OAAO;QACN,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE;YACxB,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;gBAChD,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,IAAI,KAAK,CAAC,qBAAqB,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAC1F,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBACzC,CAAC;YAAA,CACD,CAAC,CAAC;YACH,IAAI,CAAC;gBACJ,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC5E,MAAM,IAAI,GAAG,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC;gBAC3C,IAAI,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,gBAAgB;oBAAE,OAAO,WAAW,CAAC;gBAC3E,IAAI,IAAI,KAAK,WAAW;oBAAE,MAAM,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE,sCAAsC,CAAC,CAAC;gBAC7F,OAAO,UAAU,CAAC;YACnB,CAAC;oBAAS,CAAC;gBACV,WAAW,EAAE,CAAC;YACf,CAAC;QAAA,CACD;QACD,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE;QAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;KAChC,CAAC;AAAA,CACF","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type { Args } from \"../../cli/args.ts\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { AuthStorage } from \"../../core/auth-storage.ts\";\nimport { createExtensionRuntime } from \"../../core/extensions/loader.ts\";\nimport { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { resolveCliModel } from \"../../core/model-resolver.ts\";\nimport type { ResourceLoader } from \"../../core/resource-loader.ts\";\nimport { createAgentSession } from \"../../core/sdk.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { AcpError, type AcpSession } from \"./acp-agent.ts\";\n\n/** No discovery or client-requested executables in the restricted ACP profile. */\nfunction emptyResources(): ResourceLoader {\n\treturn {\n\t\tgetExtensions: () => ({ extensions: [], errors: [], runtime: createExtensionRuntime() }),\n\t\tgetSkills: () => ({ skills: [], diagnostics: [] }),\n\t\tgetPrompts: () => ({ prompts: [], diagnostics: [] }),\n\t\tgetThemes: () => ({ themes: [], diagnostics: [] }),\n\t\tgetAgentsFiles: () => ({ agentsFiles: [] }),\n\t\tgetSystemPrompt: () =>\n\t\t\t\"You are OMK, a conversational coding assistant. No tools are available in this ACP profile.\",\n\t\tgetAppendSystemPrompt: () => [],\n\t\textendResources: () => {},\n\t\treload: async () => {},\n\t};\n}\n\nexport async function createAcpSession(cwd: string, args: Args): Promise<AcpSession> {\n\tif (!(await stat(cwd)).isDirectory()) throw new AcpError(-32602, \"cwd must be a directory\");\n\tconst agentDir = getAgentDir();\n\tconst authStorage = AuthStorage.create(join(agentDir, \"auth.json\"));\n\tconst modelRegistry = ModelRegistry.create(authStorage, join(agentDir, \"models.json\"));\n\tconst selected = resolveCliModel({ cliModel: args.model, cliProvider: args.provider, modelRegistry });\n\tif (selected.error) throw new AcpError(-32602, \"Model selection failed; check --model and --provider\");\n\tconst model =\n\t\tselected.model ?? modelRegistry.getAvailable().find((m) => !args.provider || m.provider === args.provider);\n\tif (!model) throw new AcpError(-32000, \"No model available; configure credentials using omk /login first\");\n\tconst { session } = await createAgentSession({\n\t\tcwd,\n\t\tagentDir,\n\t\tauthStorage,\n\t\tmodelRegistry,\n\t\tmodel,\n\t\tmodelPinned: true,\n\t\tthinkingLevel: args.thinking ?? selected.thinkingLevel,\n\t\ttools: [],\n\t\tnoTools: \"all\",\n\t\tresourceLoader: emptyResources(),\n\t\tsessionManager: SessionManager.inMemory(cwd),\n\t\tsettingsManager: SettingsManager.inMemory({ retry: { enabled: false } }),\n\t});\n\treturn {\n\t\tasync prompt(text, emit) {\n\t\t\tconst unsubscribe = session.subscribe((event) => {\n\t\t\t\tif (event.type === \"message_update\" && event.assistantMessageEvent.type === \"text_delta\") {\n\t\t\t\t\temit(event.assistantMessageEvent.delta);\n\t\t\t\t}\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait session.prompt(text, { source: \"rpc\", expandPromptTemplates: false });\n\t\t\t\tconst kind = session.lastTermination?.kind;\n\t\t\t\tif (kind === \"user_abort\" || kind === \"provider_abort\") return \"cancelled\";\n\t\t\t\tif (kind !== \"completed\") throw new AcpError(-32603, \"Prompt did not complete successfully\");\n\t\t\t\treturn \"end_turn\";\n\t\t\t} finally {\n\t\t\t\tunsubscribe();\n\t\t\t}\n\t\t},\n\t\tcancel: () => session.abort(),\n\t\tdispose: () => session.dispose(),\n\t};\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Readable } from "node:stream";
|
|
2
|
+
import { type AcpSessionFactory } from "./acp-agent.ts";
|
|
3
|
+
/** LF-only JSON-RPC transport, bounded per frame and in-flight request set. */
|
|
4
|
+
export declare function serveAcp(input: Readable, output: (message: object) => void, createSession: AcpSessionFactory, version: string): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=acp-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-transport.d.ts","sourceRoot":"","sources":["../../../src/modes/acp/acp-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAsB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE5E,+EAA+E;AAC/E,wBAAsB,QAAQ,CAC7B,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,EACjC,aAAa,EAAE,iBAAiB,EAChC,OAAO,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAsFf","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport { AcpAgent, AcpError, type AcpSessionFactory } from \"./acp-agent.ts\";\n\n/** LF-only JSON-RPC transport, bounded per frame and in-flight request set. */\nexport async function serveAcp(\n\tinput: Readable,\n\toutput: (message: object) => void,\n\tcreateSession: AcpSessionFactory,\n\tversion: string,\n): Promise<void> {\n\tconst agent = new AcpAgent(createSession, version, output);\n\tconst pending = new Set<Promise<void>>();\n\tconst ids = new Set<string | number>();\n\tconst decoder = new StringDecoder(\"utf8\");\n\tlet buffer = \"\";\n\tconst maxBytes = 1024 * 1024;\n\tconst fail = (id: unknown, code: number, message: string) =>\n\t\toutput({ jsonrpc: \"2.0\", id, error: { code, message } });\n\tconst receive = (line: string): void => {\n\t\tlet raw: unknown;\n\t\ttry {\n\t\t\traw = JSON.parse(line);\n\t\t} catch {\n\t\t\tfail(null, -32700, \"Parse error\");\n\t\t\treturn;\n\t\t}\n\t\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\t\tfail(null, -32600, \"Invalid request\");\n\t\t\treturn;\n\t\t}\n\t\tconst request = raw as Record<string, unknown>;\n\t\tconst id = request.id;\n\t\tconst hasId = Object.hasOwn(request, \"id\");\n\t\tconst validId = typeof id === \"string\" || (typeof id === \"number\" && Number.isSafeInteger(id));\n\t\tif (request.jsonrpc !== \"2.0\" || typeof request.method !== \"string\" || (hasId && !validId)) {\n\t\t\tfail(validId ? id : null, -32600, \"Invalid request\");\n\t\t\treturn;\n\t\t}\n\t\t// Only cancellation is a notification. No session creation/provider call without a response ID.\n\t\tif (!hasId && request.method !== \"session/cancel\") return;\n\t\tif (hasId && validId && ids.has(id)) {\n\t\t\tfail(id, -32600, \"Duplicate in-flight id\");\n\t\t\treturn;\n\t\t}\n\t\tif (pending.size >= 32) {\n\t\t\tif (hasId) fail(id, -32000, \"Request limit reached\");\n\t\t\treturn;\n\t\t}\n\t\tif (validId) ids.add(id);\n\t\tconst work = agent\n\t\t\t.dispatch(request.method, request.params ?? {})\n\t\t\t.then(\n\t\t\t\t(result) => {\n\t\t\t\t\tif (hasId) output({ jsonrpc: \"2.0\", id, result });\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (hasId)\n\t\t\t\t\t\tfail(\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\terror instanceof AcpError ? error.code : -32603,\n\t\t\t\t\t\t\terror instanceof AcpError ? error.message : \"Agent operation failed\",\n\t\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t)\n\t\t\t.finally(() => {\n\t\t\t\tpending.delete(work);\n\t\t\t\tif (validId) ids.delete(id);\n\t\t\t});\n\t\tpending.add(work);\n\t};\n\ttry {\n\t\tfor await (const chunk of input) {\n\t\t\tbuffer += typeof chunk === \"string\" ? chunk : decoder.write(chunk);\n\t\t\tlet newline = buffer.indexOf(\"\\n\");\n\t\t\twhile (newline !== -1) {\n\t\t\t\tconst line = buffer.slice(0, newline);\n\t\t\t\tif (Buffer.byteLength(line) > maxBytes) throw new AcpError(-32600, \"Frame too large\");\n\t\t\t\treceive(line);\n\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\tnewline = buffer.indexOf(\"\\n\");\n\t\t\t}\n\t\t\tif (Buffer.byteLength(buffer) > maxBytes) throw new AcpError(-32600, \"Frame too large\");\n\t\t}\n\t\tbuffer += decoder.end();\n\t\tif (buffer.trim()) fail(null, -32700, \"Incomplete JSONL frame\");\n\t} catch (error) {\n\t\tfail(\n\t\t\tnull,\n\t\t\terror instanceof AcpError ? error.code : -32603,\n\t\t\terror instanceof AcpError ? error.message : \"Transport failed\",\n\t\t);\n\t} finally {\n\t\tawait agent.close();\n\t\tawait Promise.all(pending);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { StringDecoder } from "node:string_decoder";
|
|
2
|
+
import { AcpAgent, AcpError } from "./acp-agent.js";
|
|
3
|
+
/** LF-only JSON-RPC transport, bounded per frame and in-flight request set. */
|
|
4
|
+
export async function serveAcp(input, output, createSession, version) {
|
|
5
|
+
const agent = new AcpAgent(createSession, version, output);
|
|
6
|
+
const pending = new Set();
|
|
7
|
+
const ids = new Set();
|
|
8
|
+
const decoder = new StringDecoder("utf8");
|
|
9
|
+
let buffer = "";
|
|
10
|
+
const maxBytes = 1024 * 1024;
|
|
11
|
+
const fail = (id, code, message) => output({ jsonrpc: "2.0", id, error: { code, message } });
|
|
12
|
+
const receive = (line) => {
|
|
13
|
+
let raw;
|
|
14
|
+
try {
|
|
15
|
+
raw = JSON.parse(line);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
fail(null, -32700, "Parse error");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
22
|
+
fail(null, -32600, "Invalid request");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const request = raw;
|
|
26
|
+
const id = request.id;
|
|
27
|
+
const hasId = Object.hasOwn(request, "id");
|
|
28
|
+
const validId = typeof id === "string" || (typeof id === "number" && Number.isSafeInteger(id));
|
|
29
|
+
if (request.jsonrpc !== "2.0" || typeof request.method !== "string" || (hasId && !validId)) {
|
|
30
|
+
fail(validId ? id : null, -32600, "Invalid request");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Only cancellation is a notification. No session creation/provider call without a response ID.
|
|
34
|
+
if (!hasId && request.method !== "session/cancel")
|
|
35
|
+
return;
|
|
36
|
+
if (hasId && validId && ids.has(id)) {
|
|
37
|
+
fail(id, -32600, "Duplicate in-flight id");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (pending.size >= 32) {
|
|
41
|
+
if (hasId)
|
|
42
|
+
fail(id, -32000, "Request limit reached");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (validId)
|
|
46
|
+
ids.add(id);
|
|
47
|
+
const work = agent
|
|
48
|
+
.dispatch(request.method, request.params ?? {})
|
|
49
|
+
.then((result) => {
|
|
50
|
+
if (hasId)
|
|
51
|
+
output({ jsonrpc: "2.0", id, result });
|
|
52
|
+
}, (error) => {
|
|
53
|
+
if (hasId)
|
|
54
|
+
fail(id, error instanceof AcpError ? error.code : -32603, error instanceof AcpError ? error.message : "Agent operation failed");
|
|
55
|
+
})
|
|
56
|
+
.finally(() => {
|
|
57
|
+
pending.delete(work);
|
|
58
|
+
if (validId)
|
|
59
|
+
ids.delete(id);
|
|
60
|
+
});
|
|
61
|
+
pending.add(work);
|
|
62
|
+
};
|
|
63
|
+
try {
|
|
64
|
+
for await (const chunk of input) {
|
|
65
|
+
buffer += typeof chunk === "string" ? chunk : decoder.write(chunk);
|
|
66
|
+
let newline = buffer.indexOf("\n");
|
|
67
|
+
while (newline !== -1) {
|
|
68
|
+
const line = buffer.slice(0, newline);
|
|
69
|
+
if (Buffer.byteLength(line) > maxBytes)
|
|
70
|
+
throw new AcpError(-32600, "Frame too large");
|
|
71
|
+
receive(line);
|
|
72
|
+
buffer = buffer.slice(newline + 1);
|
|
73
|
+
newline = buffer.indexOf("\n");
|
|
74
|
+
}
|
|
75
|
+
if (Buffer.byteLength(buffer) > maxBytes)
|
|
76
|
+
throw new AcpError(-32600, "Frame too large");
|
|
77
|
+
}
|
|
78
|
+
buffer += decoder.end();
|
|
79
|
+
if (buffer.trim())
|
|
80
|
+
fail(null, -32700, "Incomplete JSONL frame");
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
fail(null, error instanceof AcpError ? error.code : -32603, error instanceof AcpError ? error.message : "Transport failed");
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
await agent.close();
|
|
87
|
+
await Promise.all(pending);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=acp-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-transport.js","sourceRoot":"","sources":["../../../src/modes/acp/acp-transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAA0B,MAAM,gBAAgB,CAAC;AAE5E,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,KAAe,EACf,MAAiC,EACjC,aAAgC,EAChC,OAAe,EACC;IAChB,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACzC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;IAC7B,MAAM,IAAI,GAAG,CAAC,EAAW,EAAE,IAAY,EAAE,OAAe,EAAE,EAAE,CAC3D,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,CAAC,IAAY,EAAQ,EAAE,CAAC;QACvC,IAAI,GAAY,CAAC;QACjB,IAAI,CAAC;YACJ,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACR,IAAI,CAAC,IAAI,EAAE,C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AAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBACtC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,QAAQ;oBAAE,MAAM,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;gBACtF,OAAO,CAAC,IAAI,CAAC,CAAC;gBACd,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;gBACnC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,QAAQ;gBAAE,MAAM,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;QACzF,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QACxB,IAAI,MAAM,CAAC,IAAI,EAAE;YAAE,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CACH,IAAI,EACJ,KAAK,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAC/C,KAAK,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAC9D,CAAC;IACH,CAAC;YAAS,CAAC;QACV,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;AAAA,CACD","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport { AcpAgent, AcpError, type AcpSessionFactory } from \"./acp-agent.ts\";\n\n/** LF-only JSON-RPC transport, bounded per frame and in-flight request set. */\nexport async function serveAcp(\n\tinput: Readable,\n\toutput: (message: object) => void,\n\tcreateSession: AcpSessionFactory,\n\tversion: string,\n): Promise<void> {\n\tconst agent = new AcpAgent(createSession, version, output);\n\tconst pending = new Set<Promise<void>>();\n\tconst ids = new Set<string | number>();\n\tconst decoder = new StringDecoder(\"utf8\");\n\tlet buffer = \"\";\n\tconst maxBytes = 1024 * 1024;\n\tconst fail = (id: unknown, code: number, message: string) =>\n\t\toutput({ jsonrpc: \"2.0\", id, error: { code, message } });\n\tconst receive = (line: string): void => {\n\t\tlet raw: unknown;\n\t\ttry {\n\t\t\traw = JSON.parse(line);\n\t\t} catch {\n\t\t\tfail(null, -32700, \"Parse error\");\n\t\t\treturn;\n\t\t}\n\t\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\t\tfail(null, -32600, \"Invalid request\");\n\t\t\treturn;\n\t\t}\n\t\tconst request = raw as Record<string, unknown>;\n\t\tconst id = request.id;\n\t\tconst hasId = Object.hasOwn(request, \"id\");\n\t\tconst validId = typeof id === \"string\" || (typeof id === \"number\" && Number.isSafeInteger(id));\n\t\tif (request.jsonrpc !== \"2.0\" || typeof request.method !== \"string\" || (hasId && !validId)) {\n\t\t\tfail(validId ? id : null, -32600, \"Invalid request\");\n\t\t\treturn;\n\t\t}\n\t\t// Only cancellation is a notification. No session creation/provider call without a response ID.\n\t\tif (!hasId && request.method !== \"session/cancel\") return;\n\t\tif (hasId && validId && ids.has(id)) {\n\t\t\tfail(id, -32600, \"Duplicate in-flight id\");\n\t\t\treturn;\n\t\t}\n\t\tif (pending.size >= 32) {\n\t\t\tif (hasId) fail(id, -32000, \"Request limit reached\");\n\t\t\treturn;\n\t\t}\n\t\tif (validId) ids.add(id);\n\t\tconst work = agent\n\t\t\t.dispatch(request.method, request.params ?? {})\n\t\t\t.then(\n\t\t\t\t(result) => {\n\t\t\t\t\tif (hasId) output({ jsonrpc: \"2.0\", id, result });\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (hasId)\n\t\t\t\t\t\tfail(\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\terror instanceof AcpError ? error.code : -32603,\n\t\t\t\t\t\t\terror instanceof AcpError ? error.message : \"Agent operation failed\",\n\t\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t)\n\t\t\t.finally(() => {\n\t\t\t\tpending.delete(work);\n\t\t\t\tif (validId) ids.delete(id);\n\t\t\t});\n\t\tpending.add(work);\n\t};\n\ttry {\n\t\tfor await (const chunk of input) {\n\t\t\tbuffer += typeof chunk === \"string\" ? chunk : decoder.write(chunk);\n\t\t\tlet newline = buffer.indexOf(\"\\n\");\n\t\t\twhile (newline !== -1) {\n\t\t\t\tconst line = buffer.slice(0, newline);\n\t\t\t\tif (Buffer.byteLength(line) > maxBytes) throw new AcpError(-32600, \"Frame too large\");\n\t\t\t\treceive(line);\n\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\tnewline = buffer.indexOf(\"\\n\");\n\t\t\t}\n\t\t\tif (Buffer.byteLength(buffer) > maxBytes) throw new AcpError(-32600, \"Frame too large\");\n\t\t}\n\t\tbuffer += decoder.end();\n\t\tif (buffer.trim()) fail(null, -32700, \"Incomplete JSONL frame\");\n\t} catch (error) {\n\t\tfail(\n\t\t\tnull,\n\t\t\terror instanceof AcpError ? error.code : -32603,\n\t\t\terror instanceof AcpError ? error.message : \"Transport failed\",\n\t\t);\n\t} finally {\n\t\tawait agent.close();\n\t\tawait Promise.all(pending);\n\t}\n}\n"]}
|