@zvada/agent-server 0.3.21 → 0.3.23
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 +332 -0
- package/README.md +2 -1
- package/dist/types/accounts/chatgpt.d.ts +1 -1
- package/dist/types/accounts/chatgpt.d.ts.map +1 -1
- package/dist/types/accounts/http.d.ts +2 -4
- package/dist/types/accounts/http.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +37 -11
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +66 -13
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/logins.d.ts +4 -3
- package/dist/types/client/logins.d.ts.map +1 -1
- package/dist/types/client/streams.d.ts +9 -3
- package/dist/types/client/streams.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +1 -1
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +12 -3
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +8 -2
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +22 -8
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +16 -5
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/events.d.ts +9 -1
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/login.d.ts +4 -1
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/models.d.ts +5 -1
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/options.d.ts +10 -4
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/results.d.ts +16 -0
- package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +50 -12
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts +21 -2
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +61 -14
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/homes.d.ts +26 -5
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts +4 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +45 -20
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/options.d.ts +32 -5
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/session.d.ts +70 -33
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn.d.ts +37 -8
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
- package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +3 -1
- package/dist/types/core/agents/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/diffs.d.ts +9 -0
- package/dist/types/core/agents/diffs.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +3 -2
- package/dist/types/core/agents/elicitation.d.ts.map +1 -1
- package/dist/types/core/agents/login.d.ts +6 -0
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/mcp-config.d.ts +0 -4
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
- package/dist/types/core/agents/plan.d.ts +2 -13
- package/dist/types/core/agents/plan.d.ts.map +1 -1
- package/dist/types/core/agents/process-pool.d.ts +193 -0
- package/dist/types/core/agents/process-pool.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
- package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
- package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/steps.d.ts +132 -0
- package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +49 -6
- package/dist/types/core/agents/session-agent.d.ts.map +1 -1
- package/dist/types/core/diagnostics.d.ts +4 -1
- package/dist/types/core/diagnostics.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +6 -1
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +32 -6
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/lifeline.d.ts +0 -20
- package/dist/types/core/processes/lifeline.d.ts.map +1 -1
- package/dist/types/core/provision/index.d.ts +2 -2
- package/dist/types/core/provision/index.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +2 -1
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/npm.d.ts +20 -8
- package/dist/types/core/provision/npm.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +4 -1
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +2 -1
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +18 -9
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +5 -1
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-clis.d.ts +9 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-logins.d.ts +33 -5
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
- package/dist/types/core/runtime/model-lists.d.ts +2 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
- package/dist/types/core/runtime/permission-policy.d.ts +5 -3
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
- package/dist/types/core/runtime/request-broker.d.ts +2 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts +14 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/core/utils/deadline.d.ts +6 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -1
- package/dist/types/core/utils/errors.d.ts +15 -1
- package/dist/types/core/utils/errors.d.ts.map +1 -1
- package/dist/types/operator/index.d.ts +11 -0
- package/dist/types/operator/index.d.ts.map +1 -0
- package/dist/types/operator/mcp.d.ts +33 -0
- package/dist/types/operator/mcp.d.ts.map +1 -0
- package/dist/types/operator/operator.d.ts +206 -0
- package/dist/types/operator/operator.d.ts.map +1 -0
- package/dist/types/operator/render.d.ts +89 -0
- package/dist/types/operator/render.d.ts.map +1 -0
- package/dist/types/operator/view.d.ts +44 -0
- package/dist/types/operator/view.d.ts.map +1 -0
- package/dist/types/protocol/auth.d.ts +54 -24
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +14 -7
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +2 -0
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +40 -3
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/credentials.d.ts +7 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +2 -1
- package/dist/types/protocol/execution.d.ts.map +1 -1
- package/dist/types/protocol/factories.d.ts +12 -2
- package/dist/types/protocol/factories.d.ts.map +1 -1
- package/dist/types/protocol/harness.d.ts +6 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +19 -0
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +47 -8
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/model-catalog.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/parts.d.ts +14 -0
- package/dist/types/protocol/parts.d.ts.map +1 -1
- package/dist/types/protocol/plan.d.ts +20 -0
- package/dist/types/protocol/plan.d.ts.map +1 -0
- package/dist/types/protocol/tool-state.d.ts +12 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +129 -23
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +70 -10
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/acp/binding.d.ts +6 -1
- package/dist/types/server/acp/binding.d.ts.map +1 -1
- package/dist/types/server/acp/translate.d.ts +33 -7
- package/dist/types/server/acp/translate.d.ts.map +1 -1
- package/dist/types/server/agent-server.d.ts +6 -0
- package/dist/types/server/agent-server.d.ts.map +1 -1
- package/dist/types/server/feedback.d.ts +2 -1
- package/dist/types/server/feedback.d.ts.map +1 -1
- package/dist/types/server/install.d.ts +11 -0
- package/dist/types/server/install.d.ts.map +1 -1
- package/dist/types/server/session-gate.d.ts +2 -1
- package/dist/types/server/session-gate.d.ts.map +1 -1
- package/dist/types/server/session-store.d.ts +1 -0
- package/dist/types/server/session-store.d.ts.map +1 -1
- package/dist/types/server/subscriptions.d.ts +2 -1
- package/dist/types/server/subscriptions.d.ts.map +1 -1
- package/dist/types/server/transports.d.ts.map +1 -1
- package/dist/types/sync/fit.d.ts +8 -7
- package/dist/types/sync/fit.d.ts.map +1 -1
- package/dist/types/sync/history-sqlite.d.ts.map +1 -1
- package/dist/types/sync/index.d.ts +1 -0
- package/dist/types/sync/index.d.ts.map +1 -1
- package/dist/types/sync/journal-sqlite.d.ts +2 -1
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
- package/dist/types/sync/journal.d.ts +11 -3
- package/dist/types/sync/journal.d.ts.map +1 -1
- package/dist/types/sync/projection.d.ts +6 -0
- package/dist/types/sync/projection.d.ts.map +1 -1
- package/dist/types/sync/recovery.d.ts +2 -1
- package/dist/types/sync/recovery.d.ts.map +1 -1
- package/dist/types/sync/schema.d.ts +10 -0
- package/dist/types/sync/schema.d.ts.map +1 -1
- package/dist/types/sync/sql.d.ts +2 -1
- package/dist/types/sync/sql.d.ts.map +1 -1
- package/dist/types/sync/worker.d.ts.map +1 -1
- package/docs/consuming.md +464 -40
- package/docs/deploy.md +36 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +396 -30
- package/package.json +11 -1
- package/src/accounts/chatgpt.ts +2 -2
- package/src/accounts/http.ts +2 -16
- package/src/client/client.ts +92 -31
- package/src/client/connection.ts +113 -22
- package/src/client/index.ts +1 -0
- package/src/client/logins.ts +24 -15
- package/src/client/streams.ts +12 -4
- package/src/client/turns.ts +1 -1
- package/src/core/agents/acp/acp-agent.ts +181 -52
- package/src/core/agents/acp/adapter.ts +9 -1
- package/src/core/agents/acp/client.ts +16 -4
- package/src/core/agents/acp/mappings.ts +27 -0
- package/src/core/agents/base.ts +25 -10
- package/src/core/agents/claude-code/adapter.ts +47 -17
- package/src/core/agents/claude-code/approvals.ts +6 -5
- package/src/core/agents/claude-code/claude-agent.ts +60 -30
- package/src/core/agents/claude-code/events.ts +11 -1
- package/src/core/agents/claude-code/login.ts +14 -2
- package/src/core/agents/claude-code/mcp.ts +31 -15
- package/src/core/agents/claude-code/models.ts +7 -2
- package/src/core/agents/claude-code/options.ts +11 -3
- package/src/core/agents/claude-code/outcome.ts +10 -2
- package/src/core/agents/claude-code/results.ts +73 -0
- package/src/core/agents/claude-code/sdk-pair.ts +66 -0
- package/src/core/agents/claude-code/session.ts +166 -37
- package/src/core/agents/claude-code/spend.ts +1 -1
- package/src/core/agents/claude-code/tools.ts +108 -12
- package/src/core/agents/codex-app-server/adapter.ts +37 -12
- package/src/core/agents/codex-app-server/client.ts +69 -10
- package/src/core/agents/codex-app-server/codex-agent.ts +141 -55
- package/src/core/agents/codex-app-server/commands.ts +2 -2
- package/src/core/agents/codex-app-server/credentials.ts +10 -5
- package/src/core/agents/codex-app-server/effort.ts +1 -1
- package/src/core/agents/codex-app-server/homes.ts +59 -10
- package/src/core/agents/codex-app-server/items.ts +219 -31
- package/src/core/agents/codex-app-server/login.ts +14 -2
- package/src/core/agents/codex-app-server/mcp.ts +142 -26
- package/src/core/agents/codex-app-server/models.ts +9 -8
- package/src/core/agents/codex-app-server/options.ts +79 -11
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/codex-app-server/protocol.ts +14 -4
- package/src/core/agents/codex-app-server/requests.ts +14 -6
- package/src/core/agents/codex-app-server/session.ts +156 -81
- package/src/core/agents/codex-app-server/subagents.ts +21 -14
- package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
- package/src/core/agents/codex-app-server/turn-items.ts +1 -1
- package/src/core/agents/codex-app-server/turn.ts +96 -35
- package/src/core/agents/codex-app-server/user-login.ts +107 -0
- package/src/core/agents/credentials.ts +5 -2
- package/src/core/agents/diffs.ts +25 -0
- package/src/core/agents/elicitation.ts +2 -2
- package/src/core/agents/login.ts +6 -0
- package/src/core/agents/mcp-config.ts +2 -2
- package/src/core/agents/plan.ts +3 -19
- package/src/core/agents/process-pool.ts +432 -0
- package/src/core/agents/scripted/adapter.ts +142 -0
- package/src/core/agents/scripted/mcp-call.ts +134 -0
- package/src/core/agents/scripted/scripted-agent.ts +418 -0
- package/src/core/agents/scripted/scripts.ts +171 -0
- package/src/core/agents/scripted/steps.ts +127 -0
- package/src/core/agents/session-agent.ts +105 -8
- package/src/core/diagnostics.ts +9 -1
- package/src/core/index.ts +12 -0
- package/src/core/presets.ts +99 -14
- package/src/core/processes/lifeline.ts +99 -25
- package/src/core/provision/index.ts +1 -2
- package/src/core/provision/install-build.ts +4 -1
- package/src/core/provision/npm.ts +309 -97
- package/src/core/provision/provisioner.ts +22 -8
- package/src/core/provision/tools.ts +44 -19
- package/src/core/runtime/agent-runtime.ts +70 -34
- package/src/core/runtime/event-processor.ts +18 -2
- package/src/core/runtime/harness-clis.ts +36 -1
- package/src/core/runtime/harness-logins.ts +82 -31
- package/src/core/runtime/model-lists.ts +1 -1
- package/src/core/runtime/permission-policy.ts +4 -3
- package/src/core/runtime/request-broker.ts +1 -1
- package/src/core/runtime/turn.ts +53 -3
- package/src/core/utils/deadline.ts +23 -0
- package/src/core/utils/errors.ts +24 -4
- package/src/operator/index.ts +40 -0
- package/src/operator/mcp.ts +171 -0
- package/src/operator/operator.ts +782 -0
- package/src/operator/render.ts +473 -0
- package/src/operator/view.ts +82 -0
- package/src/protocol/auth.ts +30 -23
- package/src/protocol/clis.ts +12 -4
- package/src/protocol/credentials.ts +19 -0
- package/src/protocol/execution.ts +5 -0
- package/src/protocol/factories.ts +25 -3
- package/src/protocol/harness.ts +11 -1
- package/src/protocol/history.ts +20 -0
- package/src/protocol/lifecycle.ts +10 -1
- package/src/protocol/model-catalog.ts +19 -8
- package/src/protocol/parts.ts +12 -1
- package/src/protocol/plan.ts +35 -0
- package/src/protocol/tool-state.ts +14 -1
- package/src/protocol/wire.ts +14 -0
- package/src/server/acp/binding.ts +113 -22
- package/src/server/acp/translate.ts +161 -8
- package/src/server/agent-server.ts +10 -1
- package/src/server/bin.ts +83 -9
- package/src/server/feedback.ts +1 -1
- package/src/server/install.ts +82 -4
- package/src/server/session-gate.ts +1 -1
- package/src/server/session-store.ts +5 -1
- package/src/server/subscriptions.ts +1 -1
- package/src/server/transports.ts +14 -0
- package/src/sync/fit.ts +115 -28
- package/src/sync/history-sqlite.ts +6 -2
- package/src/sync/index.ts +1 -0
- package/src/sync/journal-sqlite.ts +20 -2
- package/src/sync/journal.ts +10 -2
- package/src/sync/projection.ts +10 -0
- package/src/sync/recovery.ts +11 -4
- package/src/sync/schema.ts +7 -5
- package/src/sync/sql.ts +1 -1
- package/src/sync/worker.ts +4 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
- package/dist/types/core/agents/session-pool.d.ts +0 -41
- package/dist/types/core/agents/session-pool.d.ts.map +0 -1
- package/src/core/agents/claude-code/session-pool.ts +0 -136
- package/src/core/agents/session-pool.ts +0 -111
package/src/core/runtime/turn.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AgentHarness,
|
|
3
|
+
AgentInput,
|
|
3
4
|
ErrorInfo,
|
|
4
5
|
LifecycleEvent,
|
|
6
|
+
RunConfig,
|
|
5
7
|
RunRequest,
|
|
6
8
|
StopReason,
|
|
7
9
|
ThinkingLevel,
|
|
@@ -59,6 +61,8 @@ export interface SessionMemory {
|
|
|
59
61
|
announcedNative?: string;
|
|
60
62
|
/** Its recently settled turns, oldest first: a retry converges on one. */
|
|
61
63
|
readonly settled: Map<string, SettledTurn>;
|
|
64
|
+
/** The turns that fell out of `settled`, by id: a retry of one is refused, never run again. */
|
|
65
|
+
readonly forgotten: Set<string>;
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
/** What the runtime lends its turns. */
|
|
@@ -77,6 +81,46 @@ export interface TurnHost {
|
|
|
77
81
|
|
|
78
82
|
const CANCEL = { decision: "cancel" } as const;
|
|
79
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Whether a turn sets a field: a value, but a boolean only when `true`, a
|
|
86
|
+
* string only when it is not empty, and an array or a record only when it
|
|
87
|
+
* holds something; the others mean the same as unset.
|
|
88
|
+
*/
|
|
89
|
+
function setsField(config: RunConfig, field: string): boolean {
|
|
90
|
+
const value = (config as Record<string, unknown>)[field];
|
|
91
|
+
if (value === undefined || value === false || value === "") return false;
|
|
92
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
93
|
+
if (typeof value === "object" && value !== null) return Object.keys(value).length > 0;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The settings a turn set that its harness never applies. */
|
|
98
|
+
export function ignoredSettingsOf(config: RunConfig, ignored: readonly string[] = []): string[] {
|
|
99
|
+
return ignored.filter((field) => setsField(config, field));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// @ref LLP 0013#f12-a-lone-surrogate-hung-codex — no agent is given text it cannot read
|
|
103
|
+
/**
|
|
104
|
+
* Input as an agent is given it: every string of it well-formed, a lone
|
|
105
|
+
* UTF-16 surrogate (a string cut in the middle of an emoji) made U+FFFD.
|
|
106
|
+
* Codex cannot read a line that carries one and never answers it. The user
|
|
107
|
+
* echo is made of the caller's own input, not this (LLP 0002, The user echo
|
|
108
|
+
* comes first). A text element's byte range still holds: UTF-8 writes a lone
|
|
109
|
+
* surrogate as U+FFFD, three bytes.
|
|
110
|
+
*/
|
|
111
|
+
export function wellFormedInput(input: AgentInput): AgentInput {
|
|
112
|
+
if (typeof input === "string") return input.toWellFormed();
|
|
113
|
+
return input.map(
|
|
114
|
+
(part) =>
|
|
115
|
+
Object.fromEntries(
|
|
116
|
+
Object.entries(part).map(([key, value]) => [
|
|
117
|
+
key,
|
|
118
|
+
typeof value === "string" ? value.toWellFormed() : value,
|
|
119
|
+
]),
|
|
120
|
+
) as typeof part,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
80
124
|
/**
|
|
81
125
|
* One admitted turn, from admission until it settles. It executes the request
|
|
82
126
|
* on its harness, streams what the harness does through the processor to its
|
|
@@ -166,22 +210,28 @@ export class Turn {
|
|
|
166
210
|
config.model,
|
|
167
211
|
);
|
|
168
212
|
|
|
213
|
+
// @ref LLP 0001#d22--a-turn-says-what-it-did-not-apply — up front, then as the harness finds out
|
|
214
|
+
const notApplied = ignoredSettingsOf(config, agent.capabilities.ignoredSettings);
|
|
215
|
+
this.processor.markNotApplied(notApplied);
|
|
169
216
|
await this.emit({
|
|
170
217
|
type: "turn.started",
|
|
171
218
|
turnId,
|
|
172
219
|
sessionId,
|
|
173
|
-
execution: this.execution,
|
|
220
|
+
execution: { ...this.execution, ...(notApplied.length && { notApplied }) },
|
|
174
221
|
timestamp: Date.now(),
|
|
175
222
|
});
|
|
176
223
|
// @ref LLP 0002#the-user-echo-comes-first — before any harness output
|
|
177
224
|
// The user echo: the submitted input goes back onto the stream as a
|
|
178
225
|
// complete user message (outputIndex 0) before any harness output, so
|
|
179
|
-
// the stream is a complete transcript and multi-client attach works.
|
|
226
|
+
// the stream is a complete transcript and multi-client attach works. It is
|
|
227
|
+
// the caller's input as sent, which the caller can predict; the agent is
|
|
228
|
+
// given it well-formed (`wellFormedInput`).
|
|
180
229
|
for (const event of this.processor.echoUserMessage(input)) await this.emit(event);
|
|
181
230
|
|
|
182
231
|
let threw: TurnThrew | undefined;
|
|
183
232
|
try {
|
|
184
|
-
|
|
233
|
+
const given = wellFormedInput(input);
|
|
234
|
+
for await (const raw of agent.execute(given, this.agentOptions(modelThinking))) {
|
|
185
235
|
await this.announceNativeSession();
|
|
186
236
|
if (config.includeRaw) {
|
|
187
237
|
await this.emit({
|
|
@@ -21,6 +21,29 @@ export async function withTimeout<T>(
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Wait for `promise` until `signal` aborts: its value, or the signal's reason
|
|
26
|
+
* thrown once the signal aborts first. Only the wait ends: the work goes on
|
|
27
|
+
* for whoever else waits for it. Without a signal it waits for the work.
|
|
28
|
+
*/
|
|
29
|
+
export async function untilAborted<T>(
|
|
30
|
+
promise: Promise<T>,
|
|
31
|
+
signal: AbortSignal | undefined,
|
|
32
|
+
): Promise<T> {
|
|
33
|
+
if (!signal) return await promise;
|
|
34
|
+
let off = () => {};
|
|
35
|
+
try {
|
|
36
|
+
return await Promise.race([
|
|
37
|
+
promise,
|
|
38
|
+
new Promise<never>((_, reject) => {
|
|
39
|
+
off = onAbort(signal, () => reject(signal.reason));
|
|
40
|
+
}),
|
|
41
|
+
]);
|
|
42
|
+
} finally {
|
|
43
|
+
off();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
/**
|
|
25
48
|
* Run `fn` once `signal` aborts, or at once if it already has. Returns what
|
|
26
49
|
* removes it again. Without a signal it never runs.
|
package/src/core/utils/errors.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { type ErrorCategory, classifyError } from "../../protocol/index.ts";
|
|
|
4
4
|
* Appended to setup/integration errors only — the moments a coding agent
|
|
5
5
|
* integrating this package is most likely holding actionable friction. Runtime
|
|
6
6
|
* failures stay clean: they are usually the harness's or the caller's problem,
|
|
7
|
-
* and hinting there would train agents to file noise.
|
|
7
|
+
* and hinting there would train agents to file noise. Installing a CLI is one
|
|
8
|
+
* since the engine installs during a turn and at `clis/prepare` (LLP 0010):
|
|
9
|
+
* its failure reaches a product's users, on the stream and in `clis/*`.
|
|
8
10
|
*/
|
|
9
11
|
function feedbackHint(category: string, subject: string): string {
|
|
10
12
|
return `\nAI agent? Report this agent-server friction: npx --yes hivenet@latest --to agent-server --category ${category} --subject "${subject}" --message "<what you tried and what you expected>"`;
|
|
@@ -65,6 +67,19 @@ export class TurnConflictError extends AgentServerError {
|
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
/**
|
|
71
|
+
* A turn id the session already ran, whose answer the runtime no longer keeps
|
|
72
|
+
* (a volatile session remembers its last 16 turns): a retry this late cannot
|
|
73
|
+
* converge, and is never run a second time. The wire's `turnConflict`.
|
|
74
|
+
*/
|
|
75
|
+
export class TurnForgottenError extends TurnConflictError {
|
|
76
|
+
constructor(sessionId: string, turnId: string) {
|
|
77
|
+
super(sessionId, turnId);
|
|
78
|
+
this.message = `turn ${turnId} on session ${sessionId} already ran, and its answer is no longer kept: send new input as a new turn`;
|
|
79
|
+
this.name = "TurnForgottenError";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
68
83
|
/**
|
|
69
84
|
* A turn's request that `RunRequestSchema` refuses: it never runs. The wire
|
|
70
85
|
* refuses the same request as `invalidParams` before it reaches the engine.
|
|
@@ -178,10 +193,15 @@ export class CliNotFoundError extends AgentServerError {
|
|
|
178
193
|
}
|
|
179
194
|
}
|
|
180
195
|
|
|
181
|
-
/**
|
|
196
|
+
/**
|
|
197
|
+
* Managed CLI provisioning failed (download, integrity, or a bad override).
|
|
198
|
+
* `category` says what failed where the install knows (`network` for a
|
|
199
|
+
* registry that cannot be reached or answers 5xx, and for a cut transfer);
|
|
200
|
+
* otherwise its message is classified. `clis/*` and the turn carry it alike.
|
|
201
|
+
*/
|
|
182
202
|
export class CliProvisionError extends AgentServerError {
|
|
183
|
-
constructor(message: string, options?: { cause?: unknown }) {
|
|
184
|
-
super(
|
|
203
|
+
constructor(message: string, options?: { cause?: unknown; category?: ErrorCategory }) {
|
|
204
|
+
super(message, "cliProvisionFailed", options?.category);
|
|
185
205
|
this.name = "CliProvisionError";
|
|
186
206
|
if (options?.cause !== undefined) this.cause = options.cause;
|
|
187
207
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@zvada/agent-server/operator`: the session tools an outside agent operates a
|
|
3
|
+
* product's coding agents with, and their MCP binding. Imports only the
|
|
4
|
+
* protocol and zod; the product is the `OperatorHost` (LLP 0014).
|
|
5
|
+
*/
|
|
6
|
+
export { PLAN_OPTIONS, PLAN_TITLE } from "../protocol/plan.ts";
|
|
7
|
+
export {
|
|
8
|
+
type McpHandler,
|
|
9
|
+
type McpServerInfo,
|
|
10
|
+
type ToolSource,
|
|
11
|
+
createMcpHandler,
|
|
12
|
+
} from "./mcp.ts";
|
|
13
|
+
export {
|
|
14
|
+
type Operator,
|
|
15
|
+
type OperatorClock,
|
|
16
|
+
type OperatorHost,
|
|
17
|
+
type OperatorOptions,
|
|
18
|
+
type SendOptions,
|
|
19
|
+
type SendResult,
|
|
20
|
+
type SessionEntry,
|
|
21
|
+
type StartInput,
|
|
22
|
+
type StartResult,
|
|
23
|
+
type Tool,
|
|
24
|
+
type ToolInfo,
|
|
25
|
+
type ViewOptions,
|
|
26
|
+
OperatorError,
|
|
27
|
+
createOperator,
|
|
28
|
+
tool,
|
|
29
|
+
} from "./operator.ts";
|
|
30
|
+
export { type Answer, callHint, oneLine, quote, quoted } from "./render.ts";
|
|
31
|
+
export {
|
|
32
|
+
type DecisionRequest,
|
|
33
|
+
type Phase,
|
|
34
|
+
type QuestionRequest,
|
|
35
|
+
type SessionView,
|
|
36
|
+
type ViewMessage,
|
|
37
|
+
type Waiting,
|
|
38
|
+
phaseOf,
|
|
39
|
+
viewOf,
|
|
40
|
+
} from "./view.ts";
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The operator tools over MCP, with no dependency: one function answers one
|
|
3
|
+
* JSON-RPC message (or a batch) of the Model Context Protocol's tool surface.
|
|
4
|
+
*
|
|
5
|
+
* It serves stateless Streamable HTTP. A product's route parses the POST
|
|
6
|
+
* body, calls the handler with the caller it authenticated, and answers
|
|
7
|
+
* `200 application/json` with the result, or `202` with no body when the
|
|
8
|
+
* result is null (a notification). It answers GET with `405`: the server
|
|
9
|
+
* never opens a stream of its own.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// @ref LLP 0014#the-mcp-binding — the engine answers MCP's tool methods; the route, its authentication and its caller are the host's
|
|
13
|
+
|
|
14
|
+
import { OperatorError, type ToolInfo } from "./operator.ts";
|
|
15
|
+
import { quoted } from "./render.ts";
|
|
16
|
+
|
|
17
|
+
/** Anything that lists and runs tools: an operator, or a host's wrapper around one. */
|
|
18
|
+
export interface ToolSource<Caller> {
|
|
19
|
+
tools(caller: Caller): ToolInfo[];
|
|
20
|
+
call(name: string, args: unknown, caller: Caller): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface McpServerInfo {
|
|
24
|
+
name: string;
|
|
25
|
+
version: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
/** Words for the client's model about how to use the server. */
|
|
28
|
+
instructions?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The MCP protocol versions this binding answers, newest first: the list the
|
|
33
|
+
* official SDK (`@modelcontextprotocol/sdk` 1.32, `SUPPORTED_PROTOCOL_VERSIONS`
|
|
34
|
+
* in its `types.js`) accepts. The tool methods used here are the same in each.
|
|
35
|
+
*/
|
|
36
|
+
export const MCP_PROTOCOL_VERSIONS = [
|
|
37
|
+
"2025-11-25",
|
|
38
|
+
"2025-06-18",
|
|
39
|
+
"2025-03-26",
|
|
40
|
+
"2024-11-05",
|
|
41
|
+
"2024-10-07",
|
|
42
|
+
] as const;
|
|
43
|
+
|
|
44
|
+
/** The most messages one batch may hold. */
|
|
45
|
+
const MAX_BATCH = 20;
|
|
46
|
+
|
|
47
|
+
export type McpHandler<Caller> = (message: unknown, caller: Caller) => Promise<unknown | null>;
|
|
48
|
+
|
|
49
|
+
type Id = string | number | null;
|
|
50
|
+
const ok = (id: Id, result: unknown) => ({ jsonrpc: "2.0" as const, id, result });
|
|
51
|
+
const fail = (id: Id, code: number, message: string) => ({
|
|
52
|
+
jsonrpc: "2.0" as const,
|
|
53
|
+
id,
|
|
54
|
+
error: { code, message },
|
|
55
|
+
});
|
|
56
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
57
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
|
+
const text = (value: string, isError?: boolean) => ({
|
|
59
|
+
content: [{ type: "text", text: value }],
|
|
60
|
+
...(isError ? { isError: true } : {}),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** Answer one MCP JSON-RPC message (or batch array). Returns the response, or null for a notification. */
|
|
64
|
+
export function createMcpHandler<Caller>(
|
|
65
|
+
source: ToolSource<Caller>,
|
|
66
|
+
info: McpServerInfo,
|
|
67
|
+
): McpHandler<Caller> {
|
|
68
|
+
const serverInfo = {
|
|
69
|
+
name: info.name,
|
|
70
|
+
version: info.version,
|
|
71
|
+
...(info.title ? { title: info.title } : {}),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
async function one(message: unknown, caller: Caller): Promise<unknown | null> {
|
|
75
|
+
if (!isRecord(message) || message.jsonrpc !== "2.0") {
|
|
76
|
+
return fail(isRecord(message) ? idOf(message) : null, -32600, "Invalid Request");
|
|
77
|
+
}
|
|
78
|
+
// A response to a request this server never sent, or a notification: nothing to answer.
|
|
79
|
+
if (typeof message.method !== "string") {
|
|
80
|
+
return "id" in message && ("result" in message || "error" in message)
|
|
81
|
+
? null
|
|
82
|
+
: fail(idOf(message), -32600, "Invalid Request");
|
|
83
|
+
}
|
|
84
|
+
if (!("id" in message)) return null;
|
|
85
|
+
const id = idOf(message);
|
|
86
|
+
const params = isRecord(message.params) ? message.params : {};
|
|
87
|
+
switch (message.method) {
|
|
88
|
+
case "initialize": {
|
|
89
|
+
const asked = params.protocolVersion;
|
|
90
|
+
const protocolVersion =
|
|
91
|
+
MCP_PROTOCOL_VERSIONS.find((v) => v === asked) ?? MCP_PROTOCOL_VERSIONS[0];
|
|
92
|
+
return ok(id, {
|
|
93
|
+
protocolVersion,
|
|
94
|
+
capabilities: { tools: { listChanged: false } },
|
|
95
|
+
serverInfo,
|
|
96
|
+
...(info.instructions ? { instructions: info.instructions } : {}),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
case "ping":
|
|
100
|
+
return ok(id, {});
|
|
101
|
+
case "tools/list": {
|
|
102
|
+
try {
|
|
103
|
+
const tools = source.tools(caller);
|
|
104
|
+
return ok(id, {
|
|
105
|
+
tools: tools.map((tool) => ({
|
|
106
|
+
name: tool.name,
|
|
107
|
+
title: tool.title,
|
|
108
|
+
description: tool.description,
|
|
109
|
+
inputSchema: tool.inputSchema,
|
|
110
|
+
annotations: {
|
|
111
|
+
title: tool.title,
|
|
112
|
+
readOnlyHint: tool.readOnly,
|
|
113
|
+
destructiveHint: tool.destructive === true,
|
|
114
|
+
openWorldHint: tool.openWorld === true,
|
|
115
|
+
},
|
|
116
|
+
})),
|
|
117
|
+
});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return fail(id, -32603, messageOf(error));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
case "tools/call": {
|
|
123
|
+
if (typeof params.name !== "string" || !params.name) {
|
|
124
|
+
return fail(id, -32602, "tools/call needs the tool's name");
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return ok(id, text(await source.call(params.name, params.arguments ?? {}, caller)));
|
|
128
|
+
} catch (error) {
|
|
129
|
+
// The model reads the reason and can act on it; a JSON-RPC error it would not see.
|
|
130
|
+
// A refusal's words are meant for it; any other failure's may be an agent's or a
|
|
131
|
+
// repository's, so it is one quoted line, never a line that reads as a hint.
|
|
132
|
+
return ok(
|
|
133
|
+
id,
|
|
134
|
+
text(
|
|
135
|
+
error instanceof OperatorError
|
|
136
|
+
? error.message
|
|
137
|
+
: `The tool failed: ${quoted(messageOf(error))}`,
|
|
138
|
+
true,
|
|
139
|
+
),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
return fail(id, -32601, `Method not found: ${message.method}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return async (message, caller) => {
|
|
149
|
+
if (!Array.isArray(message)) return one(message, caller);
|
|
150
|
+
if (!message.length) return fail(null, -32600, "Invalid Request: empty batch");
|
|
151
|
+
if (message.length > MAX_BATCH) {
|
|
152
|
+
return fail(null, -32600, `Invalid Request: a batch holds at most ${MAX_BATCH} messages`);
|
|
153
|
+
}
|
|
154
|
+
// One after another: a batch is never more calls at once than one message.
|
|
155
|
+
const replies: unknown[] = [];
|
|
156
|
+
for (const each of message) {
|
|
157
|
+
const answer = await one(each, caller);
|
|
158
|
+
if (answer !== null) replies.push(answer);
|
|
159
|
+
}
|
|
160
|
+
return replies.length ? replies : null;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function idOf(message: Record<string, unknown>): Id {
|
|
165
|
+
const id = message.id;
|
|
166
|
+
return typeof id === "string" || typeof id === "number" ? id : null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function messageOf(error: unknown): string {
|
|
170
|
+
return error instanceof Error ? error.message : String(error);
|
|
171
|
+
}
|