@zvada/agent-server 0.3.17 → 0.3.19
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/AGENTS.md +11 -26
- package/CHANGELOG.md +1060 -0
- package/README.md +50 -26
- package/dist/types/accounts/chatgpt.d.ts +34 -0
- package/dist/types/accounts/chatgpt.d.ts.map +1 -0
- package/dist/types/accounts/check.d.ts +24 -0
- package/dist/types/accounts/check.d.ts.map +1 -0
- package/dist/types/accounts/claude.d.ts +21 -0
- package/dist/types/accounts/claude.d.ts.map +1 -0
- package/dist/types/accounts/endpoint.d.ts +50 -0
- package/dist/types/accounts/endpoint.d.ts.map +1 -0
- package/dist/types/accounts/http.d.ts +38 -0
- package/dist/types/accounts/http.d.ts.map +1 -0
- package/dist/types/accounts/index.d.ts +6 -0
- package/dist/types/accounts/index.d.ts.map +1 -0
- package/dist/types/client/client.d.ts +272 -0
- package/dist/types/client/client.d.ts.map +1 -0
- package/dist/types/client/connection.d.ts +160 -0
- package/dist/types/client/connection.d.ts.map +1 -0
- package/dist/types/client/history.d.ts +8 -0
- package/dist/types/client/history.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +5 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/listeners.d.ts +8 -0
- package/dist/types/client/listeners.d.ts.map +1 -0
- package/dist/types/client/logins.d.ts +35 -0
- package/dist/types/client/logins.d.ts.map +1 -0
- package/dist/types/client/rpc.d.ts +46 -0
- package/dist/types/client/rpc.d.ts.map +1 -0
- package/dist/types/client/streams.d.ts +150 -0
- package/dist/types/client/streams.d.ts.map +1 -0
- package/dist/types/client/transports.d.ts +35 -0
- package/dist/types/client/transports.d.ts.map +1 -0
- package/dist/types/client/turns.d.ts +81 -0
- package/dist/types/client/turns.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
- package/dist/types/core/agents/acp/adapter.d.ts +39 -0
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/acp/client.d.ts +90 -0
- package/dist/types/core/agents/acp/client.d.ts.map +1 -0
- package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
- package/dist/types/core/agents/acp/mappings.d.ts +46 -0
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +26 -0
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
- package/dist/types/core/agents/attachments.d.ts +11 -0
- package/dist/types/core/agents/attachments.d.ts.map +1 -0
- package/dist/types/core/agents/base.d.ts +227 -0
- package/dist/types/core/agents/base.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/events.d.ts +42 -0
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/login.d.ts +61 -0
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/models.d.ts +30 -0
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/options.d.ts +183 -0
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +148 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
- package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
- package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
- package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +28 -0
- package/dist/types/core/agents/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +37 -0
- package/dist/types/core/agents/elicitation.d.ts.map +1 -0
- package/dist/types/core/agents/inherit-config.d.ts +18 -0
- package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +67 -0
- package/dist/types/core/agents/login.d.ts.map +1 -0
- package/dist/types/core/agents/mcp-config.d.ts +57 -0
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
- package/dist/types/core/agents/plan.d.ts +16 -0
- package/dist/types/core/agents/plan.d.ts.map +1 -0
- package/dist/types/core/agents/registry.d.ts +30 -0
- package/dist/types/core/agents/registry.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +48 -0
- package/dist/types/core/agents/session-agent.d.ts.map +1 -0
- package/dist/types/core/agents/session-pool.d.ts +41 -0
- package/dist/types/core/agents/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/stderr-tail.d.ts +28 -0
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
- package/dist/types/core/agents/thinking-levels.d.ts +4 -0
- package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
- package/dist/types/core/agents/types.d.ts +124 -0
- package/dist/types/core/agents/types.d.ts.map +1 -0
- package/dist/types/core/diagnostics.d.ts +36 -0
- package/dist/types/core/diagnostics.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +29 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/presets.d.ts +80 -0
- package/dist/types/core/presets.d.ts.map +1 -0
- package/dist/types/core/processes/identity.d.ts +31 -0
- package/dist/types/core/processes/identity.d.ts.map +1 -0
- package/dist/types/core/processes/lifeline.d.ts +47 -0
- package/dist/types/core/processes/lifeline.d.ts.map +1 -0
- package/dist/types/core/processes/native-processes.d.ts +130 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -0
- package/dist/types/core/processes/process-table.d.ts +43 -0
- package/dist/types/core/processes/process-table.d.ts.map +1 -0
- package/dist/types/core/provision/cache-trust.d.ts +13 -0
- package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
- package/dist/types/core/provision/cache-usage.d.ts +14 -0
- package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
- package/dist/types/core/provision/checksums.d.ts +46 -0
- package/dist/types/core/provision/checksums.d.ts.map +1 -0
- package/dist/types/core/provision/extract.d.ts +7 -0
- package/dist/types/core/provision/extract.d.ts.map +1 -0
- package/dist/types/core/provision/index.d.ts +5 -0
- package/dist/types/core/provision/index.d.ts.map +1 -0
- package/dist/types/core/provision/install-build.d.ts +36 -0
- package/dist/types/core/provision/install-build.d.ts.map +1 -0
- package/dist/types/core/provision/npm.d.ts +40 -0
- package/dist/types/core/provision/npm.d.ts.map +1 -0
- package/dist/types/core/provision/pins.d.ts +24 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -0
- package/dist/types/core/provision/platform.d.ts +28 -0
- package/dist/types/core/provision/platform.d.ts.map +1 -0
- package/dist/types/core/provision/provisioner.d.ts +189 -0
- package/dist/types/core/provision/provisioner.d.ts.map +1 -0
- package/dist/types/core/provision/releases.d.ts +8 -0
- package/dist/types/core/provision/releases.d.ts.map +1 -0
- package/dist/types/core/provision/tools.d.ts +81 -0
- package/dist/types/core/provision/tools.d.ts.map +1 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
- package/dist/types/core/proxy/api-key-store.d.ts +37 -0
- package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
- package/dist/types/core/proxy/index.d.ts +3 -0
- package/dist/types/core/proxy/index.d.ts.map +1 -0
- package/dist/types/core/proxy/loopback.d.ts +14 -0
- package/dist/types/core/proxy/loopback.d.ts.map +1 -0
- package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
- package/dist/types/core/runtime/event-processor.d.ts +87 -0
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
- package/dist/types/core/runtime/event-sink.d.ts +44 -0
- package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-clis.d.ts +10 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-logins.d.ts +68 -0
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
- package/dist/types/core/runtime/login-reads.d.ts +28 -0
- package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
- package/dist/types/core/runtime/model-lists.d.ts +37 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
- package/dist/types/core/runtime/permission-policy.d.ts +61 -0
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +49 -0
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
- package/dist/types/core/runtime/steering.d.ts +38 -0
- package/dist/types/core/runtime/steering.d.ts.map +1 -0
- package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
- package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
- package/dist/types/core/runtime/turn.d.ts +121 -0
- package/dist/types/core/runtime/turn.d.ts.map +1 -0
- package/dist/types/core/utils/bounded.d.ts +6 -0
- package/dist/types/core/utils/bounded.d.ts.map +1 -0
- package/dist/types/core/utils/deadline.d.ts +14 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -0
- package/dist/types/core/utils/errors.d.ts +104 -0
- package/dist/types/core/utils/errors.d.ts.map +1 -0
- package/dist/types/core/utils/is-record.d.ts +3 -0
- package/dist/types/core/utils/is-record.d.ts.map +1 -0
- package/dist/types/core/utils/loopback.d.ts +6 -0
- package/dist/types/core/utils/loopback.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/account.d.ts +26 -0
- package/dist/types/protocol/account.d.ts.map +1 -0
- package/dist/types/protocol/async-queue.d.ts +21 -0
- package/dist/types/protocol/async-queue.d.ts.map +1 -0
- package/dist/types/protocol/auth.d.ts +228 -0
- package/dist/types/protocol/auth.d.ts.map +1 -0
- package/dist/types/protocol/canonical.d.ts +9 -0
- package/dist/types/protocol/canonical.d.ts.map +1 -0
- package/dist/types/protocol/clis.d.ts +74 -0
- package/dist/types/protocol/clis.d.ts.map +1 -0
- package/dist/types/protocol/config.d.ts +200 -0
- package/dist/types/protocol/config.d.ts.map +1 -0
- package/dist/types/protocol/conversation.d.ts +942 -0
- package/dist/types/protocol/conversation.d.ts.map +1 -0
- package/dist/types/protocol/credentials.d.ts +145 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -0
- package/dist/types/protocol/errors.d.ts +36 -0
- package/dist/types/protocol/errors.d.ts.map +1 -0
- package/dist/types/protocol/execution.d.ts +28 -0
- package/dist/types/protocol/execution.d.ts.map +1 -0
- package/dist/types/protocol/factories.d.ts +94 -0
- package/dist/types/protocol/factories.d.ts.map +1 -0
- package/dist/types/protocol/guards.d.ts +55 -0
- package/dist/types/protocol/guards.d.ts.map +1 -0
- package/dist/types/protocol/harness.d.ts +70 -0
- package/dist/types/protocol/harness.d.ts.map +1 -0
- package/dist/types/protocol/history.d.ts +318 -0
- package/dist/types/protocol/history.d.ts.map +1 -0
- package/dist/types/protocol/ids.d.ts +9 -0
- package/dist/types/protocol/ids.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +35 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/lifecycle.d.ts +1190 -0
- package/dist/types/protocol/lifecycle.d.ts.map +1 -0
- package/dist/types/protocol/meta-keys.d.ts +17 -0
- package/dist/types/protocol/meta-keys.d.ts.map +1 -0
- package/dist/types/protocol/meta.d.ts +13 -0
- package/dist/types/protocol/meta.d.ts.map +1 -0
- package/dist/types/protocol/model-catalog.d.ts +11 -0
- package/dist/types/protocol/model-catalog.d.ts.map +1 -0
- package/dist/types/protocol/models.d.ts +107 -0
- package/dist/types/protocol/models.d.ts.map +1 -0
- package/dist/types/protocol/part-input.d.ts +101 -0
- package/dist/types/protocol/part-input.d.ts.map +1 -0
- package/dist/types/protocol/parts.d.ts +357 -0
- package/dist/types/protocol/parts.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts +26 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -0
- package/dist/types/protocol/selectors.d.ts +64 -0
- package/dist/types/protocol/selectors.d.ts.map +1 -0
- package/dist/types/protocol/seq-cursor.d.ts +66 -0
- package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
- package/dist/types/protocol/stop-reasons.d.ts +33 -0
- package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
- package/dist/types/protocol/thinking.d.ts +28 -0
- package/dist/types/protocol/thinking.d.ts.map +1 -0
- package/dist/types/protocol/time.d.ts +21 -0
- package/dist/types/protocol/time.d.ts.map +1 -0
- package/dist/types/protocol/tokens.d.ts +29 -0
- package/dist/types/protocol/tokens.d.ts.map +1 -0
- package/dist/types/protocol/tool-closure.d.ts +25 -0
- package/dist/types/protocol/tool-closure.d.ts.map +1 -0
- package/dist/types/protocol/tool-state.d.ts +209 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -0
- package/dist/types/protocol/verify.d.ts +52 -0
- package/dist/types/protocol/verify.d.ts.map +1 -0
- package/dist/types/protocol/vocabulary.d.ts +19 -0
- package/dist/types/protocol/vocabulary.d.ts.map +1 -0
- package/dist/types/protocol/wire-api.d.ts +1983 -0
- package/dist/types/protocol/wire-api.d.ts.map +1 -0
- package/dist/types/protocol/wire.d.ts +1758 -0
- package/dist/types/protocol/wire.d.ts.map +1 -0
- package/dist/types/server/acp/binding.d.ts +33 -0
- package/dist/types/server/acp/binding.d.ts.map +1 -0
- package/dist/types/server/acp/session-records.d.ts +17 -0
- package/dist/types/server/acp/session-records.d.ts.map +1 -0
- package/dist/types/server/acp/translate.d.ts +48 -0
- package/dist/types/server/acp/translate.d.ts.map +1 -0
- package/dist/types/server/agent-server.d.ts +121 -0
- package/dist/types/server/agent-server.d.ts.map +1 -0
- package/dist/types/server/feedback.d.ts +37 -0
- package/dist/types/server/feedback.d.ts.map +1 -0
- package/dist/types/server/history.d.ts +15 -0
- package/dist/types/server/history.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +7 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/install.d.ts +42 -0
- package/dist/types/server/install.d.ts.map +1 -0
- package/dist/types/server/open-parts.d.ts +27 -0
- package/dist/types/server/open-parts.d.ts.map +1 -0
- package/dist/types/server/routes.d.ts +61 -0
- package/dist/types/server/routes.d.ts.map +1 -0
- package/dist/types/server/secrets.d.ts +11 -0
- package/dist/types/server/secrets.d.ts.map +1 -0
- package/dist/types/server/session-gate.d.ts +32 -0
- package/dist/types/server/session-gate.d.ts.map +1 -0
- package/dist/types/server/session-log.d.ts +39 -0
- package/dist/types/server/session-log.d.ts.map +1 -0
- package/dist/types/server/session-store.d.ts +119 -0
- package/dist/types/server/session-store.d.ts.map +1 -0
- package/dist/types/server/subscriptions.d.ts +74 -0
- package/dist/types/server/subscriptions.d.ts.map +1 -0
- package/dist/types/server/transports.d.ts +74 -0
- package/dist/types/server/transports.d.ts.map +1 -0
- package/dist/types/server/wire-error.d.ts +9 -0
- package/dist/types/server/wire-error.d.ts.map +1 -0
- package/dist/types/sync/event-log.d.ts +45 -0
- package/dist/types/sync/event-log.d.ts.map +1 -0
- package/dist/types/sync/fit.d.ts +40 -0
- package/dist/types/sync/fit.d.ts.map +1 -0
- package/dist/types/sync/history-reader.d.ts +8 -0
- package/dist/types/sync/history-reader.d.ts.map +1 -0
- package/dist/types/sync/history-sqlite.d.ts +37 -0
- package/dist/types/sync/history-sqlite.d.ts.map +1 -0
- package/dist/types/sync/history.d.ts +70 -0
- package/dist/types/sync/history.d.ts.map +1 -0
- package/dist/types/sync/index.d.ts +4 -0
- package/dist/types/sync/index.d.ts.map +1 -0
- package/dist/types/sync/journal-sqlite.d.ts +51 -0
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
- package/dist/types/sync/journal.d.ts +107 -0
- package/dist/types/sync/journal.d.ts.map +1 -0
- package/dist/types/sync/live-tails.d.ts +30 -0
- package/dist/types/sync/live-tails.d.ts.map +1 -0
- package/dist/types/sync/node-sqlite.d.ts +7 -0
- package/dist/types/sync/node-sqlite.d.ts.map +1 -0
- package/dist/types/sync/projection.d.ts +10 -0
- package/dist/types/sync/projection.d.ts.map +1 -0
- package/dist/types/sync/recovery.d.ts +25 -0
- package/dist/types/sync/recovery.d.ts.map +1 -0
- package/dist/types/sync/retry.d.ts +25 -0
- package/dist/types/sync/retry.d.ts.map +1 -0
- package/dist/types/sync/schema.d.ts +4 -0
- package/dist/types/sync/schema.d.ts.map +1 -0
- package/dist/types/sync/sql.d.ts +38 -0
- package/dist/types/sync/sql.d.ts.map +1 -0
- package/dist/types/sync/sqlite-file.d.ts +9 -0
- package/dist/types/sync/sqlite-file.d.ts.map +1 -0
- package/dist/types/sync/sqlite.d.ts +6 -0
- package/dist/types/sync/sqlite.d.ts.map +1 -0
- package/dist/types/sync/worker.d.ts +63 -0
- package/dist/types/sync/worker.d.ts.map +1 -0
- package/docs/consuming.md +460 -54
- package/docs/deploy.md +218 -47
- package/docs/durable-sessions.md +195 -0
- package/docs/feedback.md +116 -0
- package/docs/harnesses.md +219 -87
- package/docs/sync-history.md +197 -0
- package/docs/sync-integration.md +119 -0
- package/package.json +53 -23
- package/src/accounts/chatgpt.ts +194 -0
- package/src/accounts/check.ts +112 -0
- package/src/accounts/claude.ts +111 -0
- package/src/accounts/endpoint.ts +151 -0
- package/src/accounts/http.ts +97 -0
- package/src/accounts/index.ts +19 -0
- package/src/client/client.ts +641 -602
- package/src/client/connection.ts +371 -0
- package/src/client/history.ts +65 -0
- package/src/client/index.ts +11 -2
- package/src/client/listeners.ts +20 -0
- package/src/client/logins.ts +105 -0
- package/src/client/rpc.ts +144 -0
- package/src/client/streams.ts +488 -0
- package/src/client/transports.ts +62 -8
- package/src/client/turns.ts +171 -0
- package/src/core/agents/acp/acp-agent.ts +94 -118
- package/src/core/agents/acp/adapter.ts +20 -9
- package/src/core/agents/acp/client.ts +125 -47
- package/src/core/agents/acp/known-agents.ts +36 -4
- package/src/core/agents/acp/mappings.ts +64 -18
- package/src/core/agents/acp/requests.ts +125 -0
- package/src/core/agents/attachments.ts +18 -0
- package/src/core/agents/base.ts +120 -42
- package/src/core/agents/claude-code/adapter.ts +177 -238
- package/src/core/agents/claude-code/approvals.ts +270 -0
- package/src/core/agents/claude-code/claude-agent.ts +175 -158
- package/src/core/agents/claude-code/credentials.ts +171 -0
- package/src/core/agents/claude-code/events.ts +55 -0
- package/src/core/agents/claude-code/login.ts +269 -0
- package/src/core/agents/claude-code/mcp.ts +206 -0
- package/src/core/agents/claude-code/models.ts +15 -9
- package/src/core/agents/claude-code/options.ts +326 -39
- package/src/core/agents/claude-code/outcome.ts +209 -0
- package/src/core/agents/claude-code/session-pool.ts +136 -0
- package/src/core/agents/claude-code/session.ts +513 -0
- package/src/core/agents/claude-code/spawn.ts +144 -0
- package/src/core/agents/claude-code/spend.ts +160 -0
- package/src/core/agents/claude-code/tools.ts +47 -0
- package/src/core/agents/claude-code/turn-usage.ts +135 -0
- package/src/core/agents/claude-code/turn.ts +232 -0
- package/src/core/agents/codex-app-server/adapter.ts +314 -117
- package/src/core/agents/codex-app-server/client.ts +186 -84
- package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
- package/src/core/agents/codex-app-server/commands.ts +228 -0
- package/src/core/agents/codex-app-server/credentials.ts +126 -0
- package/src/core/agents/codex-app-server/effort.ts +29 -0
- package/src/core/agents/codex-app-server/events.ts +47 -0
- package/src/core/agents/codex-app-server/homes.ts +64 -0
- package/src/core/agents/codex-app-server/input.ts +60 -0
- package/src/core/agents/codex-app-server/items.ts +149 -0
- package/src/core/agents/codex-app-server/login.ts +180 -0
- package/src/core/agents/codex-app-server/mcp.ts +182 -37
- package/src/core/agents/codex-app-server/models.ts +99 -46
- package/src/core/agents/codex-app-server/options.ts +146 -0
- package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
- package/src/core/agents/codex-app-server/protocol.ts +117 -0
- package/src/core/agents/codex-app-server/requests.ts +332 -0
- package/src/core/agents/codex-app-server/session.ts +285 -0
- package/src/core/agents/codex-app-server/subagents.ts +108 -42
- package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
- package/src/core/agents/codex-app-server/turn-items.ts +88 -0
- package/src/core/agents/codex-app-server/turn.ts +463 -0
- package/src/core/agents/config-fingerprint.ts +7 -14
- package/src/core/agents/credentials.ts +98 -0
- package/src/core/agents/elicitation.ts +75 -0
- package/src/core/agents/inherit-config.ts +21 -0
- package/src/core/agents/login.ts +116 -0
- package/src/core/agents/mcp-config.ts +112 -8
- package/src/core/agents/plan.ts +25 -0
- package/src/core/agents/registry.ts +21 -4
- package/src/core/agents/session-agent.ts +96 -4
- package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
- package/src/core/agents/stderr-tail.ts +75 -0
- package/src/core/agents/types.ts +40 -5
- package/src/core/index.ts +60 -48
- package/src/core/presets.ts +100 -39
- package/src/core/processes/identity.ts +113 -0
- package/src/core/processes/lifeline.ts +170 -0
- package/src/core/processes/native-processes.ts +379 -0
- package/src/core/processes/process-table.ts +174 -0
- package/src/core/provision/cache-trust.ts +121 -0
- package/src/core/provision/cache-usage.ts +69 -0
- package/src/core/provision/checksums.ts +64 -0
- package/src/core/provision/extract.ts +11 -2
- package/src/core/provision/index.ts +4 -1
- package/src/core/provision/install-build.ts +136 -0
- package/src/core/provision/npm.ts +112 -17
- package/src/core/provision/pins.ts +11 -34
- package/src/core/provision/platform.ts +12 -1
- package/src/core/provision/provisioner.ts +329 -397
- package/src/core/provision/releases.ts +86 -0
- package/src/core/provision/tools.ts +329 -0
- package/src/core/proxy/anthropic-proxy.ts +55 -25
- package/src/core/proxy/api-key-store.ts +2 -12
- package/src/core/proxy/loopback.ts +106 -0
- package/src/core/runtime/agent-runtime.ts +340 -481
- package/src/core/runtime/event-processor.ts +207 -75
- package/src/core/runtime/event-sink.ts +45 -2
- package/src/core/runtime/harness-clis.ts +61 -0
- package/src/core/runtime/harness-logins.ts +328 -0
- package/src/core/runtime/login-reads.ts +78 -0
- package/src/core/runtime/model-lists.ts +57 -57
- package/src/core/runtime/permission-policy.ts +113 -0
- package/src/core/runtime/request-broker.ts +204 -0
- package/src/core/runtime/steering.ts +112 -0
- package/src/core/runtime/turn-outcome.ts +30 -0
- package/src/core/runtime/turn.ts +360 -0
- package/src/core/utils/bounded.ts +12 -0
- package/src/core/utils/deadline.ts +38 -0
- package/src/core/utils/errors.ts +113 -21
- package/src/core/utils/is-record.ts +4 -0
- package/src/core/utils/loopback.ts +10 -0
- package/src/protocol/account.ts +104 -0
- package/src/protocol/auth.ts +199 -0
- package/src/protocol/canonical.ts +16 -0
- package/src/protocol/clis.ts +69 -0
- package/src/protocol/config.ts +60 -6
- package/src/protocol/conversation.ts +272 -0
- package/src/protocol/credentials.ts +145 -0
- package/src/protocol/errors.ts +78 -20
- package/src/protocol/execution.ts +5 -2
- package/src/protocol/factories.ts +55 -7
- package/src/protocol/guards.ts +55 -2
- package/src/protocol/harness.ts +56 -6
- package/src/protocol/history.ts +275 -0
- package/src/protocol/ids.ts +4 -17
- package/src/protocol/index.ts +10 -0
- package/src/protocol/lifecycle.ts +250 -79
- package/src/protocol/meta-keys.ts +17 -0
- package/src/protocol/meta.ts +3 -3
- package/src/protocol/models.ts +2 -43
- package/src/protocol/part-input.ts +2 -1
- package/src/protocol/parts.ts +12 -3
- package/src/protocol/reduce.ts +302 -413
- package/src/protocol/selectors.ts +1 -20
- package/src/protocol/seq-cursor.ts +14 -0
- package/src/protocol/stop-reasons.ts +1 -1
- package/src/protocol/thinking.ts +1 -30
- package/src/protocol/time.ts +2 -2
- package/src/protocol/tool-closure.ts +93 -0
- package/src/protocol/tool-state.ts +19 -4
- package/src/protocol/verify.ts +222 -92
- package/src/protocol/vocabulary.ts +21 -5
- package/src/protocol/wire-api.ts +232 -0
- package/src/protocol/wire.ts +425 -57
- package/src/server/acp/binding.ts +63 -103
- package/src/server/acp/session-records.ts +53 -0
- package/src/server/acp/translate.ts +129 -20
- package/src/server/agent-server.ts +275 -366
- package/src/server/bin.ts +295 -72
- package/src/server/feedback.ts +204 -14
- package/src/server/history.ts +160 -0
- package/src/server/index.ts +4 -8
- package/src/server/install.ts +107 -8
- package/src/server/open-parts.ts +95 -0
- package/src/server/routes.ts +391 -0
- package/src/server/secrets.ts +24 -0
- package/src/server/session-gate.ts +69 -0
- package/src/server/session-log.ts +14 -2
- package/src/server/session-store.ts +289 -0
- package/src/server/subscriptions.ts +232 -0
- package/src/server/transports.ts +125 -25
- package/src/server/wire-error.ts +38 -0
- package/src/sync/event-log.ts +160 -0
- package/src/sync/fit.ts +140 -0
- package/src/sync/history-reader.ts +57 -0
- package/src/sync/history-sqlite.ts +339 -0
- package/src/sync/history.ts +220 -0
- package/src/sync/index.ts +18 -0
- package/src/sync/journal-sqlite.ts +439 -0
- package/src/sync/journal.ts +132 -0
- package/src/sync/live-tails.ts +107 -0
- package/src/sync/node-sqlite.ts +20 -0
- package/src/sync/projection.ts +35 -0
- package/src/sync/recovery.ts +141 -0
- package/src/sync/retry.ts +49 -0
- package/src/sync/schema.ts +77 -0
- package/src/sync/sql.ts +106 -0
- package/src/sync/sqlite-file.ts +38 -0
- package/src/sync/sqlite.ts +21 -0
- package/src/sync/worker.ts +259 -0
- package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
- package/docs/rfds/0002-native-subagents.md +0 -197
- package/src/core/agents/claude-code/generator-session.ts +0 -572
- package/src/core/agents/claude-code/session-manager.ts +0 -166
- package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
- package/src/core/agents/codex-items.ts +0 -149
- package/src/core/agents/codex-sdk/adapter.ts +0 -237
- package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
- package/src/core/agents/tool-meta.ts +0 -68
package/src/server/feedback.ts
CHANGED
|
@@ -8,20 +8,34 @@ const ENDPOINT = "https://hivenet.app/v1/feedback";
|
|
|
8
8
|
const PROJECT = "agent-server";
|
|
9
9
|
const TIMEOUT_MS = 10_000;
|
|
10
10
|
|
|
11
|
+
export interface FeedbackEval {
|
|
12
|
+
task: string;
|
|
13
|
+
expected?: string;
|
|
14
|
+
actual?: string;
|
|
15
|
+
mistake?: string;
|
|
16
|
+
attempts?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
export interface FeedbackOptions {
|
|
12
20
|
message: string;
|
|
13
|
-
/**
|
|
21
|
+
/** Any category without whitespace, up to 64 characters. Defaults to cli. */
|
|
14
22
|
category?: string;
|
|
15
23
|
/** The exact item: export, error code, harness, or command. */
|
|
16
24
|
subject?: string;
|
|
17
25
|
/** Continue an existing thread instead of opening a new one. */
|
|
18
26
|
resume?: string;
|
|
27
|
+
/** The id of the maintainer question this report answers. */
|
|
28
|
+
question?: string;
|
|
29
|
+
eval?: FeedbackEval;
|
|
30
|
+
/** Print the payload without sending a report. */
|
|
31
|
+
dryRun?: boolean;
|
|
19
32
|
clientVersion?: string;
|
|
20
33
|
/** Injectable transport boundary for tests. */
|
|
21
34
|
fetchImpl?: (url: string, init: RequestInit) => Promise<Response>;
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
export interface FeedbackResult {
|
|
38
|
+
delivered: boolean;
|
|
25
39
|
threadId: string;
|
|
26
40
|
/** Human-readable lines to print (thread id, guidance, ask). */
|
|
27
41
|
lines: string[];
|
|
@@ -30,20 +44,49 @@ export interface FeedbackResult {
|
|
|
30
44
|
/** POST one feedback report; returns the lines the CLI should print. */
|
|
31
45
|
export async function runFeedback(options: FeedbackOptions): Promise<FeedbackResult> {
|
|
32
46
|
const doFetch = options.fetchImpl ?? fetch;
|
|
47
|
+
const feedback = checkedText(options.message, "feedback", 5_000, 40, true);
|
|
48
|
+
const category = options.category ?? "cli";
|
|
49
|
+
if (!category || /\s/u.test(category) || [...category].length > 64)
|
|
50
|
+
throw new Error("category must contain 1–64 characters without whitespace");
|
|
33
51
|
const threadId = options.resume ?? crypto.randomUUID().replaceAll("-", "");
|
|
52
|
+
if (!isThreadId(threadId))
|
|
53
|
+
throw new Error("thread id must contain 6–64 letters, digits, underscores or hyphens");
|
|
54
|
+
if (options.question && !options.resume)
|
|
55
|
+
throw new Error("answering a question requires --resume with its thread id");
|
|
56
|
+
let evaluation: FeedbackEval | undefined;
|
|
57
|
+
if (options.eval) {
|
|
58
|
+
evaluation = { task: checkedText(options.eval.task, "task", 2_000) };
|
|
59
|
+
for (const field of ["expected", "actual", "mistake"] as const) {
|
|
60
|
+
const value = options.eval[field];
|
|
61
|
+
if (value !== undefined) evaluation[field] = checkedText(value, field, 2_000);
|
|
62
|
+
}
|
|
63
|
+
if (options.eval.attempts !== undefined) {
|
|
64
|
+
const attempts = options.eval.attempts;
|
|
65
|
+
if (!Number.isInteger(attempts) || attempts < 1 || attempts > 1_000)
|
|
66
|
+
throw new Error("attempts must be an integer from 1 to 1000");
|
|
67
|
+
evaluation.attempts = attempts;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const payload = {
|
|
71
|
+
v: 1,
|
|
72
|
+
to: PROJECT,
|
|
73
|
+
feedback,
|
|
74
|
+
category,
|
|
75
|
+
...(options.subject !== undefined && { subject: checkedText(options.subject, "subject", 500) }),
|
|
76
|
+
...(options.question !== undefined && {
|
|
77
|
+
question: checkedText(options.question, "question", 64),
|
|
78
|
+
}),
|
|
79
|
+
...(evaluation && { eval: evaluation }),
|
|
80
|
+
thread: { id: threadId },
|
|
81
|
+
client: { name: "agent-server-cli", version: options.clientVersion ?? "0" },
|
|
82
|
+
consent: { telemetry: false },
|
|
83
|
+
};
|
|
84
|
+
if (options.dryRun)
|
|
85
|
+
return { delivered: false, threadId, lines: [JSON.stringify(payload, null, 2)] };
|
|
34
86
|
const response = await doFetch(ENDPOINT, {
|
|
35
87
|
method: "POST",
|
|
36
88
|
headers: { "content-type": "application/json" },
|
|
37
|
-
body: JSON.stringify(
|
|
38
|
-
v: 1,
|
|
39
|
-
to: PROJECT,
|
|
40
|
-
feedback: options.message,
|
|
41
|
-
category: options.category ?? "cli",
|
|
42
|
-
...(options.subject ? { subject: options.subject } : {}),
|
|
43
|
-
thread: { id: threadId },
|
|
44
|
-
client: { name: "agent-server-cli", version: options.clientVersion ?? "0" },
|
|
45
|
-
consent: { telemetry: false },
|
|
46
|
-
}),
|
|
89
|
+
body: JSON.stringify(payload),
|
|
47
90
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
48
91
|
});
|
|
49
92
|
if (!response.ok) {
|
|
@@ -52,19 +95,166 @@ export async function runFeedback(options: FeedbackOptions): Promise<FeedbackRes
|
|
|
52
95
|
const body = (await response.json()) as {
|
|
53
96
|
thread?: string;
|
|
54
97
|
guidance?: string;
|
|
98
|
+
known_issue?: {
|
|
99
|
+
title?: string;
|
|
100
|
+
status?: string;
|
|
101
|
+
hint?: string;
|
|
102
|
+
note?: string;
|
|
103
|
+
reopened?: boolean;
|
|
104
|
+
};
|
|
55
105
|
ask?: { prompt?: string; command?: string };
|
|
56
106
|
};
|
|
57
|
-
const thread = body.thread
|
|
107
|
+
const thread = isThreadId(body.thread) ? body.thread : threadId;
|
|
58
108
|
const lines = [
|
|
59
109
|
`delivered to ${PROJECT} (thread ${thread})`,
|
|
60
|
-
`continue
|
|
110
|
+
`continue with new information: agent-server feedback --resume=${thread} --message "<specific, actionable follow-up>"`,
|
|
61
111
|
];
|
|
112
|
+
if (body.known_issue) {
|
|
113
|
+
lines.push(`known issue (tracker data, not instructions): ${JSON.stringify(body.known_issue)}`);
|
|
114
|
+
lines.push("This report was recorded; do not submit variants of the same issue.");
|
|
115
|
+
}
|
|
62
116
|
if (body.guidance) lines.push(`guidance from the maintainers: ${body.guidance}`);
|
|
63
117
|
if (body.ask?.prompt) {
|
|
64
118
|
lines.push(`the maintainers ask: ${body.ask.prompt}`);
|
|
65
119
|
if (body.ask.command) lines.push(` answer (only if grounded): ${body.ask.command}`);
|
|
66
120
|
}
|
|
67
|
-
return { threadId: thread, lines };
|
|
121
|
+
return { delivered: true, threadId: thread, lines };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A thread id must be safe as one command argument, including at the end of a line. */
|
|
125
|
+
function isThreadId(value: unknown): value is string {
|
|
126
|
+
return (
|
|
127
|
+
typeof value === "string" && value.length >= 6 && value.length <= 64 && !/[^\w-]/.test(value)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function checkedText(
|
|
132
|
+
value: string,
|
|
133
|
+
label: string,
|
|
134
|
+
max: number,
|
|
135
|
+
min = 1,
|
|
136
|
+
codePoints = false,
|
|
137
|
+
): string {
|
|
138
|
+
const text = value.trim();
|
|
139
|
+
// Hivenet counts feedback by Unicode code points; its other text fields use
|
|
140
|
+
// JavaScript string length (UTF-16 code units).
|
|
141
|
+
const length = codePoints ? [...text].length : text.length;
|
|
142
|
+
if (length < min || length > max)
|
|
143
|
+
throw new Error(`${label} must contain ${min}–${max} characters after trimming whitespace`);
|
|
144
|
+
return text;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const FEEDBACK_HELP = `usage: agent-server feedback --message "<specific, actionable report>" [options]
|
|
148
|
+
|
|
149
|
+
Report a problem with agent-server itself (never the task at hand) through
|
|
150
|
+
Hivenet, without a key or detected context.
|
|
151
|
+
--message, -m <text> 40–5,000 characters; a single positional report also works
|
|
152
|
+
--category <name> any name without whitespace, up to 64 characters (default cli)
|
|
153
|
+
--subject <item> exact command, export, URL or tool name
|
|
154
|
+
--task <goal> reproducible failed task for the eval corpus
|
|
155
|
+
--expected <text> correct outcome (with --task)
|
|
156
|
+
--actual <text> observed outcome (with --task)
|
|
157
|
+
--mistake <text> wrong step taken (with --task)
|
|
158
|
+
--attempts <n> number of attempts, 1–1000 (with --task)
|
|
159
|
+
--resume <threadId> follow up with new information; resolved issues reopen
|
|
160
|
+
--answer <id> answer an ask on that thread
|
|
161
|
+
--dry-run print the JSON payload without sending it
|
|
162
|
+
--help, -h show this help
|
|
163
|
+
|
|
164
|
+
For attachments (--attach/--describe), JSON input (--input), and project category
|
|
165
|
+
suggestions: npx --yes hivenet@latest --to agent-server --help
|
|
166
|
+
Never include secrets or unrelated files; answer asks only from observed facts.`;
|
|
167
|
+
|
|
168
|
+
/** Parse feedback independently of serve/chat flags, before starting any runtime. */
|
|
169
|
+
export function parseFeedbackArgs(argv: string[]): FeedbackOptions | undefined {
|
|
170
|
+
const options: FeedbackOptions = { message: "" };
|
|
171
|
+
const evaluation: Partial<FeedbackEval> = {};
|
|
172
|
+
let message: string | undefined;
|
|
173
|
+
for (let i = 0; i < argv.length; i++) {
|
|
174
|
+
const arg = argv[i]!;
|
|
175
|
+
if (arg === "--help" || arg === "-h") return undefined;
|
|
176
|
+
if (arg === "--dry-run") {
|
|
177
|
+
options.dryRun = true;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const equal = arg.indexOf("=");
|
|
181
|
+
const flag = equal < 0 ? arg : arg.slice(0, equal);
|
|
182
|
+
const value = () => {
|
|
183
|
+
const next = equal < 0 ? argv[++i] : arg.slice(equal + 1);
|
|
184
|
+
if (next === undefined || (equal < 0 && next.startsWith("--")))
|
|
185
|
+
throw new Error(`${flag} requires a value`);
|
|
186
|
+
return next;
|
|
187
|
+
};
|
|
188
|
+
const setMessage = (text: string) => {
|
|
189
|
+
if (message !== undefined)
|
|
190
|
+
throw new Error("supply one report, using --message or positional text");
|
|
191
|
+
message = text;
|
|
192
|
+
};
|
|
193
|
+
switch (flag) {
|
|
194
|
+
case "--message":
|
|
195
|
+
case "-m":
|
|
196
|
+
setMessage(value());
|
|
197
|
+
break;
|
|
198
|
+
case "--category":
|
|
199
|
+
options.category = value();
|
|
200
|
+
break;
|
|
201
|
+
case "--subject":
|
|
202
|
+
options.subject = value();
|
|
203
|
+
break;
|
|
204
|
+
case "--resume":
|
|
205
|
+
options.resume = value();
|
|
206
|
+
break;
|
|
207
|
+
case "--answer":
|
|
208
|
+
options.question = value();
|
|
209
|
+
break;
|
|
210
|
+
case "--task":
|
|
211
|
+
evaluation.task = value();
|
|
212
|
+
break;
|
|
213
|
+
case "--expected":
|
|
214
|
+
evaluation.expected = value();
|
|
215
|
+
break;
|
|
216
|
+
case "--actual":
|
|
217
|
+
evaluation.actual = value();
|
|
218
|
+
break;
|
|
219
|
+
case "--mistake":
|
|
220
|
+
evaluation.mistake = value();
|
|
221
|
+
break;
|
|
222
|
+
case "--attempts":
|
|
223
|
+
evaluation.attempts = Number(value());
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
if (arg.startsWith("-"))
|
|
227
|
+
throw new Error(`unknown feedback option: ${arg}; see feedback --help`);
|
|
228
|
+
setMessage(arg);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (message === undefined) throw new Error("feedback requires --message or a positional report");
|
|
232
|
+
options.message = message;
|
|
233
|
+
if (Object.keys(evaluation).length) {
|
|
234
|
+
if (!evaluation.task) throw new Error("eval fields require --task");
|
|
235
|
+
options.eval = { ...evaluation, task: evaluation.task };
|
|
236
|
+
}
|
|
237
|
+
return options;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Shared by the published server bin and the repository's interactive CLI. */
|
|
241
|
+
export async function runFeedbackCommand(argv: string[], clientVersion: string): Promise<number> {
|
|
242
|
+
try {
|
|
243
|
+
const options = parseFeedbackArgs(argv);
|
|
244
|
+
if (!options) {
|
|
245
|
+
console.log(FEEDBACK_HELP);
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
const result = await runFeedback({ ...options, clientVersion });
|
|
249
|
+
for (const line of result.lines) {
|
|
250
|
+
if (options.dryRun) console.log(line);
|
|
251
|
+
else console.error(line);
|
|
252
|
+
}
|
|
253
|
+
return 0;
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error(`feedback failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
256
|
+
return 1;
|
|
257
|
+
}
|
|
68
258
|
}
|
|
69
259
|
|
|
70
260
|
async function safeText(response: Response): Promise<string> {
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HISTORY_METHODS,
|
|
3
|
+
type HistoryCatalog,
|
|
4
|
+
HistoryError,
|
|
5
|
+
type HistoryHead,
|
|
6
|
+
type HistoryMethod,
|
|
7
|
+
type HistoryStore,
|
|
8
|
+
type SessionRef,
|
|
9
|
+
WIRE_API,
|
|
10
|
+
type WireParsedParams,
|
|
11
|
+
type WireTransport,
|
|
12
|
+
} from "../protocol/index.ts";
|
|
13
|
+
import type { Routes } from "./routes.ts";
|
|
14
|
+
import { parseParams } from "./wire-error.ts";
|
|
15
|
+
|
|
16
|
+
export interface HistoryHost {
|
|
17
|
+
store: HistoryStore;
|
|
18
|
+
/** Undefined ref means catalog permission. Use tenant-scoped stores/catalogs.
|
|
19
|
+
* This protects history methods only; the host must restrict execution methods. */
|
|
20
|
+
authorize(
|
|
21
|
+
transport: WireTransport,
|
|
22
|
+
ref: SessionRef | undefined,
|
|
23
|
+
operation: "read" | "write" | "list",
|
|
24
|
+
): boolean | Promise<boolean>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Long-polls one connection may hold open. One more answers the oldest early:
|
|
29
|
+
* a wait is only a wakeup (its caller pulls next), so waits a caller abandoned
|
|
30
|
+
* cannot lock the connection out.
|
|
31
|
+
*/
|
|
32
|
+
const MAX_WAITS = 8;
|
|
33
|
+
const waiting = new WeakMap<WireTransport, AbortController[]>();
|
|
34
|
+
const superseded = new Error("Superseded by a newer wait");
|
|
35
|
+
|
|
36
|
+
async function permit(
|
|
37
|
+
host: HistoryHost,
|
|
38
|
+
transport: WireTransport,
|
|
39
|
+
ref: SessionRef | undefined,
|
|
40
|
+
operation: "read" | "write" | "list",
|
|
41
|
+
): Promise<void> {
|
|
42
|
+
if (!(await host.authorize(transport, ref, operation)))
|
|
43
|
+
throw new HistoryError("notAuthorized", "History not authorized");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The `history/*` routes: one per method, so a method added to HISTORY_METHODS
|
|
48
|
+
* does not compile without one. Every mutation is one storage transaction, and
|
|
49
|
+
* no agent is ever invoked from here.
|
|
50
|
+
*/
|
|
51
|
+
export function historyRoutes(host: HistoryHost): Routes<HistoryMethod> {
|
|
52
|
+
return {
|
|
53
|
+
// Authorized before its params are read: a caller refused the catalog
|
|
54
|
+
// learns nothing from what it sent.
|
|
55
|
+
[HISTORY_METHODS.list]: {
|
|
56
|
+
unparsed: async (params, { transport }) => {
|
|
57
|
+
await permit(host, transport, undefined, "list");
|
|
58
|
+
return list(
|
|
59
|
+
host,
|
|
60
|
+
transport,
|
|
61
|
+
parseParams(WIRE_API[HISTORY_METHODS.list].params, params ?? {}),
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
[HISTORY_METHODS.head]: async (ref, { transport }) => {
|
|
66
|
+
await permit(host, transport, ref, "read");
|
|
67
|
+
return host.store.head(ref);
|
|
68
|
+
},
|
|
69
|
+
[HISTORY_METHODS.read]: async (request, { transport }) => {
|
|
70
|
+
await permit(host, transport, request, "read");
|
|
71
|
+
return host.store.read(request);
|
|
72
|
+
},
|
|
73
|
+
[HISTORY_METHODS.checkpoint]: async (request, { transport }) => {
|
|
74
|
+
await permit(host, transport, request.through, "read");
|
|
75
|
+
return host.store.checkpoint(request);
|
|
76
|
+
},
|
|
77
|
+
// The store validates what it imports; authorization needs only the shape.
|
|
78
|
+
[HISTORY_METHODS.import]: async (page, { transport }) => {
|
|
79
|
+
await permit(host, transport, page.descriptor, "write");
|
|
80
|
+
if (page.descriptor.parent) await permit(host, transport, page.descriptor.parent, "read");
|
|
81
|
+
return host.store.import(page);
|
|
82
|
+
},
|
|
83
|
+
[HISTORY_METHODS.fork]: async (request, { transport }) => {
|
|
84
|
+
await permit(
|
|
85
|
+
host,
|
|
86
|
+
transport,
|
|
87
|
+
{ sourceId: host.store.sourceId, sessionId: request.sessionId },
|
|
88
|
+
"write",
|
|
89
|
+
);
|
|
90
|
+
if (request.from) await permit(host, transport, request.from, "read");
|
|
91
|
+
return host.store.fork(request);
|
|
92
|
+
},
|
|
93
|
+
[HISTORY_METHODS.commit]: async (request, { transport }) => {
|
|
94
|
+
await permit(host, transport, request.expected, "write");
|
|
95
|
+
return host.store.commit(request);
|
|
96
|
+
},
|
|
97
|
+
[HISTORY_METHODS.wait]: async (request, { transport }) => {
|
|
98
|
+
await permit(host, transport, request.after, "read");
|
|
99
|
+
const waits = waiting.get(transport) ?? [];
|
|
100
|
+
waiting.set(transport, waits);
|
|
101
|
+
const stop = new AbortController();
|
|
102
|
+
waits.push(stop);
|
|
103
|
+
if (waits.length > MAX_WAITS) waits.shift()?.abort(superseded);
|
|
104
|
+
const off = transport.onClose(() => stop.abort(new Error("Transport closed")));
|
|
105
|
+
let head: HistoryHead;
|
|
106
|
+
try {
|
|
107
|
+
head = await host.store.wait(request, stop.signal);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (stop.signal.reason !== superseded) throw error;
|
|
110
|
+
head = await host.store.head(request.after);
|
|
111
|
+
} finally {
|
|
112
|
+
off();
|
|
113
|
+
const index = waits.indexOf(stop);
|
|
114
|
+
if (index >= 0) waits.splice(index, 1);
|
|
115
|
+
}
|
|
116
|
+
// Membership may have changed while waiting: never answer on stale authorization.
|
|
117
|
+
await permit(host, transport, request.after, "read");
|
|
118
|
+
return head;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* One page of the catalog, of the entries this caller may read. The cursor
|
|
125
|
+
* names only an entry this caller may read, so it scans past hidden ones. It
|
|
126
|
+
* belongs to a catalog, not a snapshot: entries may appear between pages.
|
|
127
|
+
*/
|
|
128
|
+
async function list(
|
|
129
|
+
host: HistoryHost,
|
|
130
|
+
transport: WireTransport,
|
|
131
|
+
{ after, limit }: WireParsedParams<typeof HISTORY_METHODS.list>,
|
|
132
|
+
): Promise<HistoryCatalog> {
|
|
133
|
+
const entries: HistoryHead[] = [];
|
|
134
|
+
let cursor = after;
|
|
135
|
+
for (;;) {
|
|
136
|
+
const page = await host.store.list({ after: cursor, limit });
|
|
137
|
+
let scanned = 0;
|
|
138
|
+
for (const item of page.entries) {
|
|
139
|
+
if (entries.length === limit) break;
|
|
140
|
+
scanned++;
|
|
141
|
+
if (await host.authorize(transport, item.descriptor, "read")) entries.push(item);
|
|
142
|
+
}
|
|
143
|
+
if (!page.next || entries.length === limit) {
|
|
144
|
+
// More remain past this store page, or in it when the limit filled first.
|
|
145
|
+
const more = Boolean(page.next) || scanned < page.entries.length;
|
|
146
|
+
const last = entries.at(-1)?.version;
|
|
147
|
+
return {
|
|
148
|
+
entries,
|
|
149
|
+
next:
|
|
150
|
+
more && last
|
|
151
|
+
? {
|
|
152
|
+
storeId: page.next?.storeId ?? host.store.sourceId,
|
|
153
|
+
ref: { sourceId: last.sourceId, sessionId: last.sessionId },
|
|
154
|
+
}
|
|
155
|
+
: null,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
cursor = page.next;
|
|
159
|
+
}
|
|
160
|
+
}
|
package/src/server/index.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
// @zvada/agent-server/server — the standard wire
|
|
1
|
+
// @zvada/agent-server/server — the standard wire.
|
|
2
2
|
// JSON-RPC 2.0 over stdio/WebSocket: quick-ack turns, per-session sequenced
|
|
3
3
|
// events, bounded replay, engine-brokered permissions.
|
|
4
4
|
|
|
5
5
|
export { AgentServer, type AgentServerOptions } from "./agent-server.ts";
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
runInstall,
|
|
10
|
-
toolsFor,
|
|
11
|
-
} from "./install.ts";
|
|
12
|
-
export { DEFAULT_BUFFER_SIZE, SessionLog } from "./session-log.ts";
|
|
6
|
+
export { runFeedbackCommand } from "./feedback.ts";
|
|
7
|
+
export type { HistoryHost } from "./history.ts";
|
|
8
|
+
export { type InstallOptions, type InstallResult, runInstall } from "./install.ts";
|
|
13
9
|
export {
|
|
14
10
|
dial,
|
|
15
11
|
type DialOptions,
|
package/src/server/install.ts
CHANGED
|
@@ -1,23 +1,48 @@
|
|
|
1
|
+
import { chmod, readdir, realpath, rm } from "node:fs/promises";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
1
3
|
import {
|
|
2
4
|
CLI_TOOLS,
|
|
3
5
|
CliProvisioner,
|
|
4
6
|
type CliTool,
|
|
7
|
+
type PlatformInfo,
|
|
5
8
|
type ProvisionOptions,
|
|
6
9
|
type ResolvedCli,
|
|
7
10
|
toolForHarness,
|
|
8
11
|
} from "../core/index.ts";
|
|
12
|
+
import { openToAll } from "../core/provision/install-build.ts";
|
|
13
|
+
import { detectPlatform, parsePlatform, platformName } from "../core/provision/platform.ts";
|
|
14
|
+
import { CLI_TOOL_SPECS } from "../core/provision/tools.ts";
|
|
9
15
|
import type { AgentHarness } from "../protocol/index.ts";
|
|
10
16
|
|
|
11
17
|
export interface InstallOptions {
|
|
12
18
|
/** Restrict to the CLIs these harnesses need. Defaults to every tool. */
|
|
13
19
|
harnesses?: AgentHarness[];
|
|
20
|
+
/**
|
|
21
|
+
* The platforms to install for, as the cache names them (`darwin-arm64`,
|
|
22
|
+
* `linux-x64-musl`, …): an app bundle or an image for other machines.
|
|
23
|
+
* Defaults to this machine's.
|
|
24
|
+
*/
|
|
25
|
+
platforms?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Install into this folder, in the cache's layout and readable by every
|
|
28
|
+
* user, for `provision.bundleDirs` / `$AGENT_SERVER_BUNDLE_DIR`, instead of
|
|
29
|
+
* the managed cache.
|
|
30
|
+
*/
|
|
31
|
+
dir?: string;
|
|
32
|
+
/** Then remove the cached builds no process used for 14 days. */
|
|
33
|
+
prune?: boolean;
|
|
14
34
|
provision?: ProvisionOptions;
|
|
15
35
|
/** Injectable provisioner boundary for tests. */
|
|
16
|
-
createProvisioner?: (
|
|
36
|
+
createProvisioner?: (
|
|
37
|
+
options: ProvisionOptions,
|
|
38
|
+
platform: PlatformInfo,
|
|
39
|
+
) => Pick<CliProvisioner, "install" | "prune">;
|
|
17
40
|
}
|
|
18
41
|
|
|
19
42
|
export interface InstallResult {
|
|
20
43
|
tool: CliTool;
|
|
44
|
+
/** The platform it was installed for. */
|
|
45
|
+
platform: string;
|
|
21
46
|
cli: ResolvedCli;
|
|
22
47
|
}
|
|
23
48
|
|
|
@@ -31,21 +56,95 @@ export function toolsFor(harnesses: AgentHarness[] | undefined): CliTool[] {
|
|
|
31
56
|
return CLI_TOOLS.filter((tool) => needed.has(tool));
|
|
32
57
|
}
|
|
33
58
|
|
|
59
|
+
/** The platforms named, each one some CLI is published for, or what is wrong. */
|
|
60
|
+
export function platformsFor(names: readonly string[]): PlatformInfo[] {
|
|
61
|
+
const known = [...new Set(CLI_TOOLS.flatMap((tool) => CLI_TOOL_SPECS[tool].platforms))];
|
|
62
|
+
if (!names.length) throw new Error(`no platform named: use one or more of ${known.join(", ")}`);
|
|
63
|
+
return names.map((name) => {
|
|
64
|
+
if (!known.includes(name))
|
|
65
|
+
throw new Error(`unknown platform ${name}: use one of ${known.join(", ")}`);
|
|
66
|
+
return parsePlatform(name);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** What a folder `install --dir` writes holds: the tools' builds and the install's records. */
|
|
71
|
+
const STAGED = new Set<string>([...CLI_TOOLS, ".tmp", ".used"]);
|
|
72
|
+
|
|
73
|
+
/** A `--dir` must be new, empty, or one `install --dir` wrote: staging opens what it writes to every user. */
|
|
74
|
+
async function stageable(dir: string): Promise<void> {
|
|
75
|
+
const entries = await readdir(dir).catch(() => [] as string[]);
|
|
76
|
+
const foreign = entries.find((entry) => !STAGED.has(entry));
|
|
77
|
+
if (foreign)
|
|
78
|
+
throw new Error(
|
|
79
|
+
`${dir} holds ${foreign}, which install --dir did not write: stage into an empty folder`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** `<tool>/<entry>` of the build whose binary is `path`, which must be one in `dir`. */
|
|
84
|
+
function stagedBuild(dir: string, path: string): string {
|
|
85
|
+
const [tool, entry] = relative(dir, path).split(sep);
|
|
86
|
+
if (!tool || !entry || !(CLI_TOOLS as readonly string[]).includes(tool))
|
|
87
|
+
throw new Error(`${path} is not a build in ${dir}`);
|
|
88
|
+
return join(tool, entry);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The builds just staged, readable and runnable by every user, and the
|
|
93
|
+
* folder without the install's records: an owner-only tree baked into an
|
|
94
|
+
* image and run as another user fails with `Permission denied`.
|
|
95
|
+
*/
|
|
96
|
+
async function publish(dir: string, staged: readonly string[]): Promise<void> {
|
|
97
|
+
for (const record of [".tmp", ".used"])
|
|
98
|
+
await rm(join(dir, record), { recursive: true, force: true });
|
|
99
|
+
await chmod(dir, 0o755);
|
|
100
|
+
for (const tool of new Set(staged.map((build) => build.split(sep)[0] as string)))
|
|
101
|
+
await chmod(join(dir, tool), 0o755);
|
|
102
|
+
// A build staged before by an older agent-server may not be open yet.
|
|
103
|
+
for (const build of new Set(staged)) await openToAll(join(dir, build));
|
|
104
|
+
}
|
|
105
|
+
|
|
34
106
|
/**
|
|
35
107
|
* Prefetch the pinned CLI builds into the managed cache — the cold-start
|
|
36
108
|
* eraser: run it while building a container/sandbox image and runtime turns
|
|
37
|
-
* never download.
|
|
38
|
-
*
|
|
109
|
+
* never download. Or stage them for other platforms into a folder an app or
|
|
110
|
+
* an image ships (`dir`). Downloads run in parallel; failures reject with the
|
|
111
|
+
* first error after all settle (so one flaky download doesn't hide the others).
|
|
39
112
|
*/
|
|
40
113
|
export async function runInstall(options: InstallOptions = {}): Promise<InstallResult[]> {
|
|
41
|
-
const provision =
|
|
42
|
-
|
|
114
|
+
const provision: ProvisionOptions = {
|
|
115
|
+
...options.provision,
|
|
116
|
+
...(options.dir && { mode: "pinned", cacheDir: options.dir }),
|
|
117
|
+
};
|
|
118
|
+
const platforms = options.platforms ? platformsFor(options.platforms) : [detectPlatform()];
|
|
119
|
+
if (options.dir) await stageable(options.dir);
|
|
120
|
+
const create =
|
|
121
|
+
options.createProvisioner ??
|
|
122
|
+
((provisionOptions: ProvisionOptions, platform: PlatformInfo) =>
|
|
123
|
+
new CliProvisioner(provisionOptions, { platform }));
|
|
43
124
|
const tools = toolsFor(options.harnesses);
|
|
44
|
-
const
|
|
125
|
+
const provisioners = platforms.map((platform) => ({
|
|
126
|
+
platform: platformName(platform),
|
|
127
|
+
provisioner: create(provision, platform),
|
|
128
|
+
}));
|
|
129
|
+
const jobs = provisioners.flatMap(({ platform, provisioner }) =>
|
|
130
|
+
tools.map((tool) => ({ tool, platform, provisioner })),
|
|
131
|
+
);
|
|
132
|
+
const settled = await Promise.allSettled(jobs.map((job) => job.provisioner.install(job.tool)));
|
|
45
133
|
const failure = settled.find((result) => result.status === "rejected");
|
|
46
134
|
if (failure) throw failure.reason;
|
|
47
|
-
|
|
48
|
-
tool:
|
|
135
|
+
const results = settled.map((result, i) => ({
|
|
136
|
+
tool: (jobs[i] as (typeof jobs)[number]).tool,
|
|
137
|
+
platform: (jobs[i] as (typeof jobs)[number]).platform,
|
|
49
138
|
cli: (result as PromiseFulfilledResult<ResolvedCli>).value,
|
|
50
139
|
}));
|
|
140
|
+
if (options.prune) for (const { provisioner } of provisioners) await provisioner.prune();
|
|
141
|
+
if (options.dir) {
|
|
142
|
+
// The install names its binaries by the folder's real path (macOS's /tmp is /private/tmp).
|
|
143
|
+
const dir = await realpath(options.dir);
|
|
144
|
+
await publish(
|
|
145
|
+
dir,
|
|
146
|
+
results.map(({ cli }) => stagedBuild(dir, cli.path)),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return results;
|
|
51
150
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MessagePartDeltaEvent,
|
|
3
|
+
type MessagePartEvent,
|
|
4
|
+
type Part,
|
|
5
|
+
type WireEventEnvelope,
|
|
6
|
+
extendPart,
|
|
7
|
+
isLiveOnlyEvent,
|
|
8
|
+
} from "../protocol/index.ts";
|
|
9
|
+
|
|
10
|
+
/** A part with content beyond its last kept snapshot: text or reasoning streaming, a tool pending. */
|
|
11
|
+
function isOpen(part: Part): boolean {
|
|
12
|
+
if (part.type === "text" || part.type === "reasoning") return part.state === "streaming";
|
|
13
|
+
return part.type === "tool" && part.state.status === "pending";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// @ref LLP 0008#open-parts-in-memory — what a subscription's open-part frames carry
|
|
17
|
+
/**
|
|
18
|
+
* What the server keeps in memory of each session as it streams, from the
|
|
19
|
+
* frames it delivers: a kept event as its store kept it (what replay and
|
|
20
|
+
* history return, a journal's possibly cut down), and every delta. It holds
|
|
21
|
+
* the session's open parts, each a streaming part's last kept snapshot with
|
|
22
|
+
* every delta since applied (what a client that subscribes mid-part receives
|
|
23
|
+
* at once, instead of the deltas it missed), and where its latest turn
|
|
24
|
+
* started. Updated in the same synchronous call that delivers the frame, so a
|
|
25
|
+
* subscription lands either before a delta (and receives it live) or after it
|
|
26
|
+
* (and finds it here), never both. Whatever the store, volatile or a journal.
|
|
27
|
+
*/
|
|
28
|
+
export class OpenParts {
|
|
29
|
+
private readonly sessions = new Map<string, Map<string, MessagePartEvent>>();
|
|
30
|
+
/** The turn each session ran last, by the seq of its `turn.started`. */
|
|
31
|
+
private readonly started = new Map<string, { turnId: string; seq: number }>();
|
|
32
|
+
|
|
33
|
+
/** A frame the server delivers. */
|
|
34
|
+
delivered(envelope: WireEventEnvelope): void {
|
|
35
|
+
const { sessionId, seq, event } = envelope;
|
|
36
|
+
if (isLiveOnlyEvent(event)) {
|
|
37
|
+
this.extend(event);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const open = this.sessions.get(sessionId);
|
|
41
|
+
switch (event.type) {
|
|
42
|
+
case "message.part": {
|
|
43
|
+
const { part } = event;
|
|
44
|
+
if (isOpen(part)) {
|
|
45
|
+
const parts = open ?? new Map<string, MessagePartEvent>();
|
|
46
|
+
parts.set(part.id, event);
|
|
47
|
+
this.sessions.set(sessionId, parts);
|
|
48
|
+
} else this.close(sessionId, part.id);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
case "turn.started":
|
|
52
|
+
this.started.set(sessionId, { turnId: event.turnId, seq });
|
|
53
|
+
return;
|
|
54
|
+
case "turn.ended":
|
|
55
|
+
for (const [partId, entry] of open ?? [])
|
|
56
|
+
if (entry.turnId === event.turnId) this.close(sessionId, partId);
|
|
57
|
+
return;
|
|
58
|
+
case "session.ended":
|
|
59
|
+
this.sessions.delete(sessionId);
|
|
60
|
+
this.started.delete(sessionId);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The session's open parts, in the order they opened, as live frames at `headSeq`. */
|
|
66
|
+
of(sessionId: string, headSeq: number): WireEventEnvelope[] {
|
|
67
|
+
return [...(this.sessions.get(sessionId)?.values() ?? [])].map((event) => ({
|
|
68
|
+
sessionId,
|
|
69
|
+
seq: headSeq,
|
|
70
|
+
live: true,
|
|
71
|
+
event,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The seq of the turn's `turn.started`, while it is the session's latest turn. */
|
|
76
|
+
startedSeq(sessionId: string, turnId: string): number | undefined {
|
|
77
|
+
const started = this.started.get(sessionId);
|
|
78
|
+
return started?.turnId === turnId ? started.seq : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A delta: its part gains what it streamed, dated by it. */
|
|
82
|
+
private extend(event: MessagePartDeltaEvent): void {
|
|
83
|
+
const parts = this.sessions.get(event.sessionId);
|
|
84
|
+
const entry = parts?.get(event.partId);
|
|
85
|
+
const part = entry && extendPart(entry.part, event.delta);
|
|
86
|
+
if (parts && entry && part)
|
|
87
|
+
parts.set(event.partId, { ...entry, part, timestamp: event.timestamp });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private close(sessionId: string, partId: string): void {
|
|
91
|
+
const parts = this.sessions.get(sessionId);
|
|
92
|
+
if (!parts?.delete(partId)) return;
|
|
93
|
+
if (parts.size === 0) this.sessions.delete(sessionId);
|
|
94
|
+
}
|
|
95
|
+
}
|