@vibedev-si/dsh-vibedev 0.5.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -1
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/client/client.account-center.js +465 -5
- package/client/client.js +533 -30
- package/lib/announcements/routes.d.ts +70 -0
- package/lib/content/errors.d.ts +44 -0
- package/lib/content/service.d.ts +99 -0
- package/lib/contracts.d.ts +2 -2
- package/lib/gateway/http.d.ts +15 -3
- package/lib/index.d.ts +8 -0
- package/lib/index.js +711 -91
- package/lib/runtime.d.ts +2 -0
- package/lib/tools/image.d.ts +25 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -49,8 +49,8 @@ const MIN_READ_SPACING_MS = 5e3;
|
|
|
49
49
|
* current when nobody opens anything.
|
|
50
50
|
*/
|
|
51
51
|
const CATALOG_REFRESH_GAP_MS = 6e4;
|
|
52
|
-
const record$
|
|
53
|
-
const text$
|
|
52
|
+
const record$14 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
53
|
+
const text$9 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
54
54
|
/**
|
|
55
55
|
* A gateway amount as plain decimal text: a number as JavaScript writes it (`99976091.91426945`; the few numbers it
|
|
56
56
|
* writes with an exponent are spelled out), a string as sent; anything else, or text that is not a plain decimal, is
|
|
@@ -62,7 +62,7 @@ function amountOf(value) {
|
|
|
62
62
|
if (!Number.isFinite(value)) return void 0;
|
|
63
63
|
raw = String(value);
|
|
64
64
|
if (raw.includes("e")) raw = Math.abs(value) >= 1 ? BigInt(value).toString() : value.toFixed(20).replace(/0+$/, "").replace(/\.$/, "");
|
|
65
|
-
} else raw = text$
|
|
65
|
+
} else raw = text$9(value);
|
|
66
66
|
return raw !== void 0 && /^-?\d+(\.\d+)?$/.test(raw) ? raw : void 0;
|
|
67
67
|
}
|
|
68
68
|
/** What a read showed, for telling whether the next one changed anything (when it was read is not a change). */
|
|
@@ -304,14 +304,14 @@ var AccountService = class {
|
|
|
304
304
|
redirect: "error"
|
|
305
305
|
});
|
|
306
306
|
if (!response.ok) return {};
|
|
307
|
-
const body = record$
|
|
308
|
-
const data = record$
|
|
307
|
+
const body = record$14(await response.json().catch(() => void 0));
|
|
308
|
+
const data = record$14(body?.data) ?? body;
|
|
309
309
|
const balance = amountOf(data?.balance);
|
|
310
|
-
const currency = text$
|
|
310
|
+
const currency = text$9(data?.currency) ?? "CNY";
|
|
311
311
|
const frozen = amountOf(data?.frozen_balance);
|
|
312
|
-
const id = typeof data?.id === "number" ? String(data.id) : text$
|
|
313
|
-
const nickname = text$
|
|
314
|
-
const email = text$
|
|
312
|
+
const id = typeof data?.id === "number" ? String(data.id) : text$9(data?.id);
|
|
313
|
+
const nickname = text$9(data?.nickname) ?? text$9(data?.username);
|
|
314
|
+
const email = text$9(data?.email);
|
|
315
315
|
const user = id === void 0 && nickname === void 0 && email === void 0 ? void 0 : {
|
|
316
316
|
...id === void 0 ? {} : { id },
|
|
317
317
|
...email === void 0 ? {} : { email },
|
|
@@ -416,7 +416,7 @@ function userOf(user) {
|
|
|
416
416
|
...nickname === void 0 ? {} : { nickname }
|
|
417
417
|
};
|
|
418
418
|
}
|
|
419
|
-
function json$
|
|
419
|
+
function json$3(status, body) {
|
|
420
420
|
return new Response(JSON.stringify(body), {
|
|
421
421
|
status,
|
|
422
422
|
headers: {
|
|
@@ -426,9 +426,9 @@ function json$2(status, body) {
|
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
428
|
function failure$1(error) {
|
|
429
|
-
const candidate = record$
|
|
429
|
+
const candidate = record$14(error)?.code;
|
|
430
430
|
const code = candidate === "SIGN_IN_REFUSED" || candidate === "SIGN_IN_TIMEOUT" || candidate === "SIGN_IN_CANCELLED" ? candidate : "INTERNAL";
|
|
431
|
-
return json$
|
|
431
|
+
return json$3(500, { error: {
|
|
432
432
|
code,
|
|
433
433
|
message: code === "SIGN_IN_CANCELLED" ? "Sign-in was cancelled. 登录已取消。" : code === "SIGN_IN_TIMEOUT" ? "Sign-in expired. 登录已超时,请重新登录。" : "The account request could not be completed. 账号请求未完成,请查看登录诊断后重试。"
|
|
434
434
|
} });
|
|
@@ -445,8 +445,8 @@ function accountRoutes(account) {
|
|
|
445
445
|
methods: ["POST"],
|
|
446
446
|
requestBody: "buffered",
|
|
447
447
|
fetch: async (request) => {
|
|
448
|
-
const body = record$
|
|
449
|
-
return json$
|
|
448
|
+
const body = record$14(await request.json().catch(() => void 0));
|
|
449
|
+
return json$3(200, { consumed: typeof body?.id === "string" && account.consumeNavigation(body.id) });
|
|
450
450
|
}
|
|
451
451
|
},
|
|
452
452
|
{
|
|
@@ -458,7 +458,7 @@ function accountRoutes(account) {
|
|
|
458
458
|
const query = new URL(request.url, "http://host").searchParams;
|
|
459
459
|
const since = query.get("since");
|
|
460
460
|
if (since !== null && /^\d{1,15}$/.test(since)) await account.wait(Number(since), request.signal);
|
|
461
|
-
return json$
|
|
461
|
+
return json$3(200, await account.view(query.get("fresh") === "1"));
|
|
462
462
|
} catch (error) {
|
|
463
463
|
return failure$1(error);
|
|
464
464
|
}
|
|
@@ -470,8 +470,8 @@ function accountRoutes(account) {
|
|
|
470
470
|
requestBody: "buffered",
|
|
471
471
|
fetch: async (request) => {
|
|
472
472
|
try {
|
|
473
|
-
const body = record$
|
|
474
|
-
return json$
|
|
473
|
+
const body = record$14(await request.json().catch(() => void 0));
|
|
474
|
+
return json$3(200, await account.signIn(body?.open !== false));
|
|
475
475
|
} catch (error) {
|
|
476
476
|
return failure$1(error);
|
|
477
477
|
}
|
|
@@ -483,7 +483,7 @@ function accountRoutes(account) {
|
|
|
483
483
|
requestBody: "buffered",
|
|
484
484
|
fetch: () => {
|
|
485
485
|
account.cancel();
|
|
486
|
-
return Promise.resolve(json$
|
|
486
|
+
return Promise.resolve(json$3(200, { ok: true }));
|
|
487
487
|
}
|
|
488
488
|
},
|
|
489
489
|
{
|
|
@@ -492,7 +492,7 @@ function accountRoutes(account) {
|
|
|
492
492
|
requestBody: "buffered",
|
|
493
493
|
fetch: async () => {
|
|
494
494
|
try {
|
|
495
|
-
return await account.signOut() ? json$
|
|
495
|
+
return await account.signOut() ? json$3(200, { ok: true }) : json$3(409, { error: {
|
|
496
496
|
code: "SIGNED_IN_BY_APP",
|
|
497
497
|
message: "The VibeDev account is the app's sign-in; sign out in the app."
|
|
498
498
|
} });
|
|
@@ -605,10 +605,10 @@ function normalizeErrorStage(value) {
|
|
|
605
605
|
request: "submit"
|
|
606
606
|
}[word];
|
|
607
607
|
}
|
|
608
|
-
function record$
|
|
608
|
+
function record$13(value) {
|
|
609
609
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
610
610
|
}
|
|
611
|
-
function text$
|
|
611
|
+
function text$8(value) {
|
|
612
612
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
613
613
|
}
|
|
614
614
|
function count$1(value) {
|
|
@@ -617,7 +617,7 @@ function count$1(value) {
|
|
|
617
617
|
/** A CNY amount the gateway sends as a two-decimal string (a number is accepted too). */
|
|
618
618
|
function amount$1(value) {
|
|
619
619
|
if (typeof value === "number" && Number.isFinite(value)) return value.toFixed(2);
|
|
620
|
-
const raw = text$
|
|
620
|
+
const raw = text$8(value);
|
|
621
621
|
return raw !== void 0 && /^-?\d+(?:\.\d+)?$/.test(raw) ? raw : void 0;
|
|
622
622
|
}
|
|
623
623
|
/**
|
|
@@ -631,16 +631,16 @@ function amount$1(value) {
|
|
|
631
631
|
* @returns the fields found.
|
|
632
632
|
*/
|
|
633
633
|
function parseGatewayFailure(body) {
|
|
634
|
-
const root = record$
|
|
634
|
+
const root = record$13(body);
|
|
635
635
|
if (root === void 0) return {};
|
|
636
|
-
const source = record$
|
|
637
|
-
const metadata = record$
|
|
638
|
-
const gatewayCode = text$
|
|
639
|
-
const code = gatewayCode ?? text$
|
|
640
|
-
const message = text$
|
|
641
|
-
const field = text$
|
|
642
|
-
const rule = text$
|
|
643
|
-
const rechargeUrl = text$
|
|
636
|
+
const source = record$13(root.error) ?? root;
|
|
637
|
+
const metadata = record$13(source.metadata) ?? record$13(root.metadata);
|
|
638
|
+
const gatewayCode = text$8(source.gateway_code) ?? text$8(root.gateway_code);
|
|
639
|
+
const code = gatewayCode ?? text$8(source.code) ?? text$8(source.type) ?? text$8(root.reason);
|
|
640
|
+
const message = text$8(source.message) ?? (typeof root.error === "string" ? text$8(root.error) : void 0);
|
|
641
|
+
const field = text$8(source.field) ?? text$8(metadata?.field);
|
|
642
|
+
const rule = text$8(source.rule) ?? text$8(metadata?.rule);
|
|
643
|
+
const rechargeUrl = text$8(source.recharge_url) ?? text$8(root.recharge_url);
|
|
644
644
|
const numbers = {
|
|
645
645
|
active: count$1(source.active),
|
|
646
646
|
limit: count$1(source.limit)
|
|
@@ -650,19 +650,19 @@ function parseGatewayFailure(body) {
|
|
|
650
650
|
availableCny: amount$1(source.available_cny),
|
|
651
651
|
pendingCny: amount$1(source.pending_cny)
|
|
652
652
|
};
|
|
653
|
-
const submissionState = text$
|
|
654
|
-
const retryAction = text$
|
|
655
|
-
const assetId = text$
|
|
653
|
+
const submissionState = text$8(source.submission_state) ?? text$8(root.submission_state);
|
|
654
|
+
const retryAction = text$8(source.retry_action) ?? text$8(root.retry_action);
|
|
655
|
+
const assetId = text$8(source.asset_id) ?? text$8(root.asset_id);
|
|
656
656
|
return {
|
|
657
657
|
...gatewayCode === void 0 ? {} : { gatewayCode },
|
|
658
658
|
...Object.fromEntries(Object.entries({
|
|
659
|
-
category: normalizeErrorCategory(text$
|
|
660
|
-
stage: normalizeErrorStage(text$
|
|
661
|
-
requestId: text$
|
|
662
|
-
taskId: text$
|
|
663
|
-
operationId: text$
|
|
664
|
-
billingState: text$
|
|
665
|
-
retryAt: text$
|
|
659
|
+
category: normalizeErrorCategory(text$8(source.category) ?? text$8(root.category), code),
|
|
660
|
+
stage: normalizeErrorStage(text$8(source.stage) ?? text$8(root.stage)),
|
|
661
|
+
requestId: text$8(source.request_id) ?? text$8(root.request_id),
|
|
662
|
+
taskId: text$8(source.task_id) ?? text$8(root.task_id),
|
|
663
|
+
operationId: text$8(source.operation_id) ?? text$8(root.operation_id),
|
|
664
|
+
billingState: text$8(source.billing_state) ?? text$8(root.billing_state),
|
|
665
|
+
retryAt: text$8(source.retry_at) ?? text$8(root.retry_at),
|
|
666
666
|
retryAfterSeconds: count$1(source.retry_after_seconds) ?? count$1(root.retry_after_seconds)
|
|
667
667
|
}).filter(([, value]) => value !== void 0)),
|
|
668
668
|
...code === void 0 ? {} : { code },
|
|
@@ -729,11 +729,11 @@ function gatewayFailureWithHeaders(body, headers) {
|
|
|
729
729
|
const failure = parseGatewayFailure(body);
|
|
730
730
|
return {
|
|
731
731
|
...failure,
|
|
732
|
-
code: failure.gatewayCode ?? text$
|
|
733
|
-
category: normalizeErrorCategory(failure.category ?? text$
|
|
734
|
-
requestId: failure.requestId ?? text$
|
|
735
|
-
retryAction: failure.retryAction ?? text$
|
|
736
|
-
retryAt: failure.retryAt ?? text$
|
|
732
|
+
code: failure.gatewayCode ?? text$8(headers.get("x-vibedev-error-code")) ?? failure.code,
|
|
733
|
+
category: normalizeErrorCategory(failure.category ?? text$8(headers.get("x-vibedev-error-category")), failure.gatewayCode ?? text$8(headers.get("x-vibedev-error-code")) ?? failure.code),
|
|
734
|
+
requestId: failure.requestId ?? text$8(headers.get("x-request-id")),
|
|
735
|
+
retryAction: failure.retryAction ?? text$8(headers.get("x-vibedev-retry-action")),
|
|
736
|
+
retryAt: failure.retryAt ?? text$8(headers.get("x-vibedev-retry-at"))
|
|
737
737
|
};
|
|
738
738
|
}
|
|
739
739
|
function isUserAuthenticationFailure(failure) {
|
|
@@ -742,19 +742,19 @@ function isUserAuthenticationFailure(failure) {
|
|
|
742
742
|
function sdkGatewayFailure(message, headers = {}) {
|
|
743
743
|
const prefix = /\bvibedev:([A-Z][A-Z0-9_]{1,100}):/.exec(message)?.[1];
|
|
744
744
|
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];
|
|
745
|
-
const code = text$
|
|
746
|
-
const category = text$
|
|
745
|
+
const code = text$8(headers["x-vibedev-error-code"]) ?? prefix ?? legacy;
|
|
746
|
+
const category = text$8(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");
|
|
747
747
|
if (code === void 0 && category === void 0) return void 0;
|
|
748
748
|
return {
|
|
749
749
|
code,
|
|
750
750
|
category: normalizeErrorCategory(category, code),
|
|
751
|
-
requestId: text$
|
|
752
|
-
retryAction: text$
|
|
751
|
+
requestId: text$8(headers["x-request-id"]),
|
|
752
|
+
retryAction: text$8(headers["x-vibedev-retry-action"])
|
|
753
753
|
};
|
|
754
754
|
}
|
|
755
755
|
//#endregion
|
|
756
756
|
//#region src/account/center-price-contract.ts
|
|
757
|
-
const record$
|
|
757
|
+
const record$12 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
758
758
|
const keys = (value = "") => value.split(" ").filter(Boolean);
|
|
759
759
|
const scalar$1 = (value) => value === null || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" && value.length <= 1e3 && !/\b(?:Bearer\s|vdat_|sk-)|https?:\/\/|eyJ[A-Za-z0-9_-]+\./i.test(value) ? value : void 0;
|
|
760
760
|
/** Only public DNS HTTPS references become navigable links. No credentials, IPs or local hosts. */
|
|
@@ -772,7 +772,7 @@ function publicReferenceUrl(value) {
|
|
|
772
772
|
}
|
|
773
773
|
function project$1(value, shape) {
|
|
774
774
|
if (value === null) return null;
|
|
775
|
-
const source = record$
|
|
775
|
+
const source = record$12(value);
|
|
776
776
|
if (!source) return void 0;
|
|
777
777
|
const out = {};
|
|
778
778
|
for (const key of keys(shape.fields)) {
|
|
@@ -800,7 +800,7 @@ function project$1(value, shape) {
|
|
|
800
800
|
out[key] = source[key].slice(0, key === "models" ? 48 : 1e3).map((item) => child === "scalar" ? scalar$1(item) : child === "matrix" ? Array.isArray(item) ? item.slice(0, 64).map(scalar$1).filter((v) => v !== void 0) : void 0 : project$1(item, child)).filter((item) => item !== void 0);
|
|
801
801
|
}
|
|
802
802
|
for (const [key, child] of Object.entries(shape.maps ?? {})) {
|
|
803
|
-
const map = record$
|
|
803
|
+
const map = record$12(source[key]);
|
|
804
804
|
if (!map) continue;
|
|
805
805
|
out[key] = Object.fromEntries(Object.entries(map).slice(0, 64).filter(([name, value]) => /^[a-z][a-z0-9_]{0,63}$/i.test(name) && !/secret|password|credential|api_key/i.test(name) && (key !== "reasoning_effort_multipliers" || [
|
|
806
806
|
"none",
|
|
@@ -1628,11 +1628,11 @@ function projectBusinessReceipt(value) {
|
|
|
1628
1628
|
//#endregion
|
|
1629
1629
|
//#region src/account/center-contract.ts
|
|
1630
1630
|
/** Exact, read-only account-page schemas. No caller-selected URL or object shape. */
|
|
1631
|
-
const record$
|
|
1631
|
+
const record$11 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1632
1632
|
const fields = (text) => text.split(" ");
|
|
1633
1633
|
const scalar = (value) => value === null || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" && value.length <= 1e3 && !/\b(?:Bearer\s|vdat_|sk-)|https?:\/\/|eyJ[A-Za-z0-9_-]+\./i.test(value) ? value : void 0;
|
|
1634
1634
|
function project(value, shape) {
|
|
1635
|
-
const source = record$
|
|
1635
|
+
const source = record$11(value);
|
|
1636
1636
|
if (source === void 0) return void 0;
|
|
1637
1637
|
if (shape === imageSizes) return Object.fromEntries(Object.entries(source).filter(([key, item]) => {
|
|
1638
1638
|
const kilo = /^(\d{1,2}(?:\.\d{1,3})?)K$/.exec(key), dimensions = /^(\d{1,5})x(\d{1,5})$/.exec(key);
|
|
@@ -1887,7 +1887,7 @@ function centerQuery(path, params) {
|
|
|
1887
1887
|
/** Legacy summary only: monetary weekly fields become a percentage, never a five-hour window. */
|
|
1888
1888
|
function projectAccountData(value) {
|
|
1889
1889
|
const convert = (item) => {
|
|
1890
|
-
const output = project(item, subscription), source = record$
|
|
1890
|
+
const output = project(item, subscription), source = record$11(item);
|
|
1891
1891
|
if (output === void 0 || source === void 0) return void 0;
|
|
1892
1892
|
const number = (n) => typeof n === "number" && Number.isFinite(n) ? n : typeof n === "string" && /^\d+(?:\.\d+)?$/.test(n) ? Number(n) : void 0;
|
|
1893
1893
|
const used = number(source.weekly_used_usd), limit = number(source.weekly_limit_usd);
|
|
@@ -1899,7 +1899,7 @@ function projectAccountData(value) {
|
|
|
1899
1899
|
return output;
|
|
1900
1900
|
};
|
|
1901
1901
|
if (Array.isArray(value)) return value.slice(0, 1e3).map(convert).filter((item) => item !== void 0);
|
|
1902
|
-
const source = record$
|
|
1902
|
+
const source = record$11(value);
|
|
1903
1903
|
return source === void 0 ? {} : {
|
|
1904
1904
|
...project(source, { fields: ["active_count"] }),
|
|
1905
1905
|
...Array.isArray(source.subscriptions) ? { subscriptions: source.subscriptions.slice(0, 1e3).map(convert).filter((item) => item !== void 0) } : {}
|
|
@@ -2136,6 +2136,178 @@ function accountCenterRoutes(http, account) {
|
|
|
2136
2136
|
})), ...accountBusinessActionsRoutes(http, account)];
|
|
2137
2137
|
}
|
|
2138
2138
|
//#endregion
|
|
2139
|
+
//#region src/announcements/routes.ts
|
|
2140
|
+
/** The Host route the renderer polls. */
|
|
2141
|
+
const ANNOUNCEMENTS_ROUTE = "/api/dsh-vibedev/announcements";
|
|
2142
|
+
/**
|
|
2143
|
+
* The receipt's own Host route. A Host Fetch route owns one exact pathname, so this is a
|
|
2144
|
+
* sibling of the list rather than a `:id` child of it; the id is in the request body.
|
|
2145
|
+
*/
|
|
2146
|
+
const ANNOUNCEMENTS_READ_ROUTE = `${ANNOUNCEMENTS_ROUTE}/read`;
|
|
2147
|
+
/**
|
|
2148
|
+
* Where the gateway serves the same list. Every account read goes to `/v1/account/*`
|
|
2149
|
+
* (`auth/me`, `entitlements`, `model-plaza`, `payment/*`, and our own `feedback`), so
|
|
2150
|
+
* announcements belong beside them; `/api/v1/vibedev/*` is only the sign-in and
|
|
2151
|
+
* device-authorization surface (`app-token/*`, `link/redeem`).
|
|
2152
|
+
*/
|
|
2153
|
+
const GATEWAY_ANNOUNCEMENTS_PATH = "/v1/account/announcements";
|
|
2154
|
+
const json$2 = (status, body) => new Response(JSON.stringify(body), {
|
|
2155
|
+
status,
|
|
2156
|
+
headers: {
|
|
2157
|
+
"content-type": "application/json; charset=utf-8",
|
|
2158
|
+
"cache-control": "no-store"
|
|
2159
|
+
}
|
|
2160
|
+
});
|
|
2161
|
+
const unavailable = () => json$2(200, {
|
|
2162
|
+
available: false,
|
|
2163
|
+
items: [],
|
|
2164
|
+
unread: 0
|
|
2165
|
+
});
|
|
2166
|
+
const record$10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2167
|
+
const text$7 = (value) => typeof value === "string" ? value : void 0;
|
|
2168
|
+
const identifier = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
2169
|
+
/**
|
|
2170
|
+
* One announcement from the wire, with every field it needs and nothing else.
|
|
2171
|
+
* @param value - one entry of the gateway's list.
|
|
2172
|
+
* @returns the announcement, or undefined when the entry cannot be rendered.
|
|
2173
|
+
*/
|
|
2174
|
+
function parseAnnouncement(value) {
|
|
2175
|
+
const item = record$10(value);
|
|
2176
|
+
if (item === void 0) return void 0;
|
|
2177
|
+
const id = identifier(item.id);
|
|
2178
|
+
const title = text$7(item.title);
|
|
2179
|
+
const content = text$7(item.content);
|
|
2180
|
+
const createdAt = text$7(item.created_at);
|
|
2181
|
+
if (id === void 0 || title === void 0 || content === void 0 || createdAt === void 0) return void 0;
|
|
2182
|
+
return {
|
|
2183
|
+
id,
|
|
2184
|
+
title,
|
|
2185
|
+
content,
|
|
2186
|
+
createdAt,
|
|
2187
|
+
notifyMode: item.notify_mode === "popup" ? "popup" : "silent",
|
|
2188
|
+
...typeof item.starts_at === "string" ? { startsAt: item.starts_at } : {},
|
|
2189
|
+
...typeof item.ends_at === "string" ? { endsAt: item.ends_at } : {},
|
|
2190
|
+
readAt: text$7(item.read_at) ?? null
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
/**
|
|
2194
|
+
* The entries of a list answer, whether the gateway wraps them or not.
|
|
2195
|
+
* @param payload - the parsed body.
|
|
2196
|
+
* @returns the entries, or undefined when the body is not a list.
|
|
2197
|
+
*/
|
|
2198
|
+
function entriesOf(payload) {
|
|
2199
|
+
if (Array.isArray(payload)) return payload;
|
|
2200
|
+
const data = record$10(payload)?.data;
|
|
2201
|
+
return Array.isArray(data) ? data : void 0;
|
|
2202
|
+
}
|
|
2203
|
+
/**
|
|
2204
|
+
* Both routes.
|
|
2205
|
+
* @param options - the gateway client and the account whose credential the reads go with.
|
|
2206
|
+
* @returns routes for the client connection.
|
|
2207
|
+
*/
|
|
2208
|
+
function announcementRoutes({ http, account }) {
|
|
2209
|
+
const changed = () => {
|
|
2210
|
+
http.invalidateAccountSnapshots();
|
|
2211
|
+
return json$2(409, { error: {
|
|
2212
|
+
code: "ACCOUNT_CHANGED",
|
|
2213
|
+
category: "authentication",
|
|
2214
|
+
message: "账号已切换,请刷新页面。"
|
|
2215
|
+
} });
|
|
2216
|
+
};
|
|
2217
|
+
/** Resolve the account and refuse a read that belongs to the account the page no longer shows. */
|
|
2218
|
+
const enter = async (request) => {
|
|
2219
|
+
const identity = await account.identity();
|
|
2220
|
+
if (!identity.signedIn) return json$2(401, { error: {
|
|
2221
|
+
code: "AUTHENTICATION_REQUIRED",
|
|
2222
|
+
category: "authentication",
|
|
2223
|
+
message: "请先登录 VibeDev。"
|
|
2224
|
+
} });
|
|
2225
|
+
const expected = request.headers.get("X-VibeDev-Expected-User");
|
|
2226
|
+
if (expected !== null && expected !== identity.userId) return changed();
|
|
2227
|
+
return { identity };
|
|
2228
|
+
};
|
|
2229
|
+
/**
|
|
2230
|
+
* Whether a refusal means "this gateway has no announcements yet" rather than a real failure.
|
|
2231
|
+
* A route that does not exist answers 404; a method it does not serve answers 405.
|
|
2232
|
+
*/
|
|
2233
|
+
const missing = (error) => error instanceof MediaError && (error.details.status === 404 || error.details.status === 405);
|
|
2234
|
+
const request = (identity, signal) => ({
|
|
2235
|
+
timeoutMs: 15e3,
|
|
2236
|
+
signal,
|
|
2237
|
+
busyRetries: 0,
|
|
2238
|
+
isCurrentAccount: async () => {
|
|
2239
|
+
const now = await account.identity();
|
|
2240
|
+
return now.signedIn && now.userId === identity.userId;
|
|
2241
|
+
}
|
|
2242
|
+
});
|
|
2243
|
+
return [{
|
|
2244
|
+
path: ANNOUNCEMENTS_ROUTE,
|
|
2245
|
+
methods: ["GET"],
|
|
2246
|
+
requestBody: "buffered",
|
|
2247
|
+
fetch: async (incoming) => {
|
|
2248
|
+
const entered = await enter(incoming);
|
|
2249
|
+
if (entered instanceof Response) return entered;
|
|
2250
|
+
const unreadOnly = new URL(incoming.url, "http://host").searchParams.get("unread_only") === "true";
|
|
2251
|
+
try {
|
|
2252
|
+
const entries = entriesOf(await http.json(`${GATEWAY_ANNOUNCEMENTS_PATH}${unreadOnly ? "?unread_only=true" : ""}`, request(entered.identity, incoming.signal)));
|
|
2253
|
+
if (entries === void 0) return json$2(502, { error: {
|
|
2254
|
+
code: "ANNOUNCEMENTS_UNREADABLE",
|
|
2255
|
+
category: "service_unavailable"
|
|
2256
|
+
} });
|
|
2257
|
+
const items = entries.map(parseAnnouncement).filter((item) => item !== void 0);
|
|
2258
|
+
const unread = items.filter((item) => item.readAt === null).length;
|
|
2259
|
+
return json$2(200, {
|
|
2260
|
+
available: true,
|
|
2261
|
+
items,
|
|
2262
|
+
unread
|
|
2263
|
+
});
|
|
2264
|
+
} catch (error) {
|
|
2265
|
+
if (missing(error)) return unavailable();
|
|
2266
|
+
if (error instanceof MediaError && error.details.status === 401) return json$2(401, { error: {
|
|
2267
|
+
code: "AUTHENTICATION_REQUIRED",
|
|
2268
|
+
category: "authentication",
|
|
2269
|
+
message: "请先登录 VibeDev。"
|
|
2270
|
+
} });
|
|
2271
|
+
return json$2(502, { error: {
|
|
2272
|
+
code: "ANNOUNCEMENTS_UNAVAILABLE",
|
|
2273
|
+
category: "service_unavailable"
|
|
2274
|
+
} });
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
}, {
|
|
2278
|
+
path: ANNOUNCEMENTS_READ_ROUTE,
|
|
2279
|
+
methods: ["POST"],
|
|
2280
|
+
requestBody: "buffered",
|
|
2281
|
+
fetch: async (incoming) => {
|
|
2282
|
+
const entered = await enter(incoming);
|
|
2283
|
+
if (entered instanceof Response) return entered;
|
|
2284
|
+
const body = record$10(await incoming.json().catch(() => void 0));
|
|
2285
|
+
const id = identifier(body?.id);
|
|
2286
|
+
if (id === void 0) return json$2(400, { error: {
|
|
2287
|
+
code: "ANNOUNCEMENT_INVALID_ID",
|
|
2288
|
+
category: "invalid_input"
|
|
2289
|
+
} });
|
|
2290
|
+
try {
|
|
2291
|
+
await http.json(`${GATEWAY_ANNOUNCEMENTS_PATH}/${id}/read`, {
|
|
2292
|
+
...request(entered.identity, incoming.signal),
|
|
2293
|
+
method: "POST",
|
|
2294
|
+
json: {}
|
|
2295
|
+
});
|
|
2296
|
+
return json$2(200, { ok: true });
|
|
2297
|
+
} catch (error) {
|
|
2298
|
+
if (missing(error)) return json$2(200, {
|
|
2299
|
+
ok: false,
|
|
2300
|
+
available: false
|
|
2301
|
+
});
|
|
2302
|
+
return json$2(502, { error: {
|
|
2303
|
+
code: "ANNOUNCEMENT_RECEIPT_FAILED",
|
|
2304
|
+
category: "service_unavailable"
|
|
2305
|
+
} });
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
}];
|
|
2309
|
+
}
|
|
2310
|
+
//#endregion
|
|
2139
2311
|
//#region src/account/latency.ts
|
|
2140
2312
|
/** Path of the latency route. */
|
|
2141
2313
|
const LATENCY_ROUTE = "/api/dsh-vibedev/latency";
|
|
@@ -3193,7 +3365,8 @@ const ACCOUNT_PAGES = [
|
|
|
3193
3365
|
"orders",
|
|
3194
3366
|
"redeem",
|
|
3195
3367
|
"affiliate",
|
|
3196
|
-
"profile"
|
|
3368
|
+
"profile",
|
|
3369
|
+
"messages"
|
|
3197
3370
|
];
|
|
3198
3371
|
//#endregion
|
|
3199
3372
|
//#region src/gateway/http.ts
|
|
@@ -3318,11 +3491,12 @@ var GatewayHttp = class {
|
|
|
3318
3491
|
}
|
|
3319
3492
|
}
|
|
3320
3493
|
/**
|
|
3321
|
-
* Send one request and return the
|
|
3494
|
+
* Send one request and return the answer the caller asked to see.
|
|
3322
3495
|
* @param path - gateway path, or an absolute URL.
|
|
3323
3496
|
* @param request - method, body, headers and retry policy.
|
|
3324
|
-
* @returns the 2xx response,
|
|
3325
|
-
*
|
|
3497
|
+
* @returns the 2xx response, or — only when the request asks for it — a `304` (`allowNotModified`) or a redirect hop
|
|
3498
|
+
* (`redirect: 'manual'`); body unread.
|
|
3499
|
+
* @throws {@link MediaError} for every other refusal, with the gateway's code.
|
|
3326
3500
|
*/
|
|
3327
3501
|
async send(path, request = {}) {
|
|
3328
3502
|
const url = this.url(path);
|
|
@@ -3351,6 +3525,8 @@ var GatewayHttp = class {
|
|
|
3351
3525
|
} catch {}
|
|
3352
3526
|
return response;
|
|
3353
3527
|
}
|
|
3528
|
+
if (response.status === 304 && request.allowNotModified === true) return response;
|
|
3529
|
+
if (request.redirect === "manual" && response.status >= 300 && response.status < 400) return response;
|
|
3354
3530
|
const failure = gatewayFailureWithHeaders(await response.clone().json().catch(() => void 0), response.headers);
|
|
3355
3531
|
if (imageCreation && imageSubmissionUncertain(failure)) throw uncertainImage(request.idempotencyKey, void 0, response.status, failure);
|
|
3356
3532
|
if (response.status === 401 && isUserAuthenticationFailure(failure) && credential !== void 0 && credential.kind !== "key" && !refreshed) {
|
|
@@ -3431,7 +3607,7 @@ var GatewayHttp = class {
|
|
|
3431
3607
|
method: request.method ?? (body === void 0 ? "GET" : "POST"),
|
|
3432
3608
|
headers,
|
|
3433
3609
|
...body === void 0 ? {} : { body },
|
|
3434
|
-
redirect: "error",
|
|
3610
|
+
redirect: request.redirect ?? "error",
|
|
3435
3611
|
signal
|
|
3436
3612
|
});
|
|
3437
3613
|
} catch (error) {
|
|
@@ -7786,7 +7962,7 @@ function baseName(source) {
|
|
|
7786
7962
|
const name = (source.split(/[?#]/)[0] ?? source).split(/[\\/]/).pop() ?? "";
|
|
7787
7963
|
return name === "" ? "media" : decodeURIComponent(name);
|
|
7788
7964
|
}
|
|
7789
|
-
async function readCapped(response, maxBytes, source) {
|
|
7965
|
+
async function readCapped$1(response, maxBytes, source) {
|
|
7790
7966
|
const declared = Number(response.headers.get("content-length"));
|
|
7791
7967
|
if (Number.isFinite(declared) && declared > maxBytes) throw new MediaError(`"${source}" is ${(declared / 1048576).toFixed(1)} MiB; the limit is ${(maxBytes / 1048576).toFixed(1)} MiB.`, "MEDIA_TOO_LARGE");
|
|
7792
7968
|
const reader = response.body?.getReader();
|
|
@@ -7853,7 +8029,7 @@ async function loadMedia(source, reader, maxBytes, signal) {
|
|
|
7853
8029
|
throw new MediaError(`Could not download "${trimmed}" (${error instanceof Error ? error.message : String(error)}).`, "MEDIA_DOWNLOAD_FAILED", {}, { cause: error });
|
|
7854
8030
|
}
|
|
7855
8031
|
if (!response.ok) throw new MediaError(`Downloading "${trimmed}" failed with HTTP ${response.status}.`, "MEDIA_DOWNLOAD_FAILED", { status: response.status });
|
|
7856
|
-
const data = await readCapped(response, maxBytes, trimmed);
|
|
8032
|
+
const data = await readCapped$1(response, maxBytes, trimmed);
|
|
7857
8033
|
const sniffed = sniffMime(data, trimmed);
|
|
7858
8034
|
const header = response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
7859
8035
|
const mime = sniffed !== "application/octet-stream" ? sniffed : header ?? sniffed;
|
|
@@ -9131,6 +9307,414 @@ var GatewaySearchProvider = class {
|
|
|
9131
9307
|
}
|
|
9132
9308
|
};
|
|
9133
9309
|
//#endregion
|
|
9310
|
+
//#region src/content/errors.ts
|
|
9311
|
+
/**
|
|
9312
|
+
* The content library's failures. Callers of `vibedevContent` (dsh-film's
|
|
9313
|
+
* `GatewaySource`) route on three fields of the thrown object — `code`, `status`
|
|
9314
|
+
* and `message`: `code === 'NOT_SIGNED_IN'` or `status === 401` means "signed
|
|
9315
|
+
* out". The gateway client's own `MediaError` keeps `status` inside `details`,
|
|
9316
|
+
* so this layer translates it into a `ContentError` that carries both on top.
|
|
9317
|
+
* @module dsh-vibedev/content/errors
|
|
9318
|
+
*/
|
|
9319
|
+
/**
|
|
9320
|
+
* One content failure, with `code` and `status` at the top level: the host
|
|
9321
|
+
* contract reads them there, never inside a details object.
|
|
9322
|
+
*/
|
|
9323
|
+
var ContentError = class extends HarnessError {
|
|
9324
|
+
status;
|
|
9325
|
+
retryAfterMs;
|
|
9326
|
+
retryable;
|
|
9327
|
+
/**
|
|
9328
|
+
* @param message - what happened and what to do next.
|
|
9329
|
+
* @param code - the stable failure class.
|
|
9330
|
+
* @param facts - status, wait and retry facts.
|
|
9331
|
+
* @param options - the underlying cause, when there is one.
|
|
9332
|
+
*/
|
|
9333
|
+
constructor(message, code, facts = {}, options) {
|
|
9334
|
+
super(message, code, options);
|
|
9335
|
+
this.name = "ContentError";
|
|
9336
|
+
this.status = facts.status;
|
|
9337
|
+
this.retryAfterMs = facts.retryAfterMs;
|
|
9338
|
+
this.retryable = facts.retryable === true;
|
|
9339
|
+
}
|
|
9340
|
+
};
|
|
9341
|
+
const SIGN_IN = "需要登录 VibeDev 才能读取创作库:请在侧栏登录后重试。";
|
|
9342
|
+
/**
|
|
9343
|
+
* One failure from anywhere below this service, in the shape a content caller reads.
|
|
9344
|
+
* @param error - whatever was thrown, including non-errors (`Promise.reject()`).
|
|
9345
|
+
* @returns the failure to throw.
|
|
9346
|
+
*/
|
|
9347
|
+
function contentFailure(error) {
|
|
9348
|
+
if (error instanceof ContentError) return error;
|
|
9349
|
+
const thrown = error ?? {};
|
|
9350
|
+
const code = typeof thrown.code === "string" ? thrown.code : "";
|
|
9351
|
+
const status = typeof thrown.details?.status === "number" ? thrown.details.status : void 0;
|
|
9352
|
+
const retryAfterMs = typeof thrown.details?.retryAfterMs === "number" ? thrown.details.retryAfterMs : void 0;
|
|
9353
|
+
const options = error instanceof Error ? { cause: error } : {};
|
|
9354
|
+
const statusWords = status === void 0 ? "" : `${status}${code === "" || code === `HTTP_${status}` ? "" : `,${code}`}`;
|
|
9355
|
+
if (code === "ABORTED") return new ContentError("创作库请求已取消。", "ABORTED", { retryable: true }, options);
|
|
9356
|
+
if (code === "NOT_SIGNED_IN" || status === 401) return new ContentError(SIGN_IN, "NOT_SIGNED_IN", { status: 401 }, options);
|
|
9357
|
+
if (code === "NOT_FOUND" || status === 404) return new ContentError("创作库里没有这个文件或目录。", "NOT_FOUND", { status: 404 }, options);
|
|
9358
|
+
if (code === "RATE_LIMITED" || status === 429) return new ContentError(`创作库请求太频繁,请稍后重试${retryAfterMs === void 0 || retryAfterMs < 1e3 ? "" : `(约 ${Math.ceil(retryAfterMs / 1e3)} 秒后重试)`}。`, "RATE_LIMITED", {
|
|
9359
|
+
status: 429,
|
|
9360
|
+
...retryAfterMs === void 0 ? {} : { retryAfterMs },
|
|
9361
|
+
retryable: true
|
|
9362
|
+
}, options);
|
|
9363
|
+
if (code === "GATEWAY_UNREACHABLE" || code === "GATEWAY_TIMEOUT") return new ContentError("连不上 VibeDev 网关:请检查网络后重试。", "NETWORK_ERROR", { retryable: true }, options);
|
|
9364
|
+
if (code === "GATEWAY_BAD_RESPONSE") return new ContentError("网关返回的内容无法解析,请稍后重试。", "GATEWAY_BAD_RESPONSE", {
|
|
9365
|
+
...status === void 0 ? {} : { status },
|
|
9366
|
+
retryable: true
|
|
9367
|
+
}, options);
|
|
9368
|
+
if (status !== void 0 && status >= 500) return new ContentError(`创作库暂时取不到(网关 HTTP ${statusWords}),请稍后重试。`, "GATEWAY_ERROR", {
|
|
9369
|
+
status,
|
|
9370
|
+
...retryAfterMs === void 0 ? {} : { retryAfterMs },
|
|
9371
|
+
retryable: true
|
|
9372
|
+
}, options);
|
|
9373
|
+
if (status !== void 0 && status >= 400) return new ContentError(`网关拒绝了创作库请求(HTTP ${statusWords})。`, "REFUSED", {
|
|
9374
|
+
status,
|
|
9375
|
+
retryable: status === 403
|
|
9376
|
+
}, options);
|
|
9377
|
+
return new ContentError("创作库内容暂时取不到,请稍后重试。", "GATEWAY_ERROR", { retryable: true }, options);
|
|
9378
|
+
}
|
|
9379
|
+
/** Every extension a catalog reference may carry (`docs/handoff/gateway.md` §2). */
|
|
9380
|
+
const CONTENT_BLOB_EXTENSIONS = [
|
|
9381
|
+
".zip",
|
|
9382
|
+
".webp",
|
|
9383
|
+
".mp3",
|
|
9384
|
+
".ogg",
|
|
9385
|
+
".wav"
|
|
9386
|
+
];
|
|
9387
|
+
/** The largest file this service returns: the gateway's own per-file limit is 5 MB. */
|
|
9388
|
+
const CONTENT_BLOB_MAX_BYTES = 8388608;
|
|
9389
|
+
/** The sentence a caller reads when the transfer itself broke, worded as `contentFailure` words it. */
|
|
9390
|
+
const NETWORK_MESSAGE = "连不上 VibeDev 网关:请检查网络后重试。";
|
|
9391
|
+
/** The sentence for a read the caller cancelled, worded as `contentFailure` words it. */
|
|
9392
|
+
const CANCELLED_MESSAGE = "创作库请求已取消。";
|
|
9393
|
+
/** How long one catalog read or one download may take in all: retries, busy waits and the body included. */
|
|
9394
|
+
const DEFAULT_DEADLINE_MS = 9e4;
|
|
9395
|
+
/** The statuses whose `Location` this service follows itself; any other 3xx is a refusal (see `follow`). */
|
|
9396
|
+
const REDIRECTS = /* @__PURE__ */ new Set([
|
|
9397
|
+
301,
|
|
9398
|
+
302,
|
|
9399
|
+
303,
|
|
9400
|
+
307,
|
|
9401
|
+
308
|
|
9402
|
+
]);
|
|
9403
|
+
/** The `code` values a broken transfer carries (undici and the socket layer). */
|
|
9404
|
+
const BROKEN_CODE = /^(?:UND_ERR_(?:BODY|CONNECT|HEADERS)_TIMEOUT|UND_ERR_SOCKET|ECONNRESET|EPIPE|ETIMEDOUT)$/;
|
|
9405
|
+
/** The messages a broken transfer carries, for the errors that name no code. */
|
|
9406
|
+
const BROKEN_TEXT = /terminated|aborted|ECONNRESET|EPIPE|socket hang up|other side closed|timed? ?out/i;
|
|
9407
|
+
/** The creative library, for other plugins (dsh-film reads it as `vibedevContent`). */
|
|
9408
|
+
var ContentHostService = class {
|
|
9409
|
+
options;
|
|
9410
|
+
constructor(options) {
|
|
9411
|
+
this.options = options;
|
|
9412
|
+
}
|
|
9413
|
+
get version() {
|
|
9414
|
+
return this.options.version;
|
|
9415
|
+
}
|
|
9416
|
+
/** Whether a VibeDev account is signed in, on which gateway, and under which user. */
|
|
9417
|
+
account() {
|
|
9418
|
+
return this.options.account();
|
|
9419
|
+
}
|
|
9420
|
+
/**
|
|
9421
|
+
* The catalog the gateway currently publishes.
|
|
9422
|
+
* @param request - the caller's ETag, and a signal that cancels the read.
|
|
9423
|
+
* @returns the catalog, or `notModified` when the caller's ETag is still current.
|
|
9424
|
+
* @throws {@link ContentError} `NOT_SIGNED_IN` when nobody is signed in, `ABORTED` when the caller cancelled,
|
|
9425
|
+
* `NETWORK_ERROR` when the transfer broke or outlasted the deadline.
|
|
9426
|
+
*/
|
|
9427
|
+
async catalog(request = {}) {
|
|
9428
|
+
const { etag: asked, signal: callerSignal } = request ?? {};
|
|
9429
|
+
const etag = typeof asked === "string" ? asked.trim() : "";
|
|
9430
|
+
try {
|
|
9431
|
+
const response = await this.options.http.send("/v1/film-library/catalog", {
|
|
9432
|
+
method: "GET",
|
|
9433
|
+
allowNotModified: true,
|
|
9434
|
+
timeoutMs: this.options.deadlineMs ?? DEFAULT_DEADLINE_MS,
|
|
9435
|
+
busyRetries: 2,
|
|
9436
|
+
maxBusyWaitMs: 5e3,
|
|
9437
|
+
signal: this.operationSignal(callerSignal),
|
|
9438
|
+
...etag === "" ? {} : { headers: { "if-none-match": etag } }
|
|
9439
|
+
});
|
|
9440
|
+
if (response.status === 304) return { notModified: true };
|
|
9441
|
+
const body = await response.json().catch((cause) => {
|
|
9442
|
+
throw interruptedFailure(cause, callerSignal) ?? new ContentError("创作库目录不是有效的 JSON。", "GATEWAY_BAD_RESPONSE", {
|
|
9443
|
+
status: response.status,
|
|
9444
|
+
retryable: true
|
|
9445
|
+
}, { cause });
|
|
9446
|
+
});
|
|
9447
|
+
const revision = revisionOf(body);
|
|
9448
|
+
return {
|
|
9449
|
+
notModified: false,
|
|
9450
|
+
etag: canonicalEtag(response.headers.get("etag")) ?? `"${revision}"`,
|
|
9451
|
+
body
|
|
9452
|
+
};
|
|
9453
|
+
} catch (error) {
|
|
9454
|
+
throw this.settled(error, callerSignal);
|
|
9455
|
+
}
|
|
9456
|
+
}
|
|
9457
|
+
/**
|
|
9458
|
+
* One file the catalog references, by content hash.
|
|
9459
|
+
* @param request - the hash, the extension and a signal that cancels the download.
|
|
9460
|
+
* @returns the bytes, after checking them against the hash.
|
|
9461
|
+
* @throws {@link ContentError} `NOT_FOUND` for a hash the gateway does not have,
|
|
9462
|
+
* `HASH_MISMATCH` for bytes that are not the file the catalog named.
|
|
9463
|
+
*/
|
|
9464
|
+
async file(request) {
|
|
9465
|
+
const sha256 = normalizeSha256(request?.sha256);
|
|
9466
|
+
const extension = normalizeExtension(request?.extension);
|
|
9467
|
+
const callerSignal = request?.signal;
|
|
9468
|
+
const signal = this.operationSignal(callerSignal);
|
|
9469
|
+
const path = `/v1/film-library/blobs/${sha256}${extension}`;
|
|
9470
|
+
try {
|
|
9471
|
+
const first = await this.options.http.send(path, {
|
|
9472
|
+
method: "GET",
|
|
9473
|
+
redirect: "manual",
|
|
9474
|
+
headers: { accept: "*/*" },
|
|
9475
|
+
timeoutMs: 6e4,
|
|
9476
|
+
busyRetries: 2,
|
|
9477
|
+
maxBusyWaitMs: 1e4,
|
|
9478
|
+
signal
|
|
9479
|
+
});
|
|
9480
|
+
const data = await readCapped(first.status >= 300 && first.status < 400 ? await this.follow(first, signal) : first, CONTENT_BLOB_MAX_BYTES, callerSignal);
|
|
9481
|
+
if (createHash("sha256").update(data).digest("hex") !== sha256) throw new ContentError("下载的创作库文件校验失败:内容与目录登记的哈希不符。", "HASH_MISMATCH");
|
|
9482
|
+
return data;
|
|
9483
|
+
} catch (error) {
|
|
9484
|
+
throw this.settled(error, callerSignal);
|
|
9485
|
+
}
|
|
9486
|
+
}
|
|
9487
|
+
/**
|
|
9488
|
+
* The storage URL a redirect names, read without the gateway credential.
|
|
9489
|
+
* @param response - the redirect the gateway answered.
|
|
9490
|
+
* @param signal - the caller's signal and this download's deadline, as one.
|
|
9491
|
+
* @returns the storage response.
|
|
9492
|
+
*/
|
|
9493
|
+
async follow(response, signal) {
|
|
9494
|
+
await response.body?.cancel().catch(() => void 0);
|
|
9495
|
+
if (!REDIRECTS.has(response.status)) throw new ContentError("网关的下载答法无法处理。", "GATEWAY_BAD_RESPONSE", {
|
|
9496
|
+
status: response.status,
|
|
9497
|
+
retryable: false
|
|
9498
|
+
});
|
|
9499
|
+
const location = response.headers.get("location")?.trim();
|
|
9500
|
+
if (location === void 0 || location === "") throw new ContentError("网关让下载跳转,但没有给出地址。", "GATEWAY_BAD_RESPONSE", {
|
|
9501
|
+
status: response.status,
|
|
9502
|
+
retryable: false
|
|
9503
|
+
});
|
|
9504
|
+
const target = absoluteLocation(location, this.options.http.origin);
|
|
9505
|
+
if (target === void 0) throw new ContentError("网关给出的下载地址无法识别,已拒绝。", "GATEWAY_BAD_RESPONSE", {
|
|
9506
|
+
status: response.status,
|
|
9507
|
+
retryable: false
|
|
9508
|
+
});
|
|
9509
|
+
if (!this.mayFollowTo(target)) throw new ContentError("网关给出的下载地址不是 https 链接,已拒绝。", "GATEWAY_BAD_RESPONSE", {
|
|
9510
|
+
status: response.status,
|
|
9511
|
+
retryable: false
|
|
9512
|
+
});
|
|
9513
|
+
const hop = await this.options.http.send(target.toString(), {
|
|
9514
|
+
method: "GET",
|
|
9515
|
+
anonymous: true,
|
|
9516
|
+
redirect: "manual",
|
|
9517
|
+
headers: { accept: "*/*" },
|
|
9518
|
+
timeoutMs: 6e4,
|
|
9519
|
+
busyRetries: 0,
|
|
9520
|
+
signal
|
|
9521
|
+
}).catch((cause) => {
|
|
9522
|
+
const status = statusOf(cause);
|
|
9523
|
+
if (status !== void 0 && status >= 400 && status < 500 && status !== 429) throw new ContentError("网关给出的下载地址被拒绝,请稍后重试。", "GATEWAY_BAD_RESPONSE", { retryable: true }, { cause });
|
|
9524
|
+
throw cause;
|
|
9525
|
+
});
|
|
9526
|
+
if (hop.status >= 300 && hop.status < 400) {
|
|
9527
|
+
await hop.body?.cancel().catch(() => void 0);
|
|
9528
|
+
throw new ContentError("下载地址又跳转了一次,已拒绝。", "GATEWAY_BAD_RESPONSE", {
|
|
9529
|
+
status: hop.status,
|
|
9530
|
+
retryable: true
|
|
9531
|
+
});
|
|
9532
|
+
}
|
|
9533
|
+
return hop;
|
|
9534
|
+
}
|
|
9535
|
+
/**
|
|
9536
|
+
* Whether a hop may go to this address: https anywhere, plain http only from a gateway that is itself plain http
|
|
9537
|
+
* (a development or loopback gateway).
|
|
9538
|
+
* @param target - the resolved redirect target.
|
|
9539
|
+
*/
|
|
9540
|
+
mayFollowTo(target) {
|
|
9541
|
+
if (target.protocol === "https:") return true;
|
|
9542
|
+
return target.protocol === "http:" && this.options.http.origin.toLowerCase().startsWith("http:");
|
|
9543
|
+
}
|
|
9544
|
+
/**
|
|
9545
|
+
* The caller's signal and this operation's own deadline, as one signal.
|
|
9546
|
+
* @param callerSignal - the caller's signal, when it passed one.
|
|
9547
|
+
*/
|
|
9548
|
+
operationSignal(callerSignal) {
|
|
9549
|
+
const deadline = AbortSignal.timeout(this.options.deadlineMs ?? DEFAULT_DEADLINE_MS);
|
|
9550
|
+
return callerSignal === void 0 ? deadline : AbortSignal.any([callerSignal, deadline]);
|
|
9551
|
+
}
|
|
9552
|
+
/**
|
|
9553
|
+
* One failure from below, in the shape a content caller reads.
|
|
9554
|
+
* @param error - whatever was thrown.
|
|
9555
|
+
* @param callerSignal - the caller's own signal: our deadline is not a cancellation.
|
|
9556
|
+
*/
|
|
9557
|
+
settled(error, callerSignal) {
|
|
9558
|
+
const failure = contentFailure(error);
|
|
9559
|
+
if (failure.code === "ABORTED" && callerSignal?.aborted !== true) return new ContentError(NETWORK_MESSAGE, "NETWORK_ERROR", { retryable: true }, { cause: error });
|
|
9560
|
+
return failure;
|
|
9561
|
+
}
|
|
9562
|
+
};
|
|
9563
|
+
/**
|
|
9564
|
+
* The failure a body read really ended with, when the answer itself is not the problem.
|
|
9565
|
+
* @param error - what the body read threw.
|
|
9566
|
+
* @param callerSignal - the caller's own signal, if any; its abort makes this a cancellation.
|
|
9567
|
+
* @returns the failure to throw, or undefined when the answer is unreadable (the caller words that).
|
|
9568
|
+
*/
|
|
9569
|
+
function interruptedFailure(error, callerSignal) {
|
|
9570
|
+
if (callerSignal?.aborted === true) return new ContentError(CANCELLED_MESSAGE, "ABORTED", { retryable: true }, { cause: error });
|
|
9571
|
+
if (causeChain(error).some((link) => link.name === "TimeoutError" || BROKEN_CODE.test(link.code) || BROKEN_TEXT.test(link.message))) return new ContentError(NETWORK_MESSAGE, "NETWORK_ERROR", { retryable: true }, { cause: error });
|
|
9572
|
+
}
|
|
9573
|
+
/**
|
|
9574
|
+
* The HTTP status a failure from below names, read from the two error types that can carry one and from their causes:
|
|
9575
|
+
* the gateway client keeps it in `details`, a content failure on top. Nothing else counts — a `status` property on
|
|
9576
|
+
* some other thrown value is not the gateway answering.
|
|
9577
|
+
* @param error - whatever was thrown.
|
|
9578
|
+
* @returns the status, or undefined when no layer of it names one.
|
|
9579
|
+
*/
|
|
9580
|
+
function statusOf(error) {
|
|
9581
|
+
let current = error;
|
|
9582
|
+
for (let depth = 0; depth < 4 && current !== void 0 && current !== null; depth++) {
|
|
9583
|
+
if (current instanceof ContentError) return current.status;
|
|
9584
|
+
if (current instanceof MediaError) return current.details.status;
|
|
9585
|
+
current = current.cause;
|
|
9586
|
+
}
|
|
9587
|
+
}
|
|
9588
|
+
/**
|
|
9589
|
+
* The name, message and code of an error and of every error it wraps.
|
|
9590
|
+
* @param error - whatever was thrown.
|
|
9591
|
+
* @returns the facts of the chain, outermost first.
|
|
9592
|
+
*/
|
|
9593
|
+
function causeChain(error) {
|
|
9594
|
+
const links = [];
|
|
9595
|
+
let current = error;
|
|
9596
|
+
for (let depth = 0; depth < 4 && current !== void 0 && current !== null; depth++) {
|
|
9597
|
+
const record = typeof current === "object" || typeof current === "function" ? current : {};
|
|
9598
|
+
links.push({
|
|
9599
|
+
name: typeof record.name === "string" ? record.name : "",
|
|
9600
|
+
message: typeof record.message === "string" ? record.message : "",
|
|
9601
|
+
code: typeof record.code === "string" ? record.code : ""
|
|
9602
|
+
});
|
|
9603
|
+
current = record.cause;
|
|
9604
|
+
}
|
|
9605
|
+
return links;
|
|
9606
|
+
}
|
|
9607
|
+
/**
|
|
9608
|
+
* A redirect target, resolved against the gateway origin.
|
|
9609
|
+
* @param location - the `Location` header.
|
|
9610
|
+
* @param origin - the gateway origin, for a relative address.
|
|
9611
|
+
* @returns the URL, or undefined when it cannot be read as one.
|
|
9612
|
+
*/
|
|
9613
|
+
function absoluteLocation(location, origin) {
|
|
9614
|
+
try {
|
|
9615
|
+
return new URL(location, origin);
|
|
9616
|
+
} catch {
|
|
9617
|
+
return;
|
|
9618
|
+
}
|
|
9619
|
+
}
|
|
9620
|
+
/**
|
|
9621
|
+
* A gateway ETag, when it really is one: `If-None-Match` can only carry an entity tag.
|
|
9622
|
+
* @param value - the `ETag` header.
|
|
9623
|
+
* @returns the tag, or undefined when the header is missing or is something else.
|
|
9624
|
+
*/
|
|
9625
|
+
function canonicalEtag(value) {
|
|
9626
|
+
const tag = value?.trim();
|
|
9627
|
+
return tag === void 0 || !/^(?:W\/)?"[^"]*"$/.test(tag) ? void 0 : tag;
|
|
9628
|
+
}
|
|
9629
|
+
/**
|
|
9630
|
+
* The revision of a catalog body, after checking the schema this service understands.
|
|
9631
|
+
* @param body - the parsed JSON.
|
|
9632
|
+
* @returns the revision (`0` for a gateway that has published nothing yet).
|
|
9633
|
+
*/
|
|
9634
|
+
function revisionOf(body) {
|
|
9635
|
+
const record = typeof body === "object" && body !== null && !Array.isArray(body) ? body : void 0;
|
|
9636
|
+
if (record === void 0) throw new ContentError("创作库目录不是 JSON 对象。", "GATEWAY_BAD_RESPONSE", { retryable: true });
|
|
9637
|
+
if (record.schema !== 1) throw new ContentError(`创作库目录的 schema ${typeof record.schema === "number" ? `是 ${String(record.schema)}` : "不是数字"},这个版本只认 1:请更新账号插件。`, "GATEWAY_BAD_RESPONSE", { retryable: true });
|
|
9638
|
+
const revision = record.revision;
|
|
9639
|
+
if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 0) throw new ContentError("创作库目录的 revision 不是非负整数。", "GATEWAY_BAD_RESPONSE", { retryable: true });
|
|
9640
|
+
return revision;
|
|
9641
|
+
}
|
|
9642
|
+
/**
|
|
9643
|
+
* A content hash, as the catalog stores it.
|
|
9644
|
+
* @param value - what the caller passed.
|
|
9645
|
+
* @returns the 64 lowercase hex digits.
|
|
9646
|
+
*/
|
|
9647
|
+
function normalizeSha256(value) {
|
|
9648
|
+
const text = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
9649
|
+
if (!/^[a-f0-9]{64}$/.test(text)) throw new ContentError("创作库文件编号必须是 64 位十六进制 sha256。", "INVALID_REQUEST");
|
|
9650
|
+
return text;
|
|
9651
|
+
}
|
|
9652
|
+
/**
|
|
9653
|
+
* An extension from the reference pool. The caller may pass `.webp` or `webp`; nothing else gets through, which is
|
|
9654
|
+
* also what keeps a caller-supplied path out of the URL.
|
|
9655
|
+
* @param value - what the caller passed.
|
|
9656
|
+
* @returns the extension with its dot.
|
|
9657
|
+
*/
|
|
9658
|
+
function normalizeExtension(value) {
|
|
9659
|
+
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
9660
|
+
const extension = raw === "" ? "" : raw.startsWith(".") ? raw : `.${raw}`;
|
|
9661
|
+
if (!CONTENT_BLOB_EXTENSIONS.includes(extension)) throw new ContentError(`创作库文件的扩展名只能是 ${CONTENT_BLOB_EXTENSIONS.join("、")}。`, "INVALID_REQUEST");
|
|
9662
|
+
return extension;
|
|
9663
|
+
}
|
|
9664
|
+
/**
|
|
9665
|
+
* Read a body no larger than `maxBytes`, checking any declared length first and stopping at the cap while reading:
|
|
9666
|
+
* the bytes never held in memory are the ones over the limit.
|
|
9667
|
+
* @param response - a 2xx response whose body is unread.
|
|
9668
|
+
* @param maxBytes - the largest accepted size.
|
|
9669
|
+
* @param callerSignal - the caller's signal, so a cancelled read is reported as one.
|
|
9670
|
+
* @returns the bytes.
|
|
9671
|
+
*/
|
|
9672
|
+
async function readCapped(response, maxBytes, callerSignal) {
|
|
9673
|
+
const tooLarge = () => new ContentError(`创作库文件超过 ${maxBytes / 1048576} MB 的上限,已拒绝下载。`, "BLOB_TOO_LARGE", {
|
|
9674
|
+
status: response.status,
|
|
9675
|
+
retryable: false
|
|
9676
|
+
});
|
|
9677
|
+
const declaredHeader = response.headers.get("content-length");
|
|
9678
|
+
const declared = declaredHeader === null || declaredHeader.trim() === "" ? void 0 : Number(declaredHeader);
|
|
9679
|
+
if (declared !== void 0 && Number.isFinite(declared) && declared > maxBytes) {
|
|
9680
|
+
await response.body?.cancel().catch(() => void 0);
|
|
9681
|
+
throw tooLarge();
|
|
9682
|
+
}
|
|
9683
|
+
if (response.body === null) throw new ContentError("网关没有返回文件内容。", "GATEWAY_BAD_RESPONSE", {
|
|
9684
|
+
status: response.status,
|
|
9685
|
+
retryable: true
|
|
9686
|
+
});
|
|
9687
|
+
const reader = response.body.getReader();
|
|
9688
|
+
const chunks = [];
|
|
9689
|
+
let total = 0;
|
|
9690
|
+
for (;;) {
|
|
9691
|
+
let chunk;
|
|
9692
|
+
try {
|
|
9693
|
+
const step = await reader.read();
|
|
9694
|
+
chunk = step.done ? void 0 : step.value;
|
|
9695
|
+
} catch (error) {
|
|
9696
|
+
throw interruptedFailure(error, callerSignal) ?? new ContentError("创作库文件没有读完,请重试。", "GATEWAY_BAD_RESPONSE", {
|
|
9697
|
+
status: response.status,
|
|
9698
|
+
retryable: true
|
|
9699
|
+
}, { cause: error });
|
|
9700
|
+
}
|
|
9701
|
+
if (chunk === void 0) break;
|
|
9702
|
+
total += chunk.byteLength;
|
|
9703
|
+
if (total > maxBytes) {
|
|
9704
|
+
await reader.cancel().catch(() => void 0);
|
|
9705
|
+
throw tooLarge();
|
|
9706
|
+
}
|
|
9707
|
+
chunks.push(chunk);
|
|
9708
|
+
}
|
|
9709
|
+
const data = new Uint8Array(total);
|
|
9710
|
+
let offset = 0;
|
|
9711
|
+
for (const chunk of chunks) {
|
|
9712
|
+
data.set(chunk, offset);
|
|
9713
|
+
offset += chunk.byteLength;
|
|
9714
|
+
}
|
|
9715
|
+
return data;
|
|
9716
|
+
}
|
|
9717
|
+
//#endregion
|
|
9134
9718
|
//#region src/util/decimal.ts
|
|
9135
9719
|
const PATTERN = /^(-?)(\d+)(?:\.(\d*))?(?:e([+-]?\d+))?$/i;
|
|
9136
9720
|
/**
|
|
@@ -11006,6 +11590,34 @@ async function generateImages(runtime, call, request, save) {
|
|
|
11006
11590
|
};
|
|
11007
11591
|
}
|
|
11008
11592
|
/**
|
|
11593
|
+
* Build the result blocks for one generation.
|
|
11594
|
+
*
|
|
11595
|
+
* A result normally names the saved files and nothing else: carrying the pictures is what rewrote a conversation's
|
|
11596
|
+
* middle, made the next turn read the whole prompt again and charged for it. The model reads one back with
|
|
11597
|
+
* `read_image` when it needs to look; `attach` asks for them on this call, the plugin setting on every call.
|
|
11598
|
+
* @param value - the tool's structured result.
|
|
11599
|
+
* @param options - `attach` from the call and the plugin setting.
|
|
11600
|
+
* @returns a text block naming the files, plus an image block per picture when the pictures were asked for.
|
|
11601
|
+
*/
|
|
11602
|
+
function imageResultBlocks(value, options) {
|
|
11603
|
+
const pictures = options.attach === true || options.attach !== false && options.imagesInContext === true ? value.images.filter((image) => image.attachment !== void 0 && image.attachment !== null) : [];
|
|
11604
|
+
const count = value.images.length;
|
|
11605
|
+
const lines = ["Generated " + count + " image" + (count === 1 ? "" : "s") + " with " + value.model + ": " + value.images.map((image) => image.path).join(", ") + "."];
|
|
11606
|
+
if (pictures.length > 0) lines.push(count === 1 ? "It is attached below." : "They are attached below.");
|
|
11607
|
+
else lines.push(count === 1 ? "Only the saved file is here, so you cannot see the picture: read it with read_image when you need to look, or pass its path as reference_images to edit it." : "Only the saved files are here, so you cannot see the pictures: read one with read_image when you need to look, or pass a path as reference_images to edit it.");
|
|
11608
|
+
if (value.estimatedCny !== void 0) lines.push("Estimated cost " + yuan(Number(value.estimatedCny)) + ".");
|
|
11609
|
+
if (value.revisedPrompt !== void 0) lines.push("The model rewrote the prompt as: " + value.revisedPrompt);
|
|
11610
|
+
const blocks = [{
|
|
11611
|
+
type: "text",
|
|
11612
|
+
text: lines.join(" ")
|
|
11613
|
+
}];
|
|
11614
|
+
for (const picture of pictures) blocks.push({
|
|
11615
|
+
type: "image",
|
|
11616
|
+
attachment: picture.attachment
|
|
11617
|
+
});
|
|
11618
|
+
return blocks;
|
|
11619
|
+
}
|
|
11620
|
+
/**
|
|
11009
11621
|
* Build the tool.
|
|
11010
11622
|
* @param runtime - the media runtime.
|
|
11011
11623
|
* @returns the tool definition.
|
|
@@ -11013,7 +11625,7 @@ async function generateImages(runtime, call, request, save) {
|
|
|
11013
11625
|
function imageGenerateTool(runtime) {
|
|
11014
11626
|
return defineTool({
|
|
11015
11627
|
name: "image_generate",
|
|
11016
|
-
description: "Generate images with a VibeDev image model and save them in the workspace (media/images/)
|
|
11628
|
+
description: "Generate images with a VibeDev image model and save them in the workspace (media/images/). The result is the saved files, not the pictures: read one with read_image when you need to look at it. With reference_images it edits or derives from those images (style transfer, variations, putting a product into a scene). Costs VibeDev balance per image (about ¥0.1 for gpt-image models); use media_models for the models and prices. Takes about 20 seconds per image.",
|
|
11017
11629
|
parameters: {
|
|
11018
11630
|
prompt: {
|
|
11019
11631
|
type: "string",
|
|
@@ -11042,6 +11654,10 @@ function imageGenerateTool(runtime) {
|
|
|
11042
11654
|
type: "integer",
|
|
11043
11655
|
description: "Number of images, 1-4. Default 1."
|
|
11044
11656
|
},
|
|
11657
|
+
attach: {
|
|
11658
|
+
type: "boolean",
|
|
11659
|
+
description: "Put the pictures in this result so you can see them without a second call; false keeps the saved paths only. Omit for the default."
|
|
11660
|
+
},
|
|
11045
11661
|
reference_images: {
|
|
11046
11662
|
type: "array",
|
|
11047
11663
|
items: { type: "string" },
|
|
@@ -11092,20 +11708,10 @@ function imageGenerateTool(runtime) {
|
|
|
11092
11708
|
revisedPrompt: { type: "string" }
|
|
11093
11709
|
}
|
|
11094
11710
|
},
|
|
11095
|
-
render: (
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
const blocks = [{
|
|
11100
|
-
type: "text",
|
|
11101
|
-
text: lines.join(" ")
|
|
11102
|
-
}];
|
|
11103
|
-
for (const image of value.images) if (image.attachment !== void 0 && image.attachment !== null) blocks.push({
|
|
11104
|
-
type: "image",
|
|
11105
|
-
attachment: image.attachment
|
|
11106
|
-
});
|
|
11107
|
-
return blocks;
|
|
11108
|
-
}
|
|
11711
|
+
render: (args, value) => imageResultBlocks(value, {
|
|
11712
|
+
attach: args.attach,
|
|
11713
|
+
imagesInContext: runtime.settings.imagesInContext()
|
|
11714
|
+
})
|
|
11109
11715
|
},
|
|
11110
11716
|
async execute(args, exec) {
|
|
11111
11717
|
const result = await generateImages(runtime, exec, {
|
|
@@ -14323,6 +14929,7 @@ const Config = Schema.object({
|
|
|
14323
14929
|
submitAttempts: Schema.natural().min(1).max(30).default(3),
|
|
14324
14930
|
reconcileAttempts: Schema.natural().max(30).default(30),
|
|
14325
14931
|
confirmSpending: Schema.boolean().default(false).volatile(),
|
|
14932
|
+
imagesInContext: Schema.boolean().default(false).volatile(),
|
|
14326
14933
|
outputDir: Schema.string().default("media").volatile(),
|
|
14327
14934
|
imageModel: Schema.string().default("").volatile(),
|
|
14328
14935
|
videoModel: Schema.string().default("").volatile(),
|
|
@@ -14348,6 +14955,7 @@ const Config = Schema.object({
|
|
|
14348
14955
|
submitAttempts: "原键首次提交总尝试数(含首次,默认3)",
|
|
14349
14956
|
reconcileAttempts: "原键后台核对次数(0关闭,默认30)",
|
|
14350
14957
|
confirmSpending: "每次付费生成前先询问(默认关闭)",
|
|
14958
|
+
imagesInContext: "把生成的图片发给模型(默认关闭:只给保存路径)",
|
|
14351
14959
|
outputDir: "保存目录(相对于工作区)",
|
|
14352
14960
|
imageModel: "默认生图模型(留空由 Agent 按目录选择)",
|
|
14353
14961
|
videoModel: "默认视频模型(留空由 Agent 按目录选择)",
|
|
@@ -14373,6 +14981,7 @@ const Config = Schema.object({
|
|
|
14373
14981
|
submitAttempts: "Initial same-key attempts including first dispatch (default 3)",
|
|
14374
14982
|
reconcileAttempts: "Additional same-key checks (0 disables; default 30)",
|
|
14375
14983
|
confirmSpending: "Ask before each paid generation (off by default)",
|
|
14984
|
+
imagesInContext: "Send generated images to the model (off by default: paths only)",
|
|
14376
14985
|
outputDir: "Output folder (relative to the workspace)",
|
|
14377
14986
|
imageModel: "Default image model (empty: the agent chooses from the catalog)",
|
|
14378
14987
|
videoModel: "Default video model (empty: the agent chooses from the catalog)",
|
|
@@ -14388,7 +14997,7 @@ const Config = Schema.object({
|
|
|
14388
14997
|
stateDir: "Plugin data folder (empty for the default)"
|
|
14389
14998
|
}
|
|
14390
14999
|
});
|
|
14391
|
-
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/. 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.";
|
|
15000
|
+
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.";
|
|
14392
15001
|
function apply(ctx, config) {
|
|
14393
15002
|
const origin = normalizeGatewayOrigin(config.gatewayOrigin);
|
|
14394
15003
|
const stateDir = stateDirectory(config.stateDir);
|
|
@@ -14463,6 +15072,7 @@ function apply(ctx, config) {
|
|
|
14463
15072
|
settings: {
|
|
14464
15073
|
outputDir: () => config.outputDir.get(),
|
|
14465
15074
|
confirmSpending: () => config.confirmSpending.get(),
|
|
15075
|
+
imagesInContext: () => config.imagesInContext.get(),
|
|
14466
15076
|
defaultModel: (slot) => slots[slot].get()
|
|
14467
15077
|
},
|
|
14468
15078
|
fs: () => ctx.get("fs"),
|
|
@@ -14480,20 +15090,26 @@ function apply(ctx, config) {
|
|
|
14480
15090
|
mediaTasksTool(runtime),
|
|
14481
15091
|
mediaAccountTool(runtime, chain, login)
|
|
14482
15092
|
]) ctx.tools.register(tool);
|
|
15093
|
+
const accountContext = async () => {
|
|
15094
|
+
const identity = await account?.identity();
|
|
15095
|
+
const snapshot = await account?.view();
|
|
15096
|
+
return {
|
|
15097
|
+
gatewayOrigin: origin,
|
|
15098
|
+
signedIn: identity?.signedIn === true,
|
|
15099
|
+
...identity?.signedIn !== true || identity.userId === void 0 ? {} : { userId: identity.userId },
|
|
15100
|
+
...snapshot === void 0 ? {} : { revision: String(snapshot.revision) }
|
|
15101
|
+
};
|
|
15102
|
+
};
|
|
14483
15103
|
ctx.effect(() => ctx.provide("vibedevMedia", new MediaHostService(runtime, version, {
|
|
14484
|
-
account:
|
|
14485
|
-
const identity = await account?.identity();
|
|
14486
|
-
const snapshot = await account?.view();
|
|
14487
|
-
return {
|
|
14488
|
-
gatewayOrigin: origin,
|
|
14489
|
-
signedIn: identity?.signedIn === true,
|
|
14490
|
-
...identity?.signedIn !== true || identity.userId === void 0 ? {} : { userId: identity.userId },
|
|
14491
|
-
...snapshot === void 0 ? {} : { revision: String(snapshot.revision) }
|
|
14492
|
-
};
|
|
14493
|
-
},
|
|
15104
|
+
account: accountContext,
|
|
14494
15105
|
open: (page) => account?.openAccountCenter(page),
|
|
14495
15106
|
refresh: spent
|
|
14496
15107
|
})), "dsh-vibedev: media host service");
|
|
15108
|
+
ctx.effect(() => ctx.provide("vibedevContent", new ContentHostService({
|
|
15109
|
+
http,
|
|
15110
|
+
version,
|
|
15111
|
+
account: accountContext
|
|
15112
|
+
})), "dsh-vibedev: content host service");
|
|
14497
15113
|
const prompt = ctx.get("systemPrompt");
|
|
14498
15114
|
if (prompt !== void 0) prompt.section({
|
|
14499
15115
|
name: "tool:dsh-vibedev",
|
|
@@ -14584,6 +15200,10 @@ function apply(ctx, config) {
|
|
|
14584
15200
|
for (const accountRoute of [
|
|
14585
15201
|
...accountRoutes(accountService),
|
|
14586
15202
|
...accountCenterRoutes(http, accountService),
|
|
15203
|
+
...announcementRoutes({
|
|
15204
|
+
http,
|
|
15205
|
+
account: accountService
|
|
15206
|
+
}),
|
|
14587
15207
|
...latencyRoutes(latency)
|
|
14588
15208
|
]) scoped.effect(() => scoped.connection.fetch.register(accountRoute), `dsh-vibedev: ${accountRoute.path}`);
|
|
14589
15209
|
});
|
|
@@ -14634,6 +15254,6 @@ function apply(ctx, config) {
|
|
|
14634
15254
|
});
|
|
14635
15255
|
}
|
|
14636
15256
|
//#endregion
|
|
14637
|
-
export { ACCOUNT_ROUTE_PREFIX, AccountService, Config, FEEDBACK_ATTACHMENT_ROUTE, FEEDBACK_ROUTE, GATEWAY_FETCH_PROVIDER_ID as FETCH_PROVIDER_ID, GatewayFetchProvider, INSUFFICIENT_BALANCE_CODE, LATENCY_ROUTE, MediaError, MediaHostService, NegotiatedGatewayFetchProvider, GATEWAY_SEARCH_PROVIDER_ID as SEARCH_PROVIDER_ID, SIGN_IN_REQUIRED_CODE, VIBEDEV_RELAY_ROUTE, VIBEDEV_ROUTE, apply, inject, name, parseMediaCatalog, readGatewayFetchCapability, version };
|
|
15257
|
+
export { ACCOUNT_ROUTE_PREFIX, AccountService, Config, ContentError, ContentHostService, FEEDBACK_ATTACHMENT_ROUTE, FEEDBACK_ROUTE, GATEWAY_FETCH_PROVIDER_ID as FETCH_PROVIDER_ID, GatewayFetchProvider, INSUFFICIENT_BALANCE_CODE, LATENCY_ROUTE, MediaError, MediaHostService, NegotiatedGatewayFetchProvider, GATEWAY_SEARCH_PROVIDER_ID as SEARCH_PROVIDER_ID, SIGN_IN_REQUIRED_CODE, VIBEDEV_RELAY_ROUTE, VIBEDEV_ROUTE, apply, inject, name, parseMediaCatalog, readGatewayFetchCapability, version };
|
|
14638
15258
|
|
|
14639
15259
|
//# sourceMappingURL=index.js.map
|