@bastani/atomic 0.10.4-alpha.2 → 0.10.5-alpha.1
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 +238 -0
- package/dist/_shared/chunk-CDOYTDYM.js +4 -0
- package/dist/_shared/chunk-CDOYTDYM.js.map +1 -0
- package/dist/_shared/compile-cache-warmup-host-RU5L7I7A.js +1 -1
- package/dist/_shared/dist-KOELCESV.js +48 -3
- package/dist/_shared/fork-row-index-UAUAQRD5.js +47 -2
- package/dist/_shared/http-YFAPTIZD.js +16 -4
- package/dist/_shared/http-YFAPTIZD.js.map +1 -1
- package/dist/_shared/lib-4PES5P4V.js +59 -14
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +1706 -258
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +317 -64
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
- package/dist/_shared/{mode-shared-HP7GUA7J.js → mode-shared-2QJSCUM6.js} +432 -81
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -0
- package/dist/_shared/p0-cli-BB45ZQY6.js +3482 -0
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -0
- package/dist/_shared/p0-cli-GUFK7TPN.js +2 -2838
- package/dist/_shared/p0-cli-GUFK7TPN.js.map +1 -1
- package/dist/_shared/{p1a-prewarm-YK3KDTLN.js → p1a-prewarm-UQY3X2UK.js} +270 -73
- package/dist/_shared/p1a-prewarm-UQY3X2UK.js.map +1 -0
- package/dist/_shared/{p1b-elig-PXQA2FYP.js → p1b-elig-ENCUPKKJ.js} +190 -121
- package/dist/_shared/p1b-elig-ENCUPKKJ.js.map +1 -0
- package/dist/_shared/p2-common-YLSYXMDQ.js +1 -3
- package/dist/_shared/p2-common-YLSYXMDQ.js.map +1 -1
- package/dist/_shared/p2-shell-TJBYQMCJ.js +1 -1
- package/dist/_shared/p2-shell-main-B2WIALFD.js +500 -127
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +4 -4
- package/dist/_shared/sdk-WQIOHVKO.js +56 -11
- package/dist/_shared/session-data-AHTU7IS6.js +48 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +2 -2
- package/dist/_shared/settings-startup-65YEWRV2.js.map +1 -1
- package/dist/_shared/sql-session-store-5FD3WBMZ.js +57 -12
- package/dist/_shared/{startup-0-0-X4NF3GKM.js → startup-0-0-TYUFUOJZ.js} +528 -321
- package/dist/_shared/startup-0-0-TYUFUOJZ.js.map +1 -0
- package/dist/_shared/{startup-0-1-7QTG6VJZ.js → startup-0-1-D4LGGINF.js} +284 -81
- package/dist/_shared/startup-0-1-D4LGGINF.js.map +1 -0
- package/dist/_shared/{startup-0-2-KFDYPDJK.js → startup-0-2-SZGQIWHI.js} +483 -154
- package/dist/_shared/startup-0-2-SZGQIWHI.js.map +1 -0
- package/dist/_shared/startup-0-3-T4DVFYWX.js +340 -110
- package/dist/_shared/startup-0-3-T4DVFYWX.js.map +1 -1
- package/dist/_shared/startup-0-4-HN5EB4K7.js +261 -59
- package/dist/_shared/startup-0-4-HN5EB4K7.js.map +1 -1
- package/dist/_shared/startup-0-5-OHJNE6JH.js +421 -148
- package/dist/_shared/startup-0-5-OHJNE6JH.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +62 -11
- package/dist/_shared/startup-10-0-TDQNBDDL.js.map +1 -1
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +12 -11
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +53 -158
- package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +231 -46
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +115 -35
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-KQJBDKRU.js → startup-8-1-SJW2GMAM.js} +203 -62
- package/dist/_shared/startup-8-1-SJW2GMAM.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +55 -10
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +47 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +48 -3
- package/dist/builtin/intercom/CHANGELOG.md +59 -0
- package/dist/builtin/intercom/README.md +0 -1
- package/dist/builtin/intercom/broker/broker-instance.ts +13 -57
- package/dist/builtin/intercom/broker/broker-process.ts +30 -10
- package/dist/builtin/intercom/broker/broker-routing.ts +12 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +2557 -498
- package/dist/builtin/intercom/broker/broker.ts +164 -55
- package/dist/builtin/intercom/broker/client.ts +36 -16
- package/dist/builtin/intercom/broker/control.ts +83 -20
- package/dist/builtin/intercom/broker/durable-ended-queue.ts +65 -19
- package/dist/builtin/intercom/broker/host-command-environment.ts +7 -2
- package/dist/builtin/intercom/broker/multinode-router.ts +1675 -387
- package/dist/builtin/intercom/broker/multinode-state-store.ts +10 -0
- package/dist/builtin/intercom/broker/paths.ts +68 -6
- package/dist/builtin/intercom/broker/pending-send-registry.ts +5 -0
- package/dist/builtin/intercom/broker/registration-bounds.ts +38 -0
- package/dist/builtin/intercom/broker/retiring-broker-check.ts +178 -0
- package/dist/builtin/intercom/broker/return-paths.ts +268 -7
- package/dist/builtin/intercom/broker/send-handler.ts +253 -28
- package/dist/builtin/intercom/broker/send-order-gate.ts +410 -0
- package/dist/builtin/intercom/broker/spawn.ts +950 -202
- package/dist/builtin/intercom/broker/sql-lease-store.ts +37 -0
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +7 -0
- package/dist/builtin/intercom/broker/windows-cwd.ts +546 -0
- package/dist/builtin/intercom/index.bundle.mjs +3506 -2328
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/retry-policy.ts +4 -0
- package/dist/builtin/intercom/types.ts +2 -0
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +46 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +336 -86
- package/dist/builtin/web-access/CHANGELOG.md +12 -0
- package/dist/builtin/web-access/index.bundle.mjs +23 -38
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/bun/cli.js +1 -1
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/internal-intercom-broker.js +119 -4
- package/dist/bun/internal-intercom-broker.js.map +1 -1
- package/dist/bun/register-theme-validator.js +6 -0
- package/dist/bun/register-theme-validator.js.map +1 -0
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +1102 -0
- package/dist/cli/auth-cli.code.js.map +1 -0
- package/dist/cli/auth-cli.impl.js +36 -0
- package/dist/cli/auth-cli.impl.js.map +1 -0
- package/dist/cli/auth-cli.js +30 -1096
- package/dist/cli/auth-cli.js.map +1 -1
- package/dist/cli/blueprint-command.code.js +906 -0
- package/dist/cli/blueprint-command.code.js.map +1 -0
- package/dist/cli/blueprint-command.impl.js +36 -0
- package/dist/cli/blueprint-command.impl.js.map +1 -0
- package/dist/cli/blueprint-command.js +30 -900
- package/dist/cli/blueprint-command.js.map +1 -1
- package/dist/cli/intercom-command.code.js +153 -0
- package/dist/cli/intercom-command.code.js.map +1 -0
- package/dist/cli/intercom-command.impl.js +36 -0
- package/dist/cli/intercom-command.impl.js.map +1 -0
- package/dist/cli/intercom-command.js +33 -105
- package/dist/cli/intercom-command.js.map +1 -1
- package/dist/cli/list-models.code.js +60 -0
- package/dist/cli/list-models.code.js.map +1 -0
- package/dist/cli/list-models.impl.js +36 -0
- package/dist/cli/list-models.impl.js.map +1 -0
- package/dist/cli/list-models.js +33 -57
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/session-picker.code.js +55 -0
- package/dist/cli/session-picker.code.js.map +1 -0
- package/dist/cli/session-picker.impl.js +36 -0
- package/dist/cli/session-picker.impl.js.map +1 -0
- package/dist/cli/session-picker.js +33 -52
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/startup-ui.code.js +5 -0
- package/dist/cli/startup-ui.code.js.map +1 -0
- package/dist/cli/startup-ui.impl.js +36 -0
- package/dist/cli/startup-ui.impl.js.map +1 -0
- package/dist/cli/startup-ui.js +35 -4
- package/dist/cli/storage-command.code.js +3 -0
- package/dist/cli/storage-command.code.js.map +1 -0
- package/dist/cli/storage-command.impl.js +36 -0
- package/dist/cli/storage-command.impl.js.map +1 -0
- package/dist/cli/storage-command.js +35 -2
- package/dist/cli/storage-search-session.code.js +189 -0
- package/dist/cli/storage-search-session.code.js.map +1 -0
- package/dist/cli/storage-search-session.impl.js +36 -0
- package/dist/cli/storage-search-session.impl.js.map +1 -0
- package/dist/cli/storage-search-session.js +33 -186
- package/dist/cli/storage-search-session.js.map +1 -1
- package/dist/cli/team-command.code.js +217 -0
- package/dist/cli/team-command.code.js.map +1 -0
- package/dist/cli/team-command.impl.js +36 -0
- package/dist/cli/team-command.impl.js.map +1 -0
- package/dist/cli/team-command.js +32 -213
- package/dist/cli/team-command.js.map +1 -1
- package/dist/cli.js +60 -11
- package/dist/cli.js.map +1 -1
- package/dist/config.js +1 -1
- package/dist/core/agent-session-methods.d.ts +4 -3
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +5 -0
- package/dist/core/compaction/compaction.d.ts +6 -0
- package/dist/core/compaction/model-resolver.d.ts +1 -1
- package/dist/core/debug.code.js +3 -0
- package/dist/core/debug.code.js.map +1 -0
- package/dist/core/debug.impl.js +36 -0
- package/dist/core/debug.impl.js.map +1 -0
- package/dist/core/debug.js +35 -2
- package/dist/core/default-model-api-prewarm.d.ts +5 -0
- package/dist/core/export-html/card-projection.code.js +257 -0
- package/dist/core/export-html/card-projection.code.js.map +1 -0
- package/dist/core/export-html/card-projection.impl.js +36 -0
- package/dist/core/export-html/card-projection.impl.js.map +1 -0
- package/dist/core/export-html/card-projection.js +34 -255
- package/dist/core/export-html/card-projection.js.map +1 -1
- package/dist/core/export-html/index.code.js +655 -0
- package/dist/core/export-html/index.code.js.map +1 -0
- package/dist/core/export-html/index.impl.js +36 -0
- package/dist/core/export-html/index.impl.js.map +1 -0
- package/dist/core/export-html/index.js +30 -604
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/json-spans.code.js +3 -0
- package/dist/core/export-html/json-spans.code.js.map +1 -0
- package/dist/core/export-html/json-spans.impl.js +36 -0
- package/dist/core/export-html/json-spans.impl.js.map +1 -0
- package/dist/core/export-html/json-spans.js +35 -2
- package/dist/core/export-html/oversized-render-inputs.code.js +125 -0
- package/dist/core/export-html/oversized-render-inputs.code.js.map +1 -0
- package/dist/core/export-html/oversized-render-inputs.impl.js +36 -0
- package/dist/core/export-html/oversized-render-inputs.impl.js.map +1 -0
- package/dist/core/export-html/oversized-render-inputs.js +31 -120
- package/dist/core/export-html/oversized-render-inputs.js.map +1 -1
- package/dist/core/export-html/tool-renderer.code.js +350 -0
- package/dist/core/export-html/tool-renderer.code.js.map +1 -0
- package/dist/core/export-html/tool-renderer.impl.js +36 -0
- package/dist/core/export-html/tool-renderer.impl.js.map +1 -0
- package/dist/core/export-html/tool-renderer.js +33 -347
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/jiti-loader.code.js +3 -0
- package/dist/core/extensions/jiti-loader.code.js.map +1 -0
- package/dist/core/extensions/jiti-loader.impl.js +36 -0
- package/dist/core/extensions/jiti-loader.impl.js.map +1 -0
- package/dist/core/extensions/jiti-loader.js +35 -2
- package/dist/core/extensions/jiti-static-loader.code.js +3 -0
- package/dist/core/extensions/jiti-static-loader.code.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.impl.js +36 -0
- package/dist/core/extensions/jiti-static-loader.impl.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.js +35 -2
- package/dist/core/extensions/loader-host-modules.code.js +3 -0
- package/dist/core/extensions/loader-host-modules.code.js.map +1 -0
- package/dist/core/extensions/loader-host-modules.impl.js +36 -0
- package/dist/core/extensions/loader-host-modules.impl.js.map +1 -0
- package/dist/core/extensions/loader-host-modules.js +35 -2
- package/dist/core/extensions/loader-virtual-modules.d.ts +1 -6
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +3 -3
- package/dist/core/extensions/session-events.d.ts +4 -0
- package/dist/core/extensions/session-events.js.map +1 -1
- package/dist/core/intercom-broker-control-host.code.js +5 -0
- package/dist/core/intercom-broker-control-host.code.js.map +1 -0
- package/dist/core/intercom-broker-control-host.impl.js +36 -0
- package/dist/core/intercom-broker-control-host.impl.js.map +1 -0
- package/dist/core/intercom-broker-control-host.js +35 -4
- package/dist/core/intercom-broker-control.code.js +63 -0
- package/dist/core/intercom-broker-control.code.js.map +1 -0
- package/dist/core/intercom-broker-control.d.ts +21 -0
- package/dist/core/intercom-broker-control.impl.js +36 -0
- package/dist/core/intercom-broker-control.impl.js.map +1 -0
- package/dist/core/intercom-broker-control.js +35 -17
- package/dist/core/intercom-broker-control.js.map +1 -1
- package/dist/core/package-manager-storage-adapters.code.js +3 -0
- package/dist/core/package-manager-storage-adapters.code.js.map +1 -0
- package/dist/core/package-manager-storage-adapters.impl.js +36 -0
- package/dist/core/package-manager-storage-adapters.impl.js.map +1 -0
- package/dist/core/package-manager-storage-adapters.js +35 -2
- package/dist/core/process-start-token.d.ts +8 -2
- package/dist/core/process-tree-containment.d.ts +27 -0
- package/dist/core/queued-message-delivery.d.ts +5 -2
- package/dist/core/resume/blueprint/process.d.ts +3 -1
- package/dist/core/sdk.code.js +9 -0
- package/dist/core/sdk.code.js.map +1 -0
- package/dist/core/sdk.impl.js +36 -0
- package/dist/core/sdk.impl.js.map +1 -0
- package/dist/core/sdk.js +35 -8
- package/dist/core/session-manager-core.d.ts +15 -5
- package/dist/core/session-manager-core.js +195 -38
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-list.code.js +3 -0
- package/dist/core/session-manager-list.code.js.map +1 -0
- package/dist/core/session-manager-list.impl.js +36 -0
- package/dist/core/session-manager-list.impl.js.map +1 -0
- package/dist/core/session-manager-list.js +35 -2
- package/dist/core/session-manager-types.d.ts +20 -0
- package/dist/core/session-manager.code.js +8 -0
- package/dist/core/session-manager.code.js.map +1 -0
- package/dist/core/session-manager.d.ts +1 -1
- package/dist/core/session-manager.impl.js +36 -0
- package/dist/core/session-manager.impl.js.map +1 -0
- package/dist/core/session-manager.js +35 -7
- package/dist/core/session-storage.code.js +3 -0
- package/dist/core/session-storage.code.js.map +1 -0
- package/dist/core/session-storage.impl.js +36 -0
- package/dist/core/session-storage.impl.js.map +1 -0
- package/dist/core/session-storage.js +35 -2
- package/dist/core/storage/file-identity.d.ts +3 -0
- package/dist/core/storage/file-identity.js +296 -86
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +1 -1
- package/dist/core/storage/index.js +52 -7
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +47 -2
- package/dist/core/storage/node-sqlite.js +49 -4
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/dist/core/storage/offline-snapshot-file.code.js +37 -0
- package/dist/core/storage/offline-snapshot-file.code.js.map +1 -0
- package/dist/core/storage/offline-snapshot-file.impl.js +36 -0
- package/dist/core/storage/offline-snapshot-file.impl.js.map +1 -0
- package/dist/core/storage/offline-snapshot-file.js +33 -34
- package/dist/core/storage/offline-snapshot-file.js.map +1 -1
- package/dist/core/storage/provider.js +52 -7
- package/dist/core/storage/selection.js +49 -4
- package/dist/core/storage/session/branch-fork-source.code.js +146 -0
- package/dist/core/storage/session/branch-fork-source.code.js.map +1 -0
- package/dist/core/storage/session/branch-fork-source.impl.js +36 -0
- package/dist/core/storage/session/branch-fork-source.impl.js.map +1 -0
- package/dist/core/storage/session/branch-fork-source.js +32 -97
- package/dist/core/storage/session/branch-fork-source.js.map +1 -1
- package/dist/core/storage/session/card-view.code.js +60 -0
- package/dist/core/storage/session/card-view.code.js.map +1 -0
- package/dist/core/storage/session/card-view.impl.js +36 -0
- package/dist/core/storage/session/card-view.impl.js.map +1 -0
- package/dist/core/storage/session/card-view.js +34 -58
- package/dist/core/storage/session/card-view.js.map +1 -1
- package/dist/core/storage/session/child-reader.code.js +139 -0
- package/dist/core/storage/session/child-reader.code.js.map +1 -0
- package/dist/core/storage/session/child-reader.d.ts +1 -0
- package/dist/core/storage/session/child-reader.impl.js +36 -0
- package/dist/core/storage/session/child-reader.impl.js.map +1 -0
- package/dist/core/storage/session/child-reader.js +33 -91
- package/dist/core/storage/session/child-reader.js.map +1 -1
- package/dist/core/storage/session/chunked-resume-projection.code.js +3 -0
- package/dist/core/storage/session/chunked-resume-projection.code.js.map +1 -0
- package/dist/core/storage/session/chunked-resume-projection.impl.js +36 -0
- package/dist/core/storage/session/chunked-resume-projection.impl.js.map +1 -0
- package/dist/core/storage/session/chunked-resume-projection.js +35 -2
- package/dist/core/storage/session/expanded-child-details.code.js +684 -0
- package/dist/core/storage/session/expanded-child-details.code.js.map +1 -0
- package/dist/core/storage/session/expanded-child-details.impl.js +36 -0
- package/dist/core/storage/session/expanded-child-details.impl.js.map +1 -0
- package/dist/core/storage/session/expanded-child-details.js +31 -634
- package/dist/core/storage/session/expanded-child-details.js.map +1 -1
- package/dist/core/storage/session/fork-row-bytes.code.js +3 -0
- package/dist/core/storage/session/fork-row-bytes.code.js.map +1 -0
- package/dist/core/storage/session/fork-row-bytes.impl.js +36 -0
- package/dist/core/storage/session/fork-row-bytes.impl.js.map +1 -0
- package/dist/core/storage/session/fork-row-bytes.js +35 -2
- package/dist/core/storage/session/fork-row-index.code.js +3 -0
- package/dist/core/storage/session/fork-row-index.code.js.map +1 -0
- package/dist/core/storage/session/fork-row-index.impl.js +36 -0
- package/dist/core/storage/session/fork-row-index.impl.js.map +1 -0
- package/dist/core/storage/session/fork-row-index.js +35 -2
- package/dist/core/storage/session/fork-staging.code.js +580 -0
- package/dist/core/storage/session/fork-staging.code.js.map +1 -0
- package/dist/core/storage/session/fork-staging.impl.js +36 -0
- package/dist/core/storage/session/fork-staging.impl.js.map +1 -0
- package/dist/core/storage/session/fork-staging.js +30 -574
- package/dist/core/storage/session/fork-staging.js.map +1 -1
- package/dist/core/storage/session/fork-window.code.js +522 -0
- package/dist/core/storage/session/fork-window.code.js.map +1 -0
- package/dist/core/storage/session/fork-window.impl.js +36 -0
- package/dist/core/storage/session/fork-window.impl.js.map +1 -0
- package/dist/core/storage/session/fork-window.js +30 -471
- package/dist/core/storage/session/fork-window.js.map +1 -1
- package/dist/core/storage/session/history-pages.code.js +3 -0
- package/dist/core/storage/session/history-pages.code.js.map +1 -0
- package/dist/core/storage/session/history-pages.impl.js +36 -0
- package/dist/core/storage/session/history-pages.impl.js.map +1 -0
- package/dist/core/storage/session/history-pages.js +35 -2
- package/dist/core/storage/session/jsonl-entry-projection.code.js +3 -0
- package/dist/core/storage/session/jsonl-entry-projection.code.js.map +1 -0
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +36 -0
- package/dist/core/storage/session/jsonl-entry-projection.impl.js.map +1 -0
- package/dist/core/storage/session/jsonl-entry-projection.js +35 -2
- package/dist/core/storage/session/jsonl-session-store.code.js +3 -0
- package/dist/core/storage/session/jsonl-session-store.code.js.map +1 -0
- package/dist/core/storage/session/jsonl-session-store.impl.js +36 -0
- package/dist/core/storage/session/jsonl-session-store.impl.js.map +1 -0
- package/dist/core/storage/session/jsonl-session-store.js +35 -2
- package/dist/core/storage/session/memory-session-store.code.js +3 -0
- package/dist/core/storage/session/memory-session-store.code.js.map +1 -0
- package/dist/core/storage/session/memory-session-store.impl.js +36 -0
- package/dist/core/storage/session/memory-session-store.impl.js.map +1 -0
- package/dist/core/storage/session/memory-session-store.js +35 -2
- package/dist/core/storage/session/pinned-branch-resume.code.js +117 -0
- package/dist/core/storage/session/pinned-branch-resume.code.js.map +1 -0
- package/dist/core/storage/session/pinned-branch-resume.impl.js +36 -0
- package/dist/core/storage/session/pinned-branch-resume.impl.js.map +1 -0
- package/dist/core/storage/session/pinned-branch-resume.js +33 -69
- package/dist/core/storage/session/pinned-branch-resume.js.map +1 -1
- package/dist/core/storage/session/released-history-files.code.js +465 -0
- package/dist/core/storage/session/released-history-files.code.js.map +1 -0
- package/dist/core/storage/session/released-history-files.impl.js +36 -0
- package/dist/core/storage/session/released-history-files.impl.js.map +1 -0
- package/dist/core/storage/session/released-history-files.js +32 -461
- package/dist/core/storage/session/released-history-files.js.map +1 -1
- package/dist/core/storage/session/resident-fork-rows.code.js +57 -0
- package/dist/core/storage/session/resident-fork-rows.code.js.map +1 -0
- package/dist/core/storage/session/resident-fork-rows.impl.js +36 -0
- package/dist/core/storage/session/resident-fork-rows.impl.js.map +1 -0
- package/dist/core/storage/session/resident-fork-rows.js +32 -53
- package/dist/core/storage/session/resident-fork-rows.js.map +1 -1
- package/dist/core/storage/session/session-resume.code.js +3 -0
- package/dist/core/storage/session/session-resume.code.js.map +1 -0
- package/dist/core/storage/session/session-resume.impl.js +36 -0
- package/dist/core/storage/session/session-resume.impl.js.map +1 -0
- package/dist/core/storage/session/session-resume.js +35 -2
- package/dist/core/storage/session/snapshot-cut.code.js +3 -0
- package/dist/core/storage/session/snapshot-cut.code.js.map +1 -0
- package/dist/core/storage/session/snapshot-cut.impl.js +36 -0
- package/dist/core/storage/session/snapshot-cut.impl.js.map +1 -0
- package/dist/core/storage/session/snapshot-cut.js +35 -2
- package/dist/core/storage/session/snapshot-history.code.js +107 -0
- package/dist/core/storage/session/snapshot-history.code.js.map +1 -0
- package/dist/core/storage/session/snapshot-history.impl.js +36 -0
- package/dist/core/storage/session/snapshot-history.impl.js.map +1 -0
- package/dist/core/storage/session/snapshot-history.js +34 -60
- package/dist/core/storage/session/snapshot-history.js.map +1 -1
- package/dist/core/storage/session/sql-session-store.code.js +3 -0
- package/dist/core/storage/session/sql-session-store.code.js.map +1 -0
- package/dist/core/storage/session/sql-session-store.impl.js +36 -0
- package/dist/core/storage/session/sql-session-store.impl.js.map +1 -0
- package/dist/core/storage/session/sql-session-store.js +35 -2
- package/dist/core/storage/session/tree-outline.code.js +3 -0
- package/dist/core/storage/session/tree-outline.code.js.map +1 -0
- package/dist/core/storage/session/tree-outline.impl.js +36 -0
- package/dist/core/storage/session/tree-outline.impl.js.map +1 -0
- package/dist/core/storage/session/tree-outline.js +35 -2
- package/dist/core/storage/session/tree-presentation.code.js +342 -0
- package/dist/core/storage/session/tree-presentation.code.js.map +1 -0
- package/dist/core/storage/session/tree-presentation.impl.js +36 -0
- package/dist/core/storage/session/tree-presentation.impl.js.map +1 -0
- package/dist/core/storage/session/tree-presentation.js +31 -337
- package/dist/core/storage/session/tree-presentation.js.map +1 -1
- package/dist/core/storage/session/types.d.ts +26 -0
- package/dist/core/storage/storage-status.code.js +3 -0
- package/dist/core/storage/storage-status.code.js.map +1 -0
- package/dist/core/storage/storage-status.impl.js +36 -0
- package/dist/core/storage/storage-status.impl.js.map +1 -0
- package/dist/core/storage/storage-status.js +35 -2
- package/dist/core/storage/team.code.js +3 -0
- package/dist/core/storage/team.code.js.map +1 -0
- package/dist/core/storage/team.impl.js +36 -0
- package/dist/core/storage/team.impl.js.map +1 -0
- package/dist/core/storage/team.js +35 -2
- package/dist/core/structured-output/index.code.js +3 -0
- package/dist/core/structured-output/index.code.js.map +1 -0
- package/dist/core/structured-output/index.impl.js +36 -0
- package/dist/core/structured-output/index.impl.js.map +1 -0
- package/dist/core/structured-output/index.js +35 -2
- package/dist/core/tasks/command-output.d.ts +4 -1
- package/dist/core/tasks/supervisor.d.ts +2 -0
- package/dist/core/tasks/task-completion-entry.code.js +254 -0
- package/dist/core/tasks/task-completion-entry.code.js.map +1 -0
- package/dist/core/tasks/task-completion-entry.impl.js +36 -0
- package/dist/core/tasks/task-completion-entry.impl.js.map +1 -0
- package/dist/core/tasks/task-completion-entry.js +33 -251
- package/dist/core/tasks/task-completion-entry.js.map +1 -1
- package/dist/core/tasks/task-file-history.code.js +424 -0
- package/dist/core/tasks/task-file-history.code.js.map +1 -0
- package/dist/core/tasks/task-file-history.impl.js +36 -0
- package/dist/core/tasks/task-file-history.impl.js.map +1 -0
- package/dist/core/tasks/task-file-history.js +32 -375
- package/dist/core/tasks/task-file-history.js.map +1 -1
- package/dist/core/tasks/task-reference-archive.code.js +514 -0
- package/dist/core/tasks/task-reference-archive.code.js.map +1 -0
- package/dist/core/tasks/task-reference-archive.js +34 -467
- package/dist/core/tasks/task-reference-archive.js.map +1 -1
- package/dist/core/tasks/task-reference-identity.code.js +164 -0
- package/dist/core/tasks/task-reference-identity.code.js.map +1 -0
- package/dist/core/tasks/task-reference-identity.js +32 -160
- package/dist/core/tasks/task-reference-identity.js.map +1 -1
- package/dist/core/tasks/task-reference-stream.code.js +3 -0
- package/dist/core/tasks/task-reference-stream.code.js.map +1 -0
- package/dist/core/tasks/task-reference-stream.impl.js +36 -0
- package/dist/core/tasks/task-reference-stream.impl.js.map +1 -0
- package/dist/core/tasks/task-reference-stream.js +35 -2
- package/dist/core/tasks/task-unsaved-answer.code.js +3 -0
- package/dist/core/tasks/task-unsaved-answer.code.js.map +1 -0
- package/dist/core/tasks/task-unsaved-answer.impl.js +36 -0
- package/dist/core/tasks/task-unsaved-answer.impl.js.map +1 -0
- package/dist/core/tasks/task-unsaved-answer.js +35 -2
- package/dist/core/tasks/task-view-source.code.js +3 -0
- package/dist/core/tasks/task-view-source.code.js.map +1 -0
- package/dist/core/tasks/task-view-source.d.ts +9 -0
- package/dist/core/tasks/task-view-source.impl.js +36 -0
- package/dist/core/tasks/task-view-source.impl.js.map +1 -0
- package/dist/core/tasks/task-view-source.js +35 -2
- package/dist/core/tools/read-url.code.js +1530 -0
- package/dist/core/tools/read-url.code.js.map +1 -0
- package/dist/core/tools/read-url.impl.js +36 -0
- package/dist/core/tools/read-url.impl.js.map +1 -0
- package/dist/core/tools/read-url.js +30 -1524
- package/dist/core/tools/read-url.js.map +1 -1
- package/dist/core/worktree-snapshot/blob-store.js +50 -5
- package/dist/core/worktree-snapshot/errors.code.js +6 -0
- package/dist/core/worktree-snapshot/errors.code.js.map +1 -0
- package/dist/core/worktree-snapshot/errors.impl.js +36 -0
- package/dist/core/worktree-snapshot/errors.impl.js.map +1 -0
- package/dist/core/worktree-snapshot/errors.js +35 -5
- package/dist/core/worktree-snapshot/session-index-reset.code.js +136 -0
- package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -0
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +36 -0
- package/dist/core/worktree-snapshot/session-index-reset.impl.js.map +1 -0
- package/dist/core/worktree-snapshot/session-index-reset.js +34 -134
- package/dist/core/worktree-snapshot/session-index-reset.js.map +1 -1
- package/dist/extensions/codemode/execute.code.js +618 -0
- package/dist/extensions/codemode/execute.code.js.map +1 -0
- package/dist/extensions/codemode/execute.impl.js +36 -0
- package/dist/extensions/codemode/execute.impl.js.map +1 -0
- package/dist/extensions/codemode/execute.js +30 -612
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/renderer.code.js +110 -0
- package/dist/extensions/codemode/renderer.code.js.map +1 -0
- package/dist/extensions/codemode/renderer.impl.js +36 -0
- package/dist/extensions/codemode/renderer.impl.js.map +1 -0
- package/dist/extensions/codemode/renderer.js +33 -107
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/mcp/cli.code.js +565 -0
- package/dist/extensions/mcp/cli.code.js.map +1 -0
- package/dist/extensions/mcp/cli.impl.js +36 -0
- package/dist/extensions/mcp/cli.impl.js.map +1 -0
- package/dist/extensions/mcp/cli.js +32 -561
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/cli.lazy.code.js +52 -0
- package/dist/extensions/mcp/cli.lazy.code.js.map +1 -0
- package/dist/extensions/mcp/cli.lazy.impl.js +36 -0
- package/dist/extensions/mcp/cli.lazy.impl.js.map +1 -0
- package/dist/extensions/mcp/cli.lazy.js +36 -7
- package/dist/extensions/mcp/cli.lazy.js.map +1 -1
- package/dist/extensions/mcp/client/transports/stdio.d.ts +2 -0
- package/dist/extensions/mcp/runtime.code.js +5 -0
- package/dist/extensions/mcp/runtime.code.js.map +1 -0
- package/dist/extensions/mcp/runtime.impl.js +36 -0
- package/dist/extensions/mcp/runtime.impl.js.map +1 -0
- package/dist/extensions/mcp/runtime.js +35 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/main-first-time-setup.code.js +12 -0
- package/dist/main-first-time-setup.code.js.map +1 -0
- package/dist/main-first-time-setup.impl.js +36 -0
- package/dist/main-first-time-setup.impl.js.map +1 -0
- package/dist/main-first-time-setup.js +35 -11
- package/dist/main-first-time-setup.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +2 -2
- package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts +6 -1
- package/dist/modes/interactive/agent-view/contracts.d.ts +4 -0
- package/dist/modes/interactive/chat-reader-records.d.ts +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +338 -0
- package/dist/modes/interactive/components/stored-tree-view.code.js.map +1 -0
- package/dist/modes/interactive/components/stored-tree-view.impl.js +36 -0
- package/dist/modes/interactive/components/stored-tree-view.impl.js.map +1 -0
- package/dist/modes/interactive/components/stored-tree-view.js +33 -290
- package/dist/modes/interactive/components/stored-tree-view.js.map +1 -1
- package/dist/modes/interactive/components/task-selection-state.d.ts +8 -3
- package/dist/modes/interactive/components/task-transcript-page.d.ts +1 -0
- package/dist/modes/interactive/components/user-message-selector-archive.code.js +191 -0
- package/dist/modes/interactive/components/user-message-selector-archive.code.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +36 -0
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector-archive.js +34 -189
- package/dist/modes/interactive/components/user-message-selector-archive.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +6 -0
- package/dist/modes/interactive/interactive-mode-deps.js +4 -0
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-queueing.d.ts +4 -0
- package/dist/modes/interactive/interactive-render-chat.d.ts +22 -0
- package/dist/modes/interactive/interactive-startup.d.ts +2 -0
- package/dist/modes/interactive/program-status-reporter.d.ts +2 -1
- package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
- package/dist/modes/interactive/steering-queue-controller.d.ts +4 -0
- package/dist/modes/interactive/theme/theme-schema-factory.d.ts +26 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts +4 -5
- package/dist/modes/interactive-engine/engine-prewarm.d.ts +30 -5
- package/dist/modes/interactive-engine/engine-prewarm.js +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +7 -0
- package/dist/modes/interactive-engine/protocol.d.ts +32 -1
- package/dist/modes/rpc/agent-view-rpc-types.d.ts +12 -1
- package/dist/modes/rpc/agent-view-rpc-types.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +3 -1
- package/dist/modes/rpc/rpc-types.d.ts +12 -0
- package/dist/package-manager-cli.code.js +1140 -0
- package/dist/package-manager-cli.code.js.map +1 -0
- package/dist/package-manager-cli.impl.js +36 -0
- package/dist/package-manager-cli.impl.js.map +1 -0
- package/dist/package-manager-cli.js +36 -1067
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.js +2 -2
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/13.js +1 -0
- package/dist/startup-stages/2.js +1 -7
- package/dist/startup-stages/3.js +6 -2
- package/dist/startup-stages/4.js +2 -1
- package/dist/startup-stages/5.js +1 -7
- package/dist/startup-stages/6.js +7 -10
- package/dist/startup-stages/7.js +10 -3
- package/dist/startup-stages/8.js +3 -6
- package/dist/startup-stages/9.js +6 -1
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/canonical-path.js +2 -0
- package/dist/utils/canonical-path.js.map +1 -1
- package/dist/utils/child-process.d.ts +41 -1
- package/dist/utils/compile-cache-warmup-host.js +63 -18
- package/dist/utils/compile-cache-warmup-host.js.map +1 -1
- package/dist/utils/credential-redaction.d.ts +50 -1
- package/dist/utils/interactive-engine-bootstrap.d.ts +2 -0
- package/dist/utils/interactive-engine-env.d.ts +2 -0
- package/dist/utils/memoize-async.d.ts +32 -0
- package/dist/utils/memoize-async.js +91 -0
- package/dist/utils/memoize-async.js.map +1 -0
- package/dist/utils/photon.js +19 -29
- package/dist/utils/photon.js.map +1 -1
- package/dist/utils/shell.d.ts +7 -4
- package/dist/utils/startup-database-spare.code.js +108 -0
- package/dist/utils/startup-database-spare.code.js.map +1 -0
- package/dist/utils/startup-database-spare.impl.js +36 -0
- package/dist/utils/startup-database-spare.impl.js.map +1 -0
- package/dist/utils/startup-database-spare.js +33 -105
- package/dist/utils/startup-database-spare.js.map +1 -1
- package/dist/utils/tools-manager.code.js +3 -0
- package/dist/utils/tools-manager.code.js.map +1 -0
- package/dist/utils/tools-manager.impl.js +36 -0
- package/dist/utils/tools-manager.impl.js.map +1 -0
- package/dist/utils/tools-manager.js +35 -2
- package/dist/utils/windows-cwd.js +585 -0
- package/dist/utils/windows-cwd.js.map +1 -0
- package/docs/extensions.md +1 -1
- package/docs/getting-started/installation.md +2 -0
- package/docs/intercom/operations.md +1 -0
- package/docs/reference/cli.md +2 -2
- package/package.json +24 -24
- package/dist/_shared/mode-shared-HP7GUA7J.js.map +0 -1
- package/dist/_shared/p1a-prewarm-YK3KDTLN.js.map +0 -1
- package/dist/_shared/p1b-elig-PXQA2FYP.js.map +0 -1
- package/dist/_shared/startup-0-0-X4NF3GKM.js.map +0 -1
- package/dist/_shared/startup-0-1-7QTG6VJZ.js.map +0 -1
- package/dist/_shared/startup-0-2-KFDYPDJK.js.map +0 -1
- package/dist/_shared/startup-8-1-KQJBDKRU.js.map +0 -1
|
@@ -0,0 +1,1530 @@
|
|
|
1
|
+
import { __toESM } from "../../_shared/rolldown-runtime-BGM3D5V3.js";
|
|
2
|
+
import { getAgentDir } from "../../_shared/p0-cli-BB45ZQY6.js";
|
|
3
|
+
import { isReadableUrlPath, repairCollapsedScheme } from "../../_shared/startup-0-0-TYUFUOJZ.js";
|
|
4
|
+
import { sessionScratchDir } from "../../_shared/startup-0-1-D4LGGINF.js";
|
|
5
|
+
import { findAsciiCaseInsensitive, isAsciiWordCode } from "../../_shared/p1b-elig-ENCUPKKJ.js";
|
|
6
|
+
import { applyReadLineSelection, decodeReadableUrl, extractDocumentMarkdown, getArtifactManager, isDocumentPath } from "../../_shared/startup-8-1-SJW2GMAM.js";
|
|
7
|
+
import { require_undici } from "../../_shared/http-undici-FVPTZA4G.js";
|
|
8
|
+
import { require_turndown_cjs } from "../../_shared/turndown.cjs-7Z43JOED.js";
|
|
9
|
+
import { resolve } from "node:path";
|
|
10
|
+
import { isIP } from "node:net";
|
|
11
|
+
import { channel, tracingChannel } from "node:diagnostics_channel";
|
|
12
|
+
import { lookup } from "node:dns/promises";
|
|
13
|
+
// ../../node_modules/lru-cache/dist/esm/node/index.min.js
|
|
14
|
+
var S = channel("lru-cache:metrics");
|
|
15
|
+
var W = tracingChannel("lru-cache");
|
|
16
|
+
var L = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date;
|
|
17
|
+
var R = () => S.hasSubscribers || W.hasSubscribers;
|
|
18
|
+
var U = /* @__PURE__ */ new Set();
|
|
19
|
+
var M = typeof process == "object" && process ? process : {};
|
|
20
|
+
var k = (d, e, t, i) => {
|
|
21
|
+
typeof M.emitWarning == "function" ? M.emitWarning(d, e, t, i) : console.error(`[${t}] ${e}: ${d}`);
|
|
22
|
+
};
|
|
23
|
+
var H = (d) => !U.has(d);
|
|
24
|
+
var T = (d) => !!d && d === Math.floor(d) && d > 0 && isFinite(d);
|
|
25
|
+
var j = (d) => T(d) ? d <= Math.pow(2, 8) ? Uint8Array : d <= Math.pow(2, 16) ? Uint16Array : d <= Math.pow(2, 32) ? Uint32Array : d <= Number.MAX_SAFE_INTEGER ? O : null : null;
|
|
26
|
+
var O = class extends Array {
|
|
27
|
+
constructor(e) {
|
|
28
|
+
super(e), this.fill(0);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var x = class d {
|
|
32
|
+
heap;
|
|
33
|
+
length;
|
|
34
|
+
static #o = !1;
|
|
35
|
+
static create(e) {
|
|
36
|
+
let t = j(e);
|
|
37
|
+
if (!t) return [];
|
|
38
|
+
d.#o = !0;
|
|
39
|
+
let i = new d(e, t);
|
|
40
|
+
return d.#o = !1, i;
|
|
41
|
+
}
|
|
42
|
+
constructor(e, t) {
|
|
43
|
+
if (!d.#o) throw new TypeError("instantiate Stack using Stack.create(n)");
|
|
44
|
+
this.heap = new t(e), this.length = 0;
|
|
45
|
+
}
|
|
46
|
+
push(e) {
|
|
47
|
+
this.heap[this.length++] = e;
|
|
48
|
+
}
|
|
49
|
+
pop() {
|
|
50
|
+
return this.heap[--this.length];
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var I = class d {
|
|
54
|
+
#o;
|
|
55
|
+
#c;
|
|
56
|
+
#S;
|
|
57
|
+
#O;
|
|
58
|
+
#w;
|
|
59
|
+
#M;
|
|
60
|
+
#I;
|
|
61
|
+
#m;
|
|
62
|
+
get perf() {
|
|
63
|
+
return this.#m;
|
|
64
|
+
}
|
|
65
|
+
ttl;
|
|
66
|
+
ttlResolution;
|
|
67
|
+
ttlAutopurge;
|
|
68
|
+
updateAgeOnGet;
|
|
69
|
+
updateAgeOnHas;
|
|
70
|
+
allowStale;
|
|
71
|
+
noDisposeOnSet;
|
|
72
|
+
noUpdateTTL;
|
|
73
|
+
maxEntrySize;
|
|
74
|
+
sizeCalculation;
|
|
75
|
+
noDeleteOnFetchRejection;
|
|
76
|
+
noDeleteOnStaleGet;
|
|
77
|
+
allowStaleOnFetchAbort;
|
|
78
|
+
allowStaleOnFetchRejection;
|
|
79
|
+
ignoreFetchAbort;
|
|
80
|
+
backgroundFetchSize;
|
|
81
|
+
#n;
|
|
82
|
+
#b;
|
|
83
|
+
#s;
|
|
84
|
+
#i;
|
|
85
|
+
#t;
|
|
86
|
+
#l;
|
|
87
|
+
#u;
|
|
88
|
+
#a;
|
|
89
|
+
#h;
|
|
90
|
+
#y;
|
|
91
|
+
#r;
|
|
92
|
+
#_;
|
|
93
|
+
#F;
|
|
94
|
+
#d;
|
|
95
|
+
#g;
|
|
96
|
+
#T;
|
|
97
|
+
#U;
|
|
98
|
+
#f;
|
|
99
|
+
#D;
|
|
100
|
+
static unsafeExposeInternals(e) {
|
|
101
|
+
return {
|
|
102
|
+
starts: e.#F,
|
|
103
|
+
ttls: e.#d,
|
|
104
|
+
autopurgeTimers: e.#g,
|
|
105
|
+
sizes: e.#_,
|
|
106
|
+
keyMap: e.#s,
|
|
107
|
+
keyList: e.#i,
|
|
108
|
+
valList: e.#t,
|
|
109
|
+
next: e.#l,
|
|
110
|
+
prev: e.#u,
|
|
111
|
+
get head() {
|
|
112
|
+
return e.#a;
|
|
113
|
+
},
|
|
114
|
+
get tail() {
|
|
115
|
+
return e.#h;
|
|
116
|
+
},
|
|
117
|
+
free: e.#y,
|
|
118
|
+
isBackgroundFetch: (t) => e.#e(t),
|
|
119
|
+
backgroundFetch: (t, i, s, n) => e.#P(t, i, s, n),
|
|
120
|
+
moveToTail: (t) => e.#L(t),
|
|
121
|
+
indexes: (t) => e.#A(t),
|
|
122
|
+
rindexes: (t) => e.#z(t),
|
|
123
|
+
isStale: (t) => e.#p(t)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
get max() {
|
|
127
|
+
return this.#o;
|
|
128
|
+
}
|
|
129
|
+
get maxSize() {
|
|
130
|
+
return this.#c;
|
|
131
|
+
}
|
|
132
|
+
get calculatedSize() {
|
|
133
|
+
return this.#b;
|
|
134
|
+
}
|
|
135
|
+
get size() {
|
|
136
|
+
return this.#n;
|
|
137
|
+
}
|
|
138
|
+
get fetchMethod() {
|
|
139
|
+
return this.#M;
|
|
140
|
+
}
|
|
141
|
+
get memoMethod() {
|
|
142
|
+
return this.#I;
|
|
143
|
+
}
|
|
144
|
+
get dispose() {
|
|
145
|
+
return this.#S;
|
|
146
|
+
}
|
|
147
|
+
get onInsert() {
|
|
148
|
+
return this.#O;
|
|
149
|
+
}
|
|
150
|
+
get disposeAfter() {
|
|
151
|
+
return this.#w;
|
|
152
|
+
}
|
|
153
|
+
constructor(e) {
|
|
154
|
+
let { max: t = 0, ttl: i, ttlResolution: s = 1, ttlAutopurge: n, updateAgeOnGet: o, updateAgeOnHas: l, allowStale: h, dispose: r, onInsert: c, disposeAfter: m, noDisposeOnSet: _, noUpdateTTL: u, maxSize: g = 0, maxEntrySize: f = 0, sizeCalculation: y, fetchMethod: a, memoMethod: w, noDeleteOnFetchRejection: F, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: p, allowStaleOnFetchAbort: A, ignoreFetchAbort: z, backgroundFetchSize: C = 1, perf: E } = e;
|
|
155
|
+
if (this.backgroundFetchSize = C, E !== void 0 && typeof E?.now != "function") throw new TypeError("perf option must have a now() method if specified");
|
|
156
|
+
if (this.#m = E ?? L, t !== 0 && !T(t)) throw new TypeError("max option must be a nonnegative integer");
|
|
157
|
+
let v = t ? j(t) : Array;
|
|
158
|
+
if (!v) throw new Error("invalid max value: " + t);
|
|
159
|
+
if (this.#o = t, this.#c = g, this.maxEntrySize = f || this.#c, this.sizeCalculation = y, this.sizeCalculation) {
|
|
160
|
+
if (!this.#c && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
161
|
+
if (typeof this.sizeCalculation != "function") throw new TypeError("sizeCalculation set to non-function");
|
|
162
|
+
}
|
|
163
|
+
if (w !== void 0 && typeof w != "function") throw new TypeError("memoMethod must be a function if defined");
|
|
164
|
+
if (this.#I = w, a !== void 0 && typeof a != "function") throw new TypeError("fetchMethod must be a function if specified");
|
|
165
|
+
if (this.#M = a, this.#U = !!a, this.#s = /* @__PURE__ */ new Map(), this.#i = Array.from({ length: t }).fill(void 0), this.#t = Array.from({ length: t }).fill(void 0), this.#l = new v(t), this.#u = new v(t), this.#a = 0, this.#h = 0, this.#y = x.create(t), this.#n = 0, this.#b = 0, typeof r == "function" && (this.#S = r), typeof c == "function" && (this.#O = c), typeof m == "function" ? (this.#w = m, this.#r = []) : (this.#w = void 0, this.#r = void 0), this.#T = !!this.#S, this.#D = !!this.#O, this.#f = !!this.#w, this.noDisposeOnSet = !!_, this.noUpdateTTL = !!u, this.noDeleteOnFetchRejection = !!F, this.allowStaleOnFetchRejection = !!p, this.allowStaleOnFetchAbort = !!A, this.ignoreFetchAbort = !!z, this.maxEntrySize !== 0) {
|
|
166
|
+
if (this.#c !== 0 && !T(this.#c)) throw new TypeError("maxSize must be a positive integer if specified");
|
|
167
|
+
if (!T(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
|
|
168
|
+
this.#X();
|
|
169
|
+
}
|
|
170
|
+
if (this.allowStale = !!h, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!l, this.ttlResolution = T(s) || s === 0 ? s : 1, this.ttlAutopurge = !!n, this.ttl = i || 0, this.ttl) {
|
|
171
|
+
if (!T(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
|
|
172
|
+
this.#k();
|
|
173
|
+
}
|
|
174
|
+
if (this.#o === 0 && this.ttl === 0 && this.#c === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
175
|
+
if (!this.ttlAutopurge && !this.#o && !this.#c) {
|
|
176
|
+
let D = "LRU_CACHE_UNBOUNDED";
|
|
177
|
+
H(D) && (U.add(D), k("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", D, d));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
getRemainingTTL(e) {
|
|
181
|
+
return this.#s.has(e) ? 1 / 0 : 0;
|
|
182
|
+
}
|
|
183
|
+
#k() {
|
|
184
|
+
let e = new O(this.#o);
|
|
185
|
+
let t = new O(this.#o);
|
|
186
|
+
this.#d = e, this.#F = t;
|
|
187
|
+
let i = this.ttlAutopurge ? Array.from({ length: this.#o }) : void 0;
|
|
188
|
+
this.#g = i, this.#H = (h, r, c = this.#m.now()) => {
|
|
189
|
+
t[h] = r !== 0 ? c : 0, e[h] = r, s(h, r);
|
|
190
|
+
}, this.#R = (h) => {
|
|
191
|
+
t[h] = e[h] !== 0 ? this.#m.now() : 0, s(h, e[h]);
|
|
192
|
+
};
|
|
193
|
+
let s = this.ttlAutopurge ? (h, r) => {
|
|
194
|
+
if (i?.[h] && (clearTimeout(i[h]), i[h] = void 0), r && r !== 0 && i) {
|
|
195
|
+
let c = setTimeout(() => {
|
|
196
|
+
this.#p(h) ? (this.#E(this.#i[h], "expire"), i[h] = void 0) : s(h, l(h));
|
|
197
|
+
}, r + 1);
|
|
198
|
+
c.unref && c.unref(), i[h] = c;
|
|
199
|
+
}
|
|
200
|
+
} : () => {};
|
|
201
|
+
this.#v = (h, r) => {
|
|
202
|
+
if (e[r]) {
|
|
203
|
+
let c = e[r];
|
|
204
|
+
let m = t[r];
|
|
205
|
+
if (!c || !m) return;
|
|
206
|
+
h.ttl = c, h.start = m, h.now = n || o();
|
|
207
|
+
h.remainingTTL = c - (h.now - m);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
let n = 0;
|
|
211
|
+
let o = () => {
|
|
212
|
+
let h = this.#m.now();
|
|
213
|
+
if (this.ttlResolution > 0) {
|
|
214
|
+
n = h;
|
|
215
|
+
let r = setTimeout(() => n = 0, this.ttlResolution);
|
|
216
|
+
r.unref && r.unref();
|
|
217
|
+
}
|
|
218
|
+
return h;
|
|
219
|
+
};
|
|
220
|
+
this.getRemainingTTL = (h) => {
|
|
221
|
+
let r = this.#s.get(h);
|
|
222
|
+
return r === void 0 ? 0 : l(r);
|
|
223
|
+
};
|
|
224
|
+
let l = (h) => {
|
|
225
|
+
let r = e[h];
|
|
226
|
+
let c = t[h];
|
|
227
|
+
if (!r || !c) return 1 / 0;
|
|
228
|
+
return r - ((n || o()) - c);
|
|
229
|
+
};
|
|
230
|
+
this.#p = (h) => {
|
|
231
|
+
let r = t[h];
|
|
232
|
+
let c = e[h];
|
|
233
|
+
return !!c && !!r && (n || o()) - r > c;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
#R = () => {};
|
|
237
|
+
#v = () => {};
|
|
238
|
+
#H = () => {};
|
|
239
|
+
#p = () => !1;
|
|
240
|
+
#X() {
|
|
241
|
+
let e = new O(this.#o);
|
|
242
|
+
this.#b = 0, this.#_ = e, this.#x = (t) => {
|
|
243
|
+
this.#b -= e[t], e[t] = 0;
|
|
244
|
+
}, this.#N = (t, i, s, n) => {
|
|
245
|
+
if (!T(s)) {
|
|
246
|
+
if (this.#e(i)) return this.backgroundFetchSize;
|
|
247
|
+
if (n) {
|
|
248
|
+
if (typeof n != "function") throw new TypeError("sizeCalculation must be a function");
|
|
249
|
+
if (s = n(i, t), !T(s)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
250
|
+
} else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
251
|
+
}
|
|
252
|
+
return s;
|
|
253
|
+
}, this.#j = (t, i, s) => {
|
|
254
|
+
if (e[t] = i, this.#c) {
|
|
255
|
+
let n = this.#c - e[t];
|
|
256
|
+
for (; this.#b > n;) this.#G(!0);
|
|
257
|
+
}
|
|
258
|
+
this.#b += e[t], s && (s.entrySize = i, s.totalCalculatedSize = this.#b);
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
#x = (e) => {};
|
|
262
|
+
#j = (e, t, i) => {};
|
|
263
|
+
#N = (e, t, i, s) => {
|
|
264
|
+
if (i || s) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
265
|
+
return 0;
|
|
266
|
+
};
|
|
267
|
+
*#A({ allowStale: e = this.allowStale } = {}) {
|
|
268
|
+
if (this.#n) for (let t = this.#h; this.#V(t) && ((e || !this.#p(t)) && (yield t), t !== this.#a);) t = this.#u[t];
|
|
269
|
+
}
|
|
270
|
+
*#z({ allowStale: e = this.allowStale } = {}) {
|
|
271
|
+
if (this.#n) for (let t = this.#a; this.#V(t) && ((e || !this.#p(t)) && (yield t), t !== this.#h);) t = this.#l[t];
|
|
272
|
+
}
|
|
273
|
+
#V(e) {
|
|
274
|
+
return e !== void 0 && this.#s.get(this.#i[e]) === e;
|
|
275
|
+
}
|
|
276
|
+
*entries() {
|
|
277
|
+
for (let e of this.#A()) this.#t[e] !== void 0 && this.#i[e] !== void 0 && !this.#e(this.#t[e]) && (yield [this.#i[e], this.#t[e]]);
|
|
278
|
+
}
|
|
279
|
+
*rentries() {
|
|
280
|
+
for (let e of this.#z()) this.#t[e] !== void 0 && this.#i[e] !== void 0 && !this.#e(this.#t[e]) && (yield [this.#i[e], this.#t[e]]);
|
|
281
|
+
}
|
|
282
|
+
*keys() {
|
|
283
|
+
for (let e of this.#A()) {
|
|
284
|
+
let t = this.#i[e];
|
|
285
|
+
t !== void 0 && !this.#e(this.#t[e]) && (yield t);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
*rkeys() {
|
|
289
|
+
for (let e of this.#z()) {
|
|
290
|
+
let t = this.#i[e];
|
|
291
|
+
t !== void 0 && !this.#e(this.#t[e]) && (yield t);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
*values() {
|
|
295
|
+
for (let e of this.#A()) this.#t[e] !== void 0 && !this.#e(this.#t[e]) && (yield this.#t[e]);
|
|
296
|
+
}
|
|
297
|
+
*rvalues() {
|
|
298
|
+
for (let e of this.#z()) this.#t[e] !== void 0 && !this.#e(this.#t[e]) && (yield this.#t[e]);
|
|
299
|
+
}
|
|
300
|
+
[Symbol.iterator]() {
|
|
301
|
+
return this.entries();
|
|
302
|
+
}
|
|
303
|
+
[Symbol.toStringTag] = "LRUCache";
|
|
304
|
+
find(e, t = {}) {
|
|
305
|
+
for (let i of this.#A()) {
|
|
306
|
+
let s = this.#t[i];
|
|
307
|
+
let n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
308
|
+
if (n !== void 0 && e(n, this.#i[i], this)) return this.#C(this.#i[i], t);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
forEach(e, t = this) {
|
|
312
|
+
for (let i of this.#A()) {
|
|
313
|
+
let s = this.#t[i];
|
|
314
|
+
let n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
315
|
+
n !== void 0 && e.call(t, n, this.#i[i], this);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
rforEach(e, t = this) {
|
|
319
|
+
for (let i of this.#z()) {
|
|
320
|
+
let s = this.#t[i];
|
|
321
|
+
let n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
322
|
+
n !== void 0 && e.call(t, n, this.#i[i], this);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
purgeStale() {
|
|
326
|
+
let e = !1;
|
|
327
|
+
for (let t of this.#z({ allowStale: !0 })) this.#p(t) && (this.#E(this.#i[t], "expire"), e = !0);
|
|
328
|
+
return e;
|
|
329
|
+
}
|
|
330
|
+
info(e) {
|
|
331
|
+
let t = this.#s.get(e);
|
|
332
|
+
if (t === void 0) return;
|
|
333
|
+
let i = this.#t[t];
|
|
334
|
+
let s = this.#e(i) ? i.__staleWhileFetching : i;
|
|
335
|
+
if (s === void 0) return;
|
|
336
|
+
let n = { value: s };
|
|
337
|
+
if (this.#d && this.#F) {
|
|
338
|
+
let o = this.#d[t];
|
|
339
|
+
let l = this.#F[t];
|
|
340
|
+
if (o && l) n.ttl = o - (this.#m.now() - l), n.start = Date.now();
|
|
341
|
+
}
|
|
342
|
+
return this.#_ && (n.size = this.#_[t]), n;
|
|
343
|
+
}
|
|
344
|
+
dump() {
|
|
345
|
+
let e = [];
|
|
346
|
+
for (let t of this.#A({ allowStale: !0 })) {
|
|
347
|
+
let i = this.#i[t];
|
|
348
|
+
let s = this.#t[t];
|
|
349
|
+
let n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
350
|
+
if (n === void 0 || i === void 0) continue;
|
|
351
|
+
let o = { value: n };
|
|
352
|
+
if (this.#d && this.#F) {
|
|
353
|
+
o.ttl = this.#d[t];
|
|
354
|
+
let l = this.#m.now() - this.#F[t];
|
|
355
|
+
o.start = Math.floor(Date.now() - l);
|
|
356
|
+
}
|
|
357
|
+
this.#_ && (o.size = this.#_[t]), e.unshift([i, o]);
|
|
358
|
+
}
|
|
359
|
+
return e;
|
|
360
|
+
}
|
|
361
|
+
load(e) {
|
|
362
|
+
this.clear();
|
|
363
|
+
for (let [t, i] of e) {
|
|
364
|
+
if (i.start) {
|
|
365
|
+
let s = Date.now() - i.start;
|
|
366
|
+
i.start = this.#m.now() - s;
|
|
367
|
+
}
|
|
368
|
+
this.#W(t, i.value, i);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
set(e, t, i = {}) {
|
|
372
|
+
let { status: s = S.hasSubscribers ? {} : void 0 } = i;
|
|
373
|
+
i.status = s, s && (s.op = "set", s.key = e, t !== void 0 && (s.value = t), s.cache = this);
|
|
374
|
+
let n = this.#W(e, t, i);
|
|
375
|
+
return s && S.hasSubscribers && S.publish(s), n;
|
|
376
|
+
}
|
|
377
|
+
#W(e, t, i, s) {
|
|
378
|
+
let { ttl: n = this.ttl, start: o, noDisposeOnSet: l = this.noDisposeOnSet, sizeCalculation: h = this.sizeCalculation, status: r } = i, c = this.#e(t);
|
|
379
|
+
if (t === void 0) return r && (r.set = "deleted"), this.delete(e), this;
|
|
380
|
+
let { noUpdateTTL: m = this.noUpdateTTL } = i;
|
|
381
|
+
r && !c && (r.value = t);
|
|
382
|
+
let _ = this.#N(e, t, i.size || 0, h, r);
|
|
383
|
+
if (this.maxEntrySize && _ > this.maxEntrySize) return this.#E(e, "set"), r && (r.set = "miss", r.maxEntrySizeExceeded = !0), this;
|
|
384
|
+
let u = this.#n === 0 ? void 0 : this.#s.get(e);
|
|
385
|
+
if (u === void 0) u = this.#n === 0 ? this.#h : this.#y.length !== 0 ? this.#y.pop() : this.#n === this.#o ? this.#G(!1) : this.#n, this.#i[u] = e, this.#t[u] = t, this.#s.set(e, u), this.#l[this.#h] = u, this.#u[u] = this.#h, this.#h = u, this.#n++, this.#j(u, _, r), r && (r.set = "add"), m = !1, this.#D && !c && this.#O?.(t, e, "add");
|
|
386
|
+
else {
|
|
387
|
+
this.#L(u);
|
|
388
|
+
let g = this.#t[u];
|
|
389
|
+
if (t !== g) {
|
|
390
|
+
if (!l) if (this.#e(g)) {
|
|
391
|
+
g !== s && g.__abortController.abort(/* @__PURE__ */ new Error("replaced"));
|
|
392
|
+
let { __staleWhileFetching: f } = g;
|
|
393
|
+
f !== void 0 && f !== t && (this.#T && this.#S?.(f, e, "set"), this.#f && this.#r?.push([
|
|
394
|
+
f,
|
|
395
|
+
e,
|
|
396
|
+
"set"
|
|
397
|
+
]));
|
|
398
|
+
} else this.#T && this.#S?.(g, e, "set"), this.#f && this.#r?.push([
|
|
399
|
+
g,
|
|
400
|
+
e,
|
|
401
|
+
"set"
|
|
402
|
+
]);
|
|
403
|
+
if (this.#x(u), this.#j(u, _, r), this.#t[u] = t, !c) {
|
|
404
|
+
let f = g && this.#e(g) ? g.__staleWhileFetching : g;
|
|
405
|
+
let y = f === void 0 ? "add" : t !== f ? "replace" : "update";
|
|
406
|
+
r && (r.set = y, f !== void 0 && (r.oldValue = f)), this.#D && this.onInsert?.(t, e, y);
|
|
407
|
+
}
|
|
408
|
+
} else c || (r && (r.set = "update"), this.#D && this.onInsert?.(t, e, "update"));
|
|
409
|
+
}
|
|
410
|
+
if (n !== 0 && !this.#d && this.#k(), this.#d && (m || this.#H(u, n, o), r && this.#v(r, u)), !l && this.#f && this.#r) {
|
|
411
|
+
let g = this.#r;
|
|
412
|
+
let f;
|
|
413
|
+
for (; f = g?.shift();) this.#w?.(...f);
|
|
414
|
+
}
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
pop() {
|
|
418
|
+
try {
|
|
419
|
+
for (; this.#n;) {
|
|
420
|
+
let e = this.#t[this.#a];
|
|
421
|
+
if (this.#G(!0), this.#e(e)) {
|
|
422
|
+
if (e.__staleWhileFetching) return e.__staleWhileFetching;
|
|
423
|
+
} else if (e !== void 0) return e;
|
|
424
|
+
}
|
|
425
|
+
} finally {
|
|
426
|
+
if (this.#f && this.#r) {
|
|
427
|
+
let e = this.#r;
|
|
428
|
+
let t;
|
|
429
|
+
for (; t = e?.shift();) this.#w?.(...t);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
#G(e) {
|
|
434
|
+
let t = this.#a;
|
|
435
|
+
let i = this.#i[t];
|
|
436
|
+
let s = this.#t[t];
|
|
437
|
+
let n = this.#e(s);
|
|
438
|
+
n && s.__abortController.abort(/* @__PURE__ */ new Error("evicted"));
|
|
439
|
+
let o = n ? s.__staleWhileFetching : s;
|
|
440
|
+
return (this.#T || this.#f) && o !== void 0 && (this.#T && this.#S?.(o, i, "evict"), this.#f && this.#r?.push([
|
|
441
|
+
o,
|
|
442
|
+
i,
|
|
443
|
+
"evict"
|
|
444
|
+
])), this.#x(t), this.#g?.[t] && (clearTimeout(this.#g[t]), this.#g[t] = void 0), e && (this.#i[t] = void 0, this.#t[t] = void 0, this.#y.push(t)), this.#n === 1 ? (this.#a = this.#h = 0, this.#y.length = 0) : this.#a = this.#l[t], this.#s.delete(i), this.#n--, t;
|
|
445
|
+
}
|
|
446
|
+
has(e, t = {}) {
|
|
447
|
+
let { status: i = S.hasSubscribers ? {} : void 0 } = t;
|
|
448
|
+
t.status = i, i && (i.op = "has", i.key = e, i.cache = this);
|
|
449
|
+
let s = this.#Y(e, t);
|
|
450
|
+
return S.hasSubscribers && S.publish(i), s;
|
|
451
|
+
}
|
|
452
|
+
#Y(e, t = {}) {
|
|
453
|
+
let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } = t, n = this.#s.get(e);
|
|
454
|
+
if (n !== void 0) {
|
|
455
|
+
let o = this.#t[n];
|
|
456
|
+
if (this.#e(o) && o.__staleWhileFetching === void 0) return !1;
|
|
457
|
+
if (this.#p(n)) s && (s.has = "stale", this.#v(s, n));
|
|
458
|
+
else return i && this.#R(n), s && (s.has = "hit", this.#v(s, n)), !0;
|
|
459
|
+
} else s && (s.has = "miss");
|
|
460
|
+
return !1;
|
|
461
|
+
}
|
|
462
|
+
peek(e, t = {}) {
|
|
463
|
+
let { status: i = R() ? {} : void 0 } = t;
|
|
464
|
+
i && (i.op = "peek", i.key = e, i.cache = this), t.status = i;
|
|
465
|
+
let s = this.#J(e, t);
|
|
466
|
+
return S.hasSubscribers && S.publish(i), s;
|
|
467
|
+
}
|
|
468
|
+
#J(e, t) {
|
|
469
|
+
let { status: i, allowStale: s = this.allowStale } = t, n = this.#s.get(e);
|
|
470
|
+
if (n === void 0 || !s && this.#p(n)) {
|
|
471
|
+
i && (i.peek = n === void 0 ? "miss" : "stale");
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
let o = this.#t[n];
|
|
475
|
+
let l = this.#e(o) ? o.__staleWhileFetching : o;
|
|
476
|
+
return i && (l !== void 0 ? (i.peek = "hit", i.value = l) : i.peek = "miss"), l;
|
|
477
|
+
}
|
|
478
|
+
#P(e, t, i, s) {
|
|
479
|
+
let n = t === void 0 ? void 0 : this.#t[t];
|
|
480
|
+
if (this.#e(n)) return n;
|
|
481
|
+
let o = new AbortController(), { signal: l } = i;
|
|
482
|
+
l?.addEventListener("abort", () => o.abort(l.reason), { signal: o.signal });
|
|
483
|
+
let h = {
|
|
484
|
+
signal: o.signal,
|
|
485
|
+
options: i,
|
|
486
|
+
context: s
|
|
487
|
+
};
|
|
488
|
+
let r = (f, y = !1) => {
|
|
489
|
+
let { aborted: a } = o.signal, w = i.ignoreFetchAbort && f !== void 0, F = i.ignoreFetchAbort || !!(i.allowStaleOnFetchAbort && f !== void 0);
|
|
490
|
+
if (i.status && (a && !y ? (i.status.fetchAborted = !0, i.status.fetchError = o.signal.reason, w && (i.status.fetchAbortIgnored = !0)) : i.status.fetchResolved = !0), a && !w && !y) return m(o.signal.reason, F);
|
|
491
|
+
let b = u;
|
|
492
|
+
let p = this.#t[t];
|
|
493
|
+
return (p === u || p === void 0 && w && y) && (f === void 0 ? b.__staleWhileFetching !== void 0 ? this.#t[t] = b.__staleWhileFetching : this.#E(e, "fetch") : (i.status && (i.status.fetchUpdated = !0), this.#W(e, f, h.options, b))), f;
|
|
494
|
+
};
|
|
495
|
+
let c = (f) => (i.status && (i.status.fetchRejected = !0, i.status.fetchError = f), m(f, !1));
|
|
496
|
+
let m = (f, y) => {
|
|
497
|
+
let { aborted: a } = o.signal, w = a && i.allowStaleOnFetchAbort, F = w || i.allowStaleOnFetchRejection, b = F || i.noDeleteOnFetchRejection, p = u;
|
|
498
|
+
if (this.#t[t] === u && (!b || !y && p.__staleWhileFetching === void 0 ? this.#E(e, "fetch") : w || (this.#t[t] = p.__staleWhileFetching)), F) return i.status && p.__staleWhileFetching !== void 0 && (i.status.returnedStale = !0), p.__staleWhileFetching;
|
|
499
|
+
if (p.__returned === p) throw f;
|
|
500
|
+
};
|
|
501
|
+
let _ = (f, y) => {
|
|
502
|
+
let a = this.#M?.(e, n, h);
|
|
503
|
+
o.signal.addEventListener("abort", () => {
|
|
504
|
+
(!i.ignoreFetchAbort || i.allowStaleOnFetchAbort) && (f(void 0), i.allowStaleOnFetchAbort && (f = (w) => r(w, !0)));
|
|
505
|
+
}), a && a instanceof Promise ? a.then((w) => f(w === void 0 ? void 0 : w), y) : a !== void 0 && f(a);
|
|
506
|
+
};
|
|
507
|
+
i.status && (i.status.fetchDispatched = !0);
|
|
508
|
+
let u = new Promise(_).then(r, c);
|
|
509
|
+
let g = Object.assign(u, {
|
|
510
|
+
__abortController: o,
|
|
511
|
+
__staleWhileFetching: n,
|
|
512
|
+
__returned: void 0
|
|
513
|
+
});
|
|
514
|
+
return t === void 0 ? (this.#W(e, g, {
|
|
515
|
+
...h.options,
|
|
516
|
+
status: void 0
|
|
517
|
+
}), t = this.#s.get(e)) : this.#t[t] = g, g;
|
|
518
|
+
}
|
|
519
|
+
#e(e) {
|
|
520
|
+
if (!this.#U) return !1;
|
|
521
|
+
let t = e;
|
|
522
|
+
return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
|
|
523
|
+
}
|
|
524
|
+
fetch(e, t = {}) {
|
|
525
|
+
let i = W.hasSubscribers, { status: s = R() ? {} : void 0 } = t;
|
|
526
|
+
t.status = s, s && t.context && (s.context = t.context);
|
|
527
|
+
let n = this.#B(e, t);
|
|
528
|
+
return s && i && (s.trace = !0, W.tracePromise(() => n, s).catch(() => {})), n;
|
|
529
|
+
}
|
|
530
|
+
async #B(e, t = {}) {
|
|
531
|
+
let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: l = this.noDisposeOnSet, size: h = 0, sizeCalculation: r = this.sizeCalculation, noUpdateTTL: c = this.noUpdateTTL, noDeleteOnFetchRejection: m = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: _ = this.allowStaleOnFetchRejection, ignoreFetchAbort: u = this.ignoreFetchAbort, allowStaleOnFetchAbort: g = this.allowStaleOnFetchAbort, context: f, forceRefresh: y = !1, status: a, signal: w } = t;
|
|
532
|
+
if (a && (a.op = "fetch", a.key = e, y && (a.forceRefresh = !0), a.cache = this), !this.#U) return a && (a.fetch = "get"), this.#C(e, {
|
|
533
|
+
allowStale: i,
|
|
534
|
+
updateAgeOnGet: s,
|
|
535
|
+
noDeleteOnStaleGet: n,
|
|
536
|
+
status: a
|
|
537
|
+
});
|
|
538
|
+
let F = {
|
|
539
|
+
allowStale: i,
|
|
540
|
+
updateAgeOnGet: s,
|
|
541
|
+
noDeleteOnStaleGet: n,
|
|
542
|
+
ttl: o,
|
|
543
|
+
noDisposeOnSet: l,
|
|
544
|
+
size: h,
|
|
545
|
+
sizeCalculation: r,
|
|
546
|
+
noUpdateTTL: c,
|
|
547
|
+
noDeleteOnFetchRejection: m,
|
|
548
|
+
allowStaleOnFetchRejection: _,
|
|
549
|
+
allowStaleOnFetchAbort: g,
|
|
550
|
+
ignoreFetchAbort: u,
|
|
551
|
+
status: a,
|
|
552
|
+
signal: w
|
|
553
|
+
};
|
|
554
|
+
let b = this.#s.get(e);
|
|
555
|
+
if (b === void 0) {
|
|
556
|
+
a && (a.fetch = "miss");
|
|
557
|
+
let p = this.#P(e, b, F, f);
|
|
558
|
+
return p.__returned = p;
|
|
559
|
+
} else {
|
|
560
|
+
let p = this.#t[b];
|
|
561
|
+
if (this.#e(p)) {
|
|
562
|
+
let v = i && p.__staleWhileFetching !== void 0;
|
|
563
|
+
return a && (a.fetch = "inflight", v && (a.returnedStale = !0)), v ? p.__staleWhileFetching : p.__returned = p;
|
|
564
|
+
}
|
|
565
|
+
let A = this.#p(b);
|
|
566
|
+
if (!y && !A) return a && (a.fetch = "hit"), this.#L(b), s && this.#R(b), a && this.#v(a, b), p;
|
|
567
|
+
let z = this.#P(e, b, F, f);
|
|
568
|
+
let E = z.__staleWhileFetching !== void 0 && i;
|
|
569
|
+
return a && (a.fetch = A ? "stale" : "refresh", E && A && (a.returnedStale = !0)), E ? z.__staleWhileFetching : z.__returned = z;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
forceFetch(e, t = {}) {
|
|
573
|
+
let i = W.hasSubscribers, { status: s = R() ? {} : void 0 } = t;
|
|
574
|
+
t.status = s, s && t.context && (s.context = t.context);
|
|
575
|
+
let n = this.#K(e, t);
|
|
576
|
+
return s && i && (s.trace = !0, W.tracePromise(() => n, s).catch(() => {})), n;
|
|
577
|
+
}
|
|
578
|
+
async #K(e, t = {}) {
|
|
579
|
+
let i = await this.#B(e, t);
|
|
580
|
+
if (i === void 0) throw new Error("fetch() returned undefined");
|
|
581
|
+
return i;
|
|
582
|
+
}
|
|
583
|
+
memo(e, t = {}) {
|
|
584
|
+
let { status: i = S.hasSubscribers ? {} : void 0 } = t;
|
|
585
|
+
t.status = i, i && (i.op = "memo", i.key = e, t.context && (i.context = t.context), i.cache = this);
|
|
586
|
+
let s = this.#Q(e, t);
|
|
587
|
+
return i && (i.value = s), S.hasSubscribers && S.publish(i), s;
|
|
588
|
+
}
|
|
589
|
+
#Q(e, t = {}) {
|
|
590
|
+
let i = this.#I;
|
|
591
|
+
if (!i) throw new Error("no memoMethod provided to constructor");
|
|
592
|
+
let { context: s, status: n, forceRefresh: o, ...l } = t;
|
|
593
|
+
n && o && (n.forceRefresh = !0);
|
|
594
|
+
let h = this.#C(e, l);
|
|
595
|
+
let r = o || h === void 0;
|
|
596
|
+
if (n && (n.memo = r ? "miss" : "hit", r || (n.value = h)), !r) return h;
|
|
597
|
+
let c = i(e, h, {
|
|
598
|
+
options: l,
|
|
599
|
+
context: s
|
|
600
|
+
});
|
|
601
|
+
return n && (n.value = c), this.#W(e, c, l), c;
|
|
602
|
+
}
|
|
603
|
+
get(e, t = {}) {
|
|
604
|
+
let { status: i = S.hasSubscribers ? {} : void 0 } = t;
|
|
605
|
+
t.status = i, i && (i.op = "get", i.key = e, i.cache = this);
|
|
606
|
+
let s = this.#C(e, t);
|
|
607
|
+
return i && (s !== void 0 && (i.value = s), S.hasSubscribers && S.publish(i)), s;
|
|
608
|
+
}
|
|
609
|
+
#C(e, t = {}) {
|
|
610
|
+
let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: o } = t, l = this.#s.get(e);
|
|
611
|
+
if (l === void 0) {
|
|
612
|
+
o && (o.get = "miss");
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
let h = this.#t[l];
|
|
616
|
+
let r = this.#e(h);
|
|
617
|
+
return o && this.#v(o, l), this.#p(l) ? r ? (o && (o.get = "stale-fetching"), i && h.__staleWhileFetching !== void 0 ? (o && (o.returnedStale = !0), h.__staleWhileFetching) : void 0) : (n || this.#E(e, "expire"), o && (o.get = "stale"), i ? (o && (o.returnedStale = !0), h) : void 0) : (o && (o.get = r ? "fetching" : "hit"), this.#L(l), s && this.#R(l), r ? h.__staleWhileFetching : h);
|
|
618
|
+
}
|
|
619
|
+
#$(e, t) {
|
|
620
|
+
this.#u[t] = e, this.#l[e] = t;
|
|
621
|
+
}
|
|
622
|
+
#L(e) {
|
|
623
|
+
e !== this.#h && (e === this.#a ? this.#a = this.#l[e] : this.#$(this.#u[e], this.#l[e]), this.#$(this.#h, e), this.#h = e);
|
|
624
|
+
}
|
|
625
|
+
delete(e) {
|
|
626
|
+
return this.#E(e, "delete");
|
|
627
|
+
}
|
|
628
|
+
#E(e, t) {
|
|
629
|
+
S.hasSubscribers && S.publish({
|
|
630
|
+
op: "delete",
|
|
631
|
+
delete: t,
|
|
632
|
+
key: e,
|
|
633
|
+
cache: this
|
|
634
|
+
});
|
|
635
|
+
let i = !1;
|
|
636
|
+
if (this.#n !== 0) {
|
|
637
|
+
let s = this.#s.get(e);
|
|
638
|
+
if (s !== void 0) if (this.#g?.[s] && (clearTimeout(this.#g[s]), this.#g[s] = void 0), i = !0, this.#n === 1) this.#q(t);
|
|
639
|
+
else {
|
|
640
|
+
this.#x(s);
|
|
641
|
+
let n = this.#t[s];
|
|
642
|
+
if (this.#e(n) ? n.__abortController.abort(/* @__PURE__ */ new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#S?.(n, e, t), this.#f && this.#r?.push([
|
|
643
|
+
n,
|
|
644
|
+
e,
|
|
645
|
+
t
|
|
646
|
+
])), this.#s.delete(e), this.#i[s] = void 0, this.#t[s] = void 0, s === this.#h) this.#h = this.#u[s];
|
|
647
|
+
else if (s === this.#a) this.#a = this.#l[s];
|
|
648
|
+
else {
|
|
649
|
+
let o = this.#u[s];
|
|
650
|
+
this.#l[o] = this.#l[s];
|
|
651
|
+
let l = this.#l[s];
|
|
652
|
+
this.#u[l] = this.#u[s];
|
|
653
|
+
}
|
|
654
|
+
this.#n--, this.#y.push(s);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (this.#f && this.#r?.length) {
|
|
658
|
+
let s = this.#r;
|
|
659
|
+
let n;
|
|
660
|
+
for (; n = s?.shift();) this.#w?.(...n);
|
|
661
|
+
}
|
|
662
|
+
return i;
|
|
663
|
+
}
|
|
664
|
+
clear() {
|
|
665
|
+
return this.#q("delete");
|
|
666
|
+
}
|
|
667
|
+
#q(e) {
|
|
668
|
+
for (let t of this.#z({ allowStale: !0 })) {
|
|
669
|
+
let i = this.#t[t];
|
|
670
|
+
if (this.#e(i)) i.__abortController.abort(/* @__PURE__ */ new Error("deleted"));
|
|
671
|
+
else {
|
|
672
|
+
let s = this.#i[t];
|
|
673
|
+
this.#T && this.#S?.(i, s, e), this.#f && this.#r?.push([
|
|
674
|
+
i,
|
|
675
|
+
s,
|
|
676
|
+
e
|
|
677
|
+
]);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (this.#s.clear(), this.#t.fill(void 0), this.#i.fill(void 0), this.#d && this.#F) {
|
|
681
|
+
this.#d.fill(0), this.#F.fill(0);
|
|
682
|
+
for (let t of this.#g ?? []) t !== void 0 && clearTimeout(t);
|
|
683
|
+
this.#g?.fill(void 0);
|
|
684
|
+
}
|
|
685
|
+
if (this.#_ && this.#_.fill(0), this.#a = 0, this.#h = 0, this.#y.length = 0, this.#b = 0, this.#n = 0, this.#f && this.#r) {
|
|
686
|
+
let t = this.#r;
|
|
687
|
+
let i;
|
|
688
|
+
for (; i = t?.shift();) this.#w?.(...i);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
// dist/core/tools/url-ip-guards.js
|
|
693
|
+
var import_undici = /* @__PURE__ */ __toESM(require_undici(), 1);
|
|
694
|
+
var import_turndown_cjs = /* @__PURE__ */ __toESM(require_turndown_cjs(), 1);
|
|
695
|
+
function parseIpv4Part(part) {
|
|
696
|
+
if (part === "") return void 0;
|
|
697
|
+
if (/^0x[0-9a-f]+$/i.test(part)) return BigInt(Number.parseInt(part.slice(2), 16));
|
|
698
|
+
if (/^0[0-7]+$/.test(part)) return BigInt(Number.parseInt(part, 8));
|
|
699
|
+
if (/^(?:0|[1-9]\d*)$/.test(part)) return BigInt(part);
|
|
700
|
+
}
|
|
701
|
+
function dottedQuadFromValue(value) {
|
|
702
|
+
if (value < 0n || value > 4294967295n) return void 0;
|
|
703
|
+
return [
|
|
704
|
+
24n,
|
|
705
|
+
16n,
|
|
706
|
+
8n,
|
|
707
|
+
0n
|
|
708
|
+
].map((shift) => Number(value >> shift & 255n)).join(".");
|
|
709
|
+
}
|
|
710
|
+
function canonicalNumericIpv4(hostname) {
|
|
711
|
+
if (!/^[0-9a-fx.]+$/i.test(hostname)) return void 0;
|
|
712
|
+
const parts = hostname.split(".");
|
|
713
|
+
if (parts.length < 1 || parts.length > 4) return void 0;
|
|
714
|
+
const nums = parts.map(parseIpv4Part);
|
|
715
|
+
if (nums.some((part) => part === void 0)) return void 0;
|
|
716
|
+
const values = nums;
|
|
717
|
+
if (values.length === 1) return dottedQuadFromValue(values[0]);
|
|
718
|
+
if (values[0] > 255n) return void 0;
|
|
719
|
+
if (values.length === 2) {
|
|
720
|
+
if (values[1] > 16777215n) return void 0;
|
|
721
|
+
return dottedQuadFromValue((values[0] << 24n) + values[1]);
|
|
722
|
+
}
|
|
723
|
+
if (values[1] > 255n) return void 0;
|
|
724
|
+
if (values.length === 3) {
|
|
725
|
+
if (values[2] > 65535n) return void 0;
|
|
726
|
+
return dottedQuadFromValue((values[0] << 24n) + (values[1] << 16n) + values[2]);
|
|
727
|
+
}
|
|
728
|
+
if (values[2] > 255n || values[3] > 255n) return void 0;
|
|
729
|
+
return dottedQuadFromValue((values[0] << 24n) + (values[1] << 16n) + (values[2] << 8n) + values[3]);
|
|
730
|
+
}
|
|
731
|
+
function normalizeIpLiteralHost(hostname) {
|
|
732
|
+
return isIP(hostname) ? hostname : canonicalNumericIpv4(hostname);
|
|
733
|
+
}
|
|
734
|
+
function ipFamily(address) {
|
|
735
|
+
return address.includes(":") ? 6 : 4;
|
|
736
|
+
}
|
|
737
|
+
function ipv4FromHextets(high, low) {
|
|
738
|
+
return `${high >> 8}.${high & 255}.${low >> 8}.${low & 255}`;
|
|
739
|
+
}
|
|
740
|
+
function expandIpv6(address) {
|
|
741
|
+
const pieces = address.toLowerCase().replace(/%.+$/, "").split("::");
|
|
742
|
+
if (pieces.length > 2) return void 0;
|
|
743
|
+
const parseSide = (side) => side ? side.split(":").flatMap((part) => {
|
|
744
|
+
if (part.includes(".")) {
|
|
745
|
+
const nums = part.split(".").map((v) => Number.parseInt(v, 10));
|
|
746
|
+
if (nums.length !== 4 || nums.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return [NaN];
|
|
747
|
+
return [nums[0] << 8 | nums[1], nums[2] << 8 | nums[3]];
|
|
748
|
+
}
|
|
749
|
+
if (!/^[0-9a-f]{1,4}$/.test(part)) return [NaN];
|
|
750
|
+
return [Number.parseInt(part, 16)];
|
|
751
|
+
}) : [];
|
|
752
|
+
const left = parseSide(pieces[0] ?? "");
|
|
753
|
+
const right = parseSide(pieces[1] ?? "");
|
|
754
|
+
if (!left || !right || left.some(Number.isNaN) || right.some(Number.isNaN)) return void 0;
|
|
755
|
+
const zeros = pieces.length === 2 ? 8 - left.length - right.length : 0;
|
|
756
|
+
if (zeros < 0 || pieces.length === 1 && left.length !== 8) return void 0;
|
|
757
|
+
return [
|
|
758
|
+
...left,
|
|
759
|
+
...Array.from({ length: zeros }, () => 0),
|
|
760
|
+
...right
|
|
761
|
+
];
|
|
762
|
+
}
|
|
763
|
+
const NON_PUBLIC_IPV4 = [
|
|
764
|
+
["0.0.0.0", 8],
|
|
765
|
+
["10.0.0.0", 8],
|
|
766
|
+
["100.64.0.0", 10],
|
|
767
|
+
["127.0.0.0", 8],
|
|
768
|
+
["169.254.0.0", 16],
|
|
769
|
+
["172.16.0.0", 12],
|
|
770
|
+
["192.0.0.0", 24],
|
|
771
|
+
["192.0.2.0", 24],
|
|
772
|
+
["192.168.0.0", 16],
|
|
773
|
+
["198.18.0.0", 15],
|
|
774
|
+
["198.51.100.0", 24],
|
|
775
|
+
["203.0.113.0", 24],
|
|
776
|
+
["224.0.0.0", 4],
|
|
777
|
+
["240.0.0.0", 4]
|
|
778
|
+
];
|
|
779
|
+
const NON_PUBLIC_IPV6 = [
|
|
780
|
+
["::", 128],
|
|
781
|
+
["::1", 128],
|
|
782
|
+
["64:ff9b:1::", 48],
|
|
783
|
+
["100::", 64],
|
|
784
|
+
["2001::", 23],
|
|
785
|
+
["2001:db8::", 32],
|
|
786
|
+
["3fff::", 20],
|
|
787
|
+
["5f00::", 16],
|
|
788
|
+
["fc00::", 7],
|
|
789
|
+
["fe80::", 10],
|
|
790
|
+
["fec0::", 10],
|
|
791
|
+
["ff00::", 8]
|
|
792
|
+
];
|
|
793
|
+
function ipv4Value(address) {
|
|
794
|
+
const parts = address.split(".");
|
|
795
|
+
if (parts.length !== 4 || parts.some((part) => !/^\d{1,3}$/.test(part))) return void 0;
|
|
796
|
+
const octets = parts.map(Number);
|
|
797
|
+
if (octets.some((octet) => octet > 255)) return void 0;
|
|
798
|
+
return (octets[0] << 24 | octets[1] << 16 | octets[2] << 8 | octets[3]) >>> 0;
|
|
799
|
+
}
|
|
800
|
+
function inIpv4Prefix(value, base, bits) {
|
|
801
|
+
const mask = bits === 0 ? 0 : 4294967295 << 32 - bits >>> 0;
|
|
802
|
+
return (value & mask) >>> 0 === (ipv4Value(base) & mask) >>> 0;
|
|
803
|
+
}
|
|
804
|
+
function inIpv6Prefix(hextets, base, bits) {
|
|
805
|
+
for (let index = 0; index < 8 && bits > 0; index++, bits -= 16) {
|
|
806
|
+
const mask = bits >= 16 ? 65535 : 65535 << 16 - bits & 65535;
|
|
807
|
+
if ((hextets[index] & mask) !== (base[index] & mask)) return false;
|
|
808
|
+
}
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
811
|
+
const NON_PUBLIC_IPV6_PREFIXES = NON_PUBLIC_IPV6.map(([base, bits]) => [expandIpv6(base), bits]);
|
|
812
|
+
/** The IPv4 address a translation or transition IPv6 address carries, when it carries one. */
|
|
813
|
+
function embeddedIpv4(hextets) {
|
|
814
|
+
const zeros = (from, to) => hextets.slice(from, to).every((part) => part === 0);
|
|
815
|
+
const tail = () => ipv4FromHextets(hextets[6], hextets[7]);
|
|
816
|
+
if (zeros(0, 5) && hextets[5] === 65535) return tail();
|
|
817
|
+
if (zeros(0, 4) && hextets[4] === 65535 && hextets[5] === 0) return tail();
|
|
818
|
+
if (zeros(0, 6)) return tail();
|
|
819
|
+
if (hextets[0] === 100 && hextets[1] === 65435 && zeros(2, 6)) return tail();
|
|
820
|
+
if (hextets[0] === 8194) return ipv4FromHextets(hextets[1], hextets[2]);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Whether a fetch to this IP address must be refused: anything that isn't a globally reachable unicast address,
|
|
824
|
+
* including IPv6 addresses that carry such an IPv4 address.
|
|
825
|
+
*/
|
|
826
|
+
function isPrivateIpAddress(address) {
|
|
827
|
+
if (address.includes(":")) {
|
|
828
|
+
const hextets = expandIpv6(address);
|
|
829
|
+
if (!hextets) return false;
|
|
830
|
+
if (NON_PUBLIC_IPV6_PREFIXES.some(([base, bits]) => inIpv6Prefix(hextets, base, bits))) return true;
|
|
831
|
+
const embedded = embeddedIpv4(hextets);
|
|
832
|
+
return embedded !== void 0 && isPrivateIpAddress(embedded);
|
|
833
|
+
}
|
|
834
|
+
const value = ipv4Value(address);
|
|
835
|
+
return value !== void 0 && NON_PUBLIC_IPV4.some(([base, bits]) => inIpv4Prefix(value, base, bits));
|
|
836
|
+
}
|
|
837
|
+
const REMOTE_FETCH_TIMEOUT_MS = 1e4;
|
|
838
|
+
const MAX_URL_REDIRECTS = 5;
|
|
839
|
+
const MAX_URL_RESPONSE_BYTES = 10485760;
|
|
840
|
+
const MIN_CONTENT_LENGTH = 100;
|
|
841
|
+
const readUrlCache = new I({ max: 100 });
|
|
842
|
+
let turndown;
|
|
843
|
+
function getTurndown() {
|
|
844
|
+
if (!turndown) turndown = new import_turndown_cjs.default({
|
|
845
|
+
headingStyle: "atx",
|
|
846
|
+
codeBlockStyle: "fenced",
|
|
847
|
+
bulletListMarker: "-"
|
|
848
|
+
});
|
|
849
|
+
return turndown;
|
|
850
|
+
}
|
|
851
|
+
function normalizeUrlForCache(url) {
|
|
852
|
+
const repaired = repairCollapsedScheme(url);
|
|
853
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(repaired)) return repaired;
|
|
854
|
+
return /^https?:\/\//i.test(repaired) ? repaired : `https://${repaired}`;
|
|
855
|
+
}
|
|
856
|
+
const RANGE_TOKEN_RE = /^(raw|\d+(?:\+(?:\d+)|(?:-|\.\.)\d+)?)$/i;
|
|
857
|
+
const MULTI_RANGE_RE = /^\d+(?:(?:-|\.\.|,|\+)\d+)*$/;
|
|
858
|
+
function isUrlSelectorToken(token) {
|
|
859
|
+
return /^raw$/i.test(token) || RANGE_TOKEN_RE.test(token) || MULTI_RANGE_RE.test(token);
|
|
860
|
+
}
|
|
861
|
+
function parseSingleRange(token) {
|
|
862
|
+
const plus = token.match(/^(\d+)\+(\d+)$/);
|
|
863
|
+
if (plus) {
|
|
864
|
+
const start = Number.parseInt(plus[1], 10);
|
|
865
|
+
const count = Number.parseInt(plus[2], 10);
|
|
866
|
+
return start < 1 || count < 1 ? void 0 : {
|
|
867
|
+
start,
|
|
868
|
+
end: start + count - 1
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
const range = token.match(/^(\d+)(?:-|\.\.)(\d+)$/);
|
|
872
|
+
if (range) {
|
|
873
|
+
const start = Number.parseInt(range[1], 10);
|
|
874
|
+
const end = Number.parseInt(range[2], 10);
|
|
875
|
+
return start < 1 || end < start ? void 0 : {
|
|
876
|
+
start,
|
|
877
|
+
end
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
const single = token.match(/^(\d+)$/);
|
|
881
|
+
if (single) {
|
|
882
|
+
const start = Number.parseInt(single[1], 10);
|
|
883
|
+
return start < 1 ? void 0 : { start };
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function parseRangeGroup(token) {
|
|
887
|
+
const groups = token.split(",");
|
|
888
|
+
const ranges = [];
|
|
889
|
+
for (const group of groups) {
|
|
890
|
+
const r = parseSingleRange(group);
|
|
891
|
+
if (!r) return void 0;
|
|
892
|
+
ranges.push(r);
|
|
893
|
+
}
|
|
894
|
+
return ranges;
|
|
895
|
+
}
|
|
896
|
+
function tryExtractEmbeddedUrlSelector(readPath) {
|
|
897
|
+
let basePath = readPath;
|
|
898
|
+
const sels = [];
|
|
899
|
+
for (;;) {
|
|
900
|
+
const lastColonIndex = basePath.lastIndexOf(":");
|
|
901
|
+
if (lastColonIndex <= 0) break;
|
|
902
|
+
const candidate = basePath.slice(lastColonIndex + 1);
|
|
903
|
+
const remainder = basePath.slice(0, lastColonIndex);
|
|
904
|
+
if (!isReadableUrlPath(remainder) || !isUrlSelectorToken(candidate)) break;
|
|
905
|
+
try {
|
|
906
|
+
new URL(remainder.startsWith("http://") || remainder.startsWith("https://") ? remainder : `https://${remainder}`);
|
|
907
|
+
} catch {
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
sels.unshift(candidate);
|
|
911
|
+
basePath = remainder;
|
|
912
|
+
}
|
|
913
|
+
return sels.length === 0 ? null : {
|
|
914
|
+
path: basePath,
|
|
915
|
+
sels
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
function parseReadUrlTarget(readPath) {
|
|
919
|
+
const repaired = repairCollapsedScheme(readPath);
|
|
920
|
+
const embedded = tryExtractEmbeddedUrlSelector(repaired);
|
|
921
|
+
const urlPath = embedded?.path ?? repaired;
|
|
922
|
+
if (!isReadableUrlPath(urlPath)) return null;
|
|
923
|
+
let raw = false;
|
|
924
|
+
let ranges;
|
|
925
|
+
for (const sel of embedded?.sels ?? []) {
|
|
926
|
+
if (/^raw$/i.test(sel)) {
|
|
927
|
+
raw = true;
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
if (ranges !== void 0) throw new Error("URL selector has multiple range groups; combine them with commas (e.g. `:5-10,20-30`).");
|
|
931
|
+
const parsed = parseRangeGroup(sel);
|
|
932
|
+
if (!parsed) throw new Error(`Invalid URL line selector: ${sel}`);
|
|
933
|
+
ranges = parsed;
|
|
934
|
+
}
|
|
935
|
+
if (!ranges || ranges.length === 0) return {
|
|
936
|
+
url: urlPath,
|
|
937
|
+
raw
|
|
938
|
+
};
|
|
939
|
+
if (ranges.length === 1) {
|
|
940
|
+
const r = ranges[0];
|
|
941
|
+
return {
|
|
942
|
+
url: urlPath,
|
|
943
|
+
raw,
|
|
944
|
+
offset: r.start,
|
|
945
|
+
limit: r.end !== void 0 ? r.end - r.start + 1 : void 0
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
return {
|
|
949
|
+
url: urlPath,
|
|
950
|
+
raw,
|
|
951
|
+
ranges
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
function getReadUrlCacheKey(scope, requestedUrl, raw) {
|
|
955
|
+
return `${scope}::${raw ? "raw" : "rendered"}::${normalizeUrlForCache(requestedUrl)}`;
|
|
956
|
+
}
|
|
957
|
+
function looksLikeHtml(text) {
|
|
958
|
+
return /<html[\s>]/i.test(text) || /<head[\s>]/i.test(text) && /<body[\s>]/i.test(text);
|
|
959
|
+
}
|
|
960
|
+
function documentExtensionFromContentType(contentType) {
|
|
961
|
+
if (/pdf/i.test(contentType)) return ".pdf";
|
|
962
|
+
if (/msword/i.test(contentType)) return ".doc";
|
|
963
|
+
if (/wordprocessingml|officedocument\.word/i.test(contentType)) return ".docx";
|
|
964
|
+
if (/presentationml|officedocument\.presentation/i.test(contentType)) return ".pptx";
|
|
965
|
+
if (/ms-powerpoint|vnd\.ms-powerpoint/i.test(contentType)) return ".ppt";
|
|
966
|
+
if (/spreadsheetml|officedocument\.spreadsheet/i.test(contentType)) return ".xlsx";
|
|
967
|
+
if (/ms-excel|vnd\.ms-excel/i.test(contentType)) return ".xls";
|
|
968
|
+
if (/epub/i.test(contentType)) return ".epub";
|
|
969
|
+
if (/\bjson\b|ipynb|jupyter/i.test(contentType)) return ".ipynb";
|
|
970
|
+
if (/rtf/i.test(contentType)) return ".rtf";
|
|
971
|
+
}
|
|
972
|
+
function createPinnedDispatcher(pinned) {
|
|
973
|
+
return new import_undici.Agent({ connect: { lookup: (_hostname, options, callback) => {
|
|
974
|
+
if (options.all) callback(null, [pinned]);
|
|
975
|
+
else callback(null, pinned.address, pinned.family);
|
|
976
|
+
} } });
|
|
977
|
+
}
|
|
978
|
+
function toReadableStreamError(error) {
|
|
979
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
980
|
+
}
|
|
981
|
+
function createPinnedResponseBodyStream(body) {
|
|
982
|
+
let controller;
|
|
983
|
+
let terminal = false;
|
|
984
|
+
let ended = false;
|
|
985
|
+
let cleanedUp = false;
|
|
986
|
+
const detachDataListeners = () => {
|
|
987
|
+
body.removeListener("data", onData);
|
|
988
|
+
body.removeListener("end", onEnd);
|
|
989
|
+
};
|
|
990
|
+
const cleanup = () => {
|
|
991
|
+
if (cleanedUp) return;
|
|
992
|
+
cleanedUp = true;
|
|
993
|
+
detachDataListeners();
|
|
994
|
+
body.removeListener("error", onError);
|
|
995
|
+
body.removeListener("close", onClose);
|
|
996
|
+
};
|
|
997
|
+
const closeStream = () => {
|
|
998
|
+
if (terminal) return;
|
|
999
|
+
terminal = true;
|
|
1000
|
+
detachDataListeners();
|
|
1001
|
+
controller?.close();
|
|
1002
|
+
};
|
|
1003
|
+
const onData = (chunk) => {
|
|
1004
|
+
if (terminal) return;
|
|
1005
|
+
controller?.enqueue(new Uint8Array(chunk));
|
|
1006
|
+
};
|
|
1007
|
+
const onEnd = () => {
|
|
1008
|
+
ended = true;
|
|
1009
|
+
closeStream();
|
|
1010
|
+
};
|
|
1011
|
+
const onError = (error) => {
|
|
1012
|
+
if (terminal) return;
|
|
1013
|
+
terminal = true;
|
|
1014
|
+
detachDataListeners();
|
|
1015
|
+
controller?.error(toReadableStreamError(error));
|
|
1016
|
+
};
|
|
1017
|
+
const onClose = () => {
|
|
1018
|
+
if (!terminal && !ended) {
|
|
1019
|
+
terminal = true;
|
|
1020
|
+
detachDataListeners();
|
|
1021
|
+
controller?.error(/* @__PURE__ */ new Error("response body closed before the stream ended"));
|
|
1022
|
+
} else closeStream();
|
|
1023
|
+
cleanup();
|
|
1024
|
+
};
|
|
1025
|
+
return new ReadableStream({
|
|
1026
|
+
start(streamController) {
|
|
1027
|
+
controller = streamController;
|
|
1028
|
+
body.on("data", onData);
|
|
1029
|
+
body.on("end", onEnd);
|
|
1030
|
+
body.on("error", onError);
|
|
1031
|
+
body.on("close", onClose);
|
|
1032
|
+
},
|
|
1033
|
+
cancel() {
|
|
1034
|
+
if (terminal) return;
|
|
1035
|
+
terminal = true;
|
|
1036
|
+
detachDataListeners();
|
|
1037
|
+
body.pause?.();
|
|
1038
|
+
body.destroy();
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
async function closePinnedDispatcher(dispatcher) {
|
|
1043
|
+
const close = dispatcher?.close;
|
|
1044
|
+
if (typeof close === "function") await close.call(dispatcher);
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Fetch a URL through undici with the pinned dispatcher so the validated
|
|
1048
|
+
* address is the one actually connected to. Unlike `globalThis.fetch`, which
|
|
1049
|
+
* silently ignores the undici `dispatcher` option under Bun's compiled binary
|
|
1050
|
+
* (reopening a DNS-rebinding TOCTOU window for hostname targets), undici's own
|
|
1051
|
+
* client honors the dispatcher's custom `lookup` regardless of host runtime.
|
|
1052
|
+
* Adapts the undici response to the WHATWG-Response shape loadPage consumes.
|
|
1053
|
+
*/
|
|
1054
|
+
async function pinnedFetch(url, dispatcher, options) {
|
|
1055
|
+
const result = await (0, import_undici.request)(url, {
|
|
1056
|
+
method: "GET",
|
|
1057
|
+
dispatcher,
|
|
1058
|
+
signal: options.signal,
|
|
1059
|
+
headers: options.headers
|
|
1060
|
+
});
|
|
1061
|
+
const body = result.body;
|
|
1062
|
+
const status = result.statusCode;
|
|
1063
|
+
const headers = new Headers();
|
|
1064
|
+
for (const [key, value] of Object.entries(result.headers)) {
|
|
1065
|
+
if (value === void 0) continue;
|
|
1066
|
+
const values = Array.isArray(value) ? value : [value];
|
|
1067
|
+
for (const entry of values) headers.append(key, entry);
|
|
1068
|
+
}
|
|
1069
|
+
const stream = createPinnedResponseBodyStream(body);
|
|
1070
|
+
return new Response(stream, {
|
|
1071
|
+
status,
|
|
1072
|
+
headers
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
async function assertSafeFetchUrl(url) {
|
|
1076
|
+
const parsed = new URL(url);
|
|
1077
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error(`Unsupported URL protocol: ${parsed.protocol}`);
|
|
1078
|
+
if (process.env.ATOMIC_ALLOW_PRIVATE_URL_READS === "1") return void 0;
|
|
1079
|
+
const hostname = parsed.hostname.replace(/^\[|\]$/g, "").replace(/\.$/, "").toLowerCase();
|
|
1080
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "metadata.google.internal") throw new Error(`Refusing to fetch private or metadata URL: ${url}`);
|
|
1081
|
+
const literalAddress = normalizeIpLiteralHost(hostname);
|
|
1082
|
+
if (literalAddress) {
|
|
1083
|
+
if (isPrivateIpAddress(literalAddress)) throw new Error(`Refusing to fetch private or metadata URL: ${url}`);
|
|
1084
|
+
return {
|
|
1085
|
+
address: literalAddress,
|
|
1086
|
+
family: ipFamily(literalAddress),
|
|
1087
|
+
pinned: false
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
const addresses = await lookup(hostname, { all: true }).catch((error) => {
|
|
1091
|
+
throw new Error(`Could not resolve URL host ${hostname}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1092
|
+
});
|
|
1093
|
+
if (addresses.length === 0) throw new Error(`Could not resolve URL host ${hostname}: no addresses returned`);
|
|
1094
|
+
for (const address of addresses) if (isPrivateIpAddress(address.address)) throw new Error(`Refusing to fetch private or metadata URL: ${url}`);
|
|
1095
|
+
const first = addresses[0];
|
|
1096
|
+
return {
|
|
1097
|
+
address: first.address,
|
|
1098
|
+
family: first.family === 6 ? 6 : 4,
|
|
1099
|
+
pinned: true
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
async function readResponseTextWithLimit(response) {
|
|
1103
|
+
if (!response.body) {
|
|
1104
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
1105
|
+
if (buffer.length > MAX_URL_RESPONSE_BYTES) throw new Error(`URL response exceeds ${MAX_URL_RESPONSE_BYTES} byte limit`);
|
|
1106
|
+
return buffer.toString("utf8");
|
|
1107
|
+
}
|
|
1108
|
+
const reader = response.body.getReader();
|
|
1109
|
+
const decoder = new TextDecoder();
|
|
1110
|
+
const chunks = [];
|
|
1111
|
+
let totalBytes = 0;
|
|
1112
|
+
for (;;) {
|
|
1113
|
+
const { done, value } = await reader.read();
|
|
1114
|
+
if (done) break;
|
|
1115
|
+
totalBytes += value.byteLength;
|
|
1116
|
+
if (totalBytes > MAX_URL_RESPONSE_BYTES) {
|
|
1117
|
+
await reader.cancel();
|
|
1118
|
+
throw new Error(`URL response exceeds ${MAX_URL_RESPONSE_BYTES} byte limit`);
|
|
1119
|
+
}
|
|
1120
|
+
chunks.push(decoder.decode(value, { stream: true }));
|
|
1121
|
+
}
|
|
1122
|
+
chunks.push(decoder.decode());
|
|
1123
|
+
return chunks.join("");
|
|
1124
|
+
}
|
|
1125
|
+
async function loadPage(url, timeoutMs, signal, accept) {
|
|
1126
|
+
url = normalizeUrlForCache(url);
|
|
1127
|
+
const controller = new AbortController();
|
|
1128
|
+
const timer = setTimeout(() => controller.abort(), Math.min(timeoutMs, REMOTE_FETCH_TIMEOUT_MS));
|
|
1129
|
+
const onParentAbort = () => controller.abort();
|
|
1130
|
+
signal?.addEventListener("abort", onParentAbort, { once: true });
|
|
1131
|
+
try {
|
|
1132
|
+
let currentUrl = url;
|
|
1133
|
+
for (let redirects = 0; redirects <= MAX_URL_REDIRECTS; redirects++) {
|
|
1134
|
+
const pinned = await assertSafeFetchUrl(currentUrl);
|
|
1135
|
+
const dispatcher = pinned?.pinned ? createPinnedDispatcher(pinned) : void 0;
|
|
1136
|
+
try {
|
|
1137
|
+
const headers = accept ? { Accept: accept } : void 0;
|
|
1138
|
+
const response = dispatcher ? await pinnedFetch(currentUrl, dispatcher, {
|
|
1139
|
+
signal: controller.signal,
|
|
1140
|
+
headers
|
|
1141
|
+
}) : await fetch(currentUrl, {
|
|
1142
|
+
signal: controller.signal,
|
|
1143
|
+
headers,
|
|
1144
|
+
redirect: "manual"
|
|
1145
|
+
});
|
|
1146
|
+
if (response.status >= 300 && response.status < 400 && response.headers.get("location")) {
|
|
1147
|
+
await response.body?.cancel().catch(() => {});
|
|
1148
|
+
currentUrl = new URL(response.headers.get("location"), currentUrl).href;
|
|
1149
|
+
continue;
|
|
1150
|
+
}
|
|
1151
|
+
if (Number.parseInt(response.headers.get("content-length") ?? "0", 10) > MAX_URL_RESPONSE_BYTES) throw new Error(`URL response exceeds ${MAX_URL_RESPONSE_BYTES} byte limit: ${currentUrl}`);
|
|
1152
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
1153
|
+
const content = await readResponseTextWithLimit(response);
|
|
1154
|
+
return {
|
|
1155
|
+
ok: response.ok,
|
|
1156
|
+
status: response.status,
|
|
1157
|
+
content,
|
|
1158
|
+
contentType,
|
|
1159
|
+
finalUrl: response.url || currentUrl
|
|
1160
|
+
};
|
|
1161
|
+
} finally {
|
|
1162
|
+
await closePinnedDispatcher(dispatcher).catch(() => void 0);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
throw new Error(`Too many redirects while fetching URL: ${url}`);
|
|
1166
|
+
} finally {
|
|
1167
|
+
clearTimeout(timer);
|
|
1168
|
+
signal?.removeEventListener("abort", onParentAbort);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
function isLowQuality(content) {
|
|
1172
|
+
const lower = content.toLowerCase();
|
|
1173
|
+
if (/(enable javascript|javascript required|turn on javascript|please enable javascript|browser not supported)/.test(lower) && content.trim().length < 2e3) return true;
|
|
1174
|
+
const nonblank = content.split("\n").filter((line) => line.trim().length > 0);
|
|
1175
|
+
if (nonblank.length > 10 && nonblank.filter((line) => line.trim().length < 40).length / nonblank.length > .7) return true;
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
function buildLlmEndpointCandidates(url) {
|
|
1179
|
+
const parsed = (() => {
|
|
1180
|
+
try {
|
|
1181
|
+
return new URL(url);
|
|
1182
|
+
} catch {
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
})();
|
|
1186
|
+
if (!parsed) return [];
|
|
1187
|
+
const origin = parsed.origin;
|
|
1188
|
+
if (parsed.pathname === "/" || parsed.pathname === "") return [
|
|
1189
|
+
`${origin}/.well-known/llms.txt`,
|
|
1190
|
+
`${origin}/llms.txt`,
|
|
1191
|
+
`${origin}/llms.md`
|
|
1192
|
+
];
|
|
1193
|
+
const segments = parsed.pathname.replace(/\/+$/, "").split("/").filter(Boolean);
|
|
1194
|
+
const candidates = [];
|
|
1195
|
+
const depth = parsed.pathname.endsWith("/") ? segments.length : Math.max(segments.length - 1, 1);
|
|
1196
|
+
for (let scope = Math.min(depth, segments.length); scope >= 1; scope--) {
|
|
1197
|
+
const base = `${origin}/${segments.slice(0, scope).join("/")}`;
|
|
1198
|
+
candidates.push(`${base}/llms.txt`, `${base}/llms.md`);
|
|
1199
|
+
}
|
|
1200
|
+
candidates.push(`${origin}/llms.txt`, `${origin}/llms.md`);
|
|
1201
|
+
return [...new Set(candidates)];
|
|
1202
|
+
}
|
|
1203
|
+
async function tryLlmEndpoints(url, signal) {
|
|
1204
|
+
for (const endpoint of buildLlmEndpointCandidates(url)) try {
|
|
1205
|
+
const page = await loadPage(endpoint, 5e3, signal);
|
|
1206
|
+
if (page.ok && page.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(page.content)) return {
|
|
1207
|
+
content: page.content,
|
|
1208
|
+
endpoint
|
|
1209
|
+
};
|
|
1210
|
+
} catch {}
|
|
1211
|
+
return null;
|
|
1212
|
+
}
|
|
1213
|
+
function extractLinkTags(head) {
|
|
1214
|
+
const tags = [];
|
|
1215
|
+
let searchFrom = 0;
|
|
1216
|
+
while (searchFrom < head.length) {
|
|
1217
|
+
const start = findAsciiCaseInsensitive(head, "<link", searchFrom);
|
|
1218
|
+
if (start === -1) break;
|
|
1219
|
+
const afterName = start + 5;
|
|
1220
|
+
if (afterName < head.length && isAsciiWordCode(head.charCodeAt(afterName))) {
|
|
1221
|
+
searchFrom = afterName;
|
|
1222
|
+
continue;
|
|
1223
|
+
}
|
|
1224
|
+
const end = head.indexOf(">", afterName);
|
|
1225
|
+
if (end === -1) break;
|
|
1226
|
+
tags.push(head.slice(start, end + 1));
|
|
1227
|
+
searchFrom = end + 1;
|
|
1228
|
+
}
|
|
1229
|
+
return tags;
|
|
1230
|
+
}
|
|
1231
|
+
function parseAlternateMarkdownLink(html, pageUrl) {
|
|
1232
|
+
const headEnd = html.toLowerCase().indexOf("</head>");
|
|
1233
|
+
const links = extractLinkTags(html.slice(0, headEnd >= 0 ? headEnd + 7 : html.length));
|
|
1234
|
+
for (const tag of links) {
|
|
1235
|
+
const rel = /rel=["']?([^"'>]+)["']?/i.exec(tag)?.[1] ?? "";
|
|
1236
|
+
const type = /type=["']?([^"'>]+)["']?/i.exec(tag)?.[1] ?? "";
|
|
1237
|
+
const href = /href=["']?([^"'>]+)["']?/i.exec(tag)?.[1] ?? "";
|
|
1238
|
+
if (!/alternate/i.test(rel) || !href) continue;
|
|
1239
|
+
if (/RecentChanges|Special:|\/feed\/|action=feed/i.test(href)) continue;
|
|
1240
|
+
if (type.includes("markdown") || href.endsWith(".md")) try {
|
|
1241
|
+
return new URL(href, pageUrl).href;
|
|
1242
|
+
} catch {}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
async function tryMdSuffix(url, signal) {
|
|
1246
|
+
const candidates = [];
|
|
1247
|
+
if (/\/$/.test(url)) candidates.push(`${url}index.html.md`);
|
|
1248
|
+
else if (/\.\w+\/?$/.test(url)) candidates.push(`${url}.md`);
|
|
1249
|
+
else candidates.push(`${url}.md`, `${url}/index.html.md`);
|
|
1250
|
+
for (const candidate of candidates) try {
|
|
1251
|
+
const page = await loadPage(candidate, 5e3, signal);
|
|
1252
|
+
if (page.ok && page.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(page.content)) return page.content;
|
|
1253
|
+
} catch {}
|
|
1254
|
+
return null;
|
|
1255
|
+
}
|
|
1256
|
+
async function tryContentNegotiation(url, signal) {
|
|
1257
|
+
try {
|
|
1258
|
+
const page = await loadPage(url, 5e3, signal, "text/markdown, text/plain;q=0.9, text/html;q=0.8");
|
|
1259
|
+
const mime = page.contentType.toLowerCase();
|
|
1260
|
+
if (page.ok && page.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(page.content) && (mime.includes("markdown") || mime.includes("text/plain"))) return page.content;
|
|
1261
|
+
} catch {}
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
async function renderUrl(url, raw, signal) {
|
|
1265
|
+
const notes = [];
|
|
1266
|
+
let method = "text";
|
|
1267
|
+
let contentType = "";
|
|
1268
|
+
let finalUrl;
|
|
1269
|
+
let body = "";
|
|
1270
|
+
const page = await loadPage(url, REMOTE_FETCH_TIMEOUT_MS, signal);
|
|
1271
|
+
finalUrl = page.finalUrl;
|
|
1272
|
+
contentType = page.contentType;
|
|
1273
|
+
if (!page.ok) return {
|
|
1274
|
+
content: page.content || `(request failed with status ${page.status})`,
|
|
1275
|
+
finalUrl,
|
|
1276
|
+
contentType,
|
|
1277
|
+
method: "failed",
|
|
1278
|
+
notes,
|
|
1279
|
+
truncated: false
|
|
1280
|
+
};
|
|
1281
|
+
if (raw) return {
|
|
1282
|
+
content: page.content,
|
|
1283
|
+
finalUrl,
|
|
1284
|
+
contentType,
|
|
1285
|
+
method: "raw",
|
|
1286
|
+
notes,
|
|
1287
|
+
truncated: false
|
|
1288
|
+
};
|
|
1289
|
+
const buffer = Buffer.from(page.content, "utf8");
|
|
1290
|
+
const docExt = documentExtensionFromContentType(contentType) ?? (isDocumentPath(finalUrl) ? finalUrl.match(/\.\w+(?:$|[?#])/)?.[0] ?? "" : "");
|
|
1291
|
+
if (docExt) {
|
|
1292
|
+
try {
|
|
1293
|
+
body = await extractDocumentMarkdown(buffer, `${finalUrl}${docExt}`);
|
|
1294
|
+
method = "document";
|
|
1295
|
+
} catch (error) {
|
|
1296
|
+
body = `[Cannot read ${docExt} file: ${error instanceof Error ? error.message : "conversion failed"}]`;
|
|
1297
|
+
method = "document-error";
|
|
1298
|
+
}
|
|
1299
|
+
return {
|
|
1300
|
+
content: body,
|
|
1301
|
+
finalUrl,
|
|
1302
|
+
contentType,
|
|
1303
|
+
method,
|
|
1304
|
+
notes,
|
|
1305
|
+
truncated: false
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
if (/html/i.test(contentType) || looksLikeHtml(page.content)) {
|
|
1309
|
+
const altMd = parseAlternateMarkdownLink(page.content, finalUrl);
|
|
1310
|
+
if (altMd) {
|
|
1311
|
+
try {
|
|
1312
|
+
const alt = await loadPage(altMd, 5e3, signal);
|
|
1313
|
+
if (alt.ok && alt.content.trim().length > MIN_CONTENT_LENGTH && !looksLikeHtml(alt.content)) return {
|
|
1314
|
+
content: alt.content,
|
|
1315
|
+
finalUrl: alt.finalUrl,
|
|
1316
|
+
contentType: alt.contentType,
|
|
1317
|
+
method: "alternate-markdown",
|
|
1318
|
+
notes,
|
|
1319
|
+
truncated: false
|
|
1320
|
+
};
|
|
1321
|
+
} catch {}
|
|
1322
|
+
notes.push("alternate markdown link unusable");
|
|
1323
|
+
}
|
|
1324
|
+
const md = await tryMdSuffix(finalUrl, signal);
|
|
1325
|
+
if (md) return {
|
|
1326
|
+
content: md,
|
|
1327
|
+
finalUrl,
|
|
1328
|
+
contentType: "text/markdown",
|
|
1329
|
+
method: "md-suffix",
|
|
1330
|
+
notes,
|
|
1331
|
+
truncated: false
|
|
1332
|
+
};
|
|
1333
|
+
const neg = await tryContentNegotiation(finalUrl, signal);
|
|
1334
|
+
if (neg) return {
|
|
1335
|
+
content: neg,
|
|
1336
|
+
finalUrl,
|
|
1337
|
+
contentType: "text/markdown",
|
|
1338
|
+
method: "content-negotiation",
|
|
1339
|
+
notes,
|
|
1340
|
+
truncated: false
|
|
1341
|
+
};
|
|
1342
|
+
const rendered = getTurndown().turndown(page.content).trim();
|
|
1343
|
+
method = "native";
|
|
1344
|
+
if (rendered.length <= MIN_CONTENT_LENGTH || isLowQuality(rendered)) {
|
|
1345
|
+
const llms = await tryLlmEndpoints(finalUrl, signal);
|
|
1346
|
+
if (llms) return {
|
|
1347
|
+
content: llms.content,
|
|
1348
|
+
finalUrl,
|
|
1349
|
+
contentType: "text/plain",
|
|
1350
|
+
method: `llms-txt (${llms.endpoint})`,
|
|
1351
|
+
notes,
|
|
1352
|
+
truncated: false
|
|
1353
|
+
};
|
|
1354
|
+
notes.push("rendered content low quality; no markdown source discovered");
|
|
1355
|
+
}
|
|
1356
|
+
body = rendered;
|
|
1357
|
+
} else body = page.content;
|
|
1358
|
+
return {
|
|
1359
|
+
content: body,
|
|
1360
|
+
finalUrl,
|
|
1361
|
+
contentType,
|
|
1362
|
+
method,
|
|
1363
|
+
notes,
|
|
1364
|
+
truncated: false
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
function buildUrlReadOutput(result) {
|
|
1368
|
+
return `${[
|
|
1369
|
+
`URL: ${result.finalUrl}`,
|
|
1370
|
+
`Content-Type: ${result.contentType}`,
|
|
1371
|
+
`Method: ${result.method}`,
|
|
1372
|
+
...result.notes.length ? [`Notes: ${result.notes.join("; ")}`] : []
|
|
1373
|
+
].join("\n")}\n\n---\n\n${result.content}`;
|
|
1374
|
+
}
|
|
1375
|
+
async function persistReadUrlArtifact(artifactsDir, output) {
|
|
1376
|
+
if (!artifactsDir) return void 0;
|
|
1377
|
+
return getArtifactManager(artifactsDir).save(output, "read");
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Resolve a URL to its full rendered (or raw) output, using the session-scoped
|
|
1381
|
+
* cache and persisting the rendered body as a `read` artifact. Returns the
|
|
1382
|
+
* complete untruncated output so callers can apply their own line selection.
|
|
1383
|
+
*/
|
|
1384
|
+
async function loadReadUrlOutput(scope, params, artifactsDir, signal) {
|
|
1385
|
+
const parsed = parseReadUrlTarget(params.path);
|
|
1386
|
+
if (!parsed) throw new Error(`Not a readable URL: ${params.path}`);
|
|
1387
|
+
const raw = params.raw ?? parsed.raw;
|
|
1388
|
+
const key = getReadUrlCacheKey(scope, parsed.url, raw);
|
|
1389
|
+
let entry = readUrlCache.get(key);
|
|
1390
|
+
if (!entry) {
|
|
1391
|
+
const rendered = await renderUrl(parsed.url, raw, signal);
|
|
1392
|
+
const output = raw ? rendered.content : buildUrlReadOutput(rendered);
|
|
1393
|
+
const artifactId = await persistReadUrlArtifact(artifactsDir, output);
|
|
1394
|
+
entry = {
|
|
1395
|
+
artifactId,
|
|
1396
|
+
details: {
|
|
1397
|
+
url: parsed.url,
|
|
1398
|
+
finalUrl: rendered.finalUrl,
|
|
1399
|
+
contentType: rendered.contentType,
|
|
1400
|
+
method: rendered.method,
|
|
1401
|
+
truncated: rendered.truncated,
|
|
1402
|
+
notes: rendered.notes,
|
|
1403
|
+
meta: artifactId ? { artifactId } : void 0
|
|
1404
|
+
},
|
|
1405
|
+
output
|
|
1406
|
+
};
|
|
1407
|
+
readUrlCache.set(key, entry);
|
|
1408
|
+
readUrlCache.set(getReadUrlCacheKey(scope, rendered.finalUrl, raw), entry);
|
|
1409
|
+
}
|
|
1410
|
+
return {
|
|
1411
|
+
output: entry.output,
|
|
1412
|
+
details: entry.details,
|
|
1413
|
+
artifactId: entry.artifactId,
|
|
1414
|
+
raw
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
async function executeReadUrl(scope, params, artifactsDir, signal) {
|
|
1418
|
+
const loaded = await loadReadUrlOutput(scope, params, artifactsDir, signal);
|
|
1419
|
+
const entry = {
|
|
1420
|
+
output: loaded.output,
|
|
1421
|
+
details: loaded.details,
|
|
1422
|
+
artifactId: loaded.artifactId
|
|
1423
|
+
};
|
|
1424
|
+
const fetchDefaultBytes = 51200;
|
|
1425
|
+
const lines = entry.output.split("\n");
|
|
1426
|
+
const visibleLines = lines.slice(0, 300);
|
|
1427
|
+
let content = visibleLines.join("\n");
|
|
1428
|
+
const byteTruncated = Buffer.byteLength(content, "utf8") > fetchDefaultBytes;
|
|
1429
|
+
const lineTruncated = lines.length > 300;
|
|
1430
|
+
if (byteTruncated) content = content.slice(0, fetchDefaultBytes);
|
|
1431
|
+
const truncated = lineTruncated || byteTruncated;
|
|
1432
|
+
let artifactId = entry.artifactId;
|
|
1433
|
+
if (truncated && !artifactId) artifactId = await persistReadUrlArtifact(artifactsDir, entry.output);
|
|
1434
|
+
const outputLines = content.length === 0 ? 0 : content.split("\n").length;
|
|
1435
|
+
const truncation = truncated ? {
|
|
1436
|
+
content,
|
|
1437
|
+
truncated: true,
|
|
1438
|
+
truncatedBy: byteTruncated ? "bytes" : "lines",
|
|
1439
|
+
totalLines: lines.length,
|
|
1440
|
+
totalBytes: Buffer.byteLength(entry.output, "utf8"),
|
|
1441
|
+
outputLines,
|
|
1442
|
+
outputBytes: Buffer.byteLength(content, "utf8"),
|
|
1443
|
+
lastLinePartial: byteTruncated,
|
|
1444
|
+
firstLineExceedsLimit: false,
|
|
1445
|
+
maxLines: 300,
|
|
1446
|
+
maxBytes: fetchDefaultBytes
|
|
1447
|
+
} : void 0;
|
|
1448
|
+
const details = {
|
|
1449
|
+
...entry.details,
|
|
1450
|
+
truncated,
|
|
1451
|
+
meta: {
|
|
1452
|
+
...entry.details.meta ?? {},
|
|
1453
|
+
...artifactId ? { artifactId } : {},
|
|
1454
|
+
...truncation ? { truncation } : {}
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
if (truncated) content += `\n\n[Showing first ${visibleLines.length} of ${lines.length} lines.${artifactId ? ` Full output: artifact://${artifactId}` : ""}]`;
|
|
1458
|
+
return {
|
|
1459
|
+
content,
|
|
1460
|
+
details,
|
|
1461
|
+
artifactId
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
// dist/core/tools/read-url.js
|
|
1465
|
+
/**
|
|
1466
|
+
* URL branch of the `read` tool: routes plain URL reads through the
|
|
1467
|
+
* cache/artifact/llms.txt fetch pipeline ({@link executeReadUrl}); explicit
|
|
1468
|
+
* URL line selectors reuse the same safe rendering path before slicing lines.
|
|
1469
|
+
*/
|
|
1470
|
+
async function readUrlBranch(args) {
|
|
1471
|
+
const { effectivePath, rawOutput, effectiveRanges, effectiveOffset, effectiveLimit, cwd, ctx, signal, maxChars, maxBytes, oversized, sourceMeta } = args;
|
|
1472
|
+
const session = ctx?.sessionManager;
|
|
1473
|
+
const sessionDir = session?.getSessionDir?.() || (session?.isPersisted?.() ? sessionScratchDir(getAgentDir(), session.getCwd?.() ?? cwd, session.getSessionId?.() ?? "") : void 0);
|
|
1474
|
+
const scope = session?.getSessionId?.() ?? cwd;
|
|
1475
|
+
const artifactsDir = sessionDir ? resolve(sessionDir, "artifacts") : void 0;
|
|
1476
|
+
if (!effectiveRanges && !effectiveOffset && effectiveLimit === void 0) {
|
|
1477
|
+
const result = await executeReadUrl(scope, {
|
|
1478
|
+
path: effectivePath,
|
|
1479
|
+
raw: rawOutput
|
|
1480
|
+
}, artifactsDir, signal);
|
|
1481
|
+
const artifactId = result.artifactId ?? result.details.meta?.artifactId;
|
|
1482
|
+
const truncation = result.details.meta?.truncation;
|
|
1483
|
+
return {
|
|
1484
|
+
content: [{
|
|
1485
|
+
type: "text",
|
|
1486
|
+
text: result.content
|
|
1487
|
+
}],
|
|
1488
|
+
details: {
|
|
1489
|
+
...truncation ? { truncation } : {},
|
|
1490
|
+
meta: {
|
|
1491
|
+
...result.details.meta ?? {},
|
|
1492
|
+
source: effectivePath,
|
|
1493
|
+
sourcePath: effectivePath,
|
|
1494
|
+
...artifactId ? { artifactId } : {}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
const page = await loadPage(effectivePath, 1e4, signal);
|
|
1500
|
+
const textContent = rawOutput ? page.content : await decodeReadableUrl(new Response(page.content, { headers: { "content-type": page.contentType } }), page.finalUrl || effectivePath);
|
|
1501
|
+
const selection = applyReadLineSelection(textContent.split("\n"), effectiveRanges, effectiveOffset, effectiveLimit, rawOutput);
|
|
1502
|
+
const selectedText = selection.lines.join("\n");
|
|
1503
|
+
if ((effectiveRanges || effectiveOffset) && selection.lines.length === 0) return {
|
|
1504
|
+
content: [{
|
|
1505
|
+
type: "text",
|
|
1506
|
+
text: `Requested line ${effectiveRanges?.[0]?.start ?? effectiveOffset ?? 1} is beyond end of resource (${textContent.split("\n").length} lines total).`
|
|
1507
|
+
}],
|
|
1508
|
+
details: void 0
|
|
1509
|
+
};
|
|
1510
|
+
if (selectedText.length > maxChars || Buffer.byteLength(selectedText, "utf8") > maxBytes) return oversized({
|
|
1511
|
+
blocked: true,
|
|
1512
|
+
path: effectivePath,
|
|
1513
|
+
chars: selectedText.length,
|
|
1514
|
+
maxChars,
|
|
1515
|
+
startLine: selection.firstLine,
|
|
1516
|
+
totalFileLines: textContent.split("\n").length,
|
|
1517
|
+
firstLineBytes: Buffer.byteLength(selection.lines[0] ?? "", "utf8"),
|
|
1518
|
+
byteGuidance: false
|
|
1519
|
+
});
|
|
1520
|
+
return {
|
|
1521
|
+
content: [{
|
|
1522
|
+
type: "text",
|
|
1523
|
+
text: rawOutput ? selectedText : `URL: ${effectivePath}\nStatus: ${page.status}\nContent-Type: ${page.contentType || "unknown"}\n\n${selectedText}`
|
|
1524
|
+
}],
|
|
1525
|
+
details: sourceMeta(effectivePath)
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
export { readUrlBranch };
|
|
1529
|
+
|
|
1530
|
+
//# sourceMappingURL=read-url.code.js.map
|