diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e8f948a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,73 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + tags: ["v*"] + +permissions: + contents: read + +jobs: + verify: + runs-on: ubuntu-latest + timeout-minutes: 8 + steps: + - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 + with: + persist-credentials: false + fetch-depth: 0 + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + bun-version-file: package.json + - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 + with: + node-version: 22 + - run: bun install --frozen-lockfile + - run: bun run verify + - run: test -z "$(git status --porcelain --untracked-files=all -- dist)" + - name: Verify the installed tarball in Node and Bun + shell: bash + run: | + directory="$RUNNER_TEMP/package" + mkdir -p "$directory" + artifact="$(bun pm pack --ignore-scripts --quiet --destination "$directory")" + (cd "$directory" && sha256sum "$(basename "$artifact")" > SHA256SUMS) + consumer=$(mktemp -d) + cp scripts/check-consumer.mjs "$consumer/" + cd "$consumer" + bun add --ignore-scripts "$artifact" + node check-consumer.mjs + bun check-consumer.mjs + - name: Validate the release tag + if: github.ref_type == 'tag' + shell: bash + run: | + [[ "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] + [[ "$GITHUB_REF_NAME" == "v$(node -p "require('./package.json').version")" ]] + git merge-base --is-ancestor HEAD origin/main + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + if: github.ref_type == 'tag' + with: + name: verified-package + path: ${{ runner.temp }}/package/ + if-no-files-found: error + + release: + if: github.ref_type == 'tag' + needs: verify + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 + with: + name: verified-package + path: package + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: | + (cd package && sha256sum --check SHA256SUMS) + gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag --generate-notes package/*.tgz package/SHA256SUMS diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f42ec36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +/*.tgz diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cfc82e --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# DeepSeek Durable Objects + +Run a DeepSeek agent loop inside a SQLite-backed Cloudflare Durable Object. The package persists native session history, recovers interrupted turns, and resumes parked tool calls. It supports DeepSeek's API and the OpenRouter Messages route. + +## Install + +```sh +bun add github:checkfu/deepseek-durable-objects#v0.0.1 +``` + +GitHub releases also include an installable tarball and its SHA-256 checksum. Checkfu pins this repository to an exact commit in its Bun catalog. + +## Use with a Worker + +Import `openDeepSeekSession` from `deepseek-durable-objects`. Construct one runtime per Durable Object. Pass the object's SQLite storage, a stable session ID, the initial model configuration, and a tool host. Keep the provider and model pinned for that runtime. + +Call `submit`, `settle`, and `abort` from the host's turn lifecycle. Use the same operation ID when recovering or resuming a turn. Drive recovery from the Durable Object alarm. The host supplies credentials and decides which tools can run, how to publish replies, and how to record usage. Use `withDeepSeekDispatch` from `deepseek-durable-objects/transport` to intercept a model dispatch for accounting. + +Add `deepSeekWorkerdBuild` from `deepseek-durable-objects/workerd` to the Worker bundler using Cloudflare's Node compatibility. With Alchemy, load the plugin in the Worker source provider so the build sidecar can resolve it. The [standalone Worker fixture](test/fixtures/worker.mjs) shows the storage and tool interfaces in use. + +## Develop + +Run `bun install --frozen-lockfile` and `bun run verify`. The checks include the compiled package, direct provider fixtures, and a Workerd restart against the same SQLite Durable Object. Commit the generated `dist/` after changing the source so pinned Git installs can use it directly. To release, update the version and lockfile, merge to `main`, and push the matching `v` tag. diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..4fe8b15 --- /dev/null +++ b/bun.lock @@ -0,0 +1,480 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "deepseek-durable-objects", + "dependencies": { + "@deepseek-ai/cordis": "4.0.5-alpha.1", + "@deepseek-ai/dsh-agent": "0.2.1-alpha.2", + "@deepseek-ai/dsh-agent-loop": "0.2.1-alpha.2", + "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", + "@deepseek-ai/dsh-llm-deepseek": "0.2.1-alpha.2", + "@deepseek-ai/dsh-session": "0.2.1-alpha.2", + "@deepseek-ai/dsh-session-persistence": "0.2.1-alpha.2", + "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2", + "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2", + "@deepseek-ai/dsh-tools": "0.2.1-alpha.2", + "effect": "4.1.7", + "eventsource-parser": "3.1.1", + }, + "devDependencies": { + "@alchemy.run/cloudflare-runtime": "https://pkg.alchemy.run/@alchemy.run/cloudflare-runtime/-/cbd8cd35b9e50ad07d3af4a8f666da46e05f95659a5f580b62ec46a0dcde67ba.tgz", + "@types/node": "26.6.6", + "miniflare": "5.20261117.0-beta", + "rolldown": "1.2.16", + "typescript": "7.0.2", + "vitest": "5.1.1", + }, + }, + }, + "packages": { + "@alchemy.run/cloudflare-runtime": ["@alchemy.run/cloudflare-runtime@https://pkg.alchemy.run/@alchemy.run/cloudflare-runtime/-/cbd8cd35b9e50ad07d3af4a8f666da46e05f95659a5f580b62ec46a0dcde67ba.tgz", { "dependencies": { "@alchemy.run/node-utils": "https://pkg.alchemy.run/@alchemy.run/node-utils/-/3ac66c7f1348b366450188594ee3013ea56adb8cb5bff8088cba7960961df25e.tgz", "@cloudflare/unenv-preset": "^2.16.2", "@puppeteer/browsers": "^3.2.4", "capnp-es": "^0.0.17", "magic-string": "^0.30.21", "mime": "^4.1.1", "sharp": "^0.35.5", "unenv": "^2.0.0-rc.24", "workerd": "1.20261117.1", "yauzl": "^3.4.0" }, "peerDependencies": { "@distilled.cloud/cloudflare": "https://pkg.alchemy.run/@distilled.cloud/cloudflare/-/55b682d9ade478c8eaa1642d38571da6487a1e0949085cc4bda60f8fb948b290.tgz", "@effect/platform-bun": "^4.1.4", "@effect/platform-node": "^4.1.4", "effect": "^4.1.4", "rolldown": "1.2.16", "vite": "^7.0.0 || ^8.0.0" }, "optionalPeers": ["@effect/platform-bun", "@effect/platform-node", "rolldown", "vite"] }, "sha512-y2hF7Byv5FgaYHTbjH53UXFHo8CbY4Jl2Pjur5rUbVOHM8CXXNLOBrzwmsC9uC0IrUwHp8+uozEPkQ8xNlSjHA=="], + + "@alchemy.run/node-utils": ["@alchemy.run/node-utils@https://pkg.alchemy.run/@alchemy.run/node-utils/-/3ac66c7f1348b366450188594ee3013ea56adb8cb5bff8088cba7960961df25e.tgz", { "dependencies": { "chokidar": "^5.0.0", "rolldown": "1.2.16" }, "peerDependencies": { "effect": "^4.1.4" } }, "sha512-QoWbmntoVvL45vkqCuUDg4E1VFjcElKsbFUcdDowwABNNGsjRVEoj4Mi/VSyNbY1vt5q/s4jTuYTyXdn4Ijk7g=="], + + "@cloudflare/unenv-preset": ["@cloudflare/unenv-preset@2.16.2", "", { "peerDependencies": { "unenv": "2.0.0-rc.24", "workerd": ">1.20260305.0 <2.0.0-0" }, "optionalPeers": ["workerd"] }, "sha512-JBP1+Z7ZSNG/d4mRP+y8VC5dka3tZVMLEZRvS+rzQ4DGV1EoxRFQckcJTTkXbHSQiTj0DtNI01Zwb/V2fX0mvQ=="], + + "@cloudflare/workerd-darwin-64": ["@cloudflare/workerd-darwin-64@1.20261117.1", "", { "os": "darwin", "cpu": "x64" }, "sha512-qfAYw6iPoey0BmPsp4z5ARWOa+XSBD3gQzmcBI2ql9pKTSA5eEC8F1oI6BIk/FVguhomfSn5gS4RzbWhTd/EpQ=="], + + "@cloudflare/workerd-darwin-arm64": ["@cloudflare/workerd-darwin-arm64@1.20261117.1", "", { "os": "darwin", "cpu": "arm64" }, "sha512-cInx5Cr9O27oW+ujyI49lTRQZra/lMgWUFiKmGY3jxDncATSxzfQ6udXHkVvK4//1/PfxQTDyMjdQUIN8m6Aqg=="], + + "@cloudflare/workerd-linux-64": ["@cloudflare/workerd-linux-64@1.20261117.1", "", { "os": "linux", "cpu": "x64" }, "sha512-gZLA8X11m/luZwn+YA3+mDu61vdxNJzpksP/QZqjydKTQ+VUCulsK5gtn9Bqst1p3KJu2kafQpJ1nDQv4B23jA=="], + + "@cloudflare/workerd-linux-arm64": ["@cloudflare/workerd-linux-arm64@1.20261117.1", "", { "os": "linux", "cpu": "arm64" }, "sha512-gxWngFojq41ULKNKb9rpWYvKotN5hT2I/xot+Bpy31cXzrwcTgtDLSMb2t75sW5BJxH7hihFvikgYb577kB3Zg=="], + + "@cloudflare/workerd-windows-64": ["@cloudflare/workerd-windows-64@1.20261117.1", "", { "os": "win32", "cpu": "x64" }, "sha512-0OR2Btx5EDonOKvvuGDq8rxBSggxoF1ThQjbZN3vsu3GlaF/oXW5f9/iB78OgV0CzMPTi+hZgzc1NR95UJCURA=="], + + "@cspotcode/source-map-support": ["@cspotcode/source-map-support@0.8.1", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="], + + "@deepseek-ai/cordis": ["@deepseek-ai/cordis@4.0.5-alpha.1", "", { "dependencies": { "@deepseek-ai/cosmokit": "~1.8.6-alpha.1", "@standard-schema/spec": "^1.1.0" }, "peerDependencies": { "@deepseek-ai/cordis-plugin-include": "~1.0.10-alpha.1", "@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.1" }, "optionalPeers": ["@deepseek-ai/cordis-plugin-include", "@deepseek-ai/cordis-plugin-loader"], "bin": { "cordis": "bin.js" } }, "sha512-I0akiPAK9EEWO+GMAO0YGbn3/rzg/yopaxohBaG9JHM8dDzGaCZNp3mehjeC66IQL0AyTyDwvgv7v1aB+eMnKQ=="], + + "@deepseek-ai/cosmokit": ["@deepseek-ai/cosmokit@1.8.6", "", {}, "sha512-ZSD/fN52L498LBIOYwjIOlaLv5veY6ZEwI2yzvZUKQtctn0QAPqu8tKdJ+OF5+Tv6NBq1U+wJWH+QI6OGy5EvQ=="], + + "@deepseek-ai/dsh-agent": ["@deepseek-ai/dsh-agent@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-scope": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2", "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2", "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2", "@deepseek-ai/dsh-typert-protocol": "0.2.1-alpha.2", "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2", "@deepseek-ai/dsh-workspace": "0.2.1-alpha.2" }, "optionalPeers": ["@deepseek-ai/dsh-workspace"] }, "sha512-G/gqW6Y2Qki+MLUVk22+ni6rwyjkCI6tpzF7EoyTdckrk9C7sjQMrnBh0hbA65sES0DNygxLHfzEQiZjpuWIDA=="], + + "@deepseek-ai/dsh-agent-loop": ["@deepseek-ai/dsh-agent-loop@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2", "@deepseek-ai/schemastery": "~3.18.5-alpha.1", "zod": "^4.4.3" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-agent": "0.2.1-alpha.2", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-scope": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2", "@deepseek-ai/dsh-session-persistence": "0.2.1-alpha.2", "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2", "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2", "@deepseek-ai/dsh-tools": "0.2.1-alpha.2" } }, "sha512-bw5s6A/w9TJXHautNxherVEvLGc/hQzNG2FDmbMGTo5dAB1aeOY6ELES/Xv2tI6qC9jGmnC2fkejtDneiqtmcg=="], + + "@deepseek-ai/dsh-anonymous-user-id": ["@deepseek-ai/dsh-anonymous-user-id@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-home-paths": "0.2.1-alpha.2" } }, "sha512-hepWv2dYR5z6LsTOzll0rhwBdn6bo/Uy+CwT4uVzsbU7eGWf3Eszj8bLH+ytVLGxS8TuBju1yuCXBKuzShBCVA=="], + + "@deepseek-ai/dsh-atomic-write": ["@deepseek-ai/dsh-atomic-write@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-ZBbUSKxUUgXGnTbQLRSl2qjibLUEMxp0Y0nv5pZOwmXKOpxbK8w6M1GwfHt9BqpWU223H7hzgJyATQIfNhqxOw=="], + + "@deepseek-ai/dsh-attachment": ["@deepseek-ai/dsh-attachment@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-brand": "0.2.1-alpha.2" } }, "sha512-O4nn/+YIQ2X0ylrOOx5LKKWtGsezl9zTY/qIec9ugX380yTrzexMWHuRbEG/3jbIxUgXQdjqOwDLmkTVFkY38A=="], + + "@deepseek-ai/dsh-brand": ["@deepseek-ai/dsh-brand@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-2cpJzyu0IbyRXwZMBSEy+tWxj1OvhgiQwSTY1GlhEcPi+VF0nvT2pJIa/i43kH+0hs48r4tFX/v/tczK6d//Hg=="], + + "@deepseek-ai/dsh-deepseek-llm-api-extensions": ["@deepseek-ai/dsh-deepseek-llm-api-extensions@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-+qtbfWVjeZ/o0EInhPjExerAmCaKJvoVt0R58voJKXharoRo0Cq6EfpG3ZMcJB9AqHISWj9224/MWCzaklm9eQ=="], + + "@deepseek-ai/dsh-fs": ["@deepseek-ai/dsh-fs@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-sandbox": "0.2.1-alpha.2" } }, "sha512-szwTA36cWXAn/q1XhhFmyactYuGWGedHmfiBAWZPZnMf01TbSRQojpddhWIZBwjq83pf0wefaWVWrTgjTcAK7Q=="], + + "@deepseek-ai/dsh-home-paths": ["@deepseek-ai/dsh-home-paths@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-ESeto9Jn8Ya24pm7grggkpedsqUjDjk8Atl1fUzvAJnfSTZNLVbiO37HrGmZQmf3DQKktErq7XKi58uNwHNEoQ=="], + + "@deepseek-ai/dsh-launch-environment": ["@deepseek-ai/dsh-launch-environment@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-d36DPVfA6cZlK0a8STMiXXiUGkpaNYcWPi2SZqgBbmaNKBrPa7NA4cNc2xW3M0XbG3LLuLjJvAw3yQCf3XB3kQ=="], + + "@deepseek-ai/dsh-llm": ["@deepseek-ai/dsh-llm@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-timeout": "0.2.1-alpha.2", "@deepseek-ai/dsh-typert-protocol": "0.2.1-alpha.2", "@deepseek-ai/dsh-util-crypto": "0.2.1-alpha.2", "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2", "@deepseek-ai/schemastery": "~3.18.5-alpha.1", "zod": "^4.4.3" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-+pUKWsWBZorW3nQLGAC2qEQudFOscKINR0njoPhhFhJsVPuAqLUYF3bf6G4evbMKUF1+Uw901CFHOfwLluljNQ=="], + + "@deepseek-ai/dsh-llm-deepseek": ["@deepseek-ai/dsh-llm-deepseek@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/cosmokit": "~1.8.6-alpha.1", "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2", "@deepseek-ai/schemastery": "~3.18.5-alpha.1", "eventsource-parser": "^3.1.0" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.1", "@deepseek-ai/dsh-anonymous-user-id": "0.2.1-alpha.2", "@deepseek-ai/dsh-atomic-write": "0.2.1-alpha.2", "@deepseek-ai/dsh-attachment": "0.2.1-alpha.2", "@deepseek-ai/dsh-deepseek-llm-api-extensions": "0.2.1-alpha.2", "@deepseek-ai/dsh-fs": "0.2.1-alpha.2", "@deepseek-ai/dsh-home-paths": "0.2.1-alpha.2", "@deepseek-ai/dsh-launch-environment": "0.2.1-alpha.2", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-timeout": "0.2.1-alpha.2" }, "optionalPeers": ["@deepseek-ai/cordis-plugin-loader"] }, "sha512-i6xN+90NMWVZOlxlDlhWG3+hVqGVCP6IxCYkZFwjmuMQWl24dxGrhFAQG16SA7XMF82haOo9lx4HjJB1jV1x3g=="], + + "@deepseek-ai/dsh-ptc-runtime": ["@deepseek-ai/dsh-ptc-runtime@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-sandbox": "0.2.1-alpha.2" } }, "sha512-Vd41OzP+KlE4NOi34xcDSbhm/vAMz1Vjy+60jEzX0Vf/pmvg2LNTu7nQPwf81kZOcgtHUOL2ipuRbU6Ciy32yA=="], + + "@deepseek-ai/dsh-sandbox": ["@deepseek-ai/dsh-sandbox@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2" } }, "sha512-kCzOlDplb6S19sPQ68OOZfVP7lmeA2mpHN8ihWbI/OG2YODRE4cqLd18rI2FYtQjTlcCEFA4G5HtSNTpJlAWCg=="], + + "@deepseek-ai/dsh-sandbox-policy": ["@deepseek-ai/dsh-sandbox-policy@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/schemastery": "~3.18.5-alpha.1", "zod": "^4.4.3" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-agent": "0.2.1-alpha.2", "@deepseek-ai/dsh-sandbox": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2", "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2", "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2" } }, "sha512-sKCR7U2EDvyBDUtRpCCmvqIfltNt9MGMI1nG/4fV/ZfFcLV4ll8UIoMIFt4Cj3ba058o/BJTr/yWneC2Z2SfjQ=="], + + "@deepseek-ai/dsh-scope": ["@deepseek-ai/dsh-scope@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-lDS7dKz0qm2TBAwU6cIa0OokJgvPZegdN+wAYZvA4I8wsV3RkHBfctTi+g7Fp2I2iy0C5G0SM4MVtC6JHpXiNw=="], + + "@deepseek-ai/dsh-session": ["@deepseek-ai/dsh-session@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-scope": "0.2.1-alpha.2" } }, "sha512-xINgQ8XFC40aLxPLBMxAMl3ZkY8NlkasVVrnIio94hZYX+dqw7N63y53vqLU69WKTPEFJ11GdCJq4Yx5Tr2HFA=="], + + "@deepseek-ai/dsh-session-persistence": ["@deepseek-ai/dsh-session-persistence@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2", "@deepseek-ai/dsh-timeout": "0.2.1-alpha.2" } }, "sha512-dVi0eW+U9ug6XGz/b15h5fVJBVJhEWsLFtLm8hplEKct8Yb4TdPKKhFyJ+M9NrvAPxT3Di+LelIBpaqoTxJd6w=="], + + "@deepseek-ai/dsh-session-projection": ["@deepseek-ai/dsh-session-projection@0.2.1-alpha.2", "", { "dependencies": { "zod": "^4.4.3" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-session": "0.2.1-alpha.2" } }, "sha512-rwA8TiXxvoKhPNW63Y42ClqwdiVOWIs80rCpW39S3M1yWi1gnvgtEkqeLx8+cJP08zGrS2MXQpguhoc3PzWSuw=="], + + "@deepseek-ai/dsh-system-prompt": ["@deepseek-ai/dsh-system-prompt@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/schemastery": "~3.18.5-alpha.1" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-scope": "0.2.1-alpha.2" } }, "sha512-3UqSuNpaTQWRSUEE1ygCm83dcJPkhmssmwUTRGB8jufFc3ib/7i6ktqhZZNSUQrrr/d/FQ0dsQ5wo9l/iJSKWA=="], + + "@deepseek-ai/dsh-timeout": ["@deepseek-ai/dsh-timeout@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-hgII55C+B2MWnMwP8Nv1BTCh+RbNP14EhzwMfOiwBWK08PdVHi2gdB7ZtbRprps5s2fO2gVXaclgXpnLX05hgw=="], + + "@deepseek-ai/dsh-tools": ["@deepseek-ai/dsh-tools@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-util-values": "0.2.1-alpha.2", "@deepseek-ai/schemastery": "~3.18.5-alpha.1" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-agent": "0.2.1-alpha.2", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-ptc-runtime": "0.2.1-alpha.2", "@deepseek-ai/dsh-sandbox": "0.2.1-alpha.2", "@deepseek-ai/dsh-sandbox-policy": "0.2.1-alpha.2", "@deepseek-ai/dsh-scope": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2", "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2", "@deepseek-ai/dsh-user-approval": "0.2.1-alpha.2", "@deepseek-ai/dsh-working-directory": "0.2.1-alpha.2" } }, "sha512-IbWShKABOi3ezvICVZsrG7w/mdQBmkHn0AGM4CkkYJxK38OIUELGiFa/JE6PEYO71oZQgm40xZM6kknTbss6vg=="], + + "@deepseek-ai/dsh-typert-protocol": ["@deepseek-ai/dsh-typert-protocol@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/dsh-brand": "0.2.1-alpha.2" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-L/f22tnjV9LXFOf8CaX5XmEyKXR18oRKP2X3qb/I7NrAxk5uwKZcLHCFU/LXECVXrkm/Q0MPp5iNiREG1rLfzQ=="], + + "@deepseek-ai/dsh-user-approval": ["@deepseek-ai/dsh-user-approval@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/schemastery": "~3.18.5-alpha.1" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-agent": "0.2.1-alpha.2", "@deepseek-ai/dsh-brand": "0.2.1-alpha.2", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-scope": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2", "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2" } }, "sha512-6F/j21eOW2xu4QYeXXFqYTlX1IPskwFiy4bbRdbGMCi5WEmMxgP3ZRJHX4P2GRSdVPHHQyPBLgRVOOTuitGqcw=="], + + "@deepseek-ai/dsh-util-crypto": ["@deepseek-ai/dsh-util-crypto@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-Hrm2c1H5ZOGBfviHPSEfPOg+FqagqH7PwGLoB/PVWZztQ2otw31NarPgrzSXO4cVY5fUmuoK8lsMRmgnQzs0FA=="], + + "@deepseek-ai/dsh-util-values": ["@deepseek-ai/dsh-util-values@0.2.1-alpha.2", "", { "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1" } }, "sha512-0MoZ0C8rXC+2PyxJER6ZSRfkU21/HbX4Z5oCcdC3b151epcBYQVlP/o8vjqePQAJCZwTrWAEknnJHRMWbVlh0A=="], + + "@deepseek-ai/dsh-working-directory": ["@deepseek-ai/dsh-working-directory@0.2.1-alpha.2", "", { "dependencies": { "@deepseek-ai/schemastery": "~3.18.5-alpha.1", "zod": "^4.4.3" }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.5-alpha.1", "@deepseek-ai/dsh-agent": "0.2.1-alpha.2", "@deepseek-ai/dsh-fs": "0.2.1-alpha.2", "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", "@deepseek-ai/dsh-session": "0.2.1-alpha.2", "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2", "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2" } }, "sha512-6ttLaGHK6oJRWzGuKwLKVVvjz3Xkb8Qbwx7w0PPFtKyQcpOAIbFYJV1m/MQztW81Q4Av4Up5bYszKpMfpVCs4g=="], + + "@deepseek-ai/schemastery": ["@deepseek-ai/schemastery@3.18.5", "", { "dependencies": { "@deepseek-ai/cosmokit": "~1.8.6", "@standard-schema/spec": "^1.1.0" } }, "sha512-Mnobvqf9rHsZYv4g5edj5ddxS1oF1kIdSlz0DunUgnY3LWG5F26MqvH3YOOsSaodCgyzJ16OMN9O99/s5Crtdw=="], + + "@distilled.cloud/aws4signer": ["@distilled.cloud/aws4signer@https://pkg.alchemy.run/@distilled.cloud/aws4signer/-/f431855559332a685a75715ecef5c40062b578a8a1e5f75da2f68fdffcfd54f0.tgz", { "dependencies": { "@distilled.cloud/core": "https://pkg.alchemy.run/@distilled.cloud/core/-/282cb3a5de6211e420287e36c42c55ce1c65ca123baf0acf7740aeeda5fdeacd.tgz" }, "peerDependencies": { "effect": "^4.1.4" } }, "sha512-wDpniiYmZM7dMxS9Fy/jy7dphzuFGQBJ0sg3gy9czCbFoV8kx1dukOPy/sACtTTOTj+E4mfAyAeh4DBvULvx9w=="], + + "@distilled.cloud/cloudflare": ["@distilled.cloud/cloudflare@https://pkg.alchemy.run/@distilled.cloud/cloudflare/-/55b682d9ade478c8eaa1642d38571da6487a1e0949085cc4bda60f8fb948b290.tgz", { "dependencies": { "@distilled.cloud/core": "https://pkg.alchemy.run/@distilled.cloud/core/-/282cb3a5de6211e420287e36c42c55ce1c65ca123baf0acf7740aeeda5fdeacd.tgz", "@distilled.cloud/s3": "https://pkg.alchemy.run/@distilled.cloud/s3/-/45f097fb0fccbf602f66e79609b661699f9add8a44359140147233c9db16554b.tgz" }, "peerDependencies": { "effect": "^4.1.4" } }, "sha512-tgrYYwT4B6J9ciAFBdSFlO+t5kycBz0+abRimSYHeG1lld7yuNlckTi+LUIZicovdHDLelY5nKU2hH9mjROkpw=="], + + "@distilled.cloud/core": ["@distilled.cloud/core@https://pkg.alchemy.run/@distilled.cloud/core/-/282cb3a5de6211e420287e36c42c55ce1c65ca123baf0acf7740aeeda5fdeacd.tgz", { "peerDependencies": { "effect": "^4.1.4" } }, "sha512-CA/w1mv9bPxj9r5RytOQHa/vQz2z0GwmNh/jvcaVucDVhwYo5//nEKguLhnIEUtMOUyYs3pF+dtQHMMVgxI9oQ=="], + + "@distilled.cloud/s3": ["@distilled.cloud/s3@https://pkg.alchemy.run/@distilled.cloud/s3/-/45f097fb0fccbf602f66e79609b661699f9add8a44359140147233c9db16554b.tgz", { "dependencies": { "@distilled.cloud/aws4signer": "https://pkg.alchemy.run/@distilled.cloud/aws4signer/-/f431855559332a685a75715ecef5c40062b578a8a1e5f75da2f68fdffcfd54f0.tgz", "@distilled.cloud/core": "https://pkg.alchemy.run/@distilled.cloud/core/-/282cb3a5de6211e420287e36c42c55ce1c65ca123baf0acf7740aeeda5fdeacd.tgz" }, "peerDependencies": { "effect": "^4.1.4" } }, "sha512-EZtKhqR6MraL9iUW4OUzqVKRHDcyY5S4rtvm+2zR3IBlbPTnm63FZIMwT6wxfBi/jiyXm65MZbSDezt8FpQX6Q=="], + + "@emnapi/runtime": ["@emnapi/runtime@1.11.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA=="], + + "@img/colour": ["@img/colour@1.1.0", "", {}, "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ=="], + + "@img/sharp-darwin-arm64": ["@img/sharp-darwin-arm64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-darwin-arm64": "1.3.4" }, "os": "darwin", "cpu": "arm64" }, "sha512-QRUlFQ0WxvdWyqqG/WtI3iupfD5rBzmCHXSdPsY91sAtVtTo7Q4cb6zOccZ3gqEqkr0f1As1ehLqmEpDsRf+lg=="], + + "@img/sharp-darwin-x64": ["@img/sharp-darwin-x64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-darwin-x64": "1.3.4" }, "os": "darwin", "cpu": "x64" }, "sha512-+BR255RhDlpygUpOc/Jdt1nT6DQ3XG/ERo5wbcdOf5Q320dKtPCKPLR1LJs9VGXRaMa8l1uUa0tkCNOXiAxZUw=="], + + "@img/sharp-freebsd-wasm32": ["@img/sharp-freebsd-wasm32@0.35.5", "", { "dependencies": { "@img/sharp-wasm32": "0.35.5" }, "os": "freebsd" }, "sha512-Y/z91nEZ4uIBX5X3nfTovjU9lHNKFYbL2lpHCLVNmXQK03VIZvXBBt0KxbPGp2SdGSF+2mQU4e+hQaWOt86iAw=="], + + "@img/sharp-libvips-darwin-arm64": ["@img/sharp-libvips-darwin-arm64@1.3.4", "", { "os": "darwin", "cpu": "arm64" }, "sha512-5R89nBYiRdUlSWJxPhO+GVtaXzXSxKnRu/xqMn3KTA3L9EB9Oy/P+Nn2f2vlhPuUdy/Zusb2DarbyTpGCfEDuw=="], + + "@img/sharp-libvips-darwin-x64": ["@img/sharp-libvips-darwin-x64@1.3.4", "", { "os": "darwin", "cpu": "x64" }, "sha512-iR2OKH80yi0U+dUplyh3/xdpFvps6YkCwsXenIJxqxR1v9o+xtKTGbS9H7cps+2Vxjc8B1j96p75NmTGjIhtpQ=="], + + "@img/sharp-libvips-linux-arm": ["@img/sharp-libvips-linux-arm@1.3.4", "", { "os": "linux", "cpu": "arm" }, "sha512-LmRtTsOHuvM2+wlO2Db37dx5MiZhB0FvSunciw48YjdOkZz9KAiRbm8ujeMOA1INqmei5NapFxYEK1D1ZSidmw=="], + + "@img/sharp-libvips-linux-arm64": ["@img/sharp-libvips-linux-arm64@1.3.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-Y3dgX/6lE2QhQb+Gxy0WZxfg9MEm/JBjamZpS2IklP7xIQoKN4hzAm7KcMVGtaVDt3neE9OKBC7vAfonA/Lr1A=="], + + "@img/sharp-libvips-linux-ppc64": ["@img/sharp-libvips-linux-ppc64@1.3.4", "", { "os": "linux", "cpu": "ppc64" }, "sha512-Le6boB8Tai0Nis+gIxIpKx68UDVVIqdR8Tin5Yf1z2LJJQLDJvCDRqRu+jC2qCoD+eIomonmOwB4smBRxfVpYQ=="], + + "@img/sharp-libvips-linux-riscv64": ["@img/sharp-libvips-linux-riscv64@1.3.4", "", { "os": "linux", "cpu": "none" }, "sha512-aHkkIEHPRdQEegJN20MLmGtxYD9R2wQr3Cwpddnu5+YKMt6Uzax7S9h5gpZTo8wyrGuZSlfQ63OevL5mTyOC7Q=="], + + "@img/sharp-libvips-linux-s390x": ["@img/sharp-libvips-linux-s390x@1.3.4", "", { "os": "linux", "cpu": "s390x" }, "sha512-ra/mB6MikESDUO7Yg+Mi95bFBb9GsObURuhnOv3OqknjGe9sZrG8tCe9q0xSIGrtLgvgw0gKnFWcK4blSgQOuQ=="], + + "@img/sharp-libvips-linux-x64": ["@img/sharp-libvips-linux-x64@1.3.4", "", { "os": "linux", "cpu": "x64" }, "sha512-GJ//SSXbnwSDes02umB3nDJLFcQzw8a18V8fyhqr6tV515tOEMdImjjxj1AoafMRz56F3PHgftnj1QEKSU1zkw=="], + + "@img/sharp-libvips-linuxmusl-arm64": ["@img/sharp-libvips-linuxmusl-arm64@1.3.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-hvulFwtjUcagsis6BBxHwGFwWoNZjgYmULGVrZcyfNbjA8hKILbRxGg15/7w5HDyXHXUos/j6baAWqnCyQ2DWA=="], + + "@img/sharp-libvips-linuxmusl-x64": ["@img/sharp-libvips-linuxmusl-x64@1.3.4", "", { "os": "linux", "cpu": "x64" }, "sha512-6zXKeE/p39I1AmA3cJG35eyBGNqNddLnUXjhwBnsGjFPWqf5VKkDBEqaEkPDoTEtkxwi2vv8Tcr2mDyP4So7Fg=="], + + "@img/sharp-linux-arm": ["@img/sharp-linux-arm@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linux-arm": "1.3.4" }, "os": "linux", "cpu": "arm" }, "sha512-LEaXK2WdXVK5ykcw0buWyPMsmLLL2vpHLD6yrNSW+JGEL3BZPA4tpKN6iaMc4AxTTAoaX/sU1rOL51lcIz48ZQ=="], + + "@img/sharp-linux-arm64": ["@img/sharp-linux-arm64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linux-arm64": "1.3.4" }, "os": "linux", "cpu": "arm64" }, "sha512-LYVx5JTsOM2CBzmxreh+nl64/3H6Xb09iSLknqH47z2T2DFFxDeFLP5y4dJwe6H7uGQlHPyEEtIqyo3DYsRwdQ=="], + + "@img/sharp-linux-ppc64": ["@img/sharp-linux-ppc64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linux-ppc64": "1.3.4" }, "os": "linux", "cpu": "ppc64" }, "sha512-QVxAAq8evVRI9ia2vqgwrmWucn5Dfv+JdWzj75pD8omHLPSP7f8p20O8jxzjCcuCEQEOtYOZUmX1hkiZ0kdevA=="], + + "@img/sharp-linux-riscv64": ["@img/sharp-linux-riscv64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linux-riscv64": "1.3.4" }, "os": "linux", "cpu": "none" }, "sha512-LtdreXguaavKODPIfzJ4kffx7UNt1omwtK0rch4EBbbSTXPnxWmYSayXdLJw0fJzQ97kHt1gL/yh4tvU+nCyRQ=="], + + "@img/sharp-linux-s390x": ["@img/sharp-linux-s390x@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linux-s390x": "1.3.4" }, "os": "linux", "cpu": "s390x" }, "sha512-UZasTOFiYzotTsGOCu42BfUzP6Tu6Do/947iRm1RsLKvlllxwGcn4RN27LibGWceix4Y+Pmw3jsnTcCQIgWjqA=="], + + "@img/sharp-linux-x64": ["@img/sharp-linux-x64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linux-x64": "1.3.4" }, "os": "linux", "cpu": "x64" }, "sha512-SxFtLTeJInhAA9Q836kux2vZNeOBQEx658qvbboZScr0wIARym3IcGmW7KpVD5sbVg0Ojy+udFQdayYIZyoNog=="], + + "@img/sharp-linuxmusl-arm64": ["@img/sharp-linuxmusl-arm64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linuxmusl-arm64": "1.3.4" }, "os": "linux", "cpu": "arm64" }, "sha512-9HbMclmI1zlNkFRs3z9/eBtDjfD0sGlrX1z6b1qwmiFY5ElDLh4BC0LPBdVp7z1DXFiKlIcznf+ZlsuZzLxQqg=="], + + "@img/sharp-linuxmusl-x64": ["@img/sharp-linuxmusl-x64@0.35.5", "", { "optionalDependencies": { "@img/sharp-libvips-linuxmusl-x64": "1.3.4" }, "os": "linux", "cpu": "x64" }, "sha512-4KOphqB035HrVdqLZfCgMzzERrQkkzOwRhl4OAkRO1YCldbaFjySXMaK534Mo0V+LndnlJk+sbUyLeU0ULyD1A=="], + + "@img/sharp-wasm32": ["@img/sharp-wasm32@0.35.5", "", { "dependencies": { "@emnapi/runtime": "^1.11.3" } }, "sha512-Ptsga1su4tQx+LLF1ECS9U6nz5kmrXKo6XVbtR48Ke3ZRxxgaWBu7IDtEe1quo8hiupwm6WFqxVlXaSf7IINGQ=="], + + "@img/sharp-webcontainers-wasm32": ["@img/sharp-webcontainers-wasm32@0.35.5", "", { "dependencies": { "@img/sharp-wasm32": "0.35.5" }, "cpu": "none" }, "sha512-hfhF/FmoQyTUkA0bIKFOtw536BQSeBMe6BF6QyWlrPxT754+TFLaZ7sKKTfvvM0yJgKgaYTwnFCIZ/GuDw5SUA=="], + + "@img/sharp-win32-arm64": ["@img/sharp-win32-arm64@0.35.5", "", { "os": "win32", "cpu": "arm64" }, "sha512-X4t7g+7ZA5DKblCBEXGjUqqemj4vczING/5viFwAL8h4N3qYeyjwdCvRLHi4EdOUI+2Z7UFlp1VM+p/AuEtm6Q=="], + + "@img/sharp-win32-ia32": ["@img/sharp-win32-ia32@0.35.5", "", { "os": "win32", "cpu": "ia32" }, "sha512-5Zm82LoBc43nhwNybZlG7Y1KO//Zhsn306fQl29ZOuStHLGTo3BWL83q3cznX0poxSAMuYL1On/BHBxkBeKr6A=="], + + "@img/sharp-win32-x64": ["@img/sharp-win32-x64@0.35.5", "", { "os": "win32", "cpu": "x64" }, "sha512-x76eH0vEiHlcMQu8Y8IenntaACtddpT6W0wmXtWrnKcnKI7ME5DdgqhAD6SEWOEl1v2zDvkZDhFA9KnURwpfqg=="], + + "@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.3", "", {}, "sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g=="], + + "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="], + + "@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.9", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.0.3", "@jridgewell/sourcemap-codec": "^1.4.10" } }, "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ=="], + + "@oxc-project/types": ["@oxc-project/types@0.156.0", "", {}, "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw=="], + + "@poppinss/colors": ["@poppinss/colors@4.1.6", "", { "dependencies": { "kleur": "^4.1.5" } }, "sha512-H9xkIdFswbS8n1d6vmRd8+c10t2Qe+rZITbbDHHkQixH5+2x1FDGmi/0K+WgWiqQFKPSlIYB7jlH6Kpfn6Fleg=="], + + "@poppinss/dumper": ["@poppinss/dumper@0.6.5", "", { "dependencies": { "@poppinss/colors": "^4.1.5", "@sindresorhus/is": "^7.0.2", "supports-color": "^10.0.0" } }, "sha512-NBdYIb90J7LfOI32dOewKI1r7wnkiH6m920puQ3qHUeZkxNkQiFnXVWoE6YtFSv6QOiPPf7ys6i+HWWecDz7sw=="], + + "@poppinss/exception": ["@poppinss/exception@1.2.3", "", {}, "sha512-dCED+QRChTVatE9ibtoaxc+WkdzOSjYTKi/+uacHWIsfodVfpsueo3+DKpgU5Px8qXjgmXkSvhXvSCz3fnP9lw=="], + + "@puppeteer/browsers": ["@puppeteer/browsers@3.3.0", "", { "dependencies": { "modern-tar": "^0.8.6", "yargs": "^18.0.0" }, "peerDependencies": { "proxy-agent": ">=8.0.1", "yauzl": "^2.10.0 || ^3.4.0" }, "optionalPeers": ["proxy-agent", "yauzl"], "bin": { "browsers": "lib/main-cli.js" } }, "sha512-ZiOVHQ5KmsinwZJMwRc/a3xsGHbi9dRuAyf2gq4i9J5vRaI4r7SSIaJUniF1JVClG+qNoVdtBBWfL08N9Oib6g=="], + + "@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.2.16", "", { "os": "android", "cpu": "arm" }, "sha512-ia3DwAs0OsMGS7+IConptSiyk9pEXkOx/AbJ2n/lAGxH3QkWQus1t8d7gnAT38FCU2sQu8lUbeR6AiZFv4JxaA=="], + + "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.2.16", "", { "os": "android", "cpu": "arm64" }, "sha512-kx5wBiMB6E7TEvpl2B9gjLU004BkvEm2Dr941BFjx/SontPwSzNuQUIoVKxHHoSjpFIfHMmcguyLOtyn0hObRg=="], + + "@rolldown/binding-darwin-arm64": ["@rolldown/binding-darwin-arm64@1.2.16", "", { "os": "darwin", "cpu": "arm64" }, "sha512-qslZrXnKJU4cUpjoAmtAo/KQM9e2IRMlmpig6Zpwj+8KWxW8v+nkAf9216Bsek9lOC1jvg2yCjygCFo2f83msQ=="], + + "@rolldown/binding-darwin-x64": ["@rolldown/binding-darwin-x64@1.2.16", "", { "os": "darwin", "cpu": "x64" }, "sha512-FdF+y48ND13eAyM2mQn+85kvAqNlvRWROy2rhgA463X/0Gv4vGtazZtfaF1mRBLscYvtOlh4QnLjOWiFzX69OQ=="], + + "@rolldown/binding-freebsd-x64": ["@rolldown/binding-freebsd-x64@1.2.16", "", { "os": "freebsd", "cpu": "x64" }, "sha512-ddjqFM5e95AgLbUPtKIS7V1KTVlA0RUgCVr5mn+/IEhsdy3pr+Vuj/HZ7nlMN2FyxIwUktOH1LEPIQXO1v9y1Q=="], + + "@rolldown/binding-linux-arm-gnueabihf": ["@rolldown/binding-linux-arm-gnueabihf@1.2.16", "", { "os": "linux", "cpu": "arm" }, "sha512-tHdKWbFkFBI687iim3LIyIvyL7j66VvQYkDPss5Stn/qyE2tWkR1YD0dXmXPFKKqT/o5ZEJVsaRsWS2meQwGOA=="], + + "@rolldown/binding-linux-arm64-gnu": ["@rolldown/binding-linux-arm64-gnu@1.2.16", "", { "os": "linux", "cpu": "arm64" }, "sha512-FJiLGAblPBMlBEdbOqw6kW6QcXDWAf/oJu7gYs9ZJZwmg+K+/zjFLxPTIY9izJUzxzc24FHvmseyA0IvJSl17w=="], + + "@rolldown/binding-linux-arm64-musl": ["@rolldown/binding-linux-arm64-musl@1.2.16", "", { "os": "linux", "cpu": "arm64" }, "sha512-hrJpblMsrQ58U9veWpbXzkhV5zStunds6HWLprqq1qauvgBr1E6P+24kLj6lSLI9vjRn/RYpjprhkHQPKGWpNg=="], + + "@rolldown/binding-linux-ppc64-gnu": ["@rolldown/binding-linux-ppc64-gnu@1.2.16", "", { "os": "linux", "cpu": "ppc64" }, "sha512-qJd/dC6j6CwLG9/s/RP2nb1RZ0GIgj7Ioj7x/SYa3RzjVrlzrmH0fhIOpfvqQDeIsdP0loi+kHaMhJzY1PBIaA=="], + + "@rolldown/binding-linux-s390x-gnu": ["@rolldown/binding-linux-s390x-gnu@1.2.16", "", { "os": "linux", "cpu": "s390x" }, "sha512-Vx7Xg5uUJuNcujJjI70OICaH0EYj80BtOLZTSN7uOYg8QOLlyKnaG0IW7Fn/J0IpJsaKzmDKMhOQv1JBM9m9vg=="], + + "@rolldown/binding-linux-x64-gnu": ["@rolldown/binding-linux-x64-gnu@1.2.16", "", { "os": "linux", "cpu": "x64" }, "sha512-TNKhgE3uJTsTzatUSSYt0Kgo+Oa2uSlSjz4r1aEIea7HX6ULBym4fAlYUhG1i6pjNf2njfCUAfKwr6C3E9Xg1w=="], + + "@rolldown/binding-linux-x64-musl": ["@rolldown/binding-linux-x64-musl@1.2.16", "", { "os": "linux", "cpu": "x64" }, "sha512-7chXdpjXZ8qG0+mIxECN3cT9kvhZ3/oZhMX6Pp876P7CDrIy8nJswva6Mq357JR7eYXfuskwZxMeV1SzoZdHrA=="], + + "@rolldown/binding-openharmony-arm64": ["@rolldown/binding-openharmony-arm64@1.2.16", "", { "os": "none", "cpu": "arm64" }, "sha512-Kwjt+7uNTJK5/MDkGWGVO2KQPnj8yAV75dMpfwyHZrJSXWHrniOB0aUEWlVYf3H1hOqFLIStLdM5QXq6bnKmOQ=="], + + "@rolldown/binding-wasm32-wasi": ["@rolldown/binding-wasm32-wasi@1.3.4", "", { "dependencies": { "@oxc-project/types": "0.160.0" }, "cpu": "none" }, "sha512-jwO8P3o53ygo7b5061B7BeaJ1BGv3BKZ6jroFdw/01qWry7Z+qNBlDvulzbTle5s/A0Fc1FRgsTxrke9DvsSbA=="], + + "@rolldown/binding-win32-arm64-msvc": ["@rolldown/binding-win32-arm64-msvc@1.2.16", "", { "os": "win32", "cpu": "arm64" }, "sha512-/LH6WfjDRXXJz/p5xl4TmU+jpcnwcxbKEQBW/GZE0JHfN0lGIyTtsUEGaQ/q/GikkGJ2yLKe6pwm7AnEWO8pdw=="], + + "@rolldown/binding-win32-x64-msvc": ["@rolldown/binding-win32-x64-msvc@1.2.16", "", { "os": "win32", "cpu": "x64" }, "sha512-1lv1KvX0Z871zfk7vw+dnXMMnHNyDwMzWG8Kv3HxDXMOhzCX4SHc7HK319fInP0i+0p9D8brkfzL7pJOaGl+tw=="], + + "@rolldown/pluginutils": ["@rolldown/pluginutils@1.1.1", "", {}, "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA=="], + + "@sindresorhus/is": ["@sindresorhus/is@7.2.0", "", {}, "sha512-P1Cz1dWaFfR4IR+U13mqqiGsLFf1KbayybWwdd2vfctdV6hDpUkgCY0nKOLLTMSoRd/jJNjtbqzf13K8DCCXQw=="], + + "@speed-highlight/core": ["@speed-highlight/core@1.2.24", "", {}, "sha512-qeW2e1l78afw8VhRPfPQ1Gjj+KU5XFQ/OFV5ti6eTa9bruO7mJyZtA4vw0ofqmA3tKCkROE9xLk3VZoeRc98nw=="], + + "@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="], + + "@types/chai": ["@types/chai@5.2.3", "", { "dependencies": { "@types/deep-eql": "*", "assertion-error": "^2.0.1" } }, "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA=="], + + "@types/deep-eql": ["@types/deep-eql@4.0.2", "", {}, "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw=="], + + "@types/estree": ["@types/estree@1.0.11", "", {}, "sha512-YBdNe5JcjYR0sPhJW1QIeRCmI11YhYvaRuGCs9+WCeTTb+Yhb2BE2XMe5/wAqF10FK5g3+q1PDhQABfT7aX0gg=="], + + "@types/node": ["@types/node@26.6.6", "", { "dependencies": { "undici-types": "~8.9.0" } }, "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog=="], + + "@typescript/typescript-aix-ppc64": ["@typescript/typescript-aix-ppc64@7.0.2", "", { "os": "aix", "cpu": "ppc64" }, "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ=="], + + "@typescript/typescript-darwin-arm64": ["@typescript/typescript-darwin-arm64@7.0.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA=="], + + "@typescript/typescript-darwin-x64": ["@typescript/typescript-darwin-x64@7.0.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA=="], + + "@typescript/typescript-freebsd-arm64": ["@typescript/typescript-freebsd-arm64@7.0.2", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ=="], + + "@typescript/typescript-freebsd-x64": ["@typescript/typescript-freebsd-x64@7.0.2", "", { "os": "freebsd", "cpu": "x64" }, "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw=="], + + "@typescript/typescript-linux-arm": ["@typescript/typescript-linux-arm@7.0.2", "", { "os": "linux", "cpu": "arm" }, "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ=="], + + "@typescript/typescript-linux-arm64": ["@typescript/typescript-linux-arm64@7.0.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ=="], + + "@typescript/typescript-linux-loong64": ["@typescript/typescript-linux-loong64@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ=="], + + "@typescript/typescript-linux-mips64el": ["@typescript/typescript-linux-mips64el@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA=="], + + "@typescript/typescript-linux-ppc64": ["@typescript/typescript-linux-ppc64@7.0.2", "", { "os": "linux", "cpu": "ppc64" }, "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA=="], + + "@typescript/typescript-linux-riscv64": ["@typescript/typescript-linux-riscv64@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ=="], + + "@typescript/typescript-linux-s390x": ["@typescript/typescript-linux-s390x@7.0.2", "", { "os": "linux", "cpu": "s390x" }, "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw=="], + + "@typescript/typescript-linux-x64": ["@typescript/typescript-linux-x64@7.0.2", "", { "os": "linux", "cpu": "x64" }, "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A=="], + + "@typescript/typescript-netbsd-arm64": ["@typescript/typescript-netbsd-arm64@7.0.2", "", { "os": "none", "cpu": "arm64" }, "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA=="], + + "@typescript/typescript-netbsd-x64": ["@typescript/typescript-netbsd-x64@7.0.2", "", { "os": "none", "cpu": "x64" }, "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA=="], + + "@typescript/typescript-openbsd-arm64": ["@typescript/typescript-openbsd-arm64@7.0.2", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ=="], + + "@typescript/typescript-openbsd-x64": ["@typescript/typescript-openbsd-x64@7.0.2", "", { "os": "openbsd", "cpu": "x64" }, "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg=="], + + "@typescript/typescript-sunos-x64": ["@typescript/typescript-sunos-x64@7.0.2", "", { "os": "sunos", "cpu": "x64" }, "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g=="], + + "@typescript/typescript-win32-arm64": ["@typescript/typescript-win32-arm64@7.0.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ=="], + + "@typescript/typescript-win32-x64": ["@typescript/typescript-win32-x64@7.0.2", "", { "os": "win32", "cpu": "x64" }, "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g=="], + + "@vitest/mocker": ["@vitest/mocker@5.1.1", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.31", "@vitest/spy": "5.1.1", "estree-walker": "^3.0.3", "magic-string": "^1.4.5" }, "peerDependencies": { "msw": "^2.4.9 || ^3.0.0", "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "optionalPeers": ["msw", "vite"] }, "sha512-b2OgTB4+3ImWIVafXKazJXwLKwQxUNnix6b3xUvUTMh7RyXlrtzoxfZr8aEz9zkHOMAS4K5lu3TvFWoiVeVTQg=="], + + "@vitest/spy": ["@vitest/spy@5.1.1", "", {}, "sha512-6K8C6alQG1/Yc8/ZI22iJS7JEsxPdVzqtqDq+/xM4Z0mGVykemMVjLhqMy/q6/IHYG3kKD8hKSwRen/ZdyI9vQ=="], + + "ansi-regex": ["ansi-regex@6.6.0", "", {}, "sha512-XZ5apbzreCbXSKwPjJstu8R0zOi247w3XYwWxtwBXgpZrCyc1Ka7p9/xY0A9/diMewmHbEKz+FIraWaEWjlN5g=="], + + "ansi-styles": ["ansi-styles@6.2.3", "", {}, "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg=="], + + "assertion-error": ["assertion-error@2.0.1", "", {}, "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA=="], + + "capnp-es": ["capnp-es@0.0.17", "", { "peerDependencies": { "typescript": "^5.7.3 || ^6.0.0" }, "optionalPeers": ["typescript"], "bin": { "capnp-es": "dist/compiler/capnpc-js.mjs", "capnpc-js": "dist/compiler/capnpc-js.mjs", "capnpc-ts": "dist/compiler/capnpc-ts.mjs", "capnpc-dts": "dist/compiler/capnpc-dts.mjs" } }, "sha512-uIm/Aju0TNUkL51aBbhPl/2fWsSMiqDjnTnPYyx6oCAQReGCRDl7kZPDNZFer2WhOwR9+B/72olbxUV1GgoKbw=="], + + "chai": ["chai@6.3.0", "", {}, "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg=="], + + "chokidar": ["chokidar@5.0.0", "", { "dependencies": { "readdirp": "^5.0.0" } }, "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw=="], + + "cliui": ["cliui@9.0.1", "", { "dependencies": { "string-width": "^7.2.0", "strip-ansi": "^7.1.0", "wrap-ansi": "^9.0.0" } }, "sha512-k7ndgKhwoQveBL+/1tqGJYNz097I7WOvwbmmU2AR5+magtbjPWQTS1C5vzGkBC8Ym8UWRzfKUzUUqFLypY4Q+w=="], + + "cookie": ["cookie@1.1.1", "", {}, "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ=="], + + "detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="], + + "effect": ["effect@4.1.7", "", {}, "sha512-8QUe2XO3auHF5r7+bfIDWxyXlLA0sso4Sia1QYP+vrYA7qb3sq1u2eJmhyXGmKc8yZ+TY2SNxPozeMdyKmWing=="], + + "emoji-regex": ["emoji-regex@10.6.0", "", {}, "sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A=="], + + "error-stack-parser-es": ["error-stack-parser-es@1.0.5", "", {}, "sha512-5qucVt2XcuGMcEGgWI7i+yZpmpByQ8J1lHhcL7PwqCwu9FPP3VUXzT4ltHe5i2z9dePwEHcDVOAfSnHsOlCXRA=="], + + "es-module-lexer": ["es-module-lexer@2.3.2", "", {}, "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw=="], + + "escalade": ["escalade@3.2.0", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="], + + "estree-walker": ["estree-walker@3.0.3", "", { "dependencies": { "@types/estree": "^1.0.0" } }, "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g=="], + + "eventsource-parser": ["eventsource-parser@3.1.1", "", {}, "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ=="], + + "expect-type": ["expect-type@1.4.0", "", {}, "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA=="], + + "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], + + "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], + + "get-caller-file": ["get-caller-file@2.0.5", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="], + + "get-east-asian-width": ["get-east-asian-width@1.7.0", "", {}, "sha512-XjH1AECxf0giL2V1aU8vKyRR2ppRUb5c0EvT7zuJTokQ74bNo52zOtghqdWIqrhUD79fo3x0WfKZdOqxF6LG1Q=="], + + "kleur": ["kleur@4.1.5", "", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="], + + "lightningcss": ["lightningcss@1.33.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.33.0", "lightningcss-darwin-arm64": "1.33.0", "lightningcss-darwin-x64": "1.33.0", "lightningcss-freebsd-x64": "1.33.0", "lightningcss-linux-arm-gnueabihf": "1.33.0", "lightningcss-linux-arm64-gnu": "1.33.0", "lightningcss-linux-arm64-musl": "1.33.0", "lightningcss-linux-x64-gnu": "1.33.0", "lightningcss-linux-x64-musl": "1.33.0", "lightningcss-win32-arm64-msvc": "1.33.0", "lightningcss-win32-x64-msvc": "1.33.0" } }, "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA=="], + + "lightningcss-android-arm64": ["lightningcss-android-arm64@1.33.0", "", { "os": "android", "cpu": "arm64" }, "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg=="], + + "lightningcss-darwin-arm64": ["lightningcss-darwin-arm64@1.33.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg=="], + + "lightningcss-darwin-x64": ["lightningcss-darwin-x64@1.33.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ=="], + + "lightningcss-freebsd-x64": ["lightningcss-freebsd-x64@1.33.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg=="], + + "lightningcss-linux-arm-gnueabihf": ["lightningcss-linux-arm-gnueabihf@1.33.0", "", { "os": "linux", "cpu": "arm" }, "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ=="], + + "lightningcss-linux-arm64-gnu": ["lightningcss-linux-arm64-gnu@1.33.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg=="], + + "lightningcss-linux-arm64-musl": ["lightningcss-linux-arm64-musl@1.33.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ=="], + + "lightningcss-linux-x64-gnu": ["lightningcss-linux-x64-gnu@1.33.0", "", { "os": "linux", "cpu": "x64" }, "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg=="], + + "lightningcss-linux-x64-musl": ["lightningcss-linux-x64-musl@1.33.0", "", { "os": "linux", "cpu": "x64" }, "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw=="], + + "lightningcss-win32-arm64-msvc": ["lightningcss-win32-arm64-msvc@1.33.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA=="], + + "lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.33.0", "", { "os": "win32", "cpu": "x64" }, "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA=="], + + "magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="], + + "mime": ["mime@4.1.2", "", { "bin": { "mime": "bin/cli.js" } }, "sha512-ikRzZ2RwbUVDyL9SsU0f2Phcmav4yq5r8faH5ZZKHtOZrMBLnrQOrj0uvqZ5R1uQnj+RO7Wcklw/lAf81mP9LQ=="], + + "miniflare": ["miniflare@5.20261117.0-beta", "", { "dependencies": { "@cspotcode/source-map-support": "0.8.1", "sharp": "0.35.5", "undici": "7.30.1", "workerd": "1.20261117.1", "ws": "8.21.0", "youch": "4.1.0-beta.10" }, "peerDependencies": { "kerberos": "^2.0.0" }, "optionalPeers": ["kerberos"] }, "sha512-D2ygY04wQUmbpwgBhj828piErZoj7UMlXNGr4EWQp/c1PNGHyYOh0dMIyobjwOXiD5Ifl1EaEVAoNuBHK+qtkw=="], + + "modern-tar": ["modern-tar@0.8.7", "", {}, "sha512-q17gyzLiCw2wf/Rcl5c3EA5ynB2hOHb5+qMpbaILOQBaTiBx9bumfXC5sMk0wQrVoLtlBhW77dJTnLArlczsGg=="], + + "nanoid": ["nanoid@3.3.20", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ=="], + + "napi-windows-process-start-time": ["napi-windows-process-start-time@0.1.0", "", { "os": "win32", "cpu": [ "x64", "arm64", ] }, "sha512-zHxhzKsIFu3elch3eFw69WEUGc79DFhbc3nD/WEOzWL/pFFLZRW13EHnuO0c+0YjncE5uCaS9ICHxOBXkb6vPw=="], + + "obug": ["obug@3.0.0", "", {}, "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw=="], + + "pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], + + "pend": ["pend@1.2.0", "", {}, "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg=="], + + "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], + + "picomatch": ["picomatch@4.0.7", "", {}, "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA=="], + + "postcss": ["postcss@8.5.34", "", { "dependencies": { "nanoid": "^3.3.20", "picocolors": "^1.1.1", "source-map-js": "^1.2.4" } }, "sha512-P1Qzj0XXZjMda74C7qiVnBG90UKNbyNUAOeQRBW8X63RsIMV57gevRqjnkELdwtZ/S2/uQFksJhmwuN8xShLPw=="], + + "readdirp": ["readdirp@5.1.1", "", {}, "sha512-Kko+Y5XQ6fM+Ce3dq3m9YGxnacYZYl9cA1wZjaF3Vbry2L3i1qVg8+CAgNPsXRArPMUMCaOR7oa9Nqntc43JKA=="], + + "rolldown": ["rolldown@1.2.16", "", { "dependencies": { "@oxc-project/types": "=0.156.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm-eabi": "1.2.16", "@rolldown/binding-android-arm64": "1.2.16", "@rolldown/binding-darwin-arm64": "1.2.16", "@rolldown/binding-darwin-x64": "1.2.16", "@rolldown/binding-freebsd-x64": "1.2.16", "@rolldown/binding-linux-arm-gnueabihf": "1.2.16", "@rolldown/binding-linux-arm64-gnu": "1.2.16", "@rolldown/binding-linux-arm64-musl": "1.2.16", "@rolldown/binding-linux-ppc64-gnu": "1.2.16", "@rolldown/binding-linux-s390x-gnu": "1.2.16", "@rolldown/binding-linux-x64-gnu": "1.2.16", "@rolldown/binding-linux-x64-musl": "1.2.16", "@rolldown/binding-openharmony-arm64": "1.2.16", "@rolldown/binding-win32-arm64-msvc": "1.2.16", "@rolldown/binding-win32-x64-msvc": "1.2.16" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-bWvlMpFKiTfDKfnK7FC2MPgPeWCf/Kpwsq49ApdW+FQaBZb6O6dZ4MAPbPUjp7hYQrw/RobqCzn64BRrQecGHw=="], + + "semver": ["semver@7.8.6", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw=="], + + "sharp": ["sharp@0.35.5", "", { "dependencies": { "@img/colour": "^1.1.0", "detect-libc": "^2.1.2", "semver": "^7.8.5" }, "optionalDependencies": { "@img/sharp-darwin-arm64": "0.35.5", "@img/sharp-darwin-x64": "0.35.5", "@img/sharp-freebsd-wasm32": "0.35.5", "@img/sharp-libvips-darwin-arm64": "1.3.4", "@img/sharp-libvips-darwin-x64": "1.3.4", "@img/sharp-libvips-linux-arm": "1.3.4", "@img/sharp-libvips-linux-arm64": "1.3.4", "@img/sharp-libvips-linux-ppc64": "1.3.4", "@img/sharp-libvips-linux-riscv64": "1.3.4", "@img/sharp-libvips-linux-s390x": "1.3.4", "@img/sharp-libvips-linux-x64": "1.3.4", "@img/sharp-libvips-linuxmusl-arm64": "1.3.4", "@img/sharp-libvips-linuxmusl-x64": "1.3.4", "@img/sharp-linux-arm": "0.35.5", "@img/sharp-linux-arm64": "0.35.5", "@img/sharp-linux-ppc64": "0.35.5", "@img/sharp-linux-riscv64": "0.35.5", "@img/sharp-linux-s390x": "0.35.5", "@img/sharp-linux-x64": "0.35.5", "@img/sharp-linuxmusl-arm64": "0.35.5", "@img/sharp-linuxmusl-x64": "0.35.5", "@img/sharp-webcontainers-wasm32": "0.35.5", "@img/sharp-win32-arm64": "0.35.5", "@img/sharp-win32-ia32": "0.35.5", "@img/sharp-win32-x64": "0.35.5" }, "peerDependencies": { "@types/node": "*" }, "optionalPeers": ["@types/node"] }, "sha512-Ywn4OnzGukp7CDMrp08RQ50YKmuwG47brZgIVPTvBaaAfQlRlygrRqSrxdCiL9M+LlzLBiJ68IR1QqvzHyjC7g=="], + + "source-map-js": ["source-map-js@1.3.0", "", {}, "sha512-pdUVfIWcK0kCgK831ibqkZDcL7I9zljjOu0TQFnA+fiQ6y1CYqYB7RkTOHHO45FGMg5P/Mvk/+4ToQ7gAYAL5Q=="], + + "std-env": ["std-env@4.3.0", "", {}, "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag=="], + + "string-width": ["string-width@8.3.0", "", { "dependencies": { "get-east-asian-width": "^1.5.0", "strip-ansi": "^7.1.2" } }, "sha512-ZbmZM0JCihQN91dWnxoipT2KOEyHqEyfRXUyjuRhW8b/xnqPDoq4gWEVApTVa9db2wN8mmoikgFBbjh71+cGeQ=="], + + "strip-ansi": ["strip-ansi@7.2.0", "", { "dependencies": { "ansi-regex": "^6.2.2" } }, "sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w=="], + + "supports-color": ["supports-color@10.2.2", "", {}, "sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g=="], + + "tinybench": ["tinybench@6.2.5", "", {}, "sha512-b/8GRMdnY4cqkfCLyaFpTGIv1qwfi3oT0mWaepwT++6Z/ZrYehNfZZ2JDKVLKGhNoEkS3IIB1ELtCT0XS5DtOA=="], + + "tinyexec": ["tinyexec@1.4.0", "", {}, "sha512-PV6lIcJQh57aFeJDwx16JNHmgFRh5xguzallrDW1qe8nAghYgr5MKz2K5k7wEyV/ygZhdnIAP8+HZSarHPBCsg=="], + + "tinyglobby": ["tinyglobby@0.2.17", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="], + + "tslib": ["tslib@2.9.1", "", {}, "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA=="], + + "typescript": ["typescript@7.0.2", "", { "optionalDependencies": { "@typescript/typescript-aix-ppc64": "7.0.2", "@typescript/typescript-darwin-arm64": "7.0.2", "@typescript/typescript-darwin-x64": "7.0.2", "@typescript/typescript-freebsd-arm64": "7.0.2", "@typescript/typescript-freebsd-x64": "7.0.2", "@typescript/typescript-linux-arm": "7.0.2", "@typescript/typescript-linux-arm64": "7.0.2", "@typescript/typescript-linux-loong64": "7.0.2", "@typescript/typescript-linux-mips64el": "7.0.2", "@typescript/typescript-linux-ppc64": "7.0.2", "@typescript/typescript-linux-riscv64": "7.0.2", "@typescript/typescript-linux-s390x": "7.0.2", "@typescript/typescript-linux-x64": "7.0.2", "@typescript/typescript-netbsd-arm64": "7.0.2", "@typescript/typescript-netbsd-x64": "7.0.2", "@typescript/typescript-openbsd-arm64": "7.0.2", "@typescript/typescript-openbsd-x64": "7.0.2", "@typescript/typescript-sunos-x64": "7.0.2", "@typescript/typescript-win32-arm64": "7.0.2", "@typescript/typescript-win32-x64": "7.0.2" }, "bin": { "tsc": "bin/tsc" } }, "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA=="], + + "undici": ["undici@7.30.1", "", {}, "sha512-03KrMbjIFDWQR5RNPrSw3bd1r12JpyFQl9/yxjUbJtqkjmllqC5lFjZh6ujeuJCKr8EOQvRW872Oy/az+nLYxg=="], + + "undici-types": ["undici-types@8.9.0", "", {}, "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg=="], + + "unenv": ["unenv@2.0.0-rc.25", "", { "dependencies": { "pathe": "^2.0.3" } }, "sha512-oXXwuT7VhhvYRQdoy9H0f3Qqgo6kTo0Zbh/OzUxFkeSoZ6LtovJjV9Ocd3SnmKmRLndIS8yPFxo1cJbaexhRVA=="], + + "vite": ["vite@8.4.0", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", "postcss": "^8.5.33", "rolldown": "~1.3.2", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3", "napi-windows-process-start-time": "^0.1.0" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.7.1 || ^0.8.0", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-X2nUJg+9cutlz3hzqyO6p+WTwk9H257DjwAEf9EQYUFrQbDItmetadi9gYmb+l7VDy4r3VXLUnmLTwuPmzejDw=="], + + "vitest": ["vitest@5.1.1", "", { "dependencies": { "@types/chai": "^5.2.2", "@vitest/mocker": "5.1.1", "chai": "^6.3.0", "es-module-lexer": "^2.3.2", "expect-type": "^1.4.0", "magic-string": "^1.4.5", "obug": "^3.0.0", "picomatch": "^4.0.7", "std-env": "^4.3.0", "tinybench": "^6.2.3", "tinyexec": "^1.3.1", "tinyglobby": "^0.2.17", "why-is-node-running": "3.2.1" }, "peerDependencies": { "@edge-runtime/vm": "*", "@opentelemetry/api": "^1.9.0", "@types/node": "^22.0.0 || >=24.0.0", "@vitest/browser-playwright": "5.1.1", "@vitest/browser-preview": "5.1.1", "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", "@vitest/coverage-istanbul": "5.1.1", "@vitest/coverage-v8": "5.1.1", "@vitest/ui": "5.1.1", "happy-dom": "*", "jsdom": "*", "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" }, "optionalPeers": ["@edge-runtime/vm", "@opentelemetry/api", "@types/node", "@vitest/browser-playwright", "@vitest/browser-preview", "@vitest/browser-webdriverio", "@vitest/coverage-istanbul", "@vitest/coverage-v8", "@vitest/ui", "happy-dom", "jsdom"], "bin": { "vitest": "./vitest.mjs" } }, "sha512-trVmzUFOSraCZcI3uZIMD5FqBh4atFkC/XuJP/IU7qtyQay0FCs3Ia+0QiQ2JJwGyWG/xrcBoJNel2+O7kEZ0g=="], + + "why-is-node-running": ["why-is-node-running@3.2.1", "", { "bin": { "why-is-node-running": "cli.js" } }, "sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ=="], + + "workerd": ["workerd@1.20261117.1", "", { "optionalDependencies": { "@cloudflare/workerd-darwin-64": "1.20261117.1", "@cloudflare/workerd-darwin-arm64": "1.20261117.1", "@cloudflare/workerd-linux-64": "1.20261117.1", "@cloudflare/workerd-linux-arm64": "1.20261117.1", "@cloudflare/workerd-windows-64": "1.20261117.1" }, "bin": { "workerd": "bin/workerd" } }, "sha512-iakDbGVtJRiErpWSM5fYT0z3spJ2Mo1x/POsEajBNLqUbTRwm8vMqbB7g8zPN2tzs6eZYNiO5ECyEnAXO9Foxw=="], + + "wrap-ansi": ["wrap-ansi@9.0.2", "", { "dependencies": { "ansi-styles": "^6.2.1", "string-width": "^7.0.0", "strip-ansi": "^7.1.0" } }, "sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww=="], + + "ws": ["ws@8.21.0", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g=="], + + "y18n": ["y18n@5.0.8", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="], + + "yargs": ["yargs@18.2.0", "", { "dependencies": { "cliui": "^9.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "string-width": "^8.2.1", "y18n": "^5.0.5", "yargs-parser": "^22.0.0" } }, "sha512-9OpKOLeaoNFecEp7P6iYbzze/5CqWoH7N3SMs/6y1XF4nMvFMspEGZzJ6uFi9MmQwXhyzqYoSEKO3tvA3Z/o2w=="], + + "yargs-parser": ["yargs-parser@22.0.0", "", {}, "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw=="], + + "yauzl": ["yauzl@3.4.0", "", { "dependencies": { "pend": "~1.2.0" } }, "sha512-jIH9yLR9wqr0wOS0TpBvo/g/2UgZH5qePVbjgRliiF0BYvOZyaBknKsF+x9Iht0O6sqgnB93rCICdOZFecJuDw=="], + + "youch": ["youch@4.1.0-beta.10", "", { "dependencies": { "@poppinss/colors": "^4.1.5", "@poppinss/dumper": "^0.6.4", "@speed-highlight/core": "^1.2.7", "cookie": "^1.0.2", "youch-core": "^0.3.3" } }, "sha512-rLfVLB4FgQneDr0dv1oddCVZmKjcJ6yX6mS4pU82Mq/Dt9a3cLZQ62pDBL4AUO+uVrCvtWz3ZFUL2HFAFJ/BXQ=="], + + "youch-core": ["youch-core@0.3.3", "", { "dependencies": { "@poppinss/exception": "^1.2.2", "error-stack-parser-es": "^1.0.5" } }, "sha512-ho7XuGjLaJ2hWHoK8yFnsUGy2Y5uDpqSTq1FkHLK4/oqKtyUU1AFbOOxY4IpC9f0fTLjwYbslUz0Po5BpD1wrA=="], + + "zod": ["zod@4.6.7", "", {}, "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg=="], + + "@rolldown/binding-wasm32-wasi/@oxc-project/types": ["@oxc-project/types@0.160.0", "", {}, "sha512-gw4k9syEmnckbOgw2A2FU1TBDdX9hfwV9jEn/uio65pguPzwWiXQS3OIJDMEhv9m06tj9XiEe6RoD0YA+LgreA=="], + + "@vitest/mocker/@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="], + + "@vitest/mocker/magic-string": ["magic-string@1.4.5", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.6.0" } }, "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w=="], + + "cliui/string-width": ["string-width@7.2.0", "", { "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", "strip-ansi": "^7.1.0" } }, "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ=="], + + "vite/rolldown": ["rolldown@1.3.4", "", { "dependencies": { "@oxc-project/types": "=0.160.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm-eabi": "1.3.4", "@rolldown/binding-android-arm64": "1.3.4", "@rolldown/binding-darwin-arm64": "1.3.4", "@rolldown/binding-darwin-x64": "1.3.4", "@rolldown/binding-freebsd-x64": "1.3.4", "@rolldown/binding-linux-arm-gnueabihf": "1.3.4", "@rolldown/binding-linux-arm64-gnu": "1.3.4", "@rolldown/binding-linux-arm64-musl": "1.3.4", "@rolldown/binding-linux-ppc64-gnu": "1.3.4", "@rolldown/binding-linux-s390x-gnu": "1.3.4", "@rolldown/binding-linux-x64-gnu": "1.3.4", "@rolldown/binding-linux-x64-musl": "1.3.4", "@rolldown/binding-openharmony-arm64": "1.3.4", "@rolldown/binding-wasm32-wasi": "1.3.4", "@rolldown/binding-win32-arm64-msvc": "1.3.4", "@rolldown/binding-win32-x64-msvc": "1.3.4" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-p2rq4bfBmF0M6yaR8+A89fbkBQynZI2fxUW4G07eq9kpctAkpo7q5BZ4X4Mo4XZ7HHROu33cX9PeopUFN6u+2Q=="], + + "vitest/magic-string": ["magic-string@1.4.5", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.6.0" } }, "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w=="], + + "wrap-ansi/string-width": ["string-width@7.2.0", "", { "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", "strip-ansi": "^7.1.0" } }, "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ=="], + + "vite/rolldown/@oxc-project/types": ["@oxc-project/types@0.160.0", "", {}, "sha512-gw4k9syEmnckbOgw2A2FU1TBDdX9hfwV9jEn/uio65pguPzwWiXQS3OIJDMEhv9m06tj9XiEe6RoD0YA+LgreA=="], + + "vite/rolldown/@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.3.4", "", { "os": "android", "cpu": "arm" }, "sha512-xCW8CkL/ualx/SbYqeG9iK87lJCZGDQ0soE+kaORJ0Bd+pHALyE4qK7BStmEAyYWLEzZ3/biSIpA6/7GDFvzIg=="], + + "vite/rolldown/@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.3.4", "", { "os": "android", "cpu": "arm64" }, "sha512-5lifIO+b/prcM9sx/bkPN4w6UEToEfQ3gjhx0+0neuL+dkYskI792CfAq03T51jc8JFcaYXs2hi3l8RjiH/VWQ=="], + + "vite/rolldown/@rolldown/binding-darwin-arm64": ["@rolldown/binding-darwin-arm64@1.3.4", "", { "os": "darwin", "cpu": "arm64" }, "sha512-RCgxTI4AJQxhVF//BI3ImQOsXTHrF4Eg+f99jBy8WoETA2kSEGFxpnrVmW0leQq/2aBR4R5AC6csmy3rc66e3Q=="], + + "vite/rolldown/@rolldown/binding-darwin-x64": ["@rolldown/binding-darwin-x64@1.3.4", "", { "os": "darwin", "cpu": "x64" }, "sha512-zNPJVVPUaDEj+L0lImoK3rFv2b+Z5gNijI6DWu/fcD3/1TfmRXKb9ZyxbSN+2AhlctqjbNzUvCsMa+EBhnEM4Q=="], + + "vite/rolldown/@rolldown/binding-freebsd-x64": ["@rolldown/binding-freebsd-x64@1.3.4", "", { "os": "freebsd", "cpu": "x64" }, "sha512-upP6g7ZIRy5by1RDQ/EphHIdJ5xK0eUD7sUgfZFWJ49s4XdbYsIvIlAPtrFpayR70Hhf9J22lb4Pm8/9FhrZmg=="], + + "vite/rolldown/@rolldown/binding-linux-arm-gnueabihf": ["@rolldown/binding-linux-arm-gnueabihf@1.3.4", "", { "os": "linux", "cpu": "arm" }, "sha512-SAX5C5+poMLCxu8dkPF6h5yst40rkzs+9Y3cbPn2OFSydmHjAEprrGi64zGgnYyPIVZfdGUFqJ2fJbfbnHI+mA=="], + + "vite/rolldown/@rolldown/binding-linux-arm64-gnu": ["@rolldown/binding-linux-arm64-gnu@1.3.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-nwHqdlRZS6GWBef3dG5/pMY6RNTBBUjj7s0Da+m6xsFpe7jx6IC46SLZcCu8f46JOfCovZmwnrz51EzGE+7Fyw=="], + + "vite/rolldown/@rolldown/binding-linux-arm64-musl": ["@rolldown/binding-linux-arm64-musl@1.3.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-Gr78X2ur/AgLCkmZgHffk/FerIX8S5zb/eII4bCcvJo0ANzeXhTShahdNbpnY6bpiszIAgIfiuKS9ziziWsamw=="], + + "vite/rolldown/@rolldown/binding-linux-ppc64-gnu": ["@rolldown/binding-linux-ppc64-gnu@1.3.4", "", { "os": "linux", "cpu": "ppc64" }, "sha512-o9Wcn8nWrsQasaBRYM4d//FwhlBsTJYWkPVlhlt6FwzpwEoovY4IopRZjk5Fq3+ntRuSDORJjF/nA8sFeF2q6w=="], + + "vite/rolldown/@rolldown/binding-linux-s390x-gnu": ["@rolldown/binding-linux-s390x-gnu@1.3.4", "", { "os": "linux", "cpu": "s390x" }, "sha512-UDWu4jkVcx2kiBKm3Ec//4lVCbeTWj8gmJ9SyLWCdLWtTlyq7fQVeVV/14nXvRtSLErvJ2+yA/Ux5taS31Y17Q=="], + + "vite/rolldown/@rolldown/binding-linux-x64-gnu": ["@rolldown/binding-linux-x64-gnu@1.3.4", "", { "os": "linux", "cpu": "x64" }, "sha512-W9mGtTa0w4fWh8RLMNPyaEhhcuqUfO07Q4I1bBc4PDMNg7gQSw0yPQNQ3D0qwbkXwxbyL4YrIzc8n6k1vuFExQ=="], + + "vite/rolldown/@rolldown/binding-linux-x64-musl": ["@rolldown/binding-linux-x64-musl@1.3.4", "", { "os": "linux", "cpu": "x64" }, "sha512-8B+ofyQZ7/aCmkqnyMonPr5zKLqMVNczhRGFNtdIuItiwNn8iQWJawMq2E58r7bxD1XEbtRRsULY/eCWwZQ01Q=="], + + "vite/rolldown/@rolldown/binding-openharmony-arm64": ["@rolldown/binding-openharmony-arm64@1.3.4", "", { "os": "none", "cpu": "arm64" }, "sha512-TlD0FSZaC7o2B4NCe9V5N11ugTnhzTM9ksj4sgRLvrKosDzjEkvlsTX3ehkw4ZlPv8AADimZZTvJGEa16pfXug=="], + + "vite/rolldown/@rolldown/binding-win32-arm64-msvc": ["@rolldown/binding-win32-arm64-msvc@1.3.4", "", { "os": "win32", "cpu": "arm64" }, "sha512-8adGMrNtrdzi2WD1ozhYapER59gD8Q/DV6SCKJlyG2HqULPdeQUBvMa33lTsiEYwIqTZUaIU2MmvPp5f1wbtXA=="], + + "vite/rolldown/@rolldown/binding-win32-x64-msvc": ["@rolldown/binding-win32-x64-msvc@1.3.4", "", { "os": "win32", "cpu": "x64" }, "sha512-rIMjtESdXJCIoOiUTroQ1Y1rjVDZkuUVRUxs3APX2vNv175D7TDWvzdELiIhzGq9cUNUFat+co+PTmPHPqSREg=="], + } +} diff --git a/dist/DeepSeek.d.ts b/dist/DeepSeek.d.ts new file mode 100644 index 0000000..f4eeb8d --- /dev/null +++ b/dist/DeepSeek.d.ts @@ -0,0 +1,9 @@ +import type { DeepSeekSessionOptions, DeepSeekTurn, DeepSeekTurnOutcome } from "./Types.ts"; +export type { StreamChunk } from "@deepseek-ai/dsh-llm"; +export type { DeepSeekStorage } from "./Storage.ts"; +export type { DeepSeekSessionOptions, DeepSeekTurn, DeepSeekTurnOutcome } from "./Types.ts"; +export declare const openDeepSeekSession: (options: DeepSeekSessionOptions) => Promise<{ + submit: (request: Request, signal: AbortSignal) => Promise; + settle: (request: Request, signal: AbortSignal) => Promise | null>; + abort: (operationId: string) => Promise; +}>; diff --git a/dist/DeepSeek.js b/dist/DeepSeek.js new file mode 100644 index 0000000..3514b1c --- /dev/null +++ b/dist/DeepSeek.js @@ -0,0 +1,535 @@ +var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { + if (value !== null && value !== void 0) { + if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); + var dispose, inner; + if (async) { + if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); + dispose = value[Symbol.asyncDispose]; + } + if (dispose === void 0) { + if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); + dispose = value[Symbol.dispose]; + if (async) inner = dispose; + } + if (typeof dispose !== "function") throw new TypeError("Object not disposable."); + if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; + env.stack.push({ value: value, dispose: dispose, async: async }); + } + else if (async) { + env.stack.push({ async: true }); + } + return value; +}; +var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) { + return function (env) { + function fail(e) { + env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; + env.hasError = true; + } + var r, s = 0; + function next() { + while (r = env.stack.pop()) { + try { + if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); + if (r.dispose) { + var result = r.dispose.call(r.value); + if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); + } + else s |= 1; + } + catch (e) { + fail(e); + } + } + if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); + if (env.hasError) throw env.error; + } + return next(); + }; +})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { + var e = new Error(message); + return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; +}); +import { Context } from "@deepseek-ai/cordis"; +import AgentRegistry from "@deepseek-ai/dsh-agent"; +import AgentLoop from "@deepseek-ai/dsh-agent-loop"; +import LlmRuntime, { MessageId, createAssistantMessage, createUserMessage, freezeMessage, } from "@deepseek-ai/dsh-llm"; +import { DeepSeekAdapter, DeepSeekFileStore, PUBLIC_BASE_URL, resolveAdapterOptions, } from "@deepseek-ai/dsh-llm-deepseek"; +import SessionStore, { SessionId } from "@deepseek-ai/dsh-session"; +import SessionProjection from "@deepseek-ai/dsh-session-projection"; +import SystemPrompt from "@deepseek-ai/dsh-system-prompt"; +import ToolRuntime from "@deepseek-ai/dsh-tools"; +import * as Schema from "effect/Schema"; +import { latestSegment, omitUnpublishedTurns, operationStart, segmentEvents } from "./History.js"; +import { applyToolResult, parkedModelCalls } from "./ParkedTools.js"; +import { durableSessionLog } from "./SessionLog.js"; +import { fetch as workerdFetch, withDeepSeekDispatch } from "./WorkerdTransport.js"; +const key = (operationId) => `dsh-operation:${operationId}`; +const parkedKey = (operationId) => `dsh-parked:${operationId}`; +const isDeepSeekAnonymousId = (value) => typeof value === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/u.test(value); +const decodeJsonObject = Schema.decodeUnknownSync(Schema.JsonObject); +const assistantParts = (events) => events.flatMap((event) => (event.type === "assistant/message" ? [event.data] : [])); +const usageOf = (parts) => parts.reduce((total, { usage }) => ({ + input_tokens: total.input_tokens + (usage?.inputTokens ?? 0), + output_tokens: total.output_tokens + (usage?.outputTokens ?? 0), + cache_read_input_tokens: total.cache_read_input_tokens + (usage?.cacheReadTokens ?? 0), + cache_creation_input_tokens: total.cache_creation_input_tokens + (usage?.cacheWriteTokens ?? 0), +}), { + input_tokens: 0, + output_tokens: 0, + cache_read_input_tokens: 0, + cache_creation_input_tokens: 0, +}); +const resultOf = (events) => { + const ended = events.find(({ type }) => type === "turn/end"); + if (ended?.type !== "turn/end") { + return { kind: "interrupted" }; + } + const reason = ended.data.reason; + if (reason.kind === "aborted" || reason.kind === "interrupted") { + return { kind: "interrupted" }; + } + const parts = assistantParts(events); + if (reason.kind === "error") { + return { + kind: "failed", + ...(parts.some((part) => part.usage !== undefined) ? { usage: usageOf(parts) } : {}), + }; + } + const assistant = parts.at(-1); + const text = assistant?.message.content + .flatMap((part) => (part.type === "text" ? [part.text] : [])) + .join("\n") ?? ""; + const firstChunk = assistant?.stream[0]; + const startedAt = firstChunk?.type === "chunk" ? firstChunk.time : firstChunk?.time0; + return { + kind: "finished", + text, + ...(startedAt === undefined ? {} : { startedAt }), + outputLimited: reason.kind === "max-tokens", + usage: usageOf(parts), + }; +}; +export const openDeepSeekSession = async (options) => { + const { storage } = options; + const provider = options.first.provider; + const readOperation = (operationId) => storage.kv.get(key(operationId)); + const readParked = (operationId) => { + const parked = storage.kv.get(parkedKey(operationId)); + return parked !== undefined && parked.tools.length > 0 ? parked : undefined; + }; + const id = SessionId(options.sessionId); + const host = new Context(); + await host.plugin(LlmRuntime); + await host.plugin(SessionStore); + await host.plugin(SessionProjection); + await host.plugin(SystemPrompt); + await host.plugin(ToolRuntime); + await host.plugin(AgentRegistry); + await host.plugin(durableSessionLog(storage)); + const connection = resolveAdapterOptions({ + baseURL: options.baseUrl ?? PUBLIC_BASE_URL, + defaultContextWindow: 1_000_000, + maxTokens: 8192, + models: [{ id: options.first.modelId, inputModalities: ["text"], contextWindow: 1_000_000 }], + }); + const saved = storage.kv.get("dsh-anonymous"); + const anonymousId = isDeepSeekAnonymousId(saved) ? saved : crypto.randomUUID(); + if (!isDeepSeekAnonymousId(anonymousId)) { + throw new Error("DeepSeek requires a valid anonymous client identifier."); + } + storage.kv.put("dsh-anonymous", anonymousId); + let current; + const unmetered = async function* (source) { + const iterator = source[Symbol.asyncIterator](); + try { + for (;;) { + const next = await withDeepSeekDispatch(provider, (send) => send(), () => iterator.next()); + if (next.done === true) { + return; + } + yield next.value; + } + } + finally { + await iterator.return?.(); + } + }; + const recordStream = (chunks) => { + if (current === undefined) { + throw new Error("No active turn owns the provider stream."); + } + return current.recordStream(chunks); + }; + class MeteredAdapter extends DeepSeekAdapter { + async prepareCall(...args) { + const call = await super.prepareCall(...args); + return { + ...call, + stream: (options) => recordStream(call.stream(options)), + }; + } + stream(options) { + return recordStream(super.stream(options)); + } + } + const adapter = new MeteredAdapter({ + options: () => connection, + resolveFiles: () => new DeepSeekFileStore({ fetch: workerdFetch }), + resolveAuth: async () => ({ + headers: provider === "openrouter" + ? { authorization: `Bearer ${options.apiKey ?? ""}` } + : { "x-api-key": options.apiKey ?? "" }, + }), + // The adapter only uses this stable random ID as an opaque request header. + resolveUserId: () => anonymousId, + prepareExtensions: async () => ({ fields: {}, accept: async () => { } }), + }); + host.llm.registerAdapter([provider], adapter); + await host.plugin(AgentLoop, { agents: [] }); + const agentOptions = { provider, model: options.first.modelId, maxTokens: 8192 }; + const setup = (context) => { + let attempt; + let preview; + const seenText = new Set(); + context.on("agent/assistant-stream", ({ agent, frame }) => { + const live = current; + if (live?.handle.agent !== agent) { + return; + } + if (frame.type === "start") { + attempt = frame.attemptId; + preview = undefined; + seenText.clear(); + } + if (frame.type !== "chunk" || frame.attemptId !== attempt) { + return; + } + preview ??= options.startPreview?.(live.request.operationId, frame.time); + const { chunk } = frame; + if (chunk.type === "block-start" && chunk.blockType === "reasoning") { + preview?.thinking(); + } + if (chunk.type === "text-delta") { + if (!seenText.has(chunk.index) && seenText.size > 0) { + preview?.text(chunk.index, "\n"); + } + seenText.add(chunk.index); + preview?.text(chunk.index, chunk.text); + } + }); + context.systemPrompt.section({ + name: options.sessionId, + order: 0, + interpolate: false, + complete: true, + text: () => [ + options.first.system ?? "", + current?.request.systemContext ?? "", + options.systemInstructions ?? "", + ] + .filter(Boolean) + .join("\n\n"), + }); + }; + let registrations = []; + const registerTools = (context, tools) => { + for (const release of registrations) { + release(); + } + registrations = []; + for (const tool of tools) { + registrations.push(context.tools.register({ + name: tool.name, + description: tool.description, + parameters: decodeJsonObject(tool.parameters), + output: { + schema: { type: "string" }, + render: (_, value) => [{ type: "text", text: String(value) }], + }, + execute: async (input, execution) => { + const active = current; + if (active === undefined) { + throw new Error("No DeepSeek turn owns this tool call."); + } + const { request, start } = active; + const call = { + id: execution.callId, + name: tool.name, + arguments: decodeJsonObject(input), + }; + // Persist the native assistant and tool call before the host can act on it. + await log.flush(); + const outcome = await options.tools.call(request, call, execution.signal); + if (outcome.kind === "paused") { + const parked = readParked(request.operationId); + storage.kv.put(parkedKey(request.operationId), { + start, + tools: [...(parked?.tools ?? []), { call, action: outcome.action }], + }); + execution.concludeTurn(); + return options.waitingForTool ?? "Waiting for the tool result."; + } + const { text, isError } = outcome; + if (isError) { + throw new Error(text || "Workspace tool failed."); + } + return text; + }, + })); + } + }; + const log = host.sessionPersistence; + let owner; + const openAgent = async () => (await log.stat(id)) === undefined + ? host.agents.create({ sessionId: id, agentOptions, setup }) + : host.agents.resume({ resumeSessionId: id, agentOptions, setup }); + const getAgent = () => { + owner ??= openAgent().catch((error) => { + owner = undefined; + throw error; + }); + return owner; + }; + let finishing; + const finish = (handle) => { + finishing ??= (async () => { + try { + await handle.agent.whenIdle(); + await log.flush(); + } + catch (error) { + try { + await handle.dispose(); + } + catch (disposalError) { + throw new AggregateError([error, disposalError], "DeepSeek could not release its agent.", { + cause: disposalError, + }); + } + finally { + owner = undefined; + registrations = []; + } + throw error; + } + finally { + current = undefined; + finishing = undefined; + } + })(); + return finishing; + }; + const readLog = async (offset, signal) => { + const env_1 = { stack: [], error: void 0, hasError: false }; + try { + const reader = __addDisposableResource(env_1, await log.open(id, "read", { signal }), true); + return (await reader.read(offset, -1, { signal })).events; + } + catch (e_1) { + env_1.error = e_1; + env_1.hasError = true; + } + finally { + const result_1 = __disposeResources(env_1); + if (result_1) + await result_1; + } + }; + const seedPublishedHistory = async (handle, signal) => { + const prefix = options.publishedSeed; + const receipt = "dsh-published-history-seeded"; + if (prefix === undefined || storage.kv.get(receipt) === true) { + return; + } + const existing = new Set((await readLog(0, signal)).flatMap((event) => { + if (event.type === "user/message") { + return [event.data.id]; + } + if (event.type === "assistant/message") { + return [event.data.message.id]; + } + return []; + })); + const { session } = handle.agent; + for (const { turn, user, assistant } of prefix) { + const userId = MessageId(`${options.sessionId}-history-${turn}-user`); + if (!existing.has(userId)) { + const message = createUserMessage({ + content: [{ type: "text", text: user }], + source: { kind: "user" }, + }); + session.append("user/message", freezeMessage({ ...message, id: userId }), { + surfaceOp: "append", + }); + } + const assistantId = MessageId(`${options.sessionId}-history-${turn}-assistant`); + if (!existing.has(assistantId)) { + const message = createAssistantMessage({ + content: [{ type: "text", text: assistant }], + source: { provider, model: options.first.modelId }, + }); + session.append("assistant/message", { turn: 0, step: 0, message: freezeMessage({ ...message, id: assistantId }), stream: [] }, { surfaceOp: "append" }); + } + } + await log.flush(); + storage.kv.put(receipt, true); + }; + const wake = async (handle, request, segment, message) => { + current = { + request, + handle, + start: segment.start, + recordStream: options.recordRequests?.(request, () => current?.request === request) ?? unmetered, + }; + try { + handle.agent.followup(message); + } + catch (error) { + await finish(handle); + throw error; + } + }; + const resume = async (request, operation, parked, handle, signal) => { + const events = await readLog(parked.start, signal); + const modelCalls = parkedModelCalls(events, parked); + const outcomes = await Promise.all(parked.tools.map(({ call }) => options.tools.call(request, call, signal))); + signal.throwIfAborted(); + if (outcomes.some((outcome) => outcome.kind === "paused")) { + storage.kv.put(parkedKey(request.operationId), { + ...parked, + tools: parked.tools.map(({ call }, index) => { + const outcome = outcomes[index]; + return { call, action: outcome?.kind === "paused" ? outcome.action : null }; + }), + }); + return; + } + const previous = operation.continuations ?? []; + const prepared = previous.at(-1); + const message = prepared?.preparing === true + ? freezeMessage({ + id: prepared.messageId, + role: "user", + content: [], + source: { kind: "user" }, + }) + : createUserMessage({ content: [], source: { kind: "user" } }); + const segment = { + start: prepared?.preparing === true ? prepared.start : handle.agent.session.seq, + messageId: message.id, + }; + const prefix = prepared?.preparing === true ? previous.slice(0, -1) : previous; + // Keep the same cursor and wake identity if a restart interrupts preparation. + storage.kv.put(key(request.operationId), { + ...operation, + continuations: [...prefix, { ...segment, preparing: true }], + }); + for (const [index, modelCall] of modelCalls.entries()) { + const outcome = outcomes[index]; + if (outcome?.kind !== "result") { + throw new Error("DeepSeek did not receive a result for a parked tool."); + } + applyToolResult(handle.agent.session, events, modelCall, outcome); + } + await finish(handle); + signal.throwIfAborted(); + // The next native request can start only after all tool results are durable. + storage.transactionSync(() => { + storage.kv.put(key(request.operationId), { + ...operation, + continuations: [...prefix, segment], + }); + storage.kv.put(parkedKey(request.operationId), { + ...parked, + tools: [], + }); + }); + // An empty user message wakes the native loop and has no blocks on the wire. + await wake(handle, request, segment, message); + }; + return { + submit: async (request, signal) => { + signal.throwIfAborted(); + const operation = readOperation(request.operationId); + const parked = readParked(request.operationId); + if (options.apiKey === null || (operation !== undefined && parked === undefined)) { + return; + } + // Schedule recovery before publishing the start cursor or entering model code. + await storage.setAlarm(Date.now() + 5000); + signal.throwIfAborted(); + const opening = getAgent(); + const handle = await opening; + const tools = await options.tools.list(request, signal); + signal.throwIfAborted(); + if (current !== undefined || owner !== opening) { + throw new Error("The DeepSeek agent is not available for submission."); + } + registerTools(handle.agent.ctx, tools); + if (operation !== undefined) { + if (typeof operation !== "number" && parked !== undefined) { + await resume(request, operation, parked, handle, signal); + } + return; + } + const unpublished = request.unpublishedOperationIds.flatMap((operationId) => { + const old = readOperation(operationId); + return old === undefined ? [] : [old]; + }); + const offset = unpublished.reduce((earliest, old) => { + return Math.min(earliest, operationStart(old)); + }, handle.agent.session.seq); + const history = unpublished.length === 0 ? [] : await readLog(offset, signal); + signal.throwIfAborted(); + if (readOperation(request.operationId) !== undefined) { + return; + } + if (current !== undefined || owner !== opening) { + throw new Error("The DeepSeek agent is not available for submission."); + } + omitUnpublishedTurns(handle.agent.session, history, offset, unpublished); + await seedPublishedHistory(handle, signal); + signal.throwIfAborted(); + const message = createUserMessage({ + content: [{ type: "text", text: request.text }], + source: { kind: "user" }, + }); + const segment = { start: handle.agent.session.seq, messageId: message.id }; + storage.kv.put(key(request.operationId), segment); + await wake(handle, request, segment, message); + }, + settle: async (request, signal) => { + if (options.apiKey === null) { + return { kind: "missing-credentials" }; + } + const operation = readOperation(request.operationId); + if (operation === undefined) { + return null; + } + if (current?.request.operationId === request.operationId) { + await finish(current.handle); + } + else { + // Opening a fresh owner repairs an incomplete turn in the saved log. + await getAgent(); + } + const segment = latestSegment(operation); + const offset = operationStart(segment); + const nativeEvents = segmentEvents(await readLog(offset, signal), offset, segment); + const parked = readParked(request.operationId); + const calls = parked?.tools.flatMap(({ action }) => (action === null ? [] : [action])) ?? []; + return calls.length > 0 + ? { kind: "paused", calls, usage: usageOf(assistantParts(nativeEvents)) } + : resultOf(nativeEvents); + }, + abort: async (operationId) => { + if (current?.request.operationId === operationId) { + const { handle } = current; + handle.agent.cancel({ kind: "user" }); + await finish(handle); + } + return true; + }, + }; +}; diff --git a/dist/History.d.ts b/dist/History.d.ts new file mode 100644 index 0000000..a48d9d9 --- /dev/null +++ b/dist/History.d.ts @@ -0,0 +1,15 @@ +import type { MessageId } from "@deepseek-ai/dsh-llm"; +import type { Session, SessionEvent } from "@deepseek-ai/dsh-session"; +export interface DeepSeekSegment { + readonly start: number; + readonly messageId: MessageId; + readonly preparing?: true; +} +export type DeepSeekOperation = number | (DeepSeekSegment & { + readonly continuations?: ReadonlyArray; +}); +export declare const latestSegment: (operation: DeepSeekOperation) => number | DeepSeekSegment; +export declare const operationStart: (operation: DeepSeekOperation) => number; +export declare const segmentEvents: (events: ReadonlyArray, offset: number, operation: number | DeepSeekSegment) => ReadonlyArray; +/** Shadow unpublished turns in DSH's model projection while retaining their log. */ +export declare const omitUnpublishedTurns: (session: Session, events: ReadonlyArray, offset: number, operations: ReadonlyArray) => void; diff --git a/dist/History.js b/dist/History.js new file mode 100644 index 0000000..b0910c3 --- /dev/null +++ b/dist/History.js @@ -0,0 +1,92 @@ +import { createSystemMessage } from "@deepseek-ai/dsh-llm"; +export const latestSegment = (operation) => typeof operation === "number" ? operation : (operation.continuations?.at(-1) ?? operation); +export const operationStart = (operation) => typeof operation === "number" ? operation : operation.start; +export const segmentEvents = (events, offset, operation) => { + const start = operationStart(operation) - offset; + const messageId = typeof operation === "number" ? undefined : operation.messageId; + // Outcome replacements are appended before the continuation wakes the loop. + // Keep those rows even when a cancelled continuation has no native input. + let nativeStart = start; + let started = false; + for (let index = start; index < events.length; index++) { + const event = events[index]; + if (event === undefined) { + return []; + } + if (event.type === "turn/end") { + return events.slice(start, index + 1); + } + if (event.type === "turn/start") { + if (started) { + return events.slice(start, index); + } + nativeStart = index; + started = true; + } + if (messageId !== undefined && + event.type === "user/message" && + event.data.source.kind === "user" && + event.data.id !== messageId) { + // A later turn can reuse the log offset of an operation whose first write failed. + return events.slice(start, nativeStart); + } + } + return events.slice(start); +}; +const operationEvents = (events, offset, operation) => { + const first = segmentEvents(events, offset, operation); + return typeof operation === "number" + ? first + : [ + ...first, + ...(operation.continuations ?? []).flatMap((segment) => segmentEvents(events, offset, segment)), + ]; +}; +/** Shadow unpublished turns in DSH's model projection while retaining their log. */ +export const omitUnpublishedTurns = (session, events, offset, operations) => { + const omitted = new Map(); + for (const operation of operations) { + const owned = operationEvents(events, offset, operation); + const step = owned.find((event) => event.type === "step/start"); + if (step === undefined) { + continue; + } + for (const event of owned) { + if (event.surfaceOp !== undefined && session.deriveEventMessage(event) !== null) { + omitted.set(event.seq, step.data); + } + } + } + if (omitted.size === 0) { + return; + } + const nodes = [...session.surface.nodes]; + let group; + const replace = () => { + if (group === undefined) { + return; + } + const { step, start, nodes } = group; + // DSH projects an empty system message to no model input. The logged + // replacement also invalidates the upstream request series. + session.append("system/message", { ...step, message: createSystemMessage("") }, { + surfaceOp: { op: "replace", startSeq: start, endSeq: nodes.at(-1) ?? start }, + sourceEventSeqs: nodes, + }); + group = undefined; + }; + for (const [index, seq] of nodes.entries()) { + const step = omitted.get(seq); + if (step === undefined) { + replace(); + continue; + } + group ??= { step, start: seq, nodes: [] }; + group.nodes.push(seq); + // The protected system prompt at the head permits only a single-node edit. + if (index === 0) { + replace(); + } + } + replace(); +}; diff --git a/dist/OpenRouterMessages.d.ts b/dist/OpenRouterMessages.d.ts new file mode 100644 index 0000000..abfa597 --- /dev/null +++ b/dist/OpenRouterMessages.d.ts @@ -0,0 +1,2 @@ +export declare const openRouterMessagesInit: (input: RequestInit) => RequestInit; +export declare const openRouterMessagesResponse: (response: Response) => Response; diff --git a/dist/OpenRouterMessages.js b/dist/OpenRouterMessages.js new file mode 100644 index 0000000..601556e --- /dev/null +++ b/dist/OpenRouterMessages.js @@ -0,0 +1,99 @@ +import { createParser } from "eventsource-parser"; +import * as Option from "effect/Option"; +import * as Schema from "effect/Schema"; +const MAX_MESSAGES_EVENT_BYTES = 8 * 1024 * 1024; +const isObject = Schema.is(Schema.JsonObject); +const decodeObject = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.JsonObject)); +const withField = (object, key, value) => Object.fromEntries([...Object.entries(object), [key, value]]); +export const openRouterMessagesInit = (input) => { + if (typeof input.body !== "string") { + throw new TypeError("The DeepSeek SDK must send a JSON Messages request."); + } + const payload = Option.getOrUndefined(decodeObject(input.body)); + if (payload === undefined) { + throw new TypeError("The DeepSeek SDK sent an invalid Messages request."); + } + const thinking = payload["thinking"]; + const headers = new Headers(input.headers); + headers.delete("x-deepseek-harness-user-id"); + headers.delete("x-deepseek-harness-session-id"); + if (!isObject(thinking) || thinking["type"] !== "enabled") { + return { ...input, headers }; + } + headers.delete("content-length"); + // OpenRouter requires the adaptive variant to receive effort without a token budget. + return { + ...input, + headers, + body: JSON.stringify(withField(payload, "thinking", withField(thinking, "type", "adaptive"))), + }; +}; +const normalizedData = (data) => { + const event = Option.getOrUndefined(decodeObject(data)); + const kind = event?.["type"]; + if (event === undefined || (kind !== "message_start" && kind !== "message_delta")) { + return data; + } + const parent = kind === "message_start" ? event["message"] : event; + if (!isObject(parent)) { + return data; + } + const usage = parent["usage"]; + if (!isObject(usage)) { + return data; + } + const cacheRead = usage["cache_read_input_tokens"]; + const cacheWrite = usage["cache_creation_input_tokens"]; + if (cacheRead !== null && cacheWrite !== null) { + return data; + } + // The SDK accepts absent optional counters and rejects null counters. + const normalized = Object.fromEntries(Object.entries(usage).filter(([key, value]) => value !== null || + (key !== "cache_read_input_tokens" && key !== "cache_creation_input_tokens"))); + return JSON.stringify(parent === event + ? withField(event, "usage", normalized) + : withField(event, "message", withField(parent, "usage", normalized))); +}; +export const openRouterMessagesResponse = (response) => { + if (!response.ok || + response.body === null || + response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() !== + "text/event-stream") { + return response; + } + let parser; + const body = response.body + .pipeThrough(new TextDecoderStream("utf8", { fatal: true })) + .pipeThrough(new TransformStream({ + start(controller) { + parser = createParser({ + maxBufferSize: MAX_MESSAGES_EVENT_BYTES, + onComment: (comment) => controller.enqueue(`: ${comment}\n`), + onRetry: (delay) => controller.enqueue(`retry: ${delay}\n`), + onEvent: ({ id, event, data }) => { + const fields = [ + ...(id === undefined ? [] : [`id: ${id}`]), + ...(event === undefined ? [] : [`event: ${event}`]), + ...normalizedData(data) + .split("\n") + .map((line) => `data: ${line}`), + ]; + controller.enqueue(fields.join("\n") + "\n\n"); + }, + onError: (error) => { + if (error.type === "max-buffer-size-exceeded") { + throw error; + } + }, + }); + }, + transform(chunk) { + parser.feed(chunk); + }, + })) + .pipeThrough(new TextEncoderStream()); + const headers = new Headers(response.headers); + headers.delete("content-length"); + headers.delete("content-encoding"); + return new Response(body, { status: response.status, statusText: response.statusText, headers }); +}; diff --git a/dist/ParkedTools.d.ts b/dist/ParkedTools.d.ts new file mode 100644 index 0000000..96e46cb --- /dev/null +++ b/dist/ParkedTools.d.ts @@ -0,0 +1,14 @@ +import type { Session, SessionEvent } from "@deepseek-ai/dsh-session"; +import type { DeepSeekToolCall } from "./Types.ts"; +export interface ParkedTools { + readonly start: number; + readonly tools: ReadonlyArray<{ + readonly call: DeepSeekToolCall; + readonly action: Action | null; + }>; +} +export declare const parkedModelCalls: (events: ReadonlyArray, parked: ParkedTools) => ReadonlyArray>; +export declare const applyToolResult: (session: Session, events: ReadonlyArray, modelCall: SessionEvent<"tool/call">, result: { + readonly text: string; + readonly isError: boolean; +}) => void; diff --git a/dist/ParkedTools.js b/dist/ParkedTools.js new file mode 100644 index 0000000..c6dd023 --- /dev/null +++ b/dist/ParkedTools.js @@ -0,0 +1,45 @@ +import { createSystemMessage, createToolResultMessage } from "@deepseek-ai/dsh-llm"; +export const parkedModelCalls = (events, parked) => parked.tools.map(({ call }) => { + const modelCall = events.findLast((event) => event.seq >= parked.start && + event.type === "tool/call" && + event.data.callId === call.id && + event.data.name === call.name); + if (modelCall?.type !== "tool/call") { + throw new Error("A parked DeepSeek tool has no durable model call."); + } + return modelCall; +}); +export const applyToolResult = (session, events, modelCall, result) => { + const slots = events.filter((event) => event.type === "tool/result" && + event.data.message.toolCallId === modelCall.data.callId && + event.sourceEventSeqs?.includes(modelCall.seq) === true); + if (slots.some((event) => { + const meta = event.type === "tool/result" ? event.data.meta : undefined; + return (typeof meta === "object" && + meta !== null && + "checkfu_parked_result" in meta && + meta.checkfu_parked_result === true); + })) { + return; + } + const placeholder = slots.find((event) => session.surface.nodes.includes(event.seq)); + const { turn, step, callId } = modelCall.data; + if (placeholder !== undefined) { + // A native tool-result rewrite preserves the original error flag. Shadow + // the placeholder and append the actual grouped result with its own flag. + session.append("system/message", { turn, step, message: createSystemMessage("") }, { + surfaceOp: { op: "replace", startSeq: placeholder.seq, endSeq: placeholder.seq }, + sourceEventSeqs: [placeholder.seq], + }); + } + session.append("tool/result", { + turn, + step, + message: createToolResultMessage({ + callId, + content: [{ type: "text", text: result.text }], + isError: result.isError, + }), + meta: { checkfu_parked_result: true }, + }, { surfaceOp: "append", sourceEventSeqs: [modelCall.seq] }); +}; diff --git a/dist/SessionLog.d.ts b/dist/SessionLog.d.ts new file mode 100644 index 0000000..00a25ce --- /dev/null +++ b/dist/SessionLog.d.ts @@ -0,0 +1,4 @@ +import type { Context } from "@deepseek-ai/cordis"; +import { SessionPersistence } from "@deepseek-ai/dsh-session-persistence"; +import type { DeepSeekStorage } from "./Storage.ts"; +export declare const durableSessionLog: (storage: DeepSeekStorage) => new (ctx: Context) => SessionPersistence; diff --git a/dist/SessionLog.js b/dist/SessionLog.js new file mode 100644 index 0000000..40430bb --- /dev/null +++ b/dist/SessionLog.js @@ -0,0 +1,143 @@ +import { SessionLogOffset } from "@deepseek-ai/dsh-session"; +import { SessionAlreadyExistsError, SessionAlreadyOwnedError, SessionHandleClosedError, SessionPersistence, SessionPersistenceNotFoundError, SessionPersistenceRevision, SessionReadOnlyError, assertContiguous, materializeAppendBatch, materializeCreateHeader, } from "@deepseek-ai/dsh-session-persistence"; +const key = (id) => `dsh-log:${id}`; +const eventKey = (id, index) => `dsh-event:${id}:${index}`; +const stat = (head) => ({ + header: head.header, + revision: SessionPersistenceRevision(String(head.next)), + eventCount: head.next, +}); +export const durableSessionLog = (storage) => { + const readHead = (id) => storage.kv.get(key(id)); + const owners = new Set(); + const writeFailures = new Map(); + const store = (id, events) => { + const batch = materializeAppendBatch(events); + storage.transactionSync(() => { + const head = readHead(id); + if (head === undefined) { + throw new SessionPersistenceNotFoundError(id); + } + assertContiguous(id, batch, head.next); + for (const event of batch) { + storage.kv.put(eventKey(id, event.seq), event); + } + storage.kv.put(key(id), { header: head.header, next: head.next + batch.length }); + }); + }; + const flush = async () => { + if (writeFailures.size > 0) { + throw new AggregateError([...writeFailures.values()], "DeepSeek session event write failed."); + } + await storage.sync(); + }; + const open = (header, access) => { + const id = header.id; + if (access === "write") { + if (owners.has(id)) { + throw new SessionAlreadyOwnedError(id); + } + owners.add(id); + } + let closed = false; + const check = (operation, signal) => { + signal?.throwIfAborted(); + if (closed) { + throw new SessionHandleClosedError(id, operation); + } + if (operation !== "read" && access !== "write") { + throw new SessionReadOnlyError(id, operation); + } + }; + const close = async () => { + if (!closed && access === "write") { + owners.delete(id); + writeFailures.delete(id); + } + closed = true; + }; + return { + id, + header, + access, + inheritedEventCount: SessionLogOffset(0), + read: async (offset = 0, length = -1, options) => { + check("read", options?.signal); + const head = readHead(id); + if (head === undefined) { + throw new SessionPersistenceNotFoundError(id); + } + const end = length === -1 ? head.next : Math.min(head.next, offset + length); + const events = []; + for (let index = offset; index < end; index++) { + const event = storage.kv.get(eventKey(id, index)); + if (event === undefined) { + throw new Error("DeepSeek session log has a gap."); + } + events.push(event); + } + return { events, eventState: "detached" }; + }, + append: async (events, options) => { + check("append", options?.signal); + store(id, events); + }, + flush: async (options) => { + check("flush", options?.signal); + await flush(); + }, + close, + [Symbol.asyncDispose]: close, + }; + }; + return class DurableSessionLog extends SessionPersistence { + static inject = ["sessions"]; + constructor(ctx) { + super(ctx); + ctx.on("session/event", (session, event) => { + if (owners.has(session.id) && !writeFailures.has(session.id)) { + try { + store(session.id, [event]); + } + catch (error) { + writeFailures.set(session.id, error); + } + } + }); + ctx.on("session/flush", () => flush()); + } + async create(header, options) { + options?.signal?.throwIfAborted(); + if (header.isSeeded || (options?.inheritedEventCount ?? 0) !== 0) { + throw new Error("The DeepSeek Durable Object runtime does not create forked sessions."); + } + if (readHead(header.id) !== undefined) { + throw new SessionAlreadyExistsError(header.id); + } + const copy = materializeCreateHeader(header); + storage.kv.put(key(copy.id), { header: copy, next: 0 }); + return open(copy, "write"); + } + async open(id, access, options) { + options?.signal?.throwIfAborted(); + const head = readHead(id); + if (head === undefined) { + throw new SessionPersistenceNotFoundError(id); + } + return open(head.header, access); + } + async flush() { + await flush(); + } + async stat(id, options) { + options?.signal?.throwIfAborted(); + const head = readHead(id); + return head === undefined ? undefined : stat(head); + } + async list(options) { + options?.signal?.throwIfAborted(); + const rows = await storage.list({ prefix: "dsh-log:" }); + return [...rows.values()].map(stat); + } + }; +}; diff --git a/dist/Storage.d.ts b/dist/Storage.d.ts new file mode 100644 index 0000000..129f816 --- /dev/null +++ b/dist/Storage.d.ts @@ -0,0 +1,13 @@ +/** The subset of a SQLite-backed Durable Object's storage used by one runtime. */ +export interface DeepSeekStorage { + readonly kv: { + readonly get: (key: string) => Value | undefined; + readonly put: (key: string, value: Value) => void; + }; + readonly list: (options: { + prefix: string; + }) => Promise>; + readonly sync: () => Promise; + readonly transactionSync: (transaction: () => Value) => Value; + readonly setAlarm: (time: number) => Promise; +} diff --git a/dist/Storage.js b/dist/Storage.js new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/Storage.js @@ -0,0 +1 @@ +export {}; diff --git a/dist/Types.d.ts b/dist/Types.d.ts new file mode 100644 index 0000000..5f21549 --- /dev/null +++ b/dist/Types.d.ts @@ -0,0 +1,78 @@ +import type { StreamChunk } from "@deepseek-ai/dsh-llm"; +import type * as Schema from "effect/Schema"; +import type { DeepSeekStorage } from "./Storage.ts"; +export interface DeepSeekTurn { + readonly operationId: string; + readonly provider: string; + readonly modelId: string; + readonly system: string | null; + readonly systemContext?: string; + readonly text: string; + readonly unpublishedOperationIds: ReadonlyArray; +} +interface TranscriptTurn { + readonly turn: number; + readonly user: string; + readonly assistant: string; +} +interface DeepSeekTool { + readonly name: string; + readonly description: string; + readonly parameters: unknown; +} +export interface DeepSeekToolCall { + readonly id: string; + readonly name: string; + readonly arguments: Schema.JsonObject; +} +type DeepSeekToolOutcome = { + readonly kind: "result"; + readonly text: string; + readonly isError: boolean; +} | { + readonly kind: "paused"; + readonly action: Action; +}; +interface Preview { + readonly text: (part: number, delta: string) => void; + readonly thinking: () => void; +} +interface Usage { + readonly input_tokens: number; + readonly output_tokens: number; + readonly cache_read_input_tokens: number; + readonly cache_creation_input_tokens: number; +} +export type DeepSeekTurnOutcome = { + readonly kind: "finished"; + readonly text: string; + readonly startedAt?: number; + readonly outputLimited: boolean; + readonly usage: Usage; +} | { + readonly kind: "paused"; + readonly calls: ReadonlyArray; + readonly usage: Usage; +} | { + readonly kind: "failed"; + readonly usage?: Usage; +} | { + readonly kind: "interrupted" | "missing-credentials"; +}; +export interface DeepSeekSessionOptions { + readonly storage: DeepSeekStorage; + readonly sessionId: string; + readonly first: Request; + readonly publishedSeed?: ReadonlyArray; + readonly systemInstructions?: string; + readonly waitingForTool?: string; + readonly tools: { + readonly list: (request: Request, signal: AbortSignal) => Promise>; + readonly call: (request: Request, call: DeepSeekToolCall, signal: AbortSignal) => Promise>; + }; + readonly startPreview?: (operationId: string, timestamp: number) => Preview | undefined; + readonly apiKey: string | null; + readonly baseUrl: string | null; + readonly recordRequests?: (request: Request, active: () => boolean) => (source: AsyncIterable) => AsyncIterable; +} +export {}; diff --git a/dist/Types.js b/dist/Types.js new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/Types.js @@ -0,0 +1 @@ +export {}; diff --git a/dist/WorkerdBuild.d.ts b/dist/WorkerdBuild.d.ts new file mode 100644 index 0000000..bd42648 --- /dev/null +++ b/dist/WorkerdBuild.d.ts @@ -0,0 +1,9 @@ +/** Add to the Worker bundler's input plugins to use the published SDK on workerd. */ +export declare const deepSeekWorkerdBuild: { + name: string; + resolveId: { + order: "pre"; + handler(source: string, importer?: string): string | undefined; + }; + transform(code: string, id: string): string | undefined; +}; diff --git a/dist/WorkerdBuild.js b/dist/WorkerdBuild.js new file mode 100644 index 0000000..154d771 --- /dev/null +++ b/dist/WorkerdBuild.js @@ -0,0 +1,21 @@ +import { fileURLToPath } from "node:url"; +const transport = "deepseek-durable-objects:workerd-transport"; +const llmEntry = "/@deepseek-ai/dsh-llm/lib/index.js"; +const providerEntry = "/@deepseek-ai/dsh-llm-deepseek/lib/index.js"; +/** Add to the Worker bundler's input plugins to use the published SDK on workerd. */ +export const deepSeekWorkerdBuild = { + name: "deepseek-durable-objects-workerd", + resolveId: { + order: "pre", + handler(source, importer) { + if (source === transport || (source === "node:module" && importer?.endsWith(llmEntry))) { + return fileURLToPath(new URL("./WorkerdTransport.js", import.meta.url)); + } + }, + }, + transform(code, id) { + if (id.endsWith(providerEntry)) { + return `import { fetch } from ${JSON.stringify(transport)};\n${code}`; + } + }, +}; diff --git a/dist/WorkerdTransport.d.ts b/dist/WorkerdTransport.d.ts new file mode 100644 index 0000000..a09b667 --- /dev/null +++ b/dist/WorkerdTransport.d.ts @@ -0,0 +1,8 @@ +export type DeepSeekDispatch = (send: () => Promise, signal?: AbortSignal | null) => Promise; +export declare const withDeepSeekDispatch: (provider: string, dispatch: DeepSeekDispatch, read: () => Value) => Value; +/** The bundled LLM package reads its version through Node's createRequire. */ +export declare const createRequire: () => (specifier: string) => { + version: string; +}; +/** Preserve the provider's redirect refusal on Workers, which rejects redirect: "error". */ +export declare const fetch: typeof globalThis.fetch; diff --git a/dist/WorkerdTransport.js b/dist/WorkerdTransport.js new file mode 100644 index 0000000..0043f89 --- /dev/null +++ b/dist/WorkerdTransport.js @@ -0,0 +1,41 @@ +import manifest from "@deepseek-ai/dsh-llm/package.json" with { type: "json" }; +import { openRouterMessagesInit, openRouterMessagesResponse } from "./OpenRouterMessages.js"; +import { AsyncLocalStorage } from "node:async_hooks"; +const modelDispatch = new AsyncLocalStorage(); +export const withDeepSeekDispatch = (provider, dispatch, read) => modelDispatch.run({ provider, dispatch }, read); +/** The bundled LLM package reads its version through Node's createRequire. */ +export const createRequire = () => (specifier) => { + if (specifier !== "../package.json") { + throw new TypeError("Unsupported DeepSeek LLM manifest import."); + } + return { version: manifest.version }; +}; +/** Preserve the provider's redirect refusal on Workers, which rejects redirect: "error". */ +export const fetch = async (input, init) => { + const send = async (options) => { + const response = await globalThis.fetch(input, { ...options, redirect: "manual" }); + if (response.redirected || + response.type === "opaqueredirect" || + (response.status >= 300 && response.status < 400)) { + void response.body?.cancel().catch(() => undefined); + throw new TypeError("DeepSeek provider redirects are not allowed."); + } + return response; + }; + const request = typeof input === "object" && "method" in input ? input : undefined; + const method = (init?.method ?? request?.method ?? "GET").toUpperCase(); + const url = new URL(typeof input === "object" && "url" in input ? input.url : String(input)); + if (method !== "POST" || !url.pathname.endsWith("/messages")) { + return send(init); + } + const requestScope = modelDispatch.getStore(); + if (requestScope === undefined) { + throw new Error("No active turn owns the provider request."); + } + const openRouter = requestScope.provider === "openrouter"; + const options = openRouter ? openRouterMessagesInit(init ?? {}) : init; + return requestScope.dispatch(async () => { + const response = await send(options); + return openRouter ? openRouterMessagesResponse(response) : response; + }, init?.signal ?? request?.signal); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..4ecb99e --- /dev/null +++ b/package.json @@ -0,0 +1,61 @@ +{ + "name": "deepseek-durable-objects", + "version": "0.0.1", + "description": "DeepSeek agent sessions for SQLite-backed Cloudflare Durable Objects.", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/checkfu/deepseek-durable-objects.git" + }, + "files": [ + "dist" + ], + "type": "module", + "sideEffects": false, + "exports": { + ".": { + "types": "./dist/DeepSeek.d.ts", + "import": "./dist/DeepSeek.js" + }, + "./transport": { + "types": "./dist/WorkerdTransport.d.ts", + "import": "./dist/WorkerdTransport.js" + }, + "./workerd": { + "types": "./dist/WorkerdBuild.d.ts", + "import": "./dist/WorkerdBuild.js" + } + }, + "scripts": { + "build": "bun scripts/build.mjs", + "typecheck": "tsc --noEmit", + "test": "vitest run --pool=threads --no-allowOnly", + "verify": "bun run build && bun run typecheck && bun run test" + }, + "dependencies": { + "@deepseek-ai/cordis": "4.0.5-alpha.1", + "@deepseek-ai/dsh-agent": "0.2.1-alpha.2", + "@deepseek-ai/dsh-agent-loop": "0.2.1-alpha.2", + "@deepseek-ai/dsh-llm": "0.2.1-alpha.2", + "@deepseek-ai/dsh-llm-deepseek": "0.2.1-alpha.2", + "@deepseek-ai/dsh-session": "0.2.1-alpha.2", + "@deepseek-ai/dsh-session-persistence": "0.2.1-alpha.2", + "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2", + "@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2", + "@deepseek-ai/dsh-tools": "0.2.1-alpha.2", + "effect": "4.1.7", + "eventsource-parser": "3.1.1" + }, + "devDependencies": { + "@alchemy.run/cloudflare-runtime": "https://pkg.alchemy.run/@alchemy.run/cloudflare-runtime/-/cbd8cd35b9e50ad07d3af4a8f666da46e05f95659a5f580b62ec46a0dcde67ba.tgz", + "@types/node": "26.6.6", + "miniflare": "5.20261117.0-beta", + "rolldown": "1.2.16", + "typescript": "7.0.2", + "vitest": "5.1.1" + }, + "engines": { + "node": ">=22.18.0" + }, + "packageManager": "bun@1.4.2" +} diff --git a/scripts/build.mjs b/scripts/build.mjs new file mode 100644 index 0000000..3a7c0d4 --- /dev/null +++ b/scripts/build.mjs @@ -0,0 +1,11 @@ +import { rm } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; + +const root = new URL("../", import.meta.url); +await rm(new URL("dist/", root), { recursive: true, force: true }); +const compiler = Bun.spawn(["bun", "run", "tsc", "--project", "tsconfig.build.json"], { + cwd: fileURLToPath(root), + stdout: "inherit", + stderr: "inherit", +}); +process.exit(await compiler.exited); diff --git a/scripts/check-consumer.mjs b/scripts/check-consumer.mjs new file mode 100644 index 0000000..faa471c --- /dev/null +++ b/scripts/check-consumer.mjs @@ -0,0 +1,17 @@ +import assert from "node:assert/strict"; +import { access } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; +import { openDeepSeekSession } from "deepseek-durable-objects"; +import { withDeepSeekDispatch } from "deepseek-durable-objects/transport"; +import { deepSeekWorkerdBuild } from "deepseek-durable-objects/workerd"; + +assert.equal(typeof openDeepSeekSession, "function"); +assert.equal(typeof withDeepSeekDispatch, "function"); +const provider = fileURLToPath(import.meta.resolve("@deepseek-ai/dsh-llm-deepseek")); +const transport = deepSeekWorkerdBuild.resolveId.handler( + "deepseek-durable-objects:workerd-transport", + provider, +); +assert.ok(transport?.endsWith("/dist/WorkerdTransport.js")); +await access(transport); +assert.match(deepSeekWorkerdBuild.transform("", provider) ?? "", /import \{ fetch \}/u); diff --git a/src/DeepSeek.ts b/src/DeepSeek.ts new file mode 100644 index 0000000..f688790 --- /dev/null +++ b/src/DeepSeek.ts @@ -0,0 +1,553 @@ +import { Context } from "@deepseek-ai/cordis"; +import AgentRegistry from "@deepseek-ai/dsh-agent"; +import type { AgentHandle } from "@deepseek-ai/dsh-agent"; +import AgentLoop from "@deepseek-ai/dsh-agent-loop"; +import LlmRuntime, { + MessageId, + createAssistantMessage, + createUserMessage, + freezeMessage, +} from "@deepseek-ai/dsh-llm"; +import type { StreamChunk, UserMessage } from "@deepseek-ai/dsh-llm"; +import { + DeepSeekAdapter, + DeepSeekFileStore, + PUBLIC_BASE_URL, + resolveAdapterOptions, +} from "@deepseek-ai/dsh-llm-deepseek"; +import SessionStore, { SessionId } from "@deepseek-ai/dsh-session"; +import type { SessionEvent } from "@deepseek-ai/dsh-session"; +import SessionProjection from "@deepseek-ai/dsh-session-projection"; +import SystemPrompt from "@deepseek-ai/dsh-system-prompt"; +import ToolRuntime from "@deepseek-ai/dsh-tools"; +import * as Schema from "effect/Schema"; +import { latestSegment, omitUnpublishedTurns, operationStart, segmentEvents } from "./History.ts"; +import type { DeepSeekOperation, DeepSeekSegment } from "./History.ts"; +import { applyToolResult, parkedModelCalls } from "./ParkedTools.ts"; +import type { ParkedTools } from "./ParkedTools.ts"; +import { durableSessionLog } from "./SessionLog.ts"; +import { fetch as workerdFetch, withDeepSeekDispatch } from "./WorkerdTransport.ts"; +import type { DeepSeekSessionOptions, DeepSeekTurn, DeepSeekTurnOutcome } from "./Types.ts"; + +export type { StreamChunk } from "@deepseek-ai/dsh-llm"; +export type { DeepSeekStorage } from "./Storage.ts"; +export type { DeepSeekSessionOptions, DeepSeekTurn, DeepSeekTurnOutcome } from "./Types.ts"; + +const key = (operationId: string) => `dsh-operation:${operationId}`; +const parkedKey = (operationId: string) => `dsh-parked:${operationId}`; +type DeepSeekAnonymousId = ReturnType< + ConstructorParameters[0]["resolveUserId"] +>; +const isDeepSeekAnonymousId = (value: unknown): value is DeepSeekAnonymousId => + typeof value === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/u.test(value); + +const decodeJsonObject = Schema.decodeUnknownSync(Schema.JsonObject); + +const assistantParts = (events: ReadonlyArray) => + events.flatMap((event) => (event.type === "assistant/message" ? [event.data] : [])); + +const usageOf = (parts: ReturnType) => + parts.reduce( + (total, { usage }) => ({ + input_tokens: total.input_tokens + (usage?.inputTokens ?? 0), + output_tokens: total.output_tokens + (usage?.outputTokens ?? 0), + cache_read_input_tokens: total.cache_read_input_tokens + (usage?.cacheReadTokens ?? 0), + cache_creation_input_tokens: + total.cache_creation_input_tokens + (usage?.cacheWriteTokens ?? 0), + }), + { + input_tokens: 0, + output_tokens: 0, + cache_read_input_tokens: 0, + cache_creation_input_tokens: 0, + }, + ); + +const resultOf = (events: ReadonlyArray): DeepSeekTurnOutcome => { + const ended = events.find(({ type }) => type === "turn/end"); + if (ended?.type !== "turn/end") { + return { kind: "interrupted" }; + } + const reason = ended.data.reason; + if (reason.kind === "aborted" || reason.kind === "interrupted") { + return { kind: "interrupted" }; + } + const parts = assistantParts(events); + if (reason.kind === "error") { + return { + kind: "failed", + ...(parts.some((part) => part.usage !== undefined) ? { usage: usageOf(parts) } : {}), + }; + } + const assistant = parts.at(-1); + const text = + assistant?.message.content + .flatMap((part) => (part.type === "text" ? [part.text] : [])) + .join("\n") ?? ""; + const firstChunk = assistant?.stream[0]; + const startedAt = firstChunk?.type === "chunk" ? firstChunk.time : firstChunk?.time0; + return { + kind: "finished", + text, + ...(startedAt === undefined ? {} : { startedAt }), + outputLimited: reason.kind === "max-tokens", + usage: usageOf(parts), + }; +}; + +export const openDeepSeekSession = async ( + options: DeepSeekSessionOptions, +) => { + const { storage } = options; + const provider = options.first.provider; + const readOperation = (operationId: string) => + storage.kv.get(key(operationId)); + const readParked = (operationId: string) => { + const parked = storage.kv.get>(parkedKey(operationId)); + return parked !== undefined && parked.tools.length > 0 ? parked : undefined; + }; + const id = SessionId(options.sessionId); + const host = new Context(); + await host.plugin(LlmRuntime); + await host.plugin(SessionStore); + await host.plugin(SessionProjection); + await host.plugin(SystemPrompt); + await host.plugin(ToolRuntime); + await host.plugin(AgentRegistry); + await host.plugin(durableSessionLog(storage)); + const connection = resolveAdapterOptions({ + baseURL: options.baseUrl ?? PUBLIC_BASE_URL, + defaultContextWindow: 1_000_000, + maxTokens: 8192, + models: [{ id: options.first.modelId, inputModalities: ["text"], contextWindow: 1_000_000 }], + }); + const saved = storage.kv.get("dsh-anonymous"); + const anonymousId = isDeepSeekAnonymousId(saved) ? saved : crypto.randomUUID(); + if (!isDeepSeekAnonymousId(anonymousId)) { + throw new Error("DeepSeek requires a valid anonymous client identifier."); + } + storage.kv.put("dsh-anonymous", anonymousId); + let current: + | { + readonly request: Request; + readonly handle: AgentHandle; + readonly start: number; + readonly recordStream: (chunks: AsyncIterable) => AsyncIterable; + } + | undefined; + const unmetered = async function* (source: AsyncIterable) { + const iterator = source[Symbol.asyncIterator](); + try { + for (;;) { + const next = await withDeepSeekDispatch( + provider, + (send) => send(), + () => iterator.next(), + ); + if (next.done === true) { + return; + } + yield next.value; + } + } finally { + await iterator.return?.(); + } + }; + const recordStream = (chunks: AsyncIterable) => { + if (current === undefined) { + throw new Error("No active turn owns the provider stream."); + } + return current.recordStream(chunks); + }; + class MeteredAdapter extends DeepSeekAdapter { + override async prepareCall(...args: Parameters) { + const call = await super.prepareCall(...args); + return { + ...call, + stream: (options: Parameters[0]) => recordStream(call.stream(options)), + }; + } + override stream(options: Parameters[0]) { + return recordStream(super.stream(options)); + } + } + const adapter = new MeteredAdapter({ + options: () => connection, + resolveFiles: () => new DeepSeekFileStore({ fetch: workerdFetch }), + resolveAuth: async () => ({ + headers: + provider === "openrouter" + ? { authorization: `Bearer ${options.apiKey ?? ""}` } + : { "x-api-key": options.apiKey ?? "" }, + }), + // The adapter only uses this stable random ID as an opaque request header. + resolveUserId: () => anonymousId, + prepareExtensions: async () => ({ fields: {}, accept: async () => {} }), + }); + host.llm.registerAdapter([provider], adapter); + await host.plugin(AgentLoop, { agents: [] }); + + const agentOptions = { provider, model: options.first.modelId, maxTokens: 8192 }; + const setup = (context: Context) => { + let attempt: string | undefined; + let preview: ReturnType>; + const seenText = new Set(); + context.on("agent/assistant-stream", ({ agent, frame }) => { + const live = current; + if (live?.handle.agent !== agent) { + return; + } + if (frame.type === "start") { + attempt = frame.attemptId; + preview = undefined; + seenText.clear(); + } + if (frame.type !== "chunk" || frame.attemptId !== attempt) { + return; + } + preview ??= options.startPreview?.(live.request.operationId, frame.time); + const { chunk } = frame; + if (chunk.type === "block-start" && chunk.blockType === "reasoning") { + preview?.thinking(); + } + if (chunk.type === "text-delta") { + if (!seenText.has(chunk.index) && seenText.size > 0) { + preview?.text(chunk.index, "\n"); + } + seenText.add(chunk.index); + preview?.text(chunk.index, chunk.text); + } + }); + context.systemPrompt.section({ + name: options.sessionId, + order: 0, + interpolate: false, + complete: true, + text: () => + [ + options.first.system ?? "", + current?.request.systemContext ?? "", + options.systemInstructions ?? "", + ] + .filter(Boolean) + .join("\n\n"), + }); + }; + let registrations: Array<() => void> = []; + const registerTools = ( + context: Context, + tools: Awaited>, + ) => { + for (const release of registrations) { + release(); + } + registrations = []; + for (const tool of tools) { + registrations.push( + context.tools.register({ + name: tool.name, + description: tool.description, + parameters: decodeJsonObject(tool.parameters), + output: { + schema: { type: "string" }, + render: (_, value) => [{ type: "text", text: String(value) }], + }, + execute: async (input, execution) => { + const active = current; + if (active === undefined) { + throw new Error("No DeepSeek turn owns this tool call."); + } + const { request, start } = active; + const call = { + id: execution.callId, + name: tool.name, + arguments: decodeJsonObject(input), + }; + // Persist the native assistant and tool call before the host can act on it. + await log.flush(); + const outcome = await options.tools.call(request, call, execution.signal); + if (outcome.kind === "paused") { + const parked = readParked(request.operationId); + storage.kv.put(parkedKey(request.operationId), { + start, + tools: [...(parked?.tools ?? []), { call, action: outcome.action }], + } satisfies ParkedTools); + execution.concludeTurn(); + return options.waitingForTool ?? "Waiting for the tool result."; + } + const { text, isError } = outcome; + if (isError) { + throw new Error(text || "Workspace tool failed."); + } + return text; + }, + }), + ); + } + }; + + const log = host.sessionPersistence; + let owner: Promise | undefined; + const openAgent = async () => + (await log.stat(id)) === undefined + ? host.agents.create({ sessionId: id, agentOptions, setup }) + : host.agents.resume({ resumeSessionId: id, agentOptions, setup }); + const getAgent = () => { + owner ??= openAgent().catch((error: unknown) => { + owner = undefined; + throw error; + }); + return owner; + }; + let finishing: Promise | undefined; + const finish = (handle: AgentHandle) => { + finishing ??= (async () => { + try { + await handle.agent.whenIdle(); + await log.flush(); + } catch (error) { + try { + await handle.dispose(); + } catch (disposalError) { + throw new AggregateError( + [error, disposalError], + "DeepSeek could not release its agent.", + { + cause: disposalError, + }, + ); + } finally { + owner = undefined; + registrations = []; + } + throw error; + } finally { + current = undefined; + finishing = undefined; + } + })(); + return finishing; + }; + const readLog = async (offset: number, signal: AbortSignal) => { + await using reader = await log.open(id, "read", { signal }); + return (await reader.read(offset, -1, { signal })).events; + }; + const seedPublishedHistory = async (handle: AgentHandle, signal: AbortSignal) => { + const prefix = options.publishedSeed; + const receipt = "dsh-published-history-seeded"; + if (prefix === undefined || storage.kv.get(receipt) === true) { + return; + } + const existing = new Set( + (await readLog(0, signal)).flatMap((event) => { + if (event.type === "user/message") { + return [event.data.id]; + } + if (event.type === "assistant/message") { + return [event.data.message.id]; + } + return []; + }), + ); + const { session } = handle.agent; + for (const { turn, user, assistant } of prefix) { + const userId = MessageId(`${options.sessionId}-history-${turn}-user`); + if (!existing.has(userId)) { + const message = createUserMessage({ + content: [{ type: "text", text: user }], + source: { kind: "user" }, + }); + session.append("user/message", freezeMessage({ ...message, id: userId }), { + surfaceOp: "append", + }); + } + const assistantId = MessageId(`${options.sessionId}-history-${turn}-assistant`); + if (!existing.has(assistantId)) { + const message = createAssistantMessage({ + content: [{ type: "text", text: assistant }], + source: { provider, model: options.first.modelId }, + }); + session.append( + "assistant/message", + { turn: 0, step: 0, message: freezeMessage({ ...message, id: assistantId }), stream: [] }, + { surfaceOp: "append" }, + ); + } + } + await log.flush(); + storage.kv.put(receipt, true); + }; + const wake = async ( + handle: AgentHandle, + request: Request, + segment: DeepSeekSegment, + message: UserMessage, + ) => { + current = { + request, + handle, + start: segment.start, + recordStream: + options.recordRequests?.(request, () => current?.request === request) ?? unmetered, + }; + try { + handle.agent.followup(message); + } catch (error) { + await finish(handle); + throw error; + } + }; + const resume = async ( + request: Request, + operation: Exclude, + parked: ParkedTools, + handle: AgentHandle, + signal: AbortSignal, + ) => { + const events = await readLog(parked.start, signal); + const modelCalls = parkedModelCalls(events, parked); + const outcomes = await Promise.all( + parked.tools.map(({ call }) => options.tools.call(request, call, signal)), + ); + signal.throwIfAborted(); + if (outcomes.some((outcome) => outcome.kind === "paused")) { + storage.kv.put(parkedKey(request.operationId), { + ...parked, + tools: parked.tools.map(({ call }, index) => { + const outcome = outcomes[index]; + return { call, action: outcome?.kind === "paused" ? outcome.action : null }; + }), + } satisfies ParkedTools); + return; + } + const previous = operation.continuations ?? []; + const prepared = previous.at(-1); + const message = + prepared?.preparing === true + ? freezeMessage({ + id: prepared.messageId, + role: "user", + content: [], + source: { kind: "user" }, + }) + : createUserMessage({ content: [], source: { kind: "user" } }); + const segment = { + start: prepared?.preparing === true ? prepared.start : handle.agent.session.seq, + messageId: message.id, + }; + const prefix = prepared?.preparing === true ? previous.slice(0, -1) : previous; + // Keep the same cursor and wake identity if a restart interrupts preparation. + storage.kv.put(key(request.operationId), { + ...operation, + continuations: [...prefix, { ...segment, preparing: true }], + } satisfies DeepSeekOperation); + for (const [index, modelCall] of modelCalls.entries()) { + const outcome = outcomes[index]; + if (outcome?.kind !== "result") { + throw new Error("DeepSeek did not receive a result for a parked tool."); + } + applyToolResult(handle.agent.session, events, modelCall, outcome); + } + await finish(handle); + signal.throwIfAborted(); + // The next native request can start only after all tool results are durable. + storage.transactionSync(() => { + storage.kv.put(key(request.operationId), { + ...operation, + continuations: [...prefix, segment], + } satisfies DeepSeekOperation); + storage.kv.put(parkedKey(request.operationId), { + ...parked, + tools: [], + } satisfies ParkedTools); + }); + // An empty user message wakes the native loop and has no blocks on the wire. + await wake(handle, request, segment, message); + }; + return { + submit: async (request: Request, signal: AbortSignal) => { + signal.throwIfAborted(); + const operation = readOperation(request.operationId); + const parked = readParked(request.operationId); + if (options.apiKey === null || (operation !== undefined && parked === undefined)) { + return; + } + // Schedule recovery before publishing the start cursor or entering model code. + await storage.setAlarm(Date.now() + 5000); + signal.throwIfAborted(); + const opening = getAgent(); + const handle = await opening; + const tools = await options.tools.list(request, signal); + signal.throwIfAborted(); + if (current !== undefined || owner !== opening) { + throw new Error("The DeepSeek agent is not available for submission."); + } + registerTools(handle.agent.ctx, tools); + if (operation !== undefined) { + if (typeof operation !== "number" && parked !== undefined) { + await resume(request, operation, parked, handle, signal); + } + return; + } + const unpublished = request.unpublishedOperationIds.flatMap((operationId) => { + const old = readOperation(operationId); + return old === undefined ? [] : [old]; + }); + const offset = unpublished.reduce((earliest, old) => { + return Math.min(earliest, operationStart(old)); + }, handle.agent.session.seq); + const history = unpublished.length === 0 ? [] : await readLog(offset, signal); + signal.throwIfAborted(); + if (readOperation(request.operationId) !== undefined) { + return; + } + if (current !== undefined || owner !== opening) { + throw new Error("The DeepSeek agent is not available for submission."); + } + omitUnpublishedTurns(handle.agent.session, history, offset, unpublished); + await seedPublishedHistory(handle, signal); + signal.throwIfAborted(); + const message = createUserMessage({ + content: [{ type: "text", text: request.text }], + source: { kind: "user" }, + }); + const segment = { start: handle.agent.session.seq, messageId: message.id }; + storage.kv.put(key(request.operationId), segment satisfies DeepSeekOperation); + await wake(handle, request, segment, message); + }, + settle: async ( + request: Request, + signal: AbortSignal, + ): Promise | null> => { + if (options.apiKey === null) { + return { kind: "missing-credentials" }; + } + const operation = readOperation(request.operationId); + if (operation === undefined) { + return null; + } + if (current?.request.operationId === request.operationId) { + await finish(current.handle); + } else { + // Opening a fresh owner repairs an incomplete turn in the saved log. + await getAgent(); + } + const segment = latestSegment(operation); + const offset = operationStart(segment); + const nativeEvents = segmentEvents(await readLog(offset, signal), offset, segment); + const parked = readParked(request.operationId); + const calls = parked?.tools.flatMap(({ action }) => (action === null ? [] : [action])) ?? []; + return calls.length > 0 + ? { kind: "paused", calls, usage: usageOf(assistantParts(nativeEvents)) } + : resultOf(nativeEvents); + }, + abort: async (operationId: string) => { + if (current?.request.operationId === operationId) { + const { handle } = current; + handle.agent.cancel({ kind: "user" }); + await finish(handle); + } + return true; + }, + }; +}; diff --git a/src/History.ts b/src/History.ts new file mode 100644 index 0000000..d636ed7 --- /dev/null +++ b/src/History.ts @@ -0,0 +1,139 @@ +import { createSystemMessage } from "@deepseek-ai/dsh-llm"; +import type { MessageId } from "@deepseek-ai/dsh-llm"; +import type { Session, SessionEvent, SessionSeq } from "@deepseek-ai/dsh-session"; + +export interface DeepSeekSegment { + readonly start: number; + readonly messageId: MessageId; + readonly preparing?: true; +} + +// A Checkfu turn may span native DeepSeek turns when a tool parks the loop. +export type DeepSeekOperation = + | number + | (DeepSeekSegment & { + readonly continuations?: ReadonlyArray; + }); + +export const latestSegment = (operation: DeepSeekOperation): number | DeepSeekSegment => + typeof operation === "number" ? operation : (operation.continuations?.at(-1) ?? operation); + +export const operationStart = (operation: DeepSeekOperation): number => + typeof operation === "number" ? operation : operation.start; + +export const segmentEvents = ( + events: ReadonlyArray, + offset: number, + operation: number | DeepSeekSegment, +): ReadonlyArray => { + const start = operationStart(operation) - offset; + const messageId = typeof operation === "number" ? undefined : operation.messageId; + // Outcome replacements are appended before the continuation wakes the loop. + // Keep those rows even when a cancelled continuation has no native input. + let nativeStart = start; + let started = false; + for (let index = start; index < events.length; index++) { + const event = events[index]; + if (event === undefined) { + return []; + } + if (event.type === "turn/end") { + return events.slice(start, index + 1); + } + if (event.type === "turn/start") { + if (started) { + return events.slice(start, index); + } + nativeStart = index; + started = true; + } + if ( + messageId !== undefined && + event.type === "user/message" && + event.data.source.kind === "user" && + event.data.id !== messageId + ) { + // A later turn can reuse the log offset of an operation whose first write failed. + return events.slice(start, nativeStart); + } + } + return events.slice(start); +}; + +const operationEvents = ( + events: ReadonlyArray, + offset: number, + operation: DeepSeekOperation, +): ReadonlyArray => { + const first = segmentEvents(events, offset, operation); + return typeof operation === "number" + ? first + : [ + ...first, + ...(operation.continuations ?? []).flatMap((segment) => + segmentEvents(events, offset, segment), + ), + ]; +}; + +type Step = { readonly turn: number; readonly step: number }; + +/** Shadow unpublished turns in DSH's model projection while retaining their log. */ +export const omitUnpublishedTurns = ( + session: Session, + events: ReadonlyArray, + offset: number, + operations: ReadonlyArray, +): void => { + const omitted = new Map(); + for (const operation of operations) { + const owned = operationEvents(events, offset, operation); + const step = owned.find((event) => event.type === "step/start"); + if (step === undefined) { + continue; + } + for (const event of owned) { + if (event.surfaceOp !== undefined && session.deriveEventMessage(event) !== null) { + omitted.set(event.seq, step.data); + } + } + } + if (omitted.size === 0) { + return; + } + const nodes = [...session.surface.nodes]; + let group: + | { readonly step: Step; readonly start: SessionSeq; readonly nodes: Array } + | undefined; + const replace = () => { + if (group === undefined) { + return; + } + const { step, start, nodes } = group; + // DSH projects an empty system message to no model input. The logged + // replacement also invalidates the upstream request series. + session.append( + "system/message", + { ...step, message: createSystemMessage("") }, + { + surfaceOp: { op: "replace", startSeq: start, endSeq: nodes.at(-1) ?? start }, + sourceEventSeqs: nodes, + }, + ); + group = undefined; + }; + for (const [index, seq] of nodes.entries()) { + const step = omitted.get(seq); + if (step === undefined) { + replace(); + continue; + } + group ??= { step, start: seq, nodes: [] }; + group.nodes.push(seq); + // The protected system prompt at the head permits only a single-node edit. + if (index === 0) { + replace(); + } + } + replace(); +}; diff --git a/src/OpenRouterMessages.ts b/src/OpenRouterMessages.ts new file mode 100644 index 0000000..fd5c222 --- /dev/null +++ b/src/OpenRouterMessages.ts @@ -0,0 +1,116 @@ +import { createParser } from "eventsource-parser"; +import * as Option from "effect/Option"; +import * as Schema from "effect/Schema"; + +const MAX_MESSAGES_EVENT_BYTES = 8 * 1024 * 1024; + +const isObject: (value: unknown) => value is Schema.JsonObject = Schema.is(Schema.JsonObject); +const decodeObject = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.JsonObject)); +const withField = (object: Schema.JsonObject, key: string, value: Schema.Json): Schema.JsonObject => + Object.fromEntries([...Object.entries(object), [key, value]]); + +export const openRouterMessagesInit = (input: RequestInit): RequestInit => { + if (typeof input.body !== "string") { + throw new TypeError("The DeepSeek SDK must send a JSON Messages request."); + } + const payload = Option.getOrUndefined(decodeObject(input.body)); + if (payload === undefined) { + throw new TypeError("The DeepSeek SDK sent an invalid Messages request."); + } + const thinking = payload["thinking"]; + const headers = new Headers(input.headers); + headers.delete("x-deepseek-harness-user-id"); + headers.delete("x-deepseek-harness-session-id"); + if (!isObject(thinking) || thinking["type"] !== "enabled") { + return { ...input, headers }; + } + headers.delete("content-length"); + // OpenRouter requires the adaptive variant to receive effort without a token budget. + return { + ...input, + headers, + body: JSON.stringify(withField(payload, "thinking", withField(thinking, "type", "adaptive"))), + }; +}; + +const normalizedData = (data: string): string => { + const event = Option.getOrUndefined(decodeObject(data)); + const kind = event?.["type"]; + if (event === undefined || (kind !== "message_start" && kind !== "message_delta")) { + return data; + } + const parent = kind === "message_start" ? event["message"] : event; + if (!isObject(parent)) { + return data; + } + const usage = parent["usage"]; + if (!isObject(usage)) { + return data; + } + const cacheRead = usage["cache_read_input_tokens"]; + const cacheWrite = usage["cache_creation_input_tokens"]; + if (cacheRead !== null && cacheWrite !== null) { + return data; + } + // The SDK accepts absent optional counters and rejects null counters. + const normalized = Object.fromEntries( + Object.entries(usage).filter( + ([key, value]) => + value !== null || + (key !== "cache_read_input_tokens" && key !== "cache_creation_input_tokens"), + ), + ); + return JSON.stringify( + parent === event + ? withField(event, "usage", normalized) + : withField(event, "message", withField(parent, "usage", normalized)), + ); +}; + +export const openRouterMessagesResponse = (response: Response): Response => { + if ( + !response.ok || + response.body === null || + response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() !== + "text/event-stream" + ) { + return response; + } + let parser: ReturnType; + const body = response.body + .pipeThrough(new TextDecoderStream("utf8", { fatal: true })) + .pipeThrough( + new TransformStream({ + start(controller) { + parser = createParser({ + maxBufferSize: MAX_MESSAGES_EVENT_BYTES, + onComment: (comment) => controller.enqueue(`: ${comment}\n`), + onRetry: (delay) => controller.enqueue(`retry: ${delay}\n`), + onEvent: ({ id, event, data }) => { + const fields = [ + ...(id === undefined ? [] : [`id: ${id}`]), + ...(event === undefined ? [] : [`event: ${event}`]), + ...normalizedData(data) + .split("\n") + .map((line) => `data: ${line}`), + ]; + controller.enqueue(fields.join("\n") + "\n\n"); + }, + onError: (error) => { + if (error.type === "max-buffer-size-exceeded") { + throw error; + } + }, + }); + }, + transform(chunk) { + parser.feed(chunk); + }, + }), + ) + .pipeThrough(new TextEncoderStream()); + const headers = new Headers(response.headers); + headers.delete("content-length"); + headers.delete("content-encoding"); + return new Response(body, { status: response.status, statusText: response.statusText, headers }); +}; diff --git a/src/ParkedTools.ts b/src/ParkedTools.ts new file mode 100644 index 0000000..3a07882 --- /dev/null +++ b/src/ParkedTools.ts @@ -0,0 +1,84 @@ +import { createSystemMessage, createToolResultMessage } from "@deepseek-ai/dsh-llm"; +import type { Session, SessionEvent } from "@deepseek-ai/dsh-session"; +import type { DeepSeekToolCall } from "./Types.ts"; + +export interface ParkedTools { + readonly start: number; + readonly tools: ReadonlyArray<{ + readonly call: DeepSeekToolCall; + readonly action: Action | null; + }>; +} + +export const parkedModelCalls = ( + events: ReadonlyArray, + parked: ParkedTools, +): ReadonlyArray> => + parked.tools.map(({ call }) => { + const modelCall = events.findLast( + (event) => + event.seq >= parked.start && + event.type === "tool/call" && + event.data.callId === call.id && + event.data.name === call.name, + ); + if (modelCall?.type !== "tool/call") { + throw new Error("A parked DeepSeek tool has no durable model call."); + } + return modelCall; + }); + +export const applyToolResult = ( + session: Session, + events: ReadonlyArray, + modelCall: SessionEvent<"tool/call">, + result: { readonly text: string; readonly isError: boolean }, +): void => { + const slots = events.filter( + (event) => + event.type === "tool/result" && + event.data.message.toolCallId === modelCall.data.callId && + event.sourceEventSeqs?.includes(modelCall.seq) === true, + ); + if ( + slots.some((event) => { + const meta = event.type === "tool/result" ? event.data.meta : undefined; + return ( + typeof meta === "object" && + meta !== null && + "checkfu_parked_result" in meta && + meta.checkfu_parked_result === true + ); + }) + ) { + return; + } + const placeholder = slots.find((event) => session.surface.nodes.includes(event.seq)); + const { turn, step, callId } = modelCall.data; + if (placeholder !== undefined) { + // A native tool-result rewrite preserves the original error flag. Shadow + // the placeholder and append the actual grouped result with its own flag. + session.append( + "system/message", + { turn, step, message: createSystemMessage("") }, + { + surfaceOp: { op: "replace", startSeq: placeholder.seq, endSeq: placeholder.seq }, + sourceEventSeqs: [placeholder.seq], + }, + ); + } + session.append( + "tool/result", + { + turn, + step, + message: createToolResultMessage({ + callId, + content: [{ type: "text", text: result.text }], + isError: result.isError, + }), + meta: { checkfu_parked_result: true }, + }, + { surfaceOp: "append", sourceEventSeqs: [modelCall.seq] }, + ); +}; diff --git a/src/SessionLog.ts b/src/SessionLog.ts new file mode 100644 index 0000000..272447d --- /dev/null +++ b/src/SessionLog.ts @@ -0,0 +1,169 @@ +import type { Context } from "@deepseek-ai/cordis"; +import { SessionLogOffset } from "@deepseek-ai/dsh-session"; +import type { SessionEvent, SessionHeader, SessionId } from "@deepseek-ai/dsh-session"; +import { + SessionAlreadyExistsError, + SessionAlreadyOwnedError, + SessionHandleClosedError, + SessionPersistence, + SessionPersistenceNotFoundError, + SessionPersistenceRevision, + SessionReadOnlyError, + assertContiguous, + materializeAppendBatch, + materializeCreateHeader, +} from "@deepseek-ai/dsh-session-persistence"; +import type { SessionAccess, SessionHandle } from "@deepseek-ai/dsh-session-persistence"; + +import type { DeepSeekStorage } from "./Storage.ts"; + +type LogHead = { readonly header: SessionHeader; readonly next: number }; + +const key = (id: SessionId) => `dsh-log:${id}`; +const eventKey = (id: SessionId, index: number) => `dsh-event:${id}:${index}`; +const stat = (head: LogHead) => ({ + header: head.header, + revision: SessionPersistenceRevision(String(head.next)), + eventCount: head.next, +}); + +export const durableSessionLog = ( + storage: DeepSeekStorage, +): new (ctx: Context) => SessionPersistence => { + const readHead = (id: SessionId) => storage.kv.get(key(id)); + const owners = new Set(); + const writeFailures = new Map(); + const store = (id: SessionId, events: ReadonlyArray) => { + const batch = materializeAppendBatch(events); + storage.transactionSync(() => { + const head = readHead(id); + if (head === undefined) { + throw new SessionPersistenceNotFoundError(id); + } + assertContiguous(id, batch, head.next); + for (const event of batch) { + storage.kv.put(eventKey(id, event.seq), event); + } + storage.kv.put(key(id), { header: head.header, next: head.next + batch.length }); + }); + }; + const flush = async () => { + if (writeFailures.size > 0) { + throw new AggregateError([...writeFailures.values()], "DeepSeek session event write failed."); + } + await storage.sync(); + }; + const open = (header: SessionHeader, access: SessionAccess): SessionHandle => { + const id = header.id; + if (access === "write") { + if (owners.has(id)) { + throw new SessionAlreadyOwnedError(id); + } + owners.add(id); + } + let closed = false; + const check = (operation: string, signal?: AbortSignal) => { + signal?.throwIfAborted(); + if (closed) { + throw new SessionHandleClosedError(id, operation); + } + if (operation !== "read" && access !== "write") { + throw new SessionReadOnlyError(id, operation); + } + }; + const close = async () => { + if (!closed && access === "write") { + owners.delete(id); + writeFailures.delete(id); + } + closed = true; + }; + return { + id, + header, + access, + inheritedEventCount: SessionLogOffset(0), + read: async (offset = 0, length = -1, options) => { + check("read", options?.signal); + const head = readHead(id); + if (head === undefined) { + throw new SessionPersistenceNotFoundError(id); + } + const end = length === -1 ? head.next : Math.min(head.next, offset + length); + const events: Array = []; + for (let index = offset; index < end; index++) { + const event = storage.kv.get(eventKey(id, index)); + if (event === undefined) { + throw new Error("DeepSeek session log has a gap."); + } + events.push(event); + } + return { events, eventState: "detached" }; + }, + append: async (events, options) => { + check("append", options?.signal); + store(id, events); + }, + flush: async (options) => { + check("flush", options?.signal); + await flush(); + }, + close, + [Symbol.asyncDispose]: close, + }; + }; + return class DurableSessionLog extends SessionPersistence { + static readonly inject = ["sessions"]; + + constructor(ctx: Context) { + super(ctx); + ctx.on("session/event", (session, event) => { + if (owners.has(session.id) && !writeFailures.has(session.id)) { + try { + store(session.id, [event]); + } catch (error) { + writeFailures.set(session.id, error); + } + } + }); + ctx.on("session/flush", () => flush()); + } + async create(header: SessionHeader, options?: Parameters[1]) { + options?.signal?.throwIfAborted(); + if (header.isSeeded || (options?.inheritedEventCount ?? 0) !== 0) { + throw new Error("The DeepSeek Durable Object runtime does not create forked sessions."); + } + if (readHead(header.id) !== undefined) { + throw new SessionAlreadyExistsError(header.id); + } + const copy = materializeCreateHeader(header); + storage.kv.put(key(copy.id), { header: copy, next: 0 }); + return open(copy, "write"); + } + async open( + id: SessionId, + access: SessionAccess, + options?: Parameters[2], + ) { + options?.signal?.throwIfAborted(); + const head = readHead(id); + if (head === undefined) { + throw new SessionPersistenceNotFoundError(id); + } + return open(head.header, access); + } + async flush() { + await flush(); + } + async stat(id: SessionId, options?: Parameters[1]) { + options?.signal?.throwIfAborted(); + const head = readHead(id); + return head === undefined ? undefined : stat(head); + } + async list(options?: Parameters[0]) { + options?.signal?.throwIfAborted(); + const rows = await storage.list({ prefix: "dsh-log:" }); + return [...rows.values()].map(stat); + } + }; +}; diff --git a/src/Storage.ts b/src/Storage.ts new file mode 100644 index 0000000..820db86 --- /dev/null +++ b/src/Storage.ts @@ -0,0 +1,11 @@ +/** The subset of a SQLite-backed Durable Object's storage used by one runtime. */ +export interface DeepSeekStorage { + readonly kv: { + readonly get: (key: string) => Value | undefined; + readonly put: (key: string, value: Value) => void; + }; + readonly list: (options: { prefix: string }) => Promise>; + readonly sync: () => Promise; + readonly transactionSync: (transaction: () => Value) => Value; + readonly setAlarm: (time: number) => Promise; +} diff --git a/src/Types.ts b/src/Types.ts new file mode 100644 index 0000000..8e740a5 --- /dev/null +++ b/src/Types.ts @@ -0,0 +1,83 @@ +import type { StreamChunk } from "@deepseek-ai/dsh-llm"; +import type * as Schema from "effect/Schema"; +import type { DeepSeekStorage } from "./Storage.ts"; + +export interface DeepSeekTurn { + readonly operationId: string; + readonly provider: string; + readonly modelId: string; + readonly system: string | null; + readonly systemContext?: string; + readonly text: string; + readonly unpublishedOperationIds: ReadonlyArray; +} + +interface TranscriptTurn { + readonly turn: number; + readonly user: string; + readonly assistant: string; +} + +interface DeepSeekTool { + readonly name: string; + readonly description: string; + readonly parameters: unknown; +} + +export interface DeepSeekToolCall { + readonly id: string; + readonly name: string; + readonly arguments: Schema.JsonObject; +} + +type DeepSeekToolOutcome = + | { readonly kind: "result"; readonly text: string; readonly isError: boolean } + | { readonly kind: "paused"; readonly action: Action }; + +interface Preview { + readonly text: (part: number, delta: string) => void; + readonly thinking: () => void; +} + +interface Usage { + readonly input_tokens: number; + readonly output_tokens: number; + readonly cache_read_input_tokens: number; + readonly cache_creation_input_tokens: number; +} + +export type DeepSeekTurnOutcome = + | { + readonly kind: "finished"; + readonly text: string; + readonly startedAt?: number; + readonly outputLimited: boolean; + readonly usage: Usage; + } + | { readonly kind: "paused"; readonly calls: ReadonlyArray; readonly usage: Usage } + | { readonly kind: "failed"; readonly usage?: Usage } + | { readonly kind: "interrupted" | "missing-credentials" }; + +export interface DeepSeekSessionOptions { + readonly storage: DeepSeekStorage; + readonly sessionId: string; + readonly first: Request; + readonly publishedSeed?: ReadonlyArray; + readonly systemInstructions?: string; + readonly waitingForTool?: string; + readonly tools: { + readonly list: (request: Request, signal: AbortSignal) => Promise>; + readonly call: ( + request: Request, + call: DeepSeekToolCall, + signal: AbortSignal, + ) => Promise>; + }; + readonly startPreview?: (operationId: string, timestamp: number) => Preview | undefined; + readonly apiKey: string | null; + readonly baseUrl: string | null; + readonly recordRequests?: ( + request: Request, + active: () => boolean, + ) => (source: AsyncIterable) => AsyncIterable; +} diff --git a/src/WorkerdBuild.ts b/src/WorkerdBuild.ts new file mode 100644 index 0000000..5d21a9b --- /dev/null +++ b/src/WorkerdBuild.ts @@ -0,0 +1,23 @@ +import { fileURLToPath } from "node:url"; + +const transport = "deepseek-durable-objects:workerd-transport"; +const llmEntry = "/@deepseek-ai/dsh-llm/lib/index.js"; +const providerEntry = "/@deepseek-ai/dsh-llm-deepseek/lib/index.js"; + +/** Add to the Worker bundler's input plugins to use the published SDK on workerd. */ +export const deepSeekWorkerdBuild = { + name: "deepseek-durable-objects-workerd", + resolveId: { + order: "pre" as const, + handler(source: string, importer?: string) { + if (source === transport || (source === "node:module" && importer?.endsWith(llmEntry))) { + return fileURLToPath(new URL("./WorkerdTransport.js", import.meta.url)); + } + }, + }, + transform(code: string, id: string) { + if (id.endsWith(providerEntry)) { + return `import { fetch } from ${JSON.stringify(transport)};\n${code}`; + } + }, +}; diff --git a/src/WorkerdTransport.ts b/src/WorkerdTransport.ts new file mode 100644 index 0000000..40e12e3 --- /dev/null +++ b/src/WorkerdTransport.ts @@ -0,0 +1,59 @@ +import manifest from "@deepseek-ai/dsh-llm/package.json" with { type: "json" }; +import { openRouterMessagesInit, openRouterMessagesResponse } from "./OpenRouterMessages.ts"; +import { AsyncLocalStorage } from "node:async_hooks"; + +export type DeepSeekDispatch = ( + send: () => Promise, + signal?: AbortSignal | null, +) => Promise; + +const modelDispatch = new AsyncLocalStorage<{ + readonly provider: string; + readonly dispatch: DeepSeekDispatch; +}>(); + +export const withDeepSeekDispatch = ( + provider: string, + dispatch: DeepSeekDispatch, + read: () => Value, +): Value => modelDispatch.run({ provider, dispatch }, read); + +/** The bundled LLM package reads its version through Node's createRequire. */ +export const createRequire = () => (specifier: string) => { + if (specifier !== "../package.json") { + throw new TypeError("Unsupported DeepSeek LLM manifest import."); + } + return { version: manifest.version }; +}; + +/** Preserve the provider's redirect refusal on Workers, which rejects redirect: "error". */ +export const fetch: typeof globalThis.fetch = async (input, init) => { + const send = async (options: RequestInit | undefined) => { + const response = await globalThis.fetch(input, { ...options, redirect: "manual" }); + if ( + response.redirected || + response.type === "opaqueredirect" || + (response.status >= 300 && response.status < 400) + ) { + void response.body?.cancel().catch(() => undefined); + throw new TypeError("DeepSeek provider redirects are not allowed."); + } + return response; + }; + const request = typeof input === "object" && "method" in input ? input : undefined; + const method = (init?.method ?? request?.method ?? "GET").toUpperCase(); + const url = new URL(typeof input === "object" && "url" in input ? input.url : String(input)); + if (method !== "POST" || !url.pathname.endsWith("/messages")) { + return send(init); + } + const requestScope = modelDispatch.getStore(); + if (requestScope === undefined) { + throw new Error("No active turn owns the provider request."); + } + const openRouter = requestScope.provider === "openrouter"; + const options = openRouter ? openRouterMessagesInit(init ?? {}) : init; + return requestScope.dispatch(async () => { + const response = await send(options); + return openRouter ? openRouterMessagesResponse(response) : response; + }, init?.signal ?? request?.signal); +}; diff --git a/test/OpenRouterMessages.test.ts b/test/OpenRouterMessages.test.ts new file mode 100644 index 0000000..4be63c7 --- /dev/null +++ b/test/OpenRouterMessages.test.ts @@ -0,0 +1,59 @@ +import { expect, it } from "vitest"; +import { openRouterMessagesInit, openRouterMessagesResponse } from "../src/OpenRouterMessages.ts"; + +it("preserves SDK effort and transport authority in the OpenRouter request", () => { + const signal = new AbortController().signal; + const payload = { + model: "deepseek/deepseek-v4.1-flash", + thinking: { type: "enabled" }, + output_config: { effort: "high" }, + messages: [{ role: "user", content: "Test." }], + }; + const routed = openRouterMessagesInit({ + signal, + method: "POST", + headers: { + authorization: "Bearer fixture", + "content-length": "100", + "x-deepseek-harness-user-id": "private-id", + }, + body: JSON.stringify(payload), + }); + expect(routed.signal).toBe(signal); + expect(routed.method).toBe("POST"); + expect(Object.fromEntries(new Headers(routed.headers))).toEqual({ + authorization: "Bearer fixture", + }); + expect(JSON.parse(String(routed.body))).toEqual({ ...payload, thinking: { type: "adaptive" } }); +}); + +it("normalizes nullable cache counters while keeping zero, cost, UTF-8 and SSE boundaries", async () => { + const start = + ': heartbeat\r\nid: first\r\nevent: message_start\r\ndata: {"type":"message_start",\r\ndata: "message":{"usage":{"cache_read_input_tokens":null,"input_tokens":5}}}\r\n\r\n'; + const delta = + 'event: message_delta\ndata: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"cache_read_input_tokens":0,"cache_creation_input_tokens":null,"output_tokens":7,"cost":0.000002}}\n\n'; + const text = + 'event: content_block_delta\ndata: {"type":"content_block_delta","delta":{"type":"text_delta","text":"café"}}\n\n'; + const bytes = new TextEncoder().encode(start + text + delta); + const chunked = new ReadableStream({ + start(controller) { + for (let offset = 0; offset < bytes.length; offset += 3) { + controller.enqueue(bytes.slice(offset, offset + 3)); + } + controller.close(); + }, + }); + const input = new Response(chunked, { + headers: { "content-type": "text/event-stream", "content-length": String(bytes.length) }, + }); + const output = openRouterMessagesResponse(input); + expect(output.headers.has("content-length")).toBe(false); + const body = await output.text(); + expect(body).toContain( + ': heartbeat\nid: first\nevent: message_start\ndata: {"type":"message_start","message":{"usage":{"input_tokens":5}}}\n\n', + ); + expect(body).toContain(text); + expect(body).toContain( + 'data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"cache_read_input_tokens":0,"output_tokens":7,"cost":0.000002}}\n\n', + ); +}); diff --git a/test/Runtime.test.ts b/test/Runtime.test.ts new file mode 100644 index 0000000..4e0bf4b --- /dev/null +++ b/test/Runtime.test.ts @@ -0,0 +1,89 @@ +import assert from "node:assert/strict"; +import { createServer } from "node:http"; +import { once } from "node:events"; +import { text } from "node:stream/consumers"; +import { openDeepSeekSession } from "deepseek-durable-objects"; +import type { DeepSeekStorage, DeepSeekTurn } from "deepseek-durable-objects"; +import { expect, it } from "vitest"; +import { scriptedMessage } from "./helpers/ScriptedMessages.ts"; + +it("runs without a Checkfu host and restores the native conversation in a new runtime", async () => { + const requests: Array = []; + const provider = createServer((request, response) => { + void text(request).then( + (body) => { + requests.push(body); + const reply = requests.length === 1 ? "The marker is violet." : "Violet is still saved."; + const stream = scriptedMessage(requests.length, { text: reply }); + response.writeHead(stream.status, Object.fromEntries(stream.headers)); + return stream.text().then((body) => response.end(body)); + }, + (error: unknown) => + response.destroy( + error instanceof Error ? error : new Error("Unreadable request.", { cause: error }), + ), + ); + }); + try { + provider.listen(0, "127.0.0.1"); + await once(provider, "listening"); + const address = provider.address(); + assert.ok(address && typeof address !== "string"); + const rows = new Map(); + const storage: DeepSeekStorage = { + kv: { + get: (key: string) => rows.get(key) as Value | undefined, + put: (key, value) => { + rows.set(key, structuredClone(value)); + }, + }, + list: async () => new Map(), + sync: async () => {}, + transactionSync: (transaction) => transaction(), + setAlarm: async () => {}, + }; + const first: DeepSeekTurn = { + operationId: "first", + provider: "deepseek", + modelId: "deepseek-flash", + system: null, + text: "Remember violet.", + unpublishedOperationIds: [], + }; + const reopen = () => + openDeepSeekSession({ + storage, + sessionId: "external-host", + first, + apiKey: "fixture", + baseUrl: `http://127.0.0.1:${address.port}`, + tools: { + list: async () => [], + call: async () => { + throw Error("Unexpected tool call."); + }, + }, + }); + const signal = AbortSignal.timeout(10_000); + const driver = await reopen(); + await driver.submit(first, signal); + const result = await driver.settle(first, signal); + expect(result).toMatchObject({ kind: "finished", text: "The marker is violet." }); + const restarted = await reopen(); + expect(await restarted.settle(first, signal)).toEqual(result); + const followup = { ...first, operationId: "second", text: "What is the marker?" }; + await restarted.submit(followup, signal); + expect(await restarted.settle(followup, signal)).toMatchObject({ + kind: "finished", + text: "Violet is still saved.", + }); + expect(requests).toHaveLength(2); + expect(requests[1]).toContain("Remember violet."); + expect(requests[1]).toContain("The marker is violet."); + } finally { + provider.closeAllConnections(); + await new Promise((resolve, reject) => { + provider.close((error) => (error === undefined ? resolve() : reject(error))); + }); + } +}); diff --git a/test/Workerd.test.ts b/test/Workerd.test.ts new file mode 100644 index 0000000..439bb24 --- /dev/null +++ b/test/Workerd.test.ts @@ -0,0 +1,69 @@ +import cloudflare from "@alchemy.run/cloudflare-runtime/rolldown"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { deepSeekWorkerdBuild } from "deepseek-durable-objects/workerd"; +import { convertV4MiniflareOptions, Miniflare } from "miniflare"; +import { rolldown } from "rolldown"; +import { expect, it } from "vitest"; +import { scriptedMessage } from "./helpers/ScriptedMessages.ts"; + +it("resumes a parked tool in the same SQLite Durable Object after Workerd restarts", async () => { + const compatibilityDate = "2026-11-17"; + const compatibilityFlags = ["nodejs_compat"]; + const output = await mkdtemp(join(tmpdir(), "deepseek-workerd-")); + const script = join(output, "worker.mjs"); + const requests: Array = []; + let worker: Miniflare | undefined; + try { + const bundle = await rolldown({ + input: fileURLToPath(new URL("./fixtures/worker.mjs", import.meta.url)), + plugins: [deepSeekWorkerdBuild, cloudflare({ compatibilityDate, compatibilityFlags })], + }); + try { + await bundle.write({ file: script, format: "esm" }); + } finally { + await bundle.close(); + } + const open = () => + new Miniflare( + convertV4MiniflareOptions({ + modulesRoot: output, + modules: [{ type: "ESModule", path: script }], + compatibilityDate, + compatibilityFlags, + durableObjects: { SESSION: { className: "Session", useSQLite: true } }, + resourcePersistencePath: join(output, "storage"), + outboundService: async (request) => { + expect(request.url).toBe("https://provider.invalid/v1/messages"); + requests.push(await request.text()); + return scriptedMessage( + requests.length, + requests.length === 1 ? { tool: "confirm" } : { text: "Confirmation received." }, + ); + }, + }), + ); + const parked = { kind: "paused", calls: [{ tool: "confirm" }] }; + worker = open(); + const start = await worker.dispatchFetch("http://example.test/", { method: "POST" }); + expect(await start.json()).toMatchObject(parked); + expect(requests).toHaveLength(1); + await worker.dispose(); + worker = open(); + const recovered = await worker.dispatchFetch("http://example.test/"); + expect(await recovered.json()).toMatchObject(parked); + expect(requests).toHaveLength(1); + const resumed = await worker.dispatchFetch("http://example.test/answer", { method: "POST" }); + expect(await resumed.json()).toMatchObject({ + kind: "finished", + text: "Confirmation received.", + }); + expect(requests).toHaveLength(2); + expect(requests[1]).toContain("confirmed by the caller"); + } finally { + await worker?.dispose(); + await rm(output, { recursive: true, force: true }); + } +}, 30_000); diff --git a/test/fixtures/worker.mjs b/test/fixtures/worker.mjs new file mode 100644 index 0000000..7bb27cd --- /dev/null +++ b/test/fixtures/worker.mjs @@ -0,0 +1,55 @@ +import { DurableObject } from "cloudflare:workers"; +import { openDeepSeekSession } from "deepseek-durable-objects"; + +const turn = { + operationId: "turn:1", + provider: "deepseek", + modelId: "deepseek-flash", + system: null, + text: "Ask for confirmation first.", + unpublishedOperationIds: [], +}; + +export class Session extends DurableObject { + #runtime; + + async fetch(request) { + const { storage } = this.ctx; + this.#runtime ??= openDeepSeekSession({ + storage, + sessionId: "workerd-test", + first: turn, + apiKey: "fixture", + baseUrl: "https://provider.invalid", + tools: { + list: async () => [ + { + name: "confirm", + description: "Wait for the caller.", + parameters: { type: "object", properties: {} }, + }, + ], + call: async () => + storage.kv.get("confirmed") === true + ? { kind: "result", text: "confirmed by the caller", isError: false } + : { kind: "paused", action: { tool: "confirm" } }, + }, + }); + const runtime = await this.#runtime; + if (request.method === "POST") { + if (new URL(request.url).pathname === "/answer") { + storage.kv.put("confirmed", true); + } + await runtime.submit(turn, request.signal); + } + return Response.json(await runtime.settle(turn, request.signal)); + } + + async alarm() {} +} + +export default { + fetch(request, env) { + return env.SESSION.getByName("test").fetch(request); + }, +}; diff --git a/test/helpers/ScriptedMessages.ts b/test/helpers/ScriptedMessages.ts new file mode 100644 index 0000000..fd0b1f1 --- /dev/null +++ b/test/helpers/ScriptedMessages.ts @@ -0,0 +1,46 @@ +type Answer = { text: string } | { tool: string }; + +export const scriptedMessage = (request: number, answer: Answer): Response => { + const frames = [ + { + type: "message_start", + message: { + id: `msg_${request}`, + type: "message", + role: "assistant", + model: "deepseek-flash", + content: [], + stop_reason: null, + stop_sequence: null, + usage: { input_tokens: 19, output_tokens: 0 }, + }, + }, + { + type: "content_block_start", + index: 0, + content_block: + "tool" in answer + ? { type: "tool_use", id: "toolu_confirmation", name: answer.tool, input: {} } + : { type: "text", text: "" }, + }, + { + type: "content_block_delta", + index: 0, + delta: + "tool" in answer + ? { type: "input_json_delta", partial_json: "{}" } + : { type: "text_delta", text: answer.text }, + }, + { type: "content_block_stop", index: 0 }, + { + type: "message_delta", + delta: { stop_reason: "tool" in answer ? "tool_use" : "end_turn" }, + usage: { output_tokens: 7 }, + }, + { type: "message_stop" }, + ]; + return new Response( + frames.map((frame) => `event: ${frame.type}\ndata: ${JSON.stringify(frame)}\n\n`).join(""), + { headers: { "content-type": "text/event-stream" } }, + ); +}; diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..2f0979e --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "rootDir": "./src", + "outDir": "./dist", + "rewriteRelativeImportExtensions": true + }, + "include": ["src"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e587490 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "target": "ES2024", + "module": "ESNext", + "moduleResolution": "Bundler", + "lib": ["ES2024"], + "strict": true, + "exactOptionalPropertyTypes": true, + "noUncheckedIndexedAccess": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "verbatimModuleSyntax": true, + "erasableSyntaxOnly": true, + "allowImportingTsExtensions": true, + "skipLibCheck": true, + "noEmit": true, + "types": ["node"] + }, + "include": ["src", "test"] +}