dsh-desktop-statusbar 3.0.4 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.de.md +267 -0
- package/README.en.md +136 -14
- package/README.es.md +267 -0
- package/README.fr.md +267 -0
- package/README.ja.md +267 -0
- package/README.md +136 -14
- package/README.pt.md +267 -0
- package/README.ru.md +267 -0
- package/docs/pricing.de.png +0 -0
- package/docs/pricing.es.png +0 -0
- package/docs/pricing.fr.png +0 -0
- package/docs/pricing.ja.png +0 -0
- package/docs/pricing.pt.png +0 -0
- package/docs/pricing.ru.png +0 -0
- package/docs/settings.de.png +0 -0
- package/docs/settings.es.png +0 -0
- package/docs/settings.fr.png +0 -0
- package/docs/settings.ja.png +0 -0
- package/docs/settings.pt.png +0 -0
- package/docs/settings.ru.png +0 -0
- package/lib/balance-api.js +1042 -782
- package/lib/client.js +12775 -12364
- package/lib/index.js +8340 -7784
- package/lib/vendor/zod/LICENSE +21 -0
- package/lib/vendor/zod/index.cjs +52 -0
- package/lib/vendor/zod/index.js +7 -0
- package/lib/vendor/zod/locales/index.cjs +36 -0
- package/lib/vendor/zod/locales/index.d.cts +1 -0
- package/lib/vendor/zod/locales/index.d.ts +1 -0
- package/lib/vendor/zod/locales/index.js +1 -0
- package/lib/vendor/zod/locales/package.json +7 -0
- package/lib/vendor/zod/mini/index.cjs +51 -0
- package/lib/vendor/zod/mini/index.d.cts +3 -0
- package/lib/vendor/zod/mini/index.d.ts +3 -0
- package/lib/vendor/zod/mini/index.js +3 -0
- package/lib/vendor/zod/mini/package.json +7 -0
- package/lib/vendor/zod/package.json +147 -0
- package/lib/vendor/zod/v3/ZodError.cjs +167 -0
- package/lib/vendor/zod/v3/ZodError.d.cts +164 -0
- package/lib/vendor/zod/v3/ZodError.d.ts +164 -0
- package/lib/vendor/zod/v3/ZodError.js +143 -0
- package/lib/vendor/zod/v3/errors.cjs +36 -0
- package/lib/vendor/zod/v3/errors.d.cts +5 -0
- package/lib/vendor/zod/v3/errors.d.ts +5 -0
- package/lib/vendor/zod/v3/errors.js +9 -0
- package/lib/vendor/zod/v3/external.cjs +41 -0
- package/lib/vendor/zod/v3/external.d.cts +6 -0
- package/lib/vendor/zod/v3/external.d.ts +6 -0
- package/lib/vendor/zod/v3/external.js +6 -0
- package/lib/vendor/zod/v3/helpers/enumUtil.cjs +21 -0
- package/lib/vendor/zod/v3/helpers/enumUtil.d.cts +8 -0
- package/lib/vendor/zod/v3/helpers/enumUtil.d.ts +8 -0
- package/lib/vendor/zod/v3/helpers/enumUtil.js +1 -0
- package/lib/vendor/zod/v3/helpers/errorUtil.cjs +28 -0
- package/lib/vendor/zod/v3/helpers/errorUtil.d.cts +9 -0
- package/lib/vendor/zod/v3/helpers/errorUtil.d.ts +9 -0
- package/lib/vendor/zod/v3/helpers/errorUtil.js +6 -0
- package/lib/vendor/zod/v3/helpers/parseUtil.cjs +143 -0
- package/lib/vendor/zod/v3/helpers/parseUtil.d.cts +78 -0
- package/lib/vendor/zod/v3/helpers/parseUtil.d.ts +78 -0
- package/lib/vendor/zod/v3/helpers/parseUtil.js +109 -0
- package/lib/vendor/zod/v3/helpers/partialUtil.cjs +21 -0
- package/lib/vendor/zod/v3/helpers/partialUtil.d.cts +8 -0
- package/lib/vendor/zod/v3/helpers/partialUtil.d.ts +8 -0
- package/lib/vendor/zod/v3/helpers/partialUtil.js +1 -0
- package/lib/vendor/zod/v3/helpers/typeAliases.cjs +21 -0
- package/lib/vendor/zod/v3/helpers/typeAliases.d.cts +2 -0
- package/lib/vendor/zod/v3/helpers/typeAliases.d.ts +2 -0
- package/lib/vendor/zod/v3/helpers/typeAliases.js +1 -0
- package/lib/vendor/zod/v3/helpers/util.cjs +156 -0
- package/lib/vendor/zod/v3/helpers/util.d.cts +85 -0
- package/lib/vendor/zod/v3/helpers/util.d.ts +85 -0
- package/lib/vendor/zod/v3/helpers/util.js +133 -0
- package/lib/vendor/zod/v3/index.cjs +52 -0
- package/lib/vendor/zod/v3/index.d.cts +4 -0
- package/lib/vendor/zod/v3/index.d.ts +4 -0
- package/lib/vendor/zod/v3/index.js +4 -0
- package/lib/vendor/zod/v3/locales/en.cjs +112 -0
- package/lib/vendor/zod/v3/locales/en.d.cts +3 -0
- package/lib/vendor/zod/v3/locales/en.d.ts +3 -0
- package/lib/vendor/zod/v3/locales/en.js +109 -0
- package/lib/vendor/zod/v3/package.json +7 -0
- package/lib/vendor/zod/v3/standard-schema.cjs +21 -0
- package/lib/vendor/zod/v3/standard-schema.d.cts +102 -0
- package/lib/vendor/zod/v3/standard-schema.d.ts +102 -0
- package/lib/vendor/zod/v3/standard-schema.js +1 -0
- package/lib/vendor/zod/v3/types.cjs +3798 -0
- package/lib/vendor/zod/v3/types.d.cts +1034 -0
- package/lib/vendor/zod/v3/types.d.ts +1034 -0
- package/lib/vendor/zod/v3/types.js +3697 -0
- package/lib/vendor/zod/v4/classic/checks.cjs +53 -0
- package/lib/vendor/zod/v4/classic/checks.d.cts +1 -0
- package/lib/vendor/zod/v4/classic/checks.d.ts +1 -0
- package/lib/vendor/zod/v4/classic/checks.js +1 -0
- package/lib/vendor/zod/v4/classic/coerce.cjs +66 -0
- package/lib/vendor/zod/v4/classic/coerce.d.cts +17 -0
- package/lib/vendor/zod/v4/classic/coerce.d.ts +17 -0
- package/lib/vendor/zod/v4/classic/coerce.js +17 -0
- package/lib/vendor/zod/v4/classic/compat.cjs +80 -0
- package/lib/vendor/zod/v4/classic/compat.d.cts +48 -0
- package/lib/vendor/zod/v4/classic/compat.d.ts +48 -0
- package/lib/vendor/zod/v4/classic/compat.js +31 -0
- package/lib/vendor/zod/v4/classic/deep-partial.cjs +58 -0
- package/lib/vendor/zod/v4/classic/deep-partial.d.cts +14 -0
- package/lib/vendor/zod/v4/classic/deep-partial.d.ts +14 -0
- package/lib/vendor/zod/v4/classic/deep-partial.js +13 -0
- package/lib/vendor/zod/v4/classic/errors.cjs +102 -0
- package/lib/vendor/zod/v4/classic/errors.d.cts +29 -0
- package/lib/vendor/zod/v4/classic/errors.d.ts +29 -0
- package/lib/vendor/zod/v4/classic/errors.js +57 -0
- package/lib/vendor/zod/v4/classic/external.cjs +97 -0
- package/lib/vendor/zod/v4/classic/external.d.cts +19 -0
- package/lib/vendor/zod/v4/classic/external.d.ts +19 -0
- package/lib/vendor/zod/v4/classic/external.js +17 -0
- package/lib/vendor/zod/v4/classic/from-json-schema.cjs +926 -0
- package/lib/vendor/zod/v4/classic/from-json-schema.d.cts +12 -0
- package/lib/vendor/zod/v4/classic/from-json-schema.d.ts +12 -0
- package/lib/vendor/zod/v4/classic/from-json-schema.js +881 -0
- package/lib/vendor/zod/v4/classic/in-out.cjs +82 -0
- package/lib/vendor/zod/v4/classic/in-out.d.cts +8 -0
- package/lib/vendor/zod/v4/classic/in-out.d.ts +8 -0
- package/lib/vendor/zod/v4/classic/in-out.js +36 -0
- package/lib/vendor/zod/v4/classic/index.cjs +52 -0
- package/lib/vendor/zod/v4/classic/index.d.cts +3 -0
- package/lib/vendor/zod/v4/classic/index.d.ts +3 -0
- package/lib/vendor/zod/v4/classic/index.js +4 -0
- package/lib/vendor/zod/v4/classic/iso.cjs +68 -0
- package/lib/vendor/zod/v4/classic/iso.d.cts +7 -0
- package/lib/vendor/zod/v4/classic/iso.d.ts +7 -0
- package/lib/vendor/zod/v4/classic/iso.js +15 -0
- package/lib/vendor/zod/v4/classic/package.json +7 -0
- package/lib/vendor/zod/v4/classic/parse.cjs +63 -0
- package/lib/vendor/zod/v4/classic/parse.d.cts +44 -0
- package/lib/vendor/zod/v4/classic/parse.d.ts +44 -0
- package/lib/vendor/zod/v4/classic/parse.js +16 -0
- package/lib/vendor/zod/v4/classic/schemas.cjs +1676 -0
- package/lib/vendor/zod/v4/classic/schemas.d.cts +816 -0
- package/lib/vendor/zod/v4/classic/schemas.d.ts +816 -0
- package/lib/vendor/zod/v4/classic/schemas.js +1535 -0
- package/lib/vendor/zod/v4/core/api.cjs +1269 -0
- package/lib/vendor/zod/v4/core/api.d.cts +335 -0
- package/lib/vendor/zod/v4/core/api.d.ts +335 -0
- package/lib/vendor/zod/v4/core/api.js +1107 -0
- package/lib/vendor/zod/v4/core/checks.cjs +561 -0
- package/lib/vendor/zod/v4/core/checks.d.cts +294 -0
- package/lib/vendor/zod/v4/core/checks.d.ts +294 -0
- package/lib/vendor/zod/v4/core/checks.js +516 -0
- package/lib/vendor/zod/v4/core/compile.cjs +1908 -0
- package/lib/vendor/zod/v4/core/compile.d.cts +65 -0
- package/lib/vendor/zod/v4/core/compile.d.ts +65 -0
- package/lib/vendor/zod/v4/core/compile.js +1858 -0
- package/lib/vendor/zod/v4/core/core.cjs +167 -0
- package/lib/vendor/zod/v4/core/core.d.cts +82 -0
- package/lib/vendor/zod/v4/core/core.d.ts +82 -0
- package/lib/vendor/zod/v4/core/core.js +141 -0
- package/lib/vendor/zod/v4/core/doc.cjs +61 -0
- package/lib/vendor/zod/v4/core/doc.d.cts +16 -0
- package/lib/vendor/zod/v4/core/doc.d.ts +16 -0
- package/lib/vendor/zod/v4/core/doc.js +38 -0
- package/lib/vendor/zod/v4/core/errors.cjs +317 -0
- package/lib/vendor/zod/v4/core/errors.d.cts +225 -0
- package/lib/vendor/zod/v4/core/errors.d.ts +225 -0
- package/lib/vendor/zod/v4/core/errors.js +267 -0
- package/lib/vendor/zod/v4/core/index.cjs +70 -0
- package/lib/vendor/zod/v4/core/index.d.cts +19 -0
- package/lib/vendor/zod/v4/core/index.d.ts +19 -0
- package/lib/vendor/zod/v4/core/index.js +19 -0
- package/lib/vendor/zod/v4/core/json-schema-generator.cjs +122 -0
- package/lib/vendor/zod/v4/core/json-schema-generator.d.cts +65 -0
- package/lib/vendor/zod/v4/core/json-schema-generator.d.ts +65 -0
- package/lib/vendor/zod/v4/core/json-schema-generator.js +99 -0
- package/lib/vendor/zod/v4/core/json-schema-processors.cjs +929 -0
- package/lib/vendor/zod/v4/core/json-schema-processors.d.cts +65 -0
- package/lib/vendor/zod/v4/core/json-schema-processors.d.ts +65 -0
- package/lib/vendor/zod/v4/core/json-schema-processors.js +843 -0
- package/lib/vendor/zod/v4/core/json-schema.cjs +21 -0
- package/lib/vendor/zod/v4/core/json-schema.d.cts +89 -0
- package/lib/vendor/zod/v4/core/json-schema.d.ts +89 -0
- package/lib/vendor/zod/v4/core/json-schema.js +1 -0
- package/lib/vendor/zod/v4/core/memoizer.cjs +360 -0
- package/lib/vendor/zod/v4/core/memoizer.d.cts +15 -0
- package/lib/vendor/zod/v4/core/memoizer.d.ts +15 -0
- package/lib/vendor/zod/v4/core/memoizer.js +311 -0
- package/lib/vendor/zod/v4/core/package.json +7 -0
- package/lib/vendor/zod/v4/core/parse.cjs +233 -0
- package/lib/vendor/zod/v4/core/parse.d.cts +52 -0
- package/lib/vendor/zod/v4/core/parse.d.ts +52 -0
- package/lib/vendor/zod/v4/core/parse.js +175 -0
- package/lib/vendor/zod/v4/core/regexes.cjs +209 -0
- package/lib/vendor/zod/v4/core/regexes.d.cts +90 -0
- package/lib/vendor/zod/v4/core/regexes.d.ts +90 -0
- package/lib/vendor/zod/v4/core/regexes.js +156 -0
- package/lib/vendor/zod/v4/core/registries.cjs +75 -0
- package/lib/vendor/zod/v4/core/registries.d.cts +35 -0
- package/lib/vendor/zod/v4/core/registries.d.ts +35 -0
- package/lib/vendor/zod/v4/core/registries.js +51 -0
- package/lib/vendor/zod/v4/core/schemas.cjs +2669 -0
- package/lib/vendor/zod/v4/core/schemas.d.cts +1273 -0
- package/lib/vendor/zod/v4/core/schemas.d.ts +1273 -0
- package/lib/vendor/zod/v4/core/schemas.js +2606 -0
- package/lib/vendor/zod/v4/core/standard-schema.cjs +21 -0
- package/lib/vendor/zod/v4/core/standard-schema.d.cts +126 -0
- package/lib/vendor/zod/v4/core/standard-schema.d.ts +126 -0
- package/lib/vendor/zod/v4/core/standard-schema.js +1 -0
- package/lib/vendor/zod/v4/core/to-json-schema.cjs +681 -0
- package/lib/vendor/zod/v4/core/to-json-schema.d.cts +154 -0
- package/lib/vendor/zod/v4/core/to-json-schema.d.ts +154 -0
- package/lib/vendor/zod/v4/core/to-json-schema.js +651 -0
- package/lib/vendor/zod/v4/core/util.cjs +949 -0
- package/lib/vendor/zod/v4/core/util.d.cts +278 -0
- package/lib/vendor/zod/v4/core/util.d.ts +278 -0
- package/lib/vendor/zod/v4/core/util.js +859 -0
- package/lib/vendor/zod/v4/core/versions.cjs +27 -0
- package/lib/vendor/zod/v4/core/versions.d.cts +5 -0
- package/lib/vendor/zod/v4/core/versions.d.ts +5 -0
- package/lib/vendor/zod/v4/core/versions.js +5 -0
- package/lib/vendor/zod/v4/core/visit.cjs +214 -0
- package/lib/vendor/zod/v4/core/visit.d.cts +30 -0
- package/lib/vendor/zod/v4/core/visit.d.ts +30 -0
- package/lib/vendor/zod/v4/core/visit.js +169 -0
- package/lib/vendor/zod/v4/index.cjs +51 -0
- package/lib/vendor/zod/v4/index.d.cts +3 -0
- package/lib/vendor/zod/v4/index.d.ts +3 -0
- package/lib/vendor/zod/v4/index.js +4 -0
- package/lib/vendor/zod/v4/locales/ar.cjs +138 -0
- package/lib/vendor/zod/v4/locales/ar.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ar.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ar.js +111 -0
- package/lib/vendor/zod/v4/locales/az.cjs +137 -0
- package/lib/vendor/zod/v4/locales/az.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/az.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/az.js +110 -0
- package/lib/vendor/zod/v4/locales/be.cjs +195 -0
- package/lib/vendor/zod/v4/locales/be.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/be.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/be.js +168 -0
- package/lib/vendor/zod/v4/locales/bg.cjs +152 -0
- package/lib/vendor/zod/v4/locales/bg.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/bg.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/bg.js +125 -0
- package/lib/vendor/zod/v4/locales/bn.cjs +140 -0
- package/lib/vendor/zod/v4/locales/bn.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/bn.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/bn.js +113 -0
- package/lib/vendor/zod/v4/locales/ca.cjs +139 -0
- package/lib/vendor/zod/v4/locales/ca.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ca.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ca.js +112 -0
- package/lib/vendor/zod/v4/locales/ckb.cjs +160 -0
- package/lib/vendor/zod/v4/locales/ckb.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ckb.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ckb.js +133 -0
- package/lib/vendor/zod/v4/locales/cs.cjs +143 -0
- package/lib/vendor/zod/v4/locales/cs.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/cs.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/cs.js +116 -0
- package/lib/vendor/zod/v4/locales/da.cjs +147 -0
- package/lib/vendor/zod/v4/locales/da.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/da.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/da.js +120 -0
- package/lib/vendor/zod/v4/locales/de.cjs +140 -0
- package/lib/vendor/zod/v4/locales/de.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/de.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/de.js +113 -0
- package/lib/vendor/zod/v4/locales/el.cjs +139 -0
- package/lib/vendor/zod/v4/locales/el.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/el.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/el.js +112 -0
- package/lib/vendor/zod/v4/locales/en.cjs +152 -0
- package/lib/vendor/zod/v4/locales/en.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/en.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/en.js +125 -0
- package/lib/vendor/zod/v4/locales/eo.cjs +141 -0
- package/lib/vendor/zod/v4/locales/eo.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/eo.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/eo.js +114 -0
- package/lib/vendor/zod/v4/locales/es.cjs +163 -0
- package/lib/vendor/zod/v4/locales/es.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/es.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/es.js +136 -0
- package/lib/vendor/zod/v4/locales/fa.cjs +146 -0
- package/lib/vendor/zod/v4/locales/fa.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/fa.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/fa.js +119 -0
- package/lib/vendor/zod/v4/locales/fi.cjs +144 -0
- package/lib/vendor/zod/v4/locales/fi.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/fi.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/fi.js +117 -0
- package/lib/vendor/zod/v4/locales/fr-CA.cjs +139 -0
- package/lib/vendor/zod/v4/locales/fr-CA.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/fr-CA.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/fr-CA.js +112 -0
- package/lib/vendor/zod/v4/locales/fr.cjs +156 -0
- package/lib/vendor/zod/v4/locales/fr.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/fr.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/fr.js +129 -0
- package/lib/vendor/zod/v4/locales/gu.cjs +140 -0
- package/lib/vendor/zod/v4/locales/gu.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/gu.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/gu.js +113 -0
- package/lib/vendor/zod/v4/locales/he.cjs +248 -0
- package/lib/vendor/zod/v4/locales/he.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/he.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/he.js +221 -0
- package/lib/vendor/zod/v4/locales/hi.cjs +138 -0
- package/lib/vendor/zod/v4/locales/hi.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/hi.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/hi.js +111 -0
- package/lib/vendor/zod/v4/locales/hr.cjs +153 -0
- package/lib/vendor/zod/v4/locales/hr.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/hr.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/hr.js +126 -0
- package/lib/vendor/zod/v4/locales/hu.cjs +140 -0
- package/lib/vendor/zod/v4/locales/hu.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/hu.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/hu.js +113 -0
- package/lib/vendor/zod/v4/locales/hy.cjs +185 -0
- package/lib/vendor/zod/v4/locales/hy.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/hy.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/hy.js +158 -0
- package/lib/vendor/zod/v4/locales/id.cjs +138 -0
- package/lib/vendor/zod/v4/locales/id.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/id.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/id.js +111 -0
- package/lib/vendor/zod/v4/locales/index.cjs +152 -0
- package/lib/vendor/zod/v4/locales/index.d.cts +63 -0
- package/lib/vendor/zod/v4/locales/index.d.ts +63 -0
- package/lib/vendor/zod/v4/locales/index.js +63 -0
- package/lib/vendor/zod/v4/locales/is.cjs +141 -0
- package/lib/vendor/zod/v4/locales/is.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/is.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/is.js +114 -0
- package/lib/vendor/zod/v4/locales/it.cjs +140 -0
- package/lib/vendor/zod/v4/locales/it.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/it.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/it.js +113 -0
- package/lib/vendor/zod/v4/locales/ja.cjs +139 -0
- package/lib/vendor/zod/v4/locales/ja.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ja.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ja.js +112 -0
- package/lib/vendor/zod/v4/locales/ka.cjs +144 -0
- package/lib/vendor/zod/v4/locales/ka.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ka.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ka.js +117 -0
- package/lib/vendor/zod/v4/locales/kh.cjs +12 -0
- package/lib/vendor/zod/v4/locales/kh.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/kh.d.ts +5 -0
- package/lib/vendor/zod/v4/locales/kh.js +5 -0
- package/lib/vendor/zod/v4/locales/km.cjs +142 -0
- package/lib/vendor/zod/v4/locales/km.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/km.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/km.js +115 -0
- package/lib/vendor/zod/v4/locales/kn.cjs +143 -0
- package/lib/vendor/zod/v4/locales/kn.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/kn.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/kn.js +116 -0
- package/lib/vendor/zod/v4/locales/ko.cjs +143 -0
- package/lib/vendor/zod/v4/locales/ko.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ko.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ko.js +116 -0
- package/lib/vendor/zod/v4/locales/lt.cjs +234 -0
- package/lib/vendor/zod/v4/locales/lt.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/lt.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/lt.js +207 -0
- package/lib/vendor/zod/v4/locales/mk.cjs +141 -0
- package/lib/vendor/zod/v4/locales/mk.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/mk.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/mk.js +114 -0
- package/lib/vendor/zod/v4/locales/ms.cjs +139 -0
- package/lib/vendor/zod/v4/locales/ms.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ms.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ms.js +112 -0
- package/lib/vendor/zod/v4/locales/ne.cjs +138 -0
- package/lib/vendor/zod/v4/locales/ne.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ne.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ne.js +111 -0
- package/lib/vendor/zod/v4/locales/nl.cjs +142 -0
- package/lib/vendor/zod/v4/locales/nl.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/nl.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/nl.js +115 -0
- package/lib/vendor/zod/v4/locales/nn.cjs +140 -0
- package/lib/vendor/zod/v4/locales/nn.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/nn.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/nn.js +113 -0
- package/lib/vendor/zod/v4/locales/no.cjs +140 -0
- package/lib/vendor/zod/v4/locales/no.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/no.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/no.js +113 -0
- package/lib/vendor/zod/v4/locales/ota.cjs +141 -0
- package/lib/vendor/zod/v4/locales/ota.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ota.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ota.js +114 -0
- package/lib/vendor/zod/v4/locales/package.json +7 -0
- package/lib/vendor/zod/v4/locales/pl.cjs +141 -0
- package/lib/vendor/zod/v4/locales/pl.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/pl.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/pl.js +114 -0
- package/lib/vendor/zod/v4/locales/ps.cjs +146 -0
- package/lib/vendor/zod/v4/locales/ps.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ps.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ps.js +119 -0
- package/lib/vendor/zod/v4/locales/pt-BR.cjs +170 -0
- package/lib/vendor/zod/v4/locales/pt-BR.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/pt-BR.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/pt-BR.js +143 -0
- package/lib/vendor/zod/v4/locales/pt.cjs +169 -0
- package/lib/vendor/zod/v4/locales/pt.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/pt.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/pt.js +142 -0
- package/lib/vendor/zod/v4/locales/ro.cjs +149 -0
- package/lib/vendor/zod/v4/locales/ro.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ro.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ro.js +122 -0
- package/lib/vendor/zod/v4/locales/ru.cjs +195 -0
- package/lib/vendor/zod/v4/locales/ru.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ru.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ru.js +168 -0
- package/lib/vendor/zod/v4/locales/sk.cjs +143 -0
- package/lib/vendor/zod/v4/locales/sk.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/sk.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/sk.js +116 -0
- package/lib/vendor/zod/v4/locales/sl.cjs +141 -0
- package/lib/vendor/zod/v4/locales/sl.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/sl.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/sl.js +114 -0
- package/lib/vendor/zod/v4/locales/sv.cjs +142 -0
- package/lib/vendor/zod/v4/locales/sv.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/sv.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/sv.js +115 -0
- package/lib/vendor/zod/v4/locales/ta.cjs +142 -0
- package/lib/vendor/zod/v4/locales/ta.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ta.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ta.js +115 -0
- package/lib/vendor/zod/v4/locales/tg.cjs +144 -0
- package/lib/vendor/zod/v4/locales/tg.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/tg.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/tg.js +117 -0
- package/lib/vendor/zod/v4/locales/th.cjs +142 -0
- package/lib/vendor/zod/v4/locales/th.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/th.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/th.js +115 -0
- package/lib/vendor/zod/v4/locales/tk.cjs +134 -0
- package/lib/vendor/zod/v4/locales/tk.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/tk.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/tk.js +107 -0
- package/lib/vendor/zod/v4/locales/tr.cjs +137 -0
- package/lib/vendor/zod/v4/locales/tr.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/tr.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/tr.js +110 -0
- package/lib/vendor/zod/v4/locales/ua.cjs +12 -0
- package/lib/vendor/zod/v4/locales/ua.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ua.d.ts +5 -0
- package/lib/vendor/zod/v4/locales/ua.js +5 -0
- package/lib/vendor/zod/v4/locales/uk.cjs +140 -0
- package/lib/vendor/zod/v4/locales/uk.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/uk.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/uk.js +113 -0
- package/lib/vendor/zod/v4/locales/ur.cjs +142 -0
- package/lib/vendor/zod/v4/locales/ur.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/ur.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/ur.js +115 -0
- package/lib/vendor/zod/v4/locales/uz.cjs +140 -0
- package/lib/vendor/zod/v4/locales/uz.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/uz.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/uz.js +113 -0
- package/lib/vendor/zod/v4/locales/vi.cjs +140 -0
- package/lib/vendor/zod/v4/locales/vi.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/vi.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/vi.js +113 -0
- package/lib/vendor/zod/v4/locales/yo.cjs +139 -0
- package/lib/vendor/zod/v4/locales/yo.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/yo.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/yo.js +112 -0
- package/lib/vendor/zod/v4/locales/zh-CN.cjs +141 -0
- package/lib/vendor/zod/v4/locales/zh-CN.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/zh-CN.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/zh-CN.js +114 -0
- package/lib/vendor/zod/v4/locales/zh-TW.cjs +139 -0
- package/lib/vendor/zod/v4/locales/zh-TW.d.cts +5 -0
- package/lib/vendor/zod/v4/locales/zh-TW.d.ts +4 -0
- package/lib/vendor/zod/v4/locales/zh-TW.js +112 -0
- package/lib/vendor/zod/v4/mini/checks.cjs +54 -0
- package/lib/vendor/zod/v4/mini/checks.d.cts +1 -0
- package/lib/vendor/zod/v4/mini/checks.d.ts +1 -0
- package/lib/vendor/zod/v4/mini/checks.js +1 -0
- package/lib/vendor/zod/v4/mini/coerce.cjs +71 -0
- package/lib/vendor/zod/v4/mini/coerce.d.cts +7 -0
- package/lib/vendor/zod/v4/mini/coerce.d.ts +7 -0
- package/lib/vendor/zod/v4/mini/coerce.js +22 -0
- package/lib/vendor/zod/v4/mini/deep-partial.cjs +58 -0
- package/lib/vendor/zod/v4/mini/deep-partial.d.cts +14 -0
- package/lib/vendor/zod/v4/mini/deep-partial.d.ts +14 -0
- package/lib/vendor/zod/v4/mini/deep-partial.js +13 -0
- package/lib/vendor/zod/v4/mini/external.cjs +95 -0
- package/lib/vendor/zod/v4/mini/external.d.cts +16 -0
- package/lib/vendor/zod/v4/mini/external.d.ts +16 -0
- package/lib/vendor/zod/v4/mini/external.js +16 -0
- package/lib/vendor/zod/v4/mini/in-out.cjs +82 -0
- package/lib/vendor/zod/v4/mini/in-out.d.cts +8 -0
- package/lib/vendor/zod/v4/mini/in-out.d.ts +8 -0
- package/lib/vendor/zod/v4/mini/in-out.js +36 -0
- package/lib/vendor/zod/v4/mini/index.cjs +51 -0
- package/lib/vendor/zod/v4/mini/index.d.cts +3 -0
- package/lib/vendor/zod/v4/mini/index.d.ts +3 -0
- package/lib/vendor/zod/v4/mini/index.js +3 -0
- package/lib/vendor/zod/v4/mini/iso.cjs +83 -0
- package/lib/vendor/zod/v4/mini/iso.d.cts +22 -0
- package/lib/vendor/zod/v4/mini/iso.d.ts +22 -0
- package/lib/vendor/zod/v4/mini/iso.js +34 -0
- package/lib/vendor/zod/v4/mini/package.json +7 -0
- package/lib/vendor/zod/v4/mini/parse.cjs +37 -0
- package/lib/vendor/zod/v4/mini/parse.d.cts +1 -0
- package/lib/vendor/zod/v4/mini/parse.d.ts +1 -0
- package/lib/vendor/zod/v4/mini/parse.js +1 -0
- package/lib/vendor/zod/v4/mini/schemas.cjs +1147 -0
- package/lib/vendor/zod/v4/mini/schemas.d.cts +480 -0
- package/lib/vendor/zod/v4/mini/schemas.d.ts +480 -0
- package/lib/vendor/zod/v4/mini/schemas.js +1002 -0
- package/lib/vendor/zod/v4/package.json +7 -0
- package/lib/vendor/zod/v4-mini/index.cjs +51 -0
- package/lib/vendor/zod/v4-mini/index.d.cts +3 -0
- package/lib/vendor/zod/v4-mini/index.d.ts +3 -0
- package/lib/vendor/zod/v4-mini/index.js +3 -0
- package/lib/vendor/zod/v4-mini/package.json +7 -0
- package/package.json +84 -72
- package/tests/_host-lib.js +50 -0
- package/tests/fixtures/holiday-notice-2023.txt +8 -0
- package/tests/fixtures/holiday-notice-2024.txt +9 -0
- package/tests/fixtures/holiday-notice-2025.txt +8 -0
- package/tests/fixtures/holiday-notice-2026.txt +9 -0
- package/tests/helpers/client-harness.js +86 -0
- package/tests/package.json +3 -0
- package/tests/verify-activemodel.js +173 -0
- package/tests/verify-balance-api.js +368 -0
- package/tests/verify-balance-vendors.js +422 -0
- package/tests/verify-balance.js +1041 -0
- package/tests/verify-billing-stall.js +404 -0
- package/tests/verify-client-hygiene.js +425 -0
- package/tests/verify-client-price.mjs +133 -0
- package/tests/verify-clock.js +246 -0
- package/tests/verify-compaction-usage.js +342 -0
- package/tests/verify-context.js +179 -0
- package/tests/verify-copy.js +317 -0
- package/tests/verify-cost-overflow.js +150 -0
- package/tests/verify-deadcode.js +171 -0
- package/tests/verify-dev-fixtures.js +850 -0
- package/tests/verify-dev-mode.js +659 -0
- package/tests/verify-drag-card.js +176 -0
- package/tests/verify-fixes.js +520 -0
- package/tests/verify-generic-relay.js +487 -0
- package/tests/verify-holiday-persist.js +180 -0
- package/tests/verify-holiday-route.js +65 -0
- package/tests/verify-holiday-update.js +226 -0
- package/tests/verify-holiday.js +118 -0
- package/tests/verify-holidays.js +91 -0
- package/tests/verify-host-guards.mjs +97 -0
- package/tests/verify-host.js +461 -0
- package/tests/verify-hover.js +619 -0
- package/tests/verify-ledger-keep.js +1015 -0
- package/tests/verify-ledger-prices.js +238 -0
- package/tests/verify-list-layout.js +610 -0
- package/tests/verify-magpie-quota.mjs +582 -0
- package/tests/verify-migration.js +179 -0
- package/tests/verify-model-match.js +306 -0
- package/tests/verify-modelrow-scroll.js +669 -0
- package/tests/verify-navicon.js +348 -0
- package/tests/verify-price-filled.js +831 -0
- package/tests/verify-price-parity.js +392 -0
- package/tests/verify-prices.js +258 -0
- package/tests/verify-pricing.js +161 -0
- package/tests/verify-progress-events.js +260 -0
- package/tests/verify-provider-fees.js +919 -0
- package/tests/verify-relay-settings.js +2447 -0
- package/tests/verify-release-age.js +394 -0
- package/tests/verify-release.js +200 -0
- package/tests/verify-render.js +557 -0
- package/tests/verify-reprice.js +127 -0
- package/tests/verify-routes.js +215 -0
- package/tests/verify-self-update-status.js +155 -0
- package/tests/verify-self-update.js +467 -0
- package/tests/verify-speed.js +61 -0
- package/tests/verify-star-tip.js +156 -0
- package/tests/verify-subagent-total.js +1354 -0
- package/tests/verify-timing.js +671 -0
- package/tests/verify-tips.js +1046 -0
- package/tests/verify-tokens.js +230 -0
- package/tests/verify-update-duration.js +135 -0
- package/tests/verify-update-retry.js +375 -0
- package/tests/verify-version.js +127 -0
- package/tests/verify-weekend.js +104 -0
- package/tests/verify.js +3510 -0
- package/tools/shot.cjs +12 -10
- package/tools/sync-from-plugin.cjs +63 -22
- package/tools/sync-to-plugin.cjs +38 -16
- package/tools/test.cjs +53 -17
- package/docs/statusbar.en.png +0 -0
- package/docs/statusbar.png +0 -0
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Provider fee regression: drive the real Host projection and HTTP routes with
|
|
3
|
+
* an isolated DSH_HOME and compressed session logs.
|
|
4
|
+
* Run: node tests/verify-provider-fees.js
|
|
5
|
+
*/
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const { pathToFileURL } = require('node:url');
|
|
11
|
+
const zlib = require('node:zlib');
|
|
12
|
+
|
|
13
|
+
const ROOT = path.join(__dirname, '..');
|
|
14
|
+
const INDEX = path.join(ROOT, 'lib', 'index.js');
|
|
15
|
+
const HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-provider-fees-'));
|
|
16
|
+
const STATUS = path.join(HOME, 'dsh-status-bar');
|
|
17
|
+
const SESSIONS = path.join(HOME, 'sessions');
|
|
18
|
+
const PROFILE_DIR = path.join(HOME, 'profiles', 'desktop');
|
|
19
|
+
const LEDGER_FILE = path.join(STATUS, 'usage-ledger.json');
|
|
20
|
+
const API = '/dsh-desktop-statusbar/api';
|
|
21
|
+
const PROVIDER_A = 'fee-provider-a';
|
|
22
|
+
const PROVIDER_B = 'fee-provider-b';
|
|
23
|
+
const M = 1000000;
|
|
24
|
+
const BEIJING_OFFSET = 8 * 3600 * 1000;
|
|
25
|
+
|
|
26
|
+
/* Use yesterday at 20:00 Beijing time: always off-peak and inside the ledger window. */
|
|
27
|
+
const bjNow = new Date(Date.now() + BEIJING_OFFSET);
|
|
28
|
+
const OFF_PEAK_AT = Date.UTC(
|
|
29
|
+
bjNow.getUTCFullYear(), bjNow.getUTCMonth(), bjNow.getUTCDate() - 1, 12, 0, 0
|
|
30
|
+
);
|
|
31
|
+
/* 2025-01-06 was a Monday outside the built-in 2026 holiday calendar. */
|
|
32
|
+
const PEAK_AT = Date.UTC(2025, 0, 6, 2, 0, 0);
|
|
33
|
+
const DAY = (() => {
|
|
34
|
+
const at = new Date(OFF_PEAK_AT);
|
|
35
|
+
return at.getFullYear() + '-' + String(at.getMonth() + 1).padStart(2, '0')
|
|
36
|
+
+ '-' + String(at.getDate()).padStart(2, '0');
|
|
37
|
+
})();
|
|
38
|
+
|
|
39
|
+
process.env.DSH_HOME = HOME;
|
|
40
|
+
globalThis.setInterval = () => 0;
|
|
41
|
+
|
|
42
|
+
function writeSession(id, parentSession, events) {
|
|
43
|
+
const dir = path.join(SESSIONS, id);
|
|
44
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
45
|
+
const header = { type: 'session', id, parentSession };
|
|
46
|
+
const lines = [header].concat(events).map((event) => JSON.stringify(event));
|
|
47
|
+
fs.writeFileSync(path.join(dir, 'usage.jsonl.zstd'), zlib.zstdCompressSync(Buffer.from(lines.join('\n') + '\n')));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function assistantMessage(seq, time, provider, model, inputTokens, turn = 1, step = seq) {
|
|
51
|
+
const source = { kind: 'model', model };
|
|
52
|
+
if (provider !== undefined) source.provider = provider;
|
|
53
|
+
return {
|
|
54
|
+
type: 'assistant/message',
|
|
55
|
+
seq,
|
|
56
|
+
time,
|
|
57
|
+
data: { turn, step, message: { source }, usage: { inputTokens } },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function zeroTier() {
|
|
62
|
+
return { input: 0, cacheRead: 0, cacheWrite: 0, output: 0 };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function tierPrice(input, output = 0) {
|
|
66
|
+
const tier = { input, cacheRead: 0, cacheWrite: 0, output };
|
|
67
|
+
return { tiered: false, currency: 'CNY', feeConfigured: true, feeMultiplier: 1, peak: { ...tier }, offPeak: { ...tier } };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* 把价格库压成台账 `priceFingerprint` 的 fp4 格式,用于模拟"重启后客户端还没上报价格库"。 */
|
|
71
|
+
function bookFingerprint(book) {
|
|
72
|
+
const names = Object.keys(book).sort();
|
|
73
|
+
const rows = [];
|
|
74
|
+
const tierOf = (t) => (t === null || t === undefined
|
|
75
|
+
? null : [t.input, t.cacheRead, t.cacheWrite, t.output]);
|
|
76
|
+
for (const name of names) {
|
|
77
|
+
const one = book[name];
|
|
78
|
+
const peak = tierOf(one.peak);
|
|
79
|
+
const offPeak = tierOf(one.offPeak);
|
|
80
|
+
if (peak === null && offPeak === null) continue;
|
|
81
|
+
rows.push([
|
|
82
|
+
name, peak !== null ? peak : offPeak, offPeak !== null ? offPeak : peak,
|
|
83
|
+
one.tiered === false ? 0 : 1, one.currency === 'USD' ? 'USD' : 'CNY',
|
|
84
|
+
typeof one.feeMultiplier === 'number' ? one.feeMultiplier : null,
|
|
85
|
+
one.feeConfigured === true ? 1 : 0,
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
return 'fp4:' + JSON.stringify(rows);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* USD 价格条目:USD 历史重算用例用。fee === undefined 表示"没配置倍率"(应转欠账)。 */
|
|
92
|
+
function usdTierPrice(input, output = 0, fee) {
|
|
93
|
+
const tier = { input, cacheRead: 0, cacheWrite: 0, output };
|
|
94
|
+
const entry = { tiered: false, currency: 'USD', peak: { ...tier }, offPeak: { ...tier } };
|
|
95
|
+
if (fee !== undefined) {
|
|
96
|
+
entry.feeConfigured = true;
|
|
97
|
+
entry.feeMultiplier = fee;
|
|
98
|
+
}
|
|
99
|
+
return entry;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* 普通 CNY 价格条目:不带 feeMultiplier / feeConfigured。用于「relay 缺倍率」与「Magpie 默认模型价」。 */
|
|
103
|
+
function plainTierPrice(input, output = 0) {
|
|
104
|
+
const tier = { input, cacheRead: 0, cacheWrite: 0, output };
|
|
105
|
+
return { tiered: false, currency: 'CNY', peak: { ...tier }, offPeak: { ...tier } };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function hit(handler, pathname, options = {}) {
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const listeners = {};
|
|
111
|
+
const req = {
|
|
112
|
+
url: pathname,
|
|
113
|
+
method: options.method || 'GET',
|
|
114
|
+
/* relay 配置 GET 会校验 Host 与 TCP 对端:假 req 补本机 Host / 回环 socket。 */
|
|
115
|
+
headers: { host: '127.0.0.1:19387' },
|
|
116
|
+
socket: { remoteAddress: '127.0.0.1' },
|
|
117
|
+
on(name, fn) {
|
|
118
|
+
listeners[name] = (listeners[name] || []).concat(fn);
|
|
119
|
+
return req;
|
|
120
|
+
},
|
|
121
|
+
destroy() {},
|
|
122
|
+
};
|
|
123
|
+
let status = null;
|
|
124
|
+
let text = null;
|
|
125
|
+
const res = {
|
|
126
|
+
writeHead(code) { status = code; },
|
|
127
|
+
end(body) { text = body; },
|
|
128
|
+
};
|
|
129
|
+
Promise.resolve(handler(req, res)).then(() => {
|
|
130
|
+
resolve({ status, body: text === null ? null : JSON.parse(text) });
|
|
131
|
+
}, reject);
|
|
132
|
+
if (options.body !== undefined) {
|
|
133
|
+
for (const fn of listeners.data || []) fn(options.body);
|
|
134
|
+
}
|
|
135
|
+
for (const fn of listeners.end || []) fn();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function addUsage(projection, state, event) {
|
|
140
|
+
const next = projection.apply(state, event);
|
|
141
|
+
projection.stateSchema.parse(next);
|
|
142
|
+
return next;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function main() {
|
|
146
|
+
fs.mkdirSync(STATUS, { recursive: true });
|
|
147
|
+
fs.mkdirSync(SESSIONS, { recursive: true });
|
|
148
|
+
fs.mkdirSync(PROFILE_DIR, { recursive: true });
|
|
149
|
+
fs.writeFileSync(path.join(PROFILE_DIR, 'cordis.patch.yml'), [
|
|
150
|
+
'- id: llm-pi-ai # provider-fees fixture',
|
|
151
|
+
' name: "@deepseek-ai/dsh-llm-pi-ai"',
|
|
152
|
+
' config:',
|
|
153
|
+
' providers:',
|
|
154
|
+
' fee-provider-a:',
|
|
155
|
+
' baseURL: https://relay-a.invalid/v1',
|
|
156
|
+
' fee-provider-b:',
|
|
157
|
+
' baseURL: https://relay-b.invalid/v1',
|
|
158
|
+
' plain-provider:',
|
|
159
|
+
' baseURL: http://127.0.0.1:19999/v1',
|
|
160
|
+
' official-api:',
|
|
161
|
+
' baseURL: https://api.deepseek.com/v1',
|
|
162
|
+
' workbuddy-points:',
|
|
163
|
+
' baseURL: https://relay-points.invalid/v1',
|
|
164
|
+
' qoder-points:',
|
|
165
|
+
' baseURL: https://api.qoder.invalid/v1',
|
|
166
|
+
].join('\n'));
|
|
167
|
+
const nineAm = new Date();
|
|
168
|
+
nineAm.setHours(9, 0, 0, 0);
|
|
169
|
+
fs.writeFileSync(path.join(STATUS, 'exchange-rate.json'), JSON.stringify({
|
|
170
|
+
rate: 6.7,
|
|
171
|
+
fetchedAt: Math.max(Date.now(), nineAm.getTime() + 1000),
|
|
172
|
+
source: 'provider-fees-test',
|
|
173
|
+
}));
|
|
174
|
+
|
|
175
|
+
const mod = await import(pathToFileURL(INDEX).href);
|
|
176
|
+
const projections = [];
|
|
177
|
+
let handler = null;
|
|
178
|
+
const secrets = new Map();
|
|
179
|
+
const credentials = {
|
|
180
|
+
resolve: async (ref) => secrets.has(ref) ? { value: secrets.get(ref), source: 'test' } : null,
|
|
181
|
+
set: async (ref, value) => { secrets.set(ref, value); },
|
|
182
|
+
unset: async (ref) => { secrets.delete(ref); },
|
|
183
|
+
};
|
|
184
|
+
const realFetchBeforeApply = globalThis.fetch;
|
|
185
|
+
globalThis.fetch = async () => new Response(null, { status: 503 });
|
|
186
|
+
try {
|
|
187
|
+
mod.apply({
|
|
188
|
+
logger: { info() {} },
|
|
189
|
+
effect: (fn) => fn(),
|
|
190
|
+
sessionProjections: { register: (projection) => { projections.push(projection); return () => {}; } },
|
|
191
|
+
webServer: { register: (route) => {
|
|
192
|
+
if (route.path === API) handler = route.handler;
|
|
193
|
+
return () => {};
|
|
194
|
+
} },
|
|
195
|
+
credentials,
|
|
196
|
+
get: (name) => name === 'credentials' ? credentials : undefined,
|
|
197
|
+
});
|
|
198
|
+
} finally {
|
|
199
|
+
globalThis.fetch = realFetchBeforeApply;
|
|
200
|
+
}
|
|
201
|
+
assert.equal(typeof handler, 'function', 'Host API route captured through mod.apply');
|
|
202
|
+
const usageProjection = projections.find((projection) => projection.key === 'desktopStatusbarUsage');
|
|
203
|
+
assert.ok(usageProjection, 'sessionUsage projection captured through mod.apply');
|
|
204
|
+
|
|
205
|
+
const post = (pathname, body) => hit(handler, pathname, { method: 'POST', body: JSON.stringify(body) });
|
|
206
|
+
const postRelay = async (channelKey, endpoint, feeMultiplier) => {
|
|
207
|
+
const result = await post(API + '/relay-balance-config', {
|
|
208
|
+
channelKey,
|
|
209
|
+
endpoint,
|
|
210
|
+
currency: 'USD',
|
|
211
|
+
balancePath: '$.data.balance',
|
|
212
|
+
feeMultiplier,
|
|
213
|
+
token: 'fixture-token-not-a-secret',
|
|
214
|
+
userId: 'fixture-user',
|
|
215
|
+
});
|
|
216
|
+
assert.equal(result.status, 200, 'relay config write succeeded for ' + channelKey + ': ' + JSON.stringify(result.body));
|
|
217
|
+
return result.body;
|
|
218
|
+
};
|
|
219
|
+
const postMagpie = async (feeMultiplier) => {
|
|
220
|
+
const result = await post(API + '/relay-balance-config', { channelKey: 'Magpie', feeMultiplier });
|
|
221
|
+
assert.equal(result.status, 200, 'Magpie multiplier config write succeeded');
|
|
222
|
+
return result.body;
|
|
223
|
+
};
|
|
224
|
+
const removeMagpie = async () => {
|
|
225
|
+
const result = await post(API + '/relay-balance-config', { channelKey: 'Magpie', remove: true });
|
|
226
|
+
assert.equal(result.status, 200, 'Magpie channel removal succeeded: ' + JSON.stringify(result.body));
|
|
227
|
+
return result.body;
|
|
228
|
+
};
|
|
229
|
+
const postPrices = (models) => post(API + '/prices', { models });
|
|
230
|
+
const daily = () => hit(handler, API + '/daily-usage?force=1');
|
|
231
|
+
const initialLedger = await daily();
|
|
232
|
+
assert.equal(initialLedger.status, 200, 'startup ledger queue settled through the real route');
|
|
233
|
+
|
|
234
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 2);
|
|
235
|
+
await postRelay(PROVIDER_B, 'https://relay-b.invalid/balance', 4);
|
|
236
|
+
await postMagpie(1.5);
|
|
237
|
+
|
|
238
|
+
/* Projection dataflow: message provider, routed attempt provider, summary provider,
|
|
239
|
+
missing-provider default, and a config change between calls. */
|
|
240
|
+
assert.ok(usageProjection.stateVersion > 8, 'usage projection version bumped to replay old states');
|
|
241
|
+
let state = usageProjection.init();
|
|
242
|
+
state = addUsage(usageProjection, state, assistantMessage(1, OFF_PEAK_AT, PROVIDER_A, 'shared-model', 10));
|
|
243
|
+
state = addUsage(usageProjection, state, assistantMessage(2, OFF_PEAK_AT, PROVIDER_B, 'shared-model', 20));
|
|
244
|
+
state = addUsage(usageProjection, state, {
|
|
245
|
+
type: 'model/selection', seq: 3, time: OFF_PEAK_AT + 10,
|
|
246
|
+
data: { provider: PROVIDER_B, model: 'attempt-model' },
|
|
247
|
+
});
|
|
248
|
+
state = addUsage(usageProjection, state, {
|
|
249
|
+
type: 'assistant/attempt', seq: 4, time: OFF_PEAK_AT + 20,
|
|
250
|
+
data: { turn: 1, step: 4, stream: [{ type: 'usage', usage: { inputTokens: 30 } }] },
|
|
251
|
+
});
|
|
252
|
+
state = addUsage(usageProjection, state, {
|
|
253
|
+
type: 'compaction/summary', seq: 5, time: OFF_PEAK_AT + 30,
|
|
254
|
+
data: { model: 'summary-model', provider: PROVIDER_A, usage: { inputTokens: 40 } },
|
|
255
|
+
});
|
|
256
|
+
state = addUsage(usageProjection, state, assistantMessage(6, OFF_PEAK_AT + 40, undefined, 'shared-model', 50));
|
|
257
|
+
state = addUsage(usageProjection, state, {
|
|
258
|
+
type: 'compaction/summary', seq: 7, time: OFF_PEAK_AT + 50,
|
|
259
|
+
data: { model: 'summary-no-provider', usage: { inputTokens: 60 } },
|
|
260
|
+
});
|
|
261
|
+
const changed = await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 5);
|
|
262
|
+
assert.equal(changed.ok, true, 'relay multiplier can change through real route');
|
|
263
|
+
state = addUsage(usageProjection, state, assistantMessage(8, OFF_PEAK_AT + 60, PROVIDER_A, 'shared-model', 70));
|
|
264
|
+
|
|
265
|
+
assert.equal(state.calls.length, 7, 'all usage events with a model were projected');
|
|
266
|
+
/* v10 合同:session calls 只持久 provider,倍率由客户端按当前非密配置动态算。
|
|
267
|
+
这里同时反证 calls 上没有 feeMultiplier 快照字段(否则会重新引入事件时刻语义)。 */
|
|
268
|
+
assert.deepEqual(state.calls.map((call) => call.provider), [
|
|
269
|
+
PROVIDER_A, PROVIDER_B, PROVIDER_B, PROVIDER_A, '', '', PROVIDER_A,
|
|
270
|
+
], 'provider 只取事件来源,不按 model 或旧 route 推断');
|
|
271
|
+
assert.deepEqual(state.calls.map((call) => call.feeMultiplier === undefined), [
|
|
272
|
+
true, true, true, true, true, true, true,
|
|
273
|
+
], 'session call 不保存事件时刻的 feeMultiplier 快照');
|
|
274
|
+
assert.equal(state.calls[2].model, 'attempt-model', 'assistant/attempt uses its preceding route model');
|
|
275
|
+
assert.equal(state.calls[4].model, 'shared-model', 'same model is retained separately across providers');
|
|
276
|
+
assert.equal(state.calls[5].model, 'summary-no-provider', 'summary model comes from data.model');
|
|
277
|
+
assert.equal(state.overflowByProvider, undefined, 'provider-aware overflow 已删除(客户端零引用)');
|
|
278
|
+
|
|
279
|
+
let noRoute = usageProjection.init();
|
|
280
|
+
noRoute = addUsage(usageProjection, noRoute, {
|
|
281
|
+
type: 'assistant/attempt', seq: 9, time: OFF_PEAK_AT,
|
|
282
|
+
data: { turn: 1, step: 1, stream: [{ type: 'usage', usage: { inputTokens: 100 } }] },
|
|
283
|
+
});
|
|
284
|
+
assert.equal(noRoute.calls.length, 0, 'attempt without same-route model is not model-inferred');
|
|
285
|
+
|
|
286
|
+
/* Overflow must retain three independent provider/model/multiplier/tier bins. */
|
|
287
|
+
let overflowState = usageProjection.init();
|
|
288
|
+
let seq = 1;
|
|
289
|
+
const overflowCall = (provider, time, step) => ({
|
|
290
|
+
type: 'assistant/message', seq: seq++, time,
|
|
291
|
+
data: {
|
|
292
|
+
turn: 2, step,
|
|
293
|
+
message: { source: { kind: 'model', provider, model: 'overflow-model' } },
|
|
294
|
+
usage: { inputTokens: 1 },
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
overflowState = addUsage(usageProjection, overflowState, overflowCall(PROVIDER_A, OFF_PEAK_AT, 1));
|
|
298
|
+
overflowState = addUsage(usageProjection, overflowState, overflowCall(PROVIDER_A, PEAK_AT, 2));
|
|
299
|
+
await postRelay(PROVIDER_B, 'https://relay-b.invalid/balance', 2);
|
|
300
|
+
overflowState = addUsage(usageProjection, overflowState, overflowCall(PROVIDER_B, OFF_PEAK_AT, 3));
|
|
301
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 7);
|
|
302
|
+
overflowState = addUsage(usageProjection, overflowState, overflowCall(PROVIDER_A, OFF_PEAK_AT, 4));
|
|
303
|
+
for (let i = 5; i <= 4004; i += 1) {
|
|
304
|
+
overflowState = addUsage(usageProjection, overflowState, overflowCall('overflow-filler', OFF_PEAK_AT, i));
|
|
305
|
+
}
|
|
306
|
+
assert.equal(overflowState.calls.length, 4000, 'MAX_CALLS tail is retained');
|
|
307
|
+
/* 旧 model-keyed overflow 是客户端真正读取的那份:4 条被挤掉(同属 overflow-model),
|
|
308
|
+
peak 1 条、offPeak 3 条(A/B 两个 provider 按模型合并)。 */
|
|
309
|
+
assert.deepEqual(
|
|
310
|
+
[overflowState.overflow['overflow-model'].peak.input, overflowState.overflow['overflow-model'].offPeak.input],
|
|
311
|
+
[1, 3],
|
|
312
|
+
'overflow 按模型合并两档(同模型不同 provider 合并,客户端只读这一份)'
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
/* Ledger route: two providers, same model, hand-computable prices. */
|
|
316
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 2);
|
|
317
|
+
await postRelay(PROVIDER_B, 'https://relay-b.invalid/balance', 3);
|
|
318
|
+
let priceBook = {
|
|
319
|
+
'fee-model': tierPrice(1),
|
|
320
|
+
'sub-model': tierPrice(2),
|
|
321
|
+
};
|
|
322
|
+
let posted = await postPrices(priceBook);
|
|
323
|
+
assert.equal(posted.status, 200, 'initial prices accepted');
|
|
324
|
+
writeSession('ledger-session', null, [
|
|
325
|
+
assistantMessage(1, OFF_PEAK_AT, PROVIDER_A, 'fee-model', M),
|
|
326
|
+
assistantMessage(2, OFF_PEAK_AT, PROVIDER_B, 'fee-model', M),
|
|
327
|
+
]);
|
|
328
|
+
let report = await daily();
|
|
329
|
+
assert.equal(report.status, 200, 'daily usage route returned HTTP 200');
|
|
330
|
+
let day = report.body.days.find((entry) => entry.date === DAY);
|
|
331
|
+
assert.ok(day, 'daily usage includes test date ' + DAY);
|
|
332
|
+
assert.equal(day.cost, 5, 'same model: 1 * multiplier 2 + 1 * multiplier 3 = 5');
|
|
333
|
+
assert.equal(day.costByCurrency.CNY, 5, 'costByCurrency also reflects provider multipliers');
|
|
334
|
+
|
|
335
|
+
/* A multiplier-only change does not rewrite already settled ledger history. */
|
|
336
|
+
let disk = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
337
|
+
disk.days[DAY].legacyCost = 77;
|
|
338
|
+
fs.writeFileSync(LEDGER_FILE, JSON.stringify(disk));
|
|
339
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 5);
|
|
340
|
+
report = await daily();
|
|
341
|
+
day = report.body.days.find((entry) => entry.date === DAY);
|
|
342
|
+
assert.equal(day.cost, 5, 'changing provider multiplier does not reprice historical cost');
|
|
343
|
+
assert.equal(day.costByCurrency.CNY, 5, 'historical costByCurrency is unchanged');
|
|
344
|
+
assert.equal(JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')).days[DAY].legacyCost, 77,
|
|
345
|
+
'legacyCost snapshot survives multiplier-only change');
|
|
346
|
+
|
|
347
|
+
/* Same-model debt separates provider and multiplier; another model separates the model key. */
|
|
348
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 7);
|
|
349
|
+
const ledgerEvents = [
|
|
350
|
+
assistantMessage(1, OFF_PEAK_AT, PROVIDER_A, 'fee-model', M),
|
|
351
|
+
assistantMessage(2, OFF_PEAK_AT, PROVIDER_B, 'fee-model', M),
|
|
352
|
+
assistantMessage(3, OFF_PEAK_AT, PROVIDER_A, 'fee-model', M),
|
|
353
|
+
];
|
|
354
|
+
writeSession('ledger-session', null, ledgerEvents);
|
|
355
|
+
report = await daily();
|
|
356
|
+
day = report.body.days.find((entry) => entry.date === DAY);
|
|
357
|
+
assert.equal(day.cost, 12, 'new priced provider-A call adds 7; prior 5 remains');
|
|
358
|
+
const recordDebt = async (seq, provider, model) => {
|
|
359
|
+
ledgerEvents.push(assistantMessage(seq, OFF_PEAK_AT, provider, model, M));
|
|
360
|
+
writeSession('ledger-session', null, ledgerEvents);
|
|
361
|
+
const next = await daily();
|
|
362
|
+
const nextDay = next.body.days.find((entry) => entry.date === DAY);
|
|
363
|
+
assert.equal(nextDay.cost, 12, 'unpriced usage does not alter settled cost');
|
|
364
|
+
};
|
|
365
|
+
await recordDebt(4, PROVIDER_A, 'debt-model');
|
|
366
|
+
await postRelay(PROVIDER_B, 'https://relay-b.invalid/balance', 7);
|
|
367
|
+
await recordDebt(5, PROVIDER_B, 'debt-model');
|
|
368
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 8);
|
|
369
|
+
await recordDebt(6, PROVIDER_A, 'debt-model');
|
|
370
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 7);
|
|
371
|
+
await recordDebt(7, PROVIDER_A, 'alternate-debt-model');
|
|
372
|
+
|
|
373
|
+
disk = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
374
|
+
const debts = disk.days[DAY].unpricedByProvider;
|
|
375
|
+
assert.equal(debts.length, 3, 'provider/model produce three distinct debt snapshots(relay 缺倍率统一记 1)');
|
|
376
|
+
assert.ok(debts.every((debt) => debt.peak === null && debt.offPeak.input > 0),
|
|
377
|
+
'each debt snapshot preserves peak/offPeak token partitions');
|
|
378
|
+
for (const [provider, model, multiplier, tokens] of [
|
|
379
|
+
[PROVIDER_A, 'debt-model', 1, M * 2],
|
|
380
|
+
[PROVIDER_B, 'debt-model', 1, M],
|
|
381
|
+
[PROVIDER_A, 'alternate-debt-model', 1, M],
|
|
382
|
+
]) {
|
|
383
|
+
assert.ok(debts.some((debt) => debt.provider === provider
|
|
384
|
+
&& debt.model === model && debt.feeMultiplier === multiplier && debt.offPeak.input === tokens),
|
|
385
|
+
'debt key/snapshot includes ' + provider + ' / ' + model + ' / multiplier ' + multiplier + ' / tokens ' + tokens);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* Insert a pre-Stage2B model-only legacy debt entry, which must settle at multiplier 1. */
|
|
389
|
+
disk.days[DAY].unpriced = disk.days[DAY].unpriced || {};
|
|
390
|
+
disk.days[DAY].unpriced['legacy-debt-model'] = {
|
|
391
|
+
peak: zeroTier(),
|
|
392
|
+
offPeak: { input: M, cacheRead: 0, cacheWrite: 0, output: 0 },
|
|
393
|
+
};
|
|
394
|
+
fs.writeFileSync(LEDGER_FILE, JSON.stringify(disk));
|
|
395
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 9);
|
|
396
|
+
await postRelay(PROVIDER_B, 'https://relay-b.invalid/balance', 9);
|
|
397
|
+
report = await daily();
|
|
398
|
+
day = report.body.days.find((entry) => entry.date === DAY);
|
|
399
|
+
assert.equal(day.cost, 12, 'later multiplier change leaves settled history alone before debt settlement');
|
|
400
|
+
|
|
401
|
+
priceBook = {
|
|
402
|
+
...priceBook,
|
|
403
|
+
'debt-model': tierPrice(1),
|
|
404
|
+
'alternate-debt-model': tierPrice(1),
|
|
405
|
+
'legacy-debt-model': tierPrice(1),
|
|
406
|
+
};
|
|
407
|
+
posted = await postPrices(priceBook);
|
|
408
|
+
assert.equal(posted.status, 200, 'prices route accepted debt model prices');
|
|
409
|
+
assert.equal(posted.body.settled.entries, 4, 'three provider-scoped and one legacy debt entries settle');
|
|
410
|
+
assert.equal(posted.body.settled.amount, 5, 'snapshots 2 + 1 + 1 and legacy multiplier 1 = 5');
|
|
411
|
+
report = await daily();
|
|
412
|
+
day = report.body.days.find((entry) => entry.date === DAY);
|
|
413
|
+
assert.equal(day.cost, 17, 'historical 12 + settled debt 5 = 17');
|
|
414
|
+
assert.equal(day.costByCurrency.CNY, 17, 'debt settlement updates currency bucket by 5');
|
|
415
|
+
assert.equal(JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')).days[DAY].legacyCost, 77,
|
|
416
|
+
'legacyCost snapshot is not rewritten by multiplier changes or debt settlement');
|
|
417
|
+
|
|
418
|
+
/* A real parent/child session pair exercises the real subagent route. */
|
|
419
|
+
await postRelay(PROVIDER_A, 'https://relay-a.invalid/balance', 9);
|
|
420
|
+
writeSession('parent-session', null, []);
|
|
421
|
+
writeSession('child-session', 'parent-session', [
|
|
422
|
+
assistantMessage(1, OFF_PEAK_AT, PROVIDER_A, 'sub-model', M),
|
|
423
|
+
]);
|
|
424
|
+
const subagent = await hit(handler, API + '/subagent-usage?sessionId=parent-session&since=0');
|
|
425
|
+
assert.equal(subagent.status, 200, 'real subagent route returned HTTP 200');
|
|
426
|
+
assert.equal(subagent.body.total.calls, 1, 'one child usage call counted');
|
|
427
|
+
assert.equal(subagent.body.total.cost, 18, 'subagent cost = base 2 * provider multiplier 9 exactly once');
|
|
428
|
+
assert.equal(subagent.body.children[0].cost, 18, 'child detail uses the same exact multiplied amount');
|
|
429
|
+
|
|
430
|
+
/* Relay matching is exact; the balance amount itself is never fee-multiplied. */
|
|
431
|
+
const realFetch = globalThis.fetch;
|
|
432
|
+
const fetched = [];
|
|
433
|
+
let balanceFixture = { data: { balance: '12.34' } };
|
|
434
|
+
globalThis.fetch = async (url) => {
|
|
435
|
+
fetched.push(String(url));
|
|
436
|
+
return new Response(JSON.stringify(balanceFixture), {
|
|
437
|
+
status: 200,
|
|
438
|
+
headers: { 'content-type': 'application/json' },
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
try {
|
|
442
|
+
const exact = await hit(handler, API + '/balance?provider=' + encodeURIComponent(PROVIDER_A)
|
|
443
|
+
+ '&model=fee-model&force=1');
|
|
444
|
+
assert.equal(exact.status, 200, 'exact relay balance route returned HTTP 200');
|
|
445
|
+
assert.equal(exact.body.ok, true, 'exact channel configuration was used');
|
|
446
|
+
assert.equal(exact.body.total, '12.34', 'balance total is not multiplied by feeMultiplier');
|
|
447
|
+
assert.deepEqual(fetched, ['https://relay-a.invalid/balance'], 'provider A exact channel only was fetched');
|
|
448
|
+
|
|
449
|
+
/* balanceDivisor: optional per-channel unit divisor, applied before formatting. */
|
|
450
|
+
const divisorWrite = await post(API + '/relay-balance-config', {
|
|
451
|
+
channelKey: PROVIDER_A,
|
|
452
|
+
balanceDivisor: 500000,
|
|
453
|
+
});
|
|
454
|
+
assert.equal(divisorWrite.status, 200,
|
|
455
|
+
'balanceDivisor accepted on ordinary relay channel: ' + JSON.stringify(divisorWrite.body));
|
|
456
|
+
const divisorGet = await hit(handler, API + '/relay-balance-config');
|
|
457
|
+
const channelA = divisorGet.body.channels.find((one) => one.channelKey === PROVIDER_A);
|
|
458
|
+
const channelB = divisorGet.body.channels.find((one) => one.channelKey === PROVIDER_B);
|
|
459
|
+
assert.equal(channelA.balanceDivisor, 500000, 'balanceDivisor round-trips through GET');
|
|
460
|
+
assert.equal(channelA.feeMultiplier, 9, 'unrelated relay fields keep their values');
|
|
461
|
+
assert.equal(channelB.balanceDivisor, 1, 'channels without balanceDivisor default to 1');
|
|
462
|
+
|
|
463
|
+
balanceFixture = { data: { balance: '5000000' } };
|
|
464
|
+
const scaled = await hit(handler, API + '/balance?provider=' + encodeURIComponent(PROVIDER_A)
|
|
465
|
+
+ '&model=fee-model&force=1');
|
|
466
|
+
assert.equal(scaled.body.ok, true, 'scaled relay balance usable');
|
|
467
|
+
assert.equal(scaled.body.total, '10.00',
|
|
468
|
+
'5000000 / balanceDivisor 500000 = 10.00, not multiplied by feeMultiplier 9');
|
|
469
|
+
|
|
470
|
+
const invalidDivisor = await post(API + '/relay-balance-config', { channelKey: PROVIDER_A, balanceDivisor: 0 });
|
|
471
|
+
assert.equal(invalidDivisor.status, 400, 'non-positive balanceDivisor rejected');
|
|
472
|
+
const magpieDivisor = await post(API + '/relay-balance-config', { channelKey: 'Magpie', balanceDivisor: 500000 });
|
|
473
|
+
assert.equal(magpieDivisor.status, 400, 'Magpie channel rejects balanceDivisor');
|
|
474
|
+
|
|
475
|
+
/* Model-level relay config: channelKey is the model name, used only when the provider misses. */
|
|
476
|
+
const modelChannel = 'model-channel-probe';
|
|
477
|
+
const modelChannelWrite = await post(API + '/relay-balance-config', {
|
|
478
|
+
channelKey: modelChannel,
|
|
479
|
+
endpoint: 'https://relay-model.invalid/balance',
|
|
480
|
+
currency: 'CNY',
|
|
481
|
+
balancePath: '$.data.balance',
|
|
482
|
+
feeMultiplier: 1,
|
|
483
|
+
token: 'model-channel-token',
|
|
484
|
+
userId: 'model-channel-user',
|
|
485
|
+
});
|
|
486
|
+
assert.equal(modelChannelWrite.status, 200,
|
|
487
|
+
'model-keyed relay channel accepted: ' + JSON.stringify(modelChannelWrite.body));
|
|
488
|
+
balanceFixture = { data: { balance: '7.77' } };
|
|
489
|
+
const modelFallbackMark = fetched.length;
|
|
490
|
+
const byModel = await hit(handler, API + '/balance?provider=' + encodeURIComponent('unknown-relay-provider')
|
|
491
|
+
+ '&model=' + encodeURIComponent(modelChannel) + '&force=1');
|
|
492
|
+
assert.equal(byModel.status, 200, 'model fallback returned HTTP 200');
|
|
493
|
+
assert.equal(byModel.body.ok, true, 'model fallback used the model-keyed relay channel');
|
|
494
|
+
assert.equal(byModel.body.total, '7.77', 'model fallback formats the relay balance');
|
|
495
|
+
assert.deepEqual(fetched.slice(modelFallbackMark), ['https://relay-model.invalid/balance'],
|
|
496
|
+
'model fallback fetched only the model-keyed endpoint');
|
|
497
|
+
|
|
498
|
+
const providerWinsMark = fetched.length;
|
|
499
|
+
await hit(handler, API + '/balance?provider=' + encodeURIComponent(PROVIDER_A)
|
|
500
|
+
+ '&model=' + encodeURIComponent(modelChannel) + '&force=1');
|
|
501
|
+
assert.deepEqual(fetched.slice(providerWinsMark), ['https://relay-a.invalid/balance'],
|
|
502
|
+
'exact provider channel wins over a model-keyed channel');
|
|
503
|
+
|
|
504
|
+
const magpieMark = fetched.length;
|
|
505
|
+
await hit(handler, API + '/balance?provider=Magpie&model=' + encodeURIComponent(modelChannel) + '&force=1');
|
|
506
|
+
/* 3.0.4 起 queryMagpieBalance 会查两个端点(/v1/magpie/quotas + /v1/models),多 2 次 fetch;
|
|
507
|
+
这里钉住「不按模型名回退到单条 channel」,而不是旧的 4 次总数。 */
|
|
508
|
+
assert.equal(fetched.length, magpieMark + 2, 'Magpie 走 quotas + models 两个端点,不按模型名回退');
|
|
509
|
+
|
|
510
|
+
/* Magpie 与未知 provider 每次只探测 Magpie 的 quotas + models 两个端点(2 次 fetch),
|
|
511
|
+
绝不按模型名回退到单条 relay channel。 */
|
|
512
|
+
const magpieOnlyMark = fetched.length;
|
|
513
|
+
await hit(handler, API + '/balance?provider=Magpie&model=fee-model&force=1');
|
|
514
|
+
assert.equal(fetched.length, magpieOnlyMark + 2, 'Magpie 只查 quotas + models');
|
|
515
|
+
const unknownMark = fetched.length;
|
|
516
|
+
await hit(handler, API + '/balance?provider=unconfigured-provider&model=deepseek-flash&force=1');
|
|
517
|
+
assert.equal(fetched.length, unknownMark + 2, 'unknown provider 只探测 Magpie 两个端点');
|
|
518
|
+
const suffixMark = fetched.length;
|
|
519
|
+
await hit(handler, API + '/balance?provider=' + encodeURIComponent(PROVIDER_A + '-suffix')
|
|
520
|
+
+ '&model=fee-model&force=1');
|
|
521
|
+
assert.equal(fetched.length, suffixMark + 2, 'provider 名后缀不精确命中 relay,只探测 Magpie 两个端点');
|
|
522
|
+
} finally {
|
|
523
|
+
globalThis.fetch = realFetch;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/* Price-entry feeMultiplier: the client relay station stores it on each model entry. */
|
|
527
|
+
const dayCostNow = async () => {
|
|
528
|
+
const next = await daily();
|
|
529
|
+
const entry = next.body.days.find((one) => one.date === DAY);
|
|
530
|
+
assert.ok(entry, 'daily usage still has test date ' + DAY);
|
|
531
|
+
return entry.cost;
|
|
532
|
+
};
|
|
533
|
+
const costBeforeEntryFee = await dayCostNow();
|
|
534
|
+
priceBook = {
|
|
535
|
+
...priceBook,
|
|
536
|
+
'fee-entry-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 2 }),
|
|
537
|
+
'plain-entry-model': tierPrice(1, 0),
|
|
538
|
+
'zero-fee-entry-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 0 }),
|
|
539
|
+
'negative-fee-entry-model': Object.assign(tierPrice(1, 0), { feeMultiplier: -1 }),
|
|
540
|
+
'string-fee-entry-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 'x' }),
|
|
541
|
+
};
|
|
542
|
+
posted = await postPrices(priceBook);
|
|
543
|
+
assert.equal(posted.status, 200, 'price book with feeMultiplier entries accepted');
|
|
544
|
+
writeSession('price-entry-fee-session', null, [
|
|
545
|
+
assistantMessage(1, OFF_PEAK_AT, 'plain-provider', 'fee-entry-model', M),
|
|
546
|
+
assistantMessage(2, OFF_PEAK_AT, 'plain-provider', 'plain-entry-model', M),
|
|
547
|
+
assistantMessage(3, OFF_PEAK_AT, 'plain-provider', 'zero-fee-entry-model', M),
|
|
548
|
+
assistantMessage(4, OFF_PEAK_AT, 'plain-provider', 'negative-fee-entry-model', M),
|
|
549
|
+
assistantMessage(5, OFF_PEAK_AT, 'plain-provider', 'string-fee-entry-model', M),
|
|
550
|
+
]);
|
|
551
|
+
const costAfterEntryFee = await dayCostNow();
|
|
552
|
+
assert.equal(costAfterEntryFee - costBeforeEntryFee, 6,
|
|
553
|
+
'feeMultiplier 2 doubles one call; missing/0/-1/"x" fall back to 1 (2 + 1 + 1 + 1 + 1 = 6)');
|
|
554
|
+
|
|
555
|
+
/* The provider channel multiplier and the price-entry multiplier multiply. */
|
|
556
|
+
const costBeforeProduct = await dayCostNow();
|
|
557
|
+
writeSession('price-entry-fee-product-session', null, [
|
|
558
|
+
assistantMessage(1, OFF_PEAK_AT, PROVIDER_A, 'fee-entry-model', M),
|
|
559
|
+
]);
|
|
560
|
+
const costAfterProduct = await dayCostNow();
|
|
561
|
+
assert.equal(costAfterProduct - costBeforeProduct, 18,
|
|
562
|
+
'channel multiplier 9 * price-entry multiplier 2 = 18 for a 1 CNY call');
|
|
563
|
+
|
|
564
|
+
/* Debt settlement applies the price-entry multiplier on both debt paths.
|
|
565
|
+
The model name must not token-match any priced key, or it would be priced instead of debited. */
|
|
566
|
+
writeSession('price-entry-fee-debt-session', null, [
|
|
567
|
+
assistantMessage(1, OFF_PEAK_AT, 'plain-provider', 'zzz-debt-probe', M),
|
|
568
|
+
]);
|
|
569
|
+
const costWithDebt = await dayCostNow();
|
|
570
|
+
assert.equal(costWithDebt, costAfterProduct, 'unpriced model does not change settled cost');
|
|
571
|
+
|
|
572
|
+
disk = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
573
|
+
disk.days[DAY].unpriced = disk.days[DAY].unpriced || {};
|
|
574
|
+
disk.days[DAY].unpriced['legacy-fee-debt-model'] = {
|
|
575
|
+
peak: zeroTier(),
|
|
576
|
+
offPeak: { input: M, cacheRead: 0, cacheWrite: 0, output: 0 },
|
|
577
|
+
};
|
|
578
|
+
fs.writeFileSync(LEDGER_FILE, JSON.stringify(disk));
|
|
579
|
+
|
|
580
|
+
priceBook = {
|
|
581
|
+
...priceBook,
|
|
582
|
+
'zzz-debt-probe': Object.assign(tierPrice(1, 0), { feeMultiplier: 2 }),
|
|
583
|
+
'legacy-fee-debt-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 2 }),
|
|
584
|
+
};
|
|
585
|
+
posted = await postPrices(priceBook);
|
|
586
|
+
assert.equal(posted.status, 200, 'prices for fee debts accepted');
|
|
587
|
+
assert.equal(posted.body.settled.entries, 2, 'provider-scoped and legacy debts both settle');
|
|
588
|
+
assert.equal(posted.body.settled.amount, 4,
|
|
589
|
+
'each 1 CNY debt * price-entry multiplier 2 = 2, total 4');
|
|
590
|
+
const costAfterDebt = await dayCostNow();
|
|
591
|
+
assert.equal(costAfterDebt - costWithDebt, 4, 'settled debt adds the multiplied amount to day cost');
|
|
592
|
+
|
|
593
|
+
/* Tolerant model-name matching: provider prefix + separator variants hit the same price entry. */
|
|
594
|
+
const tolerantBefore = await dayCostNow();
|
|
595
|
+
priceBook = {
|
|
596
|
+
...priceBook,
|
|
597
|
+
'claude-opus-5.5': tierPrice(1, 0),
|
|
598
|
+
};
|
|
599
|
+
posted = await postPrices(priceBook);
|
|
600
|
+
assert.equal(posted.status, 200, 'tolerant-matching price book accepted');
|
|
601
|
+
writeSession('tolerant-match-session', null, [
|
|
602
|
+
assistantMessage(1, OFF_PEAK_AT, 'plain-provider', 'remote-magpie/group/claude-opus-5-5', M),
|
|
603
|
+
]);
|
|
604
|
+
const tolerantAfter = await dayCostNow();
|
|
605
|
+
assert.equal(tolerantAfter - tolerantBefore, 1,
|
|
606
|
+
'prefixed + dashed model name hits the claude-opus-5.5 price entry (compact-name match)');
|
|
607
|
+
|
|
608
|
+
/* Compact match must be exact: deepseek-v4 must not borrow the deepseek-v4-pro price. */
|
|
609
|
+
const mismatchBefore = await dayCostNow();
|
|
610
|
+
priceBook = {
|
|
611
|
+
...priceBook,
|
|
612
|
+
'deepseek-v4-pro': tierPrice(1, 0),
|
|
613
|
+
};
|
|
614
|
+
posted = await postPrices(priceBook);
|
|
615
|
+
assert.equal(posted.status, 200, 'mismatch-guard price book accepted');
|
|
616
|
+
writeSession('tolerant-mismatch-session', null, [
|
|
617
|
+
assistantMessage(1, OFF_PEAK_AT, 'plain-provider', 'deepseek-v4', M),
|
|
618
|
+
]);
|
|
619
|
+
const mismatchAfter = await dayCostNow();
|
|
620
|
+
assert.equal(mismatchAfter, mismatchBefore,
|
|
621
|
+
'deepseek-v4 must not borrow deepseek-v4-pro price (compact strings differ)');
|
|
622
|
+
const mismatchLedger = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
623
|
+
assert.equal((mismatchLedger.days[DAY].unpricedByProvider || []).some((one) => one.model === 'deepseek-v4'),
|
|
624
|
+
true, 'deepseek-v4 is recorded as unpriced debt instead of borrowing a similar key');
|
|
625
|
+
console.log('Tolerant matching: prefixed/dashed names hit the same price; deepseek-v4 stays unpriced.');
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
/* ---- task-10:provider 归属(official / points / relay)与按归属计价 ---- */
|
|
629
|
+
const affiliationBefore = await dayCostNow();
|
|
630
|
+
const affiliationBook = Object.assign({}, priceBook, {
|
|
631
|
+
'aff-official-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 2, feeConfigured: true }),
|
|
632
|
+
});
|
|
633
|
+
let affPosted = await postPrices(affiliationBook);
|
|
634
|
+
assert.equal(affPosted.status, 200, 'affiliation price book accepted');
|
|
635
|
+
writeSession('aff-official-session', null, [assistantMessage(1, OFF_PEAK_AT, 'official-api', 'aff-official-model', M)]);
|
|
636
|
+
let affAfter = await dayCostNow();
|
|
637
|
+
assert.equal(affAfter - affiliationBefore, 1, 'official provider 忽略价格条目倍率,按官方价 1 计费');
|
|
638
|
+
writeSession('aff-relay-session', null, [assistantMessage(1, OFF_PEAK_AT, 'plain-provider', 'aff-official-model', M)]);
|
|
639
|
+
affAfter = await dayCostNow();
|
|
640
|
+
assert.equal(affAfter - affiliationBefore, 3, 'relay provider 按价格条目倍率 2 计费(1 + 2)');
|
|
641
|
+
writeSession('aff-points-session', null, [assistantMessage(1, OFF_PEAK_AT, 'workbuddy-points', 'aff-official-model', M)]);
|
|
642
|
+
writeSession('aff-qoder-session', null, [assistantMessage(1, OFF_PEAK_AT, 'qoder-points', 'aff-official-model', M)]);
|
|
643
|
+
affAfter = await dayCostNow();
|
|
644
|
+
assert.equal(affAfter - affiliationBefore, 5, 'WorkBuddy / Qoder 积分制仍按官方价(各 1)');
|
|
645
|
+
|
|
646
|
+
/* relay 缺倍率:不按官方价结算,记 provider 欠账;补 feeConfigured 后按倍率结算并触发指纹变更 */
|
|
647
|
+
const missingBefore = await dayCostNow();
|
|
648
|
+
const missingBook = Object.assign({}, affiliationBook, {
|
|
649
|
+
'aff-relay-missing': { tiered: false, currency: 'CNY', peak: { ...zeroTier(), input: 1 }, offPeak: { ...zeroTier(), input: 1 } },
|
|
650
|
+
});
|
|
651
|
+
affPosted = await postPrices(missingBook);
|
|
652
|
+
assert.equal(affPosted.status, 200, 'relay missing-fee price book accepted');
|
|
653
|
+
writeSession('aff-missing-session', null, [assistantMessage(1, OFF_PEAK_AT, 'plain-provider', 'aff-relay-missing', M)]);
|
|
654
|
+
const missingAfter = await dayCostNow();
|
|
655
|
+
assert.equal(missingAfter, missingBefore, 'relay 缺 feeConfigured 不产生官方价费用');
|
|
656
|
+
const missingLedger = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
657
|
+
const missingDebt = (missingLedger.days[DAY].unpricedByProvider || []).filter((one) => one.provider === 'plain-provider' && one.model === 'aff-relay-missing');
|
|
658
|
+
assert.equal(missingDebt.length, 1, 'relay 缺倍率记录 provider 欠账');
|
|
659
|
+
assert.equal(missingDebt[0].feeMultiplier, 1, '缺倍率欠账的 feeMultiplier 记为 1');
|
|
660
|
+
const missingFixed = Object.assign({}, missingBook, {
|
|
661
|
+
'aff-relay-missing': Object.assign(tierPrice(1, 0), { feeMultiplier: 3, feeConfigured: true }),
|
|
662
|
+
});
|
|
663
|
+
affPosted = await postPrices(missingFixed);
|
|
664
|
+
assert.equal(affPosted.body.changed, true, 'feeConfigured / feeMultiplier 变化触发价格指纹变更并结算');
|
|
665
|
+
assert.equal(affPosted.body.settled.entries, 1, '补齐倍率后结算 1 条欠账');
|
|
666
|
+
assert.equal(affPosted.body.settled.amount, 3, '按补上的倍率 3 结算');
|
|
667
|
+
const missingAfterFix = await dayCostNow();
|
|
668
|
+
assert.equal(missingAfterFix - missingBefore, 3, '补齐倍率后费用增加 3');
|
|
669
|
+
|
|
670
|
+
console.log('Provider affiliation: official 忽略条目倍率;relay 按条目倍率;WorkBuddy/Qoder 按官方价;缺倍率记欠账。');
|
|
671
|
+
|
|
672
|
+
/* ---- task-11:一次性历史重算(relay 历史按倍率修正,官方/points/缺日志保留) ---- */
|
|
673
|
+
const auditAtConfigured = OFF_PEAK_AT - 3 * 24 * 3600 * 1000;
|
|
674
|
+
const auditAtMissing = OFF_PEAK_AT - 4 * 24 * 3600 * 1000;
|
|
675
|
+
const auditAtOfficial = OFF_PEAK_AT - 5 * 24 * 3600 * 1000;
|
|
676
|
+
const auditAtPoints = OFF_PEAK_AT - 6 * 24 * 3600 * 1000;
|
|
677
|
+
const dateOf = (at) => { const d = new Date(at); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
678
|
+
const auditDayConfigured = dateOf(auditAtConfigured);
|
|
679
|
+
const auditDayMissing = dateOf(auditAtMissing);
|
|
680
|
+
const auditDayOfficial = dateOf(auditAtOfficial);
|
|
681
|
+
const auditDayPoints = dateOf(auditAtPoints);
|
|
682
|
+
const auditDayNoLog = dateOf(auditAtPoints - 24 * 3600 * 1000);
|
|
683
|
+
priceBook = Object.assign({}, priceBook, {
|
|
684
|
+
'audit-relay-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 2, feeConfigured: true }),
|
|
685
|
+
'audit-missing-model': { tiered: false, currency: 'CNY', peak: { input: 1, cacheRead: 0, cacheWrite: 0, output: 0 }, offPeak: { input: 1, cacheRead: 0, cacheWrite: 0, output: 0 } },
|
|
686
|
+
'audit-official-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 2, feeConfigured: true }),
|
|
687
|
+
'audit-points-model': Object.assign(tierPrice(1, 0), { feeMultiplier: 2, feeConfigured: true }),
|
|
688
|
+
});
|
|
689
|
+
affPosted = await postPrices(priceBook);
|
|
690
|
+
assert.equal(affPosted.status, 200, 'audit price book accepted');
|
|
691
|
+
writeSession('audit-configured-session', null, [assistantMessage(1, auditAtConfigured, 'plain-provider', 'audit-relay-model', M)]);
|
|
692
|
+
writeSession('audit-missing-session', null, [assistantMessage(1, auditAtMissing, 'plain-provider', 'audit-missing-model', M)]);
|
|
693
|
+
writeSession('audit-official-session', null, [assistantMessage(1, auditAtOfficial, 'official-api', 'audit-official-model', M)]);
|
|
694
|
+
writeSession('audit-points-session', null, [assistantMessage(1, auditAtPoints, 'workbuddy-points', 'audit-points-model', M)]);
|
|
695
|
+
const auditLedger = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
696
|
+
auditLedger.providerPricingAuditVersion = '';
|
|
697
|
+
const seedAuditDay = (cost) => ({ input: M, cacheRead: 0, cacheWrite: 0, output: 0, calls: 1, cost: cost, costByCurrency: { CNY: cost } });
|
|
698
|
+
auditLedger.days[auditDayConfigured] = seedAuditDay(1);
|
|
699
|
+
auditLedger.days[auditDayMissing] = seedAuditDay(1);
|
|
700
|
+
auditLedger.days[auditDayOfficial] = seedAuditDay(1);
|
|
701
|
+
auditLedger.days[auditDayPoints] = seedAuditDay(1);
|
|
702
|
+
auditLedger.days[auditDayNoLog] = seedAuditDay(7);
|
|
703
|
+
auditLedger.seen['audit-configured-session'] = [1];
|
|
704
|
+
auditLedger.seen['audit-missing-session'] = [1];
|
|
705
|
+
auditLedger.seen['audit-official-session'] = [1];
|
|
706
|
+
auditLedger.seen['audit-points-session'] = [1];
|
|
707
|
+
fs.writeFileSync(LEDGER_FILE, JSON.stringify(auditLedger));
|
|
708
|
+
const auditBackupPath = LEDGER_FILE + '.bak-provider-pricing';
|
|
709
|
+
try { fs.rmSync(auditBackupPath, { force: true }); } catch (error) { /* none */ }
|
|
710
|
+
const auditBeforeRaw = fs.readFileSync(LEDGER_FILE, 'utf8');
|
|
711
|
+
report = await daily();
|
|
712
|
+
const auditCost = (dayKey) => { const diskNow = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')); return diskNow.days[dayKey] === undefined ? undefined : diskNow.days[dayKey].cost; };
|
|
713
|
+
assert.equal(auditCost(auditDayConfigured), 2, 'relay 已配倍率:历史官方价 1 → 官方价 × 2 = 2');
|
|
714
|
+
assert.equal(auditCost(auditDayMissing), 0, 'relay 缺倍率:移除原官方价成本');
|
|
715
|
+
assert.equal(auditCost(auditDayOfficial), 1, 'official 历史成本保持原样');
|
|
716
|
+
assert.equal(auditCost(auditDayPoints), 1, 'points 历史成本保持原样');
|
|
717
|
+
assert.equal(auditCost(auditDayNoLog), 7, '缺日志日期保留原值');
|
|
718
|
+
const auditDisk = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
719
|
+
const auditDebt = (auditDisk.days[auditDayMissing].unpricedByProvider || []).filter((one) => one.provider === 'plain-provider' && one.model === 'audit-missing-model');
|
|
720
|
+
assert.equal(auditDebt.length, 1, 'relay 缺倍率历史写入 unpricedByProvider 欠账');
|
|
721
|
+
assert.equal(auditDebt[0].feeMultiplier, 1, '历史欠账 feeMultiplier 记 1');
|
|
722
|
+
assert.equal(auditDisk.providerPricingAuditVersion, 2, '历史重算一次性标记置 2');
|
|
723
|
+
const auditBackup = fs.readFileSync(auditBackupPath, 'utf8');
|
|
724
|
+
assert.equal(auditBackup, auditBeforeRaw, '重算前备份 usage-ledger.json.bak-provider-pricing 且只备份一次');
|
|
725
|
+
assert.deepStrictEqual(auditDisk.seen['audit-configured-session'], [1], '历史重算保留 seen');
|
|
726
|
+
const auditBeforeSecond = auditCost(auditDayConfigured);
|
|
727
|
+
report = await daily();
|
|
728
|
+
assert.equal(auditCost(auditDayConfigured), auditBeforeSecond, '重复执行幂等:日期费用不再变化');
|
|
729
|
+
const auditDiskSecond = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
730
|
+
assert.equal(auditDiskSecond.providerPricingAuditVersion, 2, '重复执行不重复迁移');
|
|
731
|
+
|
|
732
|
+
console.log('History audit: relay 已配倍率重算 / 缺倍率转欠账 / official+points 不动 / 缺日志保留 / 幂等。');
|
|
733
|
+
|
|
734
|
+
/* ---- task-13:USD 历史重算(relay USD 有倍率→改、无倍率→转欠账、official/points 不动、v1→v2 不重复扣 CNY) ---- */
|
|
735
|
+
const auditUsdAtFee = OFF_PEAK_AT - 8 * 24 * 3600 * 1000;
|
|
736
|
+
const auditUsdAtDebt = OFF_PEAK_AT - 9 * 24 * 3600 * 1000;
|
|
737
|
+
const auditUsdAtOfficial = OFF_PEAK_AT - 10 * 24 * 3600 * 1000;
|
|
738
|
+
const auditUsdAtPoints = OFF_PEAK_AT - 11 * 24 * 3600 * 1000;
|
|
739
|
+
const auditUsdAtV1 = OFF_PEAK_AT - 12 * 24 * 3600 * 1000;
|
|
740
|
+
const auditUsdAtPrefix = OFF_PEAK_AT - 13 * 24 * 3600 * 1000;
|
|
741
|
+
const auditUsdAtOrbi = OFF_PEAK_AT - 14 * 24 * 3600 * 1000;
|
|
742
|
+
const auditUsdDayFee = dateOf(auditUsdAtFee);
|
|
743
|
+
const auditUsdDayDebt = dateOf(auditUsdAtDebt);
|
|
744
|
+
const auditUsdDayOfficial = dateOf(auditUsdAtOfficial);
|
|
745
|
+
const auditUsdDayPoints = dateOf(auditUsdAtPoints);
|
|
746
|
+
const auditUsdDayV1 = dateOf(auditUsdAtV1);
|
|
747
|
+
const auditUsdDayPrefix = dateOf(auditUsdAtPrefix);
|
|
748
|
+
const auditUsdDayOrbi = dateOf(auditUsdAtOrbi);
|
|
749
|
+
priceBook = Object.assign({}, priceBook, {
|
|
750
|
+
'audit-usd-relay-fee': usdTierPrice(1, 0, 2),
|
|
751
|
+
'audit-usd-relay-debt': usdTierPrice(1),
|
|
752
|
+
'audit-usd-official': usdTierPrice(1, 0, 2),
|
|
753
|
+
'audit-usd-points': usdTierPrice(1, 0, 2),
|
|
754
|
+
'audit-usd-v1-model': usdTierPrice(1),
|
|
755
|
+
'audit-usd-prefix-model': usdTierPrice(1, 0, 2),
|
|
756
|
+
'audit-usd-orbi-model': usdTierPrice(1),
|
|
757
|
+
/* 和内置表同名的 CNY 模型,用来验证 v1→v2 迁移不会把 v1 已扣过的 CNY 再扣一次。 */
|
|
758
|
+
'deepseek-flash': tierPrice(1, 0),
|
|
759
|
+
});
|
|
760
|
+
affPosted = await postPrices(priceBook);
|
|
761
|
+
assert.equal(affPosted.status, 200, 'USD audit price book accepted');
|
|
762
|
+
/* 模拟真实故障现场:台账指纹里记着完整价目表(含 USD 模型),但 host 重启后
|
|
763
|
+
`clientPrices` 为空、当前价库只剩内置 CNY 表。把客户端当前价库换成一个不含
|
|
764
|
+
USD 审计模型的版本,历史重算必须靠指纹还原单价,不能靠当前价库。 */
|
|
765
|
+
const auditUsdHistoryBook = priceBook;
|
|
766
|
+
const auditUsdActiveBook = Object.assign({}, priceBook);
|
|
767
|
+
for (const name of ['audit-usd-relay-fee', 'audit-usd-relay-debt', 'audit-usd-official',
|
|
768
|
+
'audit-usd-points', 'audit-usd-v1-model', 'audit-usd-prefix-model', 'audit-usd-orbi-model']) {
|
|
769
|
+
delete auditUsdActiveBook[name];
|
|
770
|
+
}
|
|
771
|
+
affPosted = await postPrices(auditUsdActiveBook);
|
|
772
|
+
assert.equal(affPosted.status, 200, 'restart-like price book accepted');
|
|
773
|
+
writeSession('audit-usd-fee-session', null, [assistantMessage(1, auditUsdAtFee, 'plain-provider', 'audit-usd-relay-fee', M)]);
|
|
774
|
+
writeSession('audit-usd-debt-session', null, [assistantMessage(1, auditUsdAtDebt, 'plain-provider', 'audit-usd-relay-debt', M)]);
|
|
775
|
+
writeSession('audit-usd-official-session', null, [assistantMessage(1, auditUsdAtOfficial, 'official-api', 'audit-usd-official', M)]);
|
|
776
|
+
writeSession('audit-usd-points-session', null, [assistantMessage(1, auditUsdAtPoints, 'workbuddy-points', 'audit-usd-points', M)]);
|
|
777
|
+
writeSession('audit-usd-v1-cny-session', null, [assistantMessage(1, auditUsdAtV1, 'plain-provider', 'deepseek-flash', M)]);
|
|
778
|
+
writeSession('audit-usd-v1-usd-session', null, [assistantMessage(1, auditUsdAtV1, 'plain-provider', 'audit-usd-v1-model', M)]);
|
|
779
|
+
/* 老日志 provider 为空:只能靠模型命名空间前缀判 relay。 */
|
|
780
|
+
writeSession('audit-usd-prefix-session', null, [assistantMessage(1, auditUsdAtPrefix, undefined, 'remote-magpie/group/audit-usd-prefix-model', M)]);
|
|
781
|
+
/* provider 配置缺失:只能靠 provider 短名兜底判 relay。 */
|
|
782
|
+
writeSession('audit-usd-orbi-session', null, [assistantMessage(1, auditUsdAtOrbi, 'orbi', 'audit-usd-orbi-model', M)]);
|
|
783
|
+
const usdSeed = (usd, cny = 0) => ({
|
|
784
|
+
input: M, cacheRead: 0, cacheWrite: 0, output: 0, calls: 1,
|
|
785
|
+
cost: usd + cny, costByCurrency: { CNY: cny, USD: usd },
|
|
786
|
+
});
|
|
787
|
+
const seedUsdAuditLedger = (version) => {
|
|
788
|
+
const next = JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8'));
|
|
789
|
+
next.providerPricingAuditVersion = version;
|
|
790
|
+
next.priceFingerprint = bookFingerprint(auditUsdHistoryBook);
|
|
791
|
+
next.days[auditUsdDayFee] = usdSeed(1);
|
|
792
|
+
next.days[auditUsdDayDebt] = usdSeed(1);
|
|
793
|
+
next.days[auditUsdDayOfficial] = usdSeed(1);
|
|
794
|
+
next.days[auditUsdDayPoints] = usdSeed(1);
|
|
795
|
+
next.days[auditUsdDayV1] = usdSeed(1, 5);
|
|
796
|
+
next.days[auditUsdDayPrefix] = usdSeed(1);
|
|
797
|
+
next.days[auditUsdDayOrbi] = usdSeed(1);
|
|
798
|
+
next.seen['audit-usd-fee-session'] = [1];
|
|
799
|
+
next.seen['audit-usd-debt-session'] = [1];
|
|
800
|
+
next.seen['audit-usd-official-session'] = [1];
|
|
801
|
+
next.seen['audit-usd-points-session'] = [1];
|
|
802
|
+
next.seen['audit-usd-v1-cny-session'] = [1];
|
|
803
|
+
next.seen['audit-usd-v1-usd-session'] = [1];
|
|
804
|
+
next.seen['audit-usd-prefix-session'] = [1];
|
|
805
|
+
next.seen['audit-usd-orbi-session'] = [1];
|
|
806
|
+
fs.writeFileSync(LEDGER_FILE, JSON.stringify(next));
|
|
807
|
+
};
|
|
808
|
+
const usdDayOnDisk = (key) => JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')).days[key];
|
|
809
|
+
const assertUsdAuditDays = (tag) => {
|
|
810
|
+
assert.equal(usdDayOnDisk(auditUsdDayFee).cost, 2, tag + ': relay USD 有倍率 → 1 × 2 = 2');
|
|
811
|
+
assert.equal(usdDayOnDisk(auditUsdDayFee).costByCurrency.USD, 2, tag + ': relay USD 费用写进 USD 桶');
|
|
812
|
+
assert.equal(usdDayOnDisk(auditUsdDayDebt).cost, 0, tag + ': relay USD 缺倍率 → 官方价移除');
|
|
813
|
+
assert.equal(usdDayOnDisk(auditUsdDayDebt).costByCurrency.USD, 0, tag + ': relay USD 缺倍率 → USD 桶清零');
|
|
814
|
+
assert.ok((usdDayOnDisk(auditUsdDayDebt).unpricedByProvider || []).some((one) =>
|
|
815
|
+
one.provider === 'plain-provider' && one.model === 'audit-usd-relay-debt'),
|
|
816
|
+
tag + ': relay USD 缺倍率写入 provider 欠账');
|
|
817
|
+
assert.equal(usdDayOnDisk(auditUsdDayOfficial).cost, 1, tag + ': official USD 历史保持');
|
|
818
|
+
assert.equal(usdDayOnDisk(auditUsdDayOfficial).costByCurrency.USD, 1, tag + ': official USD 桶保持');
|
|
819
|
+
assert.equal(usdDayOnDisk(auditUsdDayPoints).cost, 1, tag + ': WorkBuddy points USD 历史保持');
|
|
820
|
+
assert.equal(usdDayOnDisk(auditUsdDayPoints).costByCurrency.USD, 1, tag + ': points USD 桶保持');
|
|
821
|
+
assert.equal(usdDayOnDisk(auditUsdDayPrefix).cost, 2, tag + ': provider 为空的 remote-magpie 模型按前缀判 relay 并重算');
|
|
822
|
+
assert.equal(usdDayOnDisk(auditUsdDayPrefix).costByCurrency.USD, 2, tag + ': 前缀兜底的 USD 桶正确');
|
|
823
|
+
assert.equal(usdDayOnDisk(auditUsdDayOrbi).cost, 0, tag + ': 配置缺失的 orbi provider 按短名兜底判 relay');
|
|
824
|
+
assert.ok((usdDayOnDisk(auditUsdDayOrbi).unpricedByProvider || []).some((one) =>
|
|
825
|
+
one.provider === 'orbi' && one.model === 'audit-usd-orbi-model'),
|
|
826
|
+
tag + ': orbi 缺倍率 USD 欠账已记录');
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
/* v1→v2 迁移:v1 已修正过的 CNY 不再扣,USD 缺口补上。 */
|
|
830
|
+
seedUsdAuditLedger(1);
|
|
831
|
+
report = await daily();
|
|
832
|
+
assertUsdAuditDays('v1→v2');
|
|
833
|
+
assert.equal(usdDayOnDisk(auditUsdDayV1).cost, 5, 'v1→v2: 已修正的 CNY 历史不重复扣');
|
|
834
|
+
assert.equal(usdDayOnDisk(auditUsdDayV1).costByCurrency.CNY, 5, 'v1→v2: CNY 桶保持 5');
|
|
835
|
+
assert.equal(usdDayOnDisk(auditUsdDayV1).costByCurrency.USD, 0, 'v1→v2: 漏掉的 USD 桶被修正为 0');
|
|
836
|
+
assert.ok((usdDayOnDisk(auditUsdDayV1).unpricedByProvider || []).some((one) =>
|
|
837
|
+
one.provider === 'plain-provider' && one.model === 'audit-usd-v1-model'),
|
|
838
|
+
'v1→v2: 补记 USD 欠账');
|
|
839
|
+
assert.ok((usdDayOnDisk(auditUsdDayV1).unpricedByProvider || []).every((one) => one.model !== 'deepseek-flash'),
|
|
840
|
+
'v1→v2: 不重复记 deepseek-flash 欠账');
|
|
841
|
+
|
|
842
|
+
/* 全新台账(无版本标记):USD 用例同样成立。 */
|
|
843
|
+
seedUsdAuditLedger('');
|
|
844
|
+
report = await daily();
|
|
845
|
+
assertUsdAuditDays('fresh');
|
|
846
|
+
assert.equal(JSON.parse(fs.readFileSync(LEDGER_FILE, 'utf8')).providerPricingAuditVersion, 2,
|
|
847
|
+
'USD 历史重算完成后标记 v2');
|
|
848
|
+
const usdAfterSecond = JSON.stringify(usdDayOnDisk(auditUsdDayFee));
|
|
849
|
+
report = await daily();
|
|
850
|
+
assert.equal(JSON.stringify(usdDayOnDisk(auditUsdDayFee)), usdAfterSecond, '重复执行幂等:USD 日费用不再变化');
|
|
851
|
+
console.log('USD history audit: relay 有倍率重算 / 缺倍率转欠账 / official+points 保持 / 前缀与 provider 兜底 / 幂等。');
|
|
852
|
+
|
|
853
|
+
/* ---- Magpie 子代理费用:只走子代理聚合路径,按实际模型价计,缺倍率默认 1 ---- */
|
|
854
|
+
priceBook = Object.assign({}, priceBook, {
|
|
855
|
+
'deepseek-chat': plainTierPrice(2, 0),
|
|
856
|
+
'deepseek-reasoner': Object.assign(tierPrice(1, 0), { feeMultiplier: 2 }),
|
|
857
|
+
'plain-unpriced-model': plainTierPrice(2, 0),
|
|
858
|
+
'gpt-5-parent': tierPrice(1, 0),
|
|
859
|
+
});
|
|
860
|
+
const magpiePost = await postPrices(priceBook);
|
|
861
|
+
assert.equal(magpiePost.status, 200, 'Magpie subagent price book accepted');
|
|
862
|
+
|
|
863
|
+
const subagentCost = async (parentId, childId, childProvider, childModel, parentProvider, parentModel) => {
|
|
864
|
+
const parentEvents = parentProvider === undefined ? [] : [assistantMessage(1, OFF_PEAK_AT, parentProvider, parentModel, M)];
|
|
865
|
+
writeSession(parentId, null, parentEvents);
|
|
866
|
+
writeSession(childId, parentId, [assistantMessage(1, OFF_PEAK_AT, childProvider, childModel, M)]);
|
|
867
|
+
const res = await hit(handler, API + '/subagent-usage?sessionId=' + encodeURIComponent(parentId) + '&since=0');
|
|
868
|
+
assert.equal(res.status, 200, 'subagent route 200 for ' + parentId);
|
|
869
|
+
return { total: res.body.total, child: res.body.children[0] };
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
/* 父会话用 GPT 模型;子代理 provider magpie + DeepSeek 模型。Magpie 通道倍率=1 时按模型价 2 计(非零)。 */
|
|
873
|
+
await postMagpie(1);
|
|
874
|
+
let magpieRes = await subagentCost('magpie-parent-default', 'magpie-child-default', 'magpie', 'deepseek-chat', 'openai', 'gpt-5-parent');
|
|
875
|
+
assert.equal(magpieRes.total.calls, 1, 'Magpie 子代理 1 次调用');
|
|
876
|
+
assert.equal(magpieRes.total.cost, 2, 'Magpie 子代理默认按模型价 2 计(缺倍率默认 1,非零)');
|
|
877
|
+
assert.equal(magpieRes.child.cost, 2, 'Magpie 子代理明细与 total 一致');
|
|
878
|
+
|
|
879
|
+
/* 显式 Magpie 通道倍率 1.5,provider 别名 remote-magpie:2 × 1.5 = 3(准确乘算)。 */
|
|
880
|
+
await postMagpie(1.5);
|
|
881
|
+
magpieRes = await subagentCost('magpie-parent-fee', 'magpie-child-fee', 'remote-magpie', 'deepseek-chat');
|
|
882
|
+
assert.equal(magpieRes.total.cost, 3, '显式 Magpie 通道倍率 1.5 × 模型价 2 = 3');
|
|
883
|
+
|
|
884
|
+
/* 价格条目自带 feeMultiplier 2:模型价 1 × 通道 1.5 × 条目 2 = 3。 */
|
|
885
|
+
magpieRes = await subagentCost('magpie-parent-entry', 'magpie-child-entry', 'magpie', 'deepseek-reasoner');
|
|
886
|
+
assert.equal(magpieRes.total.cost, 3, 'Magpie 通道 1.5 × 价格条目 feeMultiplier 2 × 模型价 1 = 3');
|
|
887
|
+
|
|
888
|
+
/* 普通 relay 缺 feeConfigured:子代理聚合仍按旧行为,不按官方价误计(0)。 */
|
|
889
|
+
magpieRes = await subagentCost('plain-parent-sub', 'plain-child-sub', 'plain-provider', 'plain-unpriced-model');
|
|
890
|
+
assert.equal(magpieRes.total.cost, 0, '普通 relay 缺 feeConfigured 时子代理费用仍为 0(不按官方价误计)');
|
|
891
|
+
|
|
892
|
+
/* 真正没有 Magpie 通道倍率配置:移除通道后,Magpie + DeepSeek 子代理仍按模型价 2 × 1 计费(非零)。 */
|
|
893
|
+
await removeMagpie();
|
|
894
|
+
magpieRes = await subagentCost('magpie-parent-nocfg', 'magpie-child-nocfg', 'magpie', 'deepseek-chat');
|
|
895
|
+
assert.equal(magpieRes.total.calls, 1, '无 Magpie 配置时子代理仍计 1 次调用');
|
|
896
|
+
assert.equal(magpieRes.total.cost, 2, '无 Magpie 通道倍率配置时按模型价 2 × 默认 1 计(非零)');
|
|
897
|
+
assert.equal(magpieRes.child.cost, 2, '无 Magpie 配置时子代理明细同为 2');
|
|
898
|
+
|
|
899
|
+
/* 重新显式配置 Magpie 倍率 3:2 × 3 = 6,恢复后仍准确乘算。 */
|
|
900
|
+
await postMagpie(3);
|
|
901
|
+
magpieRes = await subagentCost('magpie-parent-restored', 'magpie-child-restored', 'magpie', 'deepseek-chat');
|
|
902
|
+
assert.equal(magpieRes.total.cost, 6, '恢复显式 Magpie 倍率 3 后准确乘算 2 × 3 = 6');
|
|
903
|
+
await postMagpie(1.5);
|
|
904
|
+
|
|
905
|
+
console.log('Magpie subagent: 默认模型价非零 / 无配置默认 1 倍 / 显式通道与条目倍率准确 / 普通 relay 缺倍率仍 0。');
|
|
906
|
+
console.log('PROVIDER FEE CHECKS PASSED');
|
|
907
|
+
console.log('Projection: message/attempt/summary providers, missing-provider defaults, provider-only calls (no event multiplier), replay version.');
|
|
908
|
+
console.log('Overflow: 4004 calls retain 4000 and keep provider/model/peak buckets separate.');
|
|
909
|
+
console.log('Ledger: provider rates, immutable history, provider debt snapshot, legacy multiplier=1 settlement.');
|
|
910
|
+
console.log('Routes: real parent/child subagent cost and exact relay matching; balance total remains unscaled.');
|
|
911
|
+
console.log('Price entries: per-model feeMultiplier multiplies cost and debt; missing/0/-1/"x" fall back to 1.');
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
main().catch((error) => {
|
|
915
|
+
console.error('PROVIDER FEE CHECKS FAILED:', error && error.stack ? error.stack : error);
|
|
916
|
+
process.exitCode = 1;
|
|
917
|
+
}).finally(() => {
|
|
918
|
+
try { fs.rmSync(HOME, { recursive: true, force: true }); } catch (error) { /* best effort test cleanup */ }
|
|
919
|
+
});
|