@vibedev-si/dsh-vibedev 0.11.2 → 0.11.4
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 +54 -1
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/client/client.account-center.js +1341 -9
- package/client/client.js +175 -2
- package/lib/account/center-contract.d.ts +2 -0
- package/lib/account/voice-profile-routes.d.ts +33 -0
- package/lib/audio/request.d.ts +53 -3
- package/lib/audio/voice-profiles.d.ts +207 -0
- package/lib/contracts.d.ts +2 -2
- package/lib/gateway/catalog.d.ts +5 -0
- package/lib/gateway/paid-path.d.ts +11 -0
- package/lib/index.js +1333 -237
- package/lib/tools/voice-profiles.d.ts +30 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -50,8 +50,8 @@ const MIN_READ_SPACING_MS = 5e3;
|
|
|
50
50
|
* current when nobody opens anything.
|
|
51
51
|
*/
|
|
52
52
|
const CATALOG_REFRESH_GAP_MS = 6e4;
|
|
53
|
-
const record$
|
|
54
|
-
const text$
|
|
53
|
+
const record$17 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
54
|
+
const text$10 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
55
55
|
/**
|
|
56
56
|
* A gateway amount as plain decimal text: a number as JavaScript writes it (`99976091.91426945`; the few numbers it
|
|
57
57
|
* writes with an exponent are spelled out), a string as sent; anything else, or text that is not a plain decimal, is
|
|
@@ -63,7 +63,7 @@ function amountOf(value) {
|
|
|
63
63
|
if (!Number.isFinite(value)) return void 0;
|
|
64
64
|
raw = String(value);
|
|
65
65
|
if (raw.includes("e")) raw = Math.abs(value) >= 1 ? BigInt(value).toString() : value.toFixed(20).replace(/0+$/, "").replace(/\.$/, "");
|
|
66
|
-
} else raw = text$
|
|
66
|
+
} else raw = text$10(value);
|
|
67
67
|
return raw !== void 0 && /^-?\d+(\.\d+)?$/.test(raw) ? raw : void 0;
|
|
68
68
|
}
|
|
69
69
|
/** What a read showed, for telling whether the next one changed anything (when it was read is not a change). */
|
|
@@ -305,14 +305,14 @@ var AccountService = class {
|
|
|
305
305
|
redirect: "error"
|
|
306
306
|
});
|
|
307
307
|
if (!response.ok) return {};
|
|
308
|
-
const body = record$
|
|
309
|
-
const data = record$
|
|
308
|
+
const body = record$17(await response.json().catch(() => void 0));
|
|
309
|
+
const data = record$17(body?.data) ?? body;
|
|
310
310
|
const balance = amountOf(data?.balance);
|
|
311
|
-
const currency = text$
|
|
311
|
+
const currency = text$10(data?.currency) ?? "CNY";
|
|
312
312
|
const frozen = amountOf(data?.frozen_balance);
|
|
313
|
-
const id = typeof data?.id === "number" ? String(data.id) : text$
|
|
314
|
-
const nickname = text$
|
|
315
|
-
const email = text$
|
|
313
|
+
const id = typeof data?.id === "number" ? String(data.id) : text$10(data?.id);
|
|
314
|
+
const nickname = text$10(data?.nickname) ?? text$10(data?.username);
|
|
315
|
+
const email = text$10(data?.email);
|
|
316
316
|
const user = id === void 0 && nickname === void 0 && email === void 0 ? void 0 : {
|
|
317
317
|
...id === void 0 ? {} : { id },
|
|
318
318
|
...email === void 0 ? {} : { email },
|
|
@@ -426,8 +426,8 @@ function json$3(status, body) {
|
|
|
426
426
|
}
|
|
427
427
|
});
|
|
428
428
|
}
|
|
429
|
-
function failure$
|
|
430
|
-
const candidate = record$
|
|
429
|
+
function failure$2(error) {
|
|
430
|
+
const candidate = record$17(error)?.code;
|
|
431
431
|
const code = candidate === "SIGN_IN_REFUSED" || candidate === "SIGN_IN_TIMEOUT" || candidate === "SIGN_IN_CANCELLED" ? candidate : "INTERNAL";
|
|
432
432
|
return json$3(500, { error: {
|
|
433
433
|
code,
|
|
@@ -446,7 +446,7 @@ function accountRoutes(account) {
|
|
|
446
446
|
methods: ["POST"],
|
|
447
447
|
requestBody: "buffered",
|
|
448
448
|
fetch: async (request) => {
|
|
449
|
-
const body = record$
|
|
449
|
+
const body = record$17(await request.json().catch(() => void 0));
|
|
450
450
|
return json$3(200, { consumed: typeof body?.id === "string" && account.consumeNavigation(body.id) });
|
|
451
451
|
}
|
|
452
452
|
},
|
|
@@ -461,7 +461,7 @@ function accountRoutes(account) {
|
|
|
461
461
|
if (since !== null && /^\d{1,15}$/.test(since)) await account.wait(Number(since), request.signal);
|
|
462
462
|
return json$3(200, await account.view(query.get("fresh") === "1"));
|
|
463
463
|
} catch (error) {
|
|
464
|
-
return failure$
|
|
464
|
+
return failure$2(error);
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
},
|
|
@@ -471,10 +471,10 @@ function accountRoutes(account) {
|
|
|
471
471
|
requestBody: "buffered",
|
|
472
472
|
fetch: async (request) => {
|
|
473
473
|
try {
|
|
474
|
-
const body = record$
|
|
474
|
+
const body = record$17(await request.json().catch(() => void 0));
|
|
475
475
|
return json$3(200, await account.signIn(body?.open !== false));
|
|
476
476
|
} catch (error) {
|
|
477
|
-
return failure$
|
|
477
|
+
return failure$2(error);
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
},
|
|
@@ -498,7 +498,7 @@ function accountRoutes(account) {
|
|
|
498
498
|
message: "The VibeDev account is the app's sign-in; sign out in the app."
|
|
499
499
|
} });
|
|
500
500
|
} catch (error) {
|
|
501
|
-
return failure$
|
|
501
|
+
return failure$2(error);
|
|
502
502
|
}
|
|
503
503
|
}
|
|
504
504
|
}
|
|
@@ -606,10 +606,10 @@ function normalizeErrorStage(value) {
|
|
|
606
606
|
request: "submit"
|
|
607
607
|
}[word];
|
|
608
608
|
}
|
|
609
|
-
function record$
|
|
609
|
+
function record$16(value) {
|
|
610
610
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
611
611
|
}
|
|
612
|
-
function text$
|
|
612
|
+
function text$9(value) {
|
|
613
613
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
614
614
|
}
|
|
615
615
|
function count$1(value) {
|
|
@@ -618,7 +618,7 @@ function count$1(value) {
|
|
|
618
618
|
/** A CNY amount the gateway sends as a two-decimal string (a number is accepted too). */
|
|
619
619
|
function amount$2(value) {
|
|
620
620
|
if (typeof value === "number" && Number.isFinite(value)) return value.toFixed(2);
|
|
621
|
-
const raw = text$
|
|
621
|
+
const raw = text$9(value);
|
|
622
622
|
return raw !== void 0 && /^-?\d+(?:\.\d+)?$/.test(raw) ? raw : void 0;
|
|
623
623
|
}
|
|
624
624
|
/**
|
|
@@ -632,16 +632,16 @@ function amount$2(value) {
|
|
|
632
632
|
* @returns the fields found.
|
|
633
633
|
*/
|
|
634
634
|
function parseGatewayFailure(body) {
|
|
635
|
-
const root = record$
|
|
635
|
+
const root = record$16(body);
|
|
636
636
|
if (root === void 0) return {};
|
|
637
|
-
const source = record$
|
|
638
|
-
const metadata = record$
|
|
639
|
-
const gatewayCode = text$
|
|
640
|
-
const code = gatewayCode ?? text$
|
|
641
|
-
const message = text$
|
|
642
|
-
const field = text$
|
|
643
|
-
const rule = text$
|
|
644
|
-
const rechargeUrl = text$
|
|
637
|
+
const source = record$16(root.error) ?? root;
|
|
638
|
+
const metadata = record$16(source.metadata) ?? record$16(root.metadata);
|
|
639
|
+
const gatewayCode = text$9(source.gateway_code) ?? text$9(root.gateway_code);
|
|
640
|
+
const code = gatewayCode ?? text$9(source.code) ?? text$9(source.type) ?? text$9(root.reason);
|
|
641
|
+
const message = text$9(source.message) ?? (typeof root.error === "string" ? text$9(root.error) : void 0);
|
|
642
|
+
const field = text$9(source.field) ?? text$9(metadata?.field);
|
|
643
|
+
const rule = text$9(source.rule) ?? text$9(metadata?.rule);
|
|
644
|
+
const rechargeUrl = text$9(source.recharge_url) ?? text$9(root.recharge_url);
|
|
645
645
|
const numbers = {
|
|
646
646
|
active: count$1(source.active),
|
|
647
647
|
limit: count$1(source.limit)
|
|
@@ -651,19 +651,19 @@ function parseGatewayFailure(body) {
|
|
|
651
651
|
availableCny: amount$2(source.available_cny),
|
|
652
652
|
pendingCny: amount$2(source.pending_cny)
|
|
653
653
|
};
|
|
654
|
-
const submissionState = text$
|
|
655
|
-
const retryAction = text$
|
|
656
|
-
const assetId = text$
|
|
654
|
+
const submissionState = text$9(source.submission_state) ?? text$9(root.submission_state);
|
|
655
|
+
const retryAction = text$9(source.retry_action) ?? text$9(root.retry_action);
|
|
656
|
+
const assetId = text$9(source.asset_id) ?? text$9(root.asset_id);
|
|
657
657
|
return {
|
|
658
658
|
...gatewayCode === void 0 ? {} : { gatewayCode },
|
|
659
659
|
...Object.fromEntries(Object.entries({
|
|
660
|
-
category: normalizeErrorCategory(text$
|
|
661
|
-
stage: normalizeErrorStage(text$
|
|
662
|
-
requestId: text$
|
|
663
|
-
taskId: text$
|
|
664
|
-
operationId: text$
|
|
665
|
-
billingState: text$
|
|
666
|
-
retryAt: text$
|
|
660
|
+
category: normalizeErrorCategory(text$9(source.category) ?? text$9(root.category), code),
|
|
661
|
+
stage: normalizeErrorStage(text$9(source.stage) ?? text$9(root.stage)),
|
|
662
|
+
requestId: text$9(source.request_id) ?? text$9(root.request_id),
|
|
663
|
+
taskId: text$9(source.task_id) ?? text$9(root.task_id),
|
|
664
|
+
operationId: text$9(source.operation_id) ?? text$9(root.operation_id),
|
|
665
|
+
billingState: text$9(source.billing_state) ?? text$9(root.billing_state),
|
|
666
|
+
retryAt: text$9(source.retry_at) ?? text$9(root.retry_at),
|
|
667
667
|
retryAfterSeconds: count$1(source.retry_after_seconds) ?? count$1(root.retry_after_seconds)
|
|
668
668
|
}).filter(([, value]) => value !== void 0)),
|
|
669
669
|
...code === void 0 ? {} : { code },
|
|
@@ -730,11 +730,11 @@ function gatewayFailureWithHeaders(body, headers) {
|
|
|
730
730
|
const failure = parseGatewayFailure(body);
|
|
731
731
|
return {
|
|
732
732
|
...failure,
|
|
733
|
-
code: failure.gatewayCode ?? text$
|
|
734
|
-
category: normalizeErrorCategory(failure.category ?? text$
|
|
735
|
-
requestId: failure.requestId ?? text$
|
|
736
|
-
retryAction: failure.retryAction ?? text$
|
|
737
|
-
retryAt: failure.retryAt ?? text$
|
|
733
|
+
code: failure.gatewayCode ?? text$9(headers.get("x-vibedev-error-code")) ?? failure.code,
|
|
734
|
+
category: normalizeErrorCategory(failure.category ?? text$9(headers.get("x-vibedev-error-category")), failure.gatewayCode ?? text$9(headers.get("x-vibedev-error-code")) ?? failure.code),
|
|
735
|
+
requestId: failure.requestId ?? text$9(headers.get("x-request-id")),
|
|
736
|
+
retryAction: failure.retryAction ?? text$9(headers.get("x-vibedev-retry-action")),
|
|
737
|
+
retryAt: failure.retryAt ?? text$9(headers.get("x-vibedev-retry-at"))
|
|
738
738
|
};
|
|
739
739
|
}
|
|
740
740
|
function isUserAuthenticationFailure(failure) {
|
|
@@ -743,19 +743,19 @@ function isUserAuthenticationFailure(failure) {
|
|
|
743
743
|
function sdkGatewayFailure(message, headers = {}) {
|
|
744
744
|
const prefix = /\bvibedev:([A-Z][A-Z0-9_]{1,100}):/.exec(message)?.[1];
|
|
745
745
|
const legacy = /["'](?:gateway_code|code)["']\s*:\s*["'](APP_TOKEN_EXPIRED|APP_TOKEN_INVALID|INVALID_API_KEY|APP_SESSION_REVOKED|SESSION_REVOKED|AUTHENTICATION_REQUIRED)["']/.exec(message)?.[1];
|
|
746
|
-
const code = text$
|
|
747
|
-
const category = text$
|
|
746
|
+
const code = text$9(headers["x-vibedev-error-code"]) ?? prefix ?? legacy;
|
|
747
|
+
const category = text$9(headers["x-vibedev-error-category"]) ?? (code === void 0 ? void 0 : /^(?:APP_TOKEN_EXPIRED|APP_TOKEN_INVALID|INVALID_API_KEY|APP_SESSION_REVOKED|SESSION_REVOKED|AUTHENTICATION_REQUIRED)$/.test(code) ? "authentication" : /^(?:BALANCE_INSUFFICIENT|SUBSCRIPTION_QUOTA_EXHAUSTED|MODEL_NOT_INCLUDED|BILLING_SOURCE_UNAVAILABLE)$/.test(code) ? "billing" : code === "CONTENT_REJECTED" ? "content_rejected" : code === "SUBMISSION_UNCERTAIN" ? "submission_uncertain" : /^(?:UPSTREAM_UNAVAILABLE|TASK_QUERY_UNAVAILABLE|RESULT_DOWNLOAD_UNAVAILABLE)$/.test(code) ? "service_unavailable" : "internal_error");
|
|
748
748
|
if (code === void 0 && category === void 0) return void 0;
|
|
749
749
|
return {
|
|
750
750
|
code,
|
|
751
751
|
category: normalizeErrorCategory(category, code),
|
|
752
|
-
requestId: text$
|
|
753
|
-
retryAction: text$
|
|
752
|
+
requestId: text$9(headers["x-request-id"]),
|
|
753
|
+
retryAction: text$9(headers["x-vibedev-retry-action"])
|
|
754
754
|
};
|
|
755
755
|
}
|
|
756
756
|
//#endregion
|
|
757
757
|
//#region src/account/center-price-contract.ts
|
|
758
|
-
const record$
|
|
758
|
+
const record$15 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
759
759
|
const keys = (value = "") => value.split(" ").filter(Boolean);
|
|
760
760
|
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;
|
|
761
761
|
/** Only public DNS HTTPS references become navigable links. No credentials, IPs or local hosts. */
|
|
@@ -773,7 +773,7 @@ function publicReferenceUrl(value) {
|
|
|
773
773
|
}
|
|
774
774
|
function project$1(value, shape) {
|
|
775
775
|
if (value === null) return null;
|
|
776
|
-
const source = record$
|
|
776
|
+
const source = record$15(value);
|
|
777
777
|
if (!source) return void 0;
|
|
778
778
|
const out = {};
|
|
779
779
|
for (const key of keys(shape.fields)) {
|
|
@@ -801,7 +801,7 @@ function project$1(value, shape) {
|
|
|
801
801
|
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);
|
|
802
802
|
}
|
|
803
803
|
for (const [key, child] of Object.entries(shape.maps ?? {})) {
|
|
804
|
-
const map = record$
|
|
804
|
+
const map = record$15(source[key]);
|
|
805
805
|
if (!map) continue;
|
|
806
806
|
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" || [
|
|
807
807
|
"none",
|
|
@@ -1629,11 +1629,11 @@ function projectBusinessReceipt(value) {
|
|
|
1629
1629
|
//#endregion
|
|
1630
1630
|
//#region src/account/center-contract.ts
|
|
1631
1631
|
/** Exact, read-only account-page schemas. No caller-selected URL or object shape. */
|
|
1632
|
-
const record$
|
|
1632
|
+
const record$14 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1633
1633
|
const fields = (text) => text.split(" ");
|
|
1634
1634
|
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;
|
|
1635
1635
|
function project(value, shape) {
|
|
1636
|
-
const source = record$
|
|
1636
|
+
const source = record$14(value);
|
|
1637
1637
|
if (source === void 0) return void 0;
|
|
1638
1638
|
if (shape === imageSizes) return Object.fromEntries(Object.entries(source).filter(([key, item]) => {
|
|
1639
1639
|
const kilo = /^(\d{1,2}(?:\.\d{1,3})?)K$/.exec(key), dimensions = /^(\d{1,5})x(\d{1,5})$/.exec(key);
|
|
@@ -1646,7 +1646,7 @@ function project(value, shape) {
|
|
|
1646
1646
|
"inbound_endpoint",
|
|
1647
1647
|
"upstream_endpoint",
|
|
1648
1648
|
"endpoint"
|
|
1649
|
-
].includes(key) && (typeof item !== "string" || !
|
|
1649
|
+
].includes(key) && (typeof item !== "string" || !safeEndpoint(item))) continue;
|
|
1650
1650
|
if (item !== void 0) result[key] = item;
|
|
1651
1651
|
}
|
|
1652
1652
|
for (const [key, child] of Object.entries(shape.objects ?? {})) {
|
|
@@ -1656,7 +1656,13 @@ function project(value, shape) {
|
|
|
1656
1656
|
for (const [key, child] of Object.entries(shape.arrays ?? {})) if (Array.isArray(source[key])) result[key] = source[key].slice(0, 1e3).map((item) => child === "scalar" ? scalar(item) : project(item, child)).filter((item) => item !== void 0);
|
|
1657
1657
|
return result;
|
|
1658
1658
|
}
|
|
1659
|
-
const SAFE_ENDPOINTS = new Set(fields("/v1/systemone /v1/completions /v1/alpha/search /v1/responses/compact /v1/responses/input_tokens /v1/images/tasks /v1/videos/generations /v1/videos/edits /v1/videos/extensions /v1beta/models /v1beta/cachedContents /v1internal:streamGenerateContent /v1/messages /v1/messages/count_tokens /v1/chat/completions /v1/responses /v1/embeddings /v1/images/generations /v1/images/edits /v1/videos /v1/audio/speech /v1/audio/transcriptions /v1/audio/translations /v1/realtime /messages /messages/count_tokens /chat/completions /responses /embeddings /images/generations /images/edits /videos /tts /stt /realtime /alpha/search /v3/contents/generations/tasks /api/v3/contents/generations/tasks /v1/contents/generations/tasks"));
|
|
1659
|
+
const SAFE_ENDPOINTS = new Set(fields("/v1/systemone /v1/completions /v1/alpha/search /v1/responses/compact /v1/responses/input_tokens /v1/images/tasks /v1/videos/generations /v1/videos/edits /v1/videos/extensions /v1beta/models /v1beta/cachedContents /v1internal:streamGenerateContent /v1/messages /v1/messages/count_tokens /v1/chat/completions /v1/responses /v1/embeddings /v1/images/generations /v1/images/edits /v1/videos /v1/audio/speech /v1/audio/transcriptions /v1/audio/translations /v1/realtime /messages /messages/count_tokens /chat/completions /responses /embeddings /images/generations /images/edits /videos /tts /stt /realtime /alpha/search /v3/contents/generations/tasks /api/v3/contents/generations/tasks /v1/contents/generations/tasks /v1/audio/voice-profiles /v1/audio/voice-profiles/:id /v1/audio/voice-profiles/{id}"));
|
|
1660
|
+
/** Voice profiles (`GET`/`POST /v1/audio/voice-profiles`, `DELETE /v1/audio/voice-profiles/{id}`): the route template above, or a concrete `vp_…` id. */
|
|
1661
|
+
const VOICE_PROFILE_ENDPOINT = /^\/v1\/audio\/voice-profiles\/vp_[A-Za-z0-9_-]{1,120}$/;
|
|
1662
|
+
/** An endpoint a usage or error row may show. */
|
|
1663
|
+
function safeEndpoint(value) {
|
|
1664
|
+
return SAFE_ENDPOINTS.has(value) || VOICE_PROFILE_ENDPOINT.test(value);
|
|
1665
|
+
}
|
|
1660
1666
|
const imageSizes = { fields: [] };
|
|
1661
1667
|
const group = { fields: fields("id name platform description status subscription_type rate_multiplier peak_rate_enabled peak_start peak_end peak_rate_multiplier") };
|
|
1662
1668
|
const window = { fields: fields("state remaining_percent resets_at") };
|
|
@@ -1888,7 +1894,7 @@ function centerQuery(path, params) {
|
|
|
1888
1894
|
/** Legacy summary only: monetary weekly fields become a percentage, never a five-hour window. */
|
|
1889
1895
|
function projectAccountData(value) {
|
|
1890
1896
|
const convert = (item) => {
|
|
1891
|
-
const output = project(item, subscription), source = record$
|
|
1897
|
+
const output = project(item, subscription), source = record$14(item);
|
|
1892
1898
|
if (output === void 0 || source === void 0) return void 0;
|
|
1893
1899
|
const number = (n) => typeof n === "number" && Number.isFinite(n) ? n : typeof n === "string" && /^\d+(?:\.\d+)?$/.test(n) ? Number(n) : void 0;
|
|
1894
1900
|
const used = number(source.weekly_used_usd), limit = number(source.weekly_limit_usd);
|
|
@@ -1900,7 +1906,7 @@ function projectAccountData(value) {
|
|
|
1900
1906
|
return output;
|
|
1901
1907
|
};
|
|
1902
1908
|
if (Array.isArray(value)) return value.slice(0, 1e3).map(convert).filter((item) => item !== void 0);
|
|
1903
|
-
const source = record$
|
|
1909
|
+
const source = record$14(value);
|
|
1904
1910
|
return source === void 0 ? {} : {
|
|
1905
1911
|
...project(source, { fields: ["active_count"] }),
|
|
1906
1912
|
...Array.isArray(source.subscriptions) ? { subscriptions: source.subscriptions.slice(0, 1e3).map(convert).filter((item) => item !== void 0) } : {}
|
|
@@ -1936,14 +1942,14 @@ function projectCenterRoute(path, value) {
|
|
|
1936
1942
|
//#endregion
|
|
1937
1943
|
//#region src/account/center-business.ts
|
|
1938
1944
|
const object$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1939
|
-
const answer$
|
|
1945
|
+
const answer$3 = (status, body) => new Response(JSON.stringify(body), {
|
|
1940
1946
|
status,
|
|
1941
1947
|
headers: {
|
|
1942
1948
|
"content-type": "application/json; charset=utf-8",
|
|
1943
1949
|
"cache-control": "private, no-store"
|
|
1944
1950
|
}
|
|
1945
1951
|
});
|
|
1946
|
-
const failure = (status, code, notSubmitted, extra = {}) => answer$
|
|
1952
|
+
const failure$1 = (status, code, notSubmitted, extra = {}) => answer$3(status, {
|
|
1947
1953
|
...extra,
|
|
1948
1954
|
...notSubmitted ? { not_submitted: true } : {},
|
|
1949
1955
|
error: {
|
|
@@ -1951,7 +1957,7 @@ const failure = (status, code, notSubmitted, extra = {}) => answer$2(status, {
|
|
|
1951
1957
|
category: code === "INVALID_INPUT" ? "invalid_input" : code === "ACCOUNT_CHANGED" ? "access_restricted" : "service_unavailable"
|
|
1952
1958
|
}
|
|
1953
1959
|
});
|
|
1954
|
-
const sameAccount$
|
|
1960
|
+
const sameAccount$2 = (a, b) => a.signedIn && b.signedIn && a.userId !== void 0 && a.userId === b.userId;
|
|
1955
1961
|
/** The buffered wire body must be unambiguous before it is canonicalized and fingerprinted. */
|
|
1956
1962
|
function uniqueBusinessJson(raw) {
|
|
1957
1963
|
if (Buffer.byteLength(raw, "utf8") > 1 << 20) throw new Error("body too large");
|
|
@@ -1986,29 +1992,29 @@ function accountBusinessActionsRoutes(http, account) {
|
|
|
1986
1992
|
let before, dispatched = false;
|
|
1987
1993
|
const stillCurrent = async () => {
|
|
1988
1994
|
try {
|
|
1989
|
-
return before !== void 0 && sameAccount$
|
|
1995
|
+
return before !== void 0 && sameAccount$2(before, await account.identity());
|
|
1990
1996
|
} catch {
|
|
1991
1997
|
return false;
|
|
1992
1998
|
}
|
|
1993
1999
|
};
|
|
1994
2000
|
try {
|
|
1995
|
-
if (new URL(request.url, "http://host").search !== "") return failure(400, "INVALID_INPUT", true);
|
|
2001
|
+
if (new URL(request.url, "http://host").search !== "") return failure$1(400, "INVALID_INPUT", true);
|
|
1996
2002
|
let body;
|
|
1997
2003
|
try {
|
|
1998
2004
|
body = object$2(uniqueBusinessJson(await request.text()));
|
|
1999
2005
|
} catch {
|
|
2000
|
-
return failure(400, "INVALID_INPUT", true);
|
|
2006
|
+
return failure$1(400, "INVALID_INPUT", true);
|
|
2001
2007
|
}
|
|
2002
2008
|
if (body === void 0 || Object.keys(body).some((key) => ![
|
|
2003
2009
|
"operation_id",
|
|
2004
2010
|
"expected_user_id",
|
|
2005
2011
|
"payload"
|
|
2006
|
-
].includes(key)) || !validOperationId(body.operation_id) || typeof body.expected_user_id !== "string") return failure(400, "INVALID_INPUT", true);
|
|
2012
|
+
].includes(key)) || !validOperationId(body.operation_id) || typeof body.expected_user_id !== "string") return failure$1(400, "INVALID_INPUT", true);
|
|
2007
2013
|
const parsed = validateBusinessAction(kind, body.payload);
|
|
2008
|
-
if (parsed === void 0) return failure(400, "INVALID_INPUT", true);
|
|
2014
|
+
if (parsed === void 0) return failure$1(400, "INVALID_INPUT", true);
|
|
2009
2015
|
before = await account.identity();
|
|
2010
|
-
if (!before.signedIn || before.userId === void 0) return failure(401, "ACCOUNT_UNAVAILABLE", true);
|
|
2011
|
-
if (before.userId !== body.expected_user_id) return failure(409, "ACCOUNT_CHANGED", true);
|
|
2016
|
+
if (!before.signedIn || before.userId === void 0) return failure$1(401, "ACCOUNT_UNAVAILABLE", true);
|
|
2017
|
+
if (before.userId !== body.expected_user_id) return failure$1(409, "ACCOUNT_CHANGED", true);
|
|
2012
2018
|
dispatched = true;
|
|
2013
2019
|
const raw = await http.json(`/v1/account/${parsed.wire}`, {
|
|
2014
2020
|
method: parsed.method,
|
|
@@ -2021,24 +2027,24 @@ function accountBusinessActionsRoutes(http, account) {
|
|
|
2021
2027
|
});
|
|
2022
2028
|
if (!await stillCurrent()) {
|
|
2023
2029
|
http.invalidateAccountSnapshots();
|
|
2024
|
-
return failure(409, "ACCOUNT_CHANGED", false);
|
|
2030
|
+
return failure$1(409, "ACCOUNT_CHANGED", false);
|
|
2025
2031
|
}
|
|
2026
2032
|
const receipt = object$2(projectBusinessReceipt(object$2(raw)?.data));
|
|
2027
2033
|
const expectedAction = kind === "redeem/apply" ? "redeem" : kind.replace("/", ".");
|
|
2028
|
-
if (receipt === void 0 || receipt.operation_id !== body.operation_id || receipt.action !== expectedAction) return failure(502, "ACCOUNT_ACTION_UNKNOWN", false);
|
|
2034
|
+
if (receipt === void 0 || receipt.operation_id !== body.operation_id || receipt.action !== expectedAction) return failure$1(502, "ACCOUNT_ACTION_UNKNOWN", false);
|
|
2029
2035
|
if (receipt.state === "succeeded") http.invalidateAccountSnapshots();
|
|
2030
|
-
return answer$
|
|
2036
|
+
return answer$3(200, {
|
|
2031
2037
|
code: 0,
|
|
2032
2038
|
data: receipt
|
|
2033
2039
|
});
|
|
2034
2040
|
} catch (error) {
|
|
2035
2041
|
if (before !== void 0 && !await stillCurrent()) {
|
|
2036
2042
|
http.invalidateAccountSnapshots();
|
|
2037
|
-
return failure(409, "ACCOUNT_CHANGED", !dispatched);
|
|
2043
|
+
return failure$1(409, "ACCOUNT_CHANGED", !dispatched);
|
|
2038
2044
|
}
|
|
2039
2045
|
if (error instanceof MediaError) {
|
|
2040
2046
|
const status = error.details.status ?? 502;
|
|
2041
|
-
if (status === 404 || status === 405) return failure(200, "ACCOUNT_ACTION_UNSUPPORTED", true, { unsupported: true });
|
|
2047
|
+
if (status === 404 || status === 405) return failure$1(200, "ACCOUNT_ACTION_UNSUPPORTED", true, { unsupported: true });
|
|
2042
2048
|
const refused = [
|
|
2043
2049
|
400,
|
|
2044
2050
|
401,
|
|
@@ -2046,9 +2052,9 @@ function accountBusinessActionsRoutes(http, account) {
|
|
|
2046
2052
|
413,
|
|
2047
2053
|
422
|
|
2048
2054
|
].includes(status);
|
|
2049
|
-
return failure(status, refused ? error.code : "ACCOUNT_ACTION_UNKNOWN", refused);
|
|
2055
|
+
return failure$1(status, refused ? error.code : "ACCOUNT_ACTION_UNKNOWN", refused);
|
|
2050
2056
|
}
|
|
2051
|
-
return failure(502, "ACCOUNT_ACTION_UNKNOWN", !dispatched);
|
|
2057
|
+
return failure$1(502, "ACCOUNT_ACTION_UNKNOWN", !dispatched);
|
|
2052
2058
|
}
|
|
2053
2059
|
}
|
|
2054
2060
|
}));
|
|
@@ -2057,7 +2063,7 @@ function accountBusinessActionsRoutes(http, account) {
|
|
|
2057
2063
|
//#region src/account/center.ts
|
|
2058
2064
|
const CENTER_PREFIX = "/api/dsh-vibedev/account-center";
|
|
2059
2065
|
const obj = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2060
|
-
function answer$
|
|
2066
|
+
function answer$2(status, body) {
|
|
2061
2067
|
return new Response(JSON.stringify(body), {
|
|
2062
2068
|
status,
|
|
2063
2069
|
headers: {
|
|
@@ -2066,7 +2072,7 @@ function answer$1(status, body) {
|
|
|
2066
2072
|
}
|
|
2067
2073
|
});
|
|
2068
2074
|
}
|
|
2069
|
-
function sameAccount(before, after) {
|
|
2075
|
+
function sameAccount$1(before, after) {
|
|
2070
2076
|
return before.signedIn && after.signedIn && before.userId === after.userId && (before.userId !== void 0 || before.credential.token === after.credential.token);
|
|
2071
2077
|
}
|
|
2072
2078
|
function accountCenterRoutes(http, account) {
|
|
@@ -2078,7 +2084,7 @@ function accountCenterRoutes(http, account) {
|
|
|
2078
2084
|
let before;
|
|
2079
2085
|
const changed = () => {
|
|
2080
2086
|
http.invalidateAccountSnapshots();
|
|
2081
|
-
return answer$
|
|
2087
|
+
return answer$2(409, { error: {
|
|
2082
2088
|
code: "ACCOUNT_CHANGED",
|
|
2083
2089
|
message: "账号已切换,请刷新页面。"
|
|
2084
2090
|
} });
|
|
@@ -2086,14 +2092,14 @@ function accountCenterRoutes(http, account) {
|
|
|
2086
2092
|
try {
|
|
2087
2093
|
const params = new URL(request.url, "http://host").searchParams;
|
|
2088
2094
|
const parsed = centerQuery(path, params);
|
|
2089
|
-
if (parsed === void 0) return answer$
|
|
2095
|
+
if (parsed === void 0) return answer$2(400, { error: {
|
|
2090
2096
|
code: "INVALID_INPUT",
|
|
2091
2097
|
category: "invalid_input",
|
|
2092
2098
|
message: "筛选参数不符合要求。"
|
|
2093
2099
|
} });
|
|
2094
2100
|
const { query, wire, fresh } = parsed;
|
|
2095
2101
|
before = await account.identity();
|
|
2096
|
-
if (!before.signedIn) return answer$
|
|
2102
|
+
if (!before.signedIn) return answer$2(401, { error: {
|
|
2097
2103
|
code: "AUTHENTICATION_REQUIRED",
|
|
2098
2104
|
category: "authentication",
|
|
2099
2105
|
message: "请先登录 VibeDev。"
|
|
@@ -2104,30 +2110,30 @@ function accountCenterRoutes(http, account) {
|
|
|
2104
2110
|
timeoutMs: 3e4,
|
|
2105
2111
|
signal: request.signal,
|
|
2106
2112
|
busyRetries: 0,
|
|
2107
|
-
isCurrentAccount: async () => sameAccount(before, await account.identity())
|
|
2113
|
+
isCurrentAccount: async () => sameAccount$1(before, await account.identity())
|
|
2108
2114
|
};
|
|
2109
2115
|
const data = path === "entitlements" && before.userId !== void 0 && query.size === 0 ? await http.entitlements(`${http.origin}\nuser:${before.userId}`, options, fresh) : await http.json(`/v1/account/${wire}${query.size === 0 ? "" : `?${query}`}`, options);
|
|
2110
2116
|
const after = await account.identity();
|
|
2111
|
-
if (!sameAccount(before, after)) return changed();
|
|
2117
|
+
if (!sameAccount$1(before, after)) return changed();
|
|
2112
2118
|
const projected = projectCenterRoute(path, obj(data)?.data ?? data);
|
|
2113
|
-
if (projected === void 0) return answer$
|
|
2119
|
+
if (projected === void 0) return answer$2(502, { error: {
|
|
2114
2120
|
code: "ACCOUNT_READ_UNAVAILABLE",
|
|
2115
2121
|
category: "service_unavailable"
|
|
2116
2122
|
} });
|
|
2117
|
-
return answer$
|
|
2123
|
+
return answer$2(200, {
|
|
2118
2124
|
code: 0,
|
|
2119
2125
|
data: projected
|
|
2120
2126
|
});
|
|
2121
2127
|
} catch (error) {
|
|
2122
|
-
if (error instanceof MediaError && error.code === "ACCOUNT_CHANGED" || before !== void 0 && !sameAccount(before, await account.identity())) return changed();
|
|
2123
|
-
if (error instanceof MediaError && (error.details.status === 404 || error.details.status === 405)) return answer$
|
|
2124
|
-
if (error instanceof MediaError) return answer$
|
|
2128
|
+
if (error instanceof MediaError && error.code === "ACCOUNT_CHANGED" || before !== void 0 && !sameAccount$1(before, await account.identity())) return changed();
|
|
2129
|
+
if (error instanceof MediaError && (error.details.status === 404 || error.details.status === 405)) return answer$2(200, { unsupported: true });
|
|
2130
|
+
if (error instanceof MediaError) return answer$2(error.details.status ?? 502, { error: {
|
|
2125
2131
|
code: error.code,
|
|
2126
2132
|
category: error.details.category,
|
|
2127
2133
|
message: error.message,
|
|
2128
2134
|
request_id: error.details.requestId
|
|
2129
2135
|
} });
|
|
2130
|
-
return answer$
|
|
2136
|
+
return answer$2(502, { error: {
|
|
2131
2137
|
code: "ACCOUNT_READ_UNAVAILABLE",
|
|
2132
2138
|
category: "service_unavailable",
|
|
2133
2139
|
message: "账户信息暂时无法获取,请稍后刷新。"
|
|
@@ -2797,8 +2803,8 @@ const unavailable = () => json$2(200, {
|
|
|
2797
2803
|
items: [],
|
|
2798
2804
|
unread: 0
|
|
2799
2805
|
});
|
|
2800
|
-
const record$
|
|
2801
|
-
const text$
|
|
2806
|
+
const record$13 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2807
|
+
const text$8 = (value) => typeof value === "string" ? value : void 0;
|
|
2802
2808
|
const identifier = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
2803
2809
|
/**
|
|
2804
2810
|
* One announcement from the wire, with every field it needs and nothing else.
|
|
@@ -2806,12 +2812,12 @@ const identifier = (value) => typeof value === "number" && Number.isSafeInteger(
|
|
|
2806
2812
|
* @returns the announcement, or undefined when the entry cannot be rendered.
|
|
2807
2813
|
*/
|
|
2808
2814
|
function parseAnnouncement(value) {
|
|
2809
|
-
const item = record$
|
|
2815
|
+
const item = record$13(value);
|
|
2810
2816
|
if (item === void 0) return void 0;
|
|
2811
2817
|
const id = identifier(item.id);
|
|
2812
|
-
const title = text$
|
|
2813
|
-
const content = text$
|
|
2814
|
-
const createdAt = text$
|
|
2818
|
+
const title = text$8(item.title);
|
|
2819
|
+
const content = text$8(item.content);
|
|
2820
|
+
const createdAt = text$8(item.created_at);
|
|
2815
2821
|
if (id === void 0 || title === void 0 || content === void 0 || createdAt === void 0) return void 0;
|
|
2816
2822
|
return {
|
|
2817
2823
|
id,
|
|
@@ -2821,7 +2827,7 @@ function parseAnnouncement(value) {
|
|
|
2821
2827
|
notifyMode: item.notify_mode === "popup" ? "popup" : "silent",
|
|
2822
2828
|
...typeof item.starts_at === "string" ? { startsAt: item.starts_at } : {},
|
|
2823
2829
|
...typeof item.ends_at === "string" ? { endsAt: item.ends_at } : {},
|
|
2824
|
-
readAt: text$
|
|
2830
|
+
readAt: text$8(item.read_at) ?? null
|
|
2825
2831
|
};
|
|
2826
2832
|
}
|
|
2827
2833
|
/**
|
|
@@ -2831,7 +2837,7 @@ function parseAnnouncement(value) {
|
|
|
2831
2837
|
*/
|
|
2832
2838
|
function entriesOf(payload) {
|
|
2833
2839
|
if (Array.isArray(payload)) return payload;
|
|
2834
|
-
const data = record$
|
|
2840
|
+
const data = record$13(payload)?.data;
|
|
2835
2841
|
return Array.isArray(data) ? data : void 0;
|
|
2836
2842
|
}
|
|
2837
2843
|
/**
|
|
@@ -2915,7 +2921,7 @@ function announcementRoutes({ http, account }) {
|
|
|
2915
2921
|
fetch: async (incoming) => {
|
|
2916
2922
|
const entered = await enter(incoming);
|
|
2917
2923
|
if (entered instanceof Response) return entered;
|
|
2918
|
-
const body = record$
|
|
2924
|
+
const body = record$13(await incoming.json().catch(() => void 0));
|
|
2919
2925
|
const id = identifier(body?.id);
|
|
2920
2926
|
if (id === void 0) return json$2(400, { error: {
|
|
2921
2927
|
code: "ANNOUNCEMENT_INVALID_ID",
|
|
@@ -3887,7 +3893,7 @@ const invalid = (field) => json(400, { error: {
|
|
|
3887
3893
|
code: "FEEDBACK_INVALID",
|
|
3888
3894
|
field
|
|
3889
3895
|
} });
|
|
3890
|
-
const record$
|
|
3896
|
+
const record$12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
3891
3897
|
/**
|
|
3892
3898
|
* The feedback routes.
|
|
3893
3899
|
* @param options - the uploader's submit, the recent errors and the credential check.
|
|
@@ -3905,7 +3911,7 @@ function feedbackRoutes(options) {
|
|
|
3905
3911
|
requestBody: "buffered",
|
|
3906
3912
|
fetch: async (request) => {
|
|
3907
3913
|
try {
|
|
3908
|
-
const body = record$
|
|
3914
|
+
const body = record$12(await request.json().catch(() => void 0));
|
|
3909
3915
|
if (body === void 0) return invalid("body");
|
|
3910
3916
|
if (body.category !== void 0 && body.category !== null && !isCategory(body.category)) return invalid("category");
|
|
3911
3917
|
if (body.text !== void 0 && typeof body.text !== "string") return invalid("text");
|
|
@@ -3915,7 +3921,7 @@ function feedbackRoutes(options) {
|
|
|
3915
3921
|
if (text === void 0 && category === void 0) return invalid("text");
|
|
3916
3922
|
let content;
|
|
3917
3923
|
if (body.attachment !== void 0 && body.attachment !== null) {
|
|
3918
|
-
const given = record$
|
|
3924
|
+
const given = record$12(body.attachment)?.content;
|
|
3919
3925
|
if (typeof given !== "string" || given === "" || Buffer$1.byteLength(given, "utf8") > 262144) return invalid("attachment");
|
|
3920
3926
|
content = given;
|
|
3921
3927
|
}
|
|
@@ -4000,7 +4006,8 @@ const ACCOUNT_PAGES = [
|
|
|
4000
4006
|
"redeem",
|
|
4001
4007
|
"affiliate",
|
|
4002
4008
|
"profile",
|
|
4003
|
-
"messages"
|
|
4009
|
+
"messages",
|
|
4010
|
+
"voice_profiles"
|
|
4004
4011
|
];
|
|
4005
4012
|
//#endregion
|
|
4006
4013
|
//#region src/gateway/http.ts
|
|
@@ -5122,8 +5129,8 @@ const CALLBACK_PATH = "/dsh-media/callback";
|
|
|
5122
5129
|
function base64url(data) {
|
|
5123
5130
|
return data.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
5124
5131
|
}
|
|
5125
|
-
const record$
|
|
5126
|
-
const text$
|
|
5132
|
+
const record$11 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
5133
|
+
const text$7 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
5127
5134
|
/**
|
|
5128
5135
|
* Read a token answer (`redeem` or `refresh`).
|
|
5129
5136
|
* @param body - the parsed envelope `{code, data}` or a bare data object.
|
|
@@ -5132,18 +5139,18 @@ const text$6 = (value) => typeof value === "string" && value.trim() !== "" ? val
|
|
|
5132
5139
|
* @returns the grant, or undefined when the answer lacks tokens.
|
|
5133
5140
|
*/
|
|
5134
5141
|
function parseGrant(body, now, previous) {
|
|
5135
|
-
const envelope = record$
|
|
5136
|
-
const data = record$
|
|
5137
|
-
const accessToken = text$
|
|
5138
|
-
const refreshToken = text$
|
|
5142
|
+
const envelope = record$11(body);
|
|
5143
|
+
const data = record$11(envelope?.data) ?? envelope;
|
|
5144
|
+
const accessToken = text$7(data?.access_token);
|
|
5145
|
+
const refreshToken = text$7(data?.refresh_token);
|
|
5139
5146
|
if (data === void 0 || accessToken === void 0 || refreshToken === void 0) return void 0;
|
|
5140
5147
|
const seconds = (value, fallback) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
5141
|
-
const user = record$
|
|
5142
|
-
const sessionId = text$
|
|
5148
|
+
const user = record$11(data.user);
|
|
5149
|
+
const sessionId = text$7(data.session_id) ?? previous?.sessionId;
|
|
5143
5150
|
const parsedUser = user === void 0 ? previous?.user : {
|
|
5144
|
-
...text$
|
|
5145
|
-
...text$
|
|
5146
|
-
...text$
|
|
5151
|
+
...text$7(user.id) === void 0 && typeof user.id !== "number" ? {} : { id: String(user.id) },
|
|
5152
|
+
...text$7(user.email) === void 0 ? {} : { email: text$7(user.email) },
|
|
5153
|
+
...text$7(user.nickname) === void 0 ? {} : { nickname: text$7(user.nickname) }
|
|
5147
5154
|
};
|
|
5148
5155
|
return {
|
|
5149
5156
|
accessToken,
|
|
@@ -5563,8 +5570,8 @@ var PluginLogin = class {
|
|
|
5563
5570
|
return;
|
|
5564
5571
|
}
|
|
5565
5572
|
if (!live()) return;
|
|
5566
|
-
const envelope = record$
|
|
5567
|
-
const parsed = envelope !== void 0 && (envelope.code === void 0 || envelope.code === 0) && (envelope.data === void 0 || record$
|
|
5573
|
+
const envelope = record$11(body);
|
|
5574
|
+
const parsed = envelope !== void 0 && (envelope.code === void 0 || envelope.code === 0) && (envelope.data === void 0 || record$11(envelope.data) !== void 0) ? parseGrant(body, this.now()) : void 0;
|
|
5568
5575
|
if (parsed === void 0) {
|
|
5569
5576
|
answer(502, "VibeDev", failurePage({
|
|
5570
5577
|
...this.attempt,
|
|
@@ -5756,7 +5763,7 @@ const ENDPOINT = {
|
|
|
5756
5763
|
"openai-responses": "/v1/responses",
|
|
5757
5764
|
"openai-completions": "/v1/chat/completions"
|
|
5758
5765
|
};
|
|
5759
|
-
const record$
|
|
5766
|
+
const record$10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
5760
5767
|
const strings$1 = (value) => Array.isArray(value) && value.every((item) => typeof item === "string") ? value : void 0;
|
|
5761
5768
|
const positive$2 = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : void 0;
|
|
5762
5769
|
const price$1 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
@@ -5810,15 +5817,15 @@ function reasoningLevelsOf(value) {
|
|
|
5810
5817
|
* @returns the chat models, in catalog order; entries that are not chat models or cannot be called are left out.
|
|
5811
5818
|
*/
|
|
5812
5819
|
function parseCatalog(body) {
|
|
5813
|
-
const list = Array.isArray(body) ? body : record$
|
|
5820
|
+
const list = Array.isArray(body) ? body : record$10(body)?.data;
|
|
5814
5821
|
if (!Array.isArray(list)) return [];
|
|
5815
5822
|
const models = [];
|
|
5816
5823
|
const seen = /* @__PURE__ */ new Set();
|
|
5817
5824
|
for (const raw of list) {
|
|
5818
|
-
const entry = record$
|
|
5825
|
+
const entry = record$10(raw);
|
|
5819
5826
|
const id = typeof entry?.id === "string" ? entry.id.trim() : "";
|
|
5820
5827
|
if (entry === void 0 || id === "" || seen.has(id)) continue;
|
|
5821
|
-
const capabilities = record$
|
|
5828
|
+
const capabilities = record$10(entry.capabilities);
|
|
5822
5829
|
if (capabilities === void 0) continue;
|
|
5823
5830
|
if (typeof entry.media_type === "string" && entry.media_type !== "") continue;
|
|
5824
5831
|
if (typeof entry.internal_role === "string" && entry.internal_role !== "") continue;
|
|
@@ -5833,7 +5840,7 @@ function parseCatalog(body) {
|
|
|
5833
5840
|
const inputs = strings$1(capabilities.input_modalities) ?? [];
|
|
5834
5841
|
const nativeMedia = api === "openai-completions" ? NATIVE_MEDIA.filter((kind) => inputs.includes(kind)) : [];
|
|
5835
5842
|
const maxInputTokens = positive$2(capabilities.max_input_tokens);
|
|
5836
|
-
const rawFamily = record$
|
|
5843
|
+
const rawFamily = record$10(entry.model_family);
|
|
5837
5844
|
const familyId = typeof rawFamily?.id === "string" ? rawFamily.id.trim() : "";
|
|
5838
5845
|
const familyLabel = typeof rawFamily?.label === "string" ? rawFamily.label.trim() : "";
|
|
5839
5846
|
seen.add(id);
|
|
@@ -7340,7 +7347,7 @@ const PRICE_CONTEXT_QUERY = "scope=platform&period=7d&sort=recommended&page=1&pa
|
|
|
7340
7347
|
const DEFAULT_TIMEOUT_MS = 1e4;
|
|
7341
7348
|
/** The same label for an English surface. */
|
|
7342
7349
|
const DEFAULT_PROMOTION_BADGE_EN = "Limited-time offer";
|
|
7343
|
-
const record$
|
|
7350
|
+
const record$9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
7344
7351
|
const string = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
7345
7352
|
const amount$1 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
7346
7353
|
const groupId = (value) => {
|
|
@@ -7355,7 +7362,7 @@ function instant$1(value) {
|
|
|
7355
7362
|
return Number.isFinite(parsed) ? parsed : void 0;
|
|
7356
7363
|
}
|
|
7357
7364
|
function tier(value) {
|
|
7358
|
-
const source = record$
|
|
7365
|
+
const source = record$9(value);
|
|
7359
7366
|
if (source === void 0) return void 0;
|
|
7360
7367
|
const prevSpendMin = amount$1(source.prev_spend_min);
|
|
7361
7368
|
const discountRate = amount$1(source.discount_rate);
|
|
@@ -7371,7 +7378,7 @@ function tier(value) {
|
|
|
7371
7378
|
* @returns the promotion with its window resolved, or undefined.
|
|
7372
7379
|
*/
|
|
7373
7380
|
function parsePromotion(value) {
|
|
7374
|
-
const source = record$
|
|
7381
|
+
const source = record$9(value);
|
|
7375
7382
|
if (source === void 0) return void 0;
|
|
7376
7383
|
const model = string(source.model);
|
|
7377
7384
|
const startsAt = string(source.starts_at);
|
|
@@ -7521,16 +7528,16 @@ var PromotionService = class {
|
|
|
7521
7528
|
}
|
|
7522
7529
|
/** The pricing group the account center already prices this account with. */
|
|
7523
7530
|
async priceGroup() {
|
|
7524
|
-
const answer = record$
|
|
7531
|
+
const answer = record$9(await this.options.http.json(`${PRICE_CONTEXT_PATH}?${PRICE_CONTEXT_QUERY}`, {
|
|
7525
7532
|
timeoutMs: this.timeoutMs,
|
|
7526
7533
|
busyRetries: 0
|
|
7527
7534
|
}));
|
|
7528
|
-
const data = record$
|
|
7529
|
-
return groupId(record$
|
|
7535
|
+
const data = record$9(answer?.data) ?? answer;
|
|
7536
|
+
return groupId(record$9(data?.price_context)?.group_id);
|
|
7530
7537
|
}
|
|
7531
7538
|
/** The public list. `anonymous` keeps a signed-out or broken sign-in from changing the answer. */
|
|
7532
7539
|
async list() {
|
|
7533
|
-
const data = record$
|
|
7540
|
+
const data = record$9(await this.options.http.json(PROMOTIONS_PATH, {
|
|
7534
7541
|
anonymous: true,
|
|
7535
7542
|
timeoutMs: this.timeoutMs,
|
|
7536
7543
|
busyRetries: 0
|
|
@@ -8373,7 +8380,7 @@ function installGatewayModels(ctx, options) {
|
|
|
8373
8380
|
const PROMOTIONS_ROUTE = "/api/dsh-vibedev/promotions";
|
|
8374
8381
|
/** How long the page waits for a promotion answer before showing prices without labels. */
|
|
8375
8382
|
const ROUTE_WAIT_MS = 2e3;
|
|
8376
|
-
const answer = (body) => new Response(JSON.stringify(body), {
|
|
8383
|
+
const answer$1 = (body) => new Response(JSON.stringify(body), {
|
|
8377
8384
|
status: 200,
|
|
8378
8385
|
headers: {
|
|
8379
8386
|
"content-type": "application/json",
|
|
@@ -8398,7 +8405,7 @@ function promotionRoutes(promotions) {
|
|
|
8398
8405
|
items = [];
|
|
8399
8406
|
}
|
|
8400
8407
|
const group = promotions.snapshotGroup();
|
|
8401
|
-
return answer({
|
|
8408
|
+
return answer$1({
|
|
8402
8409
|
code: 0,
|
|
8403
8410
|
data: {
|
|
8404
8411
|
items,
|
|
@@ -8445,10 +8452,10 @@ const FIRST_LOOK_MS = 1e3;
|
|
|
8445
8452
|
const LOOK_STEP_MAX_MS = 1e4;
|
|
8446
8453
|
/** Uploads this library starts for one file: its own, and one more after another upload of the file ended without it. */
|
|
8447
8454
|
const OWN_UPLOADS = 2;
|
|
8448
|
-
const record$
|
|
8449
|
-
const text$
|
|
8455
|
+
const record$8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
8456
|
+
const text$6 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
8450
8457
|
const httpUrl$1 = (value) => {
|
|
8451
|
-
const url = text$
|
|
8458
|
+
const url = text$6(value);
|
|
8452
8459
|
return url !== void 0 && /^https?:\/\//i.test(url) ? url : void 0;
|
|
8453
8460
|
};
|
|
8454
8461
|
/**
|
|
@@ -8458,17 +8465,17 @@ const httpUrl$1 = (value) => {
|
|
|
8458
8465
|
* @returns the asset facts, or undefined when the answer names no usable URL.
|
|
8459
8466
|
*/
|
|
8460
8467
|
function parseAsset(body, fallbackType) {
|
|
8461
|
-
const raw = record$
|
|
8462
|
-
const assetId = text$
|
|
8468
|
+
const raw = record$8(body);
|
|
8469
|
+
const assetId = text$6(raw?.asset_id);
|
|
8463
8470
|
const referenceUrl = httpUrl$1(raw?.reference_url);
|
|
8464
8471
|
if (raw === void 0 || assetId === void 0 || referenceUrl === void 0) return void 0;
|
|
8465
8472
|
const contentUrl = httpUrl$1(raw.content_url);
|
|
8466
|
-
const expiresAt = text$
|
|
8473
|
+
const expiresAt = text$6(raw.expires_at);
|
|
8467
8474
|
const duration = raw.duration_ms;
|
|
8468
8475
|
return {
|
|
8469
8476
|
assetId,
|
|
8470
8477
|
referenceUrl,
|
|
8471
|
-
contentType: text$
|
|
8478
|
+
contentType: text$6(raw.content_type) ?? fallbackType,
|
|
8472
8479
|
...contentUrl === void 0 ? {} : { contentUrl },
|
|
8473
8480
|
...expiresAt === void 0 ? {} : { expiresAt },
|
|
8474
8481
|
...typeof duration === "number" && Number.isFinite(duration) && duration > 0 ? { durationMs: duration } : {}
|
|
@@ -8608,7 +8615,7 @@ var MediaLibrary = class {
|
|
|
8608
8615
|
}
|
|
8609
8616
|
/** `POST /uploads`: the asset when the library already holds the file, else the upload it hands out. */
|
|
8610
8617
|
async declare(media, purpose, sha256, signal) {
|
|
8611
|
-
const created = record$
|
|
8618
|
+
const created = record$8(await this.http.json("/v1/media-assets/uploads", {
|
|
8612
8619
|
method: "POST",
|
|
8613
8620
|
json: {
|
|
8614
8621
|
filename: media.name,
|
|
@@ -8619,7 +8626,7 @@ var MediaLibrary = class {
|
|
|
8619
8626
|
},
|
|
8620
8627
|
signal
|
|
8621
8628
|
}));
|
|
8622
|
-
const assetId = text$
|
|
8629
|
+
const assetId = text$6(created?.asset_id);
|
|
8623
8630
|
if (created === void 0 || assetId === void 0) throw new MediaError(`The VibeDev gateway did not accept the upload of "${media.source}".`, "ASSET_UPLOAD_REFUSED");
|
|
8624
8631
|
if (created.upload_required !== false) return {
|
|
8625
8632
|
kind: "upload",
|
|
@@ -8642,10 +8649,10 @@ var MediaLibrary = class {
|
|
|
8642
8649
|
}
|
|
8643
8650
|
/** PUT the bytes where `uploads` said, then `complete`. */
|
|
8644
8651
|
async put(media, sha256, assetId, created, signal) {
|
|
8645
|
-
const uploadUrl = httpUrl$1(created.upload_url) ?? (text$
|
|
8652
|
+
const uploadUrl = httpUrl$1(created.upload_url) ?? (text$6(created.upload_url)?.startsWith("/") === true ? this.http.url(text$6(created.upload_url)) : void 0);
|
|
8646
8653
|
if (uploadUrl === void 0) throw new MediaError(`The VibeDev gateway returned no upload address for "${media.source}".`, "ASSET_UPLOAD_URL_MISSING");
|
|
8647
8654
|
const headers = { "content-type": media.mime };
|
|
8648
|
-
for (const [name, value] of Object.entries(record$
|
|
8655
|
+
for (const [name, value] of Object.entries(record$8(created.upload_headers) ?? {})) if (typeof value === "string") headers[name.toLowerCase()] = value;
|
|
8649
8656
|
await this.http.send(uploadUrl, {
|
|
8650
8657
|
method: "PUT",
|
|
8651
8658
|
body: media.data,
|
|
@@ -8707,8 +8714,8 @@ const AUDIO_GENERATION_KINDS = [
|
|
|
8707
8714
|
"speech",
|
|
8708
8715
|
"transcription"
|
|
8709
8716
|
];
|
|
8710
|
-
const record$
|
|
8711
|
-
const text$
|
|
8717
|
+
const record$7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
8718
|
+
const text$5 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
8712
8719
|
const strings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string") ? value : void 0;
|
|
8713
8720
|
const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
8714
8721
|
const positive$1 = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
@@ -8755,15 +8762,15 @@ function parseModes(raw) {
|
|
|
8755
8762
|
const version = field(raw, "modes_schema_version");
|
|
8756
8763
|
const modesRaw = raw.modes;
|
|
8757
8764
|
if (version === void 0 && modesRaw === void 0) return {};
|
|
8758
|
-
if (version !== 1 || record$
|
|
8765
|
+
if (version !== 1 || record$7(modesRaw) === void 0) return { unreadableModesVersion: typeof version === "number" ? version : 0 };
|
|
8759
8766
|
const modes = {};
|
|
8760
8767
|
for (const mode of VIDEO_MODES) {
|
|
8761
|
-
const entry = record$
|
|
8768
|
+
const entry = record$7(modesRaw[mode]);
|
|
8762
8769
|
if (entry === void 0) continue;
|
|
8763
|
-
const inputsRaw = record$
|
|
8770
|
+
const inputsRaw = record$7(entry.inputs) ?? {};
|
|
8764
8771
|
const inputs = {};
|
|
8765
8772
|
for (const [key, limitRaw] of Object.entries(inputsRaw)) {
|
|
8766
|
-
const limit = record$
|
|
8773
|
+
const limit = record$7(limitRaw);
|
|
8767
8774
|
const min = count(limit?.min);
|
|
8768
8775
|
const max = count(limit?.max);
|
|
8769
8776
|
if (!VIDEO_INPUTS.includes(key) || limit === void 0 || min === void 0 || max === void 0 || min > max) return { unreadableModesVersion: 1 };
|
|
@@ -8872,11 +8879,11 @@ function parseVideoCapabilities(raw) {
|
|
|
8872
8879
|
if (Array.isArray(combinationsRaw)) {
|
|
8873
8880
|
const combinations = [];
|
|
8874
8881
|
for (const item of combinationsRaw) {
|
|
8875
|
-
const entry = record$
|
|
8882
|
+
const entry = record$7(item);
|
|
8876
8883
|
if (entry === void 0) continue;
|
|
8877
8884
|
const duration = positive$1(field(entry, "duration_seconds"));
|
|
8878
|
-
const ratio = text$
|
|
8879
|
-
const resolution = text$
|
|
8885
|
+
const ratio = text$5(entry.ratio);
|
|
8886
|
+
const resolution = text$5(entry.resolution);
|
|
8880
8887
|
combinations.push({
|
|
8881
8888
|
...duration === void 0 ? {} : { duration },
|
|
8882
8889
|
...ratio === void 0 ? {} : { ratio },
|
|
@@ -8966,12 +8973,12 @@ const PRICE_UNITS = [
|
|
|
8966
8973
|
];
|
|
8967
8974
|
/** The audio block: `entry.audio`, else `capabilities.audio`, else the fields flattened into `capabilities`. */
|
|
8968
8975
|
function audioBlock(entry, capabilities) {
|
|
8969
|
-
const own = record$
|
|
8976
|
+
const own = record$7(entry.audio) ?? record$7(capabilities.audio);
|
|
8970
8977
|
if (own !== void 0) return own;
|
|
8971
8978
|
return field(capabilities, "generation_kind") !== void 0 ? capabilities : void 0;
|
|
8972
8979
|
}
|
|
8973
8980
|
function stringChoices(raw) {
|
|
8974
|
-
const choices = record$
|
|
8981
|
+
const choices = record$7(raw);
|
|
8975
8982
|
if (choices === void 0) return void 0;
|
|
8976
8983
|
const out = {};
|
|
8977
8984
|
for (const [name, values] of Object.entries(choices)) {
|
|
@@ -9015,7 +9022,7 @@ function parseReferenceLimits(raw, form) {
|
|
|
9015
9022
|
if (mimes !== void 0 && mimes.length > 0) limits.mimes = mimes;
|
|
9016
9023
|
const exclusive = list(raw, "mutually_exclusive_with") ?? list(raw, "exclusive_with");
|
|
9017
9024
|
if (exclusive !== void 0 && exclusive.length > 0) limits.exclusiveWith = exclusive;
|
|
9018
|
-
const purpose = text$
|
|
9025
|
+
const purpose = text$5(field(raw, "asset_purpose")) ?? text$5(raw.purpose);
|
|
9019
9026
|
if (purpose !== void 0) limits.purpose = purpose;
|
|
9020
9027
|
return limits;
|
|
9021
9028
|
}
|
|
@@ -9044,11 +9051,11 @@ function seedReferenceLimits(raw) {
|
|
|
9044
9051
|
function parseOutputFormats(raw) {
|
|
9045
9052
|
const declared = field(raw, "output_formats");
|
|
9046
9053
|
if (!Array.isArray(declared)) return void 0;
|
|
9047
|
-
const rates = record$
|
|
9054
|
+
const rates = record$7(field(raw, "sample_rates")) ?? record$7(field(raw, "output_sample_rates"));
|
|
9048
9055
|
const formats = [];
|
|
9049
9056
|
for (const item of declared) {
|
|
9050
|
-
const entry = record$
|
|
9051
|
-
const format = (entry === void 0 ? text$
|
|
9057
|
+
const entry = record$7(item);
|
|
9058
|
+
const format = (entry === void 0 ? text$5(item) : text$5(entry.format))?.toLowerCase();
|
|
9052
9059
|
if (format === void 0 || formats.some((known) => known.format === format)) continue;
|
|
9053
9060
|
const sampleRates = (entry === void 0 ? void 0 : field(entry, "sample_rates")) ?? rates?.[format];
|
|
9054
9061
|
const valid = Array.isArray(sampleRates) ? sampleRates.filter((rate) => positive$1(rate) !== void 0 && Number.isInteger(rate)) : [];
|
|
@@ -9067,20 +9074,20 @@ function parseOutputFormats(raw) {
|
|
|
9067
9074
|
* @returns the declared capabilities; `generationKind` is absent unless declared.
|
|
9068
9075
|
*/
|
|
9069
9076
|
function parseAudioCapabilities(raw) {
|
|
9070
|
-
const kindRaw = text$
|
|
9077
|
+
const kindRaw = text$5(field(raw, "generation_kind"))?.toLowerCase();
|
|
9071
9078
|
const generationKind = AUDIO_GENERATION_KINDS.includes(kindRaw ?? "") ? kindRaw : void 0;
|
|
9072
|
-
const billingRaw = text$
|
|
9079
|
+
const billingRaw = text$5(field(raw, "billing_unit"))?.toLowerCase();
|
|
9073
9080
|
const billingUnit = billingRaw === "generation" || billingRaw === "original_second" || billingRaw === "minute" ? billingRaw : void 0;
|
|
9074
|
-
const promptField = text$
|
|
9081
|
+
const promptField = text$5(field(raw, "prompt_field"));
|
|
9075
9082
|
const requestFields = list(raw, "request_fields") ?? [];
|
|
9076
9083
|
const union = [
|
|
9077
9084
|
"reference_audio_input",
|
|
9078
9085
|
"reference_image_input",
|
|
9079
9086
|
"speaker_input"
|
|
9080
9087
|
].some((name) => bool(raw, name) !== void 0);
|
|
9081
|
-
const references = parseReferenceLimits(record$
|
|
9088
|
+
const references = parseReferenceLimits(record$7(field(raw, "references")) ?? record$7(field(raw, "reference_audio")), union ? "object" : "url") ?? seedReferenceLimits(raw);
|
|
9082
9089
|
const outputFormats = parseOutputFormats(raw);
|
|
9083
|
-
const defaultFormat = text$
|
|
9090
|
+
const defaultFormat = text$5(field(raw, "default_format"))?.toLowerCase();
|
|
9084
9091
|
const choices = stringChoices(field(raw, "choices") ?? field(raw, "field_options"));
|
|
9085
9092
|
const watermarkFields = list(raw, "watermark_fields");
|
|
9086
9093
|
const result = { requestFields };
|
|
@@ -9092,6 +9099,7 @@ function parseAudioCapabilities(raw) {
|
|
|
9092
9099
|
if (defaultFormat !== void 0 && outputFormats?.some((format) => format.format === defaultFormat) === true) result.defaultFormat = defaultFormat;
|
|
9093
9100
|
if (choices !== void 0) result.choices = choices;
|
|
9094
9101
|
if (watermarkFields !== void 0 && watermarkFields.length > 0) result.watermarkFields = watermarkFields;
|
|
9102
|
+
if (bool(raw, "supports_voice_cover") === true) result.supportsVoiceCover = true;
|
|
9095
9103
|
for (const [key, ...names] of [
|
|
9096
9104
|
[
|
|
9097
9105
|
"maxPromptChars",
|
|
@@ -9120,13 +9128,13 @@ function parseAudioCapabilities(raw) {
|
|
|
9120
9128
|
return result;
|
|
9121
9129
|
}
|
|
9122
9130
|
function parsePricing(value, audioUnit) {
|
|
9123
|
-
const raw = record$
|
|
9131
|
+
const raw = record$7(value);
|
|
9124
9132
|
if (raw === void 0) return void 0;
|
|
9125
9133
|
const unit = (item) => PRICE_UNITS.includes(item) ? item : item === void 0 && audioUnit !== void 0 ? audioUnit : void 0;
|
|
9126
9134
|
const tiers = [];
|
|
9127
9135
|
if (Array.isArray(raw.tiers)) for (const entry of raw.tiers) {
|
|
9128
|
-
const tier = record$
|
|
9129
|
-
const name = text$
|
|
9136
|
+
const tier = record$7(entry);
|
|
9137
|
+
const name = text$5(tier?.tier);
|
|
9130
9138
|
const tierUnit = unit(tier?.unit);
|
|
9131
9139
|
const amount = typeof tier?.amount === "number" && Number.isFinite(tier.amount) && tier.amount >= 0 ? tier.amount : void 0;
|
|
9132
9140
|
if (name !== void 0 && tierUnit !== void 0 && amount !== void 0) tiers.push({
|
|
@@ -9135,12 +9143,12 @@ function parsePricing(value, audioUnit) {
|
|
|
9135
9143
|
amount
|
|
9136
9144
|
});
|
|
9137
9145
|
}
|
|
9138
|
-
const fallback = record$
|
|
9146
|
+
const fallback = record$7(raw.default);
|
|
9139
9147
|
const fallbackUnit = unit(fallback?.unit);
|
|
9140
9148
|
const fallbackAmount = typeof fallback?.amount === "number" && Number.isFinite(fallback.amount) && fallback.amount >= 0 ? fallback.amount : void 0;
|
|
9141
9149
|
if (tiers.length === 0 && (fallbackUnit === void 0 || fallbackAmount === void 0)) return void 0;
|
|
9142
9150
|
return {
|
|
9143
|
-
currency: text$
|
|
9151
|
+
currency: text$5(raw.currency) ?? "CNY",
|
|
9144
9152
|
tiers,
|
|
9145
9153
|
...fallbackUnit === void 0 || fallbackAmount === void 0 ? {} : { default: {
|
|
9146
9154
|
unit: fallbackUnit,
|
|
@@ -9163,7 +9171,7 @@ function condition(raw, snake) {
|
|
|
9163
9171
|
*/
|
|
9164
9172
|
function parseVideoPricing(value) {
|
|
9165
9173
|
if (value === void 0 || value === null) return {};
|
|
9166
|
-
const raw = record$
|
|
9174
|
+
const raw = record$7(value);
|
|
9167
9175
|
if (raw === void 0) return { videoPricingIssue: "invalid" };
|
|
9168
9176
|
if (field(raw, "schema_version") !== 1) return { videoPricingIssue: "unknown-schema" };
|
|
9169
9177
|
const invalid = { videoPricingIssue: "invalid" };
|
|
@@ -9173,9 +9181,9 @@ function parseVideoPricing(value) {
|
|
|
9173
9181
|
if (!Array.isArray(rulesRaw) || rulesRaw.length === 0) return invalid;
|
|
9174
9182
|
const rules = [];
|
|
9175
9183
|
for (const item of rulesRaw) {
|
|
9176
|
-
const entry = record$
|
|
9184
|
+
const entry = record$7(item);
|
|
9177
9185
|
if (entry === void 0) return invalid;
|
|
9178
|
-
const resolution = text$
|
|
9186
|
+
const resolution = text$5(field(entry, "resolution"));
|
|
9179
9187
|
const perMillion = price(field(entry, "price_per_million_tokens"));
|
|
9180
9188
|
const estimateRaw = field(entry, "estimated_price_per_second");
|
|
9181
9189
|
const perSecond = estimateRaw === void 0 || estimateRaw === null ? void 0 : price(estimateRaw);
|
|
@@ -9203,10 +9211,10 @@ function parseVideoPricing(value) {
|
|
|
9203
9211
|
}
|
|
9204
9212
|
/** Which kind of media model a catalog entry is, or undefined for a chat or internal model. */
|
|
9205
9213
|
function kindOf(entry, capabilities, audio) {
|
|
9206
|
-
if (text$
|
|
9214
|
+
if (text$5(entry.internal_role) !== void 0) return void 0;
|
|
9207
9215
|
if (audio?.generationKind === "transcription") return "transcription";
|
|
9208
9216
|
if (audio?.generationKind !== void 0) return "audio";
|
|
9209
|
-
const mediaType = text$
|
|
9217
|
+
const mediaType = text$5(entry.media_type);
|
|
9210
9218
|
if (mediaType === "video" || mediaType === "image" || mediaType === "audio" || mediaType === "transcription") return mediaType;
|
|
9211
9219
|
if (capabilities.transcription === true || capabilities.realtime_transcription === true) return "transcription";
|
|
9212
9220
|
const outputs = strings(capabilities.output_modalities) ?? strings(entry.output_modalities) ?? [];
|
|
@@ -9225,22 +9233,22 @@ function kindOf(entry, capabilities, audio) {
|
|
|
9225
9233
|
* @returns the media models, in catalog order.
|
|
9226
9234
|
*/
|
|
9227
9235
|
function parseMediaCatalog(body) {
|
|
9228
|
-
const entries = Array.isArray(body) ? body : record$
|
|
9236
|
+
const entries = Array.isArray(body) ? body : record$7(body)?.data;
|
|
9229
9237
|
if (!Array.isArray(entries)) return [];
|
|
9230
9238
|
const models = [];
|
|
9231
9239
|
const seen = /* @__PURE__ */ new Set();
|
|
9232
9240
|
for (const item of entries) {
|
|
9233
|
-
const entry = record$
|
|
9234
|
-
const id = text$
|
|
9241
|
+
const entry = record$7(item);
|
|
9242
|
+
const id = text$5(entry?.id);
|
|
9235
9243
|
if (entry === void 0 || id === void 0 || seen.has(id)) continue;
|
|
9236
|
-
const capabilities = record$
|
|
9244
|
+
const capabilities = record$7(entry.capabilities) ?? {};
|
|
9237
9245
|
const audioRaw = audioBlock(entry, capabilities);
|
|
9238
9246
|
const audio = audioRaw === void 0 ? void 0 : parseAudioCapabilities(audioRaw);
|
|
9239
9247
|
const kind = kindOf(entry, capabilities, audio);
|
|
9240
9248
|
if (kind === void 0) continue;
|
|
9241
9249
|
seen.add(id);
|
|
9242
|
-
const name = text$
|
|
9243
|
-
const description = text$
|
|
9250
|
+
const name = text$5(entry.display_name) ?? id;
|
|
9251
|
+
const description = text$5(entry.description);
|
|
9244
9252
|
const pricing = parsePricing(entry.media_pricing, audio?.billingUnit);
|
|
9245
9253
|
const { videoPricing, videoPricingIssue } = parseVideoPricing(field(entry, "video_pricing"));
|
|
9246
9254
|
const inputModalities = strings(capabilities.input_modalities) ?? strings(entry.input_modalities) ?? [];
|
|
@@ -9249,7 +9257,7 @@ function parseMediaCatalog(body) {
|
|
|
9249
9257
|
let video;
|
|
9250
9258
|
if (kind === "video") video = {
|
|
9251
9259
|
...parseVideoCapabilities(capabilities),
|
|
9252
|
-
...parseVideoCapabilities(record$
|
|
9260
|
+
...parseVideoCapabilities(record$7(entry.video) ?? {})
|
|
9253
9261
|
};
|
|
9254
9262
|
const imageSizes = kind === "image" ? optionList(field(capabilities, "image_sizes")) : void 0;
|
|
9255
9263
|
const imageRatios = kind === "image" ? optionList(field(capabilities, "image_ratios")) : void 0;
|
|
@@ -9872,7 +9880,7 @@ var GatewayFetchError = class extends WebError {
|
|
|
9872
9880
|
this.name = "GatewayFetchError";
|
|
9873
9881
|
}
|
|
9874
9882
|
};
|
|
9875
|
-
function record$
|
|
9883
|
+
function record$6(value) {
|
|
9876
9884
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9877
9885
|
}
|
|
9878
9886
|
function positive(value) {
|
|
@@ -9912,14 +9920,14 @@ function invalidCapability() {
|
|
|
9912
9920
|
}
|
|
9913
9921
|
/** Decode only the fixed advertised Fetch V1 lane; absence is not a request to probe an endpoint. */
|
|
9914
9922
|
function readGatewayFetchCapability(payload) {
|
|
9915
|
-
if (record$
|
|
9916
|
-
if (!record$
|
|
9923
|
+
if (record$6(payload) && (payload.error !== void 0 || typeof payload.code === "number" && payload.code !== 0)) throw invalidCapability();
|
|
9924
|
+
if (!record$6(payload) || !record$6(payload.data)) return void 0;
|
|
9917
9925
|
const capabilities = payload.data.capabilities;
|
|
9918
9926
|
if (capabilities === void 0) return void 0;
|
|
9919
9927
|
if (!Array.isArray(capabilities)) throw invalidCapability();
|
|
9920
9928
|
if (!capabilities.includes("web-fetch-v1")) return void 0;
|
|
9921
9929
|
const value = payload.data.web_fetch;
|
|
9922
|
-
if (!record$
|
|
9930
|
+
if (!record$6(value) || value.path !== FETCH_PATH || value.mode !== "extracted_content" || value.content_format !== "markdown" || value.character_unit !== "unicode_code_point" || value.security_scope !== SECURITY_SCOPE || !positive(value.max_url_characters) || !positive(value.max_body_characters) || !positive(value.max_provider_response_bytes) || !positive(value.timeout_ms) || !Array.isArray(value.allowed_ports) || value.allowed_ports.length === 0 || !value.allowed_ports.every((port) => port === 80 || port === 443)) throw invalidCapability();
|
|
9923
9931
|
return {
|
|
9924
9932
|
path: FETCH_PATH,
|
|
9925
9933
|
mode: "extracted_content",
|
|
@@ -9940,7 +9948,7 @@ function normalizedRequest(value) {
|
|
|
9940
9948
|
}
|
|
9941
9949
|
/** Decode extraction facts without claiming an observed target status, final address or completeness. */
|
|
9942
9950
|
function decodeGatewayFetchResponse(payload, requestedUrl, maxBodyCharacters) {
|
|
9943
|
-
if (!record$
|
|
9951
|
+
if (!record$6(payload) || typeof payload.requested_url !== "string" || payload.final_url !== null || payload.target_status_code !== null || payload.source_completeness !== "unknown" || typeof payload.truncated !== "boolean" || typeof payload.cached !== "boolean" || !record$6(payload.body) || payload.body.kind !== "text" || payload.body.format !== "markdown" || typeof payload.body.content !== "string" || payload.body.content.trim() === "" || payload.title !== void 0 && (typeof payload.title !== "string" || exceeds(payload.title, 4096))) throw invalidResponse();
|
|
9944
9952
|
try {
|
|
9945
9953
|
if (normalizedRequest(payload.requested_url) !== normalizedRequest(requestedUrl)) throw invalidResponse();
|
|
9946
9954
|
} catch {
|
|
@@ -9969,8 +9977,8 @@ function decodeGatewayFetchResponse(payload, requestedUrl, maxBodyCharacters) {
|
|
|
9969
9977
|
}
|
|
9970
9978
|
function dependencyFailure(error, stage) {
|
|
9971
9979
|
if (error instanceof GatewayFetchError) return error;
|
|
9972
|
-
const source = record$
|
|
9973
|
-
const details = record$
|
|
9980
|
+
const source = record$6(error) ? error : void 0;
|
|
9981
|
+
const details = record$6(source?.details) ? source.details : void 0;
|
|
9974
9982
|
const failure = gatewayFailureWithHeaders({ error: {
|
|
9975
9983
|
code: safeId(source?.code),
|
|
9976
9984
|
message: typeof source?.message === "string" ? source.message : void 0,
|
|
@@ -10053,7 +10061,7 @@ async function readJson(response, maxBytes, signal) {
|
|
|
10053
10061
|
}
|
|
10054
10062
|
function gatewayError(response, payload) {
|
|
10055
10063
|
const parsed = gatewayFailureWithHeaders(payload, response.headers);
|
|
10056
|
-
const source = record$
|
|
10064
|
+
const source = record$6(payload) && record$6(payload.error) ? payload.error : void 0;
|
|
10057
10065
|
const code = safeId(parsed.code) ?? "WEB_FETCH_FAILED";
|
|
10058
10066
|
const requestId = safeRequestId(parsed.requestId) ?? safeRequestId(response.headers.get("x-request-id"));
|
|
10059
10067
|
const wait = retryAfterMs(response.headers.get("retry-after")) ?? (positive(source?.retry_after_seconds) ? source.retry_after_seconds * 1e3 : void 0);
|
|
@@ -10481,7 +10489,7 @@ var GatewaySearchError = class extends WebError {
|
|
|
10481
10489
|
function isRecord(value) {
|
|
10482
10490
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10483
10491
|
}
|
|
10484
|
-
function text$
|
|
10492
|
+
function text$4(value) {
|
|
10485
10493
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
10486
10494
|
}
|
|
10487
10495
|
/** The gateway's own words for a failure, for error messages: ` (CODE: message)`. */
|
|
@@ -10563,9 +10571,9 @@ function mapSearchResponse(payload) {
|
|
|
10563
10571
|
const sources = [];
|
|
10564
10572
|
for (const item of payload.results) {
|
|
10565
10573
|
if (!isRecord(item) || typeof item.url !== "string" || !URL.canParse(item.url)) continue;
|
|
10566
|
-
const title = text$
|
|
10567
|
-
const snippet = text$
|
|
10568
|
-
const publishedAt = text$
|
|
10574
|
+
const title = text$4(item.title);
|
|
10575
|
+
const snippet = text$4(item.snippet);
|
|
10576
|
+
const publishedAt = text$4(item.published_at);
|
|
10569
10577
|
sources.push({
|
|
10570
10578
|
url: item.url,
|
|
10571
10579
|
...title === void 0 ? {} : { title },
|
|
@@ -10573,7 +10581,7 @@ function mapSearchResponse(payload) {
|
|
|
10573
10581
|
...publishedAt === void 0 ? {} : { publishedAt }
|
|
10574
10582
|
});
|
|
10575
10583
|
}
|
|
10576
|
-
const answers = (Array.isArray(payload.answers) ? payload.answers : []).map((answer) => text$
|
|
10584
|
+
const answers = (Array.isArray(payload.answers) ? payload.answers : []).map((answer) => text$4(answer) ?? (isRecord(answer) ? text$4(answer.answer) : void 0)).filter((answer) => answer !== void 0);
|
|
10577
10585
|
return {
|
|
10578
10586
|
...answers.length === 0 ? {} : { content: answers.join("\n\n") },
|
|
10579
10587
|
sources,
|
|
@@ -11754,6 +11762,514 @@ function quotedCny(quote) {
|
|
|
11754
11762
|
return quote.status === "estimate" ? format(roundHalfUp(decimal(quote.amountCny), 2), 2) : void 0;
|
|
11755
11763
|
}
|
|
11756
11764
|
//#endregion
|
|
11765
|
+
//#region src/audio/voice-profiles.ts
|
|
11766
|
+
/**
|
|
11767
|
+
* Voice profiles (音色): a user's own singing voice, kept by the gateway under a
|
|
11768
|
+
* `vp_…` id that `audio_generate` passes as `voice_id` to a model declaring it
|
|
11769
|
+
* (Suno V6 音色翻唱). The gateway's OpenAI-style endpoints:
|
|
11770
|
+
*
|
|
11771
|
+
* | call | what |
|
|
11772
|
+
* | -------------------------------------- | -------------------------------------- |
|
|
11773
|
+
* | `POST /v1/audio/voice-profiles` | `{ model, file_url, title }` → profile |
|
|
11774
|
+
* | `GET /v1/audio/voice-profiles` | the account's profiles |
|
|
11775
|
+
* | `DELETE /v1/audio/voice-profiles/{id}` | close one for good |
|
|
11776
|
+
*
|
|
11777
|
+
* Creating a profile is free and makes no song. The audio is checked here first
|
|
11778
|
+
* (type, ≤ 10 MiB, 6–60 s), uploaded to the media library under the
|
|
11779
|
+
* `audio_reference` purpose like speech references, and its public HTTPS link
|
|
11780
|
+
* goes in `file_url`. A profile is usable only once its status is `ready`.
|
|
11781
|
+
*
|
|
11782
|
+
* Only `vp_…` ids ever cross this module: a provider's own voice id is never
|
|
11783
|
+
* read out of an answer, never accepted as input, and is scrubbed from the
|
|
11784
|
+
* failure reasons shown to the user.
|
|
11785
|
+
* @module dsh-vibedev/audio/voice-profiles
|
|
11786
|
+
*/
|
|
11787
|
+
/** The gateway endpoint. */
|
|
11788
|
+
const VOICE_PROFILES_PATH = "/v1/audio/voice-profiles";
|
|
11789
|
+
/** The model a profile is created for. */
|
|
11790
|
+
const VOICE_PROFILE_MODEL = "suno-v6-vibedev";
|
|
11791
|
+
/** The only id form accepted or shown. */
|
|
11792
|
+
const VOICE_PROFILE_ID = /^vp_[A-Za-z0-9_-]{1,120}$/;
|
|
11793
|
+
/** The media-library purpose the voice sample is uploaded under. */
|
|
11794
|
+
const VOICE_PROFILE_PURPOSE = "audio_reference";
|
|
11795
|
+
/** What the gateway takes as a voice sample. */
|
|
11796
|
+
const VOICE_SAMPLE_LIMITS = {
|
|
11797
|
+
maxBytes: 10485760,
|
|
11798
|
+
minSeconds: 6,
|
|
11799
|
+
maxSeconds: 60,
|
|
11800
|
+
/** Below this the voice is usually less faithful; the interfaces recommend it. */
|
|
11801
|
+
recommendedMinSeconds: 10,
|
|
11802
|
+
extensions: [
|
|
11803
|
+
"mp3",
|
|
11804
|
+
"wav",
|
|
11805
|
+
"m4a",
|
|
11806
|
+
"aac",
|
|
11807
|
+
"flac",
|
|
11808
|
+
"ogg"
|
|
11809
|
+
],
|
|
11810
|
+
mimes: [
|
|
11811
|
+
"audio/mpeg",
|
|
11812
|
+
"audio/mp3",
|
|
11813
|
+
"audio/wav",
|
|
11814
|
+
"audio/x-wav",
|
|
11815
|
+
"audio/wave",
|
|
11816
|
+
"audio/vnd.wave",
|
|
11817
|
+
"audio/mp4",
|
|
11818
|
+
"audio/x-m4a",
|
|
11819
|
+
"audio/m4a",
|
|
11820
|
+
"audio/aac",
|
|
11821
|
+
"audio/x-aac",
|
|
11822
|
+
"audio/flac",
|
|
11823
|
+
"audio/x-flac",
|
|
11824
|
+
"audio/ogg"
|
|
11825
|
+
]
|
|
11826
|
+
};
|
|
11827
|
+
/** How long the creation request may take: Suno can need well over a minute for a longer sample. */
|
|
11828
|
+
const VOICE_CREATE_TIMEOUT_MS = 18e4;
|
|
11829
|
+
/**
|
|
11830
|
+
* The creation's `Idempotency-Key`: the same sample under the same title always sends the same key, so a retry is the
|
|
11831
|
+
* same operation to a gateway that deduplicates by it; a different title is a different profile.
|
|
11832
|
+
* @param data - the sample's bytes.
|
|
11833
|
+
* @param title - the checked title.
|
|
11834
|
+
* @returns `vp-` and 32 hex digits.
|
|
11835
|
+
*/
|
|
11836
|
+
function voiceIdempotencyKey(data, title) {
|
|
11837
|
+
const sample = createHash("sha256").update(data).digest("hex");
|
|
11838
|
+
return `vp-${createHash("sha256").update(`${sample}\n${title}`).digest("hex").slice(0, 32)}`;
|
|
11839
|
+
}
|
|
11840
|
+
/** A creation whose outcome the client cannot know: no answer in time, no connection, or the gateway's 504. */
|
|
11841
|
+
function voiceOutcomeUnknown(error) {
|
|
11842
|
+
return error instanceof MediaError && (error.code === "GATEWAY_TIMEOUT" || error.code === "GATEWAY_UNREACHABLE" || error.details.status === 504);
|
|
11843
|
+
}
|
|
11844
|
+
/**
|
|
11845
|
+
* Provider refusals and what they mean, checked in order against the reason and the code (Suno refuses a sample that
|
|
11846
|
+
* "matches an existing recording", for one). A reason none of them matches is shown as it came, scrubbed.
|
|
11847
|
+
*/
|
|
11848
|
+
const VOICE_REJECTIONS = [
|
|
11849
|
+
{
|
|
11850
|
+
kind: "similar_recording",
|
|
11851
|
+
pattern: /match(?:es|ed)? (?:an? )?existing recording|similar to (?:an? )?(?:existing|known) (?:recording|song|track)|existing (?:recording|track) match|copyright|copyrighted|already exists in (?:the )?(?:catalog|library)|duplicate recording/i,
|
|
11852
|
+
en: "This sample is too similar to an existing recording. Use a different clean, original vocal.",
|
|
11853
|
+
zh: "这段样本和已有录音太像,请换一段干净、独特的人声。"
|
|
11854
|
+
},
|
|
11855
|
+
{
|
|
11856
|
+
kind: "too_short",
|
|
11857
|
+
pattern: /too short|shorter than|at least \d+(?:\.\d+)? ?s(?:ec(?:ond)?s?)?\b|minimum (?:duration|length)|duration (?:is )?below/i,
|
|
11858
|
+
en: "This sample is too short: at least 6 seconds are needed (10–60 s works best).",
|
|
11859
|
+
zh: "样本太短:至少需要 6 秒(建议 10–60 秒)。"
|
|
11860
|
+
},
|
|
11861
|
+
{
|
|
11862
|
+
kind: "too_long",
|
|
11863
|
+
pattern: /too long|longer than|at most \d+(?:\.\d+)? ?s(?:ec(?:ond)?s?)?\b|maximum (?:duration|length)|duration (?:is )?(?:above|exceeds?)|exceeds? (?:the )?(?:max(?:imum)? )?duration/i,
|
|
11864
|
+
en: "This sample is too long: at most 60 seconds. Trim it to 10–60 s of clean vocals.",
|
|
11865
|
+
zh: "样本太长:最多 60 秒,请剪到 10–60 秒的干净人声。"
|
|
11866
|
+
},
|
|
11867
|
+
{
|
|
11868
|
+
kind: "format",
|
|
11869
|
+
pattern: /unsupported (?:audio |file )?(?:format|type|codec)|invalid (?:audio |file )?(?:format|type)|format (?:is )?not supported|could not (?:decode|read|parse) (?:the )?(?:audio|file)|corrupt(?:ed)? (?:audio|file)/i,
|
|
11870
|
+
en: "This audio format is not supported, or the file could not be read. Use mp3, wav, m4a, aac, flac or ogg.",
|
|
11871
|
+
zh: "音频格式不支持或文件无法读取,请使用 mp3、wav、m4a、aac、flac 或 ogg。"
|
|
11872
|
+
},
|
|
11873
|
+
{
|
|
11874
|
+
kind: "not_clean_vocal",
|
|
11875
|
+
pattern: /no (?:clear |detectable |audible )?(?:vocals?|voice|singing)|not (?:a )?clean vocal|vocals? not (?:detected|found|clear)|background (?:music|noise)|accompaniment|instrumental|multiple (?:voices|singers|speakers)|too (?:much )?noisy|noise level/i,
|
|
11876
|
+
en: "This is not a clean solo vocal. Use a recording of one voice without accompaniment or background noise.",
|
|
11877
|
+
zh: "这不是干净的人声:请换一段只有一个人声、不带伴奏和杂音的录音。"
|
|
11878
|
+
}
|
|
11879
|
+
];
|
|
11880
|
+
/**
|
|
11881
|
+
* The plain meaning of a provider refusal.
|
|
11882
|
+
* @param reason - the provider's reason, and/or its code.
|
|
11883
|
+
* @returns the rejection, or undefined when none matches.
|
|
11884
|
+
*/
|
|
11885
|
+
function voiceRejectionOf(...texts) {
|
|
11886
|
+
const text = texts.filter((item) => item !== void 0).join(" ").replace(/[_-]+/g, " ");
|
|
11887
|
+
return text === "" ? void 0 : VOICE_REJECTIONS.find((rule) => rule.pattern.test(text));
|
|
11888
|
+
}
|
|
11889
|
+
const record$5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
11890
|
+
const text$3 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
11891
|
+
const READY = /* @__PURE__ */ new Set([
|
|
11892
|
+
"ready",
|
|
11893
|
+
"active",
|
|
11894
|
+
"available",
|
|
11895
|
+
"succeeded",
|
|
11896
|
+
"success",
|
|
11897
|
+
"completed"
|
|
11898
|
+
]);
|
|
11899
|
+
const FAILED$1 = /* @__PURE__ */ new Set([
|
|
11900
|
+
"failed",
|
|
11901
|
+
"failure",
|
|
11902
|
+
"error",
|
|
11903
|
+
"rejected",
|
|
11904
|
+
"invalid",
|
|
11905
|
+
"cancelled",
|
|
11906
|
+
"canceled",
|
|
11907
|
+
"expired"
|
|
11908
|
+
]);
|
|
11909
|
+
const DELETED = /* @__PURE__ */ new Set([
|
|
11910
|
+
"deleted",
|
|
11911
|
+
"closed",
|
|
11912
|
+
"removed",
|
|
11913
|
+
"disabled"
|
|
11914
|
+
]);
|
|
11915
|
+
/** Map the gateway's status word; anything not settled counts as still being made. */
|
|
11916
|
+
function voiceStatusOf(raw) {
|
|
11917
|
+
const value = raw?.toLowerCase();
|
|
11918
|
+
if (value === void 0) return "processing";
|
|
11919
|
+
if (READY.has(value)) return "ready";
|
|
11920
|
+
if (FAILED$1.has(value)) return "failed";
|
|
11921
|
+
if (DELETED.has(value)) return "deleted";
|
|
11922
|
+
return "processing";
|
|
11923
|
+
}
|
|
11924
|
+
/**
|
|
11925
|
+
* A failure reason safe to show: no links, bearer tokens or long opaque ids (a provider's voice id would be one),
|
|
11926
|
+
* at most 300 characters. `vp_…` ids stay.
|
|
11927
|
+
*/
|
|
11928
|
+
function scrubReason(value) {
|
|
11929
|
+
const clean = value.replace(/https?:\/\/[^\s)\]}>"']+/gi, "[link]").replace(/\b(?:Bearer\s+\S+|vdat_\S+|sk-\S+|eyJ[\w-]+\.[\w.-]+)/gi, "[redacted]").replace(/\b(?!vp_)[A-Za-z0-9][A-Za-z0-9_-]{23,}\b/g, "[id]").replace(/[\r\n\t]+/g, " ").trim();
|
|
11930
|
+
const chars = [...clean];
|
|
11931
|
+
return chars.length <= 300 ? clean : `${chars.slice(0, 299).join("")}…`;
|
|
11932
|
+
}
|
|
11933
|
+
function isoOf(value) {
|
|
11934
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
|
|
11935
|
+
const ms = value < 0xe8d4a51000 ? value * 1e3 : value;
|
|
11936
|
+
const date = new Date(ms);
|
|
11937
|
+
return Number.isFinite(date.getTime()) ? date.toISOString() : void 0;
|
|
11938
|
+
}
|
|
11939
|
+
const raw = text$3(value);
|
|
11940
|
+
if (raw === void 0) return void 0;
|
|
11941
|
+
const parsed = Date.parse(raw);
|
|
11942
|
+
return Number.isFinite(parsed) ? new Date(parsed).toISOString() : void 0;
|
|
11943
|
+
}
|
|
11944
|
+
function secondsOf(raw) {
|
|
11945
|
+
for (const key of [
|
|
11946
|
+
"duration_seconds",
|
|
11947
|
+
"duration",
|
|
11948
|
+
"audio_duration_seconds",
|
|
11949
|
+
"audio_duration"
|
|
11950
|
+
]) {
|
|
11951
|
+
const value = raw[key];
|
|
11952
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
11953
|
+
}
|
|
11954
|
+
const ms = raw.duration_ms;
|
|
11955
|
+
return typeof ms === "number" && Number.isFinite(ms) && ms > 0 ? ms / 1e3 : void 0;
|
|
11956
|
+
}
|
|
11957
|
+
/**
|
|
11958
|
+
* Read one profile from a gateway answer. Only the allow-listed fields are kept, and an entry whose id is not a
|
|
11959
|
+
* `vp_…` id is dropped whole, so a provider id can never reach a caller.
|
|
11960
|
+
* @param value - one entry, or `{ data: entry }`.
|
|
11961
|
+
* @returns the profile, or undefined.
|
|
11962
|
+
*/
|
|
11963
|
+
function parseVoiceProfile(value) {
|
|
11964
|
+
const outer = record$5(value);
|
|
11965
|
+
const raw = record$5(outer?.data) !== void 0 && outer?.id === void 0 ? record$5(outer?.data) : outer;
|
|
11966
|
+
if (raw === void 0) return void 0;
|
|
11967
|
+
const id = text$3(raw.id) ?? text$3(raw.voice_profile_id);
|
|
11968
|
+
if (id === void 0 || !VOICE_PROFILE_ID.test(id)) return void 0;
|
|
11969
|
+
const rawStatus = text$3(raw.status) ?? text$3(raw.state);
|
|
11970
|
+
const status = voiceStatusOf(rawStatus);
|
|
11971
|
+
const error = record$5(raw.error);
|
|
11972
|
+
const reason = text$3(error?.message) ?? text$3(raw.failure_reason) ?? text$3(raw.error_message) ?? text$3(raw.reason) ?? text$3(raw.error);
|
|
11973
|
+
const code = text$3(error?.code) ?? text$3(raw.failure_code) ?? text$3(raw.error_code);
|
|
11974
|
+
const title = text$3(raw.title) ?? text$3(raw.name);
|
|
11975
|
+
const seconds = secondsOf(raw);
|
|
11976
|
+
const createdAt = isoOf(raw.created_at) ?? isoOf(raw.created);
|
|
11977
|
+
const model = text$3(raw.model);
|
|
11978
|
+
const rejection = status === "failed" ? voiceRejectionOf(reason, code) : void 0;
|
|
11979
|
+
return {
|
|
11980
|
+
id,
|
|
11981
|
+
status,
|
|
11982
|
+
...title === void 0 ? {} : { title: [...title].slice(0, 160).join("") },
|
|
11983
|
+
...rawStatus === void 0 ? {} : { rawStatus: rawStatus.slice(0, 40) },
|
|
11984
|
+
...status === "failed" && reason !== void 0 ? { failureReason: scrubReason(reason) } : {},
|
|
11985
|
+
...rejection === void 0 ? {} : { failureKind: rejection.kind },
|
|
11986
|
+
...status === "failed" && code !== void 0 && /^[\w.-]{1,80}$/.test(code) ? { failureCode: code } : {},
|
|
11987
|
+
...seconds === void 0 ? {} : { durationSeconds: Math.round(seconds * 10) / 10 },
|
|
11988
|
+
...createdAt === void 0 ? {} : { createdAt },
|
|
11989
|
+
...model === void 0 || !/^[\w.-]{1,80}$/.test(model) ? {} : { model }
|
|
11990
|
+
};
|
|
11991
|
+
}
|
|
11992
|
+
/**
|
|
11993
|
+
* Read a list answer: `{ data: [...] }`, `{ items: [...] }`, `{ data: { items: [...] } }` or a bare array.
|
|
11994
|
+
* @param value - the answer.
|
|
11995
|
+
* @returns the profiles, newest first when the gateway dates them.
|
|
11996
|
+
*/
|
|
11997
|
+
function parseVoiceProfiles(value) {
|
|
11998
|
+
const outer = record$5(value);
|
|
11999
|
+
const inner = record$5(outer?.data);
|
|
12000
|
+
return (Array.isArray(value) ? value : Array.isArray(outer?.data) ? outer.data : Array.isArray(outer?.items) ? outer.items : Array.isArray(inner?.items) ? inner.items : Array.isArray(inner?.data) ? inner.data : []).slice(0, 500).map(parseVoiceProfile).filter((item) => item !== void 0 && item.status !== "deleted").sort((a, b) => (b.createdAt ?? "").localeCompare(a.createdAt ?? ""));
|
|
12001
|
+
}
|
|
12002
|
+
/**
|
|
12003
|
+
* Check a profile id before it is sent: only `vp_…` ids.
|
|
12004
|
+
* @param id - what the caller passed.
|
|
12005
|
+
* @returns the trimmed id.
|
|
12006
|
+
* @throws {@link MediaError} `VOICE_PROFILE_ID_INVALID` for anything else (a provider's own id included).
|
|
12007
|
+
*/
|
|
12008
|
+
function checkVoiceProfileId(id, field = "id") {
|
|
12009
|
+
const value = typeof id === "string" ? id.trim() : "";
|
|
12010
|
+
if (!VOICE_PROFILE_ID.test(value)) throw localInputError("A voice profile is named by its vp_… id (voice_profile_list shows them); no other voice id is accepted.", "VOICE_PROFILE_ID_INVALID", { field });
|
|
12011
|
+
return value;
|
|
12012
|
+
}
|
|
12013
|
+
/** Check a title: required, trimmed, at most {@link VOICE_TITLE_MAX} characters, no control characters. */
|
|
12014
|
+
function checkVoiceTitle(title) {
|
|
12015
|
+
const value = typeof title === "string" ? title.replace(/\s+/g, " ").trim() : "";
|
|
12016
|
+
if (value === "") throw localInputError("A voice profile needs a name (title).", "VOICE_TITLE_REQUIRED", { field: "title" });
|
|
12017
|
+
if (/[\u0000-\u001f\u007f]/.test(value)) throw localInputError("The voice profile name may not hold control characters.", "VOICE_TITLE_INVALID", { field: "title" });
|
|
12018
|
+
if ([...value].length > 80) throw localInputError(`The voice profile name is ${[...value].length} characters; at most 80.`, "VOICE_TITLE_TOO_LONG", { field: "title" });
|
|
12019
|
+
return value;
|
|
12020
|
+
}
|
|
12021
|
+
/** The file extension of a name, lower-case, without the dot. */
|
|
12022
|
+
function extensionOf(name) {
|
|
12023
|
+
return /\.([a-z0-9]{2,5})$/i.exec(name.trim())?.[1]?.toLowerCase();
|
|
12024
|
+
}
|
|
12025
|
+
/**
|
|
12026
|
+
* The length of a PCM WAV or a FLAC file from its header, when it can be read without decoding.
|
|
12027
|
+
* Other formats are measured by the media library after the upload.
|
|
12028
|
+
* @param data - the file bytes.
|
|
12029
|
+
* @returns seconds, or undefined.
|
|
12030
|
+
*/
|
|
12031
|
+
function headerSeconds(data) {
|
|
12032
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
12033
|
+
const ascii = (at, length) => at + length <= data.length ? String.fromCharCode(...data.subarray(at, at + length)) : "";
|
|
12034
|
+
if (ascii(0, 4) === "RIFF" && ascii(8, 4) === "WAVE") {
|
|
12035
|
+
let byteRate;
|
|
12036
|
+
for (let at = 12; at + 8 <= data.length;) {
|
|
12037
|
+
const id = ascii(at, 4), size = view.getUint32(at + 4, true);
|
|
12038
|
+
if (id === "fmt " && at + 16 <= data.length) byteRate = view.getUint32(at + 16, true);
|
|
12039
|
+
if (id === "data") {
|
|
12040
|
+
if (byteRate === void 0 || byteRate === 0) return void 0;
|
|
12041
|
+
const bytes = size === 0 || size === 4294967295 ? data.length - at - 8 : Math.min(size, data.length - at - 8);
|
|
12042
|
+
return bytes > 0 ? bytes / byteRate : void 0;
|
|
12043
|
+
}
|
|
12044
|
+
at += 8 + size + size % 2;
|
|
12045
|
+
}
|
|
12046
|
+
return;
|
|
12047
|
+
}
|
|
12048
|
+
if (ascii(0, 4) === "fLaC" && data.length >= 42 && (data[4] & 127) === 0) {
|
|
12049
|
+
const b = data.subarray(8, 42);
|
|
12050
|
+
const rate = b[10] << 12 | b[11] << 4 | b[12] >> 4;
|
|
12051
|
+
const total = (b[13] & 15) * 2 ** 32 + (b[14] << 24 >>> 0) + (b[15] << 16) + (b[16] << 8) + b[17];
|
|
12052
|
+
return rate > 0 && total > 0 ? total / rate : void 0;
|
|
12053
|
+
}
|
|
12054
|
+
}
|
|
12055
|
+
/**
|
|
12056
|
+
* Check a voice sample before anything is uploaded: type (extension or sniffed MIME on the allow-list), size, and —
|
|
12057
|
+
* when its header tells — its length.
|
|
12058
|
+
* @param media - the loaded file.
|
|
12059
|
+
* @returns the length read from the header, when there was one.
|
|
12060
|
+
* @throws {@link MediaError} with `rule` naming the broken limit.
|
|
12061
|
+
*/
|
|
12062
|
+
function checkVoiceSample(media) {
|
|
12063
|
+
const limits = VOICE_SAMPLE_LIMITS;
|
|
12064
|
+
const extension = extensionOf(media.name);
|
|
12065
|
+
const mime = media.mime.toLowerCase().split(";")[0]?.trim() ?? "";
|
|
12066
|
+
if (!(limits.mimes.includes(mime) || mime === "application/octet-stream" && extension !== void 0 && limits.extensions.includes(extension))) throw voiceRule(`"${media.source}" is ${mime || "of an unknown type"}; a voice sample must be ${limits.extensions.join(", ")}.`, "VOICE_SAMPLE_FORMAT", "format");
|
|
12067
|
+
if (media.data.byteLength === 0) throw voiceRule(`"${media.source}" is empty.`, "VOICE_SAMPLE_EMPTY", "empty");
|
|
12068
|
+
if (media.data.byteLength > limits.maxBytes) throw voiceRule(`"${media.source}" is ${(media.data.byteLength / 1048576).toFixed(1)} MiB; a voice sample may be at most 10 MiB.`, "VOICE_SAMPLE_TOO_LARGE", "too_large");
|
|
12069
|
+
const seconds = headerSeconds(media.data);
|
|
12070
|
+
if (seconds !== void 0) checkVoiceSeconds(seconds, media.source);
|
|
12071
|
+
return seconds === void 0 ? {} : { seconds };
|
|
12072
|
+
}
|
|
12073
|
+
/** Check a measured length against 6–60 s. */
|
|
12074
|
+
function checkVoiceSeconds(seconds, source) {
|
|
12075
|
+
const limits = VOICE_SAMPLE_LIMITS;
|
|
12076
|
+
if (seconds < limits.minSeconds) throw voiceRule(`"${source}" is ${seconds.toFixed(1)} s; a voice sample needs at least ${limits.minSeconds} s (10–60 s of clean vocals works best).`, "VOICE_SAMPLE_TOO_SHORT", "too_short");
|
|
12077
|
+
if (seconds > limits.maxSeconds) throw voiceRule(`"${source}" is ${seconds.toFixed(1)} s; a voice sample may be at most ${limits.maxSeconds} s. Trim it to 10–60 s of clean vocals.`, "VOICE_SAMPLE_TOO_LONG", "too_long");
|
|
12078
|
+
}
|
|
12079
|
+
function voiceRule(message, code, rule) {
|
|
12080
|
+
return localInputError(message, code, {
|
|
12081
|
+
field: "source",
|
|
12082
|
+
rule
|
|
12083
|
+
});
|
|
12084
|
+
}
|
|
12085
|
+
/** The voice-profile endpoints, with the local checks and the upload in front of a creation. */
|
|
12086
|
+
var VoiceProfiles = class {
|
|
12087
|
+
options;
|
|
12088
|
+
sleep;
|
|
12089
|
+
now;
|
|
12090
|
+
constructor(options) {
|
|
12091
|
+
this.options = options;
|
|
12092
|
+
this.sleep = options.sleep ?? delay$1;
|
|
12093
|
+
this.now = options.now ?? Date.now;
|
|
12094
|
+
}
|
|
12095
|
+
request(options) {
|
|
12096
|
+
return {
|
|
12097
|
+
timeoutMs: 3e4,
|
|
12098
|
+
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
12099
|
+
...options.isCurrentAccount === void 0 ? {} : { isCurrentAccount: options.isCurrentAccount }
|
|
12100
|
+
};
|
|
12101
|
+
}
|
|
12102
|
+
/** The account's profiles (closed ones left out). */
|
|
12103
|
+
async list(options = {}) {
|
|
12104
|
+
return parseVoiceProfiles(await this.options.http.json(VOICE_PROFILES_PATH, this.request(options)));
|
|
12105
|
+
}
|
|
12106
|
+
/** One profile, read from the list (the gateway offers no single read). */
|
|
12107
|
+
async get(id, options = {}) {
|
|
12108
|
+
const wanted = checkVoiceProfileId(id);
|
|
12109
|
+
return (await this.list(options)).find((profile) => profile.id === wanted);
|
|
12110
|
+
}
|
|
12111
|
+
/**
|
|
12112
|
+
* Check, upload and create one profile. Nothing is created when a check fails, the upload fails, the media library
|
|
12113
|
+
* hands back no public HTTPS link, or the measured length is outside 6–60 s.
|
|
12114
|
+
* @param media - the loaded voice sample.
|
|
12115
|
+
* @param title - the profile's name.
|
|
12116
|
+
* @param options - cancellation and the account guard.
|
|
12117
|
+
* @returns the profile as the gateway answered (often still being made).
|
|
12118
|
+
*/
|
|
12119
|
+
async create(media, title, options = {}) {
|
|
12120
|
+
const name = checkVoiceTitle(title);
|
|
12121
|
+
const local = checkVoiceSample(media);
|
|
12122
|
+
let asset;
|
|
12123
|
+
try {
|
|
12124
|
+
asset = await this.options.upload(media, VOICE_PROFILE_PURPOSE, options.signal);
|
|
12125
|
+
} catch (error) {
|
|
12126
|
+
if (error instanceof MediaError && (error.code === "ABORTED" || error.code === "ACCOUNT_CHANGED" || error.code === "NOT_SIGNED_IN")) throw error;
|
|
12127
|
+
throw new MediaError(`The voice sample "${media.source}" could not be uploaded to the VibeDev media library${error instanceof Error ? ` (${error.message})` : ""}. No voice profile was created.`, "VOICE_SAMPLE_UPLOAD_FAILED", {
|
|
12128
|
+
stage: "upload",
|
|
12129
|
+
retryable: true,
|
|
12130
|
+
submissionState: "not_submitted",
|
|
12131
|
+
billingState: "not_charged"
|
|
12132
|
+
}, { cause: error });
|
|
12133
|
+
}
|
|
12134
|
+
const measured = asset.durationMs === void 0 ? local.seconds : asset.durationMs / 1e3;
|
|
12135
|
+
if (measured === void 0) throw localInputError(`The length of "${media.source}" could not be measured, so the 6–60 s limit cannot be checked. Export it as a standard WAV or MP3 and try again.`, "VOICE_SAMPLE_DURATION_UNKNOWN", {
|
|
12136
|
+
field: "source",
|
|
12137
|
+
rule: "duration_unknown"
|
|
12138
|
+
});
|
|
12139
|
+
checkVoiceSeconds(measured, media.source);
|
|
12140
|
+
if (!/^https:\/\//i.test(asset.referenceUrl)) throw new MediaError("The VibeDev media library returned no public HTTPS link for the voice sample, so no voice profile was created. Try again later.", "VOICE_SAMPLE_URL_UNAVAILABLE", {
|
|
12141
|
+
stage: "upload",
|
|
12142
|
+
retryable: true,
|
|
12143
|
+
submissionState: "not_submitted",
|
|
12144
|
+
billingState: "not_charged"
|
|
12145
|
+
});
|
|
12146
|
+
const before = await this.list(options).then((list) => new Set(list.map((item) => item.id)), (error) => {
|
|
12147
|
+
if (error instanceof MediaError && (error.code === "ABORTED" || error.code === "ACCOUNT_CHANGED")) throw error;
|
|
12148
|
+
});
|
|
12149
|
+
let answer;
|
|
12150
|
+
try {
|
|
12151
|
+
answer = await this.options.http.json(VOICE_PROFILES_PATH, {
|
|
12152
|
+
...this.request(options),
|
|
12153
|
+
timeoutMs: VOICE_CREATE_TIMEOUT_MS,
|
|
12154
|
+
method: "POST",
|
|
12155
|
+
idempotencyKey: voiceIdempotencyKey(media.data, name),
|
|
12156
|
+
busyRetries: 0,
|
|
12157
|
+
json: {
|
|
12158
|
+
model: VOICE_PROFILE_MODEL,
|
|
12159
|
+
file_url: asset.referenceUrl,
|
|
12160
|
+
title: name
|
|
12161
|
+
}
|
|
12162
|
+
});
|
|
12163
|
+
} catch (error) {
|
|
12164
|
+
if (voiceOutcomeUnknown(error)) {
|
|
12165
|
+
const confirmed = await this.confirmCreated(before, name, options);
|
|
12166
|
+
return {
|
|
12167
|
+
...confirmed,
|
|
12168
|
+
...confirmed.durationSeconds === void 0 ? { durationSeconds: Math.round(measured * 10) / 10 } : {}
|
|
12169
|
+
};
|
|
12170
|
+
}
|
|
12171
|
+
const rejection = error instanceof MediaError && (error.details.status ?? 0) >= 400 && (error.details.status ?? 0) < 500 ? voiceRejectionOf(error.message, error.code) : void 0;
|
|
12172
|
+
if (rejection === void 0) throw error;
|
|
12173
|
+
throw new MediaError(`${rejection.en} ${rejection.zh} (${scrubReason(error.message)}) No voice profile was created and nothing was charged.`, "VOICE_SAMPLE_REJECTED", {
|
|
12174
|
+
...error.details,
|
|
12175
|
+
category: "invalid_input",
|
|
12176
|
+
rule: rejection.kind,
|
|
12177
|
+
field: "source",
|
|
12178
|
+
submissionState: "rejected",
|
|
12179
|
+
billingState: "not_charged"
|
|
12180
|
+
}, { cause: error });
|
|
12181
|
+
}
|
|
12182
|
+
const profile = parseVoiceProfile(answer);
|
|
12183
|
+
if (profile === void 0) throw new MediaError("The VibeDev gateway accepted the voice sample but answered without a vp_… profile id. Check voice_profile_list before trying again.", "VOICE_PROFILE_BAD_RESPONSE", {
|
|
12184
|
+
stage: "submit",
|
|
12185
|
+
retryable: false
|
|
12186
|
+
});
|
|
12187
|
+
return {
|
|
12188
|
+
...profile,
|
|
12189
|
+
...profile.durationSeconds === void 0 ? { durationSeconds: Math.round(measured * 10) / 10 } : {},
|
|
12190
|
+
...profile.title === void 0 ? { title: name } : {}
|
|
12191
|
+
};
|
|
12192
|
+
}
|
|
12193
|
+
/**
|
|
12194
|
+
* Find the profile a creation without an answer made: read the list (after 3 s, 5 s, then every 10 s, for up to
|
|
12195
|
+
* three minutes) for an id that was not there before, the one under the same title first. Without the earlier list,
|
|
12196
|
+
* only a profile under the same title counts.
|
|
12197
|
+
* @throws {@link MediaError} `VOICE_PROFILE_UNCONFIRMED` (retryable, outcome unknown, nothing charged) when none appears.
|
|
12198
|
+
*/
|
|
12199
|
+
async confirmCreated(before, title, options) {
|
|
12200
|
+
const started = this.now();
|
|
12201
|
+
const limit = this.options.confirmTimeoutMs ?? 18e4;
|
|
12202
|
+
const steps = [3e3, 5e3];
|
|
12203
|
+
for (let round = 0;; round++) {
|
|
12204
|
+
const left = started + limit - this.now();
|
|
12205
|
+
if (left <= 0) break;
|
|
12206
|
+
await this.sleep(Math.min(steps[round] ?? 1e4, left), options.signal);
|
|
12207
|
+
let list;
|
|
12208
|
+
try {
|
|
12209
|
+
list = await this.list(options);
|
|
12210
|
+
} catch (error) {
|
|
12211
|
+
if (error instanceof MediaError && (error.code === "ABORTED" || error.code === "ACCOUNT_CHANGED")) throw error;
|
|
12212
|
+
continue;
|
|
12213
|
+
}
|
|
12214
|
+
const fresh = list.filter((item) => before === void 0 ? item.title === title : !before.has(item.id));
|
|
12215
|
+
const found = fresh.find((item) => item.title === title) ?? fresh[0];
|
|
12216
|
+
if (found !== void 0) return found;
|
|
12217
|
+
}
|
|
12218
|
+
throw new MediaError("The VibeDev gateway did not answer in time while creating the voice profile. It may have been created on the gateway: refresh the list in a little while to check, and try again only if it is not there. 网关处理超时。可能已在网关侧创建,请稍后刷新列表确认;若列表没有,再重试。", "VOICE_PROFILE_UNCONFIRMED", {
|
|
12219
|
+
category: "submission_uncertain",
|
|
12220
|
+
stage: "submit",
|
|
12221
|
+
retryable: true,
|
|
12222
|
+
submissionState: "unknown",
|
|
12223
|
+
billingState: "not_charged",
|
|
12224
|
+
retryAction: "reconcile"
|
|
12225
|
+
});
|
|
12226
|
+
}
|
|
12227
|
+
/**
|
|
12228
|
+
* Close one profile for good. Songs already made with it are not affected.
|
|
12229
|
+
* @param id - a `vp_…` id.
|
|
12230
|
+
*/
|
|
12231
|
+
async remove(id, options = {}) {
|
|
12232
|
+
const wanted = checkVoiceProfileId(id);
|
|
12233
|
+
await this.options.http.send(`${VOICE_PROFILES_PATH}/${encodeURIComponent(wanted)}`, {
|
|
12234
|
+
...this.request(options),
|
|
12235
|
+
method: "DELETE",
|
|
12236
|
+
busyRetries: 0
|
|
12237
|
+
});
|
|
12238
|
+
}
|
|
12239
|
+
/**
|
|
12240
|
+
* Read the profile until it is ready or failed, or the wait runs out: 2 s, then 3 s, 5 s and every 8 s.
|
|
12241
|
+
* @param id - the profile.
|
|
12242
|
+
* @param options - cancellation, the time limit and a progress callback.
|
|
12243
|
+
* @returns the last state read; `processing` when the wait ran out.
|
|
12244
|
+
*/
|
|
12245
|
+
async waitUntilSettled(id, options = {}) {
|
|
12246
|
+
const started = this.now();
|
|
12247
|
+
const limit = options.timeoutMs ?? 18e4;
|
|
12248
|
+
const steps = [
|
|
12249
|
+
2e3,
|
|
12250
|
+
3e3,
|
|
12251
|
+
5e3
|
|
12252
|
+
];
|
|
12253
|
+
let last = {
|
|
12254
|
+
id: checkVoiceProfileId(id),
|
|
12255
|
+
status: "processing"
|
|
12256
|
+
};
|
|
12257
|
+
for (let round = 0;; round++) {
|
|
12258
|
+
const left = started + limit - this.now();
|
|
12259
|
+
if (left <= 0) return last;
|
|
12260
|
+
await this.sleep(Math.min(steps[round] ?? 8e3, left), options.signal);
|
|
12261
|
+
const found = await this.get(id, options);
|
|
12262
|
+
if (found === void 0) throw new MediaError(`Voice profile ${id} is no longer on this account (it may have been deleted).`, "VOICE_PROFILE_NOT_FOUND", {
|
|
12263
|
+
status: 404,
|
|
12264
|
+
retryable: false
|
|
12265
|
+
});
|
|
12266
|
+
last = found;
|
|
12267
|
+
options.onProgress?.(found, this.now() - started);
|
|
12268
|
+
if (found.status !== "processing") return found;
|
|
12269
|
+
}
|
|
12270
|
+
}
|
|
12271
|
+
};
|
|
12272
|
+
//#endregion
|
|
11757
12273
|
//#region src/audio/request.ts
|
|
11758
12274
|
/**
|
|
11759
12275
|
* Audio generation requests — music, podcasts and speech — checked against what
|
|
@@ -11764,7 +12280,7 @@ function quotedCny(quote) {
|
|
|
11764
12280
|
*
|
|
11765
12281
|
* | kind | wire fields |
|
|
11766
12282
|
* | ------- | --------------------------------------------------------------- |
|
|
11767
|
-
* | music | model, prompt, lyrics, genre, mood, gender
|
|
12283
|
+
* | music | model, prompt, lyrics, genre, mood, gender; as declared: style, title, instrumental, voice_id, source_audio_url, audio_weight, mode |
|
|
11768
12284
|
* | podcast | model, prompt, source_url |
|
|
11769
12285
|
* | speech | as declared; Seed: model, text_prompt, references, audio_config, watermark |
|
|
11770
12286
|
*
|
|
@@ -11810,6 +12326,38 @@ const SPEECH_ONLY = [
|
|
|
11810
12326
|
"sampleRate",
|
|
11811
12327
|
"duration"
|
|
11812
12328
|
];
|
|
12329
|
+
/** Fields that belong to music only: a voice profile and the song to cover. */
|
|
12330
|
+
const MUSIC_ONLY = ["voiceId", "sourceAudio"];
|
|
12331
|
+
/**
|
|
12332
|
+
* The mode a music request derives (see {@link MusicMode}).
|
|
12333
|
+
* @param request - the request.
|
|
12334
|
+
* @returns the mode.
|
|
12335
|
+
*/
|
|
12336
|
+
function musicModeOf(request) {
|
|
12337
|
+
if (has(request.voiceId)) return "voice_cover";
|
|
12338
|
+
if (has(request.sourceAudio)) return "cover";
|
|
12339
|
+
return "generate";
|
|
12340
|
+
}
|
|
12341
|
+
/** The song to cover: audio, or a video whose sound is used. */
|
|
12342
|
+
const SOURCE_AUDIO_MIMES = [
|
|
12343
|
+
"audio/mpeg",
|
|
12344
|
+
"audio/mp3",
|
|
12345
|
+
"audio/wav",
|
|
12346
|
+
"audio/x-wav",
|
|
12347
|
+
"audio/wave",
|
|
12348
|
+
"audio/mp4",
|
|
12349
|
+
"audio/x-m4a",
|
|
12350
|
+
"audio/aac",
|
|
12351
|
+
"audio/x-aac",
|
|
12352
|
+
"audio/flac",
|
|
12353
|
+
"audio/x-flac",
|
|
12354
|
+
"audio/ogg",
|
|
12355
|
+
"video/mp4",
|
|
12356
|
+
"video/quicktime",
|
|
12357
|
+
"video/webm"
|
|
12358
|
+
];
|
|
12359
|
+
/** The largest song to cover: the provider recommends 8–10 MB, so 10 MiB is held here before anything is uploaded. */
|
|
12360
|
+
const SOURCE_AUDIO_MAX_BYTES = 10485760;
|
|
11813
12361
|
/** Default limit on one reference file when the catalog states none. */
|
|
11814
12362
|
const DEFAULT_REFERENCE_BYTES = 20971520;
|
|
11815
12363
|
const OPERATION_ID = /^[\w-]{8,80}$/;
|
|
@@ -11841,26 +12389,26 @@ function promptFieldOf(model) {
|
|
|
11841
12389
|
"input"
|
|
11842
12390
|
].find((name) => fields.includes(name));
|
|
11843
12391
|
}
|
|
11844
|
-
function refuse(message, field) {
|
|
12392
|
+
function refuse$1(message, field) {
|
|
11845
12393
|
throw localInputError(message, "AUDIO_OPTION_INVALID", field === void 0 ? {} : { field });
|
|
11846
12394
|
}
|
|
11847
12395
|
/** Check one value against the model's declared choices for a field. */
|
|
11848
12396
|
function checkChoice(audio, wire, value) {
|
|
11849
12397
|
const choices = audio?.choices?.[wire];
|
|
11850
|
-
if (choices !== void 0 && !choices.some((choice) => choice.toLowerCase() === value.toLowerCase())) refuse(`${wire} "${value}" is not offered by this model; it takes ${choices.join(", ")}.`, wire);
|
|
12398
|
+
if (choices !== void 0 && !choices.some((choice) => choice.toLowerCase() === value.toLowerCase())) refuse$1(`${wire} "${value}" is not offered by this model; it takes ${choices.join(", ")}.`, wire);
|
|
11851
12399
|
}
|
|
11852
12400
|
/** The output format and sample rate a speech request uses, from the declared formats only. */
|
|
11853
12401
|
function audioConfigOf(model, format, sampleRate) {
|
|
11854
12402
|
const formats = model.audio?.outputFormats ?? [];
|
|
11855
12403
|
if (formats.length === 0) {
|
|
11856
|
-
if (format !== void 0 || sampleRate !== void 0) refuse(`${model.id} declares no output formats, so format and sample_rate cannot be chosen.`, "format");
|
|
12404
|
+
if (format !== void 0 || sampleRate !== void 0) refuse$1(`${model.id} declares no output formats, so format and sample_rate cannot be chosen.`, "format");
|
|
11857
12405
|
return;
|
|
11858
12406
|
}
|
|
11859
12407
|
const wanted = format?.trim().toLowerCase();
|
|
11860
12408
|
const chosen = wanted === void 0 || wanted === "" ? formats.find((item) => item.format === model.audio?.defaultFormat) ?? formats[0] : formats.find((item) => item.format === wanted);
|
|
11861
|
-
if (chosen === void 0) refuse(`${model.id} writes ${formats.map((item) => item.format).join(", ")}, not "${format}".`, "format");
|
|
12409
|
+
if (chosen === void 0) refuse$1(`${model.id} writes ${formats.map((item) => item.format).join(", ")}, not "${format}".`, "format");
|
|
11862
12410
|
if (sampleRate !== void 0) {
|
|
11863
|
-
if (chosen.sampleRates.length > 0 && !chosen.sampleRates.includes(sampleRate)) refuse(`${chosen.format.toUpperCase()} from ${model.id} takes a sample rate of ${chosen.sampleRates.join(", ")} Hz, not ${sampleRate}.`, "sample_rate");
|
|
12411
|
+
if (chosen.sampleRates.length > 0 && !chosen.sampleRates.includes(sampleRate)) refuse$1(`${chosen.format.toUpperCase()} from ${model.id} takes a sample rate of ${chosen.sampleRates.join(", ")} Hz, not ${sampleRate}.`, "sample_rate");
|
|
11864
12412
|
return {
|
|
11865
12413
|
format: chosen.format,
|
|
11866
12414
|
sample_rate: sampleRate
|
|
@@ -11888,19 +12436,24 @@ function audioRequestBody(model, request) {
|
|
|
11888
12436
|
if (fields.length === 0) throw localInputError(`${model.id} declares no request fields, so no request can be built for it.`, "AUDIO_FIELDS_UNDECLARED", { field: "model" });
|
|
11889
12437
|
if (kind !== "speech") for (const name of SPEECH_ONLY) {
|
|
11890
12438
|
const value = request[name];
|
|
11891
|
-
if (value !== void 0 && !(Array.isArray(value) && value.length === 0)) refuse(`${name === "sampleRate" ? "sample_rate" : name} is for speech; ${kind === "music" ? "music" : "a podcast"} does not take it.`, name);
|
|
12439
|
+
if (value !== void 0 && !(Array.isArray(value) && value.length === 0)) refuse$1(`${name === "sampleRate" ? "sample_rate" : name} is for speech; ${kind === "music" ? "music" : "a podcast"} does not take it.`, name);
|
|
12440
|
+
}
|
|
12441
|
+
if (kind !== "music") {
|
|
12442
|
+
for (const name of MUSIC_ONLY) if (has(request[name])) refuse$1(`${name === "voiceId" ? "voice_id" : "source_audio"} is for music; ${kind === "speech" ? "speech" : "a podcast"} does not take it.`, name);
|
|
11892
12443
|
}
|
|
11893
12444
|
const takes = (wire) => fields.includes(wire);
|
|
11894
12445
|
const body = { model: model.id };
|
|
11895
12446
|
const promptField = promptFieldOf(model);
|
|
11896
12447
|
const prompt = request.prompt?.trim();
|
|
11897
12448
|
if (has(prompt)) {
|
|
11898
|
-
if (promptField === void 0) refuse(`${model.id} takes no text prompt.`, "prompt");
|
|
11899
|
-
if (audio?.maxPromptChars !== void 0 && [...prompt].length > audio.maxPromptChars) refuse(`The text is ${[...prompt].length} characters; ${model.id} takes at most ${audio.maxPromptChars}.`, promptField);
|
|
12449
|
+
if (promptField === void 0) refuse$1(`${model.id} takes no text prompt.`, "prompt");
|
|
12450
|
+
if (audio?.maxPromptChars !== void 0 && [...prompt].length > audio.maxPromptChars) refuse$1(`The text is ${[...prompt].length} characters; ${model.id} takes at most ${audio.maxPromptChars}.`, promptField);
|
|
11900
12451
|
body[promptField] = prompt;
|
|
11901
12452
|
}
|
|
11902
12453
|
for (const [key, wire] of [
|
|
11903
12454
|
["lyrics", "lyrics"],
|
|
12455
|
+
["style", "style"],
|
|
12456
|
+
["title", "title"],
|
|
11904
12457
|
["genre", "genre"],
|
|
11905
12458
|
["mood", "mood"],
|
|
11906
12459
|
["gender", "gender"],
|
|
@@ -11908,28 +12461,53 @@ function audioRequestBody(model, request) {
|
|
|
11908
12461
|
]) {
|
|
11909
12462
|
const value = request[key]?.trim();
|
|
11910
12463
|
if (!has(value)) continue;
|
|
11911
|
-
if (!takes(wire)) refuse(`${model.id} does not take ${wire}; it takes ${fields.filter((name) => name !== "model").join(", ")}.`, wire);
|
|
12464
|
+
if (!takes(wire)) refuse$1(`${model.id} does not take ${wire}; it takes ${fields.filter((name) => name !== "model").join(", ")}.`, wire);
|
|
11912
12465
|
checkChoice(audio, wire, value);
|
|
11913
|
-
if (wire === "source_url" && !/^https?:\/\//i.test(value)) refuse("source_url must be an http(s) link.", wire);
|
|
12466
|
+
if (wire === "source_url" && !/^https?:\/\//i.test(value)) refuse$1("source_url must be an http(s) link.", wire);
|
|
11914
12467
|
body[wire] = value;
|
|
11915
12468
|
}
|
|
12469
|
+
if (request.instrumental !== void 0) {
|
|
12470
|
+
if (!takes("instrumental")) refuse$1(`${model.id} does not take instrumental.`, "instrumental");
|
|
12471
|
+
body.instrumental = request.instrumental;
|
|
12472
|
+
}
|
|
12473
|
+
if (kind === "music") {
|
|
12474
|
+
if (has(request.voiceId)) {
|
|
12475
|
+
const voiceId = checkVoiceProfileId(request.voiceId, "voice_id");
|
|
12476
|
+
if (!takes("voice_id")) refuse$1(`${model.id} does not take voice_id; a voice cover needs a music model that declares it (media_models lists the fields).`, "voice_id");
|
|
12477
|
+
if (!supportsVoiceCover(model)) refuse$1(`${model.id} does not support voice covers (it declares no supports_voice_cover), so voice_id would be ignored; leave model out to use one that does.`, "voice_id");
|
|
12478
|
+
body.voice_id = voiceId;
|
|
12479
|
+
}
|
|
12480
|
+
if (has(request.sourceAudio) && !takes("source_audio_url")) refuse$1(`${model.id} does not take source_audio_url; covering a song needs a music model that declares it (media_models lists the fields).`, "source_audio");
|
|
12481
|
+
const mode = musicModeOf(request);
|
|
12482
|
+
if (request.audioWeight !== void 0) {
|
|
12483
|
+
const weight = request.audioWeight;
|
|
12484
|
+
if (typeof weight !== "number" || !Number.isFinite(weight) || weight < 0 || weight > 1) refuse$1(`audio_weight must be a number from 0 to 1 (inclusive); ${String(weight)} was given.`, "audio_weight");
|
|
12485
|
+
if (mode === "generate") refuse$1("audio_weight (how closely the song follows the reference audio) only applies to a cover: give source_audio (上传翻唱) or voice_id (音色翻唱), or leave audio_weight out.", "audio_weight");
|
|
12486
|
+
if (!takes("audio_weight")) refuse$1(`${model.id} does not take audio_weight.`, "audio_weight");
|
|
12487
|
+
body.audio_weight = weight;
|
|
12488
|
+
}
|
|
12489
|
+
if (takes("mode")) {
|
|
12490
|
+
checkChoice(audio, "mode", mode);
|
|
12491
|
+
body.mode = mode;
|
|
12492
|
+
}
|
|
12493
|
+
} else if (request.audioWeight !== void 0) refuse$1(`audio_weight is for music covers; ${kind === "speech" ? "speech" : "a podcast"} does not take it.`, "audio_weight");
|
|
11916
12494
|
if (request.duration !== void 0) {
|
|
11917
|
-
if (!takes("duration")) refuse(`${model.id} does not take a duration.`, "duration");
|
|
12495
|
+
if (!takes("duration")) refuse$1(`${model.id} does not take a duration.`, "duration");
|
|
11918
12496
|
body.duration = request.duration;
|
|
11919
12497
|
}
|
|
11920
12498
|
if (request.watermark !== void 0) {
|
|
11921
|
-
if (!takes("watermark")) refuse(`${model.id} does not take watermark.`, "watermark");
|
|
12499
|
+
if (!takes("watermark")) refuse$1(`${model.id} does not take watermark.`, "watermark");
|
|
11922
12500
|
const fields = audio?.watermarkFields;
|
|
11923
12501
|
if (fields === void 0) body.watermark = request.watermark;
|
|
11924
12502
|
else if (fields.includes("aigc_watermark")) body.watermark = { aigc_watermark: request.watermark };
|
|
11925
|
-
else refuse(`${model.id} declares its watermark as ${fields.join(", ")}, without a switch to turn it on or off.`, "watermark");
|
|
12503
|
+
else refuse$1(`${model.id} declares its watermark as ${fields.join(", ")}, without a switch to turn it on or off.`, "watermark");
|
|
11926
12504
|
}
|
|
11927
12505
|
if (request.format !== void 0 || request.sampleRate !== void 0 || takes("audio_config")) {
|
|
11928
|
-
if (!takes("audio_config")) refuse(`${model.id} does not take an output format or sample rate.`, "format");
|
|
12506
|
+
if (!takes("audio_config")) refuse$1(`${model.id} does not take an output format or sample rate.`, "format");
|
|
11929
12507
|
const config = audioConfigOf(model, request.format, request.sampleRate);
|
|
11930
12508
|
if (config !== void 0) body.audio_config = config;
|
|
11931
12509
|
}
|
|
11932
|
-
if ((request.references?.length ?? 0) > 0 && !takes("references")) refuse(`${model.id} does not take reference audio.`, "references");
|
|
12510
|
+
if ((request.references?.length ?? 0) > 0 && !takes("references")) refuse$1(`${model.id} does not take reference audio.`, "references");
|
|
11933
12511
|
if (kind === "music" && !has(prompt)) throw localInputError("Music needs a prompt describing the song.", "AUDIO_PROMPT_REQUIRED", { field: "prompt" });
|
|
11934
12512
|
if (kind === "podcast" && !has(prompt) && body.source_url === void 0) throw localInputError("A podcast needs a prompt (the topic), a source_url, or both.", "AUDIO_PROMPT_REQUIRED", { field: "prompt" });
|
|
11935
12513
|
if (kind === "speech" && !has(prompt)) throw localInputError("Speech needs the text to speak.", "AUDIO_PROMPT_REQUIRED", { field: promptField ?? "prompt" });
|
|
@@ -11938,10 +12516,10 @@ function audioRequestBody(model, request) {
|
|
|
11938
12516
|
/** Load, check and upload the reference audio of a speech request; their measured lengths are checked too. */
|
|
11939
12517
|
async function uploadReferences(runtime, call, model, sources, body) {
|
|
11940
12518
|
const limits = model.audio?.references;
|
|
11941
|
-
if (limits === void 0) refuse(`${model.id} does not take reference audio.`, "references");
|
|
11942
|
-
if (sources.length < limits.min || sources.length > limits.max) refuse(limits.min === limits.max ? `${model.id} takes exactly ${limits.max} reference audio file(s); ${sources.length} were given.` : `${model.id} takes ${limits.min}–${limits.max} reference audio file(s); ${sources.length} were given.`, "references");
|
|
12519
|
+
if (limits === void 0) refuse$1(`${model.id} does not take reference audio.`, "references");
|
|
12520
|
+
if (sources.length < limits.min || sources.length > limits.max) refuse$1(limits.min === limits.max ? `${model.id} takes exactly ${limits.max} reference audio file(s); ${sources.length} were given.` : `${model.id} takes ${limits.min}–${limits.max} reference audio file(s); ${sources.length} were given.`, "references");
|
|
11943
12521
|
const clash = (limits.exclusiveWith ?? []).filter((name) => body[name] !== void 0);
|
|
11944
|
-
if (clash.length > 0) refuse(`Reference audio cannot be combined with ${clash.join(", ")} on ${model.id}.`, "references");
|
|
12522
|
+
if (clash.length > 0) refuse$1(`Reference audio cannot be combined with ${clash.join(", ")} on ${model.id}.`, "references");
|
|
11945
12523
|
const maxBytes = limits.maxBytes ?? DEFAULT_REFERENCE_BYTES;
|
|
11946
12524
|
const loaded = [];
|
|
11947
12525
|
for (const source of sources) {
|
|
@@ -11969,12 +12547,85 @@ async function uploadReferences(runtime, call, model, sources, body) {
|
|
|
11969
12547
|
return checked;
|
|
11970
12548
|
}
|
|
11971
12549
|
/**
|
|
12550
|
+
* Load, check and upload the song a cover is made from, and hand back its public HTTPS link. Every failure is an
|
|
12551
|
+
* explicit error: a cover never quietly becomes a plain generation.
|
|
12552
|
+
* @param runtime - the media runtime.
|
|
12553
|
+
* @param call - the tool call or host call.
|
|
12554
|
+
* @param source - a workspace path, `chat:N` (audio), `chat:video:N`, or an https link.
|
|
12555
|
+
* @returns the media library's public HTTPS link.
|
|
12556
|
+
*/
|
|
12557
|
+
async function uploadSourceAudio(runtime, call, source) {
|
|
12558
|
+
if (/^http:\/\//i.test(source)) refuse$1("source_audio must be an https link, a workspace file or a chat attachment; plain http links are not taken.", "source_audio");
|
|
12559
|
+
if (/^data:/i.test(source)) refuse$1("source_audio must be a workspace file, a chat attachment or an https link.", "source_audio");
|
|
12560
|
+
const chat = parseChatReference(source);
|
|
12561
|
+
const media = await runtime.load(call, source, chat?.kind === "video" ? "video" : "audio", SOURCE_AUDIO_MAX_BYTES).catch((error) => {
|
|
12562
|
+
if (error instanceof MediaError && error.code === "MEDIA_TOO_LARGE") throw localInputError(`The song to cover is larger than 10 MiB (${error.message}). Keep the source audio for a cover under 10 MB; trim or compress a larger file first. 翻唱源音频建议控制在 10 MB 以内,超大的请先剪辑或压缩。`, "SOURCE_AUDIO_TOO_LARGE", {
|
|
12563
|
+
field: "source_audio",
|
|
12564
|
+
rule: "too_large"
|
|
12565
|
+
});
|
|
12566
|
+
throw error;
|
|
12567
|
+
});
|
|
12568
|
+
const mime = media.mime.toLowerCase().split(";")[0]?.trim() ?? "";
|
|
12569
|
+
if (!SOURCE_AUDIO_MIMES.includes(mime)) throw localInputError(`"${media.source}" is ${mime || "of an unknown type"}; the song to cover must be audio (mp3, wav, m4a, aac, flac, ogg) or video (mp4, mov, webm).`, "SOURCE_AUDIO_MEDIA_TYPE_UNSUPPORTED", { field: "source_audio" });
|
|
12570
|
+
let asset;
|
|
12571
|
+
try {
|
|
12572
|
+
asset = await runtime.library.upload(media, "audio_reference", call.signal);
|
|
12573
|
+
} catch (error) {
|
|
12574
|
+
if (error instanceof MediaError && (error.code === "ABORTED" || error.code === "ACCOUNT_CHANGED" || error.code === "NOT_SIGNED_IN")) throw error;
|
|
12575
|
+
throw new MediaError(`The song to cover ("${media.source}") could not be uploaded to the VibeDev media library${error instanceof Error ? ` (${error.message})` : ""}. Nothing was submitted or charged.`, "SOURCE_AUDIO_UPLOAD_FAILED", {
|
|
12576
|
+
stage: "upload",
|
|
12577
|
+
retryable: true,
|
|
12578
|
+
submissionState: "not_submitted",
|
|
12579
|
+
billingState: "not_charged"
|
|
12580
|
+
}, { cause: error });
|
|
12581
|
+
}
|
|
12582
|
+
if (!/^https:\/\//i.test(asset.referenceUrl)) throw new MediaError(`The VibeDev media library returned no public HTTPS link for "${media.source}", so the cover was not submitted (nothing was charged). Try again later.`, "SOURCE_AUDIO_URL_UNAVAILABLE", {
|
|
12583
|
+
stage: "upload",
|
|
12584
|
+
retryable: true,
|
|
12585
|
+
submissionState: "not_submitted",
|
|
12586
|
+
billingState: "not_charged"
|
|
12587
|
+
});
|
|
12588
|
+
return asset.referenceUrl;
|
|
12589
|
+
}
|
|
12590
|
+
/** Whether a model sings in a voice profile, as the catalog declares it (`audio.supports_voice_cover`). */
|
|
12591
|
+
function supportsVoiceCover(model) {
|
|
12592
|
+
return model.audio?.supportsVoiceCover === true;
|
|
12593
|
+
}
|
|
12594
|
+
/**
|
|
12595
|
+
* The model of a voice cover nobody named: the first music model that declares `supports_voice_cover: true`, by
|
|
12596
|
+
* declaration only. None is an error: a model without it would ignore `voice_id` and still charge.
|
|
12597
|
+
*/
|
|
12598
|
+
async function chooseVoiceCoverModel(runtime, signal) {
|
|
12599
|
+
const found = (await runtime.models(signal)).find((candidate) => servesSlot(candidate, "music") && supportsVoiceCover(candidate));
|
|
12600
|
+
if (found !== void 0) return found;
|
|
12601
|
+
throw new MediaError("No model on this VibeDev account supports voice covers right now (none declares supports_voice_cover), so nothing was submitted or charged. 当前没有支持音色翻唱的模型。", "VOICE_COVER_MODEL_UNAVAILABLE", {
|
|
12602
|
+
category: "model_unavailable",
|
|
12603
|
+
stage: "catalog",
|
|
12604
|
+
submissionState: "not_submitted",
|
|
12605
|
+
billingState: "not_charged",
|
|
12606
|
+
retryable: false,
|
|
12607
|
+
field: "voice_id"
|
|
12608
|
+
});
|
|
12609
|
+
}
|
|
12610
|
+
/**
|
|
11972
12611
|
* Choose the model for a request: the one named (an id or an alias), else the
|
|
11973
12612
|
* pinned or first model of the kind. A named model must make the kind asked for.
|
|
12613
|
+
*
|
|
12614
|
+
* Music without a named model: a voice cover (`voice_cover`) takes the first model that declares
|
|
12615
|
+
* `supports_voice_cover: true` (see {@link chooseVoiceCoverModel}); a cover or a plain song follows `musicModel` as
|
|
12616
|
+
* before, preferring a model that declares the fields the request uses and not a voice-cover model unless
|
|
12617
|
+
* `musicModel` itself names it.
|
|
11974
12618
|
*/
|
|
11975
12619
|
async function chooseAudioModel(runtime, request, signal) {
|
|
11976
12620
|
if (request.kind === void 0 && !has(request.model)) throw localInputError("Say what to make (music, podcast or speech), or name a model.", "AUDIO_KIND_REQUIRED", { field: "type" });
|
|
11977
|
-
if (request.kind !== void 0)
|
|
12621
|
+
if (request.kind !== void 0) {
|
|
12622
|
+
if (request.kind !== "music" || has(request.model)) return runtime.pickModel("audio", request.kind, request.model, void 0, signal);
|
|
12623
|
+
if (musicModeOf(request) === "voice_cover") return chooseVoiceCoverModel(runtime, signal);
|
|
12624
|
+
const needed = [...has(request.sourceAudio) ? ["source_audio_url"] : [], ...request.audioWeight !== void 0 ? ["audio_weight"] : []];
|
|
12625
|
+
const pinned = runtime.settings.defaultModel("music").trim().toLowerCase();
|
|
12626
|
+
const accept = (candidate) => (candidate.id.toLowerCase() === pinned || !supportsVoiceCover(candidate)) && needed.every((name) => requestFieldsOf(candidate).includes(name));
|
|
12627
|
+
return runtime.pickModel("audio", "music", void 0, accept, signal);
|
|
12628
|
+
}
|
|
11978
12629
|
const model = await runtime.findModel(request.model, signal);
|
|
11979
12630
|
if (model.kind !== "audio") throw localInputError(`${model.id} is not an audio generation model.`, "MODEL_KIND_MISMATCH", { field: "model" });
|
|
11980
12631
|
if (audioKindOf(model) === void 0) throw localInputError(`${model.id} does not declare what kind of audio it makes, so it cannot be used for generation.`, "AUDIO_KIND_UNDECLARED", { field: "model" });
|
|
@@ -11998,10 +12649,18 @@ async function prepareAudioTask(runtime, call, request, save) {
|
|
|
11998
12649
|
const body = audioRequestBody(model, request);
|
|
11999
12650
|
const references = request.references ?? [];
|
|
12000
12651
|
if (references.length > 0) body.references = (await uploadReferences(runtime, call, model, references, body)).map((item) => model.audio?.references?.form === "object" ? { audio_url: item.asset.referenceUrl } : item.asset.referenceUrl);
|
|
12001
|
-
else if ((model.audio?.references?.min ?? 0) > 0) refuse(`${model.id} needs at least ${model.audio?.references?.min} reference audio file(s).`, "references");
|
|
12652
|
+
else if ((model.audio?.references?.min ?? 0) > 0) refuse$1(`${model.id} needs at least ${model.audio?.references?.min} reference audio file(s).`, "references");
|
|
12653
|
+
if (kind === "music" && has(request.sourceAudio)) body.source_audio_url = await uploadSourceAudio(runtime, call, request.sourceAudio.trim());
|
|
12002
12654
|
const quote = quoteAudio(model);
|
|
12655
|
+
const mode = kind === "music" ? musicModeOf(request) : "generate";
|
|
12003
12656
|
const what = {
|
|
12004
|
-
music: {
|
|
12657
|
+
music: mode === "voice_cover" ? {
|
|
12658
|
+
en: "a voice cover",
|
|
12659
|
+
zh: "一首音色翻唱"
|
|
12660
|
+
} : mode === "cover" ? {
|
|
12661
|
+
en: "a cover",
|
|
12662
|
+
zh: "一首翻唱"
|
|
12663
|
+
} : {
|
|
12005
12664
|
en: "a song",
|
|
12006
12665
|
zh: "一首音乐"
|
|
12007
12666
|
},
|
|
@@ -12074,6 +12733,8 @@ function audioFormOf(model) {
|
|
|
12074
12733
|
});
|
|
12075
12734
|
for (const [key, wire] of [
|
|
12076
12735
|
["lyrics", "lyrics"],
|
|
12736
|
+
["style", "style"],
|
|
12737
|
+
["title", "title"],
|
|
12077
12738
|
["genre", "genre"],
|
|
12078
12739
|
["mood", "mood"],
|
|
12079
12740
|
["gender", "gender"],
|
|
@@ -12088,6 +12749,22 @@ function audioFormOf(model) {
|
|
|
12088
12749
|
...choices === void 0 ? {} : { choices }
|
|
12089
12750
|
});
|
|
12090
12751
|
}
|
|
12752
|
+
if (kind === "music") {
|
|
12753
|
+
for (const [key, wire] of [
|
|
12754
|
+
["instrumental", "instrumental"],
|
|
12755
|
+
["voiceId", "voice_id"],
|
|
12756
|
+
["sourceAudio", "source_audio_url"],
|
|
12757
|
+
["audioWeight", "audio_weight"]
|
|
12758
|
+
]) if (fields.includes(wire)) out.push({
|
|
12759
|
+
key,
|
|
12760
|
+
wire,
|
|
12761
|
+
required: false
|
|
12762
|
+
});
|
|
12763
|
+
} else if (fields.includes("instrumental")) out.push({
|
|
12764
|
+
key: "instrumental",
|
|
12765
|
+
wire: "instrumental",
|
|
12766
|
+
required: false
|
|
12767
|
+
});
|
|
12091
12768
|
if (kind === "speech") {
|
|
12092
12769
|
if (fields.includes("references") && audio?.references !== void 0) out.push({
|
|
12093
12770
|
key: "references",
|
|
@@ -12128,7 +12805,7 @@ function audioFormOf(model) {
|
|
|
12128
12805
|
}
|
|
12129
12806
|
//#endregion
|
|
12130
12807
|
//#region src/tasks/progress.ts
|
|
12131
|
-
const record$
|
|
12808
|
+
const record$4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
12132
12809
|
const nonNegative = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
12133
12810
|
const position = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
12134
12811
|
const instant = (value) => {
|
|
@@ -12171,7 +12848,7 @@ function progressOf$1(value) {
|
|
|
12171
12848
|
return number > 1 ? number / 100 : number;
|
|
12172
12849
|
}
|
|
12173
12850
|
function timingOf(value, receivedAt) {
|
|
12174
|
-
const raw = record$
|
|
12851
|
+
const raw = record$4(value);
|
|
12175
12852
|
if (raw === void 0) return void 0;
|
|
12176
12853
|
const serverTime = instant(raw.server_time);
|
|
12177
12854
|
const skew = serverTime === void 0 ? 0 : receivedAt - serverTime;
|
|
@@ -12200,7 +12877,7 @@ function timingOf(value, receivedAt) {
|
|
|
12200
12877
|
};
|
|
12201
12878
|
}
|
|
12202
12879
|
function queueOf(value) {
|
|
12203
|
-
const raw = record$
|
|
12880
|
+
const raw = record$4(value);
|
|
12204
12881
|
if (raw === void 0) return void 0;
|
|
12205
12882
|
const facts = {
|
|
12206
12883
|
position: position(raw.position),
|
|
@@ -12876,7 +13553,7 @@ const REFERENCE_TYPES = [
|
|
|
12876
13553
|
"image/webp"
|
|
12877
13554
|
];
|
|
12878
13555
|
const SIZE = /^\d{2,5}x\d{2,5}$/;
|
|
12879
|
-
const record$
|
|
13556
|
+
const record$3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
12880
13557
|
const text$2 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
12881
13558
|
const noPaths = { readPath: () => Promise.reject(new MediaError("The gateway returned an unexpected image reference.", "GATEWAY_BAD_RESPONSE")) };
|
|
12882
13559
|
/**
|
|
@@ -12887,11 +13564,11 @@ const noPaths = { readPath: () => Promise.reject(new MediaError("The gateway ret
|
|
|
12887
13564
|
* @returns the images and the revised prompt, when the model returned one.
|
|
12888
13565
|
*/
|
|
12889
13566
|
async function decodeImages(runtime, body, signal) {
|
|
12890
|
-
const items = record$
|
|
13567
|
+
const items = record$3(body)?.data;
|
|
12891
13568
|
const images = [];
|
|
12892
13569
|
let revisedPrompt;
|
|
12893
13570
|
for (const item of Array.isArray(items) ? items : []) {
|
|
12894
|
-
const entry = record$
|
|
13571
|
+
const entry = record$3(item);
|
|
12895
13572
|
if (entry === void 0) continue;
|
|
12896
13573
|
revisedPrompt ??= text$2(entry.revised_prompt);
|
|
12897
13574
|
const b64 = text$2(entry.b64_json);
|
|
@@ -14330,7 +15007,7 @@ var MediaHostService = class {
|
|
|
14330
15007
|
* the answer arrived.
|
|
14331
15008
|
* @module dsh-vibedev/tasks/remote
|
|
14332
15009
|
*/
|
|
14333
|
-
const record$
|
|
15010
|
+
const record$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
14334
15011
|
const text$1 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
14335
15012
|
const httpUrl = (value) => {
|
|
14336
15013
|
const url = text$1(value);
|
|
@@ -14374,9 +15051,9 @@ const seconds = (value) => {
|
|
|
14374
15051
|
/** The blocks billing facts are read from, in order: `billing`, `usage`, `effective`, then the answer itself. */
|
|
14375
15052
|
function billingBlocks(raw) {
|
|
14376
15053
|
return [
|
|
14377
|
-
record$
|
|
14378
|
-
record$
|
|
14379
|
-
record$
|
|
15054
|
+
record$2(raw.billing),
|
|
15055
|
+
record$2(raw.usage),
|
|
15056
|
+
record$2(raw.effective),
|
|
14380
15057
|
raw
|
|
14381
15058
|
].filter((block) => block !== void 0);
|
|
14382
15059
|
}
|
|
@@ -14429,7 +15106,7 @@ function billedLengths(raw) {
|
|
|
14429
15106
|
};
|
|
14430
15107
|
}
|
|
14431
15108
|
function errorOf(raw) {
|
|
14432
|
-
const nested = record$
|
|
15109
|
+
const nested = record$2(raw.error);
|
|
14433
15110
|
const message = text$1(nested?.message) ?? text$1(raw.error) ?? text$1(raw.failure_reason) ?? text$1(raw.error_message) ?? text$1(raw.fail_reason);
|
|
14434
15111
|
const code = text$1(nested?.code) ?? text$1(nested?.type) ?? text$1(raw.error_code);
|
|
14435
15112
|
if (message === void 0 && code === void 0) return void 0;
|
|
@@ -14448,7 +15125,7 @@ function errorOf(raw) {
|
|
|
14448
15125
|
};
|
|
14449
15126
|
}
|
|
14450
15127
|
function receiptFacts(raw) {
|
|
14451
|
-
const effective = record$
|
|
15128
|
+
const effective = record$2(raw.effective) ?? {};
|
|
14452
15129
|
const source = effective.billing_source;
|
|
14453
15130
|
return {
|
|
14454
15131
|
...Object.fromEntries(Object.entries({
|
|
@@ -14469,7 +15146,7 @@ function progressOf(value) {
|
|
|
14469
15146
|
return Math.min(100, Math.round(value <= 1 && value !== 0 ? value * 100 : value));
|
|
14470
15147
|
}
|
|
14471
15148
|
function receipt(raw) {
|
|
14472
|
-
const effective = record$
|
|
15149
|
+
const effective = record$2(raw.effective) ?? {};
|
|
14473
15150
|
const estimatedCny = amount(effective.estimated_cny);
|
|
14474
15151
|
const chargedCny = amount(effective.charged_cny) ?? amount(raw.charged_cny);
|
|
14475
15152
|
return {
|
|
@@ -14485,12 +15162,12 @@ function receipt(raw) {
|
|
|
14485
15162
|
* @returns the task, or undefined when the answer names no task id.
|
|
14486
15163
|
*/
|
|
14487
15164
|
function parseVideoTask(body, receivedAt = Date.now()) {
|
|
14488
|
-
const raw = record$
|
|
15165
|
+
const raw = record$2(body);
|
|
14489
15166
|
const id = text$1(raw?.id) ?? text$1(raw?.task_id);
|
|
14490
15167
|
if (raw === void 0 || id === void 0) return void 0;
|
|
14491
15168
|
const status = text$1(raw.status) ?? "queued";
|
|
14492
|
-
const video = record$
|
|
14493
|
-
const asset = record$
|
|
15169
|
+
const video = record$2(raw.video) ?? {};
|
|
15170
|
+
const asset = record$2(raw.asset) ?? record$2(video.asset) ?? {};
|
|
14494
15171
|
const url = httpUrl(video.url) ?? httpUrl(asset.content_url) ?? httpUrl(raw.url) ?? httpUrl(asset.reference_url);
|
|
14495
15172
|
const durationMs = typeof asset.duration_ms === "number" && asset.duration_ms > 0 ? asset.duration_ms : void 0;
|
|
14496
15173
|
const seconds = typeof raw.seconds === "number" ? raw.seconds : typeof raw.seconds === "string" ? Number(raw.seconds) : void 0;
|
|
@@ -14526,14 +15203,14 @@ function parseVideoTask(body, receivedAt = Date.now()) {
|
|
|
14526
15203
|
* @returns the task, or undefined when the answer names no task id.
|
|
14527
15204
|
*/
|
|
14528
15205
|
function parseAudioTask(body, receivedAt = Date.now()) {
|
|
14529
|
-
const raw = record$
|
|
15206
|
+
const raw = record$2(body);
|
|
14530
15207
|
const id = text$1(raw?.id) ?? text$1(raw?.task_id);
|
|
14531
15208
|
if (raw === void 0 || id === void 0) return void 0;
|
|
14532
15209
|
const status = text$1(raw.status) ?? "queued";
|
|
14533
15210
|
const state = stateOf(status);
|
|
14534
15211
|
const outputs = [];
|
|
14535
15212
|
if (Array.isArray(raw.outputs)) for (const [index, item] of raw.outputs.entries()) {
|
|
14536
|
-
const output = record$
|
|
15213
|
+
const output = record$2(item);
|
|
14537
15214
|
if (output === void 0) continue;
|
|
14538
15215
|
const url = httpUrl(output.content_url) ?? httpUrl(output.url);
|
|
14539
15216
|
const contentType = text$1(output.content_type);
|
|
@@ -15705,7 +16382,7 @@ function mediaAccountTool(runtime, chain, login) {
|
|
|
15705
16382
|
function audioGenerateTool(runtime) {
|
|
15706
16383
|
return defineTool({
|
|
15707
16384
|
name: "audio_generate",
|
|
15708
|
-
description: "Generate music (a song with vocals or an instrumental), a podcast episode (a spoken conversation about a topic or a web page) or speech (text read aloud, optionally in the voice of reference audio) with a VibeDev audio model. It runs as a background job: this call returns once the gateway accepts the task, you are notified when it finishes, and the files are saved in the workspace (media/audio/). Each model takes only the fields it declares; media_models lists them with prices (music and podcasts per request, speech per second of original audio). Final billing follows the gateway receipt.",
|
|
16385
|
+
description: "Generate music (a song with vocals or an instrumental), a podcast episode (a spoken conversation about a topic or a web page) or speech (text read aloud, optionally in the voice of reference audio) with a VibeDev audio model. It runs as a background job: this call returns once the gateway accepts the task, you are notified when it finishes, and the files are saved in the workspace (media/audio/). Each model takes only the fields it declares; media_models lists them with prices (music and podcasts per request, speech per second of original audio). Final billing follows the gateway receipt. Music covers, on a model that declares the fields: voice_id (a vp_… voice profile from voice_profile_list, for 音色翻唱) and/or source_audio (a song to cover, 上传翻唱). The mode is chosen automatically and sent as mode when the model declares it: voice_id given → voice_cover; only source_audio → cover; neither → generate. voice_id together with source_audio means covering that audio in the chosen voice (voice_cover, both sent). Without a named model a voice cover uses the first model that supports voice covers (media_models), while covers and plain songs use the music model. audio_weight (0–1) applies only to a cover or voice cover.",
|
|
15709
16386
|
parameters: {
|
|
15710
16387
|
type: {
|
|
15711
16388
|
type: "string",
|
|
@@ -15733,6 +16410,30 @@ function audioGenerateTool(runtime) {
|
|
|
15733
16410
|
type: "string",
|
|
15734
16411
|
description: "Music only: the singer's voice, such as male or female."
|
|
15735
16412
|
},
|
|
16413
|
+
style: {
|
|
16414
|
+
type: "string",
|
|
16415
|
+
description: "Music only, when the model declares it: the style, such as \"lo-fi hip hop, warm piano\"."
|
|
16416
|
+
},
|
|
16417
|
+
title: {
|
|
16418
|
+
type: "string",
|
|
16419
|
+
description: "Music only, when the model declares it: the song title."
|
|
16420
|
+
},
|
|
16421
|
+
instrumental: {
|
|
16422
|
+
type: "boolean",
|
|
16423
|
+
description: "Music only, when the model declares it: true for no vocals."
|
|
16424
|
+
},
|
|
16425
|
+
voice_id: {
|
|
16426
|
+
type: "string",
|
|
16427
|
+
description: "Music only (音色翻唱): a voice profile id of the form vp_… from voice_profile_list whose status is ready. No other kind of voice id is accepted. Sends mode voice_cover; with source_audio as well, that audio is covered in this voice."
|
|
16428
|
+
},
|
|
16429
|
+
source_audio: {
|
|
16430
|
+
type: "string",
|
|
16431
|
+
description: "Music only (上传翻唱): the song to cover — a workspace file path, chat:1 for the most recent audio the user attached (chat:video:1 for an attached video), or an https link; audio (mp3, wav, m4a, aac, flac, ogg) or video (mp4, mov, webm), at most 10 MB (trim or compress a larger file first). It is uploaded to the VibeDev media library first. Sends mode cover (voice_cover with voice_id)."
|
|
16432
|
+
},
|
|
16433
|
+
audio_weight: {
|
|
16434
|
+
type: "number",
|
|
16435
|
+
description: "Music covers only (needs voice_id or source_audio): how closely the song follows the reference audio, from 0 to 1 inclusive."
|
|
16436
|
+
},
|
|
15736
16437
|
source_url: {
|
|
15737
16438
|
type: "string",
|
|
15738
16439
|
description: "Podcast only: an http(s) page for the hosts to discuss."
|
|
@@ -15819,6 +16520,12 @@ function audioGenerateTool(runtime) {
|
|
|
15819
16520
|
...args.genre === void 0 ? {} : { genre: args.genre },
|
|
15820
16521
|
...args.mood === void 0 ? {} : { mood: args.mood },
|
|
15821
16522
|
...args.gender === void 0 ? {} : { gender: args.gender },
|
|
16523
|
+
...args.style === void 0 ? {} : { style: args.style },
|
|
16524
|
+
...args.title === void 0 ? {} : { title: args.title },
|
|
16525
|
+
...args.instrumental === void 0 ? {} : { instrumental: args.instrumental },
|
|
16526
|
+
...args.voice_id === void 0 ? {} : { voiceId: args.voice_id },
|
|
16527
|
+
...args.source_audio === void 0 ? {} : { sourceAudio: args.source_audio },
|
|
16528
|
+
...args.audio_weight === void 0 ? {} : { audioWeight: args.audio_weight },
|
|
15822
16529
|
...args.source_url === void 0 ? {} : { sourceUrl: args.source_url },
|
|
15823
16530
|
...args.references === void 0 ? {} : { references: args.references },
|
|
15824
16531
|
...args.format === void 0 ? {} : { format: args.format },
|
|
@@ -15898,6 +16605,7 @@ function describeAudioModel(model) {
|
|
|
15898
16605
|
if (model.audioKind === void 0) return "does not declare what kind of audio it makes; it cannot be used for generation";
|
|
15899
16606
|
const fields = requestFieldsOf(model).filter((name) => name !== "model");
|
|
15900
16607
|
const parts = [`fields: ${fields.join(", ") || "none declared"}`];
|
|
16608
|
+
if (audio?.supportsVoiceCover === true) parts.push("supports voice covers (voice_id)");
|
|
15901
16609
|
const prompt = promptFieldOf(model);
|
|
15902
16610
|
if (prompt !== void 0 && prompt !== "prompt") parts.push(`the text goes in ${prompt}`);
|
|
15903
16611
|
const references = audio?.references;
|
|
@@ -16136,7 +16844,7 @@ const ACCEPTED = [
|
|
|
16136
16844
|
"video/mp4",
|
|
16137
16845
|
"video/webm"
|
|
16138
16846
|
];
|
|
16139
|
-
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
16847
|
+
const record$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
16140
16848
|
const text = (value) => typeof value === "string" ? value : void 0;
|
|
16141
16849
|
/**
|
|
16142
16850
|
* The length of a PCM WAV file from its header.
|
|
@@ -16261,19 +16969,19 @@ function audioTranscribeTool(runtime) {
|
|
|
16261
16969
|
busyRetries: BUSY_RETRIES,
|
|
16262
16970
|
maxBusyWaitMs: 3e4
|
|
16263
16971
|
});
|
|
16264
|
-
let answer = record(await response.json().catch(() => void 0));
|
|
16972
|
+
let answer = record$1(await response.json().catch(() => void 0));
|
|
16265
16973
|
const started = runtime.now();
|
|
16266
16974
|
while (text(answer?.text) === void 0) {
|
|
16267
16975
|
const id = text(answer?.id) ?? text(answer?.task_id);
|
|
16268
16976
|
const status = text(answer?.status)?.toLowerCase();
|
|
16269
16977
|
if (status === "failed" || status === "error" || status === "cancelled") {
|
|
16270
|
-
const error = record(answer?.error);
|
|
16978
|
+
const error = record$1(answer?.error);
|
|
16271
16979
|
throw new MediaError(`The transcription failed${error === void 0 ? "" : ` (${text(error.code) ?? ""}: ${text(error.message) ?? ""})`}; failed transcriptions are not charged.`, "TRANSCRIPTION_FAILED");
|
|
16272
16980
|
}
|
|
16273
16981
|
if (id === void 0) throw new MediaError("The VibeDev gateway returned neither a transcript nor a task.", "GATEWAY_BAD_RESPONSE");
|
|
16274
16982
|
if (runtime.now() - started > POLL_LIMIT_MS) throw new MediaError(`The transcription task ${id} did not finish within 15 minutes.`, "TRANSCRIPTION_TIMEOUT");
|
|
16275
16983
|
await sleep(POLL_MS, exec.signal);
|
|
16276
|
-
answer = record(await runtime.http.json(`/v1/audio/transcriptions/${encodeURIComponent(id)}`, {
|
|
16984
|
+
answer = record$1(await runtime.http.json(`/v1/audio/transcriptions/${encodeURIComponent(id)}`, {
|
|
16277
16985
|
timeoutMs: 3e4,
|
|
16278
16986
|
signal: exec.signal
|
|
16279
16987
|
}));
|
|
@@ -16295,6 +17003,388 @@ function audioTranscribeTool(runtime) {
|
|
|
16295
17003
|
});
|
|
16296
17004
|
}
|
|
16297
17005
|
//#endregion
|
|
17006
|
+
//#region src/gateway/paid-path.ts
|
|
17007
|
+
/**
|
|
17008
|
+
* Which accepted gateway requests may have spent money, so the balance is read again after them.
|
|
17009
|
+
* @module dsh-vibedev/gateway/paid-path
|
|
17010
|
+
*/
|
|
17011
|
+
/** Generations and transcriptions (uploads and reads are free). */
|
|
17012
|
+
const PAID_PATH = /^\/v1\/(?:images|videos|audio)(?:\/|$)/;
|
|
17013
|
+
/** Free paths under a paid prefix: voice profiles are created, listed and deleted without a charge. */
|
|
17014
|
+
const FREE_PATH = /^\/v1\/audio\/voice-profiles(?:\/|$)/;
|
|
17015
|
+
/**
|
|
17016
|
+
* Whether an accepted request may have been charged.
|
|
17017
|
+
* @param method - the HTTP method.
|
|
17018
|
+
* @param path - the request path, without the query.
|
|
17019
|
+
* @returns true for a POST to a generation or transcription endpoint.
|
|
17020
|
+
*/
|
|
17021
|
+
function isPaidRequest(method, path) {
|
|
17022
|
+
return method === "POST" && PAID_PATH.test(path) && !FREE_PATH.test(path);
|
|
17023
|
+
}
|
|
17024
|
+
//#endregion
|
|
17025
|
+
//#region src/account/voice-profile-routes.ts
|
|
17026
|
+
/**
|
|
17027
|
+
* The account center's 「我的音色」 routes (answers are never cached; credentials and provider ids never leave):
|
|
17028
|
+
*
|
|
17029
|
+
* - `GET /api/dsh-vibedev/voice-profiles` — `{ code: 0, data: { items, limits } }`, or `{ unsupported: true }` when
|
|
17030
|
+
* the gateway has no voice profiles;
|
|
17031
|
+
* - `POST /api/dsh-vibedev/voice-profiles` — `{ title, filename, data (base64), expected_user_id }`: checked, uploaded
|
|
17032
|
+
* and created; answers the profile, usually still `processing` (the page then reads the list until it settles);
|
|
17033
|
+
* - `POST /api/dsh-vibedev/voice-profiles/delete` — `{ id, expected_user_id }`: closes a `vp_…` profile for good.
|
|
17034
|
+
*
|
|
17035
|
+
* Every call is held to the account the page shows (`X-VibeDev-Expected-User` or `expected_user_id`): a different
|
|
17036
|
+
* signed-in account answers 409 `ACCOUNT_CHANGED` and nothing is sent.
|
|
17037
|
+
* @module dsh-vibedev/account/voice-profile-routes
|
|
17038
|
+
*/
|
|
17039
|
+
const VOICE_PROFILE_ROUTE = "/api/dsh-vibedev/voice-profiles";
|
|
17040
|
+
const VOICE_PROFILE_DELETE_ROUTE = "/api/dsh-vibedev/voice-profiles/delete";
|
|
17041
|
+
/** The limits the page checks before it uploads. */
|
|
17042
|
+
const VOICE_PAGE_LIMITS = {
|
|
17043
|
+
maxBytes: VOICE_SAMPLE_LIMITS.maxBytes,
|
|
17044
|
+
minSeconds: VOICE_SAMPLE_LIMITS.minSeconds,
|
|
17045
|
+
maxSeconds: VOICE_SAMPLE_LIMITS.maxSeconds,
|
|
17046
|
+
recommendedMinSeconds: VOICE_SAMPLE_LIMITS.recommendedMinSeconds,
|
|
17047
|
+
extensions: VOICE_SAMPLE_LIMITS.extensions
|
|
17048
|
+
};
|
|
17049
|
+
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
17050
|
+
const answer = (status, body) => new Response(JSON.stringify(body), {
|
|
17051
|
+
status,
|
|
17052
|
+
headers: {
|
|
17053
|
+
"content-type": "application/json; charset=utf-8",
|
|
17054
|
+
"cache-control": "private, no-store"
|
|
17055
|
+
}
|
|
17056
|
+
});
|
|
17057
|
+
const refuse = (status, code, category, extra = {}) => answer(status, { error: {
|
|
17058
|
+
code,
|
|
17059
|
+
category,
|
|
17060
|
+
...extra
|
|
17061
|
+
} });
|
|
17062
|
+
const sameAccount = (a, b) => a.signedIn && b.signedIn && a.userId !== void 0 && a.userId === b.userId;
|
|
17063
|
+
/** A failure as the page shows it: code, category, the rule a local check broke, and a message safe to display. */
|
|
17064
|
+
function failure(error) {
|
|
17065
|
+
if (error instanceof MediaError) {
|
|
17066
|
+
const category = error.details.category ?? "internal_error";
|
|
17067
|
+
const status = error.details.status ?? (category === "invalid_input" ? 400 : category === "authentication" ? 401 : 502);
|
|
17068
|
+
return refuse(status, error.code, category, {
|
|
17069
|
+
message: error.message,
|
|
17070
|
+
...error.details.rule === void 0 ? {} : { rule: error.details.rule },
|
|
17071
|
+
...error.details.requestId === void 0 ? {} : { request_id: error.details.requestId }
|
|
17072
|
+
});
|
|
17073
|
+
}
|
|
17074
|
+
return refuse(502, "VOICE_PROFILE_UNAVAILABLE", "service_unavailable");
|
|
17075
|
+
}
|
|
17076
|
+
/**
|
|
17077
|
+
* The routes.
|
|
17078
|
+
* @param voices - the voice-profile service.
|
|
17079
|
+
* @param account - the signed-in account, for the account guard.
|
|
17080
|
+
* @returns routes for the client connection.
|
|
17081
|
+
*/
|
|
17082
|
+
function voiceProfileRoutes(voices, account) {
|
|
17083
|
+
/** The signed-in account the request expects, or the refusal to answer with. */
|
|
17084
|
+
const guard = async (expected) => {
|
|
17085
|
+
const before = await account.identity();
|
|
17086
|
+
if (!before.signedIn || before.userId === void 0) return refuse(401, "AUTHENTICATION_REQUIRED", "authentication");
|
|
17087
|
+
if (typeof expected !== "string" || expected !== before.userId) return refuse(409, "ACCOUNT_CHANGED", "access_restricted");
|
|
17088
|
+
return {
|
|
17089
|
+
before,
|
|
17090
|
+
isCurrentAccount: async () => {
|
|
17091
|
+
try {
|
|
17092
|
+
return sameAccount(before, await account.identity());
|
|
17093
|
+
} catch {
|
|
17094
|
+
return false;
|
|
17095
|
+
}
|
|
17096
|
+
}
|
|
17097
|
+
};
|
|
17098
|
+
};
|
|
17099
|
+
const json = async (request) => {
|
|
17100
|
+
try {
|
|
17101
|
+
return record(JSON.parse(await request.text()));
|
|
17102
|
+
} catch {
|
|
17103
|
+
return;
|
|
17104
|
+
}
|
|
17105
|
+
};
|
|
17106
|
+
return [{
|
|
17107
|
+
path: VOICE_PROFILE_ROUTE,
|
|
17108
|
+
methods: ["GET", "POST"],
|
|
17109
|
+
requestBody: "buffered",
|
|
17110
|
+
fetch: async (request) => {
|
|
17111
|
+
try {
|
|
17112
|
+
if (request.method === "GET") {
|
|
17113
|
+
const checked = await guard(request.headers.get("X-VibeDev-Expected-User"));
|
|
17114
|
+
if (checked instanceof Response) return checked;
|
|
17115
|
+
const items = await voices.list({
|
|
17116
|
+
signal: request.signal,
|
|
17117
|
+
isCurrentAccount: checked.isCurrentAccount
|
|
17118
|
+
});
|
|
17119
|
+
if (!await checked.isCurrentAccount()) return refuse(409, "ACCOUNT_CHANGED", "access_restricted");
|
|
17120
|
+
return answer(200, {
|
|
17121
|
+
code: 0,
|
|
17122
|
+
data: {
|
|
17123
|
+
items,
|
|
17124
|
+
limits: VOICE_PAGE_LIMITS
|
|
17125
|
+
}
|
|
17126
|
+
});
|
|
17127
|
+
}
|
|
17128
|
+
const body = await json(request);
|
|
17129
|
+
if (body === void 0) return refuse(400, "INVALID_INPUT", "invalid_input");
|
|
17130
|
+
const checked = await guard(typeof body.expected_user_id === "string" ? body.expected_user_id : void 0);
|
|
17131
|
+
if (checked instanceof Response) return checked;
|
|
17132
|
+
const { title, filename, data } = body;
|
|
17133
|
+
if (typeof title !== "string" || typeof filename !== "string" || filename.length > 255 || typeof data !== "string" || data === "") return refuse(400, "INVALID_INPUT", "invalid_input");
|
|
17134
|
+
if (data.length > Math.ceil(VOICE_SAMPLE_LIMITS.maxBytes / 3) * 4 + 8) return refuse(413, "VOICE_SAMPLE_TOO_LARGE", "invalid_input", { rule: "too_large" });
|
|
17135
|
+
const bytes = new Uint8Array(Buffer$1.from(data, "base64"));
|
|
17136
|
+
const name = filename.replace(/[\\/]/g, "_").trim() || "voice";
|
|
17137
|
+
const profile = await voices.create({
|
|
17138
|
+
source: name,
|
|
17139
|
+
name,
|
|
17140
|
+
mime: sniffMime(bytes, name),
|
|
17141
|
+
data: bytes
|
|
17142
|
+
}, title, {
|
|
17143
|
+
signal: request.signal,
|
|
17144
|
+
isCurrentAccount: checked.isCurrentAccount
|
|
17145
|
+
});
|
|
17146
|
+
return answer(200, {
|
|
17147
|
+
code: 0,
|
|
17148
|
+
data: profile
|
|
17149
|
+
});
|
|
17150
|
+
} catch (error) {
|
|
17151
|
+
if (error instanceof MediaError && (error.details.status === 404 || error.details.status === 405) && request.method === "GET") return answer(200, { unsupported: true });
|
|
17152
|
+
return failure(error);
|
|
17153
|
+
}
|
|
17154
|
+
}
|
|
17155
|
+
}, {
|
|
17156
|
+
path: VOICE_PROFILE_DELETE_ROUTE,
|
|
17157
|
+
methods: ["POST"],
|
|
17158
|
+
requestBody: "buffered",
|
|
17159
|
+
fetch: async (request) => {
|
|
17160
|
+
try {
|
|
17161
|
+
const body = await json(request);
|
|
17162
|
+
if (body === void 0) return refuse(400, "INVALID_INPUT", "invalid_input");
|
|
17163
|
+
const id = checkVoiceProfileId(body.id);
|
|
17164
|
+
const checked = await guard(typeof body.expected_user_id === "string" ? body.expected_user_id : void 0);
|
|
17165
|
+
if (checked instanceof Response) return checked;
|
|
17166
|
+
await voices.remove(id, {
|
|
17167
|
+
signal: request.signal,
|
|
17168
|
+
isCurrentAccount: checked.isCurrentAccount
|
|
17169
|
+
});
|
|
17170
|
+
return answer(200, {
|
|
17171
|
+
code: 0,
|
|
17172
|
+
data: { id }
|
|
17173
|
+
});
|
|
17174
|
+
} catch (error) {
|
|
17175
|
+
return failure(error);
|
|
17176
|
+
}
|
|
17177
|
+
}
|
|
17178
|
+
}];
|
|
17179
|
+
}
|
|
17180
|
+
//#endregion
|
|
17181
|
+
//#region src/tools/voice-profiles.ts
|
|
17182
|
+
/**
|
|
17183
|
+
* `voice_profile_create`, `voice_profile_list`, `voice_profile_delete`: the user's voice profiles (音色) for Suno
|
|
17184
|
+
* voice covers. Creating one is free and makes no song; only `vp_…` ids are shown or accepted.
|
|
17185
|
+
* @module dsh-vibedev/tools/voice-profiles
|
|
17186
|
+
*/
|
|
17187
|
+
const PROFILE_SCHEMA = {
|
|
17188
|
+
type: "object",
|
|
17189
|
+
additionalProperties: false,
|
|
17190
|
+
properties: {
|
|
17191
|
+
id: {
|
|
17192
|
+
type: "string",
|
|
17193
|
+
required: true
|
|
17194
|
+
},
|
|
17195
|
+
status: {
|
|
17196
|
+
type: "string",
|
|
17197
|
+
required: true
|
|
17198
|
+
},
|
|
17199
|
+
title: { type: "string" },
|
|
17200
|
+
failureReason: { type: "string" },
|
|
17201
|
+
failureKind: { type: "string" },
|
|
17202
|
+
durationSeconds: { type: "number" },
|
|
17203
|
+
createdAt: { type: "string" }
|
|
17204
|
+
}
|
|
17205
|
+
};
|
|
17206
|
+
/** The model-facing projection of one profile. */
|
|
17207
|
+
function shown(profile) {
|
|
17208
|
+
return {
|
|
17209
|
+
id: profile.id,
|
|
17210
|
+
status: profile.status,
|
|
17211
|
+
...profile.title === void 0 ? {} : { title: profile.title },
|
|
17212
|
+
...profile.failureReason === void 0 ? {} : { failureReason: profile.failureReason },
|
|
17213
|
+
...profile.failureKind === void 0 ? {} : { failureKind: profile.failureKind },
|
|
17214
|
+
...profile.durationSeconds === void 0 ? {} : { durationSeconds: profile.durationSeconds },
|
|
17215
|
+
...profile.createdAt === void 0 ? {} : { createdAt: profile.createdAt }
|
|
17216
|
+
};
|
|
17217
|
+
}
|
|
17218
|
+
/** A failure in plain words when the refusal is recognised (with the provider's reason after it), else the reason as it came. */
|
|
17219
|
+
function failureWords(profile) {
|
|
17220
|
+
const known = VOICE_REJECTIONS.find((rule) => rule.kind === profile.failureKind);
|
|
17221
|
+
if (known === void 0) return profile.failureReason;
|
|
17222
|
+
return `${known.en} ${known.zh}${profile.failureReason === void 0 ? "" : ` (${profile.failureReason})`}`;
|
|
17223
|
+
}
|
|
17224
|
+
/** One line per profile, for messages. */
|
|
17225
|
+
function describeVoiceProfile(profile) {
|
|
17226
|
+
const state = profile.status === "ready" ? "ready — usable as audio_generate voice_id" : profile.status === "failed" ? `failed: ${failureWords(profile) ?? "the gateway gave no reason"}` : "still being created";
|
|
17227
|
+
const facts = [profile.durationSeconds === void 0 ? void 0 : `${profile.durationSeconds.toFixed(1)} s`, profile.createdAt].filter(Boolean);
|
|
17228
|
+
return `${profile.id}${profile.title === void 0 ? "" : ` "${profile.title}"`} — ${state}${facts.length === 0 ? "" : ` (${facts.join(", ")})`}`;
|
|
17229
|
+
}
|
|
17230
|
+
const LIMITS = `${VOICE_SAMPLE_LIMITS.minSeconds}–${VOICE_SAMPLE_LIMITS.maxSeconds} s (10–60 s works best), at most 10 MiB, ${VOICE_SAMPLE_LIMITS.extensions.join("/")}, ideally clean solo vocals without accompaniment`;
|
|
17231
|
+
/**
|
|
17232
|
+
* `voice_profile_create`.
|
|
17233
|
+
* @param runtime - loads the sample (workspace paths, links, chat attachments).
|
|
17234
|
+
* @param profiles - the voice-profile service.
|
|
17235
|
+
* @returns the tool.
|
|
17236
|
+
*/
|
|
17237
|
+
function voiceProfileCreateTool(runtime, profiles) {
|
|
17238
|
+
return defineTool({
|
|
17239
|
+
name: "voice_profile_create",
|
|
17240
|
+
description: "Create a VibeDev voice profile (音色) from a recording of the user's own singing voice, for Suno voice covers (audio_generate voice_id). Free: it makes no song and charges nothing. The sample must be " + LIMITS + "; it is checked, uploaded to the VibeDev media library and submitted, and the call waits until the profile is ready or failed (creation can take 2–3 minutes; when the gateway does not answer in time the list is checked for the new profile before anything is reported). The result is a vp_… id — the only form of voice id that exists for the user; never ask for or pass any other voice id. Only create one when the user asks, from audio they have the right to use. Do not promise that a profile is kept forever.",
|
|
17241
|
+
parameters: {
|
|
17242
|
+
source: {
|
|
17243
|
+
type: "string",
|
|
17244
|
+
required: true,
|
|
17245
|
+
description: `The voice sample: ${SOURCE_HELP}.`
|
|
17246
|
+
},
|
|
17247
|
+
title: {
|
|
17248
|
+
type: "string",
|
|
17249
|
+
required: true,
|
|
17250
|
+
description: "A name for the profile, at most 80 characters."
|
|
17251
|
+
}
|
|
17252
|
+
},
|
|
17253
|
+
output: {
|
|
17254
|
+
schema: {
|
|
17255
|
+
type: "object",
|
|
17256
|
+
additionalProperties: false,
|
|
17257
|
+
properties: {
|
|
17258
|
+
profile: PROFILE_SCHEMA,
|
|
17259
|
+
message: {
|
|
17260
|
+
type: "string",
|
|
17261
|
+
required: true
|
|
17262
|
+
}
|
|
17263
|
+
}
|
|
17264
|
+
},
|
|
17265
|
+
render: (_args, value) => [{
|
|
17266
|
+
type: "text",
|
|
17267
|
+
text: value.message
|
|
17268
|
+
}]
|
|
17269
|
+
},
|
|
17270
|
+
timeoutMs: 6e5,
|
|
17271
|
+
async execute(args, exec) {
|
|
17272
|
+
const title = checkVoiceTitle(args.title);
|
|
17273
|
+
const media = await runtime.load(exec, args.source, "audio", VOICE_SAMPLE_LIMITS.maxBytes);
|
|
17274
|
+
const created = await profiles.create(media, title, { signal: exec.signal });
|
|
17275
|
+
const final = created.status === "processing" ? await profiles.waitUntilSettled(created.id, { signal: exec.signal }) : created;
|
|
17276
|
+
const message = final.status === "ready" ? `Voice profile created and ready: ${describeVoiceProfile(final)}. Pass voice_id "${final.id}" to audio_generate (music) for a voice cover. Creating it charged nothing.` : final.status === "failed" ? `The voice profile could not be created: ${describeVoiceProfile(final)}. Nothing was charged. A clean solo vocal of 10–60 s usually works.` : `Voice profile ${final.id} is still being created. voice_profile_list shows when it is ready; do not use it before then. Nothing was charged.`;
|
|
17277
|
+
return {
|
|
17278
|
+
profile: shown(final),
|
|
17279
|
+
message
|
|
17280
|
+
};
|
|
17281
|
+
}
|
|
17282
|
+
});
|
|
17283
|
+
}
|
|
17284
|
+
/**
|
|
17285
|
+
* `voice_profile_list`.
|
|
17286
|
+
* @param profiles - the voice-profile service.
|
|
17287
|
+
* @returns the tool.
|
|
17288
|
+
*/
|
|
17289
|
+
function voiceProfileListTool(profiles) {
|
|
17290
|
+
return defineTool({
|
|
17291
|
+
name: "voice_profile_list",
|
|
17292
|
+
description: "List the user's VibeDev voice profiles (音色): vp_… id, name, status (ready, processing or failed with the reason), length and creation time. Only a ready profile can be passed to audio_generate as voice_id.",
|
|
17293
|
+
parameters: {},
|
|
17294
|
+
output: {
|
|
17295
|
+
schema: {
|
|
17296
|
+
type: "object",
|
|
17297
|
+
additionalProperties: false,
|
|
17298
|
+
properties: {
|
|
17299
|
+
profiles: {
|
|
17300
|
+
type: "array",
|
|
17301
|
+
items: PROFILE_SCHEMA
|
|
17302
|
+
},
|
|
17303
|
+
message: {
|
|
17304
|
+
type: "string",
|
|
17305
|
+
required: true
|
|
17306
|
+
}
|
|
17307
|
+
}
|
|
17308
|
+
},
|
|
17309
|
+
render: (_args, value) => [{
|
|
17310
|
+
type: "text",
|
|
17311
|
+
text: value.message
|
|
17312
|
+
}]
|
|
17313
|
+
},
|
|
17314
|
+
isConcurrencySafe: () => true,
|
|
17315
|
+
async execute(_args, exec) {
|
|
17316
|
+
const list = await profiles.list({ signal: exec.signal });
|
|
17317
|
+
return {
|
|
17318
|
+
profiles: list.map(shown),
|
|
17319
|
+
message: list.length === 0 ? "This VibeDev account has no voice profiles. voice_profile_create makes one from a 10–60 s recording of the user's voice (free)." : `Voice profiles:\n${list.map((profile) => `- ${describeVoiceProfile(profile)}`).join("\n")}`
|
|
17320
|
+
};
|
|
17321
|
+
}
|
|
17322
|
+
});
|
|
17323
|
+
}
|
|
17324
|
+
/**
|
|
17325
|
+
* `voice_profile_delete`.
|
|
17326
|
+
* @param runtime - for the user's confirmation, when the host can ask.
|
|
17327
|
+
* @param profiles - the voice-profile service.
|
|
17328
|
+
* @returns the tool.
|
|
17329
|
+
*/
|
|
17330
|
+
function voiceProfileDeleteTool(runtime, profiles) {
|
|
17331
|
+
return defineTool({
|
|
17332
|
+
name: "voice_profile_delete",
|
|
17333
|
+
description: "Permanently delete one of the user's VibeDev voice profiles by its vp_… id. This cannot be undone: the profile cannot be used for new voice covers again; songs already made with it are not affected. Only delete when the user explicitly asks for that profile.",
|
|
17334
|
+
parameters: { id: {
|
|
17335
|
+
type: "string",
|
|
17336
|
+
required: true,
|
|
17337
|
+
description: "The vp_… id from voice_profile_list."
|
|
17338
|
+
} },
|
|
17339
|
+
output: {
|
|
17340
|
+
schema: {
|
|
17341
|
+
type: "object",
|
|
17342
|
+
additionalProperties: false,
|
|
17343
|
+
properties: {
|
|
17344
|
+
id: {
|
|
17345
|
+
type: "string",
|
|
17346
|
+
required: true
|
|
17347
|
+
},
|
|
17348
|
+
message: {
|
|
17349
|
+
type: "string",
|
|
17350
|
+
required: true
|
|
17351
|
+
}
|
|
17352
|
+
}
|
|
17353
|
+
},
|
|
17354
|
+
render: (_args, value) => [{
|
|
17355
|
+
type: "text",
|
|
17356
|
+
text: value.message
|
|
17357
|
+
}]
|
|
17358
|
+
},
|
|
17359
|
+
async execute(args, exec) {
|
|
17360
|
+
const id = checkVoiceProfileId(args.id);
|
|
17361
|
+
const approval = runtime.options.approval?.();
|
|
17362
|
+
if (approval !== void 0 && exec.agent !== void 0) {
|
|
17363
|
+
const en = `Permanently delete voice profile ${id}? It cannot be restored; songs already made with it are not affected.`;
|
|
17364
|
+
const zh = `永久删除音色 ${id}?删除后不可恢复;已生成的歌曲不受影响。`;
|
|
17365
|
+
const outcome = await approval.request({
|
|
17366
|
+
agent: exec.agent,
|
|
17367
|
+
toolName: "voice_profile_delete",
|
|
17368
|
+
callId: exec.callId,
|
|
17369
|
+
signal: exec.signal,
|
|
17370
|
+
reason: en,
|
|
17371
|
+
displayReason: {
|
|
17372
|
+
en,
|
|
17373
|
+
zh,
|
|
17374
|
+
"zh-CN": zh
|
|
17375
|
+
}
|
|
17376
|
+
});
|
|
17377
|
+
if (outcome !== "allowed-once") throw new MediaError(outcome === "cancelled" ? "The deletion was cancelled; the voice profile is kept." : "The user did not confirm the deletion; the voice profile is kept.", "VOICE_PROFILE_DELETE_DECLINED");
|
|
17378
|
+
}
|
|
17379
|
+
await profiles.remove(id, { signal: exec.signal });
|
|
17380
|
+
return {
|
|
17381
|
+
id,
|
|
17382
|
+
message: `Voice profile ${id} was deleted for good. Songs already made with it are not affected.`
|
|
17383
|
+
};
|
|
17384
|
+
}
|
|
17385
|
+
});
|
|
17386
|
+
}
|
|
17387
|
+
//#endregion
|
|
16298
17388
|
//#region src/index.ts
|
|
16299
17389
|
/**
|
|
16300
17390
|
* dsh-vibedev (formerly dsh-media): the VibeDev account and the VibeDev
|
|
@@ -16318,8 +17408,6 @@ function audioTranscribeTool(runtime) {
|
|
|
16318
17408
|
* ```
|
|
16319
17409
|
* @module dsh-vibedev
|
|
16320
17410
|
*/
|
|
16321
|
-
/** Requests that are charged: generations and transcriptions (uploads and reads are free). */
|
|
16322
|
-
const PAID_PATH = /^\/v1\/(?:images|videos|audio)(?:\/|$)/;
|
|
16323
17411
|
/**
|
|
16324
17412
|
* How long a model listing waits for promotion labels before it answers without
|
|
16325
17413
|
* them. A picker must never wait on decoration.
|
|
@@ -16422,7 +17510,7 @@ const Config = Schema.object({
|
|
|
16422
17510
|
stateDir: "Plugin data folder (empty for the default)"
|
|
16423
17511
|
}
|
|
16424
17512
|
});
|
|
16425
|
-
const GUIDANCE = "VibeDev media tools: image_generate, video_generate, audio_generate (music, a podcast or speech) and audio_transcribe create and transcribe media with the user's VibeDev account; media_models lists models and prices. Use them on your own judgment whenever generated media serves the request (illustrations, product shots, storyboard frames, short clips, background music, a podcast episode, a voice-over), not only when a tool is named. They spend the user's balance, so make what the request needs rather than speculative variations. Results are saved in the workspace under media/. An image result is the saved file, not the picture: read it with read_image when you need to look, and read each file once — every read is another image in the context. Pass files the user attached in this chat as chat:1 (the most recent), chat:2, and so on. Video and audio run as background jobs: carry on and let the job notification report the result.";
|
|
17513
|
+
const GUIDANCE = "VibeDev media tools: image_generate, video_generate, audio_generate (music, a podcast or speech) and audio_transcribe create and transcribe media with the user's VibeDev account; media_models lists models and prices. Use them on your own judgment whenever generated media serves the request (illustrations, product shots, storyboard frames, short clips, background music, a podcast episode, a voice-over), not only when a tool is named. They spend the user's balance, so make what the request needs rather than speculative variations. Results are saved in the workspace under media/. An image result is the saved file, not the picture: read it with read_image when you need to look, and read each file once — every read is another image in the context. Pass files the user attached in this chat as chat:1 (the most recent), chat:2, and so on. Video and audio run as background jobs: carry on and let the job notification report the result. Voice covers (音色翻唱) use the user's own voice profile: voice_profile_create makes one for free from a 6–60 s vocal recording (voice_profile_list, voice_profile_delete), and audio_generate takes its vp_… id as voice_id; source_audio covers an uploaded song.";
|
|
16426
17514
|
function apply(ctx, config) {
|
|
16427
17515
|
const origin = normalizeGatewayOrigin(config.gatewayOrigin);
|
|
16428
17516
|
const stateDir = stateDirectory(config.stateDir);
|
|
@@ -16464,7 +17552,7 @@ function apply(ctx, config) {
|
|
|
16464
17552
|
resolveCredential: () => chain.resolve(),
|
|
16465
17553
|
rejectToken: (credential) => chain.reject(credential),
|
|
16466
17554
|
onAccepted: ({ method, path }) => {
|
|
16467
|
-
if (method
|
|
17555
|
+
if (isPaidRequest(method, path)) spent();
|
|
16468
17556
|
}
|
|
16469
17557
|
});
|
|
16470
17558
|
const promotions = new PromotionService({ http });
|
|
@@ -16508,6 +17596,10 @@ function apply(ctx, config) {
|
|
|
16508
17596
|
jobs: () => ctx.get("jobs"),
|
|
16509
17597
|
log: warn
|
|
16510
17598
|
});
|
|
17599
|
+
const voices = new VoiceProfiles({
|
|
17600
|
+
http,
|
|
17601
|
+
upload: (media, purpose, signal) => runtime.library.upload(media, purpose, signal)
|
|
17602
|
+
});
|
|
16511
17603
|
for (const tool of [
|
|
16512
17604
|
mediaModelsTool(runtime),
|
|
16513
17605
|
imageGenerateTool(runtime),
|
|
@@ -16515,7 +17607,10 @@ function apply(ctx, config) {
|
|
|
16515
17607
|
audioGenerateTool(runtime),
|
|
16516
17608
|
audioTranscribeTool(runtime),
|
|
16517
17609
|
mediaTasksTool(runtime),
|
|
16518
|
-
mediaAccountTool(runtime, chain, login)
|
|
17610
|
+
mediaAccountTool(runtime, chain, login),
|
|
17611
|
+
voiceProfileCreateTool(runtime, voices),
|
|
17612
|
+
voiceProfileListTool(voices),
|
|
17613
|
+
voiceProfileDeleteTool(runtime, voices)
|
|
16519
17614
|
]) ctx.tools.register(tool);
|
|
16520
17615
|
const accountContext = async () => {
|
|
16521
17616
|
const identity = await account?.identity();
|
|
@@ -16636,6 +17731,7 @@ function apply(ctx, config) {
|
|
|
16636
17731
|
for (const accountRoute of [
|
|
16637
17732
|
...accountRoutes(accountService),
|
|
16638
17733
|
...accountCenterRoutes(http, accountService),
|
|
17734
|
+
...voiceProfileRoutes(voices, accountService),
|
|
16639
17735
|
...announcementRoutes({
|
|
16640
17736
|
http,
|
|
16641
17737
|
account: accountService
|