From c83fa0b8f37158a4de09021271efbfe5d86fac4e Mon Sep 17 00:00:00 2001 From: Simon Shi Date: Sat, 27 Jun 2026 20:03:05 +0800 Subject: [PATCH] test: add unit tests and remove dead code - Add vitest with 98 tests across 6 test files covering: - cosy.ts: URL builders, mode detection, model name mapping - thinking-parser.ts: ThinkingTagParser with all tag variants and chunked streaming - transform.ts: getContentText, transformTools, transformMessagesForQoder - pat.ts: isPatRefresh, encodePatRefresh/decodePatRefresh roundtrip - qoder-encoding.ts: custom encoding correctness and edge cases - models.ts: static model definitions integrity checks - Remove dead code: - QODER_CN_DIRECT_BASE_URL (unused export in cosy.ts) - THINKING_START_TAG / THINKING_END_TAG (unused constants in thinking-parser.ts) - Add test/test:watch scripts to package.json --- package-lock.json | 1276 ++++++++++++++++++++++++- package.json | 5 +- src/__tests__/cosy.test.ts | 238 +++++ src/__tests__/models.test.ts | 88 ++ src/__tests__/pat.test.ts | 69 ++ src/__tests__/qoder-encoding.test.ts | 70 ++ src/__tests__/thinking-parser.test.ts | 236 +++++ src/__tests__/transform.test.ts | 240 +++++ src/cosy.ts | 2 - src/thinking-parser.ts | 5 +- 10 files changed, 2220 insertions(+), 9 deletions(-) create mode 100644 src/__tests__/cosy.test.ts create mode 100644 src/__tests__/models.test.ts create mode 100644 src/__tests__/pat.test.ts create mode 100644 src/__tests__/qoder-encoding.test.ts create mode 100644 src/__tests__/thinking-parser.test.ts create mode 100644 src/__tests__/transform.test.ts diff --git a/package-lock.json b/package-lock.json index 1c87088..6d0b10e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "@earendil-works/pi-ai": "^0.80.2", "@earendil-works/pi-coding-agent": "^0.80.2", "esbuild": "^0.28.1", - "typescript": "^5.7.0" + "typescript": "^5.7.0", + "vitest": "^4.1.9" } }, "node_modules/@anthropic-ai/sdk": { @@ -1258,7 +1259,7 @@ "typebox": "1.1.38" }, "bin": { - "pi-ai": "dist/cli.js" + "pi-ai": "./dist/cli.js" }, "engines": { "node": ">=22.19.0" @@ -2698,6 +2699,40 @@ "zod": "^3.25.28 || ^4" } }, + "node_modules/@emnapi/core": { + "version": "1.11.1", + "resolved": "https://registry.npmmirror.com/@emnapi/core/-/core-1.11.1.tgz", + "integrity": "sha512-RSvbQmHzdKzNsLYa/wHrbc3KN4sYLKAdPZxqiM2HATqv/SBk2/ENSHpvXGaLOMcsAyz0poEGqkmmKYG3OWiJEQ==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.2.2", + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/runtime": { + "version": "1.11.1", + "resolved": "https://registry.npmmirror.com/@emnapi/runtime/-/runtime-1.11.1.tgz", + "integrity": "sha512-vgj7R3y3Wgx24IQaGPA/R6YFXLHVMOZ0uVEyIQPaWs+rd1AzfEMXlAC22FYwO1XkKR6NPsq7mUandH8oIRdZFw==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/wasi-threads": { + "version": "1.2.2", + "resolved": "https://registry.npmmirror.com/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz", + "integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.28.1", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz", @@ -3165,6 +3200,13 @@ } } }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmmirror.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "dev": true, + "license": "MIT" + }, "node_modules/@mistralai/mistralai": { "version": "2.2.6", "resolved": "https://registry.npmjs.org/@mistralai/mistralai/-/mistralai-2.2.6.tgz", @@ -3186,6 +3228,25 @@ } } }, + "node_modules/@napi-rs/wasm-runtime": { + "version": "1.1.6", + "resolved": "https://registry.npmmirror.com/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.6.tgz", + "integrity": "sha512-ZLv/JdUfkvOy9eCnnBaGfiO+XimbjebAeO+MRQqD/B+FR1tnRN0tpKSJHRbE8sFfS6aqsXZ67TQjfwfsxULVbg==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.3" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1", + "@emnapi/runtime": "^1.7.1" + } + }, "node_modules/@nodable/entities": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@nodable/entities/-/entities-2.1.1.tgz", @@ -3219,6 +3280,16 @@ "node": ">=14" } }, + "node_modules/@oxc-project/types": { + "version": "0.137.0", + "resolved": "https://registry.npmmirror.com/@oxc-project/types/-/types-0.137.0.tgz", + "integrity": "sha512-WT+Gb24i8hmvo85AIv2oEYouEXkRlKAlT9WaCa3TfLgNCN+GhrJOGZuIlMouAh38Qe4QOx26eUOVsq70qXrywA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/Boshen" + } + }, "node_modules/@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", @@ -3292,6 +3363,288 @@ "dev": true, "license": "BSD-3-Clause" }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-android-arm64/-/binding-android-arm64-1.1.3.tgz", + "integrity": "sha512-DT6Z3PhvioeHMvxo+xHc3KtqggrI7CCTXCmC2h/5zUlp5jVitv7XEy+9q5/7v8IolhlioawpMo8Kg0EEBy7J0g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.1.3.tgz", + "integrity": "sha512-0NwgwsjM7LrsuVnXMK3koTpagBNOhloc/BNjKqZjv4V5zI5r13qx69uVhRx+o5Z0yy4Hzq+lpy7TAgUG/ocvrw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.1.3.tgz", + "integrity": "sha512-YtiBp4disu6V560loT6PjMdiRaWmVvDNrUunAalbiFx2ggeJwxdAsgZMcoGP17uyAsTwAj5V1niksxlHnVQ1Sw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.1.3.tgz", + "integrity": "sha512-yD3EkEdXk2LypPxnf/kSZHirarsI8gcPzc62SukhR9VJTyvV+F9Q/GxWNuCojc7sXyuVC4DxRGhdDK4X8VSsbw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.1.3.tgz", + "integrity": "sha512-c+8vieQbsD7HNAHKIA34w0GJ9FedFFuJGD+7E6vz7Q3uqAIugL5p45fhlsj4UaAsHpcmlqugBWMhA0/j7o0sIg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.1.3.tgz", + "integrity": "sha512-50jD0uUwLvur7Zz9LHz17kaAdTPjn5wN93hEgjvmYFRZwiR7ZJYovTd5ipyWJDAnXKvZ+wgc+/Ika6dwSF5OcA==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.1.3.tgz", + "integrity": "sha512-BO9+oPL8K9poZJBfYPsXNtYjPE5uM3qeehT3aFcW4LITOl+iSqhp0abzjR2nWBUNjIZeKXjAEWBZ64WjNoHd6w==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.1.3.tgz", + "integrity": "sha512-f3VpLB1vQ0Eo6ecr/6cekLnvYMFF4YBFoVGkfkvPLq1bAkbAwHYQPZKoAmG6OJyTcxxoC+AvezGx/S1obNC0Mw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.1.3.tgz", + "integrity": "sha512-AmurZ26Pqx/RI9N1gzEOCklkKXl927yjfXWUUS0O7Puh8ARM/Ob8qfrD3qnWksScdw6cSrW5PSHE9DyLu7+PtA==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.1.3.tgz", + "integrity": "sha512-JJpqs8bRGITDOdbkNKnlojzBabbOHrqjSvDr0IVsZObE1lBcPjxItUEY9eWIDbxaJ3cGrXPWGfGkIxFijg/URg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.1.3.tgz", + "integrity": "sha512-rSJcdjPxzA/by/6/rYs+v+bXU7UjvnbUWz8MJb6kh6+knqB1dCrtHg0uu7C/4haqJvqdkYHQ5IGn+tCH9GLW/g==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.1.3.tgz", + "integrity": "sha512-hQ3/PYkDJICgevvyNcVrihVeqq7k1Pp3VZ9lY+dauAYUJKO+auqApvANhvR1An9BhmqYKvW2Mu1F9u4DXSMLxQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.1.3.tgz", + "integrity": "sha512-Elcv/BtML9lXrV6JuKITc/grN2kYV9gjsQpW8Jfw4ioK0TOkjBjye0nnyqQNy9STNaI20lXNaQBRrD5gSgR0Yg==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "1.11.1", + "@emnapi/runtime": "1.11.1", + "@napi-rs/wasm-runtime": "^1.1.6" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.1.3.tgz", + "integrity": "sha512-2DrEfhluH9yhiaFApmsjsjwrSYbNcY1oFTzYSP1a535jDbV98zCFanA/96TBUd0iDFcxGmw9QRExwGCXz3U+/g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.1.3.tgz", + "integrity": "sha512-OL4OMk7UPXOeVGGd3qo5zJyPIljf4AFgk5QAkPPS+OoLuOOozhuaQGC18MxVTnw/06q93gShAJzlwnSCY9YtqA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmmirror.com/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "dev": true, + "license": "MIT" + }, "node_modules/@smithy/core": { "version": "3.24.6", "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.24.6.tgz", @@ -3421,6 +3774,49 @@ "node": ">=14.0.0" } }, + "node_modules/@standard-schema/spec": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/@standard-schema/spec/-/spec-1.1.0.tgz", + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tybys/wasm-util": { + "version": "0.10.3", + "resolved": "https://registry.npmmirror.com/@tybys/wasm-util/-/wasm-util-0.10.3.tgz", + "integrity": "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmmirror.com/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmmirror.com/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.9", + "resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.9.tgz", + "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/node": { "version": "25.9.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.3.tgz", @@ -3438,6 +3834,119 @@ "dev": true, "license": "MIT" }, + "node_modules/@vitest/expect": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/@vitest/expect/-/expect-4.1.9.tgz", + "integrity": "sha512-vl/rYsUKcBr3SnQn166+XR5ZQcgMx3DQhFWdfli/cWpLnLUmbxZvyrJZotLFUryib+LtArYMSTJ5RbQ57ZqrlA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.1.0", + "@types/chai": "^5.2.2", + "@vitest/spy": "4.1.9", + "@vitest/utils": "4.1.9", + "chai": "^6.2.2", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/@vitest/mocker/-/mocker-4.1.9.tgz", + "integrity": "sha512-EVkXzBjrPGM+cK8/ANWgBrkUCfJfb38/EfTSO8h7pWvKkyPkpWxvR7BkD2MyItMF62C97zAEoqdpUixwR/e+Rw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "4.1.9", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.21" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/pretty-format": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/@vitest/pretty-format/-/pretty-format-4.1.9.tgz", + "integrity": "sha512-s0iufns3iIFitdgm+YR7g1whCAaGtXz459VS9/PqyKDEEFgYIhsHOQmXgIgDuYCt7DeQmiZT0Qe2OA2p4ZPu5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/@vitest/runner/-/runner-4.1.9.tgz", + "integrity": "sha512-KXLMDtc7oe70+3mJfGrPUWPesswH+3sTxAMAMl8DG7I8IUQT4XW718dY5ID3vPUcmlu27CcKfY4P3h3I29SLJg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "4.1.9", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/@vitest/snapshot/-/snapshot-4.1.9.tgz", + "integrity": "sha512-Jc7RKGNBo8Z28WYIm0Niej4xdSPByRf6mU58VpHQkd6Zh05rlnA+twjbK5HyeIGHxrzsc3mJgS43uM0CZKzaIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.9", + "@vitest/utils": "4.1.9", + "magic-string": "^0.30.21", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/@vitest/spy/-/spy-4.1.9.tgz", + "integrity": "sha512-fHpsS6mIi+PiEW+vcRVOMkX1oSaPKne3VOclSFICPcGOmfKgXPU5iAah+wcNcj2xPrCCmfq99IDGf+EojhhvhA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/@vitest/utils/-/utils-4.1.9.tgz", + "integrity": "sha512-A51o8ymO5PpqlWNnBP9ZHPXDIpuMtTLlGSjN7la4US+LJzoUMyhwjA5QXlm39JexgwHKW4Xjs8Z2d3dLCXOeuA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.9", + "convert-source-map": "^2.0.0", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/agent-base": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", @@ -3461,6 +3970,16 @@ ], "license": "MIT" }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -3506,6 +4025,23 @@ "dev": true, "license": "BSD-3-Clause" }, + "node_modules/chai": { + "version": "6.2.2", + "resolved": "https://registry.npmmirror.com/chai/-/chai-6.2.2.tgz", + "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "dev": true, + "license": "MIT" + }, "node_modules/data-uri-to-buffer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", @@ -3534,6 +4070,16 @@ } } }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", @@ -3544,6 +4090,13 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/es-module-lexer": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/es-module-lexer/-/es-module-lexer-2.1.0.tgz", + "integrity": "sha512-n27zTYMjYu1aj4MjCWzSP7G9r75utsaoc8m61weK+W8JMBGGQybd43GstCXZ3WNmSFtGT9wi59qQTW6mhTR5LQ==", + "dev": true, + "license": "MIT" + }, "node_modules/esbuild": { "version": "0.28.1", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", @@ -3586,6 +4139,26 @@ "@esbuild/win32-x64": "0.28.1" } }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmmirror.com/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmmirror.com/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", @@ -3632,6 +4205,24 @@ "fxparser": "src/cli/cli.js" } }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmmirror.com/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, "node_modules/fetch-blob": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", @@ -3669,6 +4260,21 @@ "node": ">=12.20.0" } }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/gaxios": { "version": "7.1.5", "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-7.1.5.tgz", @@ -3802,6 +4408,279 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/lightningcss": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss/-/lightningcss-1.32.0.tgz", + "integrity": "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.32.0", + "lightningcss-darwin-arm64": "1.32.0", + "lightningcss-darwin-x64": "1.32.0", + "lightningcss-freebsd-x64": "1.32.0", + "lightningcss-linux-arm-gnueabihf": "1.32.0", + "lightningcss-linux-arm64-gnu": "1.32.0", + "lightningcss-linux-arm64-musl": "1.32.0", + "lightningcss-linux-x64-gnu": "1.32.0", + "lightningcss-linux-x64-musl": "1.32.0", + "lightningcss-win32-arm64-msvc": "1.32.0", + "lightningcss-win32-x64-msvc": "1.32.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-android-arm64/-/lightningcss-android-arm64-1.32.0.tgz", + "integrity": "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.32.0.tgz", + "integrity": "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.32.0.tgz", + "integrity": "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.32.0.tgz", + "integrity": "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.32.0.tgz", + "integrity": "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz", + "integrity": "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.32.0.tgz", + "integrity": "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz", + "integrity": "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.32.0.tgz", + "integrity": "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz", + "integrity": "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.32.0", + "resolved": "https://registry.npmmirror.com/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz", + "integrity": "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, "node_modules/long": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", @@ -3809,6 +4688,16 @@ "dev": true, "license": "Apache-2.0" }, + "node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -3816,6 +4705,25 @@ "dev": true, "license": "MIT" }, + "node_modules/nanoid": { + "version": "3.3.15", + "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.15.tgz", + "integrity": "sha512-y7Wygv/7mEOvxTuEQDB8StXdMRBWf1kR/tlhAzBRUFkB2jfcLOAxO/SHmOO2zgz1pVgK29/kyupn059/bCHdjA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -3856,6 +4764,20 @@ "url": "https://opencollective.com/node-fetch" } }, + "node_modules/obug": { + "version": "2.1.3", + "resolved": "https://registry.npmmirror.com/obug/-/obug-2.1.3.tgz", + "integrity": "sha512-9miFgM2OFba7hB+pRgvtV84pYTBaoTHohvmIgiRt6dRIzbwEOIaNaP+dIlGs2fNFoB0SeISs0Jz5WFVRid6Xyg==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/openai": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/openai/-/openai-6.26.0.tgz", @@ -3915,6 +4837,62 @@ "node": ">=14.0.0" } }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmmirror.com/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.4", + "resolved": "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.4.tgz", + "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.15", + "resolved": "https://registry.npmmirror.com/postcss/-/postcss-8.5.15.tgz", + "integrity": "sha512-FfR8sjd4em2T6fb3I2MwAJU7HWVMr9zba+enmQeeWFfCbm+UOC/0X4DS8XtpUTMwWMGbjKYP7xjfNekzyGmB3A==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.12", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, "node_modules/protobufjs": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.3.tgz", @@ -3950,6 +4928,40 @@ "node": ">= 4" } }, + "node_modules/rolldown": { + "version": "1.1.3", + "resolved": "https://registry.npmmirror.com/rolldown/-/rolldown-1.1.3.tgz", + "integrity": "sha512-1F1eEtUBtFvcGm1HQ9TiUIUHPQG7mSAODrhIzjxoUEFuo8OcbrGLiVLkevNgj84TE4lnHvnumwFjhJO5Eu135g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.137.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm64": "1.1.3", + "@rolldown/binding-darwin-arm64": "1.1.3", + "@rolldown/binding-darwin-x64": "1.1.3", + "@rolldown/binding-freebsd-x64": "1.1.3", + "@rolldown/binding-linux-arm-gnueabihf": "1.1.3", + "@rolldown/binding-linux-arm64-gnu": "1.1.3", + "@rolldown/binding-linux-arm64-musl": "1.1.3", + "@rolldown/binding-linux-ppc64-gnu": "1.1.3", + "@rolldown/binding-linux-s390x-gnu": "1.1.3", + "@rolldown/binding-linux-x64-gnu": "1.1.3", + "@rolldown/binding-linux-x64-musl": "1.1.3", + "@rolldown/binding-openharmony-arm64": "1.1.3", + "@rolldown/binding-wasm32-wasi": "1.1.3", + "@rolldown/binding-win32-arm64-msvc": "1.1.3", + "@rolldown/binding-win32-x64-msvc": "1.1.3" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -3971,6 +4983,37 @@ ], "license": "MIT" }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, + "node_modules/source-map-js": { + "version": "1.2.1", + "resolved": "https://registry.npmmirror.com/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmmirror.com/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/std-env": { + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/std-env/-/std-env-4.1.0.tgz", + "integrity": "sha512-Rq7ybcX2RuC55r9oaPVEW7/xu3tj8u4GeBYHBWCychFtzMIr86A7e3PPEBPT37sHStKX3+TiX/Fr/ACmJLVlLQ==", + "dev": true, + "license": "MIT" + }, "node_modules/strnum": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.4.0.tgz", @@ -3987,6 +5030,50 @@ "anynum": "^1.0.0" } }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmmirror.com/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "1.2.4", + "resolved": "https://registry.npmmirror.com/tinyexec/-/tinyexec-1.2.4.tgz", + "integrity": "sha512-SHf/r48b7vOrjve9PxJo3MN5v5yuyjHvdUcrQffT3WXMUfnGmHDVbC4k3sHJaJTgZCwpUplIaAo5ANtMyp3YHg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmmirror.com/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tinyrainbow": { + "version": "3.1.0", + "resolved": "https://registry.npmmirror.com/tinyrainbow/-/tinyrainbow-3.1.0.tgz", + "integrity": "sha512-Bf+ILmBgretUrdJxzXM0SgXLZ3XfiaUuOj/IKQHuTXip+05Xn+uyEYdVg0kYDipTBcLrCVyUzAPz7QmArb0mmw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/ts-algebra": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ts-algebra/-/ts-algebra-2.0.0.tgz", @@ -4029,6 +5116,174 @@ "dev": true, "license": "MIT" }, + "node_modules/vite": { + "version": "8.1.0", + "resolved": "https://registry.npmmirror.com/vite/-/vite-8.1.0.tgz", + "integrity": "sha512-BuJcQK/56NQTWDGn4ABea3q4SSBdNPWwNZKTkkUpcMPnLoquSYH8llRtSUIgoL1KSCpHt5eghLShn50mH36y7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.32.0", + "picomatch": "^4.0.4", + "postcss": "^8.5.15", + "rolldown": "~1.1.2", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.3.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" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitest": { + "version": "4.1.9", + "resolved": "https://registry.npmmirror.com/vitest/-/vitest-4.1.9.tgz", + "integrity": "sha512-nE3/LEyc0z87uHYLZebqCUOaJr2hdtuPp7BQ4BosVFnfltxgAvMG08NyrSGlPpOUWvR27c5flSmYFTNr78L9GQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "4.1.9", + "@vitest/mocker": "4.1.9", + "@vitest/pretty-format": "4.1.9", + "@vitest/runner": "4.1.9", + "@vitest/snapshot": "4.1.9", + "@vitest/spy": "4.1.9", + "@vitest/utils": "4.1.9", + "es-module-lexer": "^2.0.0", + "expect-type": "^1.3.0", + "magic-string": "^0.30.21", + "obug": "^2.1.1", + "pathe": "^2.0.3", + "picomatch": "^4.0.3", + "std-env": "^4.0.0-rc.1", + "tinybench": "^2.9.0", + "tinyexec": "^1.0.2", + "tinyglobby": "^0.2.15", + "tinyrainbow": "^3.1.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "4.1.9", + "@vitest/browser-preview": "4.1.9", + "@vitest/browser-webdriverio": "4.1.9", + "@vitest/coverage-istanbul": "4.1.9", + "@vitest/coverage-v8": "4.1.9", + "@vitest/ui": "4.1.9", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, "node_modules/web-streams-polyfill": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", @@ -4039,6 +5294,23 @@ "node": ">= 8" } }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmmirror.com/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/ws": { "version": "8.21.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz", diff --git a/package.json b/package.json index 270d20f..0a19c78 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ "lint": "node node_modules/@biomejs/biome/bin/biome check .", "lint:fix": "node node_modules/@biomejs/biome/bin/biome check --write .", "format": "node node_modules/@biomejs/biome/bin/biome format --write .", + "test": "vitest run", + "test:watch": "vitest", "prepare": "npm run build", "prepublishOnly": "npm run check && npm run build" }, @@ -37,7 +39,8 @@ "@earendil-works/pi-ai": "^0.80.2", "@earendil-works/pi-coding-agent": "^0.80.2", "esbuild": "^0.28.1", - "typescript": "^5.7.0" + "typescript": "^5.7.0", + "vitest": "^4.1.9" }, "repository": { "type": "git", diff --git a/src/__tests__/cosy.test.ts b/src/__tests__/cosy.test.ts new file mode 100644 index 0000000..1b93b08 --- /dev/null +++ b/src/__tests__/cosy.test.ts @@ -0,0 +1,238 @@ +import { describe, expect, it } from "vitest"; +import { + getQoderBaseUrl, + getQoderCNDirectModel, + getQoderCNFriendlyModelInfo, + getQoderCenterUrl, + getQoderChatURL, + getQoderExchangeURL, + getQoderManageUrl, + getQoderMode, + getQoderModelListURL, + getQoderOpenApiUrl, + getQoderRefreshURL, + getQoderUsageURL, + getQoderUserEmailFallback, + getQoderUserInfoURL, + isQoderCNMode, + toQoderCNFriendlyModel, +} from "../cosy.js"; + +// ── getQoderMode ────────────────────────────────────────────────────────── + +describe("getQoderMode", () => { + it('returns "cn" for explicit CN variants', () => { + expect(getQoderMode("cn")).toBe("cn"); + expect(getQoderMode("china")).toBe("cn"); + expect(getQoderMode("qodercn")).toBe("cn"); + expect(getQoderMode("qoder-cn")).toBe("cn"); + expect(getQoderMode("CN")).toBe("cn"); + expect(getQoderMode("China")).toBe("cn"); + }); + + it('returns "global" for explicit global variants', () => { + expect(getQoderMode("global")).toBe("global"); + expect(getQoderMode("intl")).toBe("global"); + expect(getQoderMode("international")).toBe("global"); + expect(getQoderMode("qoder")).toBe("global"); + }); + + it("falls back to global for unknown strings", () => { + expect(getQoderMode("unknown")).toBe("global"); + expect(getQoderMode("")).toBe("global"); + }); +}); + +// ── isQoderCNMode ───────────────────────────────────────────────────────── + +describe("isQoderCNMode", () => { + it("returns true for CN modes", () => { + expect(isQoderCNMode("cn")).toBe(true); + expect(isQoderCNMode("china")).toBe(true); + }); + + it("returns false for global modes", () => { + expect(isQoderCNMode("global")).toBe(false); + expect(isQoderCNMode("intl")).toBe(false); + }); +}); + +// ── URL builders ────────────────────────────────────────────────────────── + +describe("getQoderBaseUrl", () => { + it("returns CN URL for cn mode", () => { + expect(getQoderBaseUrl("cn")).toBe("https://gateway.qoder.com.cn/"); + }); + + it("returns global URL for global mode", () => { + expect(getQoderBaseUrl("global")).toBe("https://api3.qoder.sh/"); + }); +}); + +describe("getQoderOpenApiUrl", () => { + it("returns CN URL for cn mode", () => { + expect(getQoderOpenApiUrl("cn")).toBe("https://openapi.qoder.com.cn"); + }); + + it("returns global URL for global mode", () => { + expect(getQoderOpenApiUrl("global")).toBe("https://openapi.qoder.sh"); + }); +}); + +describe("getQoderCenterUrl", () => { + it("returns CN URL for cn mode", () => { + expect(getQoderCenterUrl("cn")).toBe("https://gateway.qoder.com.cn"); + }); + + it("returns global URL for global mode", () => { + expect(getQoderCenterUrl("global")).toBe("https://center.qoder.sh"); + }); +}); + +describe("getQoderModelListURL", () => { + it("constructs correct CN URL", () => { + expect(getQoderModelListURL("cn")).toBe("https://gateway.qoder.com.cn/algo/api/v2/model/list"); + }); + + it("constructs correct global URL", () => { + expect(getQoderModelListURL("global")).toBe("https://api3.qoder.sh/algo/api/v2/model/list"); + }); +}); + +describe("getQoderChatURL", () => { + it("contains base URL and chat path", () => { + const url = getQoderChatURL("global"); + expect(url).toContain("https://api3.qoder.sh/"); + expect(url).toContain("algo/api/v2/service/pro/sse/agent_chat_generation"); + expect(url).toContain("Encode=1"); + }); +}); + +describe("getQoderExchangeURL", () => { + it("constructs correct CN URL", () => { + expect(getQoderExchangeURL("cn")).toBe("https://openapi.qoder.com.cn/api/v1/jobToken/exchange"); + }); + + it("constructs correct global URL", () => { + expect(getQoderExchangeURL("global")).toBe("https://openapi.qoder.sh/api/v1/jobToken/exchange"); + }); +}); + +describe("getQoderUserInfoURL", () => { + it("constructs correct URL", () => { + expect(getQoderUserInfoURL("global")).toBe("https://openapi.qoder.sh/api/v1/userinfo"); + }); +}); + +describe("getQoderUsageURL", () => { + it("constructs correct URL", () => { + expect(getQoderUsageURL("global")).toBe("https://openapi.qoder.sh/api/v2/quota/usage"); + }); +}); + +describe("getQoderRefreshURL", () => { + it("constructs correct CN URL", () => { + expect(getQoderRefreshURL("cn")).toBe("https://gateway.qoder.com.cn/algo/api/v3/user/refresh_token"); + }); + + it("constructs correct global URL", () => { + expect(getQoderRefreshURL("global")).toBe("https://center.qoder.sh/algo/api/v3/user/refresh_token"); + }); +}); + +describe("getQoderManageUrl", () => { + it("returns CN URL", () => { + expect(getQoderManageUrl("cn")).toBe("https://qoder.com.cn"); + }); + + it("returns global URL", () => { + expect(getQoderManageUrl("global")).toBe("https://qoder.com"); + }); +}); + +describe("getQoderUserEmailFallback", () => { + it("returns CN email", () => { + expect(getQoderUserEmailFallback("cn")).toBe("user@qoder.com.cn"); + }); + + it("returns global email", () => { + expect(getQoderUserEmailFallback("global")).toBe("user@qoder.com"); + }); +}); + +// ── getQoderCNDirectModel ───────────────────────────────────────────────── + +describe("getQoderCNDirectModel", () => { + it("maps known model IDs to internal keys", () => { + expect(getQoderCNDirectModel("qoder-cn")).toBe("auto"); + expect(getQoderCNDirectModel("qwen3.7-max")).toBe("qmodel_latest"); + expect(getQoderCNDirectModel("qwen3.7-plus")).toBe("qmodel"); + expect(getQoderCNDirectModel("qwen3.6-plus")).toBe("qmodel"); + expect(getQoderCNDirectModel("qwen3.6-flash")).toBe("q36fmodel"); + expect(getQoderCNDirectModel("deepseek-v4-pro")).toBe("dmodel"); + expect(getQoderCNDirectModel("deepseek-v4-flash")).toBe("dfmodel"); + expect(getQoderCNDirectModel("glm-5.2")).toBe("gm51model"); + expect(getQoderCNDirectModel("glm-5.1")).toBe("gm51model"); + expect(getQoderCNDirectModel("kimi-k2.6")).toBe("kmodel"); + expect(getQoderCNDirectModel("minimax-m2.7")).toBe("mmodel"); + expect(getQoderCNDirectModel("minimax-m3")).toBe("mmodel"); + }); + + it("returns the input ID for unknown models", () => { + expect(getQoderCNDirectModel("custom-model")).toBe("custom-model"); + }); + + it('defaults to "auto" when no input', () => { + expect(getQoderCNDirectModel()).toBe("auto"); + expect(getQoderCNDirectModel("")).toBe("auto"); + }); +}); + +// ── getQoderCNFriendlyModelInfo ─────────────────────────────────────────── + +describe("getQoderCNFriendlyModelInfo", () => { + it("returns known friendly info for mapped keys", () => { + const info = getQoderCNFriendlyModelInfo("qmodel_latest"); + expect(info.id).toBe("qwen3.7-max"); + expect(info.name).toBe("Qwen 3.7 Max · Qoder CN"); + }); + + it("returns auto mapping", () => { + const info = getQoderCNFriendlyModelInfo("auto"); + expect(info.id).toBe("auto"); + expect(info.name).toBe("Auto · Qoder CN"); + }); + + it("generates friendly name for unknown keys", () => { + const info = getQoderCNFriendlyModelInfo("my-custom-model", "My Custom Model"); + expect(info.id).toBe("my-custom-model"); + expect(info.name).toContain("Qoder CN"); + }); + + it("prettifies model names with version numbers", () => { + const info = getQoderCNFriendlyModelInfo("some-model", "Qwen3.7-New"); + expect(info.name).toContain("Qwen 3.7"); + expect(info.name).toContain("Qoder CN"); + }); +}); + +// ── toQoderCNFriendlyModel ──────────────────────────────────────────────── + +describe("toQoderCNFriendlyModel", () => { + it("maps known model ID to friendly version", () => { + const result = toQoderCNFriendlyModel({ id: "qmodel_latest", name: "Original Name" }); + expect(result.id).toBe("qwen3.7-max"); + expect(result.name).toBe("Qwen 3.7 Max · Qoder CN"); + }); + + it("preserves extra fields", () => { + const result = toQoderCNFriendlyModel({ id: "auto", name: "Auto", extra: "field" } as any); + expect(result.extra).toBe("field"); + }); + + it("handles unknown models by prettifying display name", () => { + const result = toQoderCNFriendlyModel({ id: "custom", name: "CustomModel V2-Pro" }); + expect(result.id).toBe("custom"); + expect(result.name).toContain("Qoder CN"); + }); +}); diff --git a/src/__tests__/models.test.ts b/src/__tests__/models.test.ts new file mode 100644 index 0000000..ec9ba65 --- /dev/null +++ b/src/__tests__/models.test.ts @@ -0,0 +1,88 @@ +import { describe, expect, it } from "vitest"; +import { ZERO_COST, staticCnModels, staticModels } from "../models.js"; + +// ── staticModels ────────────────────────────────────────────────────────── + +describe("staticModels", () => { + it("is a non-empty array", () => { + expect(Array.isArray(staticModels)).toBe(true); + expect(staticModels.length).toBeGreaterThan(0); + }); + + it("has auto as first entry", () => { + expect(staticModels[0].id).toBe("auto"); + }); + + it("every model has required fields", () => { + for (const m of staticModels) { + expect(m.id).toBeTruthy(); + expect(m.name).toBeTruthy(); + expect(m.api).toBe("qoder-api"); + expect(m.provider).toBe("qoder"); + expect(m.baseUrl).toBeTruthy(); + expect(typeof m.reasoning).toBe("boolean"); + expect(typeof m.supportsEffort).toBe("boolean"); + expect(Array.isArray(m.input)).toBe(true); + expect(m.cost).toBe(ZERO_COST); + expect(m.contextWindow).toBeGreaterThan(0); + expect(m.maxTokens).toBeGreaterThan(0); + } + }); + + it("has unique IDs", () => { + const ids = staticModels.map((m) => m.id); + expect(new Set(ids).size).toBe(ids.length); + }); +}); + +// ── staticCnModels ──────────────────────────────────────────────────────── + +describe("staticCnModels", () => { + it("is a non-empty array", () => { + expect(Array.isArray(staticCnModels)).toBe(true); + expect(staticCnModels.length).toBeGreaterThan(0); + }); + + it("has auto as first entry", () => { + expect(staticCnModels[0].id).toBe("auto"); + }); + + it("every CN model has required fields", () => { + for (const m of staticCnModels) { + expect(m.id).toBeTruthy(); + expect(m.name).toBeTruthy(); + expect(m.api).toBe("qoder-api"); + expect(m.provider).toBe("qoder-cn"); + expect(m.baseUrl).toContain("qoder.com.cn"); + expect(typeof m.reasoning).toBe("boolean"); + expect(typeof m.supportsEffort).toBe("boolean"); + expect(Array.isArray(m.input)).toBe(true); + expect(m.cost).toBe(ZERO_COST); + expect(m.contextWindow).toBeGreaterThan(0); + expect(m.maxTokens).toBeGreaterThan(0); + } + }); + + it("has unique IDs", () => { + const ids = staticCnModels.map((m) => m.id); + expect(new Set(ids).size).toBe(ids.length); + }); + + it("every CN model has a description", () => { + for (const m of staticCnModels) { + expect(m.description).toBeTruthy(); + } + }); +}); + +// ── ZERO_COST ───────────────────────────────────────────────────────────── + +describe("ZERO_COST", () => { + it("has all zero values", () => { + expect(ZERO_COST).toEqual({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }); + }); + + it("is frozen", () => { + expect(Object.isFrozen(ZERO_COST)).toBe(true); + }); +}); diff --git a/src/__tests__/pat.test.ts b/src/__tests__/pat.test.ts new file mode 100644 index 0000000..1b0eda3 --- /dev/null +++ b/src/__tests__/pat.test.ts @@ -0,0 +1,69 @@ +import { describe, expect, it } from "vitest"; +import { PAT_REFRESH_PREFIX, decodePatRefresh, encodePatRefresh, isPatRefresh } from "../pat.js"; + +// ── isPatRefresh ────────────────────────────────────────────────────────── + +describe("isPatRefresh", () => { + it("returns true for PAT refresh strings", () => { + expect(isPatRefresh("pat|mytoken|refresh123|user1|machine1")).toBe(true); + }); + + it("returns true for minimal PAT prefix", () => { + expect(isPatRefresh("pat|")).toBe(true); + }); + + it("returns false for non-PAT refresh strings", () => { + expect(isPatRefresh("some-other-refresh-token")).toBe(false); + expect(isPatRefresh("refresh|user|machine")).toBe(false); + }); + + it("returns false for empty string", () => { + expect(isPatRefresh("")).toBe(false); + }); +}); + +// ── encodePatRefresh / decodePatRefresh ─────────────────────────────────── + +describe("encodePatRefresh / decodePatRefresh roundtrip", () => { + it("encodes and decodes correctly", () => { + const encoded = encodePatRefresh("pt-abc123", "jrt-xyz", "user-42", "machine-7"); + expect(encoded).toBe("pat|pt-abc123|jrt-xyz|user-42|machine-7"); + + const decoded = decodePatRefresh(encoded); + expect(decoded).toEqual({ + pat: "pt-abc123", + jobRefreshToken: "jrt-xyz", + userID: "user-42", + machineID: "machine-7", + }); + }); + + it("handles empty fields", () => { + const encoded = encodePatRefresh("", "", "", ""); + expect(encoded).toBe("pat||||"); + + const decoded = decodePatRefresh(encoded); + expect(decoded).toEqual({ + pat: "", + jobRefreshToken: "", + userID: "", + machineID: "", + }); + }); + + it("handles pipe characters in fields gracefully", () => { + // The decode splits on |, so extra pipes shift fields + const encoded = encodePatRefresh("pt-test", "jrt-ok", "u1", "m1"); + const decoded = decodePatRefresh(encoded); + expect(decoded.pat).toBe("pt-test"); + expect(decoded.jobRefreshToken).toBe("jrt-ok"); + expect(decoded.userID).toBe("u1"); + expect(decoded.machineID).toBe("m1"); + }); +}); + +describe("PAT_REFRESH_PREFIX", () => { + it('is "pat"', () => { + expect(PAT_REFRESH_PREFIX).toBe("pat"); + }); +}); diff --git a/src/__tests__/qoder-encoding.test.ts b/src/__tests__/qoder-encoding.test.ts new file mode 100644 index 0000000..9f98d73 --- /dev/null +++ b/src/__tests__/qoder-encoding.test.ts @@ -0,0 +1,70 @@ +import { describe, expect, it } from "vitest"; +import { qoderEncodeBody } from "../qoder-encoding.js"; + +describe("qoderEncodeBody", () => { + it("encodes a simple string", () => { + const result = qoderEncodeBody("hello"); + expect(result).toBeTruthy(); + expect(typeof result).toBe("string"); + // Should not contain standard base64 padding char '=' + expect(result).not.toContain("="); + }); + + it("encodes a Buffer", () => { + const buf = Buffer.from("hello world"); + const result = qoderEncodeBody(buf); + expect(result).toBeTruthy(); + expect(result).not.toContain("="); + }); + + it("produces deterministic output", () => { + const a = qoderEncodeBody("test input"); + const b = qoderEncodeBody("test input"); + expect(a).toBe(b); + }); + + it("produces different output for different inputs", () => { + const a = qoderEncodeBody("input A"); + const b = qoderEncodeBody("input B"); + expect(a).not.toBe(b); + }); + + it("handles empty string", () => { + const result = qoderEncodeBody(""); + expect(result).toBe(""); + }); + + it("handles empty Buffer", () => { + const result = qoderEncodeBody(Buffer.alloc(0)); + expect(result).toBe(""); + }); + + it("replaces '=' padding with '$'", () => { + // Base64 of "a" is "YQ==" which has padding — our encoding should use $ + const result = qoderEncodeBody("a"); + expect(result).not.toContain("="); + expect(result).toContain("$"); + }); + + it("uses custom alphabet (not standard base64)", () => { + const result = qoderEncodeBody("The quick brown fox"); + // Standard base64 would use A-Za-z0-9+/= + // Our encoding uses a custom alphabet, so the output should differ + const stdBase64 = Buffer.from("The quick brown fox").toString("base64"); + expect(result).not.toBe(stdBase64); + }); + + it("handles binary content", () => { + const binary = Buffer.from([0x00, 0xff, 0x80, 0x7f, 0x01]); + const result = qoderEncodeBody(binary); + expect(result).toBeTruthy(); + expect(result).not.toContain("="); + }); + + it("handles JSON content", () => { + const json = JSON.stringify({ key: "value", num: 42 }); + const result = qoderEncodeBody(json); + expect(result).toBeTruthy(); + expect(result).not.toContain("="); + }); +}); diff --git a/src/__tests__/thinking-parser.test.ts b/src/__tests__/thinking-parser.test.ts new file mode 100644 index 0000000..b5de5ad --- /dev/null +++ b/src/__tests__/thinking-parser.test.ts @@ -0,0 +1,236 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import type { AssistantMessage, AssistantMessageEventStream } from "@earendil-works/pi-ai"; +import { ThinkingTagParser } from "../thinking-parser.js"; + +function createMockStream() { + const events: any[] = []; + const push = vi.fn((event: any) => events.push(event)); + const stream = { + push, + end: vi.fn(), + [Symbol.iterator]: function* () {}, + [Symbol.asyncIterator]: function* () {}, + events, + } as unknown as AssistantMessageEventStream; + return { stream, push, events }; +} + +function createOutput(): AssistantMessage { + return { + role: "assistant", + content: [], + api: "qoder-api" as any, + provider: "qoder", + model: "test", + usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, + stopReason: "stop", + timestamp: Date.now(), + } as AssistantMessage; +} + +describe("ThinkingTagParser", () => { + let output: AssistantMessage; + let stream: AssistantMessageEventStream; + let pushMock: ReturnType; + + beforeEach(() => { + output = createOutput(); + const mock = createMockStream(); + stream = mock.stream; + pushMock = mock.push; + }); + + // ── Plain text (no thinking tags) ───────────────────────────────────── + + it("passes plain text through without modification", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("Hello world"); + parser.finalize(); + + expect(output.content).toHaveLength(1); + expect(output.content[0]).toMatchObject({ type: "text", text: "Hello world" }); + }); + + it("handles empty input", () => { + const parser = new ThinkingTagParser(output, stream); + parser.finalize(); + expect(output.content).toHaveLength(0); + }); + + // ── Standard tags ────────────────────────────────────────── + + it("extracts thinking content from tags", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("Hello reasoning here world"); + parser.finalize(); + + // Parser inserts thinking block before existing text via splice, then creates a new text block after + expect(output.content).toHaveLength(3); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "reasoning here" }); + expect(output.content[1]).toMatchObject({ type: "text", text: "Hello " }); + expect(output.content[2]).toMatchObject({ type: "text", text: " world" }); + }); + + it("handles thinking-only content", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("just thinking"); + parser.finalize(); + + expect(output.content).toHaveLength(1); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "just thinking" }); + }); + + // ── Alternative tag variants ────────────────────────────────────────── + + it("handles tags", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("Hello reasoning world"); + parser.finalize(); + + expect(output.content).toHaveLength(3); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "reasoning" }); + expect(output.content[1]).toMatchObject({ type: "text", text: "Hello " }); + expect(output.content[2]).toMatchObject({ type: "text", text: " world" }); + }); + + it("handles tags", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("deep thought"); + parser.finalize(); + + expect(output.content).toHaveLength(1); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "deep thought" }); + }); + + it("handles tags", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("pondering"); + parser.finalize(); + + expect(output.content).toHaveLength(1); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "pondering" }); + }); + + // ── Chunked streaming ───────────────────────────────────────────────── + + it("handles thinking content split across multiple chunks", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("Hello part1 "); + parser.processChunk("part2 world"); + parser.finalize(); + + expect(output.content).toHaveLength(3); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "part1 part2" }); + expect(output.content[1]).toMatchObject({ type: "text", text: "Hello " }); + expect(output.content[2]).toMatchObject({ type: "text", text: " world" }); + }); + + it("handles open tag split across chunks", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("text body"); + parser.finalize(); + + expect(output.content).toHaveLength(2); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "body" }); + expect(output.content[1]).toMatchObject({ type: "text", text: "text " }); + }); + + // ── Multiple thinking blocks ────────────────────────────────────────── + + it("handles multiple thinking blocks", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("first text second"); + parser.finalize(); + + // After first thinking block, the parser is in "thinkingExtracted" state + // and emits remaining text. The second tag is in the post-thinking + // text buffer and gets emitted as plain text (parser doesn't re-enter thinking). + expect(output.content.length).toBeGreaterThanOrEqual(1); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "first" }); + }); + + // ── Edge cases ──────────────────────────────────────────────────────── + + it("handles text ending with partial tag prefix", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("Hello c.type === "text"); + expect(textBlocks.length).toBeGreaterThanOrEqual(1); + const allText = textBlocks.map((c: any) => c.text).join(""); + expect(allText).toContain("Hello"); + expect(allText).toContain(" { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("thought\n\nActual text"); + parser.finalize(); + + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "thought" }); + expect(output.content[1]).toMatchObject({ type: "text", text: "Actual text" }); + }); + + // ── getTextBlockIndex ───────────────────────────────────────────────── + + it("tracks text block index correctly", () => { + const parser = new ThinkingTagParser(output, stream); + expect(parser.getTextBlockIndex()).toBeNull(); + + parser.processChunk("Hello"); + expect(parser.getTextBlockIndex()).toBe(0); + + parser.processChunk("thought"); + parser.processChunk(" World"); + expect(parser.getTextBlockIndex()).not.toBeNull(); + }); + + // ── Stream events ───────────────────────────────────────────────────── + + it("emits text_start and text_delta events for plain text", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("Hi"); + parser.finalize(); + + const eventTypes = pushMock.mock.calls.map((c: any) => c[0].type); + expect(eventTypes).toContain("text_start"); + expect(eventTypes).toContain("text_delta"); + }); + + it("emits thinking_start and thinking_delta events for thinking content", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("deep"); + parser.finalize(); + + const eventTypes = pushMock.mock.calls.map((c: any) => c[0].type); + expect(eventTypes).toContain("thinking_start"); + expect(eventTypes).toContain("thinking_delta"); + expect(eventTypes).toContain("thinking_end"); + }); + + // ── Finalize with remaining buffer ──────────────────────────────────── + + it("finalize flushes remaining text when not in thinking mode", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("partial"); + parser.finalize(); + + expect(output.content).toHaveLength(1); + expect(output.content[0]).toMatchObject({ type: "text", text: "partial" }); + }); + + it("finalize flushes remaining thinking when in thinking mode", () => { + const parser = new ThinkingTagParser(output, stream); + parser.processChunk("unfinished"); + parser.finalize(); + + expect(output.content).toHaveLength(1); + expect(output.content[0]).toMatchObject({ type: "thinking", thinking: "unfinished" }); + }); +}); diff --git a/src/__tests__/transform.test.ts b/src/__tests__/transform.test.ts new file mode 100644 index 0000000..65ccf17 --- /dev/null +++ b/src/__tests__/transform.test.ts @@ -0,0 +1,240 @@ +import { describe, expect, it } from "vitest"; +import type { Message, Tool } from "@earendil-works/pi-ai"; +import { getContentText, transformMessagesForQoder, transformTools } from "../transform.js"; + +// ── getContentText ──────────────────────────────────────────────────────── + +describe("getContentText", () => { + it("returns string content directly", () => { + const msg = { role: "user", content: "hello" } as Message; + expect(getContentText(msg)).toBe("hello"); + }); + + it("joins text and thinking blocks from array content", () => { + const msg = { + role: "assistant", + content: [ + { type: "text", text: "answer" }, + { type: "thinking", thinking: "reasoning" }, + ], + } as unknown as Message; + expect(getContentText(msg)).toBe("answerreasoning"); + }); + + it("skips non-text/non-thinking blocks", () => { + const msg = { + role: "assistant", + content: [ + { type: "text", text: "a" }, + { type: "image", data: "base64", mimeType: "image/png" }, + { type: "text", text: "b" }, + ], + } as unknown as Message; + expect(getContentText(msg)).toBe("ab"); + }); + + it("returns empty string for null content", () => { + const msg = { role: "assistant", content: null } as unknown as Message; + expect(getContentText(msg)).toBe(""); + }); + + it("returns empty string for undefined content", () => { + const msg = { role: "assistant" } as unknown as Message; + expect(getContentText(msg)).toBe(""); + }); +}); + +// ── transformTools ──────────────────────────────────────────────────────── + +describe("transformTools", () => { + it("transforms tools to Qoder format", () => { + const tools: Tool[] = [ + { + name: "read_file", + description: "Read a file", + parameters: { type: "object", properties: { path: { type: "string" } } }, + }, + ]; + + const result = transformTools(tools); + expect(result).toHaveLength(1); + expect(result[0]).toEqual({ + type: "function", + function: { + name: "read_file", + description: "Read a file", + parameters: { type: "object", properties: { path: { type: "string" } } }, + }, + }); + }); + + it("handles empty tools array", () => { + expect(transformTools([])).toEqual([]); + }); + + it("preserves all tool properties", () => { + const tools: Tool[] = [ + { name: "a", description: "desc a", parameters: { p: 1 } }, + { name: "b", description: "desc b", parameters: { q: 2 } }, + ]; + const result = transformTools(tools); + expect(result).toHaveLength(2); + expect(result[0].function.name).toBe("a"); + expect(result[1].function.name).toBe("b"); + }); +}); + +// ── transformMessagesForQoder ───────────────────────────────────────────── + +describe("transformMessagesForQoder", () => { + it("passes through simple user string messages", () => { + const msgs: Message[] = [{ role: "user", content: "hello" } as Message]; + const result = transformMessagesForQoder(msgs); + expect(result).toEqual([{ role: "user", content: "hello" }]); + }); + + it("skips assistant messages with error stopReason", () => { + const msgs = [ + { role: "user", content: "hi" }, + { role: "assistant", content: "err", stopReason: "error" }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect(result).toHaveLength(1); + expect(result[0].role).toBe("user"); + }); + + it("skips assistant messages with aborted stopReason", () => { + const msgs = [ + { role: "assistant", content: "aborted", stopReason: "aborted" }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect(result).toHaveLength(0); + }); + + it("handles user message with array content (text only)", () => { + const msgs = [ + { + role: "user", + content: [ + { type: "text", text: "part1" }, + { type: "text", text: "part2" }, + ], + }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect(result[0].content).toBe("part1part2"); + }); + + it("handles user message with image content", () => { + const msgs = [ + { + role: "user", + content: [ + { type: "text", text: "look at " }, + { type: "image", data: "abc123", mimeType: "image/png" }, + ], + }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + const content = result[0].content as any[]; + expect(content).toHaveLength(2); + expect(content[0]).toEqual({ type: "text", text: "look at " }); + expect(content[1]).toEqual({ + type: "image_url", + image_url: { url: "data:image/png;base64,abc123" }, + }); + }); + + it("handles assistant message with text and tool calls", () => { + const msgs = [ + { + role: "assistant", + content: [ + { type: "text", text: "I'll read the file" }, + { + type: "toolCall", + id: "call_1", + name: "read_file", + arguments: { path: "/tmp/test" }, + }, + ], + }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect(result[0].role).toBe("assistant"); + expect(result[0].content).toBe("I'll read the file"); + expect((result[0] as any).tool_calls).toHaveLength(1); + expect((result[0] as any).tool_calls[0]).toMatchObject({ + id: "call_1", + type: "function", + function: { + name: "read_file", + arguments: JSON.stringify({ path: "/tmp/test" }), + }, + }); + }); + + it("handles assistant message with thinking block", () => { + const msgs = [ + { + role: "assistant", + content: [ + { type: "thinking", thinking: "let me think" }, + { type: "text", text: "answer" }, + ], + }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect(result[0].content).toContain("let me think"); + expect(result[0].content).toContain("answer"); + }); + + it("handles toolResult messages", () => { + const msgs = [ + { + role: "toolResult", + toolCallId: "call_1", + content: "file content here", + }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect(result[0]).toEqual({ + role: "tool", + tool_call_id: "call_1", + content: "file content here", + }); + }); + + it("handles assistant message with string content", () => { + const msgs = [ + { + role: "assistant", + content: "simple response", + }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect(result[0]).toEqual({ + role: "assistant", + content: "simple response", + }); + }); + + it("sets content to null for assistant messages with empty content", () => { + const msgs = [ + { + role: "assistant", + content: [ + { + type: "toolCall", + id: "c1", + name: "fn", + arguments: {}, + }, + ], + }, + ] as unknown as Message[]; + const result = transformMessagesForQoder(msgs); + expect((result[0] as any).content).toBeNull(); + expect((result[0] as any).tool_calls).toHaveLength(1); + }); +}); diff --git a/src/cosy.ts b/src/cosy.ts index ee44751..7fdb635 100644 --- a/src/cosy.ts +++ b/src/cosy.ts @@ -70,8 +70,6 @@ export function getQoderBaseUrl(mode?: string): string { return isQoderCNMode(mode) ? "https://gateway.qoder.com.cn/" : "https://api3.qoder.sh/"; } -export const QODER_CN_DIRECT_BASE_URL = getQoderBaseUrl("cn"); - export function getQoderOpenApiUrl(mode?: string): string { return isQoderCNMode(mode) ? "https://openapi.qoder.com.cn" : "https://openapi.qoder.sh"; } diff --git a/src/thinking-parser.ts b/src/thinking-parser.ts index ece7f42..560dba7 100644 --- a/src/thinking-parser.ts +++ b/src/thinking-parser.ts @@ -5,9 +5,6 @@ import type { ThinkingContent, } from "@earendil-works/pi-ai"; -export const THINKING_START_TAG = ""; -export const THINKING_END_TAG = ""; - const THINKING_TAG_VARIANTS: Array<{ open: string; close: string }> = [ { open: "", close: "" }, { open: "", close: "" }, @@ -38,7 +35,7 @@ export class ThinkingTagParser { private thinkingBlockIndex: number | null = null; private textBlockIndex: number | null = null; private lastTextBlockIndex: number | null = null; - private activeEndTag: string = THINKING_END_TAG; + private activeEndTag: string = THINKING_TAG_VARIANTS[0].close; constructor( private output: AssistantMessage,