attention-manifest-protocol 0.4.0 → 0.4.2
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 +250 -226
- package/CHANGELOG.zh-CN.md +63 -39
- package/README.md +22 -1
- package/README.zh-CN.md +22 -1
- package/docs/probes/calibration-imported.json +141 -141
- package/docs/probes/eval-recorded-replay.json +597 -597
- package/docs/probes/eval-replay.json +124 -124
- package/docs/probes/eval-summary.json +42 -42
- package/docs/probes/runtime-eval.json +4230 -4230
- package/lib/attention/attention.d.ts +153 -0
- package/lib/attention/attention.js +209 -0
- package/lib/attention/budget.d.ts +31 -0
- package/lib/attention/budget.js +55 -0
- package/lib/attention/cognition.d.ts +230 -0
- package/lib/attention/cognition.js +245 -0
- package/lib/attention/index.d.ts +8 -0
- package/lib/attention/index.js +7 -0
- package/lib/attention/interrupts.d.ts +97 -0
- package/lib/attention/interrupts.js +151 -0
- package/lib/attention/resource.d.ts +167 -0
- package/lib/attention/resource.js +148 -0
- package/lib/attention/social.d.ts +74 -0
- package/lib/attention/social.js +153 -0
- package/lib/attention/socialTypes.d.ts +102 -0
- package/lib/attention/socialTypes.js +1 -0
- package/lib/authz/authz.d.ts +75 -0
- package/lib/authz/authz.js +176 -0
- package/lib/authz/index.d.ts +1 -0
- package/lib/authz/index.js +1 -0
- package/lib/bayes/calibration.d.ts +67 -0
- package/lib/bayes/calibration.js +114 -0
- package/lib/bayes/calibrationRegistry.d.ts +39 -0
- package/lib/bayes/calibrationRegistry.js +61 -0
- package/lib/bayes/calibrationSelection.d.ts +40 -0
- package/lib/bayes/calibrationSelection.js +89 -0
- package/lib/bayes/engine.d.ts +163 -0
- package/lib/bayes/engine.js +354 -0
- package/lib/bayes/index.d.ts +6 -0
- package/lib/bayes/index.js +6 -0
- package/lib/bayes/reliability.d.ts +27 -0
- package/lib/bayes/reliability.js +38 -0
- package/lib/bayes/scopedPriors.d.ts +34 -0
- package/lib/bayes/scopedPriors.js +70 -0
- package/lib/boundary/frame.d.ts +63 -0
- package/lib/boundary/frame.js +239 -0
- package/lib/boundary/ids.d.ts +8 -0
- package/lib/boundary/ids.js +12 -0
- package/lib/boundary/index.d.ts +12 -0
- package/lib/boundary/index.js +8 -0
- package/lib/boundary/refTable.d.ts +49 -0
- package/lib/boundary/refTable.js +92 -0
- package/lib/boundary/toolCall.d.ts +33 -0
- package/lib/boundary/toolCall.js +173 -0
- package/lib/concept/concept.d.ts +67 -0
- package/lib/concept/concept.js +1 -0
- package/lib/concept/conceptBudget.d.ts +56 -0
- package/lib/concept/conceptBudget.js +281 -0
- package/lib/concept/conceptBudgetTypes.d.ts +74 -0
- package/lib/concept/conceptBudgetTypes.js +1 -0
- package/lib/concept/index.d.ts +3 -0
- package/lib/concept/index.js +3 -0
- package/lib/concurrency/idempotency.d.ts +16 -0
- package/lib/concurrency/idempotency.js +21 -0
- package/lib/concurrency/index.d.ts +5 -0
- package/lib/concurrency/index.js +5 -0
- package/lib/concurrency/mutex.d.ts +13 -0
- package/lib/concurrency/mutex.js +26 -0
- package/lib/concurrency/namedLocks.d.ts +7 -0
- package/lib/concurrency/namedLocks.js +31 -0
- package/lib/concurrency/retry.d.ts +23 -0
- package/lib/concurrency/retry.js +38 -0
- package/lib/concurrency/worker.d.ts +42 -0
- package/lib/concurrency/worker.js +67 -0
- package/lib/context/agentContext.d.ts +58 -0
- package/lib/context/agentContext.js +197 -0
- package/lib/context/ast.d.ts +98 -0
- package/lib/context/ast.js +414 -0
- package/lib/context/contentStore.d.ts +16 -0
- package/lib/context/contentStore.js +61 -0
- package/lib/context/context.d.ts +15 -0
- package/lib/context/context.js +39 -0
- package/lib/context/contextIndex.d.ts +40 -0
- package/lib/context/contextIndex.js +64 -0
- package/lib/context/document.d.ts +102 -0
- package/lib/context/document.js +22 -0
- package/lib/context/fileStorePath.d.ts +1 -0
- package/lib/context/fileStorePath.js +13 -0
- package/lib/context/index.d.ts +22 -0
- package/lib/context/index.js +11 -0
- package/lib/context/lifecycle.d.ts +91 -0
- package/lib/context/lifecycle.js +163 -0
- package/lib/context/projections.d.ts +20 -0
- package/lib/context/projections.js +127 -0
- package/lib/context/workspace.d.ts +111 -0
- package/lib/context/workspace.js +318 -0
- package/lib/context/workspaceProtocol.d.ts +30 -0
- package/lib/context/workspaceProtocol.js +49 -0
- package/lib/context/workspaceService.d.ts +63 -0
- package/lib/context/workspaceService.js +352 -0
- package/lib/cooperation/board.d.ts +47 -0
- package/lib/cooperation/board.js +66 -0
- package/lib/cooperation/collaboration.d.ts +55 -0
- package/lib/cooperation/collaboration.js +1 -0
- package/lib/cooperation/index.d.ts +6 -0
- package/lib/cooperation/index.js +6 -0
- package/lib/cooperation/merge.d.ts +69 -0
- package/lib/cooperation/merge.js +109 -0
- package/lib/cooperation/metrics.d.ts +39 -0
- package/lib/cooperation/metrics.js +17 -0
- package/lib/cooperation/session.d.ts +75 -0
- package/lib/cooperation/session.js +74 -0
- package/lib/cooperation/unified.d.ts +38 -0
- package/lib/cooperation/unified.js +40 -0
- package/lib/database/adapter/adapters.d.ts +24 -0
- package/lib/database/adapter/adapters.js +31 -0
- package/lib/database/adapter/index.d.ts +4 -0
- package/lib/database/adapter/index.js +4 -0
- package/lib/database/adapter/runtimeSink.d.ts +20 -0
- package/lib/database/adapter/runtimeSink.js +50 -0
- package/lib/database/adapter/sessionStore.d.ts +11 -0
- package/lib/database/adapter/sessionStore.js +23 -0
- package/lib/database/adapter/turnStore.d.ts +10 -0
- package/lib/database/adapter/turnStore.js +15 -0
- package/lib/database/entity/agent.d.ts +133 -0
- package/lib/database/entity/agent.js +61 -0
- package/lib/database/entity/entity.d.ts +715 -0
- package/lib/database/entity/entity.js +372 -0
- package/lib/database/entity/handle.d.ts +31 -0
- package/lib/database/entity/handle.js +53 -0
- package/lib/database/entity/index.d.ts +32 -0
- package/lib/database/entity/index.js +22 -0
- package/lib/database/entity/message.d.ts +27 -0
- package/lib/database/entity/message.js +52 -0
- package/lib/database/entity/meta.d.ts +11 -0
- package/lib/database/entity/meta.js +1 -0
- package/lib/database/entity/object.d.ts +23 -0
- package/lib/database/entity/object.js +24 -0
- package/lib/database/entity/outbox.d.ts +9 -0
- package/lib/database/entity/outbox.js +5 -0
- package/lib/database/entity/process.d.ts +30 -0
- package/lib/database/entity/process.js +40 -0
- package/lib/database/entity/registry.d.ts +81 -0
- package/lib/database/entity/registry.js +91 -0
- package/lib/database/entity/runtimeApproval.d.ts +23 -0
- package/lib/database/entity/runtimeApproval.js +5 -0
- package/lib/database/entity/runtimeSession.d.ts +7 -0
- package/lib/database/entity/runtimeSession.js +5 -0
- package/lib/database/entity/runtimeTurn.d.ts +9 -0
- package/lib/database/entity/runtimeTurn.js +5 -0
- package/lib/database/entity/thread.d.ts +35 -0
- package/lib/database/entity/thread.js +55 -0
- package/lib/database/entity/window.d.ts +39 -0
- package/lib/database/entity/window.js +56 -0
- package/lib/database/entity/worker.d.ts +42 -0
- package/lib/database/entity/worker.js +58 -0
- package/lib/database/index.d.ts +6 -0
- package/lib/database/index.js +6 -0
- package/lib/database/repository/addressSpaceRepository.d.ts +18 -0
- package/lib/database/repository/addressSpaceRepository.js +40 -0
- package/lib/database/repository/agentRepository.d.ts +41 -0
- package/lib/database/repository/agentRepository.js +398 -0
- package/lib/database/repository/base.d.ts +31 -0
- package/lib/database/repository/base.js +23 -0
- package/lib/database/repository/executionRepository.d.ts +64 -0
- package/lib/database/repository/executionRepository.js +379 -0
- package/lib/database/repository/handleRepository.d.ts +35 -0
- package/lib/database/repository/handleRepository.js +57 -0
- package/lib/database/repository/index.d.ts +20 -0
- package/lib/database/repository/index.js +17 -0
- package/lib/database/repository/messageRepository.d.ts +33 -0
- package/lib/database/repository/messageRepository.js +45 -0
- package/lib/database/repository/objectRepository.d.ts +43 -0
- package/lib/database/repository/objectRepository.js +60 -0
- package/lib/database/repository/outboxRepository.d.ts +15 -0
- package/lib/database/repository/outboxRepository.js +51 -0
- package/lib/database/repository/processRepository.d.ts +31 -0
- package/lib/database/repository/processRepository.js +48 -0
- package/lib/database/repository/registryRepository.d.ts +72 -0
- package/lib/database/repository/registryRepository.js +95 -0
- package/lib/database/repository/repository.d.ts +322 -0
- package/lib/database/repository/repository.js +332 -0
- package/lib/database/repository/runtimeApprovalRepository.d.ts +14 -0
- package/lib/database/repository/runtimeApprovalRepository.js +35 -0
- package/lib/database/repository/runtimeSessionRepository.d.ts +9 -0
- package/lib/database/repository/runtimeSessionRepository.js +21 -0
- package/lib/database/repository/runtimeTurnRepository.d.ts +10 -0
- package/lib/database/repository/runtimeTurnRepository.js +32 -0
- package/lib/database/repository/socialRepository.d.ts +22 -0
- package/lib/database/repository/socialRepository.js +155 -0
- package/lib/database/repository/threadRepository.d.ts +29 -0
- package/lib/database/repository/threadRepository.js +48 -0
- package/lib/database/repository/windowRepository.d.ts +46 -0
- package/lib/database/repository/windowRepository.js +68 -0
- package/lib/database/repository/workerRepository.d.ts +38 -0
- package/lib/database/repository/workerRepository.js +61 -0
- package/lib/database/service/database.d.ts +55 -0
- package/lib/database/service/database.js +77 -0
- package/lib/database/service/handleService.d.ts +20 -0
- package/lib/database/service/handleService.js +34 -0
- package/lib/database/service/index.d.ts +16 -0
- package/lib/database/service/index.js +11 -0
- package/lib/database/service/messageService.d.ts +26 -0
- package/lib/database/service/messageService.js +40 -0
- package/lib/database/service/objectService.d.ts +32 -0
- package/lib/database/service/objectService.js +31 -0
- package/lib/database/service/processService.d.ts +22 -0
- package/lib/database/service/processService.js +45 -0
- package/lib/database/service/registryServices.d.ts +43 -0
- package/lib/database/service/registryServices.js +60 -0
- package/lib/database/service/service.d.ts +131 -0
- package/lib/database/service/service.js +153 -0
- package/lib/database/service/stepService.d.ts +23 -0
- package/lib/database/service/stepService.js +35 -0
- package/lib/database/service/threadService.d.ts +23 -0
- package/lib/database/service/threadService.js +48 -0
- package/lib/database/service/windowService.d.ts +15 -0
- package/lib/database/service/windowService.js +22 -0
- package/lib/database/service/workerService.d.ts +28 -0
- package/lib/database/service/workerService.js +34 -0
- package/lib/database/sql/index.d.ts +3 -0
- package/lib/database/sql/index.js +2 -0
- package/lib/database/sql/schema.d.ts +5 -0
- package/lib/database/sql/schema.js +416 -0
- package/lib/database/sql/sql.d.ts +290 -0
- package/lib/database/sql/sql.js +430 -0
- package/lib/database/store/database.d.ts +75 -0
- package/lib/database/store/database.js +143 -0
- package/lib/database/store/index.d.ts +3 -0
- package/lib/database/store/index.js +2 -0
- package/lib/database/store/store.d.ts +145 -0
- package/lib/database/store/store.js +192 -0
- package/lib/delegate/index.d.ts +2 -0
- package/lib/delegate/index.js +2 -0
- package/lib/delegate/team.d.ts +92 -0
- package/lib/delegate/team.js +200 -0
- package/lib/delegate/teamTypes.d.ts +43 -0
- package/lib/delegate/teamTypes.js +1 -0
- package/lib/diagnosis/checklist.d.ts +16 -0
- package/lib/diagnosis/checklist.js +61 -0
- package/lib/diagnosis/context.d.ts +19 -0
- package/lib/diagnosis/context.js +79 -0
- package/lib/diagnosis/frame.d.ts +34 -0
- package/lib/diagnosis/frame.js +230 -0
- package/lib/diagnosis/index.d.ts +5 -0
- package/lib/diagnosis/index.js +5 -0
- package/lib/diagnosis/router.d.ts +22 -0
- package/lib/diagnosis/router.js +47 -0
- package/lib/diagnosis/types.d.ts +78 -0
- package/lib/diagnosis/types.js +2 -0
- package/lib/error/agentError.d.ts +9 -0
- package/lib/error/agentError.js +13 -0
- package/lib/error/ampError.d.ts +14 -0
- package/lib/error/ampError.js +19 -0
- package/lib/error/authzError.d.ts +10 -0
- package/lib/error/authzError.js +11 -0
- package/lib/error/boundaryRejection.d.ts +16 -0
- package/lib/error/boundaryRejection.js +14 -0
- package/lib/error/index.d.ts +7 -0
- package/lib/error/index.js +7 -0
- package/lib/error/kernelError.d.ts +11 -0
- package/lib/error/kernelError.js +12 -0
- package/lib/error/mailboxError.d.ts +5 -0
- package/lib/error/mailboxError.js +6 -0
- package/lib/error/windowError.d.ts +8 -0
- package/lib/error/windowError.js +9 -0
- package/lib/evaluation/agreement.d.ts +22 -0
- package/lib/evaluation/agreement.js +82 -0
- package/lib/evaluation/index.d.ts +2 -0
- package/lib/evaluation/index.js +2 -0
- package/lib/evaluation/labels.d.ts +56 -0
- package/lib/evaluation/labels.js +206 -0
- package/lib/evidence/evidenceGraph.d.ts +37 -0
- package/lib/evidence/evidenceGraph.js +165 -0
- package/lib/evidence/index.d.ts +4 -0
- package/lib/evidence/index.js +2 -0
- package/lib/evidence/revalidation.d.ts +70 -0
- package/lib/evidence/revalidation.js +146 -0
- package/lib/execution/exec.d.ts +151 -0
- package/lib/execution/exec.js +282 -0
- package/lib/execution/handles.d.ts +25 -0
- package/lib/execution/handles.js +45 -0
- package/lib/execution/index.d.ts +3 -0
- package/lib/execution/index.js +3 -0
- package/lib/execution/pin.d.ts +60 -0
- package/lib/execution/pin.js +103 -0
- package/lib/frame/frame.d.ts +61 -0
- package/lib/frame/frame.js +1 -0
- package/lib/frame/index.d.ts +1 -0
- package/lib/frame/index.js +1 -0
- package/lib/goal/goal.d.ts +19 -0
- package/lib/goal/goal.js +21 -0
- package/lib/goal/index.d.ts +2 -0
- package/lib/goal/index.js +1 -0
- package/lib/goal/plan.d.ts +125 -0
- package/lib/goal/plan.js +60 -0
- package/lib/governance/attentionManifest.d.ts +279 -0
- package/lib/governance/attentionManifest.js +467 -0
- package/lib/governance/audit.d.ts +123 -0
- package/lib/governance/audit.js +263 -0
- package/lib/governance/budget.d.ts +219 -0
- package/lib/governance/budget.js +424 -0
- package/lib/governance/context.d.ts +159 -0
- package/lib/governance/context.js +229 -0
- package/lib/governance/control.d.ts +65 -0
- package/lib/governance/control.js +89 -0
- package/lib/governance/cooperation.d.ts +163 -0
- package/lib/governance/cooperation.js +350 -0
- package/lib/governance/credential.d.ts +117 -0
- package/lib/governance/credential.js +229 -0
- package/lib/governance/httpServer.d.ts +18 -0
- package/lib/governance/httpServer.js +74 -0
- package/lib/governance/index.d.ts +32 -0
- package/lib/governance/index.js +32 -0
- package/lib/governance/legal.d.ts +222 -0
- package/lib/governance/legal.js +371 -0
- package/lib/governance/matrix.d.ts +170 -0
- package/lib/governance/matrix.js +365 -0
- package/lib/governance/perspectives.d.ts +98 -0
- package/lib/governance/perspectives.js +340 -0
- package/lib/governance/signing.d.ts +131 -0
- package/lib/governance/signing.js +241 -0
- package/lib/governance/store.d.ts +33 -0
- package/lib/governance/store.js +89 -0
- package/lib/governance/switching.d.ts +183 -0
- package/lib/governance/switching.js +257 -0
- package/lib/governance/toolPolicy.d.ts +37 -0
- package/lib/governance/toolPolicy.js +42 -0
- package/lib/governance/transport.d.ts +76 -0
- package/lib/governance/transport.js +124 -0
- package/lib/governance/types.d.ts +218 -0
- package/lib/governance/types.js +72 -0
- package/lib/governance/workflow.d.ts +174 -0
- package/lib/governance/workflow.js +612 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +1 -0
- package/lib/interaction/interaction.d.ts +83 -0
- package/lib/interaction/interaction.js +256 -0
- package/lib/ipc/index.d.ts +4 -0
- package/lib/ipc/index.js +3 -0
- package/lib/ipc/mailbox.d.ts +37 -0
- package/lib/ipc/mailbox.js +77 -0
- package/lib/ipc/memorySocialStore.d.ts +14 -0
- package/lib/ipc/memorySocialStore.js +83 -0
- package/lib/ipc/social.d.ts +80 -0
- package/lib/ipc/social.js +1 -0
- package/lib/kernel/index.d.ts +2 -0
- package/lib/kernel/index.js +1 -0
- package/lib/kernel/scheduler.d.ts +195 -0
- package/lib/kernel/scheduler.js +334 -0
- package/lib/ledger/checkpoint.d.ts +116 -0
- package/lib/ledger/checkpoint.js +223 -0
- package/lib/ledger/index.d.ts +4 -0
- package/lib/ledger/index.js +4 -0
- package/lib/ledger/ledger.d.ts +21 -0
- package/lib/ledger/ledger.js +23 -0
- package/lib/ledger/persistence.d.ts +46 -0
- package/lib/ledger/persistence.js +106 -0
- package/lib/ledger/share.d.ts +29 -0
- package/lib/ledger/share.js +39 -0
- package/lib/lock/index.d.ts +2 -0
- package/lib/lock/index.js +1 -0
- package/lib/lock/lease.d.ts +23 -0
- package/lib/lock/lease.js +42 -0
- package/lib/manifest/agentCard.d.ts +35 -0
- package/lib/manifest/agentCard.js +38 -0
- package/lib/manifest/cardSign.d.ts +25 -0
- package/lib/manifest/cardSign.js +70 -0
- package/lib/manifest/federation.d.ts +64 -0
- package/lib/manifest/federation.js +187 -0
- package/lib/manifest/federationTypes.d.ts +51 -0
- package/lib/manifest/federationTypes.js +1 -0
- package/lib/manifest/index.d.ts +8 -0
- package/lib/manifest/index.js +8 -0
- package/lib/manifest/keys.d.ts +221 -0
- package/lib/manifest/keys.js +484 -0
- package/lib/manifest/manifest.d.ts +102 -0
- package/lib/manifest/manifest.js +1 -0
- package/lib/manifest/sign.d.ts +38 -0
- package/lib/manifest/sign.js +90 -0
- package/lib/manifest/trust.d.ts +54 -0
- package/lib/manifest/trust.js +87 -0
- package/lib/mission/index.d.ts +2 -0
- package/lib/mission/index.js +1 -0
- package/lib/mission/missionQueue.d.ts +19 -0
- package/lib/mission/missionQueue.js +62 -0
- package/lib/module/index.d.ts +9 -0
- package/lib/module/index.js +9 -0
- package/lib/module/llm/deepseek.d.ts +43 -0
- package/lib/module/llm/deepseek.js +162 -0
- package/lib/module/llm/llm.d.ts +64 -0
- package/lib/module/llm/llm.js +16 -0
- package/lib/module/mcp/client.d.ts +32 -0
- package/lib/module/mcp/client.js +84 -0
- package/lib/module/mcp/http.d.ts +32 -0
- package/lib/module/mcp/http.js +83 -0
- package/lib/module/mcp/protocol.d.ts +62 -0
- package/lib/module/mcp/protocol.js +20 -0
- package/lib/module/mcp/server.d.ts +22 -0
- package/lib/module/mcp/server.js +138 -0
- package/lib/module/mcp/transport.d.ts +19 -0
- package/lib/module/mcp/transport.js +16 -0
- package/lib/module/mcp/workspaceServer.d.ts +20 -0
- package/lib/module/mcp/workspaceServer.js +90 -0
- package/lib/module/sandbox/sandbox.d.ts +24 -0
- package/lib/module/sandbox/sandbox.js +5 -0
- package/lib/module/tool/mcpExecutor.d.ts +18 -0
- package/lib/module/tool/mcpExecutor.js +41 -0
- package/lib/module/tool/policy.d.ts +30 -0
- package/lib/module/tool/policy.js +23 -0
- package/lib/module/tool/redact.d.ts +9 -0
- package/lib/module/tool/redact.js +19 -0
- package/lib/module/tool/tool.d.ts +26 -0
- package/lib/module/tool/tool.js +24 -0
- package/lib/module/tool/workspaceExecutor.d.ts +12 -0
- package/lib/module/tool/workspaceExecutor.js +25 -0
- package/lib/policy/guard.d.ts +115 -0
- package/lib/policy/guard.js +154 -0
- package/lib/policy/index.d.ts +2 -0
- package/lib/policy/index.js +2 -0
- package/lib/policy/policy.d.ts +249 -0
- package/lib/policy/policy.js +364 -0
- package/lib/process/agent.d.ts +295 -0
- package/lib/process/agent.js +1 -0
- package/lib/process/agentService.d.ts +87 -0
- package/lib/process/agentService.js +128 -0
- package/lib/process/agentStore.d.ts +35 -0
- package/lib/process/agentStore.js +328 -0
- package/lib/process/executionStore.d.ts +79 -0
- package/lib/process/executionStore.js +71 -0
- package/lib/process/index.d.ts +5 -0
- package/lib/process/index.js +5 -0
- package/lib/process/process.d.ts +120 -0
- package/lib/process/process.js +111 -0
- package/lib/process/transitions.d.ts +11 -0
- package/lib/process/transitions.js +8 -0
- package/lib/progress/index.d.ts +2 -0
- package/lib/progress/index.js +1 -0
- package/lib/progress/progress.d.ts +26 -0
- package/lib/progress/progress.js +42 -0
- package/lib/protocol/a2a.d.ts +51 -0
- package/lib/protocol/a2a.js +79 -0
- package/lib/protocol/channel.d.ts +25 -0
- package/lib/protocol/channel.js +27 -0
- package/lib/protocol/envelope.d.ts +180 -0
- package/lib/protocol/envelope.js +495 -0
- package/lib/protocol/httpChannel.d.ts +33 -0
- package/lib/protocol/httpChannel.js +59 -0
- package/lib/protocol/index.d.ts +6 -0
- package/lib/protocol/index.js +6 -0
- package/lib/protocol/protocol.d.ts +120 -0
- package/lib/protocol/protocol.js +1 -0
- package/lib/protocol/wire.d.ts +12 -0
- package/lib/protocol/wire.js +55 -0
- package/lib/receipt/index.d.ts +1 -0
- package/lib/receipt/index.js +1 -0
- package/lib/receipt/receipt.d.ts +43 -0
- package/lib/receipt/receipt.js +1 -0
- package/lib/registry/content.d.ts +10 -0
- package/lib/registry/content.js +58 -0
- package/lib/registry/index.d.ts +4 -0
- package/lib/registry/index.js +2 -0
- package/lib/registry/registry.d.ts +109 -0
- package/lib/registry/registry.js +299 -0
- package/lib/runtime/action.d.ts +46 -0
- package/lib/runtime/action.js +39 -0
- package/lib/runtime/behavior.d.ts +110 -0
- package/lib/runtime/behavior.js +179 -0
- package/lib/runtime/behaviorTuning.d.ts +59 -0
- package/lib/runtime/behaviorTuning.js +95 -0
- package/lib/runtime/cognitiveRuntime.d.ts +189 -0
- package/lib/runtime/cognitiveRuntime.js +490 -0
- package/lib/runtime/escalation.d.ts +22 -0
- package/lib/runtime/escalation.js +15 -0
- package/lib/runtime/governedTask.d.ts +57 -0
- package/lib/runtime/governedTask.js +150 -0
- package/lib/runtime/index.d.ts +15 -0
- package/lib/runtime/index.js +15 -0
- package/lib/runtime/kernelRuntime.d.ts +33 -0
- package/lib/runtime/kernelRuntime.js +105 -0
- package/lib/runtime/operation.d.ts +30 -0
- package/lib/runtime/operation.js +1 -0
- package/lib/runtime/replay.d.ts +24 -0
- package/lib/runtime/replay.js +38 -0
- package/lib/runtime/routing.d.ts +12 -0
- package/lib/runtime/routing.js +44 -0
- package/lib/runtime/safety.d.ts +15 -0
- package/lib/runtime/safety.js +28 -0
- package/lib/runtime/session.d.ts +147 -0
- package/lib/runtime/session.js +214 -0
- package/lib/runtime/sessionStore.d.ts +24 -0
- package/lib/runtime/sessionStore.js +20 -0
- package/lib/runtime/telemetry.d.ts +24 -0
- package/lib/runtime/telemetry.js +33 -0
- package/lib/runtime/turnStore.d.ts +16 -0
- package/lib/runtime/turnStore.js +15 -0
- package/lib/scenario/index.d.ts +1 -0
- package/lib/scenario/index.js +1 -0
- package/lib/scenario/scenario.d.ts +52 -0
- package/lib/scenario/scenario.js +210 -0
- package/lib/semantic/canonical.d.ts +6 -0
- package/lib/semantic/canonical.js +22 -0
- package/lib/semantic/index.d.ts +2 -0
- package/lib/semantic/index.js +2 -0
- package/lib/semantic/sha256.d.ts +1 -0
- package/lib/semantic/sha256.js +66 -0
- package/lib/storage/appendLog.d.ts +145 -0
- package/lib/storage/appendLog.js +299 -0
- package/lib/storage/fileAppendSink.d.ts +7 -0
- package/lib/storage/fileAppendSink.js +34 -0
- package/lib/storage/index.d.ts +2 -0
- package/lib/storage/index.js +2 -0
- package/lib/store/bindCache.d.ts +9 -0
- package/lib/store/bindCache.js +18 -0
- package/lib/store/cache.d.ts +48 -0
- package/lib/store/cache.js +162 -0
- package/lib/store/context.d.ts +10 -0
- package/lib/store/context.js +27 -0
- package/lib/store/handleStore.d.ts +9 -0
- package/lib/store/handleStore.js +25 -0
- package/lib/store/index.d.ts +9 -0
- package/lib/store/index.js +8 -0
- package/lib/store/messageStore.d.ts +9 -0
- package/lib/store/messageStore.js +25 -0
- package/lib/store/objectStore.d.ts +9 -0
- package/lib/store/objectStore.js +25 -0
- package/lib/store/processStore.d.ts +9 -0
- package/lib/store/processStore.js +25 -0
- package/lib/store/threadStore.d.ts +9 -0
- package/lib/store/threadStore.js +25 -0
- package/lib/store/windowStore.d.ts +9 -0
- package/lib/store/windowStore.js +25 -0
- package/lib/structure/abstractSyntaxTree.d.ts +181 -0
- package/lib/structure/abstractSyntaxTree.js +400 -0
- package/lib/structure/avlTree.d.ts +125 -0
- package/lib/structure/avlTree.js +369 -0
- package/lib/structure/binarySearchTree.d.ts +125 -0
- package/lib/structure/binarySearchTree.js +306 -0
- package/lib/structure/binaryTree.d.ts +174 -0
- package/lib/structure/binaryTree.js +495 -0
- package/lib/structure/bloomFilter.d.ts +126 -0
- package/lib/structure/bloomFilter.js +177 -0
- package/lib/structure/compare.d.ts +55 -0
- package/lib/structure/compare.js +96 -0
- package/lib/structure/cuckooFilter.d.ts +149 -0
- package/lib/structure/cuckooFilter.js +267 -0
- package/lib/structure/deque.d.ts +117 -0
- package/lib/structure/deque.js +205 -0
- package/lib/structure/filterKey.d.ts +19 -0
- package/lib/structure/filterKey.js +28 -0
- package/lib/structure/hash.d.ts +129 -0
- package/lib/structure/hash.js +241 -0
- package/lib/structure/heap.d.ts +152 -0
- package/lib/structure/heap.js +227 -0
- package/lib/structure/index.d.ts +20 -0
- package/lib/structure/index.js +20 -0
- package/lib/structure/iterator.d.ts +6 -0
- package/lib/structure/iterator.js +16 -0
- package/lib/structure/lru.d.ts +235 -0
- package/lib/structure/lru.js +524 -0
- package/lib/structure/ordered.d.ts +89 -0
- package/lib/structure/ordered.js +336 -0
- package/lib/structure/priority.d.ts +499 -0
- package/lib/structure/priority.js +756 -0
- package/lib/structure/queue.d.ts +90 -0
- package/lib/structure/queue.js +154 -0
- package/lib/structure/redBlackTree.d.ts +142 -0
- package/lib/structure/redBlackTree.js +644 -0
- package/lib/structure/segmentTree.d.ts +129 -0
- package/lib/structure/segmentTree.js +205 -0
- package/lib/structure/stack.d.ts +77 -0
- package/lib/structure/stack.js +107 -0
- package/lib/structure/unordered.d.ts +99 -0
- package/lib/structure/unordered.js +341 -0
- package/lib/thread/index.d.ts +2 -0
- package/lib/thread/index.js +2 -0
- package/lib/thread/thread.d.ts +107 -0
- package/lib/thread/thread.js +81 -0
- package/lib/thread/transitions.d.ts +8 -0
- package/lib/thread/transitions.js +9 -0
- package/lib/types/common.d.ts +80 -0
- package/lib/types/common.js +5 -0
- package/lib/types/index.d.ts +23 -0
- package/lib/types/index.js +1 -0
- package/lib/warrant/epistemic.d.ts +141 -0
- package/lib/warrant/epistemic.js +1 -0
- package/lib/warrant/index.d.ts +3 -0
- package/lib/warrant/index.js +3 -0
- package/lib/warrant/inquiry.d.ts +69 -0
- package/lib/warrant/inquiry.js +119 -0
- package/lib/warrant/warrant.d.ts +46 -0
- package/lib/warrant/warrant.js +153 -0
- package/lib/window/compaction.d.ts +57 -0
- package/lib/window/compaction.js +334 -0
- package/lib/window/compactionTypes.d.ts +113 -0
- package/lib/window/compactionTypes.js +1 -0
- package/lib/window/index.d.ts +7 -0
- package/lib/window/index.js +3 -0
- package/lib/window/page.d.ts +16 -0
- package/lib/window/page.js +2 -0
- package/lib/window/window.d.ts +68 -0
- package/lib/window/window.js +194 -0
- package/package.json +22 -1
- package/src/authz/index.ts +1 -0
- package/src/concept/index.ts +3 -0
- package/src/concurrency/index.ts +5 -0
- package/src/cooperation/index.ts +6 -0
- package/src/delegate/index.ts +2 -0
- package/src/error/index.ts +7 -0
- package/src/evaluation/index.ts +2 -0
- package/src/execution/index.ts +3 -0
- package/src/frame/index.ts +1 -0
- package/src/index.ts +11 -0
- package/src/ledger/index.ts +4 -0
- package/src/manifest/index.ts +8 -0
- package/src/policy/index.ts +2 -0
- package/src/protocol/index.ts +6 -0
- package/src/receipt/index.ts +1 -0
- package/src/semantic/index.ts +2 -0
- package/src/storage/index.ts +2 -0
- package/src/structure/index.ts +20 -0
- package/src/thread/index.ts +2 -0
- package/src/warrant/index.ts +3 -0
- package/src/window/index.ts +7 -4
- package/tools/rewrite-declaration-extensions.ts +98 -0
- package/tsconfig.build.json +14 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unordered binary tree.
|
|
3
|
+
*
|
|
4
|
+
* The tree is shape-oriented rather than search-oriented: values have no
|
|
5
|
+
* ordering, `insert` fills the first missing child in level order, and the
|
|
6
|
+
* four traversal orders are available for inspection. Node objects are
|
|
7
|
+
* deliberately exposed through {@link BinaryTree.root}; a tree assembled by
|
|
8
|
+
* hand should be passed to the constructor so its `size` is computed from the
|
|
9
|
+
* existing nodes.
|
|
10
|
+
*
|
|
11
|
+
* `size` is maintained by {@link BinaryTree.insert} and
|
|
12
|
+
* {@link BinaryTree.clear}. Mutating the exposed nodes directly is not tracked
|
|
13
|
+
* by `size`; construct a new tree after manual restructuring.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* A binary-tree node. Missing children are represented by `null`.
|
|
17
|
+
*/
|
|
18
|
+
export class BinaryTreeNode {
|
|
19
|
+
/**
|
|
20
|
+
* Stored value.
|
|
21
|
+
*/
|
|
22
|
+
value;
|
|
23
|
+
/**
|
|
24
|
+
* Left child, or `null` when absent.
|
|
25
|
+
*/
|
|
26
|
+
left;
|
|
27
|
+
/**
|
|
28
|
+
* Right child, or `null` when absent.
|
|
29
|
+
*/
|
|
30
|
+
right;
|
|
31
|
+
/**
|
|
32
|
+
* Create a node.
|
|
33
|
+
*
|
|
34
|
+
* @param value - Stored value.
|
|
35
|
+
* @param left - Left child; defaults to `null`.
|
|
36
|
+
* @param right - Right child; defaults to `null`.
|
|
37
|
+
*/
|
|
38
|
+
constructor(value, left = null, right = null) {
|
|
39
|
+
this.value = value;
|
|
40
|
+
this.left = left;
|
|
41
|
+
this.right = right;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A binary tree with level-order construction, insertion and traversal.
|
|
46
|
+
*
|
|
47
|
+
* An empty tree has `size` 0 and `height` 0; a single node has height 1. A tree
|
|
48
|
+
* built from an existing root computes its size once in the constructor. All
|
|
49
|
+
* traversals are iterative, so unusually deep manual trees do not consume the
|
|
50
|
+
* call stack.
|
|
51
|
+
*/
|
|
52
|
+
export class BinaryTree {
|
|
53
|
+
rootNode;
|
|
54
|
+
count;
|
|
55
|
+
/**
|
|
56
|
+
* Create a tree from an existing node graph.
|
|
57
|
+
*
|
|
58
|
+
* `size` is computed by walking the supplied graph. Passing `null` creates an
|
|
59
|
+
* empty tree.
|
|
60
|
+
*
|
|
61
|
+
* @param root - Root node, or `null` for an empty tree.
|
|
62
|
+
*/
|
|
63
|
+
constructor(root = null) {
|
|
64
|
+
this.rootNode = root;
|
|
65
|
+
this.count = BinaryTree.countNodes(root);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build a tree from a level-order array.
|
|
69
|
+
*
|
|
70
|
+
* Index 0 is the root; the children of index `i` are at `2i + 1` and
|
|
71
|
+
* `2i + 2`. `null` entries are holes. Trailing `null` entries are ignored, and
|
|
72
|
+
* entries below a hole are unreachable and therefore omitted.
|
|
73
|
+
*
|
|
74
|
+
* @param values - Level-order values, with `null` marking a missing node.
|
|
75
|
+
*/
|
|
76
|
+
static fromLevelOrder(values) {
|
|
77
|
+
let last = values.length - 1;
|
|
78
|
+
while (last >= 0 && values[last] === null) {
|
|
79
|
+
last -= 1;
|
|
80
|
+
}
|
|
81
|
+
if (last < 0) {
|
|
82
|
+
return new BinaryTree();
|
|
83
|
+
}
|
|
84
|
+
const nodes = [];
|
|
85
|
+
let root = null;
|
|
86
|
+
for (let index = 0; index <= last; index += 1) {
|
|
87
|
+
const value = values[index];
|
|
88
|
+
if (value === null) {
|
|
89
|
+
nodes.push(null);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (index === 0) {
|
|
93
|
+
const rootNode = new BinaryTreeNode(value);
|
|
94
|
+
root = rootNode;
|
|
95
|
+
nodes.push(rootNode);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const parent = nodes[(index - 1) >> 1];
|
|
99
|
+
if (parent === null || parent === (void 0)) {
|
|
100
|
+
nodes.push(null);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const node = new BinaryTreeNode(value);
|
|
104
|
+
if (index % 2 === 1) {
|
|
105
|
+
parent.left = node;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
parent.right = node;
|
|
109
|
+
}
|
|
110
|
+
nodes.push(node);
|
|
111
|
+
}
|
|
112
|
+
return new BinaryTree(root);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Build a complete tree from values in level order.
|
|
116
|
+
*
|
|
117
|
+
* Every position is filled, so the result is always complete. An empty
|
|
118
|
+
* iterable produces an empty tree.
|
|
119
|
+
*
|
|
120
|
+
* @param values - Values to place in level order.
|
|
121
|
+
*/
|
|
122
|
+
static fromArray(values) {
|
|
123
|
+
const items = Array.from(values);
|
|
124
|
+
if (items.length === 0) {
|
|
125
|
+
return new BinaryTree();
|
|
126
|
+
}
|
|
127
|
+
const nodes = [];
|
|
128
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
129
|
+
nodes.push(new BinaryTreeNode(items[index]));
|
|
130
|
+
}
|
|
131
|
+
for (let index = 0; index < nodes.length; index += 1) {
|
|
132
|
+
const leftIndex = 2 * index + 1;
|
|
133
|
+
const rightIndex = 2 * index + 2;
|
|
134
|
+
if (leftIndex < nodes.length) {
|
|
135
|
+
nodes[index].left = nodes[leftIndex];
|
|
136
|
+
}
|
|
137
|
+
if (rightIndex < nodes.length) {
|
|
138
|
+
nodes[index].right = nodes[rightIndex];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return new BinaryTree(nodes[0] ?? null);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Root node, or `null` for an empty tree.
|
|
145
|
+
*/
|
|
146
|
+
get root() {
|
|
147
|
+
return this.rootNode;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Number of reachable nodes.
|
|
151
|
+
*
|
|
152
|
+
* Maintained by {@link insert} and {@link clear}. A tree built with the
|
|
153
|
+
* constructor starts from a traversal count; direct edits to exposed nodes are
|
|
154
|
+
* not reflected here.
|
|
155
|
+
*/
|
|
156
|
+
get size() {
|
|
157
|
+
return this.count;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Number of nodes on the longest root-to-leaf path.
|
|
161
|
+
*
|
|
162
|
+
* Empty trees have height 0 and leaves have height 1. Computed on demand in
|
|
163
|
+
* O(n) time.
|
|
164
|
+
*/
|
|
165
|
+
get height() {
|
|
166
|
+
if (this.rootNode === null) {
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
let maximum = 0;
|
|
170
|
+
const stack = [{ node: this.rootNode, depth: 1 }];
|
|
171
|
+
while (stack.length > 0) {
|
|
172
|
+
const frame = stack.pop();
|
|
173
|
+
if (frame === (void 0)) {
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (frame.depth > maximum) {
|
|
177
|
+
maximum = frame.depth;
|
|
178
|
+
}
|
|
179
|
+
if (frame.node.left !== null) {
|
|
180
|
+
stack.push({ node: frame.node.left, depth: frame.depth + 1 });
|
|
181
|
+
}
|
|
182
|
+
if (frame.node.right !== null) {
|
|
183
|
+
stack.push({ node: frame.node.right, depth: frame.depth + 1 });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return maximum;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Whether the tree contains no nodes.
|
|
190
|
+
*/
|
|
191
|
+
get isEmpty() {
|
|
192
|
+
return this.count === 0;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Insert a value at the first missing child in level order.
|
|
196
|
+
*
|
|
197
|
+
* The tree therefore keeps its complete shape when it started complete; for a
|
|
198
|
+
* manually built tree the search is still breadth-first, so the shallowest
|
|
199
|
+
* available slot is filled first. `size` is incremented.
|
|
200
|
+
*
|
|
201
|
+
* @param value - Value to store.
|
|
202
|
+
* @returns The newly created node.
|
|
203
|
+
*/
|
|
204
|
+
insert(value) {
|
|
205
|
+
const node = new BinaryTreeNode(value);
|
|
206
|
+
if (this.rootNode === null) {
|
|
207
|
+
this.rootNode = node;
|
|
208
|
+
this.count = 1;
|
|
209
|
+
return node;
|
|
210
|
+
}
|
|
211
|
+
const queue = [this.rootNode];
|
|
212
|
+
let index = 0;
|
|
213
|
+
while (index < queue.length) {
|
|
214
|
+
const current = queue[index];
|
|
215
|
+
index += 1;
|
|
216
|
+
if (current.left === null) {
|
|
217
|
+
current.left = node;
|
|
218
|
+
this.count += 1;
|
|
219
|
+
return node;
|
|
220
|
+
}
|
|
221
|
+
queue.push(current.left);
|
|
222
|
+
if (current.right === null) {
|
|
223
|
+
current.right = node;
|
|
224
|
+
this.count += 1;
|
|
225
|
+
return node;
|
|
226
|
+
}
|
|
227
|
+
queue.push(current.right);
|
|
228
|
+
}
|
|
229
|
+
throw new Error("BinaryTree: no insertion point found");
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Remove every node and reset `size` to 0.
|
|
233
|
+
*/
|
|
234
|
+
clear() {
|
|
235
|
+
this.rootNode = null;
|
|
236
|
+
this.count = 0;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Iterate values in the requested order.
|
|
240
|
+
*
|
|
241
|
+
* `null` holes are skipped. The tree is traversed iteratively, so the caller
|
|
242
|
+
* does not consume call-stack depth. Mutating the tree while iterating is not
|
|
243
|
+
* supported.
|
|
244
|
+
*
|
|
245
|
+
* @param order - Traversal order; defaults to `levelorder`.
|
|
246
|
+
*/
|
|
247
|
+
traverse(order = "levelorder") {
|
|
248
|
+
if (order === "preorder") {
|
|
249
|
+
return this.preorderValues();
|
|
250
|
+
}
|
|
251
|
+
if (order === "inorder") {
|
|
252
|
+
return this.inorderValues();
|
|
253
|
+
}
|
|
254
|
+
if (order === "postorder") {
|
|
255
|
+
return this.postorderValues();
|
|
256
|
+
}
|
|
257
|
+
return this.levelOrderValues();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Collect values in the requested traversal order.
|
|
261
|
+
*
|
|
262
|
+
* @param order - Traversal order; defaults to `levelorder`.
|
|
263
|
+
*/
|
|
264
|
+
toArray(order = "levelorder") {
|
|
265
|
+
return Array.from(this.traverse(order));
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Mirror the tree by swapping every left and right child.
|
|
269
|
+
*
|
|
270
|
+
* The shape is unchanged, so `size` and `height` stay the same. Returns the
|
|
271
|
+
* tree itself for chaining.
|
|
272
|
+
*/
|
|
273
|
+
invert() {
|
|
274
|
+
if (this.rootNode === null) {
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
const stack = [this.rootNode];
|
|
278
|
+
while (stack.length > 0) {
|
|
279
|
+
const node = stack.pop();
|
|
280
|
+
if (node === (void 0)) {
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
const left = node.left;
|
|
284
|
+
node.left = node.right;
|
|
285
|
+
node.right = left;
|
|
286
|
+
if (node.left !== null) {
|
|
287
|
+
stack.push(node.left);
|
|
288
|
+
}
|
|
289
|
+
if (node.right !== null) {
|
|
290
|
+
stack.push(node.right);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Whether all levels except possibly the last are full and the last level is
|
|
297
|
+
* filled from the left. An empty tree is complete.
|
|
298
|
+
*/
|
|
299
|
+
isComplete() {
|
|
300
|
+
if (this.rootNode === null) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
const queue = [this.rootNode];
|
|
304
|
+
let sawHole = false;
|
|
305
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
306
|
+
const node = queue[index];
|
|
307
|
+
if (node === null) {
|
|
308
|
+
sawHole = true;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (sawHole) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
queue.push(node.left);
|
|
315
|
+
queue.push(node.right);
|
|
316
|
+
}
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Whether every node has either zero or two children. An empty tree is full.
|
|
321
|
+
*/
|
|
322
|
+
isFull() {
|
|
323
|
+
if (this.rootNode === null) {
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
const stack = [this.rootNode];
|
|
327
|
+
while (stack.length > 0) {
|
|
328
|
+
const node = stack.pop();
|
|
329
|
+
if (node === (void 0)) {
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
const hasLeft = node.left !== null;
|
|
333
|
+
const hasRight = node.right !== null;
|
|
334
|
+
if (hasLeft !== hasRight) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
if (node.left !== null) {
|
|
338
|
+
stack.push(node.left);
|
|
339
|
+
}
|
|
340
|
+
if (node.right !== null) {
|
|
341
|
+
stack.push(node.right);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Deep-copy the tree.
|
|
348
|
+
*
|
|
349
|
+
* Every node is recreated, so the copy shares no nodes with the original.
|
|
350
|
+
* The copy's size is computed from the cloned shape.
|
|
351
|
+
*/
|
|
352
|
+
clone() {
|
|
353
|
+
const root = this.rootNode;
|
|
354
|
+
if (root === null) {
|
|
355
|
+
return new BinaryTree();
|
|
356
|
+
}
|
|
357
|
+
const copies = new Map();
|
|
358
|
+
const originals = [];
|
|
359
|
+
const stack = [root];
|
|
360
|
+
while (stack.length > 0) {
|
|
361
|
+
const node = stack.pop();
|
|
362
|
+
if (node === (void 0)) {
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
copies.set(node, new BinaryTreeNode(node.value));
|
|
366
|
+
originals.push(node);
|
|
367
|
+
if (node.left !== null) {
|
|
368
|
+
stack.push(node.left);
|
|
369
|
+
}
|
|
370
|
+
if (node.right !== null) {
|
|
371
|
+
stack.push(node.right);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (const original of originals) {
|
|
375
|
+
const copy = copies.get(original);
|
|
376
|
+
if (copy === (void 0)) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (original.left !== null) {
|
|
380
|
+
copy.left = copies.get(original.left) ?? null;
|
|
381
|
+
}
|
|
382
|
+
if (original.right !== null) {
|
|
383
|
+
copy.right = copies.get(original.right) ?? null;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return new BinaryTree(copies.get(root) ?? null);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Iterate values in preorder (node, left, right).
|
|
390
|
+
*
|
|
391
|
+
* Equivalent to `traverse('preorder')`.
|
|
392
|
+
*/
|
|
393
|
+
[Symbol.iterator]() {
|
|
394
|
+
return this.preorderValues();
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Count reachable nodes without recursion.
|
|
398
|
+
*/
|
|
399
|
+
static countNodes(root) {
|
|
400
|
+
if (root === null) {
|
|
401
|
+
return 0;
|
|
402
|
+
}
|
|
403
|
+
let count = 0;
|
|
404
|
+
const stack = [root];
|
|
405
|
+
while (stack.length > 0) {
|
|
406
|
+
const node = stack.pop();
|
|
407
|
+
if (node === (void 0)) {
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
count += 1;
|
|
411
|
+
if (node.left !== null) {
|
|
412
|
+
stack.push(node.left);
|
|
413
|
+
}
|
|
414
|
+
if (node.right !== null) {
|
|
415
|
+
stack.push(node.right);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return count;
|
|
419
|
+
}
|
|
420
|
+
*preorderValues() {
|
|
421
|
+
if (this.rootNode === null) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const stack = [this.rootNode];
|
|
425
|
+
while (stack.length > 0) {
|
|
426
|
+
const node = stack.pop();
|
|
427
|
+
if (node === (void 0)) {
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
yield node.value;
|
|
431
|
+
if (node.right !== null) {
|
|
432
|
+
stack.push(node.right);
|
|
433
|
+
}
|
|
434
|
+
if (node.left !== null) {
|
|
435
|
+
stack.push(node.left);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
*inorderValues() {
|
|
440
|
+
const stack = [];
|
|
441
|
+
let node = this.rootNode;
|
|
442
|
+
while (node !== null || stack.length > 0) {
|
|
443
|
+
while (node !== null) {
|
|
444
|
+
stack.push(node);
|
|
445
|
+
node = node.left;
|
|
446
|
+
}
|
|
447
|
+
const current = stack.pop();
|
|
448
|
+
if (current === (void 0)) {
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
yield current.value;
|
|
452
|
+
node = current.right;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
*postorderValues() {
|
|
456
|
+
if (this.rootNode === null) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const stack = [{ node: this.rootNode, visited: false }];
|
|
460
|
+
while (stack.length > 0) {
|
|
461
|
+
const frame = stack.pop();
|
|
462
|
+
if (frame === (void 0)) {
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
if (!frame.visited) {
|
|
466
|
+
stack.push({ node: frame.node, visited: true });
|
|
467
|
+
if (frame.node.right !== null) {
|
|
468
|
+
stack.push({ node: frame.node.right, visited: false });
|
|
469
|
+
}
|
|
470
|
+
if (frame.node.left !== null) {
|
|
471
|
+
stack.push({ node: frame.node.left, visited: false });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
yield frame.node.value;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
*levelOrderValues() {
|
|
480
|
+
if (this.rootNode === null) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const queue = [this.rootNode];
|
|
484
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
485
|
+
const node = queue[index];
|
|
486
|
+
yield node.value;
|
|
487
|
+
if (node.left !== null) {
|
|
488
|
+
queue.push(node.left);
|
|
489
|
+
}
|
|
490
|
+
if (node.right !== null) {
|
|
491
|
+
queue.push(node.right);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { FilterKey } from "./filterKey.js";
|
|
2
|
+
/**
|
|
3
|
+
* A classic Bloom filter.
|
|
4
|
+
*
|
|
5
|
+
* The filter stores a bit array and uses `k` double-hashed bit positions per
|
|
6
|
+
* key. It has no false negatives: if `add(key)` completed, `has(key)` remains
|
|
7
|
+
* true. False positives are possible and are bounded by the configured rate.
|
|
8
|
+
* Standard Bloom filters cannot delete individual keys; rebuild the filter or
|
|
9
|
+
* use {@link CuckooFilter} when deletion is required.
|
|
10
|
+
*
|
|
11
|
+
* The default hash count and bit count are derived from `expectedItems` and
|
|
12
|
+
* `falsePositiveRate` using the usual `m = -n ln p / (ln 2)^2` and
|
|
13
|
+
* `k = (m/n) ln 2` formulas. Values for unsupported sizes fail before any
|
|
14
|
+
* allocation.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Construction options for {@link BloomFilter}.
|
|
18
|
+
*/
|
|
19
|
+
export interface BloomFilterOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Expected number of distinct keys; a positive safe integer.
|
|
22
|
+
*/
|
|
23
|
+
expectedItems: number;
|
|
24
|
+
/**
|
|
25
|
+
* Target false-positive rate in `(0, 1)`. Defaults to `0.01`.
|
|
26
|
+
*/
|
|
27
|
+
falsePositiveRate?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Domain seed for both hash families. Defaults to `0n`.
|
|
30
|
+
*/
|
|
31
|
+
seed?: bigint;
|
|
32
|
+
/**
|
|
33
|
+
* Hard cap on bit-array size; defaults to 2^31 bits (256 MiB).
|
|
34
|
+
*/
|
|
35
|
+
maxBits?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A Bloom filter over string or `Uint8Array` keys.
|
|
39
|
+
*
|
|
40
|
+
* `size` counts calls to {@link add}, not distinct keys: a Bloom filter cannot
|
|
41
|
+
* know whether a key was already present. `setBits` and `fillRatio` expose the
|
|
42
|
+
* actual bit occupancy, which is the useful signal for saturation.
|
|
43
|
+
*/
|
|
44
|
+
export declare class BloomFilter {
|
|
45
|
+
/**
|
|
46
|
+
* Requested expected key count.
|
|
47
|
+
*/
|
|
48
|
+
readonly expectedItems: number;
|
|
49
|
+
/**
|
|
50
|
+
* Requested target false-positive rate.
|
|
51
|
+
*/
|
|
52
|
+
readonly falsePositiveRate: number;
|
|
53
|
+
/**
|
|
54
|
+
* Number of bits in the filter.
|
|
55
|
+
*/
|
|
56
|
+
readonly bitSize: number;
|
|
57
|
+
/**
|
|
58
|
+
* Number of double-hashed probes per key.
|
|
59
|
+
*/
|
|
60
|
+
readonly hashCount: number;
|
|
61
|
+
/**
|
|
62
|
+
* Number of bytes allocated for the bit array.
|
|
63
|
+
*/
|
|
64
|
+
readonly byteSize: number;
|
|
65
|
+
private readonly bits;
|
|
66
|
+
private readonly seed;
|
|
67
|
+
private insertions;
|
|
68
|
+
private bitsSet;
|
|
69
|
+
/**
|
|
70
|
+
* Build a filter sized for `expectedItems` at `falsePositiveRate`.
|
|
71
|
+
*
|
|
72
|
+
* @throws RangeError for non-positive/non-integer item counts, rates outside
|
|
73
|
+
* `(0, 1)`, or a computed bit count above `maxBits`.
|
|
74
|
+
*/
|
|
75
|
+
constructor(options: BloomFilterOptions);
|
|
76
|
+
/**
|
|
77
|
+
* Insert a key.
|
|
78
|
+
*
|
|
79
|
+
* Duplicate insertion is harmless and increments {@link size}; the bit
|
|
80
|
+
* occupancy only changes for bits that were previously unset.
|
|
81
|
+
*
|
|
82
|
+
* @param key - String or byte key.
|
|
83
|
+
* @returns This filter, for chaining.
|
|
84
|
+
*/
|
|
85
|
+
add(key: FilterKey): this;
|
|
86
|
+
/**
|
|
87
|
+
* Test a key.
|
|
88
|
+
*
|
|
89
|
+
* `false` means the key was definitely not inserted (or the filter was
|
|
90
|
+
* cleared). `true` may be a false positive.
|
|
91
|
+
*/
|
|
92
|
+
has(key: FilterKey): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Remove every key and reset all counters.
|
|
95
|
+
*/
|
|
96
|
+
clear(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Number of `add` calls, including duplicates.
|
|
99
|
+
*/
|
|
100
|
+
get size(): number;
|
|
101
|
+
/**
|
|
102
|
+
* Number of bits currently set to one.
|
|
103
|
+
*/
|
|
104
|
+
get setBits(): number;
|
|
105
|
+
/**
|
|
106
|
+
* Fraction of bits set to one.
|
|
107
|
+
*/
|
|
108
|
+
get fillRatio(): number;
|
|
109
|
+
/**
|
|
110
|
+
* True when every bit is set and the filter is fully saturated.
|
|
111
|
+
*/
|
|
112
|
+
get isSaturated(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Estimated current false-positive probability from the number of inserted
|
|
115
|
+
* keys: `(1 - e^(-k*n/m))^k`.
|
|
116
|
+
*/
|
|
117
|
+
get estimatedFalsePositiveRate(): number;
|
|
118
|
+
/**
|
|
119
|
+
* Set one bit, updating the occupancy counter only on a 0 -> 1 change.
|
|
120
|
+
*/
|
|
121
|
+
private setBit;
|
|
122
|
+
/**
|
|
123
|
+
* Read one bit.
|
|
124
|
+
*/
|
|
125
|
+
private getBit;
|
|
126
|
+
}
|