@lynn123411/dsh-a6api 1.5.1 → 1.5.3
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.md +2 -1
- package/lib/client.js +41 -3
- package/lib/client.js.map +2 -2
- package/lib/index.js +20 -5
- package/lib/index.js.map +2 -2
- package/lib/types/client/store.d.ts +1 -1
- package/lib/types/server/a6api-client.d.ts +7 -0
- package/lib/types/types.d.ts +2 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -386,6 +386,17 @@ function formatCnyPrice(micros, exchangeRate = 6.7209) {
|
|
|
386
386
|
if (cny < 1) return `\xA5${cny.toFixed(4)}`;
|
|
387
387
|
return `\xA5${cny.toFixed(3)}`;
|
|
388
388
|
}
|
|
389
|
+
var BLENDED_OUT_SHARE = 35e-4;
|
|
390
|
+
function computeBlendedPrice100m(inMicros, cacheReadMicros, outMicros, cacheHitRatePct, exchangeRate) {
|
|
391
|
+
const inY = inMicros / 1e6 * exchangeRate;
|
|
392
|
+
const hitY = cacheReadMicros / 1e6 * exchangeRate;
|
|
393
|
+
const outY = outMicros / 1e6 * exchangeRate;
|
|
394
|
+
if (inY <= 0 && hitY <= 0 && outY <= 0) return void 0;
|
|
395
|
+
const h = Math.min(1, Math.max(0, cacheHitRatePct / 100));
|
|
396
|
+
const inShare = 1 - BLENDED_OUT_SHARE;
|
|
397
|
+
const per1M = h * inShare * hitY + (1 - h) * inShare * inY + BLENDED_OUT_SHARE * outY;
|
|
398
|
+
return per1M * 100;
|
|
399
|
+
}
|
|
389
400
|
function buildWebHeaders2(userId, accessToken) {
|
|
390
401
|
const headers = {
|
|
391
402
|
Accept: "application/json",
|
|
@@ -648,6 +659,7 @@ async function fetchChannelDetails(channelId, userId, accessToken, targetModelNa
|
|
|
648
659
|
const recentSuccessRate = item.recent_success_rate !== void 0 ? Number(item.recent_success_rate) / 100 : 100;
|
|
649
660
|
const cacheHitRate = item.cache_hit_rate_24h !== void 0 ? Number(item.cache_hit_rate_24h) / 100 : 72;
|
|
650
661
|
const lastSuccessAt = Number(item.last_success_at || item.last_test_time || 0);
|
|
662
|
+
const blended100m = computeBlendedPrice100m(inMicros, cacheReadMicros, outMicros, cacheHitRate, rate);
|
|
651
663
|
const ratioCny = Number(item.realtime_ratio_cny || inMicros / 1e6 * rate || 0.0341);
|
|
652
664
|
const ratioFormatted = ratioCny.toFixed(4);
|
|
653
665
|
return {
|
|
@@ -686,6 +698,7 @@ async function fetchChannelDetails(channelId, userId, accessToken, targetModelNa
|
|
|
686
698
|
p50_ttft_ms: Number(item.p50_ttft_ms || 2273),
|
|
687
699
|
recent_p50_ms: Number(item.recent_p50_ms || item.last_test_response_ms || 2340),
|
|
688
700
|
cache_hit_rate_pct: cacheHitRate,
|
|
701
|
+
blended_price_100m_cny: blended100m,
|
|
689
702
|
labels,
|
|
690
703
|
last_success_at: lastSuccessAt,
|
|
691
704
|
last_success_text: formatRelativeTime(lastSuccessAt),
|
|
@@ -756,6 +769,7 @@ async function fetchChannelDetails(channelId, userId, accessToken, targetModelNa
|
|
|
756
769
|
recent_p50_ms: Number(logSnapshot.use_time ? logSnapshot.use_time * 1e3 : 2340),
|
|
757
770
|
p50_ttft_ms: 2273,
|
|
758
771
|
cache_hit_rate_pct: 72,
|
|
772
|
+
blended_price_100m_cny: computeBlendedPrice100m(inMicros, cacheReadMicros, outMicros, 72, rate),
|
|
759
773
|
labels: ["\u7A33\u5B9A", "\u4F4E\u4EF7", "\u9AD8\u901F", "\u9AD8\u8D28"],
|
|
760
774
|
last_success_at: Math.floor(Date.now() / 1e3),
|
|
761
775
|
last_success_text: "\u521A\u521A",
|
|
@@ -1814,8 +1828,8 @@ function createUpstreamMemo(ttlMs, shouldCache) {
|
|
|
1814
1828
|
cache.clear();
|
|
1815
1829
|
inflight.clear();
|
|
1816
1830
|
},
|
|
1817
|
-
async get(key, fetcher) {
|
|
1818
|
-
const hit = cache.get(key);
|
|
1831
|
+
async get(key, fetcher, opts) {
|
|
1832
|
+
const hit = opts?.force ? void 0 : cache.get(key);
|
|
1819
1833
|
if (hit && hit.epoch === epoch && Date.now() - hit.at < ttlMs) return hit.data;
|
|
1820
1834
|
let pending = inflight.get(key);
|
|
1821
1835
|
if (!pending) {
|
|
@@ -1845,8 +1859,8 @@ function stateCacheKeyOf(config) {
|
|
|
1845
1859
|
};
|
|
1846
1860
|
return `${config.baseURL || ""}|${config.userId || ""}|${fingerprint(config.apiKey || "")}|${fingerprint(config.accessToken || "")}`;
|
|
1847
1861
|
}
|
|
1848
|
-
async function getCachedStateResponse(config, configAccess) {
|
|
1849
|
-
return stateMemo.get(stateCacheKeyOf(config), () => buildStateResponse(config, configAccess));
|
|
1862
|
+
async function getCachedStateResponse(config, configAccess, force = false) {
|
|
1863
|
+
return stateMemo.get(stateCacheKeyOf(config), () => buildStateResponse(config, configAccess), { force });
|
|
1850
1864
|
}
|
|
1851
1865
|
async function buildStateResponse(config, configAccess) {
|
|
1852
1866
|
const token = config.accessToken || "";
|
|
@@ -2012,7 +2026,8 @@ function apply(ctx) {
|
|
|
2012
2026
|
try {
|
|
2013
2027
|
if (pathname === "/state" && (req.method === "GET" || req.method === "HEAD")) {
|
|
2014
2028
|
const config = await configAccess.readConfig();
|
|
2015
|
-
const
|
|
2029
|
+
const force = url.searchParams.get("force") === "1";
|
|
2030
|
+
const response = await getCachedStateResponse(config, configAccess, force);
|
|
2016
2031
|
return sendJson(res, 200, { ok: true, data: response });
|
|
2017
2032
|
}
|
|
2018
2033
|
if (pathname === "/config" && req.method === "POST") {
|