@vibedev-si/dsh-vibedev 0.5.3 → 0.6.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 +24 -0
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/lib/content/errors.d.ts +44 -0
- package/lib/content/service.d.ts +99 -0
- package/lib/gateway/http.d.ts +15 -3
- package/lib/index.d.ts +4 -0
- package/lib/index.js +434 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
本插件由 `dsh-media` 改名而来,见下面的「从 dsh-media 升级」。
|
|
12
12
|
|
|
13
|
+
## 0.6.0 用户可见更新
|
|
14
|
+
|
|
15
|
+
新增给其他插件用的宿主服务 `vibedevContent`:影视工作台用它读取创作库(目录、按内容哈希下载并核对哈希的文件、登录状态)。要等网关的创作库接口上线、影视工作台接上之后才生效,这一版本身没有用户能看到的变化;媒体工具、模型和账户页一个字节都不变。见下文「给其他插件用」。
|
|
16
|
+
|
|
13
17
|
## 0.5.3 用户可见更新
|
|
14
18
|
|
|
15
19
|
旧充值返利比例为 0 时,邀请返利页对旧充值模式的好友写明“旧充值返利已停止,目前不产生返利”,不再显示“按 0% 返利”;读不到比例时写明暂时无法读取,不再说按充值金额返利。
|
|
@@ -279,6 +283,22 @@
|
|
|
279
283
|
|
|
280
284
|
0.3.8 起,`models()` 返回的图片模型会带上网关为它声明的尺寸档位和画面比例:网关 `/v1/models` 里的 `capabilities.image_sizes` 对应 `imageSizes`(如 `["1K", "1.5K", "2K", "4K"]`),`capabilities.image_ratios` 对应 `imageRatios`(如 `["1:1", "16:9", "9:16"]`),供影视工作台的图片节点列出可选项。每个模型各用自己的列表,按网关给的顺序和写法原样保留(`1.5K`、`3K` 不换算、不补全),只去掉非文字、空白和重复的项;没有声明、声明为空列表或格式不对时就不带这两个字段,不影响其余模型和整个列表。模型列表刷新后这两个字段随之更新,网关删掉的选项会消失。它们只是能力说明,不会出现在生成请求里:图片请求仍然只发送 `model`、`prompt`、`n`、`size`(像素宽高)和 `quality`。
|
|
281
285
|
|
|
286
|
+
### 创作库:`vibedevContent`(0.6.0)
|
|
287
|
+
|
|
288
|
+
影视工作台读「创作库」也走账号插件,凭据一样不离开这里。影视工作台(dsh-film)在 `src/library/source.ts` 里用 `ctx.get('vibedevContent')` 找到它,和找 `vibedevMedia` 一模一样。服务名 `vibedevContent`,三个方法:
|
|
289
|
+
|
|
290
|
+
| 方法 | 参数 | 返回 |
|
|
291
|
+
| --- | --- | --- |
|
|
292
|
+
| `account()` | 无 | 与 `vibedevMedia.account()` 同一个形状:`{ gatewayOrigin, signedIn, userId?, revision? }` |
|
|
293
|
+
| `catalog(request)` | `{ etag?, signal? }`:上次拿到的 `etag`;取消这次读取的 `AbortSignal` | `{ notModified: true }`(内容没变),或 `{ notModified: false, etag, body }`(`body` 是解析好的目录 JSON) |
|
|
294
|
+
| `file(request)` | `{ sha256, extension, signal? }`:目录登记的内容哈希(64 位十六进制),以及带点或不带点的扩展名 | `Uint8Array`:已经核对过哈希的文件字节 |
|
|
295
|
+
|
|
296
|
+
`catalog()` 走 `GET /v1/film-library/catalog`,传 `etag` 时带 `If-None-Match`,网关回 304 就只回 `notModified`;`file()` 走 `GET /v1/film-library/blobs/{sha256}{扩展名}`。
|
|
297
|
+
|
|
298
|
+
`extension` 写 `.webp` 或 `webp` 都行,只接受 `.zip`、`.webp`、`.mp3`、`.ogg`、`.wav`;单个文件上限 8 MB(网关自己限 5 MB)。网关用一次 3xx 跳转给出临时下载地址时,由插件自己跟这一次跳转(301、302、303、307、308 都认,再跳一次就算拒绝):跳转那一跳不带凭据;那一跳除了 429 之外收到任何 4xx,一律当作「网关给出的下载地址被拒绝,请稍后重试。」(`GATEWAY_BAD_RESPONSE`,可重试)——不带凭据的请求被拒,既不是这个用户的登录问题,也不是文件真的没了;429 仍按限流处理,5xx 和连不上仍按网关故障处理。
|
|
299
|
+
|
|
300
|
+
失败抛 `ContentError`,`code` 和 `status` 都在错误对象顶层(宿主的调用方只读这两个):`NOT_SIGNED_IN`(`status: 401`)、`NOT_FOUND`(404)、`RATE_LIMITED`(429,带 `retryAfterMs`)、`REFUSED`(其余 4xx)、`GATEWAY_ERROR`(5xx)、`GATEWAY_BAD_RESPONSE`、`NETWORK_ERROR`、`INVALID_REQUEST`、`BLOB_TOO_LARGE`、`HASH_MISMATCH`、`ABORTED`。`status` 只在网关确实对这次请求答复了 HTTP 状态时带上:标了状态码的那几类一定带;`GATEWAY_BAD_RESPONSE` 和 `BLOB_TOO_LARGE` 有时带(下载地址被拒绝的那一类不带,所以它不会被当成「需要登录」或「没有这个文件」);`NETWORK_ERROR`、`INVALID_REQUEST`、`HASH_MISMATCH`、`ABORTED` 不带。每条错误的 `message` 都是一句可以直接给用户看的中文,细节留在 `cause` 里。
|
|
301
|
+
|
|
282
302
|
## 开发
|
|
283
303
|
|
|
284
304
|
```bash
|
|
@@ -299,6 +319,10 @@ npm run build
|
|
|
299
319
|
|
|
300
320
|
## English
|
|
301
321
|
|
|
322
|
+
### What changes in 0.6.0
|
|
323
|
+
|
|
324
|
+
A new host service for other plugins, `vibedevContent`: the film workbench uses it to read the creative library (its catalog, files downloaded by content hash and checked against that hash, and the signed-in state). It takes effect only once the gateway's creative-library endpoints are live and the film workbench is wired to it — this version alone changes nothing a user can see, and the media tools, models and account pages are untouched. See "给其他插件用 / for other plugins" below.
|
|
325
|
+
|
|
302
326
|
### What changes in 0.5.3
|
|
303
327
|
|
|
304
328
|
When the old top-up rate is 0, the affiliate page says old top-up rebates have stopped and nothing is earned now for invitees on the old top-up rule, instead of showing a 0% rate. When the rate cannot be read, it says so instead of describing top-up rebates.
|
package/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.
|
|
1
|
+
THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.6.0
|
|
2
2
|
|
|
3
3
|
This package bundles code from the projects below. Each is used under the licence that
|
|
4
4
|
follows its name; the licence texts are reproduced as the projects ship them.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The content library's failures. Callers of `vibedevContent` (dsh-film's
|
|
3
|
+
* `GatewaySource`) route on three fields of the thrown object — `code`, `status`
|
|
4
|
+
* and `message`: `code === 'NOT_SIGNED_IN'` or `status === 401` means "signed
|
|
5
|
+
* out". The gateway client's own `MediaError` keeps `status` inside `details`,
|
|
6
|
+
* so this layer translates it into a `ContentError` that carries both on top.
|
|
7
|
+
* @module dsh-vibedev/content/errors
|
|
8
|
+
*/
|
|
9
|
+
import { HarnessError } from '@deepseek-ai/dsh-llm';
|
|
10
|
+
/** The failure classes a content caller routes on. */
|
|
11
|
+
export type ContentErrorCode = 'NOT_SIGNED_IN' | 'NOT_FOUND' | 'RATE_LIMITED' | 'REFUSED' | 'GATEWAY_ERROR' | 'GATEWAY_BAD_RESPONSE' | 'NETWORK_ERROR' | 'INVALID_REQUEST' | 'BLOB_TOO_LARGE' | 'HASH_MISMATCH' | 'ABORTED';
|
|
12
|
+
/** What a failure may carry besides its message. */
|
|
13
|
+
export interface ContentErrorFacts {
|
|
14
|
+
/** HTTP status when the gateway answered. */
|
|
15
|
+
readonly status?: number;
|
|
16
|
+
/** How long the gateway asked the client to wait (429). */
|
|
17
|
+
readonly retryAfterMs?: number;
|
|
18
|
+
/** Whether the same request may succeed later. */
|
|
19
|
+
readonly retryable?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One content failure, with `code` and `status` at the top level: the host
|
|
23
|
+
* contract reads them there, never inside a details object.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ContentError extends HarnessError {
|
|
26
|
+
/** Narrowed to the union below, so a caller can route on the exact failure class, not on any string. */
|
|
27
|
+
readonly code: ContentErrorCode;
|
|
28
|
+
readonly status?: number;
|
|
29
|
+
readonly retryAfterMs?: number;
|
|
30
|
+
readonly retryable: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @param message - what happened and what to do next.
|
|
33
|
+
* @param code - the stable failure class.
|
|
34
|
+
* @param facts - status, wait and retry facts.
|
|
35
|
+
* @param options - the underlying cause, when there is one.
|
|
36
|
+
*/
|
|
37
|
+
constructor(message: string, code: ContentErrorCode, facts?: ContentErrorFacts, options?: ErrorOptions);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One failure from anywhere below this service, in the shape a content caller reads.
|
|
41
|
+
* @param error - whatever was thrown, including non-errors (`Promise.reject()`).
|
|
42
|
+
* @returns the failure to throw.
|
|
43
|
+
*/
|
|
44
|
+
export declare function contentFailure(error: unknown): ContentError;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The content library host service, registered as `vibedevContent`: the current
|
|
3
|
+
* catalog (`GET /v1/film-library/catalog`, ETag-conditional) and one file by
|
|
4
|
+
* content hash (`GET /v1/film-library/blobs/{sha256}{ext}`), both through the
|
|
5
|
+
* same credential plane as every other gateway call. The credential never leaves
|
|
6
|
+
* this plugin: callers get the parsed catalog and verified bytes.
|
|
7
|
+
* @module dsh-vibedev/content/service
|
|
8
|
+
*/
|
|
9
|
+
import type { MediaAccountContext } from '../contracts.js';
|
|
10
|
+
import type { GatewayHttp } from '../gateway/http.js';
|
|
11
|
+
/** One catalog read: unchanged content answers only `notModified`. */
|
|
12
|
+
export type ContentCatalogOutcome = {
|
|
13
|
+
readonly notModified: true;
|
|
14
|
+
} | {
|
|
15
|
+
readonly notModified: false;
|
|
16
|
+
readonly etag: string;
|
|
17
|
+
readonly body: unknown;
|
|
18
|
+
};
|
|
19
|
+
/** What a caller may pass to {@link ContentHostService.catalog}. */
|
|
20
|
+
export interface ContentCatalogRequest {
|
|
21
|
+
/** The ETag of the copy the caller already has; a 304 means it is still current. */
|
|
22
|
+
readonly etag?: string;
|
|
23
|
+
readonly signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
/** The catalog schema this service understands (`pipeline/build.py` writes 1). */
|
|
26
|
+
export declare const CONTENT_CATALOG_SCHEMA = 1;
|
|
27
|
+
/** What a caller may pass to {@link ContentHostService.file}. */
|
|
28
|
+
export interface ContentFileRequest {
|
|
29
|
+
/** The content hash the catalog names (64 lowercase hex digits). */
|
|
30
|
+
readonly sha256: string;
|
|
31
|
+
/** The file's extension: `.webp` or `webp`, one of {@link CONTENT_BLOB_EXTENSIONS}. */
|
|
32
|
+
readonly extension: string;
|
|
33
|
+
readonly signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
/** Every extension a catalog reference may carry (`docs/handoff/gateway.md` §2). */
|
|
36
|
+
export declare const CONTENT_BLOB_EXTENSIONS: readonly [".zip", ".webp", ".mp3", ".ogg", ".wav"];
|
|
37
|
+
/** The largest file this service returns: the gateway's own per-file limit is 5 MB. */
|
|
38
|
+
export declare const CONTENT_BLOB_MAX_BYTES: number;
|
|
39
|
+
/** Construction options. */
|
|
40
|
+
export interface ContentHostServiceOptions {
|
|
41
|
+
readonly http: GatewayHttp;
|
|
42
|
+
/** The plugin version, for callers that print it. */
|
|
43
|
+
readonly version: string;
|
|
44
|
+
/** The signed-in account, exactly as `vibedevMedia.account()` reports it. */
|
|
45
|
+
readonly account: () => Promise<MediaAccountContext>;
|
|
46
|
+
/**
|
|
47
|
+
* The longest one `catalog()` or `file()` call may take in all, retries and body included (default 90 s). Without
|
|
48
|
+
* one, a busy gateway could hold a caller through three attempts and two waits.
|
|
49
|
+
*/
|
|
50
|
+
readonly deadlineMs?: number;
|
|
51
|
+
}
|
|
52
|
+
/** The creative library, for other plugins (dsh-film reads it as `vibedevContent`). */
|
|
53
|
+
export declare class ContentHostService {
|
|
54
|
+
private readonly options;
|
|
55
|
+
constructor(options: ContentHostServiceOptions);
|
|
56
|
+
get version(): string;
|
|
57
|
+
/** Whether a VibeDev account is signed in, on which gateway, and under which user. */
|
|
58
|
+
account(): Promise<MediaAccountContext>;
|
|
59
|
+
/**
|
|
60
|
+
* The catalog the gateway currently publishes.
|
|
61
|
+
* @param request - the caller's ETag, and a signal that cancels the read.
|
|
62
|
+
* @returns the catalog, or `notModified` when the caller's ETag is still current.
|
|
63
|
+
* @throws {@link ContentError} `NOT_SIGNED_IN` when nobody is signed in, `ABORTED` when the caller cancelled,
|
|
64
|
+
* `NETWORK_ERROR` when the transfer broke or outlasted the deadline.
|
|
65
|
+
*/
|
|
66
|
+
catalog(request?: ContentCatalogRequest): Promise<ContentCatalogOutcome>;
|
|
67
|
+
/**
|
|
68
|
+
* One file the catalog references, by content hash.
|
|
69
|
+
* @param request - the hash, the extension and a signal that cancels the download.
|
|
70
|
+
* @returns the bytes, after checking them against the hash.
|
|
71
|
+
* @throws {@link ContentError} `NOT_FOUND` for a hash the gateway does not have,
|
|
72
|
+
* `HASH_MISMATCH` for bytes that are not the file the catalog named.
|
|
73
|
+
*/
|
|
74
|
+
file(request: ContentFileRequest): Promise<Uint8Array>;
|
|
75
|
+
/**
|
|
76
|
+
* The storage URL a redirect names, read without the gateway credential.
|
|
77
|
+
* @param response - the redirect the gateway answered.
|
|
78
|
+
* @param signal - the caller's signal and this download's deadline, as one.
|
|
79
|
+
* @returns the storage response.
|
|
80
|
+
*/
|
|
81
|
+
private follow;
|
|
82
|
+
/**
|
|
83
|
+
* Whether a hop may go to this address: https anywhere, plain http only from a gateway that is itself plain http
|
|
84
|
+
* (a development or loopback gateway).
|
|
85
|
+
* @param target - the resolved redirect target.
|
|
86
|
+
*/
|
|
87
|
+
private mayFollowTo;
|
|
88
|
+
/**
|
|
89
|
+
* The caller's signal and this operation's own deadline, as one signal.
|
|
90
|
+
* @param callerSignal - the caller's signal, when it passed one.
|
|
91
|
+
*/
|
|
92
|
+
private operationSignal;
|
|
93
|
+
/**
|
|
94
|
+
* One failure from below, in the shape a content caller reads.
|
|
95
|
+
* @param error - whatever was thrown.
|
|
96
|
+
* @param callerSignal - the caller's own signal: our deadline is not a cancellation.
|
|
97
|
+
*/
|
|
98
|
+
private settled;
|
|
99
|
+
}
|
package/lib/gateway/http.d.ts
CHANGED
|
@@ -60,6 +60,17 @@ export interface GatewayRequest {
|
|
|
60
60
|
readonly idempotencyKey?: string;
|
|
61
61
|
/** Send without the credential (pre-signed upload URLs, public content links). */
|
|
62
62
|
readonly anonymous?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Return a `304 Not Modified` response itself instead of failing: a conditional read that found nothing new is an
|
|
65
|
+
* answer, not a refusal.
|
|
66
|
+
*/
|
|
67
|
+
readonly allowNotModified?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Redirect handling for this request. The default `error` refuses one, and `manual` hands the hop back so the caller
|
|
70
|
+
* follows it itself, without the credential. This client never follows a redirect on its own: no gateway call it
|
|
71
|
+
* makes is supposed to redirect, and following one blindly could carry the credential somewhere it does not belong.
|
|
72
|
+
*/
|
|
73
|
+
readonly redirect?: 'error' | 'manual';
|
|
63
74
|
/** Retries after a busy answer (429, or 503 with a busy code or `Retry-After`). Defaults to 2. */
|
|
64
75
|
readonly busyRetries?: number;
|
|
65
76
|
/** Longest single wait for a busy answer; a longer `Retry-After` fails at once. Defaults to 15 s. */
|
|
@@ -102,11 +113,12 @@ export declare class GatewayHttp {
|
|
|
102
113
|
/** Whether a URL is on the gateway origin, and so may carry the credential. */
|
|
103
114
|
isGatewayUrl(url: string): boolean;
|
|
104
115
|
/**
|
|
105
|
-
* Send one request and return the
|
|
116
|
+
* Send one request and return the answer the caller asked to see.
|
|
106
117
|
* @param path - gateway path, or an absolute URL.
|
|
107
118
|
* @param request - method, body, headers and retry policy.
|
|
108
|
-
* @returns the 2xx response,
|
|
109
|
-
*
|
|
119
|
+
* @returns the 2xx response, or — only when the request asks for it — a `304` (`allowNotModified`) or a redirect hop
|
|
120
|
+
* (`redirect: 'manual'`); body unread.
|
|
121
|
+
* @throws {@link MediaError} for every other refusal, with the gateway's code.
|
|
110
122
|
*/
|
|
111
123
|
send(path: string, request?: GatewayRequest): Promise<Response>;
|
|
112
124
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ import Schema from '@deepseek-ai/schemastery';
|
|
|
25
25
|
import { type ClaudeCacheTtl } from './llm/cache-ttl.js';
|
|
26
26
|
export { MediaError } from './gateway/errors.js';
|
|
27
27
|
export { MediaHostService } from './service.js';
|
|
28
|
+
export { ContentHostService } from './content/service.js';
|
|
29
|
+
export { ContentError } from './content/errors.js';
|
|
30
|
+
export type { ContentCatalogOutcome, ContentCatalogRequest, ContentFileRequest, ContentHostServiceOptions } from './content/service.js';
|
|
31
|
+
export type { ContentErrorCode, ContentErrorFacts } from './content/errors.js';
|
|
28
32
|
export type { HostTarget, MediaOutputView, MediaTaskView } from './service.js';
|
|
29
33
|
export type { TaskPhase, TaskQueue, TaskStage, TaskTiming } from './tasks/progress.js';
|
|
30
34
|
export type { AudioForm, AudioFormField, AudioMakeKind, AudioRequest } from './audio/request.js';
|
package/lib/index.js
CHANGED
|
@@ -3318,11 +3318,12 @@ var GatewayHttp = class {
|
|
|
3318
3318
|
}
|
|
3319
3319
|
}
|
|
3320
3320
|
/**
|
|
3321
|
-
* Send one request and return the
|
|
3321
|
+
* Send one request and return the answer the caller asked to see.
|
|
3322
3322
|
* @param path - gateway path, or an absolute URL.
|
|
3323
3323
|
* @param request - method, body, headers and retry policy.
|
|
3324
|
-
* @returns the 2xx response,
|
|
3325
|
-
*
|
|
3324
|
+
* @returns the 2xx response, or — only when the request asks for it — a `304` (`allowNotModified`) or a redirect hop
|
|
3325
|
+
* (`redirect: 'manual'`); body unread.
|
|
3326
|
+
* @throws {@link MediaError} for every other refusal, with the gateway's code.
|
|
3326
3327
|
*/
|
|
3327
3328
|
async send(path, request = {}) {
|
|
3328
3329
|
const url = this.url(path);
|
|
@@ -3351,6 +3352,8 @@ var GatewayHttp = class {
|
|
|
3351
3352
|
} catch {}
|
|
3352
3353
|
return response;
|
|
3353
3354
|
}
|
|
3355
|
+
if (response.status === 304 && request.allowNotModified === true) return response;
|
|
3356
|
+
if (request.redirect === "manual" && response.status >= 300 && response.status < 400) return response;
|
|
3354
3357
|
const failure = gatewayFailureWithHeaders(await response.clone().json().catch(() => void 0), response.headers);
|
|
3355
3358
|
if (imageCreation && imageSubmissionUncertain(failure)) throw uncertainImage(request.idempotencyKey, void 0, response.status, failure);
|
|
3356
3359
|
if (response.status === 401 && isUserAuthenticationFailure(failure) && credential !== void 0 && credential.kind !== "key" && !refreshed) {
|
|
@@ -3431,7 +3434,7 @@ var GatewayHttp = class {
|
|
|
3431
3434
|
method: request.method ?? (body === void 0 ? "GET" : "POST"),
|
|
3432
3435
|
headers,
|
|
3433
3436
|
...body === void 0 ? {} : { body },
|
|
3434
|
-
redirect: "error",
|
|
3437
|
+
redirect: request.redirect ?? "error",
|
|
3435
3438
|
signal
|
|
3436
3439
|
});
|
|
3437
3440
|
} catch (error) {
|
|
@@ -7786,7 +7789,7 @@ function baseName(source) {
|
|
|
7786
7789
|
const name = (source.split(/[?#]/)[0] ?? source).split(/[\\/]/).pop() ?? "";
|
|
7787
7790
|
return name === "" ? "media" : decodeURIComponent(name);
|
|
7788
7791
|
}
|
|
7789
|
-
async function readCapped(response, maxBytes, source) {
|
|
7792
|
+
async function readCapped$1(response, maxBytes, source) {
|
|
7790
7793
|
const declared = Number(response.headers.get("content-length"));
|
|
7791
7794
|
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
7795
|
const reader = response.body?.getReader();
|
|
@@ -7853,7 +7856,7 @@ async function loadMedia(source, reader, maxBytes, signal) {
|
|
|
7853
7856
|
throw new MediaError(`Could not download "${trimmed}" (${error instanceof Error ? error.message : String(error)}).`, "MEDIA_DOWNLOAD_FAILED", {}, { cause: error });
|
|
7854
7857
|
}
|
|
7855
7858
|
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);
|
|
7859
|
+
const data = await readCapped$1(response, maxBytes, trimmed);
|
|
7857
7860
|
const sniffed = sniffMime(data, trimmed);
|
|
7858
7861
|
const header = response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
7859
7862
|
const mime = sniffed !== "application/octet-stream" ? sniffed : header ?? sniffed;
|
|
@@ -9131,6 +9134,414 @@ var GatewaySearchProvider = class {
|
|
|
9131
9134
|
}
|
|
9132
9135
|
};
|
|
9133
9136
|
//#endregion
|
|
9137
|
+
//#region src/content/errors.ts
|
|
9138
|
+
/**
|
|
9139
|
+
* The content library's failures. Callers of `vibedevContent` (dsh-film's
|
|
9140
|
+
* `GatewaySource`) route on three fields of the thrown object — `code`, `status`
|
|
9141
|
+
* and `message`: `code === 'NOT_SIGNED_IN'` or `status === 401` means "signed
|
|
9142
|
+
* out". The gateway client's own `MediaError` keeps `status` inside `details`,
|
|
9143
|
+
* so this layer translates it into a `ContentError` that carries both on top.
|
|
9144
|
+
* @module dsh-vibedev/content/errors
|
|
9145
|
+
*/
|
|
9146
|
+
/**
|
|
9147
|
+
* One content failure, with `code` and `status` at the top level: the host
|
|
9148
|
+
* contract reads them there, never inside a details object.
|
|
9149
|
+
*/
|
|
9150
|
+
var ContentError = class extends HarnessError {
|
|
9151
|
+
status;
|
|
9152
|
+
retryAfterMs;
|
|
9153
|
+
retryable;
|
|
9154
|
+
/**
|
|
9155
|
+
* @param message - what happened and what to do next.
|
|
9156
|
+
* @param code - the stable failure class.
|
|
9157
|
+
* @param facts - status, wait and retry facts.
|
|
9158
|
+
* @param options - the underlying cause, when there is one.
|
|
9159
|
+
*/
|
|
9160
|
+
constructor(message, code, facts = {}, options) {
|
|
9161
|
+
super(message, code, options);
|
|
9162
|
+
this.name = "ContentError";
|
|
9163
|
+
this.status = facts.status;
|
|
9164
|
+
this.retryAfterMs = facts.retryAfterMs;
|
|
9165
|
+
this.retryable = facts.retryable === true;
|
|
9166
|
+
}
|
|
9167
|
+
};
|
|
9168
|
+
const SIGN_IN = "需要登录 VibeDev 才能读取创作库:请在侧栏登录后重试。";
|
|
9169
|
+
/**
|
|
9170
|
+
* One failure from anywhere below this service, in the shape a content caller reads.
|
|
9171
|
+
* @param error - whatever was thrown, including non-errors (`Promise.reject()`).
|
|
9172
|
+
* @returns the failure to throw.
|
|
9173
|
+
*/
|
|
9174
|
+
function contentFailure(error) {
|
|
9175
|
+
if (error instanceof ContentError) return error;
|
|
9176
|
+
const thrown = error ?? {};
|
|
9177
|
+
const code = typeof thrown.code === "string" ? thrown.code : "";
|
|
9178
|
+
const status = typeof thrown.details?.status === "number" ? thrown.details.status : void 0;
|
|
9179
|
+
const retryAfterMs = typeof thrown.details?.retryAfterMs === "number" ? thrown.details.retryAfterMs : void 0;
|
|
9180
|
+
const options = error instanceof Error ? { cause: error } : {};
|
|
9181
|
+
const statusWords = status === void 0 ? "" : `${status}${code === "" || code === `HTTP_${status}` ? "" : `,${code}`}`;
|
|
9182
|
+
if (code === "ABORTED") return new ContentError("创作库请求已取消。", "ABORTED", { retryable: true }, options);
|
|
9183
|
+
if (code === "NOT_SIGNED_IN" || status === 401) return new ContentError(SIGN_IN, "NOT_SIGNED_IN", { status: 401 }, options);
|
|
9184
|
+
if (code === "NOT_FOUND" || status === 404) return new ContentError("创作库里没有这个文件或目录。", "NOT_FOUND", { status: 404 }, options);
|
|
9185
|
+
if (code === "RATE_LIMITED" || status === 429) return new ContentError(`创作库请求太频繁,请稍后重试${retryAfterMs === void 0 || retryAfterMs < 1e3 ? "" : `(约 ${Math.ceil(retryAfterMs / 1e3)} 秒后重试)`}。`, "RATE_LIMITED", {
|
|
9186
|
+
status: 429,
|
|
9187
|
+
...retryAfterMs === void 0 ? {} : { retryAfterMs },
|
|
9188
|
+
retryable: true
|
|
9189
|
+
}, options);
|
|
9190
|
+
if (code === "GATEWAY_UNREACHABLE" || code === "GATEWAY_TIMEOUT") return new ContentError("连不上 VibeDev 网关:请检查网络后重试。", "NETWORK_ERROR", { retryable: true }, options);
|
|
9191
|
+
if (code === "GATEWAY_BAD_RESPONSE") return new ContentError("网关返回的内容无法解析,请稍后重试。", "GATEWAY_BAD_RESPONSE", {
|
|
9192
|
+
...status === void 0 ? {} : { status },
|
|
9193
|
+
retryable: true
|
|
9194
|
+
}, options);
|
|
9195
|
+
if (status !== void 0 && status >= 500) return new ContentError(`创作库暂时取不到(网关 HTTP ${statusWords}),请稍后重试。`, "GATEWAY_ERROR", {
|
|
9196
|
+
status,
|
|
9197
|
+
...retryAfterMs === void 0 ? {} : { retryAfterMs },
|
|
9198
|
+
retryable: true
|
|
9199
|
+
}, options);
|
|
9200
|
+
if (status !== void 0 && status >= 400) return new ContentError(`网关拒绝了创作库请求(HTTP ${statusWords})。`, "REFUSED", {
|
|
9201
|
+
status,
|
|
9202
|
+
retryable: status === 403
|
|
9203
|
+
}, options);
|
|
9204
|
+
return new ContentError("创作库内容暂时取不到,请稍后重试。", "GATEWAY_ERROR", { retryable: true }, options);
|
|
9205
|
+
}
|
|
9206
|
+
/** Every extension a catalog reference may carry (`docs/handoff/gateway.md` §2). */
|
|
9207
|
+
const CONTENT_BLOB_EXTENSIONS = [
|
|
9208
|
+
".zip",
|
|
9209
|
+
".webp",
|
|
9210
|
+
".mp3",
|
|
9211
|
+
".ogg",
|
|
9212
|
+
".wav"
|
|
9213
|
+
];
|
|
9214
|
+
/** The largest file this service returns: the gateway's own per-file limit is 5 MB. */
|
|
9215
|
+
const CONTENT_BLOB_MAX_BYTES = 8388608;
|
|
9216
|
+
/** The sentence a caller reads when the transfer itself broke, worded as `contentFailure` words it. */
|
|
9217
|
+
const NETWORK_MESSAGE = "连不上 VibeDev 网关:请检查网络后重试。";
|
|
9218
|
+
/** The sentence for a read the caller cancelled, worded as `contentFailure` words it. */
|
|
9219
|
+
const CANCELLED_MESSAGE = "创作库请求已取消。";
|
|
9220
|
+
/** How long one catalog read or one download may take in all: retries, busy waits and the body included. */
|
|
9221
|
+
const DEFAULT_DEADLINE_MS = 9e4;
|
|
9222
|
+
/** The statuses whose `Location` this service follows itself; any other 3xx is a refusal (see `follow`). */
|
|
9223
|
+
const REDIRECTS = /* @__PURE__ */ new Set([
|
|
9224
|
+
301,
|
|
9225
|
+
302,
|
|
9226
|
+
303,
|
|
9227
|
+
307,
|
|
9228
|
+
308
|
|
9229
|
+
]);
|
|
9230
|
+
/** The `code` values a broken transfer carries (undici and the socket layer). */
|
|
9231
|
+
const BROKEN_CODE = /^(?:UND_ERR_(?:BODY|CONNECT|HEADERS)_TIMEOUT|UND_ERR_SOCKET|ECONNRESET|EPIPE|ETIMEDOUT)$/;
|
|
9232
|
+
/** The messages a broken transfer carries, for the errors that name no code. */
|
|
9233
|
+
const BROKEN_TEXT = /terminated|aborted|ECONNRESET|EPIPE|socket hang up|other side closed|timed? ?out/i;
|
|
9234
|
+
/** The creative library, for other plugins (dsh-film reads it as `vibedevContent`). */
|
|
9235
|
+
var ContentHostService = class {
|
|
9236
|
+
options;
|
|
9237
|
+
constructor(options) {
|
|
9238
|
+
this.options = options;
|
|
9239
|
+
}
|
|
9240
|
+
get version() {
|
|
9241
|
+
return this.options.version;
|
|
9242
|
+
}
|
|
9243
|
+
/** Whether a VibeDev account is signed in, on which gateway, and under which user. */
|
|
9244
|
+
account() {
|
|
9245
|
+
return this.options.account();
|
|
9246
|
+
}
|
|
9247
|
+
/**
|
|
9248
|
+
* The catalog the gateway currently publishes.
|
|
9249
|
+
* @param request - the caller's ETag, and a signal that cancels the read.
|
|
9250
|
+
* @returns the catalog, or `notModified` when the caller's ETag is still current.
|
|
9251
|
+
* @throws {@link ContentError} `NOT_SIGNED_IN` when nobody is signed in, `ABORTED` when the caller cancelled,
|
|
9252
|
+
* `NETWORK_ERROR` when the transfer broke or outlasted the deadline.
|
|
9253
|
+
*/
|
|
9254
|
+
async catalog(request = {}) {
|
|
9255
|
+
const { etag: asked, signal: callerSignal } = request ?? {};
|
|
9256
|
+
const etag = typeof asked === "string" ? asked.trim() : "";
|
|
9257
|
+
try {
|
|
9258
|
+
const response = await this.options.http.send("/v1/film-library/catalog", {
|
|
9259
|
+
method: "GET",
|
|
9260
|
+
allowNotModified: true,
|
|
9261
|
+
timeoutMs: this.options.deadlineMs ?? DEFAULT_DEADLINE_MS,
|
|
9262
|
+
busyRetries: 2,
|
|
9263
|
+
maxBusyWaitMs: 5e3,
|
|
9264
|
+
signal: this.operationSignal(callerSignal),
|
|
9265
|
+
...etag === "" ? {} : { headers: { "if-none-match": etag } }
|
|
9266
|
+
});
|
|
9267
|
+
if (response.status === 304) return { notModified: true };
|
|
9268
|
+
const body = await response.json().catch((cause) => {
|
|
9269
|
+
throw interruptedFailure(cause, callerSignal) ?? new ContentError("创作库目录不是有效的 JSON。", "GATEWAY_BAD_RESPONSE", {
|
|
9270
|
+
status: response.status,
|
|
9271
|
+
retryable: true
|
|
9272
|
+
}, { cause });
|
|
9273
|
+
});
|
|
9274
|
+
const revision = revisionOf(body);
|
|
9275
|
+
return {
|
|
9276
|
+
notModified: false,
|
|
9277
|
+
etag: canonicalEtag(response.headers.get("etag")) ?? `"${revision}"`,
|
|
9278
|
+
body
|
|
9279
|
+
};
|
|
9280
|
+
} catch (error) {
|
|
9281
|
+
throw this.settled(error, callerSignal);
|
|
9282
|
+
}
|
|
9283
|
+
}
|
|
9284
|
+
/**
|
|
9285
|
+
* One file the catalog references, by content hash.
|
|
9286
|
+
* @param request - the hash, the extension and a signal that cancels the download.
|
|
9287
|
+
* @returns the bytes, after checking them against the hash.
|
|
9288
|
+
* @throws {@link ContentError} `NOT_FOUND` for a hash the gateway does not have,
|
|
9289
|
+
* `HASH_MISMATCH` for bytes that are not the file the catalog named.
|
|
9290
|
+
*/
|
|
9291
|
+
async file(request) {
|
|
9292
|
+
const sha256 = normalizeSha256(request?.sha256);
|
|
9293
|
+
const extension = normalizeExtension(request?.extension);
|
|
9294
|
+
const callerSignal = request?.signal;
|
|
9295
|
+
const signal = this.operationSignal(callerSignal);
|
|
9296
|
+
const path = `/v1/film-library/blobs/${sha256}${extension}`;
|
|
9297
|
+
try {
|
|
9298
|
+
const first = await this.options.http.send(path, {
|
|
9299
|
+
method: "GET",
|
|
9300
|
+
redirect: "manual",
|
|
9301
|
+
headers: { accept: "*/*" },
|
|
9302
|
+
timeoutMs: 6e4,
|
|
9303
|
+
busyRetries: 2,
|
|
9304
|
+
maxBusyWaitMs: 1e4,
|
|
9305
|
+
signal
|
|
9306
|
+
});
|
|
9307
|
+
const data = await readCapped(first.status >= 300 && first.status < 400 ? await this.follow(first, signal) : first, CONTENT_BLOB_MAX_BYTES, callerSignal);
|
|
9308
|
+
if (createHash("sha256").update(data).digest("hex") !== sha256) throw new ContentError("下载的创作库文件校验失败:内容与目录登记的哈希不符。", "HASH_MISMATCH");
|
|
9309
|
+
return data;
|
|
9310
|
+
} catch (error) {
|
|
9311
|
+
throw this.settled(error, callerSignal);
|
|
9312
|
+
}
|
|
9313
|
+
}
|
|
9314
|
+
/**
|
|
9315
|
+
* The storage URL a redirect names, read without the gateway credential.
|
|
9316
|
+
* @param response - the redirect the gateway answered.
|
|
9317
|
+
* @param signal - the caller's signal and this download's deadline, as one.
|
|
9318
|
+
* @returns the storage response.
|
|
9319
|
+
*/
|
|
9320
|
+
async follow(response, signal) {
|
|
9321
|
+
await response.body?.cancel().catch(() => void 0);
|
|
9322
|
+
if (!REDIRECTS.has(response.status)) throw new ContentError("网关的下载答法无法处理。", "GATEWAY_BAD_RESPONSE", {
|
|
9323
|
+
status: response.status,
|
|
9324
|
+
retryable: false
|
|
9325
|
+
});
|
|
9326
|
+
const location = response.headers.get("location")?.trim();
|
|
9327
|
+
if (location === void 0 || location === "") throw new ContentError("网关让下载跳转,但没有给出地址。", "GATEWAY_BAD_RESPONSE", {
|
|
9328
|
+
status: response.status,
|
|
9329
|
+
retryable: false
|
|
9330
|
+
});
|
|
9331
|
+
const target = absoluteLocation(location, this.options.http.origin);
|
|
9332
|
+
if (target === void 0) throw new ContentError("网关给出的下载地址无法识别,已拒绝。", "GATEWAY_BAD_RESPONSE", {
|
|
9333
|
+
status: response.status,
|
|
9334
|
+
retryable: false
|
|
9335
|
+
});
|
|
9336
|
+
if (!this.mayFollowTo(target)) throw new ContentError("网关给出的下载地址不是 https 链接,已拒绝。", "GATEWAY_BAD_RESPONSE", {
|
|
9337
|
+
status: response.status,
|
|
9338
|
+
retryable: false
|
|
9339
|
+
});
|
|
9340
|
+
const hop = await this.options.http.send(target.toString(), {
|
|
9341
|
+
method: "GET",
|
|
9342
|
+
anonymous: true,
|
|
9343
|
+
redirect: "manual",
|
|
9344
|
+
headers: { accept: "*/*" },
|
|
9345
|
+
timeoutMs: 6e4,
|
|
9346
|
+
busyRetries: 0,
|
|
9347
|
+
signal
|
|
9348
|
+
}).catch((cause) => {
|
|
9349
|
+
const status = statusOf(cause);
|
|
9350
|
+
if (status !== void 0 && status >= 400 && status < 500 && status !== 429) throw new ContentError("网关给出的下载地址被拒绝,请稍后重试。", "GATEWAY_BAD_RESPONSE", { retryable: true }, { cause });
|
|
9351
|
+
throw cause;
|
|
9352
|
+
});
|
|
9353
|
+
if (hop.status >= 300 && hop.status < 400) {
|
|
9354
|
+
await hop.body?.cancel().catch(() => void 0);
|
|
9355
|
+
throw new ContentError("下载地址又跳转了一次,已拒绝。", "GATEWAY_BAD_RESPONSE", {
|
|
9356
|
+
status: hop.status,
|
|
9357
|
+
retryable: true
|
|
9358
|
+
});
|
|
9359
|
+
}
|
|
9360
|
+
return hop;
|
|
9361
|
+
}
|
|
9362
|
+
/**
|
|
9363
|
+
* Whether a hop may go to this address: https anywhere, plain http only from a gateway that is itself plain http
|
|
9364
|
+
* (a development or loopback gateway).
|
|
9365
|
+
* @param target - the resolved redirect target.
|
|
9366
|
+
*/
|
|
9367
|
+
mayFollowTo(target) {
|
|
9368
|
+
if (target.protocol === "https:") return true;
|
|
9369
|
+
return target.protocol === "http:" && this.options.http.origin.toLowerCase().startsWith("http:");
|
|
9370
|
+
}
|
|
9371
|
+
/**
|
|
9372
|
+
* The caller's signal and this operation's own deadline, as one signal.
|
|
9373
|
+
* @param callerSignal - the caller's signal, when it passed one.
|
|
9374
|
+
*/
|
|
9375
|
+
operationSignal(callerSignal) {
|
|
9376
|
+
const deadline = AbortSignal.timeout(this.options.deadlineMs ?? DEFAULT_DEADLINE_MS);
|
|
9377
|
+
return callerSignal === void 0 ? deadline : AbortSignal.any([callerSignal, deadline]);
|
|
9378
|
+
}
|
|
9379
|
+
/**
|
|
9380
|
+
* One failure from below, in the shape a content caller reads.
|
|
9381
|
+
* @param error - whatever was thrown.
|
|
9382
|
+
* @param callerSignal - the caller's own signal: our deadline is not a cancellation.
|
|
9383
|
+
*/
|
|
9384
|
+
settled(error, callerSignal) {
|
|
9385
|
+
const failure = contentFailure(error);
|
|
9386
|
+
if (failure.code === "ABORTED" && callerSignal?.aborted !== true) return new ContentError(NETWORK_MESSAGE, "NETWORK_ERROR", { retryable: true }, { cause: error });
|
|
9387
|
+
return failure;
|
|
9388
|
+
}
|
|
9389
|
+
};
|
|
9390
|
+
/**
|
|
9391
|
+
* The failure a body read really ended with, when the answer itself is not the problem.
|
|
9392
|
+
* @param error - what the body read threw.
|
|
9393
|
+
* @param callerSignal - the caller's own signal, if any; its abort makes this a cancellation.
|
|
9394
|
+
* @returns the failure to throw, or undefined when the answer is unreadable (the caller words that).
|
|
9395
|
+
*/
|
|
9396
|
+
function interruptedFailure(error, callerSignal) {
|
|
9397
|
+
if (callerSignal?.aborted === true) return new ContentError(CANCELLED_MESSAGE, "ABORTED", { retryable: true }, { cause: error });
|
|
9398
|
+
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 });
|
|
9399
|
+
}
|
|
9400
|
+
/**
|
|
9401
|
+
* The HTTP status a failure from below names, read from the two error types that can carry one and from their causes:
|
|
9402
|
+
* the gateway client keeps it in `details`, a content failure on top. Nothing else counts — a `status` property on
|
|
9403
|
+
* some other thrown value is not the gateway answering.
|
|
9404
|
+
* @param error - whatever was thrown.
|
|
9405
|
+
* @returns the status, or undefined when no layer of it names one.
|
|
9406
|
+
*/
|
|
9407
|
+
function statusOf(error) {
|
|
9408
|
+
let current = error;
|
|
9409
|
+
for (let depth = 0; depth < 4 && current !== void 0 && current !== null; depth++) {
|
|
9410
|
+
if (current instanceof ContentError) return current.status;
|
|
9411
|
+
if (current instanceof MediaError) return current.details.status;
|
|
9412
|
+
current = current.cause;
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9415
|
+
/**
|
|
9416
|
+
* The name, message and code of an error and of every error it wraps.
|
|
9417
|
+
* @param error - whatever was thrown.
|
|
9418
|
+
* @returns the facts of the chain, outermost first.
|
|
9419
|
+
*/
|
|
9420
|
+
function causeChain(error) {
|
|
9421
|
+
const links = [];
|
|
9422
|
+
let current = error;
|
|
9423
|
+
for (let depth = 0; depth < 4 && current !== void 0 && current !== null; depth++) {
|
|
9424
|
+
const record = typeof current === "object" || typeof current === "function" ? current : {};
|
|
9425
|
+
links.push({
|
|
9426
|
+
name: typeof record.name === "string" ? record.name : "",
|
|
9427
|
+
message: typeof record.message === "string" ? record.message : "",
|
|
9428
|
+
code: typeof record.code === "string" ? record.code : ""
|
|
9429
|
+
});
|
|
9430
|
+
current = record.cause;
|
|
9431
|
+
}
|
|
9432
|
+
return links;
|
|
9433
|
+
}
|
|
9434
|
+
/**
|
|
9435
|
+
* A redirect target, resolved against the gateway origin.
|
|
9436
|
+
* @param location - the `Location` header.
|
|
9437
|
+
* @param origin - the gateway origin, for a relative address.
|
|
9438
|
+
* @returns the URL, or undefined when it cannot be read as one.
|
|
9439
|
+
*/
|
|
9440
|
+
function absoluteLocation(location, origin) {
|
|
9441
|
+
try {
|
|
9442
|
+
return new URL(location, origin);
|
|
9443
|
+
} catch {
|
|
9444
|
+
return;
|
|
9445
|
+
}
|
|
9446
|
+
}
|
|
9447
|
+
/**
|
|
9448
|
+
* A gateway ETag, when it really is one: `If-None-Match` can only carry an entity tag.
|
|
9449
|
+
* @param value - the `ETag` header.
|
|
9450
|
+
* @returns the tag, or undefined when the header is missing or is something else.
|
|
9451
|
+
*/
|
|
9452
|
+
function canonicalEtag(value) {
|
|
9453
|
+
const tag = value?.trim();
|
|
9454
|
+
return tag === void 0 || !/^(?:W\/)?"[^"]*"$/.test(tag) ? void 0 : tag;
|
|
9455
|
+
}
|
|
9456
|
+
/**
|
|
9457
|
+
* The revision of a catalog body, after checking the schema this service understands.
|
|
9458
|
+
* @param body - the parsed JSON.
|
|
9459
|
+
* @returns the revision (`0` for a gateway that has published nothing yet).
|
|
9460
|
+
*/
|
|
9461
|
+
function revisionOf(body) {
|
|
9462
|
+
const record = typeof body === "object" && body !== null && !Array.isArray(body) ? body : void 0;
|
|
9463
|
+
if (record === void 0) throw new ContentError("创作库目录不是 JSON 对象。", "GATEWAY_BAD_RESPONSE", { retryable: true });
|
|
9464
|
+
if (record.schema !== 1) throw new ContentError(`创作库目录的 schema ${typeof record.schema === "number" ? `是 ${String(record.schema)}` : "不是数字"},这个版本只认 1:请更新账号插件。`, "GATEWAY_BAD_RESPONSE", { retryable: true });
|
|
9465
|
+
const revision = record.revision;
|
|
9466
|
+
if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 0) throw new ContentError("创作库目录的 revision 不是非负整数。", "GATEWAY_BAD_RESPONSE", { retryable: true });
|
|
9467
|
+
return revision;
|
|
9468
|
+
}
|
|
9469
|
+
/**
|
|
9470
|
+
* A content hash, as the catalog stores it.
|
|
9471
|
+
* @param value - what the caller passed.
|
|
9472
|
+
* @returns the 64 lowercase hex digits.
|
|
9473
|
+
*/
|
|
9474
|
+
function normalizeSha256(value) {
|
|
9475
|
+
const text = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
9476
|
+
if (!/^[a-f0-9]{64}$/.test(text)) throw new ContentError("创作库文件编号必须是 64 位十六进制 sha256。", "INVALID_REQUEST");
|
|
9477
|
+
return text;
|
|
9478
|
+
}
|
|
9479
|
+
/**
|
|
9480
|
+
* An extension from the reference pool. The caller may pass `.webp` or `webp`; nothing else gets through, which is
|
|
9481
|
+
* also what keeps a caller-supplied path out of the URL.
|
|
9482
|
+
* @param value - what the caller passed.
|
|
9483
|
+
* @returns the extension with its dot.
|
|
9484
|
+
*/
|
|
9485
|
+
function normalizeExtension(value) {
|
|
9486
|
+
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
9487
|
+
const extension = raw === "" ? "" : raw.startsWith(".") ? raw : `.${raw}`;
|
|
9488
|
+
if (!CONTENT_BLOB_EXTENSIONS.includes(extension)) throw new ContentError(`创作库文件的扩展名只能是 ${CONTENT_BLOB_EXTENSIONS.join("、")}。`, "INVALID_REQUEST");
|
|
9489
|
+
return extension;
|
|
9490
|
+
}
|
|
9491
|
+
/**
|
|
9492
|
+
* Read a body no larger than `maxBytes`, checking any declared length first and stopping at the cap while reading:
|
|
9493
|
+
* the bytes never held in memory are the ones over the limit.
|
|
9494
|
+
* @param response - a 2xx response whose body is unread.
|
|
9495
|
+
* @param maxBytes - the largest accepted size.
|
|
9496
|
+
* @param callerSignal - the caller's signal, so a cancelled read is reported as one.
|
|
9497
|
+
* @returns the bytes.
|
|
9498
|
+
*/
|
|
9499
|
+
async function readCapped(response, maxBytes, callerSignal) {
|
|
9500
|
+
const tooLarge = () => new ContentError(`创作库文件超过 ${maxBytes / 1048576} MB 的上限,已拒绝下载。`, "BLOB_TOO_LARGE", {
|
|
9501
|
+
status: response.status,
|
|
9502
|
+
retryable: false
|
|
9503
|
+
});
|
|
9504
|
+
const declaredHeader = response.headers.get("content-length");
|
|
9505
|
+
const declared = declaredHeader === null || declaredHeader.trim() === "" ? void 0 : Number(declaredHeader);
|
|
9506
|
+
if (declared !== void 0 && Number.isFinite(declared) && declared > maxBytes) {
|
|
9507
|
+
await response.body?.cancel().catch(() => void 0);
|
|
9508
|
+
throw tooLarge();
|
|
9509
|
+
}
|
|
9510
|
+
if (response.body === null) throw new ContentError("网关没有返回文件内容。", "GATEWAY_BAD_RESPONSE", {
|
|
9511
|
+
status: response.status,
|
|
9512
|
+
retryable: true
|
|
9513
|
+
});
|
|
9514
|
+
const reader = response.body.getReader();
|
|
9515
|
+
const chunks = [];
|
|
9516
|
+
let total = 0;
|
|
9517
|
+
for (;;) {
|
|
9518
|
+
let chunk;
|
|
9519
|
+
try {
|
|
9520
|
+
const step = await reader.read();
|
|
9521
|
+
chunk = step.done ? void 0 : step.value;
|
|
9522
|
+
} catch (error) {
|
|
9523
|
+
throw interruptedFailure(error, callerSignal) ?? new ContentError("创作库文件没有读完,请重试。", "GATEWAY_BAD_RESPONSE", {
|
|
9524
|
+
status: response.status,
|
|
9525
|
+
retryable: true
|
|
9526
|
+
}, { cause: error });
|
|
9527
|
+
}
|
|
9528
|
+
if (chunk === void 0) break;
|
|
9529
|
+
total += chunk.byteLength;
|
|
9530
|
+
if (total > maxBytes) {
|
|
9531
|
+
await reader.cancel().catch(() => void 0);
|
|
9532
|
+
throw tooLarge();
|
|
9533
|
+
}
|
|
9534
|
+
chunks.push(chunk);
|
|
9535
|
+
}
|
|
9536
|
+
const data = new Uint8Array(total);
|
|
9537
|
+
let offset = 0;
|
|
9538
|
+
for (const chunk of chunks) {
|
|
9539
|
+
data.set(chunk, offset);
|
|
9540
|
+
offset += chunk.byteLength;
|
|
9541
|
+
}
|
|
9542
|
+
return data;
|
|
9543
|
+
}
|
|
9544
|
+
//#endregion
|
|
9134
9545
|
//#region src/util/decimal.ts
|
|
9135
9546
|
const PATTERN = /^(-?)(\d+)(?:\.(\d*))?(?:e([+-]?\d+))?$/i;
|
|
9136
9547
|
/**
|
|
@@ -14480,20 +14891,26 @@ function apply(ctx, config) {
|
|
|
14480
14891
|
mediaTasksTool(runtime),
|
|
14481
14892
|
mediaAccountTool(runtime, chain, login)
|
|
14482
14893
|
]) ctx.tools.register(tool);
|
|
14894
|
+
const accountContext = async () => {
|
|
14895
|
+
const identity = await account?.identity();
|
|
14896
|
+
const snapshot = await account?.view();
|
|
14897
|
+
return {
|
|
14898
|
+
gatewayOrigin: origin,
|
|
14899
|
+
signedIn: identity?.signedIn === true,
|
|
14900
|
+
...identity?.signedIn !== true || identity.userId === void 0 ? {} : { userId: identity.userId },
|
|
14901
|
+
...snapshot === void 0 ? {} : { revision: String(snapshot.revision) }
|
|
14902
|
+
};
|
|
14903
|
+
};
|
|
14483
14904
|
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
|
-
},
|
|
14905
|
+
account: accountContext,
|
|
14494
14906
|
open: (page) => account?.openAccountCenter(page),
|
|
14495
14907
|
refresh: spent
|
|
14496
14908
|
})), "dsh-vibedev: media host service");
|
|
14909
|
+
ctx.effect(() => ctx.provide("vibedevContent", new ContentHostService({
|
|
14910
|
+
http,
|
|
14911
|
+
version,
|
|
14912
|
+
account: accountContext
|
|
14913
|
+
})), "dsh-vibedev: content host service");
|
|
14497
14914
|
const prompt = ctx.get("systemPrompt");
|
|
14498
14915
|
if (prompt !== void 0) prompt.section({
|
|
14499
14916
|
name: "tool:dsh-vibedev",
|
|
@@ -14634,6 +15051,6 @@ function apply(ctx, config) {
|
|
|
14634
15051
|
});
|
|
14635
15052
|
}
|
|
14636
15053
|
//#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 };
|
|
15054
|
+
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
15055
|
|
|
14639
15056
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibedev-si/dsh-vibedev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "VibeDev 账号与模型:在 DeepSeek Harness 里登录 VibeDev,与 DeepSeek 账号并存,使用 VibeDev 网关的模型(Claude、GPT 等),并生成图片、视频、音乐和播客 · VibeDev account and models for DeepSeek Harness: sign in to VibeDev next to the DeepSeek account and use the VibeDev gateway's models (Claude, GPT and more), plus image, video, music and podcast generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|