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,267 @@
|
|
|
1
|
+
import { hashBytes } from "./hash.js";
|
|
2
|
+
import { assertFilterKey, filterKeyBytes } from "./filterKey.js";
|
|
3
|
+
const DEFAULT_BUCKET_SIZE = 4;
|
|
4
|
+
const DEFAULT_FINGERPRINT_BITS = 8;
|
|
5
|
+
const DEFAULT_MAX_KICKS = 500;
|
|
6
|
+
const FINGERPRINT_SEED = 0xd1b54a32d192ed03n;
|
|
7
|
+
const MIN_FINGERPRINT_BITS = 4;
|
|
8
|
+
const MAX_FINGERPRINT_BITS = 30;
|
|
9
|
+
/**
|
|
10
|
+
* A cuckoo filter over string or `Uint8Array` keys.
|
|
11
|
+
*
|
|
12
|
+
* `capacity` is the number of fingerprint slots, not the requested value: it is
|
|
13
|
+
* `bucketCount * bucketSize`, rounded up from the constructor's `capacity`.
|
|
14
|
+
* `loadFactor` is the fraction of those slots currently occupied.
|
|
15
|
+
*/
|
|
16
|
+
export class CuckooFilter {
|
|
17
|
+
/**
|
|
18
|
+
* Requested key capacity before bucket rounding.
|
|
19
|
+
*/
|
|
20
|
+
requestedCapacity;
|
|
21
|
+
/**
|
|
22
|
+
* Fingerprints per bucket.
|
|
23
|
+
*/
|
|
24
|
+
bucketSize;
|
|
25
|
+
/**
|
|
26
|
+
* Number of buckets (a power of two).
|
|
27
|
+
*/
|
|
28
|
+
bucketCount;
|
|
29
|
+
/**
|
|
30
|
+
* Total fingerprint slots: `bucketCount * bucketSize`.
|
|
31
|
+
*/
|
|
32
|
+
capacity;
|
|
33
|
+
/**
|
|
34
|
+
* Fingerprint width in bits.
|
|
35
|
+
*/
|
|
36
|
+
fingerprintBits;
|
|
37
|
+
/**
|
|
38
|
+
* Maximum number of displacements per insertion.
|
|
39
|
+
*/
|
|
40
|
+
maxKicks;
|
|
41
|
+
buckets;
|
|
42
|
+
seed;
|
|
43
|
+
indexMask;
|
|
44
|
+
fingerprintMask;
|
|
45
|
+
initialRng;
|
|
46
|
+
rngState;
|
|
47
|
+
count = 0;
|
|
48
|
+
/**
|
|
49
|
+
* Create an empty filter.
|
|
50
|
+
*
|
|
51
|
+
* @throws RangeError for non-positive capacity, an invalid bucket/fingerprint
|
|
52
|
+
* size, a negative kick limit, or a bucket array too large to index safely.
|
|
53
|
+
*/
|
|
54
|
+
constructor(options) {
|
|
55
|
+
if (options === null || typeof (options) !== "object") {
|
|
56
|
+
throw new TypeError("options must be an object");
|
|
57
|
+
}
|
|
58
|
+
if (!Number.isSafeInteger(options.capacity) || options.capacity <= 0) {
|
|
59
|
+
throw new RangeError("capacity must be a positive safe integer");
|
|
60
|
+
}
|
|
61
|
+
const bucketSize = options.bucketSize ?? DEFAULT_BUCKET_SIZE;
|
|
62
|
+
if (!Number.isSafeInteger(bucketSize) || bucketSize <= 0 || bucketSize > 32) {
|
|
63
|
+
throw new RangeError("bucketSize must be an integer in [1, 32]");
|
|
64
|
+
}
|
|
65
|
+
const fingerprintBits = options.fingerprintBits ?? DEFAULT_FINGERPRINT_BITS;
|
|
66
|
+
if (!Number.isSafeInteger(fingerprintBits) || fingerprintBits < MIN_FINGERPRINT_BITS || fingerprintBits > MAX_FINGERPRINT_BITS) {
|
|
67
|
+
throw new RangeError(`fingerprintBits must be an integer in [${MIN_FINGERPRINT_BITS}, ${MAX_FINGERPRINT_BITS}]`);
|
|
68
|
+
}
|
|
69
|
+
const maxKicks = options.maxKicks ?? DEFAULT_MAX_KICKS;
|
|
70
|
+
if (!Number.isSafeInteger(maxKicks) || maxKicks < 0) {
|
|
71
|
+
throw new RangeError("maxKicks must be a non-negative safe integer");
|
|
72
|
+
}
|
|
73
|
+
let bucketCount = 1;
|
|
74
|
+
while (bucketCount * bucketSize < options.capacity) {
|
|
75
|
+
bucketCount *= 2;
|
|
76
|
+
if (bucketCount > 2 ** 30) {
|
|
77
|
+
throw new RangeError("capacity is too large for a cuckoo filter");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this.requestedCapacity = options.capacity;
|
|
81
|
+
this.bucketSize = bucketSize;
|
|
82
|
+
this.bucketCount = bucketCount;
|
|
83
|
+
this.capacity = bucketCount * bucketSize;
|
|
84
|
+
this.fingerprintBits = fingerprintBits;
|
|
85
|
+
this.maxKicks = maxKicks;
|
|
86
|
+
this.seed = options.seed ?? 0n;
|
|
87
|
+
this.indexMask = bucketCount - 1;
|
|
88
|
+
this.fingerprintMask = (1n << BigInt(fingerprintBits)) - 1n;
|
|
89
|
+
this.buckets = Array.from({ length: bucketCount }, () => []);
|
|
90
|
+
const seeded = Number((options.seed ?? 0n) & 0xffffffffn);
|
|
91
|
+
this.initialRng = seeded === 0 ? 0x9e37_79b9 : seeded;
|
|
92
|
+
this.rngState = this.initialRng;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Insert a key.
|
|
96
|
+
*
|
|
97
|
+
* @returns `true` if the fingerprint was stored, `false` if the kick chain
|
|
98
|
+
* was exhausted. A failed insertion is rolled back and leaves the filter
|
|
99
|
+
* unchanged.
|
|
100
|
+
*/
|
|
101
|
+
add(key) {
|
|
102
|
+
assertFilterKey(key);
|
|
103
|
+
const { index, fingerprint } = this.locate(key);
|
|
104
|
+
const first = index;
|
|
105
|
+
const second = this.alternate(first, fingerprint);
|
|
106
|
+
let currentFingerprint = fingerprint;
|
|
107
|
+
let currentIndex = this.pickBucket(first, second);
|
|
108
|
+
const history = [];
|
|
109
|
+
for (let kick = 0; kick <= this.maxKicks; kick += 1) {
|
|
110
|
+
const bucket = this.buckets[currentIndex];
|
|
111
|
+
if (bucket.length < this.bucketSize) {
|
|
112
|
+
bucket.push(currentFingerprint);
|
|
113
|
+
this.count += 1;
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (kick === this.maxKicks) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
const slot = this.randomInt(bucket.length);
|
|
120
|
+
const displaced = bucket[slot] ?? 0;
|
|
121
|
+
history.push({ bucket: currentIndex, slot, displaced });
|
|
122
|
+
bucket[slot] = currentFingerprint;
|
|
123
|
+
currentFingerprint = displaced;
|
|
124
|
+
currentIndex = this.alternate(currentIndex, currentFingerprint);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Undo every displacement. The last displaced fingerprint was never
|
|
128
|
+
* stored, and every earlier one is restored to the slot it came from.
|
|
129
|
+
*/
|
|
130
|
+
for (let index_ = history.length - 1; index_ >= 0; index_ -= 1) {
|
|
131
|
+
const record = history[index_];
|
|
132
|
+
if (record === (void 0)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
this.buckets[record.bucket][record.slot] = record.displaced;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Test whether a key may be present.
|
|
141
|
+
*/
|
|
142
|
+
has(key) {
|
|
143
|
+
assertFilterKey(key);
|
|
144
|
+
const { index, fingerprint } = this.locate(key);
|
|
145
|
+
if (this.buckets[index].includes(fingerprint)) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
const alternate = this.alternate(index, fingerprint);
|
|
149
|
+
return alternate !== index && this.buckets[alternate].includes(fingerprint);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Remove one occurrence of a key.
|
|
153
|
+
*
|
|
154
|
+
* @returns `true` if a matching fingerprint was removed, `false` otherwise.
|
|
155
|
+
* A `false` result is exact only for a key that was never inserted; a
|
|
156
|
+
* different key can share the same fingerprint, so deletion is best-effort
|
|
157
|
+
* with respect to collisions.
|
|
158
|
+
*/
|
|
159
|
+
delete(key) {
|
|
160
|
+
assertFilterKey(key);
|
|
161
|
+
const { index, fingerprint } = this.locate(key);
|
|
162
|
+
const first = this.removeFingerprint(index, fingerprint);
|
|
163
|
+
if (first) {
|
|
164
|
+
this.count -= 1;
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
const alternate = this.alternate(index, fingerprint);
|
|
168
|
+
if (alternate !== index && this.removeFingerprint(alternate, fingerprint)) {
|
|
169
|
+
this.count -= 1;
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Remove every key and reset the random kick state.
|
|
176
|
+
*/
|
|
177
|
+
clear() {
|
|
178
|
+
for (const bucket of this.buckets) {
|
|
179
|
+
bucket.length = 0;
|
|
180
|
+
}
|
|
181
|
+
this.count = 0;
|
|
182
|
+
this.rngState = this.initialRng;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Number of stored fingerprints.
|
|
186
|
+
*/
|
|
187
|
+
get size() {
|
|
188
|
+
return this.count;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Fraction of fingerprint slots occupied.
|
|
192
|
+
*/
|
|
193
|
+
get loadFactor() {
|
|
194
|
+
return this.count / this.capacity;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* True when every fingerprint slot is occupied.
|
|
198
|
+
*/
|
|
199
|
+
get isFull() {
|
|
200
|
+
return this.count === this.capacity;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Approximate false-positive probability for a non-full filter:
|
|
204
|
+
* `2 * bucketSize / 2^fingerprintBits`.
|
|
205
|
+
*/
|
|
206
|
+
get falsePositiveRate() {
|
|
207
|
+
return Math.min(1, (2 * this.bucketSize) / 2 ** this.fingerprintBits);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Hash a key once, yielding its first bucket and compact fingerprint.
|
|
211
|
+
*/
|
|
212
|
+
locate(key) {
|
|
213
|
+
const hash = hashBytes(filterKeyBytes(key), this.seed);
|
|
214
|
+
const index = Number(hash & BigInt(this.indexMask));
|
|
215
|
+
let fingerprint = Number((hash >> 32n) & this.fingerprintMask);
|
|
216
|
+
if (fingerprint === 0) {
|
|
217
|
+
fingerprint = 1;
|
|
218
|
+
}
|
|
219
|
+
return { index, fingerprint };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The other candidate bucket for a fingerprint in `index`.
|
|
223
|
+
*/
|
|
224
|
+
alternate(index, fingerprint) {
|
|
225
|
+
const bytes = Uint8Array.of(fingerprint & 0xff, (fingerprint >>> 8) & 0xff, (fingerprint >>> 16) & 0xff, (fingerprint >>> 24) & 0xff);
|
|
226
|
+
const hashed = Number(hashBytes(bytes, this.seed ^ FINGERPRINT_SEED) & BigInt(this.indexMask));
|
|
227
|
+
return (index ^ hashed) & this.indexMask;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Choose an initial bucket, preferring one with room.
|
|
231
|
+
*/
|
|
232
|
+
pickBucket(first, second) {
|
|
233
|
+
if (this.buckets[first].length < this.bucketSize) {
|
|
234
|
+
return first;
|
|
235
|
+
}
|
|
236
|
+
if (this.buckets[second].length < this.bucketSize) {
|
|
237
|
+
return second;
|
|
238
|
+
}
|
|
239
|
+
return this.randomInt(2) === 0 ? first : second;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Remove the first matching fingerprint from one bucket.
|
|
243
|
+
*/
|
|
244
|
+
removeFingerprint(index, fingerprint) {
|
|
245
|
+
const bucket = this.buckets[index];
|
|
246
|
+
const slot = bucket.indexOf(fingerprint);
|
|
247
|
+
if (slot < 0) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
const last = bucket.pop();
|
|
251
|
+
if (slot < bucket.length && last !== (void 0)) {
|
|
252
|
+
bucket[slot] = last;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Xorshift32 in [0, bound); deterministic for a given seed and insertion order.
|
|
258
|
+
*/
|
|
259
|
+
randomInt(bound) {
|
|
260
|
+
let value = this.rngState;
|
|
261
|
+
value ^= value << 13;
|
|
262
|
+
value ^= value >>> 17;
|
|
263
|
+
value ^= value << 5;
|
|
264
|
+
this.rngState = value >>> 0;
|
|
265
|
+
return this.rngState % bound;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array-backed double-ended queue.
|
|
3
|
+
*
|
|
4
|
+
* Values live in a circular buffer addressed by a head index and a count, so
|
|
5
|
+
* both the front and back of the logical sequence can be updated in O(1)
|
|
6
|
+
* amortized time without moving the other values. The buffer is not required
|
|
7
|
+
* to have a power-of-two length; it doubles when full and halves after a pop
|
|
8
|
+
* leaves it at most quarter full. Popped slots are cleared so the ring does not
|
|
9
|
+
* retain references to removed values.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A double-ended queue.
|
|
13
|
+
*
|
|
14
|
+
* Values can be added and removed at either end. `popFront`, `popBack`,
|
|
15
|
+
* `peekFront`, and `peekBack` return `undefined` when the deque is empty rather
|
|
16
|
+
* than throwing. Since `undefined` is also a valid stored value, use
|
|
17
|
+
* {@link size} or {@link isEmpty} when presence must be distinguished from
|
|
18
|
+
* absence.
|
|
19
|
+
*
|
|
20
|
+
* Iteration is front-to-back.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const deque = new Deque([2, 3]);
|
|
25
|
+
* deque.pushFront(1).pushBack(4);
|
|
26
|
+
* [...deque]; // [1, 2, 3, 4]
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class Deque<T> implements Iterable<T> {
|
|
30
|
+
private items;
|
|
31
|
+
private head;
|
|
32
|
+
private count;
|
|
33
|
+
/**
|
|
34
|
+
* Create a deque, optionally seeded from `values`.
|
|
35
|
+
*
|
|
36
|
+
* Values are pushed onto the back in iteration order, so the last value
|
|
37
|
+
* becomes the back.
|
|
38
|
+
*
|
|
39
|
+
* @param values - Values to insert, in order.
|
|
40
|
+
*/
|
|
41
|
+
constructor(values?: Iterable<T>);
|
|
42
|
+
/**
|
|
43
|
+
* Number of values currently in the deque.
|
|
44
|
+
*/
|
|
45
|
+
get size(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the deque contains no values.
|
|
48
|
+
*/
|
|
49
|
+
get isEmpty(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Add a value at the front of the deque.
|
|
52
|
+
*
|
|
53
|
+
* @param value - Value to insert.
|
|
54
|
+
* @returns This deque, for chaining.
|
|
55
|
+
*/
|
|
56
|
+
pushFront(value: T): this;
|
|
57
|
+
/**
|
|
58
|
+
* Add a value at the back of the deque.
|
|
59
|
+
*
|
|
60
|
+
* @param value - Value to insert.
|
|
61
|
+
* @returns This deque, for chaining.
|
|
62
|
+
*/
|
|
63
|
+
pushBack(value: T): this;
|
|
64
|
+
/**
|
|
65
|
+
* Alias of {@link pushBack}.
|
|
66
|
+
*
|
|
67
|
+
* @param value - Value to insert at the back.
|
|
68
|
+
* @returns This deque, for chaining.
|
|
69
|
+
*/
|
|
70
|
+
push(value: T): this;
|
|
71
|
+
/**
|
|
72
|
+
* Remove and return the value at the front of the deque.
|
|
73
|
+
*
|
|
74
|
+
* @returns The former front value, or `undefined` if the deque is empty.
|
|
75
|
+
*/
|
|
76
|
+
popFront(): T | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Remove and return the value at the back of the deque.
|
|
79
|
+
*
|
|
80
|
+
* @returns The former back value, or `undefined` if the deque is empty.
|
|
81
|
+
*/
|
|
82
|
+
popBack(): T | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Return the value at the front without removing it.
|
|
85
|
+
*
|
|
86
|
+
* @returns The front value, or `undefined` if the deque is empty.
|
|
87
|
+
*/
|
|
88
|
+
peekFront(): T | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Return the value at the back without removing it.
|
|
91
|
+
*
|
|
92
|
+
* @returns The back value, or `undefined` if the deque is empty.
|
|
93
|
+
*/
|
|
94
|
+
peekBack(): T | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Remove every value and reset the ring to its initial capacity.
|
|
97
|
+
*/
|
|
98
|
+
clear(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Snapshot the deque from front to back.
|
|
101
|
+
*
|
|
102
|
+
* @returns A new array whose first item is the front of the deque.
|
|
103
|
+
*/
|
|
104
|
+
toArray(): T[];
|
|
105
|
+
/**
|
|
106
|
+
* Iterate front to back over a snapshot taken when the iterator is created.
|
|
107
|
+
*/
|
|
108
|
+
[Symbol.iterator](): Generator<T, void, unknown>;
|
|
109
|
+
/**
|
|
110
|
+
* Copy the live values into a fresh ring, front to back.
|
|
111
|
+
*/
|
|
112
|
+
private resize;
|
|
113
|
+
/**
|
|
114
|
+
* Halve an oversized ring after a pop leaves it at most quarter full.
|
|
115
|
+
*/
|
|
116
|
+
private shrinkIfSparse;
|
|
117
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array-backed double-ended queue.
|
|
3
|
+
*
|
|
4
|
+
* Values live in a circular buffer addressed by a head index and a count, so
|
|
5
|
+
* both the front and back of the logical sequence can be updated in O(1)
|
|
6
|
+
* amortized time without moving the other values. The buffer is not required
|
|
7
|
+
* to have a power-of-two length; it doubles when full and halves after a pop
|
|
8
|
+
* leaves it at most quarter full. Popped slots are cleared so the ring does not
|
|
9
|
+
* retain references to removed values.
|
|
10
|
+
*/
|
|
11
|
+
import { generatorFrom } from "./iterator.js";
|
|
12
|
+
const INITIAL_CAPACITY = 8;
|
|
13
|
+
/**
|
|
14
|
+
* A double-ended queue.
|
|
15
|
+
*
|
|
16
|
+
* Values can be added and removed at either end. `popFront`, `popBack`,
|
|
17
|
+
* `peekFront`, and `peekBack` return `undefined` when the deque is empty rather
|
|
18
|
+
* than throwing. Since `undefined` is also a valid stored value, use
|
|
19
|
+
* {@link size} or {@link isEmpty} when presence must be distinguished from
|
|
20
|
+
* absence.
|
|
21
|
+
*
|
|
22
|
+
* Iteration is front-to-back.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const deque = new Deque([2, 3]);
|
|
27
|
+
* deque.pushFront(1).pushBack(4);
|
|
28
|
+
* [...deque]; // [1, 2, 3, 4]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class Deque {
|
|
32
|
+
items = new Array(INITIAL_CAPACITY);
|
|
33
|
+
head = 0;
|
|
34
|
+
count = 0;
|
|
35
|
+
/**
|
|
36
|
+
* Create a deque, optionally seeded from `values`.
|
|
37
|
+
*
|
|
38
|
+
* Values are pushed onto the back in iteration order, so the last value
|
|
39
|
+
* becomes the back.
|
|
40
|
+
*
|
|
41
|
+
* @param values - Values to insert, in order.
|
|
42
|
+
*/
|
|
43
|
+
constructor(values) {
|
|
44
|
+
if (values === (void 0)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const value of values) {
|
|
48
|
+
this.pushBack(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Number of values currently in the deque.
|
|
53
|
+
*/
|
|
54
|
+
get size() {
|
|
55
|
+
return this.count;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether the deque contains no values.
|
|
59
|
+
*/
|
|
60
|
+
get isEmpty() {
|
|
61
|
+
return this.count === 0;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Add a value at the front of the deque.
|
|
65
|
+
*
|
|
66
|
+
* @param value - Value to insert.
|
|
67
|
+
* @returns This deque, for chaining.
|
|
68
|
+
*/
|
|
69
|
+
pushFront(value) {
|
|
70
|
+
if (this.count === this.items.length) {
|
|
71
|
+
this.resize(this.items.length * 2);
|
|
72
|
+
}
|
|
73
|
+
this.head = (this.head - 1 + this.items.length) % this.items.length;
|
|
74
|
+
this.items[this.head] = value;
|
|
75
|
+
this.count += 1;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Add a value at the back of the deque.
|
|
80
|
+
*
|
|
81
|
+
* @param value - Value to insert.
|
|
82
|
+
* @returns This deque, for chaining.
|
|
83
|
+
*/
|
|
84
|
+
pushBack(value) {
|
|
85
|
+
if (this.count === this.items.length) {
|
|
86
|
+
this.resize(this.items.length * 2);
|
|
87
|
+
}
|
|
88
|
+
const tail = (this.head + this.count) % this.items.length;
|
|
89
|
+
this.items[tail] = value;
|
|
90
|
+
this.count += 1;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Alias of {@link pushBack}.
|
|
95
|
+
*
|
|
96
|
+
* @param value - Value to insert at the back.
|
|
97
|
+
* @returns This deque, for chaining.
|
|
98
|
+
*/
|
|
99
|
+
push(value) {
|
|
100
|
+
return this.pushBack(value);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Remove and return the value at the front of the deque.
|
|
104
|
+
*
|
|
105
|
+
* @returns The former front value, or `undefined` if the deque is empty.
|
|
106
|
+
*/
|
|
107
|
+
popFront() {
|
|
108
|
+
if (this.count === 0) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const value = this.items[this.head];
|
|
112
|
+
this.items[this.head] = undefined;
|
|
113
|
+
this.head = (this.head + 1) % this.items.length;
|
|
114
|
+
this.count -= 1;
|
|
115
|
+
this.shrinkIfSparse();
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove and return the value at the back of the deque.
|
|
120
|
+
*
|
|
121
|
+
* @returns The former back value, or `undefined` if the deque is empty.
|
|
122
|
+
*/
|
|
123
|
+
popBack() {
|
|
124
|
+
if (this.count === 0) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
const tail = (this.head + this.count - 1) % this.items.length;
|
|
128
|
+
const value = this.items[tail];
|
|
129
|
+
this.items[tail] = undefined;
|
|
130
|
+
this.count -= 1;
|
|
131
|
+
this.shrinkIfSparse();
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Return the value at the front without removing it.
|
|
136
|
+
*
|
|
137
|
+
* @returns The front value, or `undefined` if the deque is empty.
|
|
138
|
+
*/
|
|
139
|
+
peekFront() {
|
|
140
|
+
if (this.count === 0) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
return this.items[this.head];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Return the value at the back without removing it.
|
|
147
|
+
*
|
|
148
|
+
* @returns The back value, or `undefined` if the deque is empty.
|
|
149
|
+
*/
|
|
150
|
+
peekBack() {
|
|
151
|
+
if (this.count === 0) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return this.items[(this.head + this.count - 1) % this.items.length];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Remove every value and reset the ring to its initial capacity.
|
|
158
|
+
*/
|
|
159
|
+
clear() {
|
|
160
|
+
this.items = new Array(INITIAL_CAPACITY);
|
|
161
|
+
this.head = 0;
|
|
162
|
+
this.count = 0;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Snapshot the deque from front to back.
|
|
166
|
+
*
|
|
167
|
+
* @returns A new array whose first item is the front of the deque.
|
|
168
|
+
*/
|
|
169
|
+
toArray() {
|
|
170
|
+
const values = new Array(this.count);
|
|
171
|
+
for (let index = 0; index < this.count; index += 1) {
|
|
172
|
+
values[index] = this.items[(this.head + index) % this.items.length];
|
|
173
|
+
}
|
|
174
|
+
return values;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Iterate front to back over a snapshot taken when the iterator is created.
|
|
178
|
+
*/
|
|
179
|
+
[Symbol.iterator]() {
|
|
180
|
+
return generatorFrom(this.toArray());
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Copy the live values into a fresh ring, front to back.
|
|
184
|
+
*/
|
|
185
|
+
resize(capacity) {
|
|
186
|
+
const next = new Array(capacity);
|
|
187
|
+
for (let index = 0; index < this.count; index += 1) {
|
|
188
|
+
next[index] = this.items[(this.head + index) % this.items.length];
|
|
189
|
+
}
|
|
190
|
+
this.items = next;
|
|
191
|
+
this.head = 0;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Halve an oversized ring after a pop leaves it at most quarter full.
|
|
195
|
+
*/
|
|
196
|
+
shrinkIfSparse() {
|
|
197
|
+
if (this.items.length <= INITIAL_CAPACITY) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (this.count > this.items.length / 4) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
this.resize(this.items.length / 2);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key encoding shared by the probabilistic filters.
|
|
3
|
+
*
|
|
4
|
+
* Filters operate on bytes. Strings are encoded as UTF-8, and an existing
|
|
5
|
+
* `Uint8Array` is used as-is (not copied), so callers must not mutate a key
|
|
6
|
+
* buffer while it is being inserted or queried.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A key accepted by {@link BloomFilter} and {@link CuckooFilter}.
|
|
10
|
+
*/
|
|
11
|
+
export type FilterKey = string | Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* UTF-8 bytes for a string, or the original byte view for a `Uint8Array`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const filterKeyBytes: (key: FilterKey) => Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Reject non-string/non-byte values early with a useful error.
|
|
18
|
+
*/
|
|
19
|
+
export declare const assertFilterKey: (key: unknown) => asserts key is FilterKey;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key encoding shared by the probabilistic filters.
|
|
3
|
+
*
|
|
4
|
+
* Filters operate on bytes. Strings are encoded as UTF-8, and an existing
|
|
5
|
+
* `Uint8Array` is used as-is (not copied), so callers must not mutate a key
|
|
6
|
+
* buffer while it is being inserted or queried.
|
|
7
|
+
*/
|
|
8
|
+
const Encoder = new TextEncoder();
|
|
9
|
+
/**
|
|
10
|
+
* UTF-8 bytes for a string, or the original byte view for a `Uint8Array`.
|
|
11
|
+
*/
|
|
12
|
+
export const filterKeyBytes = (key) => {
|
|
13
|
+
if (typeof (key) === "string") {
|
|
14
|
+
return Encoder.encode(key);
|
|
15
|
+
}
|
|
16
|
+
if (key instanceof Uint8Array) {
|
|
17
|
+
return key;
|
|
18
|
+
}
|
|
19
|
+
throw new TypeError("filter keys must be strings or Uint8Array values");
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Reject non-string/non-byte values early with a useful error.
|
|
23
|
+
*/
|
|
24
|
+
export const assertFilterKey = (key) => {
|
|
25
|
+
if (typeof (key) !== "string" && !(key instanceof Uint8Array)) {
|
|
26
|
+
throw new TypeError("filter keys must be strings or Uint8Array values");
|
|
27
|
+
}
|
|
28
|
+
};
|