@sema-agent/core 7.57.0 → 7.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1161 -0
- package/README.md +6 -4
- package/dist/agents/cc-peer-directory.js +8 -8
- package/dist/agents/child-model-seat.d.ts +4 -2
- package/dist/agents/child-model-seat.js +5 -3
- package/dist/agents/peer-directory.d.ts +9 -0
- package/dist/agents/peer-directory.js +6 -2
- package/dist/agents/send-message-tool.js +21 -12
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/agents/subagent.js +33 -34
- package/dist/brain/anthropic.js +161 -45
- package/dist/brain/errors.d.ts +9 -3
- package/dist/brain/errors.js +7 -1
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +3 -3
- package/dist/brain/openai.js +103 -53
- package/dist/brain/provider-dialect.d.ts +11 -0
- package/dist/brain/provider-dialect.js +5 -2
- package/dist/brain/reasoning-request.js +5 -4
- package/dist/brain/reasoning.d.ts +19 -0
- package/dist/brain/reasoning.js +17 -2
- package/dist/brain/request-route.d.ts +4 -1
- package/dist/brain/request-route.js +4 -1
- package/dist/brain/route-adjudicator.d.ts +84 -18
- package/dist/brain/route-adjudicator.js +89 -22
- package/dist/brain/route-conformance.js +1 -1
- package/dist/brain/stream-engine.js +84 -49
- package/dist/brain/stream-shared.d.ts +30 -0
- package/dist/brain/stream-shared.js +34 -1
- package/dist/brain/timeout.d.ts +62 -5
- package/dist/brain/timeout.js +93 -6
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/account-row.d.ts +61 -0
- package/dist/core/account-row.js +51 -0
- package/dist/core/advisor-verdict.d.ts +2 -1
- package/dist/core/advisor-verdict.js +1 -1
- package/dist/core/allow-entry.d.ts +20 -7
- package/dist/core/allow-entry.js +18 -9
- package/dist/core/approval-object.d.ts +29 -15
- package/dist/core/approval-object.js +47 -19
- package/dist/core/ask-origin.d.ts +21 -2
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +4 -0
- package/dist/core/auto-compaction.js +2 -2
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/background-agent-store.d.ts +16 -3
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-store.d.ts +85 -23
- package/dist/core/checkpoint-store.js +31 -9
- package/dist/core/child-clamp-seats.d.ts +29 -0
- package/dist/core/child-clamp-seats.js +56 -1
- package/dist/core/compliance.d.ts +2 -2
- package/dist/core/compliance.js +1 -1
- package/dist/core/effective-path-target.d.ts +8 -2
- package/dist/core/effective-path-target.js +8 -3
- package/dist/core/engine-notice.d.ts +99 -9
- package/dist/core/engine-notice.js +19 -5
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +7 -4
- package/dist/core/gate-lanes.js +19 -6
- package/dist/core/gate-outcome.d.ts +32 -3
- package/dist/core/gate-outcome.js +19 -1
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +13 -0
- package/dist/core/hooks.d.ts +35 -4
- package/dist/core/hooks.js +17 -11
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +6 -5
- package/dist/core/image-admission.js +18 -14
- package/dist/core/locked-config.d.ts +20 -3
- package/dist/core/locked-config.js +40 -3
- package/dist/core/mailbox-store.d.ts +45 -1
- package/dist/core/mailbox-store.js +53 -9
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +117 -15
- package/dist/core/mcp-failure.js +71 -3
- package/dist/core/mcp-probe.d.ts +4 -0
- package/dist/core/mcp-probe.js +1 -1
- package/dist/core/mcp-server-link.d.ts +27 -3
- package/dist/core/mcp-server-link.js +25 -1
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +16 -20
- package/dist/core/mcp.js +112 -55
- package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
- package/dist/core/memory-engine/consolidation-driver.js +3 -3
- package/dist/core/memory-engine/consolidation.d.ts +4 -0
- package/dist/core/memory-engine/consolidation.js +1 -0
- package/dist/core/memory-engine/delegation-settlement.js +5 -12
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +50 -1
- package/dist/core/memory-engine/dual-root.js +44 -1
- package/dist/core/memory-engine/engine.d.ts +67 -14
- package/dist/core/memory-engine/engine.js +384 -212
- package/dist/core/memory-engine/export-bundle.d.ts +23 -0
- package/dist/core/memory-engine/export-bundle.js +23 -4
- package/dist/core/memory-engine/file-backend.d.ts +128 -55
- package/dist/core/memory-engine/file-backend.js +290 -117
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/layout.d.ts +59 -11
- package/dist/core/memory-engine/layout.js +190 -40
- package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
- package/dist/core/memory-engine/memory-backend-contract.js +39 -2
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/memory-engine/sync-client.d.ts +9 -1
- package/dist/core/memory-engine/sync-client.js +31 -8
- package/dist/core/memory-engine/sync.d.ts +5 -0
- package/dist/core/memory-engine/types.d.ts +6 -0
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +12 -9
- package/dist/core/mods/kernel/events.d.ts +6 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/kernel/registration.d.ts +9 -1
- package/dist/core/mods/kernel/registration.js +3 -0
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +33 -12
- package/dist/core/mods/stations.js +45 -11
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +13 -4
- package/dist/core/parent-spec-seat.d.ts +8 -3
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +6 -0
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +248 -0
- package/dist/core/peer-seat.js +439 -0
- package/dist/core/permission-rule-consent.js +10 -4
- package/dist/core/permission-rule-model.d.ts +16 -0
- package/dist/core/permission-rule-model.js +1 -1
- package/dist/core/present-plan-tool.d.ts +20 -3
- package/dist/core/present-plan-tool.js +48 -4
- package/dist/core/protocol-http-auth.d.ts +40 -29
- package/dist/core/protocol-http-auth.js +30 -32
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/resume-startup-cause.js +1 -0
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +38 -0
- package/dist/core/rewrite-rejudge.js +42 -2
- package/dist/core/roles.d.ts +34 -2
- package/dist/core/roles.js +43 -4
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/announce-once-ledger.d.ts +5 -4
- package/dist/core/runner/announce-once-ledger.js +4 -2
- package/dist/core/runner/call-hook-stations.js +2 -2
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/contracts.d.ts +33 -21
- package/dist/core/runner/credential-origin-seat.js +4 -3
- package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
- package/dist/core/runner/cwd-alignment-probe.js +21 -0
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/gate-exit.d.ts +30 -8
- package/dist/core/runner/gate-exit.js +15 -8
- package/dist/core/runner/image-removed-seat.d.ts +12 -0
- package/dist/core/runner/image-removed-seat.js +19 -0
- package/dist/core/runner/inline-image.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.js +3 -3
- package/dist/core/runner/park-commit.d.ts +1 -1
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
- package/dist/core/runner/prepare-ask-lane.js +2 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
- package/dist/core/runner/prepare-config-doors.d.ts +8 -5
- package/dist/core/runner/prepare-config-doors.js +14 -10
- package/dist/core/runner/prepare-context-lane.js +2 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
- package/dist/core/runner/prepare-delegation-surface.js +16 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
- package/dist/core/runner/prepare-hands-readface.js +9 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
- package/dist/core/runner/prepare-inherited-gate.js +14 -27
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +26 -37
- package/dist/core/runner/prepare-park-ask.d.ts +1 -1
- package/dist/core/runner/prepare-park-ask.js +2 -1
- package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
- package/dist/core/runner/prepare-policy-chain.js +18 -15
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
- package/dist/core/runner/prepare-prompt-inputs.js +8 -19
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +11 -3
- package/dist/core/runner/prepare-run-refs.d.ts +2 -3
- package/dist/core/runner/prepare-run-refs.js +4 -1
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.js +28 -13
- package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
- package/dist/core/runner/prepare-wiring-manifest.js +4 -3
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/reply-pricing.d.ts +30 -0
- package/dist/core/runner/reply-pricing.js +19 -0
- package/dist/core/runner/resume-admission.js +5 -3
- package/dist/core/runner/resume-apply.js +6 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/resume-policy-outcome.js +5 -5
- package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
- package/dist/core/runner/role-seat-defaulted.js +40 -0
- package/dist/core/runner/run-brain-sinks.js +2 -0
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.d.ts +2 -5
- package/dist/core/runner/run-identity-wiring.js +6 -4
- package/dist/core/runner/run-leg.d.ts +2 -0
- package/dist/core/runner/run-leg.js +42 -29
- package/dist/core/runner/run-notification-lane.js +3 -0
- package/dist/core/runner/run-stop-and-final-verify.js +2 -2
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
- package/dist/core/runner/run-terminal-adoption.js +9 -3
- package/dist/core/runner/run-turn-boundary.js +77 -70
- package/dist/core/runner/runtask.d.ts +1 -1
- package/dist/core/runner/runtask.js +2 -2
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +3 -18
- package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
- package/dist/core/runner/sub-agent-deny-lists.js +10 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +2 -1
- package/dist/core/runner/tool-occurrence.d.ts +5 -2
- package/dist/core/runner/tool-occurrence.js +4 -3
- package/dist/core/runner/turn-attachments.d.ts +26 -22
- package/dist/core/runner/turn-attachments.js +24 -26
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +3 -3
- package/dist/core/secret-env.d.ts +32 -2
- package/dist/core/secret-env.js +65 -3
- package/dist/core/sensitive-path-policy.js +9 -10
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-policy-store.d.ts +3 -1
- package/dist/core/session-policy-store.js +13 -9
- package/dist/core/session-store.d.ts +86 -24
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/side-query.d.ts +11 -1
- package/dist/core/side-query.js +9 -0
- package/dist/core/skill-grant-binding.d.ts +31 -2
- package/dist/core/skill-grant-binding.js +31 -1
- package/dist/core/skill-grant.d.ts +8 -5
- package/dist/core/skill-grant.js +6 -6
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/synthetic-read-verdict.js +2 -1
- package/dist/core/task-event.d.ts +92 -8
- package/dist/core/task-notification.js +16 -10
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +7 -1
- package/dist/core/task-spec.d.ts +49 -1
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +11 -1
- package/dist/core/tool-catalog-entries.js +1 -0
- package/dist/core/tool-check-reading.d.ts +1 -0
- package/dist/core/tool-check-reading.js +3 -3
- package/dist/core/tool-policy.d.ts +16 -0
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/tool-roster.d.ts +112 -5
- package/dist/core/tool-roster.js +42 -1
- package/dist/core/tool-spec.d.ts +3 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +0 -2
- package/dist/core/untrusted-egress.js +10 -14
- package/dist/core/user-attachment.js +1 -1
- package/dist/core/wiring-manifest.d.ts +18 -6
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/compaction/compaction.js +29 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
- package/dist/engine/execution-env/node-execution-env.js +24 -23
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +30 -2
- package/dist/engine/harness/agent-harness.js +43 -12
- package/dist/engine/harness/messages.d.ts +3 -1
- package/dist/engine/harness/messages.js +3 -2
- package/dist/engine/harness/types.d.ts +56 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/rejected-images.d.ts +46 -0
- package/dist/engine/llm/rejected-images.js +54 -0
- package/dist/engine/llm/tool-turns.d.ts +2 -1
- package/dist/engine/llm/types.d.ts +30 -10
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +8 -0
- package/dist/engine/loop/agent-loop.js +52 -15
- package/dist/engine/loop/types.d.ts +3 -1
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/path-to-root.d.ts +38 -0
- package/dist/engine/session/path-to-root.js +39 -0
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +11 -22
- package/dist/index.d.ts +29 -16
- package/dist/index.js +21 -11
- package/dist/internal/harness-types.d.ts +2 -2
- package/dist/internal/harness.d.ts +3 -2
- package/dist/internal/harness.js +2 -2
- package/dist/internal/llm.d.ts +1 -0
- package/dist/orchestration/workflow-observe.d.ts +17 -1
- package/dist/orchestration/workflow-observe.js +20 -0
- package/dist/orchestration/workflow-types.d.ts +32 -7
- package/dist/orchestration/workflow.js +739 -489
- package/dist/shell/counting-pass.d.ts +50 -0
- package/dist/shell/counting-pass.js +502 -0
- package/dist/shell/lex.d.ts +4 -2
- package/dist/shell/lex.js +93 -34
- package/dist/shell/shell-words.d.ts +1 -1
- package/dist/shell/shell-words.js +7 -6
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/mailbox-store.js +6 -10
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/fs-bash.d.ts +6 -0
- package/dist/tools/fs/fs-bash.js +6 -3
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +7 -3
- package/dist/tools/fs/program-read-model.d.ts +13 -0
- package/dist/tools/fs/program-read-model.js +15 -0
- package/dist/tools/fs/program-read-model.rows.js +1 -1
- package/dist/tools/fs/read-deny.d.ts +13 -10
- package/dist/tools/fs/read-deny.js +25 -5
- package/dist/tools/fs/read-floor.d.ts +19 -0
- package/dist/tools/fs/read-floor.js +23 -0
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +61 -16
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.js +1 -1
- package/dist/tools/fs/shell-read-judge.d.ts +26 -9
- package/dist/tools/fs/shell-read-judge.js +10 -6
- package/dist/tools/fs/shell-read-plan.d.ts +6 -1
- package/dist/tools/fs/shell-read-plan.js +22 -15
- package/dist/tools/fs/shell-read-start.js +1 -0
- package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
- package/dist/tools/fs/shell-reentry-text.js +25 -3
- package/dist/tools/monitor.d.ts +4 -0
- package/dist/tools/monitor.js +2 -0
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +5 -2
- package/test/export-surface.snapshot.json +149 -1
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core-stores-sql@7.59.0.json +29 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/core@7.59.0.json +2459 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/mods-kernel@7.59.0.json +29 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
- package/wire-changes/primitives@7.59.0.json +29 -0
- package/dist/primitives/credential-ref.d.ts +0 -89
- package/dist/primitives/credential-ref.js +0 -125
- package/dist/primitives/index.d.ts +0 -2
- package/dist/primitives/index.js +0 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { InMemorySessionRepo, ParentChainGuard, SessionError, findUnansweredToolBatch, compareOccupants, ownerCell, uuidv7, } from "../internal/harness.js";
|
|
1
|
+
import { InMemorySessionRepo, ParentChainGuard, SessionError, findUnansweredToolBatch, compareOccupants, ownerCell, sessionLogMarkOf, uuidv7, } from "../internal/harness.js";
|
|
2
2
|
import { isSessionConflict, readSessionListQuery } from "./session.js";
|
|
3
|
+
import { readRetentionDeclaration } from "./retention.js";
|
|
3
4
|
import { readMember } from "./thrown-value.js";
|
|
5
|
+
import { principalNameFault, principalNameOf } from "./principal-name.js";
|
|
6
|
+
import { receiptRefusal, receiveOwnProperties } from "./own-property-receipt.js";
|
|
7
|
+
import { repoLogTransfer } from "./session-log-transfer.js";
|
|
4
8
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
5
9
|
import { SESSION_DEFAULT_TTL_DAYS } from "../config/defaults.js";
|
|
6
10
|
export { SESSION_DEFAULT_TTL_DAYS };
|
|
@@ -19,22 +23,28 @@ export function admitSessionPlacement(sessionId, persisted, request, capability)
|
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
export class TtlSessionStore {
|
|
22
|
-
retention
|
|
26
|
+
retention;
|
|
23
27
|
durability;
|
|
24
28
|
placements;
|
|
25
29
|
listPlaced;
|
|
26
30
|
headOf;
|
|
27
31
|
repoHead;
|
|
32
|
+
logTransfer;
|
|
33
|
+
delete;
|
|
34
|
+
judgesRows = false;
|
|
35
|
+
beforeRowDelete;
|
|
28
36
|
repo;
|
|
29
37
|
entries = new Map();
|
|
30
38
|
pending = new Map();
|
|
31
39
|
pendingPlacedDeletes = new Set();
|
|
32
40
|
releasing = new Map();
|
|
41
|
+
resolutions = new Map();
|
|
33
42
|
pinned = new Set();
|
|
34
43
|
defaultTtlMs;
|
|
35
44
|
evictPolicy;
|
|
36
45
|
sweepTimer;
|
|
37
46
|
constructor(opts = {}) {
|
|
47
|
+
this.retention = readRetentionDeclaration("TtlSessionStoreOptions.retention", opts.retention);
|
|
38
48
|
this.repo = opts.repo ?? new InMemorySessionRepo();
|
|
39
49
|
const durability = opts.durability ?? (opts.repo === undefined ? "process-local" : undefined);
|
|
40
50
|
if (durability !== undefined)
|
|
@@ -49,9 +59,28 @@ export class TtlSessionStore {
|
|
|
49
59
|
}
|
|
50
60
|
const repoHeadOf = this.repo.headOf;
|
|
51
61
|
if (typeof repoHeadOf === "function") {
|
|
52
|
-
|
|
53
|
-
this.
|
|
62
|
+
const repoHead = (sessionId) => repoHeadOf.call(this.repo, sessionId);
|
|
63
|
+
this.repoHead = repoHead;
|
|
64
|
+
this.headOf = repoHead;
|
|
65
|
+
const { readRow, importEntries } = this.repo;
|
|
66
|
+
if (typeof readRow === "function") {
|
|
67
|
+
this.judgesRows = true;
|
|
68
|
+
this.delete = (sessionId, guard) => this.deleteOwned(sessionId, guard);
|
|
69
|
+
}
|
|
70
|
+
if (typeof readRow === "function" && typeof importEntries === "function") {
|
|
71
|
+
this.logTransfer = repoLogTransfer({
|
|
72
|
+
readRow: (id) => readRow.call(this.repo, id),
|
|
73
|
+
importEntries: (id, owner, entries, options) => importEntries.call(this.repo, id, owner, entries, options),
|
|
74
|
+
holding: (id, work) => this.holdingId(id, () => {
|
|
75
|
+
this.entries.delete(id);
|
|
76
|
+
return work();
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
54
80
|
}
|
|
81
|
+
const beforeRowDelete = readStoreHooks(opts.hooks);
|
|
82
|
+
if (beforeRowDelete !== undefined)
|
|
83
|
+
this.beforeRowDelete = (sessionId) => Reflect.apply(beforeRowDelete, opts.hooks, [sessionId]);
|
|
55
84
|
if (opts.sweepIntervalMs !== undefined && opts.sweepIntervalMs > 0) {
|
|
56
85
|
this.sweepTimer = setInterval(() => this.sweep(), opts.sweepIntervalMs);
|
|
57
86
|
this.sweepTimer.unref?.();
|
|
@@ -60,12 +89,10 @@ export class TtlSessionStore {
|
|
|
60
89
|
async acquire(sessionId, opts) {
|
|
61
90
|
this.sweep();
|
|
62
91
|
if (sessionId) {
|
|
63
|
-
|
|
64
|
-
if (inflightRelease !== undefined)
|
|
65
|
-
await inflightRelease;
|
|
92
|
+
await this.settledHolds(sessionId);
|
|
66
93
|
const existing = this.entries.get(sessionId);
|
|
67
94
|
if (existing) {
|
|
68
|
-
if (await this.
|
|
95
|
+
if ((await this.standingRow(sessionId, existing)) !== undefined) {
|
|
69
96
|
this.assertPlacementAdmission(sessionId, existing.placement, opts);
|
|
70
97
|
existing.lastActiveAt = Date.now();
|
|
71
98
|
return { session: existing.session, sessionId };
|
|
@@ -105,11 +132,11 @@ export class TtlSessionStore {
|
|
|
105
132
|
return false;
|
|
106
133
|
return this.repoHead === undefined;
|
|
107
134
|
}
|
|
108
|
-
async
|
|
135
|
+
async standingRow(sessionId, cached) {
|
|
109
136
|
if (this.repoHead === undefined)
|
|
110
|
-
return
|
|
111
|
-
const [shown, row] = await Promise.all([cached.session.getMetadata(), this.repoHead(sessionId)]);
|
|
112
|
-
return this.viewStandsFor(shown, row);
|
|
137
|
+
return null;
|
|
138
|
+
const [shown, leaf, row] = await Promise.all([cached.session.getMetadata(), cached.session.getStorage().getLeafId(), this.repoHead(sessionId)]);
|
|
139
|
+
return this.viewStandsFor(shown, row) && row !== undefined && row.leafId === leaf ? row : undefined;
|
|
113
140
|
}
|
|
114
141
|
assertPlacementAdmission(sessionId, placement, opts) {
|
|
115
142
|
const store = this;
|
|
@@ -120,6 +147,28 @@ export class TtlSessionStore {
|
|
|
120
147
|
});
|
|
121
148
|
}
|
|
122
149
|
async openOrCreate(id, requireExisting = false, placement) {
|
|
150
|
+
for (;;) {
|
|
151
|
+
const watch = { overtaken: this.releasing.has(id) };
|
|
152
|
+
const watching = this.resolutions.get(id) ?? new Set();
|
|
153
|
+
watching.add(watch);
|
|
154
|
+
this.resolutions.set(id, watching);
|
|
155
|
+
let session;
|
|
156
|
+
try {
|
|
157
|
+
session = await this.resolveRow(id, requireExisting, placement);
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
watching.delete(watch);
|
|
161
|
+
if (watching.size === 0 && this.resolutions.get(id) === watching)
|
|
162
|
+
this.resolutions.delete(id);
|
|
163
|
+
}
|
|
164
|
+
if (!watch.overtaken)
|
|
165
|
+
return session;
|
|
166
|
+
if (this.entries.get(id)?.session === session)
|
|
167
|
+
this.entries.delete(id);
|
|
168
|
+
await this.settledHolds(id);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async resolveRow(id, requireExisting, placement) {
|
|
123
172
|
try {
|
|
124
173
|
const session = await this.repo.open({ id, createdAt: "" });
|
|
125
174
|
const meta = await session.getMetadata();
|
|
@@ -234,7 +283,14 @@ export class TtlSessionStore {
|
|
|
234
283
|
return;
|
|
235
284
|
return this.holdingId(sessionId, () => this.releaseRow(sessionId, cached));
|
|
236
285
|
}
|
|
286
|
+
async settledHolds(sessionId) {
|
|
287
|
+
const held = this.releasing.get(sessionId);
|
|
288
|
+
if (held !== undefined)
|
|
289
|
+
await held;
|
|
290
|
+
}
|
|
237
291
|
async holdingId(sessionId, work) {
|
|
292
|
+
for (const watch of this.resolutions.get(sessionId) ?? [])
|
|
293
|
+
watch.overtaken = true;
|
|
238
294
|
const prior = this.releasing.get(sessionId);
|
|
239
295
|
let settle;
|
|
240
296
|
const gate = new Promise((r) => (settle = r));
|
|
@@ -242,7 +298,7 @@ export class TtlSessionStore {
|
|
|
242
298
|
try {
|
|
243
299
|
if (prior !== undefined)
|
|
244
300
|
await prior;
|
|
245
|
-
await work();
|
|
301
|
+
return await work();
|
|
246
302
|
}
|
|
247
303
|
finally {
|
|
248
304
|
if (this.releasing.get(sessionId) === gate)
|
|
@@ -253,17 +309,75 @@ export class TtlSessionStore {
|
|
|
253
309
|
async releaseRow(sessionId, cached) {
|
|
254
310
|
if (cached?.placement !== undefined)
|
|
255
311
|
this.pendingPlacedDeletes.add(sessionId);
|
|
256
|
-
const
|
|
312
|
+
const standing = cached !== undefined ? await this.standingRow(sessionId, cached) : undefined;
|
|
313
|
+
const view = standing !== undefined ? cached : undefined;
|
|
314
|
+
const judged = view === undefined && this.repoHead !== undefined && this.rowReadMatters(sessionId) ? await this.repoHead(sessionId) : undefined;
|
|
257
315
|
const placed = view !== undefined ? view.placement !== undefined : await this.rowIsPlaced(sessionId);
|
|
258
316
|
if (view === undefined && !placed)
|
|
259
317
|
return;
|
|
318
|
+
if (!placed) {
|
|
319
|
+
await this.deleteRow(await view.session.getMetadata(), this.idleViewExpectation(standing, view));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
260
322
|
const meta = view !== undefined ? await view.session.getMetadata() : { id: sessionId, createdAt: "" };
|
|
261
|
-
|
|
262
|
-
return this.repo.delete(meta);
|
|
323
|
+
const occupant = view !== undefined ? standing : (judged ?? null);
|
|
263
324
|
this.pendingPlacedDeletes.add(sessionId);
|
|
264
|
-
await this.
|
|
325
|
+
await this.deleteRow(meta, this.judgesRows ? async () => ({ row: occupant }) : undefined);
|
|
265
326
|
this.pendingPlacedDeletes.delete(sessionId);
|
|
266
327
|
}
|
|
328
|
+
idleViewExpectation(standing, view) {
|
|
329
|
+
if (!this.judgesRows || standing === null)
|
|
330
|
+
return undefined;
|
|
331
|
+
return async () => ({ row: standing, log: sessionLogMarkOf(await view.session.getStorage().getEntries()) });
|
|
332
|
+
}
|
|
333
|
+
async deleteRow(meta, expect) {
|
|
334
|
+
if (this.beforeRowDelete !== undefined)
|
|
335
|
+
await this.beforeRowDelete(meta.id);
|
|
336
|
+
if (expect === undefined) {
|
|
337
|
+
await this.repo.delete(meta);
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
await this.repo.delete(meta, await expect());
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
if (isSessionConflict(err))
|
|
345
|
+
return false;
|
|
346
|
+
throw err;
|
|
347
|
+
}
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
async deleteOwned(sessionId, guard) {
|
|
351
|
+
const want = readDeleteGuard(guard);
|
|
352
|
+
return this.holdingId(sessionId, async () => {
|
|
353
|
+
this.entries.delete(sessionId);
|
|
354
|
+
const head = await this.repoHead(sessionId);
|
|
355
|
+
if (head === undefined || head.owner !== want)
|
|
356
|
+
return false;
|
|
357
|
+
if ((await this.readPlacement(sessionId)) !== undefined)
|
|
358
|
+
return false;
|
|
359
|
+
if (!(await this.deleteRow({ id: sessionId, createdAt: "" }, async () => ({ row: head }))))
|
|
360
|
+
return false;
|
|
361
|
+
this.pinned.delete(sessionId);
|
|
362
|
+
return true;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
async rowMetadata(sessionId) {
|
|
366
|
+
try {
|
|
367
|
+
return await (await this.repo.open({ id: sessionId, createdAt: "" })).getMetadata();
|
|
368
|
+
}
|
|
369
|
+
catch (err) {
|
|
370
|
+
if (isNotFound(err))
|
|
371
|
+
return undefined;
|
|
372
|
+
throw err;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
async readPlacement(sessionId) {
|
|
376
|
+
const probe = this.placementProbe();
|
|
377
|
+
if (probe !== undefined)
|
|
378
|
+
return probe(sessionId);
|
|
379
|
+
return (await this.rowMetadata(sessionId))?.placement;
|
|
380
|
+
}
|
|
267
381
|
placementProbe() {
|
|
268
382
|
const probe = this.repo.placementOf;
|
|
269
383
|
return typeof probe === "function" ? probe.bind(this.repo) : undefined;
|
|
@@ -274,10 +388,9 @@ export class TtlSessionStore {
|
|
|
274
388
|
async rowIsPlaced(sessionId) {
|
|
275
389
|
if (!this.rowReadMatters(sessionId))
|
|
276
390
|
return false;
|
|
277
|
-
const probe = this.placementProbe();
|
|
278
391
|
let placement;
|
|
279
392
|
try {
|
|
280
|
-
placement =
|
|
393
|
+
placement = await this.readPlacement(sessionId);
|
|
281
394
|
}
|
|
282
395
|
catch (err) {
|
|
283
396
|
if (!isNotFound(err))
|
|
@@ -296,9 +409,7 @@ export class TtlSessionStore {
|
|
|
296
409
|
this.pinned.delete(sessionId);
|
|
297
410
|
}
|
|
298
411
|
async register(sessionId, owner) {
|
|
299
|
-
|
|
300
|
-
if (inflightRelease !== undefined)
|
|
301
|
-
await inflightRelease;
|
|
412
|
+
await this.settledHolds(sessionId);
|
|
302
413
|
if (await this.hasRow(sessionId))
|
|
303
414
|
return;
|
|
304
415
|
if (owner === undefined)
|
|
@@ -335,8 +446,9 @@ export class TtlSessionStore {
|
|
|
335
446
|
this.entries.delete(id);
|
|
336
447
|
if (this.evictPolicy === "delete" && e.placement === undefined) {
|
|
337
448
|
void this.holdingId(id, async () => {
|
|
338
|
-
|
|
339
|
-
|
|
449
|
+
const standing = await this.standingRow(id, e);
|
|
450
|
+
if (standing !== undefined)
|
|
451
|
+
await this.deleteRow({ id, createdAt: "" }, this.idleViewExpectation(standing, e));
|
|
340
452
|
}).catch(() => { });
|
|
341
453
|
}
|
|
342
454
|
}
|
|
@@ -379,6 +491,32 @@ function newestFirst(a, b) {
|
|
|
379
491
|
return b.lastActiveAt - a.lastActiveAt;
|
|
380
492
|
return a.sessionId < b.sessionId ? 1 : a.sessionId > b.sessionId ? -1 : 0;
|
|
381
493
|
}
|
|
494
|
+
function readStoreHooks(hooks) {
|
|
495
|
+
if (hooks === undefined)
|
|
496
|
+
return undefined;
|
|
497
|
+
if (typeof hooks !== "object" || hooks === null)
|
|
498
|
+
throw receiptRefusal(`TtlSessionStoreOptions.hooks must be an object when given, got ${hooks === null ? "null" : typeof hooks}`);
|
|
499
|
+
const got = receiveOwnProperties(hooks, { subject: "TtlSessionStoreOptions.hooks", unit: "hook", moment: "at construction" });
|
|
500
|
+
for (const name of Object.keys(got)) {
|
|
501
|
+
if (name !== "beforeSessionDelete")
|
|
502
|
+
throw receiptRefusal(`TtlSessionStoreOptions.hooks.${name} is not a hook this store runs (it runs beforeSessionDelete)`);
|
|
503
|
+
}
|
|
504
|
+
const hook = got["beforeSessionDelete"];
|
|
505
|
+
if (hook !== undefined && typeof hook !== "function")
|
|
506
|
+
throw receiptRefusal(`TtlSessionStoreOptions.hooks.beforeSessionDelete must be a function when given, got ${hook === null ? "null" : typeof hook}`);
|
|
507
|
+
return hook;
|
|
508
|
+
}
|
|
509
|
+
function readDeleteGuard(guard) {
|
|
510
|
+
if (typeof guard !== "object" || guard === null)
|
|
511
|
+
throw new TypeError(`SessionStore.delete: the guard must be an object { owner }, got ${guard === null ? "null" : typeof guard}`);
|
|
512
|
+
const owner = readMember(guard, "owner");
|
|
513
|
+
if (owner === null)
|
|
514
|
+
return null;
|
|
515
|
+
const name = principalNameOf(owner);
|
|
516
|
+
if (name === undefined)
|
|
517
|
+
throw new TypeError(`SessionStore.delete: guard.owner must be a principal name or null (anonymous), got ${principalNameFault(owner)}`);
|
|
518
|
+
return name;
|
|
519
|
+
}
|
|
382
520
|
function isNotFound(err) {
|
|
383
521
|
return readMember(err, "code") === "not_found";
|
|
384
522
|
}
|
package/dist/core/session.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { SessionWriteOptions } from "../internal/harness.js";
|
|
|
8
8
|
import type { Session } from "../internal/harness.js";
|
|
9
9
|
import type { SessionHead, SessionTreeEntry } from "../internal/harness.js";
|
|
10
10
|
export type { SessionPlacementRecord } from "../internal/harness.js";
|
|
11
|
-
export type { SessionHead } from "../internal/harness.js";
|
|
11
|
+
export type { SessionHead, SessionLogMark, SessionRowExpectation, SessionRowRead } from "../internal/harness.js";
|
|
12
12
|
/** True when `err` is a session optimistic-lock conflict (a concurrent writer won the branch leaf). Both
|
|
13
13
|
* halves read what a HOST `SessionStorage` threw, so both are guarded — unreadable is not a conflict,
|
|
14
14
|
* never a raise inside the classify-and-rethrow guard. The class test is KEPT: widening the verdict to
|
|
@@ -340,11 +340,102 @@ export interface SessionStore<S extends SessionStoreSummary = SessionStoreSummar
|
|
|
340
340
|
* authorization decision — the caller re-reads {@link headOf} and judges there. The owner lives and dies with its row.
|
|
341
341
|
*/
|
|
342
342
|
register?(sessionId: string, owner: string | null): Promise<void>;
|
|
343
|
+
/**
|
|
344
|
+
* The storage half of moving a session's log between backends (session-sync): read it out ({@link SessionLogTransfer.listEntryIds},
|
|
345
|
+
* {@link SessionLogTransfer.exportStream}) and replace it whole through a staging the readers never see
|
|
346
|
+
* ({@link SessionLogTransfer.beginReplace}). One write law for every store: a commit onto an existing row keeps that row's occupant and
|
|
347
|
+
* owner and lands only on a row that is already the committer's (compared null-safe; another owner's row is refused `conflict`, a placed
|
|
348
|
+
* row `placement_refused`, nothing written); onto an absent id it creates the row recording the committer and a fresh occupant; every
|
|
349
|
+
* entry passes the engine's import gate ({@link StreamingImportValidator}); and the owner check, the relation the committer judges, the
|
|
350
|
+
* write and the head the commit answers are one step — against every writer of the row, not only this instance's: the commit reads the
|
|
351
|
+
* row once (owner, log and head of one generation), `decide` weighs that log, and the write lands only while the row is still that
|
|
352
|
+
* generation with that log (a write through another instance or the repo since then refuses the commit `conflict`, nothing written);
|
|
353
|
+
* the head answered is the one the write committed (on `"keep"`, the one read). A refusal, or a throw from `decide`, writes nothing.
|
|
354
|
+
* **Optional**: absent = this store does not take part in a cross-backend move.
|
|
355
|
+
*/
|
|
356
|
+
readonly logTransfer?: SessionLogTransfer;
|
|
357
|
+
/**
|
|
358
|
+
* Delete a session at its owner's request — the row and its whole log. Only when the row's owner equals `guard.owner` (null-safe:
|
|
359
|
+
* `null` deletes only an anonymous row); a placed row is not deleted here (its deletion is `release`'s, through the joint reap). `true`
|
|
360
|
+
* = this call deleted the row; `false` = there was no row, the guard did not hold, or the row is placed — nothing was deleted, so a
|
|
361
|
+
* repeat is harmless. The id answers nothing afterwards, and a later create under it is a new occupant. A store wired with
|
|
362
|
+
* {@link SessionStoreHooks.beforeSessionDelete} runs it first and deletes nothing when it rejects (the call rejects with it).
|
|
363
|
+
* **Optional**: absent = this store has no owner-guarded delete.
|
|
364
|
+
*/
|
|
365
|
+
delete?(sessionId: string, guard: {
|
|
366
|
+
owner: string | null;
|
|
367
|
+
}): Promise<boolean>;
|
|
343
368
|
/** Number of live/cached sessions (best-effort). */
|
|
344
369
|
readonly size: number;
|
|
345
370
|
/** Release resources (timers, connections). Best-effort; must not throw. */
|
|
346
371
|
dispose(): void | Promise<void>;
|
|
347
372
|
}
|
|
373
|
+
/** What {@link SessionLogTransfer.exportStream} reads: `afterSeq` resumes after that 0-based position of the oldest-first log (absent
|
|
374
|
+
* = from the first entry; an integer ≥ -1); `batchSize` is how many entries a store reads per page (an integer ≥ 1; absent = the store's
|
|
375
|
+
* own page) — a store holding the log whole reads it once whatever the page, the stream is the same. A bad value is refused. */
|
|
376
|
+
export interface SessionLogExportOptions {
|
|
377
|
+
afterSeq?: number;
|
|
378
|
+
batchSize?: number;
|
|
379
|
+
}
|
|
380
|
+
/** The read and replace halves of {@link SessionStore.logTransfer}. */
|
|
381
|
+
export interface SessionLogTransfer {
|
|
382
|
+
/** The ids of the session's whole log, oldest-first (no compaction floor applied); `null` = no such session. */
|
|
383
|
+
listEntryIds(sessionId: string): Promise<readonly string[] | null>;
|
|
384
|
+
/** The session's whole log, oldest-first, as a stream; `null` = no such session (see {@link SessionLogExportOptions}). */
|
|
385
|
+
exportStream(sessionId: string, opts?: SessionLogExportOptions): Promise<AsyncIterable<SessionTreeEntry> | null>;
|
|
386
|
+
/** Open a staging for a replacement of `sessionId`'s log: entries appended to it are invisible to every reader until its commit.
|
|
387
|
+
* `preserveActorAssertions` is the import gate's trusted-source declaration (see {@link StreamingImportValidator}), read here
|
|
388
|
+
* because the gate reads each batch as it is appended. */
|
|
389
|
+
beginReplace(sessionId: string, opts?: {
|
|
390
|
+
preserveActorAssertions?: boolean;
|
|
391
|
+
}): SessionLogReplace;
|
|
392
|
+
}
|
|
393
|
+
/** What a commit's `decide` sees, inside the commit's one step: the destination's entry ids as they stand now (`null` = no row) and the
|
|
394
|
+
* staged ids, and a read of either side's entries by id. */
|
|
395
|
+
export interface SessionLogCommitView {
|
|
396
|
+
readonly current: readonly string[] | null;
|
|
397
|
+
readonly staged: readonly string[];
|
|
398
|
+
read(side: "current" | "staged", ids: readonly string[]): Promise<SessionTreeEntry[]>;
|
|
399
|
+
}
|
|
400
|
+
/** A commit of a staged replacement. */
|
|
401
|
+
export interface SessionLogCommit {
|
|
402
|
+
/** The committing principal (`null` = anonymous) — the authenticated importer, never a value read from the staged log. */
|
|
403
|
+
owner: string | null;
|
|
404
|
+
/** The committer's judgement of the relation between the two logs, inside the commit's one step: `"replace"` writes the staged log,
|
|
405
|
+
* `"keep"` leaves the destination's log as it is (an identical push); a throw writes nothing and the commit rejects with it. */
|
|
406
|
+
decide(view: SessionLogCommitView): "replace" | "keep" | Promise<"replace" | "keep">;
|
|
407
|
+
}
|
|
408
|
+
/** One staging opened by {@link SessionLogTransfer.beginReplace}. After its commit settles (either way) or its abort, it takes nothing more. */
|
|
409
|
+
export interface SessionLogReplace {
|
|
410
|
+
/** An opaque name of this staging. */
|
|
411
|
+
readonly stagingId: string;
|
|
412
|
+
/** Stage a batch, after the batches before it; each entry passes the import gate here, and a refused batch refuses the staging. */
|
|
413
|
+
append(entries: readonly SessionTreeEntry[]): Promise<void>;
|
|
414
|
+
/** The commit point: the write law of {@link SessionStore.logTransfer}, then `decide`, then the write and the head the row holds
|
|
415
|
+
* after it, in one step. Before it settles, no reader sees the staged log; a refusal, or a throw from `decide`, writes nothing; a row
|
|
416
|
+
* written by anyone else since the commit read it refuses it `conflict` (read the row again and stage again). The first commit call
|
|
417
|
+
* ends the staging, whatever its outcome. */
|
|
418
|
+
commit(input: SessionLogCommit): Promise<{
|
|
419
|
+
outcome: "replaced" | "kept";
|
|
420
|
+
head: SessionHead;
|
|
421
|
+
}>;
|
|
422
|
+
/** Drop the staging; nothing is written. Idempotent. */
|
|
423
|
+
abort(): Promise<void>;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* A deployment's hooks on a session store's row deletions — the cleanup of the deployment's own records keyed by session id (a title, a
|
|
427
|
+
* pin, an instruction baseline). `beforeSessionDelete` runs, and is awaited, before every deletion of a row the store makes (an owner's
|
|
428
|
+
* {@link SessionStore.delete}, a placed `release`, an `evict: "delete"` release or idle sweep); when it rejects the row is not deleted and
|
|
429
|
+
* the deletion fails with it — an owner's `delete` or a placed `release` called again runs both again, while an ordinary release has
|
|
430
|
+
* dropped its view and, like any failed ordinary release, has nothing more to delete. The deletion after the hook lands only on the row
|
|
431
|
+
* the store judged (the repo judges it in the step that removes the row — another writer may have deleted the row, created another under
|
|
432
|
+
* the id, or written it while the hook ran); a row that is no longer the one judged is not deleted. The row is still there while the hook
|
|
433
|
+
* runs, so no create under the same id can meet the deployment's records for the occupant being deleted. Called with the id only; it
|
|
434
|
+
* must be idempotent.
|
|
435
|
+
*/
|
|
436
|
+
export interface SessionStoreHooks {
|
|
437
|
+
beforeSessionDelete?(sessionId: string): void | Promise<void>;
|
|
438
|
+
}
|
|
348
439
|
/** Structural detection: does this store expose the optional {@link SessionStore.fork}? Mounts the fork
|
|
349
440
|
* capability only when true (INERT otherwise — mirrors `hasScheduler`/`hasBackgroundShell`). */
|
|
350
441
|
export declare function hasSessionFork(store: SessionStore): store is SessionStore & {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AssistantMessage, StopReason, Tool, ToolResultMessage, Usage, UserMessage } from "../internal/llm.js";
|
|
2
|
-
import type { Brain, Model, ModelRef, ModelRole, ModelRoles, TaskSpec, ThinkingLevel } from "./types.js";
|
|
2
|
+
import type { Brain, Model, ModelRef, ModelRole, ModelRoles, RunnerDeps, TaskSpec, ThinkingLevel } from "./types.js";
|
|
3
|
+
import type { AccountRow } from "./account-row.js";
|
|
3
4
|
import { type DegradationInfo } from "../brain/degrading.js";
|
|
4
5
|
import { type BrainErrorCode } from "../brain/errors.js";
|
|
5
6
|
/** A tool DEFINITION exposed to the model in a side query (never executed by the engine). */
|
|
@@ -113,6 +114,13 @@ export interface SideQueryResult {
|
|
|
113
114
|
* figures, untouched. `usageMissing` ⇒ the numbers are UNKNOWN shells, not zeros. */
|
|
114
115
|
usage: Usage;
|
|
115
116
|
usageMissing?: true;
|
|
117
|
+
/** This query's line in the session's account: `origin: "side_query"`, priced by the engine from the deployment's price table
|
|
118
|
+
* (the arithmetic a run's own model calls use; `usage.cost` above stays the provider's own figure), the model that ANSWERED
|
|
119
|
+
* being the one priced. A host that keeps the account keeps this line beside its run lines and reads them back through
|
|
120
|
+
* `foldAccount`. `costMicroUsd` is absent when that model has no price table (unknown, not free); a reply that reported
|
|
121
|
+
* no usage yields `tokens: 0` with `usageMissing`. A malformed price table prices at its arithmetic, as it does for a run
|
|
122
|
+
* whose deployment governs no money. */
|
|
123
|
+
account: AccountRow;
|
|
116
124
|
stopReason: StopReason;
|
|
117
125
|
/** Present on `stopReason:"error"|"aborted"` — the query did not produce a usable reply. The verb
|
|
118
126
|
* RETURNS the honest failure instead of throwing: utility callers uniformly need "no answer +
|
|
@@ -133,5 +141,7 @@ export interface SideQueryDeps {
|
|
|
133
141
|
brain: Brain;
|
|
134
142
|
models?: Record<string, Model>;
|
|
135
143
|
roles?: ModelRoles;
|
|
144
|
+
/** The deployment's price table (`RunnerDeps.pricing`) the result's `account` line is priced from; absent ⇒ the model's own `cost`, else unpriced. */
|
|
145
|
+
pricing?: RunnerDeps["pricing"];
|
|
136
146
|
}
|
|
137
147
|
export declare function runSideQuery(spec: SideQuerySpec, deps: SideQueryDeps): Promise<SideQueryResult>;
|
package/dist/core/side-query.js
CHANGED
|
@@ -6,6 +6,7 @@ import { effectiveTraitsOf, readModelPromptTraits, selectorsOf } from "../prompt
|
|
|
6
6
|
import { readDegradation } from "../brain/degrading.js";
|
|
7
7
|
import { extractErrorCode } from "../brain/errors.js";
|
|
8
8
|
import { cacheFamilyOf, uncachedInputTokensOf } from "./runner/usage-accounting.js";
|
|
9
|
+
import { priceReply } from "./runner/reply-pricing.js";
|
|
9
10
|
import { providerReportedModel } from "./message-utils.js";
|
|
10
11
|
import { providerToolCallId } from "../brain/tool-call-id.js";
|
|
11
12
|
function normalizeSideQueryUsage(model, u) {
|
|
@@ -82,6 +83,13 @@ export async function runSideQuery(spec, deps) {
|
|
|
82
83
|
const servedModel = typeof msg.model === "string" && msg.model.length > 0 ? msg.model : resolved.model.id;
|
|
83
84
|
const reportedModel = providerReportedModel(msg);
|
|
84
85
|
const errorCode = extractErrorCode(msg.errorMessage);
|
|
86
|
+
const priced = priceReply(msg.usage, { model: resolved.model, ...(degraded !== undefined && degraded.to !== resolved.model.id ? { servedBy: degraded.to } : {}) }, { pricing: deps.pricing, catalog: deps.models });
|
|
87
|
+
const account = {
|
|
88
|
+
origin: "side_query",
|
|
89
|
+
tokens: msg.usage.totalTokens || 0,
|
|
90
|
+
...(priced.priced ? { costMicroUsd: priced.costMicroUsd } : {}),
|
|
91
|
+
...(msg.usageMissing === true ? { usageMissing: true } : {}),
|
|
92
|
+
};
|
|
85
93
|
return {
|
|
86
94
|
text,
|
|
87
95
|
toolCalls,
|
|
@@ -91,6 +99,7 @@ export async function runSideQuery(spec, deps) {
|
|
|
91
99
|
...(reportedModel !== undefined ? { responseModel: reportedModel } : {}),
|
|
92
100
|
usage: normalizeSideQueryUsage(resolved.model, msg.usage),
|
|
93
101
|
...(msg.usageMissing === true ? { usageMissing: true } : {}),
|
|
102
|
+
account,
|
|
94
103
|
stopReason: msg.stopReason,
|
|
95
104
|
...(msg.errorMessage !== undefined ? { errorMessage: msg.errorMessage } : {}),
|
|
96
105
|
...(msg.stopReason === "error" && errorCode !== undefined ? { errorCode } : {}),
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* What a Skill card's approval is bound to, as ONE value: the skill the call names and the two lists approving it releases,
|
|
3
3
|
* in the rule grammar's canonical spelling (de-duplicated, sorted). Its hash is the `boundGrantDigest` a parked approval is
|
|
4
4
|
* judged by, so a reader holds the list a person approved and the binding that covers it as the same fact — the live
|
|
5
|
-
* `AskRequest`, the parked row
|
|
5
|
+
* `AskRequest`, the parked row, the inbox projection and the request a Runner hands a policy all carry it (minted by
|
|
6
|
+
* `skillGrantBindingMembers`; on a request through {@link requestGrantBinding}).
|
|
6
7
|
*
|
|
7
8
|
* A leaf on purpose: the checkpoint projection reads it at its boundary and may not import the module that mints it (it imports only
|
|
8
9
|
* the hash).
|
|
@@ -18,7 +19,8 @@ export interface BoundSkillGrants {
|
|
|
18
19
|
/**
|
|
19
20
|
* Why a card carries no binding digest — the closed set of `boundGrantAbsence`: `not_bindable` (the call is not an
|
|
20
21
|
* activation of the engine's `Skill` tool: it binds no grant) or `unreadable` (the card binds a grant and what it binds
|
|
21
|
-
* cannot be read: a stored row whose digest is not a string, or that says neither
|
|
22
|
+
* cannot be read: a stored row whose digest is not a string, or that says neither; a request copied over moved args whose
|
|
23
|
+
* digest the engine did not mint for that call, {@link withArgsBinding}).
|
|
22
24
|
*/
|
|
23
25
|
export declare const BOUND_GRANT_ABSENCES: readonly ["not_bindable", "unreadable"];
|
|
24
26
|
export type BoundGrantAbsence = (typeof BOUND_GRANT_ABSENCES)[number];
|
|
@@ -63,3 +65,30 @@ export declare function readBoundBinding(row: {
|
|
|
63
65
|
} | {
|
|
64
66
|
boundGrantAbsence: BoundGrantAbsence;
|
|
65
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* The grant-binding words of a request a Runner hands a policy — the leg's card factory `of` over the request's own `args` (the members
|
|
70
|
+
* every card of the call carries, by the same function): the digest arm with its value frozen, or the factory's absence word. The digest
|
|
71
|
+
* arm carries a note of how the same call is minted over other args, so a copy of the request over moved args carries the answer for
|
|
72
|
+
* THOSE ({@link withArgsBinding}).
|
|
73
|
+
*/
|
|
74
|
+
export declare function requestGrantBinding(of: GrantBindingOf, call: {
|
|
75
|
+
readonly toolName: string;
|
|
76
|
+
}, args: unknown): SkillGrantBindingMembers;
|
|
77
|
+
/** A carrier of a call's binding words — a request or a row: its tool name, its args and the three members, as stored. */
|
|
78
|
+
export interface GrantBindingCarrier {
|
|
79
|
+
readonly toolName?: unknown;
|
|
80
|
+
readonly args: unknown;
|
|
81
|
+
readonly boundGrantDigest?: unknown;
|
|
82
|
+
readonly boundGrants?: unknown;
|
|
83
|
+
readonly boundGrantAbsence?: unknown;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The carrier moved to other args — a copy holding `args` and the binding for THEM (a carrier that holds none moves with none). The
|
|
87
|
+
* binding follows the args by ONE rule: a digest {@link requestGrantBinding} minted for this call is minted again over `args`; a digest
|
|
88
|
+
* with no such note (a clone, a host-built request, a note minted for another call or digest) holds over the same bytes and reads
|
|
89
|
+
* `unreadable` over moved ones — it binds a grant, and what it binds over these args cannot be read here; an absence word holds for any
|
|
90
|
+
* args of the call (args never make a call a `Skill` activation, nor an unreadable binding readable). Every member is read as
|
|
91
|
+
* {@link readBoundBinding} reads a row: a digest that is not a string, or a word outside the set, moves as `unreadable`; lists that do
|
|
92
|
+
* not hash to the digest are dropped (the digest alone holds over the same bytes). Lists a request carries are a frozen copy.
|
|
93
|
+
*/
|
|
94
|
+
export declare function withArgsBinding<R extends GrantBindingCarrier>(carrier: R, args: unknown): R;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { boundInputHashOf } from "./canonical-json.js";
|
|
1
|
+
import { boundInputHashOf, canonicalize } from "./canonical-json.js";
|
|
2
2
|
export const BOUND_GRANT_ABSENCES = Object.freeze(["not_bindable", "unreadable"]);
|
|
3
3
|
const BOUND_GRANT_ABSENCE_SET = new Set(BOUND_GRANT_ABSENCES);
|
|
4
4
|
const isBoundGrantAbsence = (v) => BOUND_GRANT_ABSENCE_SET.has(v);
|
|
@@ -28,3 +28,33 @@ export function readBoundBinding(row) {
|
|
|
28
28
|
const word = row.boundGrantAbsence;
|
|
29
29
|
return { boundGrantAbsence: digest === undefined && isBoundGrantAbsence(word) ? word : "unreadable" };
|
|
30
30
|
}
|
|
31
|
+
const REMINT = new WeakMap();
|
|
32
|
+
export function requestGrantBinding(of, call, args) {
|
|
33
|
+
const members = of(call, args);
|
|
34
|
+
if (members.boundGrants === undefined)
|
|
35
|
+
return members;
|
|
36
|
+
const boundGrants = frozenGrants(members.boundGrants);
|
|
37
|
+
const toolName = call.toolName;
|
|
38
|
+
REMINT.set(boundGrants, { toolName, digest: members.boundGrantDigest, remint: (moved) => requestGrantBinding(of, { toolName }, moved) });
|
|
39
|
+
return { boundGrantDigest: members.boundGrantDigest, boundGrants };
|
|
40
|
+
}
|
|
41
|
+
export function withArgsBinding(carrier, args) {
|
|
42
|
+
if (carrier.boundGrantDigest === undefined && carrier.boundGrants === undefined && carrier.boundGrantAbsence === undefined)
|
|
43
|
+
return { ...carrier, args };
|
|
44
|
+
return { ...carrier, args, boundGrantDigest: undefined, boundGrants: undefined, boundGrantAbsence: undefined, ...movedBinding(carrier, args) };
|
|
45
|
+
}
|
|
46
|
+
function movedBinding(carrier, args) {
|
|
47
|
+
const grants = carrier.boundGrants;
|
|
48
|
+
const note = typeof grants === "object" && grants !== null ? REMINT.get(grants) : undefined;
|
|
49
|
+
if (note !== undefined && note.digest === carrier.boundGrantDigest && note.toolName === carrier.toolName)
|
|
50
|
+
return note.remint(args);
|
|
51
|
+
const read = readBoundBinding(carrier);
|
|
52
|
+
if (!("boundGrantDigest" in read))
|
|
53
|
+
return read;
|
|
54
|
+
if (canonicalize(args) !== canonicalize(carrier.args))
|
|
55
|
+
return { boundGrantAbsence: "unreadable" };
|
|
56
|
+
return read.boundGrants !== undefined ? { boundGrantDigest: read.boundGrantDigest, boundGrants: frozenGrants(read.boundGrants) } : read;
|
|
57
|
+
}
|
|
58
|
+
function frozenGrants(g) {
|
|
59
|
+
return Object.freeze({ skill: g.skill, allowedTools: Object.freeze([...g.allowedTools]), disallowedTools: Object.freeze([...g.disallowedTools]) });
|
|
60
|
+
}
|
|
@@ -50,7 +50,8 @@ export declare function skillNamedBy<T extends Pick<SkillGrantSource, "name">>(a
|
|
|
50
50
|
export declare function skillGrantDigest(skill: Pick<SkillGrantSource, "name" | "allowedTools" | "disallowedTools"> | undefined): string;
|
|
51
51
|
/**
|
|
52
52
|
* The card members of a call to the engine's `Skill` tool — the ONE factory every ask spreads them from: the live
|
|
53
|
-
* `AskRequest` an approver is handed, an ancestor's, the parked row and (through the row) the inbox projection
|
|
53
|
+
* `AskRequest` an approver is handed, an ancestor's, the parked row and (through the row) the inbox projection — and, through
|
|
54
|
+
* `requestGrantBinding`, the request a Runner hands a policy (`ToolCallRequest`: the same members over the request's own args).
|
|
54
55
|
* `boundGrants` is the skill's name and canonical lists, `boundGrantDigest` its hash — the same value, so what a person was
|
|
55
56
|
* shown and what an approving resume is judged by cannot differ. The binding is a property of the CALL, whoever asked and
|
|
56
57
|
* however the question was worded. Every other call — and any call when no skill is loaded (no engine `Skill` tool is
|
|
@@ -118,9 +119,10 @@ export declare function skillAllowDecision(hit: SkillGrantHit, updatedInput: unk
|
|
|
118
119
|
/**
|
|
119
120
|
* The Skill card's question: the reference implementation's sentence (`Execute skill: <name>`), and — when approving
|
|
120
121
|
* releases anything — the entries it releases for the rest of the run in this mode (an entry that grants nothing, or
|
|
121
|
-
* stands down in this mode, is not named). Deployment text,
|
|
122
|
+
* stands down in this mode, is not named — under the leg's `classifyAllShell` in `auto`, no shell entry). Deployment text,
|
|
123
|
+
* sanitized and capped.
|
|
122
124
|
*/
|
|
123
|
-
export declare function skillActivationQuestion(skill: SkillGrantSource, mode: PermissionMode | undefined, roster?: ReadonlySet<string>): string;
|
|
125
|
+
export declare function skillActivationQuestion(skill: SkillGrantSource, mode: PermissionMode | undefined, allShell: boolean, roster?: ReadonlySet<string>): string;
|
|
124
126
|
/** The face the gate and the resumed execution boundary read the table through, bound to the leg's call facts. */
|
|
125
127
|
export interface SkillGrantLane {
|
|
126
128
|
/** The allow layer's skill member: what grants this call in this mode, or undefined. */
|
|
@@ -150,8 +152,9 @@ export interface SkillGateSeats {
|
|
|
150
152
|
}
|
|
151
153
|
/** The `Skill` tool's per-call seat over the loaded skills: a skill that declares a list states no permission of its own. */
|
|
152
154
|
export type SkillSeatReader = (args: unknown, mode: PermissionMode | undefined) => PermissionSeatReading | undefined;
|
|
153
|
-
/** The reader over these skills (`undefined` when none is loaded): `Execute skill: <name>` for a skill declaring a list.
|
|
154
|
-
|
|
155
|
+
/** The reader over these skills (`undefined` when none is loaded): `Execute skill: <name>` for a skill declaring a list.
|
|
156
|
+
* `allShell`: the leg's `classifyAllShell` declaration (the card names only what approving releases in the call's mode). */
|
|
157
|
+
export declare function skillSeatReader(skills: readonly SkillGrantSource[], allShell: boolean, mounted?: MountedToolNames): SkillSeatReader | undefined;
|
|
155
158
|
/**
|
|
156
159
|
* The gate's seat inputs for one call, composed in ONE place: the mounted instance's static seat (`calledName`), the `Skill`
|
|
157
160
|
* tool's per-call reader in the leg's live mode (only when the call's wire name is the engine's `Skill` — `skillToolName`),
|