@vibedev-si/dsh-vibedev 0.8.1 → 0.9.0
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 +22 -0
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/client/client.account-center.js +237 -7
- package/client/client.js +18 -0
- package/lib/account/promotions.d.ts +33 -0
- package/lib/index.js +348 -62
- package/lib/llm/adapter.d.ts +9 -0
- package/lib/llm/index.d.ts +6 -0
- package/lib/llm/promotions.d.ts +124 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -49,7 +49,7 @@ const MIN_READ_SPACING_MS = 5e3;
|
|
|
49
49
|
* current when nobody opens anything.
|
|
50
50
|
*/
|
|
51
51
|
const CATALOG_REFRESH_GAP_MS = 6e4;
|
|
52
|
-
const record$
|
|
52
|
+
const record$15 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
53
53
|
const text$9 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
54
54
|
/**
|
|
55
55
|
* A gateway amount as plain decimal text: a number as JavaScript writes it (`99976091.91426945`; the few numbers it
|
|
@@ -304,8 +304,8 @@ var AccountService = class {
|
|
|
304
304
|
redirect: "error"
|
|
305
305
|
});
|
|
306
306
|
if (!response.ok) return {};
|
|
307
|
-
const body = record$
|
|
308
|
-
const data = record$
|
|
307
|
+
const body = record$15(await response.json().catch(() => void 0));
|
|
308
|
+
const data = record$15(body?.data) ?? body;
|
|
309
309
|
const balance = amountOf(data?.balance);
|
|
310
310
|
const currency = text$9(data?.currency) ?? "CNY";
|
|
311
311
|
const frozen = amountOf(data?.frozen_balance);
|
|
@@ -426,7 +426,7 @@ function json$3(status, body) {
|
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
428
|
function failure$1(error) {
|
|
429
|
-
const candidate = record$
|
|
429
|
+
const candidate = record$15(error)?.code;
|
|
430
430
|
const code = candidate === "SIGN_IN_REFUSED" || candidate === "SIGN_IN_TIMEOUT" || candidate === "SIGN_IN_CANCELLED" ? candidate : "INTERNAL";
|
|
431
431
|
return json$3(500, { error: {
|
|
432
432
|
code,
|
|
@@ -445,7 +445,7 @@ function accountRoutes(account) {
|
|
|
445
445
|
methods: ["POST"],
|
|
446
446
|
requestBody: "buffered",
|
|
447
447
|
fetch: async (request) => {
|
|
448
|
-
const body = record$
|
|
448
|
+
const body = record$15(await request.json().catch(() => void 0));
|
|
449
449
|
return json$3(200, { consumed: typeof body?.id === "string" && account.consumeNavigation(body.id) });
|
|
450
450
|
}
|
|
451
451
|
},
|
|
@@ -470,7 +470,7 @@ function accountRoutes(account) {
|
|
|
470
470
|
requestBody: "buffered",
|
|
471
471
|
fetch: async (request) => {
|
|
472
472
|
try {
|
|
473
|
-
const body = record$
|
|
473
|
+
const body = record$15(await request.json().catch(() => void 0));
|
|
474
474
|
return json$3(200, await account.signIn(body?.open !== false));
|
|
475
475
|
} catch (error) {
|
|
476
476
|
return failure$1(error);
|
|
@@ -605,7 +605,7 @@ function normalizeErrorStage(value) {
|
|
|
605
605
|
request: "submit"
|
|
606
606
|
}[word];
|
|
607
607
|
}
|
|
608
|
-
function record$
|
|
608
|
+
function record$14(value) {
|
|
609
609
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
610
610
|
}
|
|
611
611
|
function text$8(value) {
|
|
@@ -615,7 +615,7 @@ function count$1(value) {
|
|
|
615
615
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
616
616
|
}
|
|
617
617
|
/** A CNY amount the gateway sends as a two-decimal string (a number is accepted too). */
|
|
618
|
-
function amount$
|
|
618
|
+
function amount$2(value) {
|
|
619
619
|
if (typeof value === "number" && Number.isFinite(value)) return value.toFixed(2);
|
|
620
620
|
const raw = text$8(value);
|
|
621
621
|
return raw !== void 0 && /^-?\d+(?:\.\d+)?$/.test(raw) ? raw : void 0;
|
|
@@ -631,10 +631,10 @@ function amount$1(value) {
|
|
|
631
631
|
* @returns the fields found.
|
|
632
632
|
*/
|
|
633
633
|
function parseGatewayFailure(body) {
|
|
634
|
-
const root = record$
|
|
634
|
+
const root = record$14(body);
|
|
635
635
|
if (root === void 0) return {};
|
|
636
|
-
const source = record$
|
|
637
|
-
const metadata = record$
|
|
636
|
+
const source = record$14(root.error) ?? root;
|
|
637
|
+
const metadata = record$14(source.metadata) ?? record$14(root.metadata);
|
|
638
638
|
const gatewayCode = text$8(source.gateway_code) ?? text$8(root.gateway_code);
|
|
639
639
|
const code = gatewayCode ?? text$8(source.code) ?? text$8(source.type) ?? text$8(root.reason);
|
|
640
640
|
const message = text$8(source.message) ?? (typeof root.error === "string" ? text$8(root.error) : void 0);
|
|
@@ -646,9 +646,9 @@ function parseGatewayFailure(body) {
|
|
|
646
646
|
limit: count$1(source.limit)
|
|
647
647
|
};
|
|
648
648
|
const amounts = {
|
|
649
|
-
estimatedCny: amount$
|
|
650
|
-
availableCny: amount$
|
|
651
|
-
pendingCny: amount$
|
|
649
|
+
estimatedCny: amount$2(source.estimated_cny),
|
|
650
|
+
availableCny: amount$2(source.available_cny),
|
|
651
|
+
pendingCny: amount$2(source.pending_cny)
|
|
652
652
|
};
|
|
653
653
|
const submissionState = text$8(source.submission_state) ?? text$8(root.submission_state);
|
|
654
654
|
const retryAction = text$8(source.retry_action) ?? text$8(root.retry_action);
|
|
@@ -754,7 +754,7 @@ function sdkGatewayFailure(message, headers = {}) {
|
|
|
754
754
|
}
|
|
755
755
|
//#endregion
|
|
756
756
|
//#region src/account/center-price-contract.ts
|
|
757
|
-
const record$
|
|
757
|
+
const record$13 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
758
758
|
const keys = (value = "") => value.split(" ").filter(Boolean);
|
|
759
759
|
const scalar$1 = (value) => value === null || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" && value.length <= 1e3 && !/\b(?:Bearer\s|vdat_|sk-)|https?:\/\/|eyJ[A-Za-z0-9_-]+\./i.test(value) ? value : void 0;
|
|
760
760
|
/** Only public DNS HTTPS references become navigable links. No credentials, IPs or local hosts. */
|
|
@@ -772,7 +772,7 @@ function publicReferenceUrl(value) {
|
|
|
772
772
|
}
|
|
773
773
|
function project$1(value, shape) {
|
|
774
774
|
if (value === null) return null;
|
|
775
|
-
const source = record$
|
|
775
|
+
const source = record$13(value);
|
|
776
776
|
if (!source) return void 0;
|
|
777
777
|
const out = {};
|
|
778
778
|
for (const key of keys(shape.fields)) {
|
|
@@ -800,7 +800,7 @@ function project$1(value, shape) {
|
|
|
800
800
|
out[key] = source[key].slice(0, key === "models" ? 48 : 1e3).map((item) => child === "scalar" ? scalar$1(item) : child === "matrix" ? Array.isArray(item) ? item.slice(0, 64).map(scalar$1).filter((v) => v !== void 0) : void 0 : project$1(item, child)).filter((item) => item !== void 0);
|
|
801
801
|
}
|
|
802
802
|
for (const [key, child] of Object.entries(shape.maps ?? {})) {
|
|
803
|
-
const map = record$
|
|
803
|
+
const map = record$13(source[key]);
|
|
804
804
|
if (!map) continue;
|
|
805
805
|
out[key] = Object.fromEntries(Object.entries(map).slice(0, 64).filter(([name, value]) => /^[a-z][a-z0-9_]{0,63}$/i.test(name) && !/secret|password|credential|api_key/i.test(name) && (key !== "reasoning_effort_multipliers" || [
|
|
806
806
|
"none",
|
|
@@ -1628,11 +1628,11 @@ function projectBusinessReceipt(value) {
|
|
|
1628
1628
|
//#endregion
|
|
1629
1629
|
//#region src/account/center-contract.ts
|
|
1630
1630
|
/** Exact, read-only account-page schemas. No caller-selected URL or object shape. */
|
|
1631
|
-
const record$
|
|
1631
|
+
const record$12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1632
1632
|
const fields = (text) => text.split(" ");
|
|
1633
1633
|
const scalar = (value) => value === null || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" && value.length <= 1e3 && !/\b(?:Bearer\s|vdat_|sk-)|https?:\/\/|eyJ[A-Za-z0-9_-]+\./i.test(value) ? value : void 0;
|
|
1634
1634
|
function project(value, shape) {
|
|
1635
|
-
const source = record$
|
|
1635
|
+
const source = record$12(value);
|
|
1636
1636
|
if (source === void 0) return void 0;
|
|
1637
1637
|
if (shape === imageSizes) return Object.fromEntries(Object.entries(source).filter(([key, item]) => {
|
|
1638
1638
|
const kilo = /^(\d{1,2}(?:\.\d{1,3})?)K$/.exec(key), dimensions = /^(\d{1,5})x(\d{1,5})$/.exec(key);
|
|
@@ -1691,7 +1691,7 @@ const progress = {
|
|
|
1691
1691
|
arrays: { blocking_reasons: reason }
|
|
1692
1692
|
};
|
|
1693
1693
|
const usage = {
|
|
1694
|
-
fields: fields("id model request_id created_at reasoning_effort service_tier inbound_endpoint upstream_endpoint ip_address user_agent group_id subscription_id input_tokens output_tokens cache_read_tokens cache_creation_tokens cache_creation_5m_tokens cache_creation_1h_tokens total_tokens input_cost output_cost cache_read_cost cache_creation_cost actual_cost total_cost currency rate_multiplier long_context_billing_applied duration_ms first_token_ms request_type stream openai_ws_mode native_compaction_v2 billing_type billing_mode image_count image_size image_input_size image_output_size image_size_source image_input_tokens image_input_cost image_output_tokens image_output_cost media_type cache_ttl_overridden"),
|
|
1694
|
+
fields: fields("id model request_id created_at reasoning_effort service_tier inbound_endpoint upstream_endpoint ip_address user_agent group_id subscription_id input_tokens output_tokens cache_read_tokens cache_creation_tokens cache_creation_5m_tokens cache_creation_1h_tokens total_tokens input_cost output_cost cache_read_cost cache_creation_cost actual_cost total_cost promotion_id promotion_discount currency rate_multiplier long_context_billing_applied duration_ms first_token_ms request_type stream openai_ws_mode native_compaction_v2 billing_type billing_mode image_count image_size image_input_size image_output_size image_size_source image_input_tokens image_input_cost image_output_tokens image_output_cost media_type cache_ttl_overridden"),
|
|
1695
1695
|
objects: {
|
|
1696
1696
|
group,
|
|
1697
1697
|
image_size_breakdown: imageSizes
|
|
@@ -1887,7 +1887,7 @@ function centerQuery(path, params) {
|
|
|
1887
1887
|
/** Legacy summary only: monetary weekly fields become a percentage, never a five-hour window. */
|
|
1888
1888
|
function projectAccountData(value) {
|
|
1889
1889
|
const convert = (item) => {
|
|
1890
|
-
const output = project(item, subscription), source = record$
|
|
1890
|
+
const output = project(item, subscription), source = record$12(item);
|
|
1891
1891
|
if (output === void 0 || source === void 0) return void 0;
|
|
1892
1892
|
const number = (n) => typeof n === "number" && Number.isFinite(n) ? n : typeof n === "string" && /^\d+(?:\.\d+)?$/.test(n) ? Number(n) : void 0;
|
|
1893
1893
|
const used = number(source.weekly_used_usd), limit = number(source.weekly_limit_usd);
|
|
@@ -1899,7 +1899,7 @@ function projectAccountData(value) {
|
|
|
1899
1899
|
return output;
|
|
1900
1900
|
};
|
|
1901
1901
|
if (Array.isArray(value)) return value.slice(0, 1e3).map(convert).filter((item) => item !== void 0);
|
|
1902
|
-
const source = record$
|
|
1902
|
+
const source = record$12(value);
|
|
1903
1903
|
return source === void 0 ? {} : {
|
|
1904
1904
|
...project(source, { fields: ["active_count"] }),
|
|
1905
1905
|
...Array.isArray(source.subscriptions) ? { subscriptions: source.subscriptions.slice(0, 1e3).map(convert).filter((item) => item !== void 0) } : {}
|
|
@@ -1935,14 +1935,14 @@ function projectCenterRoute(path, value) {
|
|
|
1935
1935
|
//#endregion
|
|
1936
1936
|
//#region src/account/center-business.ts
|
|
1937
1937
|
const object$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1938
|
-
const answer$
|
|
1938
|
+
const answer$2 = (status, body) => new Response(JSON.stringify(body), {
|
|
1939
1939
|
status,
|
|
1940
1940
|
headers: {
|
|
1941
1941
|
"content-type": "application/json; charset=utf-8",
|
|
1942
1942
|
"cache-control": "private, no-store"
|
|
1943
1943
|
}
|
|
1944
1944
|
});
|
|
1945
|
-
const failure = (status, code, notSubmitted, extra = {}) => answer$
|
|
1945
|
+
const failure = (status, code, notSubmitted, extra = {}) => answer$2(status, {
|
|
1946
1946
|
...extra,
|
|
1947
1947
|
...notSubmitted ? { not_submitted: true } : {},
|
|
1948
1948
|
error: {
|
|
@@ -2026,7 +2026,7 @@ function accountBusinessActionsRoutes(http, account) {
|
|
|
2026
2026
|
const expectedAction = kind === "redeem/apply" ? "redeem" : kind.replace("/", ".");
|
|
2027
2027
|
if (receipt === void 0 || receipt.operation_id !== body.operation_id || receipt.action !== expectedAction) return failure(502, "ACCOUNT_ACTION_UNKNOWN", false);
|
|
2028
2028
|
if (receipt.state === "succeeded") http.invalidateAccountSnapshots();
|
|
2029
|
-
return answer$
|
|
2029
|
+
return answer$2(200, {
|
|
2030
2030
|
code: 0,
|
|
2031
2031
|
data: receipt
|
|
2032
2032
|
});
|
|
@@ -2056,7 +2056,7 @@ function accountBusinessActionsRoutes(http, account) {
|
|
|
2056
2056
|
//#region src/account/center.ts
|
|
2057
2057
|
const CENTER_PREFIX = "/api/dsh-vibedev/account-center";
|
|
2058
2058
|
const obj = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2059
|
-
function answer(status, body) {
|
|
2059
|
+
function answer$1(status, body) {
|
|
2060
2060
|
return new Response(JSON.stringify(body), {
|
|
2061
2061
|
status,
|
|
2062
2062
|
headers: {
|
|
@@ -2077,7 +2077,7 @@ function accountCenterRoutes(http, account) {
|
|
|
2077
2077
|
let before;
|
|
2078
2078
|
const changed = () => {
|
|
2079
2079
|
http.invalidateAccountSnapshots();
|
|
2080
|
-
return answer(409, { error: {
|
|
2080
|
+
return answer$1(409, { error: {
|
|
2081
2081
|
code: "ACCOUNT_CHANGED",
|
|
2082
2082
|
message: "账号已切换,请刷新页面。"
|
|
2083
2083
|
} });
|
|
@@ -2085,14 +2085,14 @@ function accountCenterRoutes(http, account) {
|
|
|
2085
2085
|
try {
|
|
2086
2086
|
const params = new URL(request.url, "http://host").searchParams;
|
|
2087
2087
|
const parsed = centerQuery(path, params);
|
|
2088
|
-
if (parsed === void 0) return answer(400, { error: {
|
|
2088
|
+
if (parsed === void 0) return answer$1(400, { error: {
|
|
2089
2089
|
code: "INVALID_INPUT",
|
|
2090
2090
|
category: "invalid_input",
|
|
2091
2091
|
message: "筛选参数不符合要求。"
|
|
2092
2092
|
} });
|
|
2093
2093
|
const { query, wire, fresh } = parsed;
|
|
2094
2094
|
before = await account.identity();
|
|
2095
|
-
if (!before.signedIn) return answer(401, { error: {
|
|
2095
|
+
if (!before.signedIn) return answer$1(401, { error: {
|
|
2096
2096
|
code: "AUTHENTICATION_REQUIRED",
|
|
2097
2097
|
category: "authentication",
|
|
2098
2098
|
message: "请先登录 VibeDev。"
|
|
@@ -2109,24 +2109,24 @@ function accountCenterRoutes(http, account) {
|
|
|
2109
2109
|
const after = await account.identity();
|
|
2110
2110
|
if (!sameAccount(before, after)) return changed();
|
|
2111
2111
|
const projected = projectCenterRoute(path, obj(data)?.data ?? data);
|
|
2112
|
-
if (projected === void 0) return answer(502, { error: {
|
|
2112
|
+
if (projected === void 0) return answer$1(502, { error: {
|
|
2113
2113
|
code: "ACCOUNT_READ_UNAVAILABLE",
|
|
2114
2114
|
category: "service_unavailable"
|
|
2115
2115
|
} });
|
|
2116
|
-
return answer(200, {
|
|
2116
|
+
return answer$1(200, {
|
|
2117
2117
|
code: 0,
|
|
2118
2118
|
data: projected
|
|
2119
2119
|
});
|
|
2120
2120
|
} catch (error) {
|
|
2121
2121
|
if (error instanceof MediaError && error.code === "ACCOUNT_CHANGED" || before !== void 0 && !sameAccount(before, await account.identity())) return changed();
|
|
2122
|
-
if (error instanceof MediaError && (error.details.status === 404 || error.details.status === 405)) return answer(200, { unsupported: true });
|
|
2123
|
-
if (error instanceof MediaError) return answer(error.details.status ?? 502, { error: {
|
|
2122
|
+
if (error instanceof MediaError && (error.details.status === 404 || error.details.status === 405)) return answer$1(200, { unsupported: true });
|
|
2123
|
+
if (error instanceof MediaError) return answer$1(error.details.status ?? 502, { error: {
|
|
2124
2124
|
code: error.code,
|
|
2125
2125
|
category: error.details.category,
|
|
2126
2126
|
message: error.message,
|
|
2127
2127
|
request_id: error.details.requestId
|
|
2128
2128
|
} });
|
|
2129
|
-
return answer(502, { error: {
|
|
2129
|
+
return answer$1(502, { error: {
|
|
2130
2130
|
code: "ACCOUNT_READ_UNAVAILABLE",
|
|
2131
2131
|
category: "service_unavailable",
|
|
2132
2132
|
message: "账户信息暂时无法获取,请稍后刷新。"
|
|
@@ -2163,7 +2163,7 @@ const unavailable = () => json$2(200, {
|
|
|
2163
2163
|
items: [],
|
|
2164
2164
|
unread: 0
|
|
2165
2165
|
});
|
|
2166
|
-
const record$
|
|
2166
|
+
const record$11 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2167
2167
|
const text$7 = (value) => typeof value === "string" ? value : void 0;
|
|
2168
2168
|
const identifier = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
2169
2169
|
/**
|
|
@@ -2172,7 +2172,7 @@ const identifier = (value) => typeof value === "number" && Number.isSafeInteger(
|
|
|
2172
2172
|
* @returns the announcement, or undefined when the entry cannot be rendered.
|
|
2173
2173
|
*/
|
|
2174
2174
|
function parseAnnouncement(value) {
|
|
2175
|
-
const item = record$
|
|
2175
|
+
const item = record$11(value);
|
|
2176
2176
|
if (item === void 0) return void 0;
|
|
2177
2177
|
const id = identifier(item.id);
|
|
2178
2178
|
const title = text$7(item.title);
|
|
@@ -2197,7 +2197,7 @@ function parseAnnouncement(value) {
|
|
|
2197
2197
|
*/
|
|
2198
2198
|
function entriesOf(payload) {
|
|
2199
2199
|
if (Array.isArray(payload)) return payload;
|
|
2200
|
-
const data = record$
|
|
2200
|
+
const data = record$11(payload)?.data;
|
|
2201
2201
|
return Array.isArray(data) ? data : void 0;
|
|
2202
2202
|
}
|
|
2203
2203
|
/**
|
|
@@ -2281,7 +2281,7 @@ function announcementRoutes({ http, account }) {
|
|
|
2281
2281
|
fetch: async (incoming) => {
|
|
2282
2282
|
const entered = await enter(incoming);
|
|
2283
2283
|
if (entered instanceof Response) return entered;
|
|
2284
|
-
const body = record$
|
|
2284
|
+
const body = record$11(await incoming.json().catch(() => void 0));
|
|
2285
2285
|
const id = identifier(body?.id);
|
|
2286
2286
|
if (id === void 0) return json$2(400, { error: {
|
|
2287
2287
|
code: "ANNOUNCEMENT_INVALID_ID",
|
|
@@ -3253,7 +3253,7 @@ const invalid = (field) => json(400, { error: {
|
|
|
3253
3253
|
code: "FEEDBACK_INVALID",
|
|
3254
3254
|
field
|
|
3255
3255
|
} });
|
|
3256
|
-
const record$
|
|
3256
|
+
const record$10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
3257
3257
|
/**
|
|
3258
3258
|
* The feedback routes.
|
|
3259
3259
|
* @param options - the uploader's submit, the recent errors and the credential check.
|
|
@@ -3271,7 +3271,7 @@ function feedbackRoutes(options) {
|
|
|
3271
3271
|
requestBody: "buffered",
|
|
3272
3272
|
fetch: async (request) => {
|
|
3273
3273
|
try {
|
|
3274
|
-
const body = record$
|
|
3274
|
+
const body = record$10(await request.json().catch(() => void 0));
|
|
3275
3275
|
if (body === void 0) return invalid("body");
|
|
3276
3276
|
if (body.category !== void 0 && body.category !== null && !isCategory(body.category)) return invalid("category");
|
|
3277
3277
|
if (body.text !== void 0 && typeof body.text !== "string") return invalid("text");
|
|
@@ -3281,7 +3281,7 @@ function feedbackRoutes(options) {
|
|
|
3281
3281
|
if (text === void 0 && category === void 0) return invalid("text");
|
|
3282
3282
|
let content;
|
|
3283
3283
|
if (body.attachment !== void 0 && body.attachment !== null) {
|
|
3284
|
-
const given = record$
|
|
3284
|
+
const given = record$10(body.attachment)?.content;
|
|
3285
3285
|
if (typeof given !== "string" || given === "" || Buffer$1.byteLength(given, "utf8") > 262144) return invalid("attachment");
|
|
3286
3286
|
content = given;
|
|
3287
3287
|
}
|
|
@@ -3394,7 +3394,7 @@ const BUSY_CODES = /* @__PURE__ */ new Set([
|
|
|
3394
3394
|
* Not retried here: a slot frees only when one of the user's tasks finishes.
|
|
3395
3395
|
*/
|
|
3396
3396
|
const TASK_LIMIT_CODES = /* @__PURE__ */ new Set(["VIDEO_TASK_LIMIT_REACHED", "AUDIO_TASK_LIMIT_REACHED"]);
|
|
3397
|
-
const DEFAULT_TIMEOUT_MS = 6e4;
|
|
3397
|
+
const DEFAULT_TIMEOUT_MS$1 = 6e4;
|
|
3398
3398
|
const DEFAULT_BUSY_WAIT_MS = 2e3;
|
|
3399
3399
|
/** The message for a call made while nobody is signed in. */
|
|
3400
3400
|
const SIGN_IN_MESSAGE$1 = "VibeDev media generation needs a signed-in VibeDev account. Call media_account with action \"sign_in\": it opens the VibeDev sign-in page in the user's browser, where new users can also register. In the VibeDev app, the account signed in to the app is used automatically.";
|
|
@@ -3600,7 +3600,7 @@ var GatewayHttp = class {
|
|
|
3600
3600
|
body = JSON.stringify(request.json);
|
|
3601
3601
|
headers["content-type"] = "application/json";
|
|
3602
3602
|
}
|
|
3603
|
-
const timeout = AbortSignal.timeout(request.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
3603
|
+
const timeout = AbortSignal.timeout(request.timeoutMs ?? DEFAULT_TIMEOUT_MS$1);
|
|
3604
3604
|
const signal = request.signal === void 0 ? timeout : AbortSignal.any([request.signal, timeout]);
|
|
3605
3605
|
try {
|
|
3606
3606
|
return await (this.options.fetch ?? globalThis.fetch)(url, {
|
|
@@ -3612,7 +3612,7 @@ var GatewayHttp = class {
|
|
|
3612
3612
|
});
|
|
3613
3613
|
} catch (error) {
|
|
3614
3614
|
if (isAborted(request.signal)) throw abortError(request.signal);
|
|
3615
|
-
if (timeout.aborted) throw new MediaError(`The VibeDev gateway did not answer within ${Math.round((request.timeoutMs ?? DEFAULT_TIMEOUT_MS) / 1e3)} s.`, "GATEWAY_TIMEOUT", { retryable: true });
|
|
3615
|
+
if (timeout.aborted) throw new MediaError(`The VibeDev gateway did not answer within ${Math.round((request.timeoutMs ?? DEFAULT_TIMEOUT_MS$1) / 1e3)} s.`, "GATEWAY_TIMEOUT", { retryable: true });
|
|
3616
3616
|
throw new MediaError("Could not reach the VibeDev gateway. Ask the user to check the network connection.", "GATEWAY_UNREACHABLE", { retryable: true });
|
|
3617
3617
|
}
|
|
3618
3618
|
}
|
|
@@ -4542,7 +4542,7 @@ const CALLBACK_PATH = "/dsh-media/callback";
|
|
|
4542
4542
|
function base64url(data) {
|
|
4543
4543
|
return data.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
4544
4544
|
}
|
|
4545
|
-
const record$
|
|
4545
|
+
const record$9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
4546
4546
|
const text$6 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
4547
4547
|
/**
|
|
4548
4548
|
* Read a token answer (`redeem` or `refresh`).
|
|
@@ -4552,13 +4552,13 @@ const text$6 = (value) => typeof value === "string" && value.trim() !== "" ? val
|
|
|
4552
4552
|
* @returns the grant, or undefined when the answer lacks tokens.
|
|
4553
4553
|
*/
|
|
4554
4554
|
function parseGrant(body, now, previous) {
|
|
4555
|
-
const envelope = record$
|
|
4556
|
-
const data = record$
|
|
4555
|
+
const envelope = record$9(body);
|
|
4556
|
+
const data = record$9(envelope?.data) ?? envelope;
|
|
4557
4557
|
const accessToken = text$6(data?.access_token);
|
|
4558
4558
|
const refreshToken = text$6(data?.refresh_token);
|
|
4559
4559
|
if (data === void 0 || accessToken === void 0 || refreshToken === void 0) return void 0;
|
|
4560
4560
|
const seconds = (value, fallback) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
4561
|
-
const user = record$
|
|
4561
|
+
const user = record$9(data.user);
|
|
4562
4562
|
const sessionId = text$6(data.session_id) ?? previous?.sessionId;
|
|
4563
4563
|
const parsedUser = user === void 0 ? previous?.user : {
|
|
4564
4564
|
...text$6(user.id) === void 0 && typeof user.id !== "number" ? {} : { id: String(user.id) },
|
|
@@ -4983,8 +4983,8 @@ var PluginLogin = class {
|
|
|
4983
4983
|
return;
|
|
4984
4984
|
}
|
|
4985
4985
|
if (!live()) return;
|
|
4986
|
-
const envelope = record$
|
|
4987
|
-
const parsed = envelope !== void 0 && (envelope.code === void 0 || envelope.code === 0) && (envelope.data === void 0 || record$
|
|
4986
|
+
const envelope = record$9(body);
|
|
4987
|
+
const parsed = envelope !== void 0 && (envelope.code === void 0 || envelope.code === 0) && (envelope.data === void 0 || record$9(envelope.data) !== void 0) ? parseGrant(body, this.now()) : void 0;
|
|
4988
4988
|
if (parsed === void 0) {
|
|
4989
4989
|
answer(502, "VibeDev", failurePage({
|
|
4990
4990
|
...this.attempt,
|
|
@@ -5169,7 +5169,7 @@ const ENDPOINT = {
|
|
|
5169
5169
|
"openai-responses": "/v1/responses",
|
|
5170
5170
|
"openai-completions": "/v1/chat/completions"
|
|
5171
5171
|
};
|
|
5172
|
-
const record$
|
|
5172
|
+
const record$8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
5173
5173
|
const strings$1 = (value) => Array.isArray(value) && value.every((item) => typeof item === "string") ? value : void 0;
|
|
5174
5174
|
const positive$2 = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : void 0;
|
|
5175
5175
|
const price$1 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
@@ -5223,15 +5223,15 @@ function reasoningLevelsOf(value) {
|
|
|
5223
5223
|
* @returns the chat models, in catalog order; entries that are not chat models or cannot be called are left out.
|
|
5224
5224
|
*/
|
|
5225
5225
|
function parseCatalog(body) {
|
|
5226
|
-
const list = Array.isArray(body) ? body : record$
|
|
5226
|
+
const list = Array.isArray(body) ? body : record$8(body)?.data;
|
|
5227
5227
|
if (!Array.isArray(list)) return [];
|
|
5228
5228
|
const models = [];
|
|
5229
5229
|
const seen = /* @__PURE__ */ new Set();
|
|
5230
5230
|
for (const raw of list) {
|
|
5231
|
-
const entry = record$
|
|
5231
|
+
const entry = record$8(raw);
|
|
5232
5232
|
const id = typeof entry?.id === "string" ? entry.id.trim() : "";
|
|
5233
5233
|
if (entry === void 0 || id === "" || seen.has(id)) continue;
|
|
5234
|
-
const capabilities = record$
|
|
5234
|
+
const capabilities = record$8(entry.capabilities);
|
|
5235
5235
|
if (capabilities === void 0) continue;
|
|
5236
5236
|
if (typeof entry.media_type === "string" && entry.media_type !== "") continue;
|
|
5237
5237
|
if (typeof entry.internal_role === "string" && entry.internal_role !== "") continue;
|
|
@@ -6373,6 +6373,219 @@ async function* toStreamChunks(events, contextWindow, callerSignal, requestedMod
|
|
|
6373
6373
|
throw new LlmError("pi-ai event stream ended without done/error", "STREAM_CLOSED");
|
|
6374
6374
|
}
|
|
6375
6375
|
//#endregion
|
|
6376
|
+
//#region src/llm/promotions.ts
|
|
6377
|
+
/** Where the gateway publishes the promotions; public, no credential needed. */
|
|
6378
|
+
const PROMOTIONS_PATH = "/api/v1/model-plaza/promotions";
|
|
6379
|
+
/** The catalog that names the account's own price group. */
|
|
6380
|
+
const PRICE_CONTEXT_PATH = "/v1/account/model-plaza";
|
|
6381
|
+
/** The catalog read only needs its price context, so it asks for one model. */
|
|
6382
|
+
const PRICE_CONTEXT_QUERY = "scope=platform&period=7d&sort=recommended&page=1&page_size=1";
|
|
6383
|
+
const DEFAULT_TIMEOUT_MS = 1e4;
|
|
6384
|
+
/** The same label for an English surface. */
|
|
6385
|
+
const DEFAULT_PROMOTION_BADGE_EN = "Limited-time offer";
|
|
6386
|
+
const record$7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
6387
|
+
const string = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
6388
|
+
const amount$1 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
6389
|
+
const groupId = (value) => {
|
|
6390
|
+
if (typeof value === "number" && Number.isInteger(value) && value > 0) return value;
|
|
6391
|
+
if (typeof value === "string" && /^[1-9]\d{0,18}$/.test(value)) return Number(value);
|
|
6392
|
+
};
|
|
6393
|
+
/** The instant an ISO timestamp names, or undefined when it names none. */
|
|
6394
|
+
function instant$1(value) {
|
|
6395
|
+
const text = string(value);
|
|
6396
|
+
if (text === void 0) return void 0;
|
|
6397
|
+
const parsed = Date.parse(text);
|
|
6398
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
6399
|
+
}
|
|
6400
|
+
function tier(value) {
|
|
6401
|
+
const source = record$7(value);
|
|
6402
|
+
if (source === void 0) return void 0;
|
|
6403
|
+
const prevSpendMin = amount$1(source.prev_spend_min);
|
|
6404
|
+
const discountRate = amount$1(source.discount_rate);
|
|
6405
|
+
if (prevSpendMin === void 0 || discountRate === void 0 || discountRate <= 0) return void 0;
|
|
6406
|
+
return {
|
|
6407
|
+
prevSpendMin,
|
|
6408
|
+
discountRate
|
|
6409
|
+
};
|
|
6410
|
+
}
|
|
6411
|
+
/**
|
|
6412
|
+
* One entry of the public list, or undefined when it cannot be shown safely.
|
|
6413
|
+
* @param value - one `data[]` entry of the gateway answer.
|
|
6414
|
+
* @returns the promotion with its window resolved, or undefined.
|
|
6415
|
+
*/
|
|
6416
|
+
function parsePromotion(value) {
|
|
6417
|
+
const source = record$7(value);
|
|
6418
|
+
if (source === void 0) return void 0;
|
|
6419
|
+
const model = string(source.model);
|
|
6420
|
+
const startsAt = string(source.starts_at);
|
|
6421
|
+
const endsAt = string(source.ends_at);
|
|
6422
|
+
const startsAtMs = instant$1(startsAt);
|
|
6423
|
+
const endsAtMs = instant$1(endsAt);
|
|
6424
|
+
if (model === void 0 || startsAt === void 0 || endsAt === void 0 || startsAtMs === void 0 || endsAtMs === void 0 || endsAtMs < startsAtMs) return void 0;
|
|
6425
|
+
const groupIds = Array.isArray(source.group_ids) ? source.group_ids.flatMap((item) => {
|
|
6426
|
+
const id = groupId(item);
|
|
6427
|
+
return id === void 0 ? [] : [id];
|
|
6428
|
+
}) : [];
|
|
6429
|
+
if (groupIds.length === 0) return void 0;
|
|
6430
|
+
const dailyCap = amount$1(source.daily_cap);
|
|
6431
|
+
const tiers = Array.isArray(source.tiers) ? source.tiers.flatMap((item) => {
|
|
6432
|
+
const parsed = tier(item);
|
|
6433
|
+
return parsed === void 0 ? [] : [parsed];
|
|
6434
|
+
}) : [];
|
|
6435
|
+
return {
|
|
6436
|
+
model,
|
|
6437
|
+
badge: string(source.badge) ?? "限时特惠",
|
|
6438
|
+
description: string(source.description) ?? "",
|
|
6439
|
+
...dailyCap === void 0 || dailyCap === 0 ? {} : { dailyCap },
|
|
6440
|
+
startsAt,
|
|
6441
|
+
endsAt,
|
|
6442
|
+
startsAtMs,
|
|
6443
|
+
endsAtMs,
|
|
6444
|
+
tiers: tiers.sort((left, right) => left.prevSpendMin - right.prevSpendMin),
|
|
6445
|
+
groupIds
|
|
6446
|
+
};
|
|
6447
|
+
}
|
|
6448
|
+
/** The selector label for one promotion, with an English surface covered too. */
|
|
6449
|
+
function promotionBadge(promotion) {
|
|
6450
|
+
return {
|
|
6451
|
+
text: {
|
|
6452
|
+
en: DEFAULT_PROMOTION_BADGE_EN,
|
|
6453
|
+
zh: promotion.badge
|
|
6454
|
+
},
|
|
6455
|
+
tone: "warning"
|
|
6456
|
+
};
|
|
6457
|
+
}
|
|
6458
|
+
/** What a parsed answer keeps: the promotion without its bookkeeping fields. */
|
|
6459
|
+
function visible(source) {
|
|
6460
|
+
return {
|
|
6461
|
+
model: source.model,
|
|
6462
|
+
badge: source.badge,
|
|
6463
|
+
description: source.description,
|
|
6464
|
+
...source.dailyCap === void 0 ? {} : { dailyCap: source.dailyCap },
|
|
6465
|
+
startsAt: source.startsAt,
|
|
6466
|
+
endsAt: source.endsAt,
|
|
6467
|
+
tiers: source.tiers
|
|
6468
|
+
};
|
|
6469
|
+
}
|
|
6470
|
+
/**
|
|
6471
|
+
* Reads the promotions, narrows them to the account's price group and answers
|
|
6472
|
+
* from a five-minute cache. Every failure answers "none", never an error.
|
|
6473
|
+
*/
|
|
6474
|
+
var PromotionService = class {
|
|
6475
|
+
options;
|
|
6476
|
+
value;
|
|
6477
|
+
group;
|
|
6478
|
+
loadedAt = 0;
|
|
6479
|
+
failedAt;
|
|
6480
|
+
inflight;
|
|
6481
|
+
now;
|
|
6482
|
+
cacheMs;
|
|
6483
|
+
failureTtlMs;
|
|
6484
|
+
timeoutMs;
|
|
6485
|
+
constructor(options) {
|
|
6486
|
+
this.options = options;
|
|
6487
|
+
this.now = options.now ?? Date.now;
|
|
6488
|
+
this.cacheMs = options.cacheMs ?? 3e5;
|
|
6489
|
+
this.failureTtlMs = options.failureTtlMs ?? 6e4;
|
|
6490
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
6491
|
+
}
|
|
6492
|
+
/** The last resolved promotions; empty until a read succeeds. */
|
|
6493
|
+
snapshot() {
|
|
6494
|
+
return this.value ?? [];
|
|
6495
|
+
}
|
|
6496
|
+
/** The price group the last successful read used, when it knew one. */
|
|
6497
|
+
snapshotGroup() {
|
|
6498
|
+
return this.group;
|
|
6499
|
+
}
|
|
6500
|
+
/**
|
|
6501
|
+
* Forget what was read, because the account it was read for changed. The next
|
|
6502
|
+
* listing reads again for the group that account belongs to.
|
|
6503
|
+
*/
|
|
6504
|
+
reset() {
|
|
6505
|
+
this.value = void 0;
|
|
6506
|
+
this.group = void 0;
|
|
6507
|
+
this.loadedAt = 0;
|
|
6508
|
+
this.failedAt = void 0;
|
|
6509
|
+
}
|
|
6510
|
+
/** Start the first read without waiting for anyone who lists models. */
|
|
6511
|
+
warm() {
|
|
6512
|
+
this.current().catch(() => void 0);
|
|
6513
|
+
}
|
|
6514
|
+
/**
|
|
6515
|
+
* The promotions that currently apply, from the cache when it is fresh.
|
|
6516
|
+
* @returns the applicable promotions, or none when they cannot be read.
|
|
6517
|
+
*/
|
|
6518
|
+
async current() {
|
|
6519
|
+
const now = this.now();
|
|
6520
|
+
if (this.value !== void 0 && now - this.loadedAt < this.cacheMs) return this.value;
|
|
6521
|
+
if (this.failedAt !== void 0 && now - this.failedAt < this.failureTtlMs) return this.value ?? [];
|
|
6522
|
+
if (this.inflight !== void 0) return this.inflight;
|
|
6523
|
+
const read = this.load().then((value) => {
|
|
6524
|
+
this.value = value;
|
|
6525
|
+
this.loadedAt = this.now();
|
|
6526
|
+
this.failedAt = void 0;
|
|
6527
|
+
return value;
|
|
6528
|
+
}, () => {
|
|
6529
|
+
this.failedAt = this.now();
|
|
6530
|
+
return this.value ?? [];
|
|
6531
|
+
}).finally(() => {
|
|
6532
|
+
this.inflight = void 0;
|
|
6533
|
+
});
|
|
6534
|
+
this.inflight = read;
|
|
6535
|
+
return read;
|
|
6536
|
+
}
|
|
6537
|
+
/**
|
|
6538
|
+
* Like {@link current}, but a read that has not finished in time answers from
|
|
6539
|
+
* the last snapshot, so a listing is never held up by a slow gateway.
|
|
6540
|
+
* @param ms - how long a caller is willing to wait.
|
|
6541
|
+
* @returns the promotions, or the last known ones.
|
|
6542
|
+
*/
|
|
6543
|
+
async currentWithin(ms) {
|
|
6544
|
+
if (this.value !== void 0 && this.now() - this.loadedAt < this.cacheMs) return this.value;
|
|
6545
|
+
const timer = { id: void 0 };
|
|
6546
|
+
const bounded = new Promise((resolve) => {
|
|
6547
|
+
timer.id = setTimeout(() => resolve(this.snapshot()), ms);
|
|
6548
|
+
timer.id.unref?.();
|
|
6549
|
+
});
|
|
6550
|
+
try {
|
|
6551
|
+
return await Promise.race([this.current(), bounded]);
|
|
6552
|
+
} finally {
|
|
6553
|
+
if (timer.id !== void 0) clearTimeout(timer.id);
|
|
6554
|
+
}
|
|
6555
|
+
}
|
|
6556
|
+
/** One read: the account's group, the public list, then the activity window. */
|
|
6557
|
+
async load() {
|
|
6558
|
+
const group = await this.priceGroup();
|
|
6559
|
+
if (group === void 0) return [];
|
|
6560
|
+
this.group = group;
|
|
6561
|
+
const list = await this.list();
|
|
6562
|
+
const now = this.now();
|
|
6563
|
+
return list.filter((entry) => entry.groupIds.includes(group) && now >= entry.startsAtMs && now <= entry.endsAtMs).map(visible);
|
|
6564
|
+
}
|
|
6565
|
+
/** The pricing group the account center already prices this account with. */
|
|
6566
|
+
async priceGroup() {
|
|
6567
|
+
const answer = record$7(await this.options.http.json(`${PRICE_CONTEXT_PATH}?${PRICE_CONTEXT_QUERY}`, {
|
|
6568
|
+
timeoutMs: this.timeoutMs,
|
|
6569
|
+
busyRetries: 0
|
|
6570
|
+
}));
|
|
6571
|
+
const data = record$7(answer?.data) ?? answer;
|
|
6572
|
+
return groupId(record$7(data?.price_context)?.group_id);
|
|
6573
|
+
}
|
|
6574
|
+
/** The public list. `anonymous` keeps a signed-out or broken sign-in from changing the answer. */
|
|
6575
|
+
async list() {
|
|
6576
|
+
const data = record$7(await this.options.http.json(PROMOTIONS_PATH, {
|
|
6577
|
+
anonymous: true,
|
|
6578
|
+
timeoutMs: this.timeoutMs,
|
|
6579
|
+
busyRetries: 0
|
|
6580
|
+
}))?.data;
|
|
6581
|
+
if (!Array.isArray(data)) return [];
|
|
6582
|
+
return data.flatMap((item) => {
|
|
6583
|
+
const parsed = parsePromotion(item);
|
|
6584
|
+
return parsed === void 0 ? [] : [parsed];
|
|
6585
|
+
});
|
|
6586
|
+
}
|
|
6587
|
+
};
|
|
6588
|
+
//#endregion
|
|
6376
6589
|
//#region src/llm/cache-ttl.ts
|
|
6377
6590
|
/** Anthropic cache retention changes only existing cache-control markers in serialized content. */
|
|
6378
6591
|
const CLAUDE_CACHE_TTLS = [
|
|
@@ -6486,6 +6699,8 @@ function _usingCtx() {
|
|
|
6486
6699
|
const SIGN_IN_REQUIRED_CODE = "VIBEDEV_SIGN_IN_REQUIRED";
|
|
6487
6700
|
/** Failure code for a used-up balance; not the Harness's `ACCOUNT_QUOTA`, which opens the DeepSeek top-up. */
|
|
6488
6701
|
const INSUFFICIENT_BALANCE_CODE = "VIBEDEV_INSUFFICIENT_BALANCE";
|
|
6702
|
+
/** No promotions apply, shared so an unlabelled listing allocates nothing. */
|
|
6703
|
+
const NO_PROMOTIONS = /* @__PURE__ */ new Map();
|
|
6489
6704
|
/** What a person reads when a VibeDev model is used before signing in. */
|
|
6490
6705
|
const SIGN_IN_MESSAGE = "请先登录 VibeDev:在侧边栏底部「登录 VibeDev」或「设置 → VibeDev 账号」中登录后即可使用这些模型。 Sign in to VibeDev (sidebar, or Settings → VibeDev account) to use these models.";
|
|
6491
6706
|
/** What a person reads when the gateway ended the sign-in and a refresh could not renew it. */
|
|
@@ -6602,12 +6817,31 @@ var GatewayAdapter = class extends LlmAdapter {
|
|
|
6602
6817
|
if (this.current().catalog.length === 0) await this.config.refreshCatalog?.();
|
|
6603
6818
|
const listed = this.current().models.getModels(provider);
|
|
6604
6819
|
const hideRelay = provider === this.config.provider && this.config.relayProvider !== void 0;
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6820
|
+
const promotions = await this.promotions();
|
|
6821
|
+
return listed.filter((model) => !hideRelay || !relayIdentity(model.id).relay).map((model) => {
|
|
6822
|
+
const promotion = promotions.get(model.id);
|
|
6823
|
+
return {
|
|
6824
|
+
provider,
|
|
6825
|
+
id: model.id,
|
|
6826
|
+
name: model.name,
|
|
6827
|
+
inputModalities: [...model.input],
|
|
6828
|
+
...promotion === void 0 ? {} : {
|
|
6829
|
+
badge: promotionBadge(promotion),
|
|
6830
|
+
description: promotion.description
|
|
6831
|
+
}
|
|
6832
|
+
};
|
|
6833
|
+
});
|
|
6834
|
+
}
|
|
6835
|
+
/** The promotions keyed by model id, or none when they cannot be read. */
|
|
6836
|
+
async promotions() {
|
|
6837
|
+
const read = this.config.promotions;
|
|
6838
|
+
if (read === void 0) return NO_PROMOTIONS;
|
|
6839
|
+
try {
|
|
6840
|
+
const list = await read();
|
|
6841
|
+
return list.length === 0 ? NO_PROMOTIONS : new Map(list.map((entry) => [entry.model, entry]));
|
|
6842
|
+
} catch {
|
|
6843
|
+
return NO_PROMOTIONS;
|
|
6844
|
+
}
|
|
6611
6845
|
}
|
|
6612
6846
|
resolveModel(provider, model, _signal) {
|
|
6613
6847
|
return Promise.resolve().then(() => this.modelInfo(this.current(), provider, model));
|
|
@@ -6956,7 +7190,8 @@ function installGatewayModels(ctx, options) {
|
|
|
6956
7190
|
onReplayDegrade: ({ provider, model, reason }) => {
|
|
6957
7191
|
ctx.logger.warn(`dsh-vibedev: unusable replay state on assistant history for "${provider}/${model}"; sending provider-neutral content (${reason})`);
|
|
6958
7192
|
},
|
|
6959
|
-
...options.onRequestEnded === void 0 ? {} : { onRequestEnded: options.onRequestEnded }
|
|
7193
|
+
...options.onRequestEnded === void 0 ? {} : { onRequestEnded: options.onRequestEnded },
|
|
7194
|
+
...options.promotions === void 0 ? {} : { promotions: options.promotions }
|
|
6960
7195
|
});
|
|
6961
7196
|
const registration = ctx.llm.registerAdapter([VIBEDEV_ROUTE, VIBEDEV_RELAY_ROUTE], adapter);
|
|
6962
7197
|
ctx.inject(["settings"], (child) => {
|
|
@@ -7076,6 +7311,47 @@ function installGatewayModels(ctx, options) {
|
|
|
7076
7311
|
};
|
|
7077
7312
|
}
|
|
7078
7313
|
//#endregion
|
|
7314
|
+
//#region src/account/promotions.ts
|
|
7315
|
+
/** The Host route the model page reads. */
|
|
7316
|
+
const PROMOTIONS_ROUTE = "/api/dsh-vibedev/promotions";
|
|
7317
|
+
/** How long the page waits for a promotion answer before showing prices without labels. */
|
|
7318
|
+
const ROUTE_WAIT_MS = 2e3;
|
|
7319
|
+
const answer = (body) => new Response(JSON.stringify(body), {
|
|
7320
|
+
status: 200,
|
|
7321
|
+
headers: {
|
|
7322
|
+
"content-type": "application/json",
|
|
7323
|
+
"cache-control": "no-store"
|
|
7324
|
+
}
|
|
7325
|
+
});
|
|
7326
|
+
/**
|
|
7327
|
+
* The Host routes that serve promotion labels to the account pages.
|
|
7328
|
+
* @param promotions - the shared service the model list labels from too.
|
|
7329
|
+
* @returns the routes to register on the connection.
|
|
7330
|
+
*/
|
|
7331
|
+
function promotionRoutes(promotions) {
|
|
7332
|
+
return [{
|
|
7333
|
+
path: PROMOTIONS_ROUTE,
|
|
7334
|
+
methods: ["GET"],
|
|
7335
|
+
requestBody: "buffered",
|
|
7336
|
+
fetch: async () => {
|
|
7337
|
+
let items = [];
|
|
7338
|
+
try {
|
|
7339
|
+
items = await promotions.currentWithin(ROUTE_WAIT_MS);
|
|
7340
|
+
} catch {
|
|
7341
|
+
items = [];
|
|
7342
|
+
}
|
|
7343
|
+
const group = promotions.snapshotGroup();
|
|
7344
|
+
return answer({
|
|
7345
|
+
code: 0,
|
|
7346
|
+
data: {
|
|
7347
|
+
items,
|
|
7348
|
+
...group === void 0 ? {} : { group_id: group }
|
|
7349
|
+
}
|
|
7350
|
+
});
|
|
7351
|
+
}
|
|
7352
|
+
}];
|
|
7353
|
+
}
|
|
7354
|
+
//#endregion
|
|
7079
7355
|
//#region src/gateway/assets.ts
|
|
7080
7356
|
/**
|
|
7081
7357
|
* The gateway media library (`/v1/media-assets`): every reference a video
|
|
@@ -14987,6 +15263,11 @@ function audioTranscribeTool(runtime) {
|
|
|
14987
15263
|
*/
|
|
14988
15264
|
/** Requests that are charged: generations and transcriptions (uploads and reads are free). */
|
|
14989
15265
|
const PAID_PATH = /^\/v1\/(?:images|videos|audio)(?:\/|$)/;
|
|
15266
|
+
/**
|
|
15267
|
+
* How long a model listing waits for promotion labels before it answers without
|
|
15268
|
+
* them. A picker must never wait on decoration.
|
|
15269
|
+
*/
|
|
15270
|
+
const PROMOTION_LIST_WAIT_MS = 1500;
|
|
14990
15271
|
/** The package version, sent in the `User-Agent` the gateway attributes plugin traffic by. */
|
|
14991
15272
|
const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
14992
15273
|
const name = "dsh-vibedev";
|
|
@@ -15115,6 +15396,8 @@ function apply(ctx, config) {
|
|
|
15115
15396
|
if (method === "POST" && PAID_PATH.test(path)) spent();
|
|
15116
15397
|
}
|
|
15117
15398
|
});
|
|
15399
|
+
const promotions = new PromotionService({ http });
|
|
15400
|
+
promotions.warm();
|
|
15118
15401
|
const store = new TaskStore(gatewayStateDirectory(stateDir, origin), Date.now, async () => {
|
|
15119
15402
|
const identity = await account?.identity();
|
|
15120
15403
|
if (identity?.signedIn === true && identity.userId !== void 0) return `${origin}\nuser:${identity.userId}`;
|
|
@@ -15203,7 +15486,8 @@ function apply(ctx, config) {
|
|
|
15203
15486
|
preferredModels: () => config.preferredModels,
|
|
15204
15487
|
onCredentialChange: (listener) => login.onChange(listener),
|
|
15205
15488
|
catalogRefreshMinutes: config.catalogRefreshMinutes,
|
|
15206
|
-
onRequestEnded: spent
|
|
15489
|
+
onRequestEnded: spent,
|
|
15490
|
+
promotions: () => promotions.currentWithin(PROMOTION_LIST_WAIT_MS)
|
|
15207
15491
|
});
|
|
15208
15492
|
llmCtx.effect(() => () => {
|
|
15209
15493
|
route = void 0;
|
|
@@ -15277,6 +15561,7 @@ function apply(ctx, config) {
|
|
|
15277
15561
|
http,
|
|
15278
15562
|
account: accountService
|
|
15279
15563
|
}),
|
|
15564
|
+
...promotionRoutes(promotions),
|
|
15280
15565
|
...latencyRoutes(latency)
|
|
15281
15566
|
]) scoped.effect(() => scoped.connection.fetch.register(accountRoute), `dsh-vibedev: ${accountRoute.path}`);
|
|
15282
15567
|
});
|
|
@@ -15299,6 +15584,7 @@ function apply(ctx, config) {
|
|
|
15299
15584
|
const unsubscribe = login.onChange(() => {
|
|
15300
15585
|
runtime.invalidateCatalog();
|
|
15301
15586
|
accountService.credentialChanged();
|
|
15587
|
+
promotions.reset();
|
|
15302
15588
|
tracker.resume().catch(() => void 0);
|
|
15303
15589
|
});
|
|
15304
15590
|
return async () => {
|