@vibedev-si/dsh-vibedev 0.11.6 → 0.13.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 +53 -3
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/client/client.account-center.js +6 -1
- package/client/client.js +101 -3
- package/lib/account/index.d.ts +2 -0
- package/lib/audio/request.d.ts +3 -2
- package/lib/auth/login.d.ts +58 -0
- package/lib/auth/remote-callback.d.ts +34 -0
- package/lib/auth/sign-in-state.d.ts +8 -2
- package/lib/gateway/catalog.d.ts +55 -3
- package/lib/gateway/paid-path.d.ts +1 -1
- package/lib/index.d.ts +9 -0
- package/lib/index.js +1771 -313
- package/lib/llm/adapter.d.ts +3 -0
- package/lib/llm/context.d.ts +2 -0
- package/lib/llm/file-placement.d.ts +31 -0
- package/lib/llm/native-files.d.ts +4 -14
- package/lib/llm/verified-files.d.ts +63 -0
- package/lib/pricing.d.ts +48 -10
- package/lib/runtime.d.ts +14 -3
- package/lib/speech/availability.d.ts +39 -0
- package/lib/speech/gateway.d.ts +69 -0
- package/lib/speech/host.d.ts +131 -0
- package/lib/speech/index.d.ts +37 -0
- package/lib/speech/recognition.d.ts +40 -0
- package/lib/speech/sign-in.d.ts +34 -0
- package/lib/speech/synthesis.d.ts +38 -0
- package/lib/speech/wave.d.ts +33 -0
- package/package.json +11 -1
package/lib/llm/adapter.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ import type { GenerateOptions, ImageAttachmentAccess, LlmModelInfo, LlmProviderI
|
|
|
29
29
|
import type { AttachmentStore, FileAttachmentRef, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
|
|
30
30
|
import type { GatewayModel } from './catalog.js';
|
|
31
31
|
import type { FileRequestTarget } from './native-files.js';
|
|
32
|
+
import { type NativeFileReceipt } from './verified-files.js';
|
|
32
33
|
import { type ActivePromotion } from './promotions.js';
|
|
33
34
|
import { type ClaudeCacheTtl } from './cache-ttl.js';
|
|
34
35
|
/** The credential for one request. */
|
|
@@ -109,6 +110,8 @@ export interface GatewayAdapterOptions {
|
|
|
109
110
|
file: string;
|
|
110
111
|
reason: string;
|
|
111
112
|
}) => void;
|
|
113
|
+
/** Optional, bounded diagnostics for a single request attempt. No filenames, paths or content. */
|
|
114
|
+
readonly onNativeFileReceipt?: (receipt: NativeFileReceipt) => void;
|
|
112
115
|
/** A request reached the gateway and ended, however it ended: it may have been charged. */
|
|
113
116
|
readonly onRequestEnded?: () => void;
|
|
114
117
|
/**
|
package/lib/llm/context.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface PiImageRequestContext {
|
|
|
31
31
|
* Only Chat Completions models supply it.
|
|
32
32
|
*/
|
|
33
33
|
files?: PiFileRequestContext;
|
|
34
|
+
/** Keeps the current request's verified media placeholders in independent pi text parts. */
|
|
35
|
+
isWireMarker?: (text: string) => boolean;
|
|
34
36
|
}
|
|
35
37
|
/** Per-route budgets from which each request image's target is derived. */
|
|
36
38
|
export interface PiImageRequestBudget {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Chat Completions places tool-result media in the SDK's adjacent user message. */
|
|
2
|
+
export declare const TOOL_RESULT_MEDIA_TEXT = "Attached media from tool result:";
|
|
3
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
export interface NativeFilePart {
|
|
5
|
+
type: 'file';
|
|
6
|
+
file: {
|
|
7
|
+
file_data: string;
|
|
8
|
+
filename?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Visit the user and tool text fields in which a generated attachment caption may appear.
|
|
13
|
+
* @param messages - SDK Chat Completions messages.
|
|
14
|
+
* @param visit - replace the visible text; content index -1 identifies a scalar string.
|
|
15
|
+
* @returns messages with only the visited text fields replaced.
|
|
16
|
+
*/
|
|
17
|
+
export declare function mapMediaText(messages: readonly unknown[], visit: (value: string, role: 'user' | 'tool', messageIndex: number, contentIndex: number) => string): unknown[];
|
|
18
|
+
/**
|
|
19
|
+
* Strip every native file from message content, including in an unsupported role.
|
|
20
|
+
* @param messages - SDK messages before placement of verified files.
|
|
21
|
+
* @returns the filtered messages, or undefined if the body already has no files.
|
|
22
|
+
*/
|
|
23
|
+
export declare function stripVisibleNativeFiles(messages: readonly unknown[]): unknown[] | undefined;
|
|
24
|
+
type Part = NativeFilePart | {
|
|
25
|
+
type: 'text';
|
|
26
|
+
text: string;
|
|
27
|
+
};
|
|
28
|
+
type Resolve = (text: string, role: 'user' | 'tool', messageIndex: number) => readonly Part[] | undefined;
|
|
29
|
+
/** Resolve exact user parts or tool-result lines. All other messages, calls and image parts keep their order. */
|
|
30
|
+
export declare function placeNativeFiles(payload: unknown, resolve: Resolve, assistantAfterToolResult?: boolean): unknown;
|
|
31
|
+
export {};
|
|
@@ -40,8 +40,7 @@ export declare const NATIVE_FILE_MAX_REQUEST_BASE64_BYTES: number;
|
|
|
40
40
|
* WMA, …) keeps its handle text only: one type the provider refuses would fail the whole request.
|
|
41
41
|
*/
|
|
42
42
|
export declare const GEMINI_INLINE_MEDIA_TYPES: readonly string[];
|
|
43
|
-
|
|
44
|
-
export declare const TOOL_RESULT_MEDIA_TEXT = "Attached media from tool result:";
|
|
43
|
+
export { TOOL_RESULT_MEDIA_TEXT } from './file-placement.js';
|
|
45
44
|
/** `FileRequestTarget` of `@deepseek-ai/dsh-attachment` (VibeDev fork): the route's limits for one file. */
|
|
46
45
|
export interface FileRequestTarget {
|
|
47
46
|
/** Hard raw-byte limit before base64 expansion; a larger file is refused before any byte is read. */
|
|
@@ -52,6 +51,8 @@ export interface FileRequestTarget {
|
|
|
52
51
|
* Absent means {@link GEMINI_INLINE_MEDIA_TYPES}.
|
|
53
52
|
*/
|
|
54
53
|
mediaTypes?: readonly string[];
|
|
54
|
+
/** The adapter can keep a source-range caption next to each delivered clip. */
|
|
55
|
+
supportsRangeLabels?: boolean;
|
|
55
56
|
}
|
|
56
57
|
/** `RequestFileAttachment` of `@deepseek-ai/dsh-attachment` (VibeDev fork): one file read whole for one request. */
|
|
57
58
|
export interface RequestFileAttachment {
|
|
@@ -117,16 +118,5 @@ export interface NativeFileInjectionOptions {
|
|
|
117
118
|
*/
|
|
118
119
|
readonly assistantAfterToolResult?: boolean;
|
|
119
120
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Put every delivered file part into a Chat Completions payload. A marker part in a user message becomes the file
|
|
122
|
-
* part in place. A Chat Completions `tool` message holds text only, so markers in a run of consecutive `tool`
|
|
123
|
-
* messages leave the tool text (the handle text stays) and their parts, in tool-result then block order, go to the
|
|
124
|
-
* user message right after the run: appended to pi-ai's "Attached image(s) from tool result:" message when pi-ai
|
|
125
|
-
* added one, otherwise in a new `{role:'user',content:[{type:'text',text:'Attached media from tool result:'},…]}`,
|
|
126
|
-
* preceded by pi-ai's bridging assistant message when the model requires one.
|
|
127
|
-
* @param payload - the request body pi-ai built.
|
|
128
|
-
* @param delivered - file parts by marker index.
|
|
129
|
-
* @param options - the model's tool-result ordering rule.
|
|
130
|
-
* @returns a shallow-copied payload, or undefined to keep it when no marker is present.
|
|
131
|
-
*/
|
|
121
|
+
/** Place each marker from a request projected by a legacy host. */
|
|
132
122
|
export declare function injectNativeFiles(payload: unknown, delivered: readonly NativeFilePart[], options?: NativeFileInjectionOptions): unknown;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ContentBlock, GenerateOptions, RequestMessage } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import type { AttachmentStore, FileAttachmentRef } from '@deepseek-ai/dsh-attachment';
|
|
3
|
+
type FileBlock = Extract<ContentBlock, {
|
|
4
|
+
type: 'file';
|
|
5
|
+
}>;
|
|
6
|
+
type TextBlock = Extract<ContentBlock, {
|
|
7
|
+
type: 'text';
|
|
8
|
+
}>;
|
|
9
|
+
interface Occurrence {
|
|
10
|
+
readonly attachmentId: string;
|
|
11
|
+
readonly mediaId: string;
|
|
12
|
+
readonly status: string;
|
|
13
|
+
readonly handle: TextBlock;
|
|
14
|
+
readonly file?: FileBlock;
|
|
15
|
+
readonly label: string;
|
|
16
|
+
readonly rangeLabel?: string;
|
|
17
|
+
readonly referenceText: string;
|
|
18
|
+
}
|
|
19
|
+
type ProjectedRequest = GenerateOptions & {
|
|
20
|
+
readonly nativeFilePolicy?: 'legacy' | 'unique-v1';
|
|
21
|
+
readonly nativeFileOccurrences?: readonly Occurrence[];
|
|
22
|
+
};
|
|
23
|
+
interface Target {
|
|
24
|
+
maxBytes: number;
|
|
25
|
+
mediaTypes?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/** Only request-local ordinal, anonymous media ID and byte count enter debug diagnostics. */
|
|
28
|
+
interface ReceiptFile {
|
|
29
|
+
position: number;
|
|
30
|
+
mediaId: string;
|
|
31
|
+
bytes: number;
|
|
32
|
+
state: 'included' | 'reference-only' | 'shared';
|
|
33
|
+
}
|
|
34
|
+
export interface NativeFileReceipt {
|
|
35
|
+
attemptId: string;
|
|
36
|
+
stage: 'payload' | 'fetch' | 'response';
|
|
37
|
+
fileCount: number;
|
|
38
|
+
files: readonly ReceiptFile[];
|
|
39
|
+
httpStatus?: number;
|
|
40
|
+
}
|
|
41
|
+
export declare function fileReceiptAttempt(observe?: (receipt: NativeFileReceipt) => void): {
|
|
42
|
+
payload: (files: ReceiptFile[]) => void;
|
|
43
|
+
fetching: () => void;
|
|
44
|
+
responded: (status: number) => void;
|
|
45
|
+
} | undefined;
|
|
46
|
+
interface ReadOptions {
|
|
47
|
+
attachments?: AttachmentStore | undefined;
|
|
48
|
+
target: (ref: FileAttachmentRef) => Target | undefined;
|
|
49
|
+
mediaTypes: readonly string[];
|
|
50
|
+
modalities?: readonly string[] | undefined;
|
|
51
|
+
maxBytes: number;
|
|
52
|
+
maxEncoded: number;
|
|
53
|
+
onDegrade?: (mediaId: string, reason: string) => void;
|
|
54
|
+
signal: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
export interface VerifiedFiles {
|
|
57
|
+
messages: RequestMessage[];
|
|
58
|
+
isMarker: (value: string) => boolean;
|
|
59
|
+
inject: (payload: unknown, assistantAfterToolResult?: boolean, written?: (files: ReceiptFile[]) => void) => unknown;
|
|
60
|
+
}
|
|
61
|
+
/** Prepare only the blocks already handed to this adapter. An old host's absent policy keeps its legacy path. */
|
|
62
|
+
export declare function prepareVerifiedFiles(request: ProjectedRequest, options: ReadOptions): Promise<VerifiedFiles | undefined>;
|
|
63
|
+
export {};
|
package/lib/pricing.d.ts
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
* Token price is never shown as an unconditional per-second price, never as
|
|
13
13
|
* 未定价 and never as free — and what cannot be estimated says so.
|
|
14
14
|
*
|
|
15
|
+
* Speech billed per character (`character`) is quoted on the text as it is
|
|
16
|
+
* sent: each Chinese character (a CJK unified ideograph, any extension) counts
|
|
17
|
+
* as the model's `han_character_weight` (2 when undeclared), every other
|
|
18
|
+
* character — letters, digits, spaces, line breaks, punctuation, the `@AudioN`
|
|
19
|
+
* reference markers — as 1. How the gateway counts is final, so such a quote
|
|
20
|
+
* always says the gateway's settlement decides.
|
|
21
|
+
*
|
|
15
22
|
* A model without a price is "not priced" (未定价), never free: only a price the
|
|
16
23
|
* catalog states as zero is shown as ¥0.
|
|
17
24
|
* @module dsh-vibedev/pricing
|
|
@@ -37,15 +44,26 @@ export declare const UNPRICED: Bilingual;
|
|
|
37
44
|
*/
|
|
38
45
|
export declare function yuan(amount: number): string;
|
|
39
46
|
/**
|
|
40
|
-
* The unit after a price: `/s`, `/原始秒`,
|
|
47
|
+
* The unit after a price: `/s`, `/原始秒`, `/次`, `/计费字符(汉字按 2 个算)`.
|
|
41
48
|
* @param unit - the price unit.
|
|
42
49
|
* @param kind - the kind of model, which names a generation (an image, a video, a request).
|
|
50
|
+
* @param hanWeight - per character: what one Chinese character counts as.
|
|
43
51
|
* @returns the suffix in both languages.
|
|
44
52
|
*/
|
|
45
|
-
export declare function unitSuffix(unit: PriceUnit, kind: MediaKind): Bilingual;
|
|
53
|
+
export declare function unitSuffix(unit: PriceUnit, kind: MediaKind, hanWeight?: number): Bilingual;
|
|
54
|
+
/**
|
|
55
|
+
* The billable characters of a text read aloud under per-character billing: each Chinese character (a CJK unified
|
|
56
|
+
* ideograph, any extension included) counts as `hanWeight`, every other character as 1 — letters, digits, spaces,
|
|
57
|
+
* line breaks and punctuation alike. A character is a Unicode code point, so one outside the BMP counts once. The
|
|
58
|
+
* gateway's own count is final (its handling of punctuation and spaces decides).
|
|
59
|
+
* @param text - the text as sent, reference markers included.
|
|
60
|
+
* @param hanWeight - what one Chinese character counts as (`han_character_weight`; 2 when undeclared).
|
|
61
|
+
* @returns the count: `你好,world` is 2 × 2 + 1 + 5 = 10.
|
|
62
|
+
*/
|
|
63
|
+
export declare function billableCharacters(text: string, hanWeight?: number): number;
|
|
46
64
|
/**
|
|
47
|
-
* A one-line price for listings: `¥0.10 per image`, `¥0.99/s (720p)
|
|
48
|
-
* A video Token price lists its rules (`视频 Token 计价:480p 无参考视频 ¥60.06/百万 Token(预计 ¥0.5819/秒)…`).
|
|
65
|
+
* A one-line price for listings: `¥0.10 per image`, `¥0.99/s (720p)`, `¥0.0003/计费字符(汉字按 2 个算)`; `not priced`
|
|
66
|
+
* without a price. A video Token price lists its rules (`视频 Token 计价:480p 无参考视频 ¥60.06/百万 Token(预计 ¥0.5819/秒)…`).
|
|
49
67
|
* @param model - the model.
|
|
50
68
|
* @param lang - the language.
|
|
51
69
|
* @returns the price line.
|
|
@@ -74,23 +92,43 @@ export interface AudioQuote {
|
|
|
74
92
|
readonly unit?: PriceUnit;
|
|
75
93
|
readonly unitPriceCny?: number;
|
|
76
94
|
/**
|
|
77
|
-
* The amount, when it is known before the request runs: per generation,
|
|
78
|
-
*
|
|
79
|
-
* original second is known only once the
|
|
95
|
+
* The amount, when it is known before the request runs: per generation, per
|
|
96
|
+
* minute of an input whose length was measured, or per billable character
|
|
97
|
+
* of a speech text. Speech billed per original second is known only once the
|
|
98
|
+
* provider reports that length.
|
|
80
99
|
*/
|
|
81
100
|
readonly amountCny?: number;
|
|
82
|
-
/**
|
|
101
|
+
/** Per character: what one Chinese character counts as (`han_character_weight`, 2 when undeclared). */
|
|
102
|
+
readonly hanCharacterWeight?: number;
|
|
103
|
+
/** Per character, quoted on a text: its billable characters as counted here (the gateway's count is final). */
|
|
104
|
+
readonly billableCharacters?: number;
|
|
105
|
+
/** The unit price: `¥0.50/次`, `¥0.02/原始秒`, `¥0.30/分钟`, `¥0.0003/计费字符(汉字按 2 个算)`, or `未定价`. */
|
|
83
106
|
readonly label: Bilingual;
|
|
84
107
|
/** How the charge is reached. */
|
|
85
108
|
readonly basis: Bilingual;
|
|
86
109
|
}
|
|
110
|
+
/** What an audio quote takes into account besides the model. */
|
|
111
|
+
export interface AudioQuoteInput {
|
|
112
|
+
/** A transcription: the measured length of the input, in seconds. */
|
|
113
|
+
readonly inputSeconds?: number;
|
|
114
|
+
/** Speech billed per character: the text exactly as it is sent, reference markers included. */
|
|
115
|
+
readonly text?: string;
|
|
116
|
+
}
|
|
87
117
|
/**
|
|
88
118
|
* Quote an audio request: music, podcast and speech generation, or a transcription.
|
|
89
119
|
* @param model - the audio or transcription model.
|
|
90
|
-
* @param
|
|
120
|
+
* @param input - for a transcription, the measured length of the input in seconds (or `{inputSeconds}`); for speech
|
|
121
|
+
* billed per character, `{text}`: the text as it is sent. Without them the quote gives the unit price only.
|
|
91
122
|
* @returns the quote; `priced: false` (未定价) when the catalog gives no usable price.
|
|
92
123
|
*/
|
|
93
|
-
export declare function quoteAudio(model: MediaModel,
|
|
124
|
+
export declare function quoteAudio(model: MediaModel, input?: number | AudioQuoteInput): AudioQuote;
|
|
125
|
+
/**
|
|
126
|
+
* The estimate an audio task records: two decimals (`0.50`); per character, four below ¥0.10 (`0.0036`) so a short
|
|
127
|
+
* text is never recorded as 0.00.
|
|
128
|
+
* @param quote - the quote.
|
|
129
|
+
* @returns the amount in yuan, or undefined without an amount.
|
|
130
|
+
*/
|
|
131
|
+
export declare function audioQuotedCny(quote: AudioQuote): string | undefined;
|
|
94
132
|
/** A video request to quote, before anything is uploaded or submitted. */
|
|
95
133
|
export interface VideoQuoteRequest {
|
|
96
134
|
readonly operationId?: string;
|
package/lib/runtime.d.ts
CHANGED
|
@@ -33,7 +33,10 @@ export declare function servesSlot(model: MediaModel, slot: ModelSlot): boolean;
|
|
|
33
33
|
* @param wanted - the id or alias.
|
|
34
34
|
* @returns the model, or undefined.
|
|
35
35
|
*/
|
|
36
|
-
export declare function modelNamed
|
|
36
|
+
export declare function modelNamed<T extends {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly aliases?: readonly string[];
|
|
39
|
+
}>(models: readonly T[], wanted: string): T | undefined;
|
|
37
40
|
/** Live settings (the plugin's volatile config). */
|
|
38
41
|
export interface MediaSettings {
|
|
39
42
|
/** Output folder, relative to the workspace (or absolute). */
|
|
@@ -96,6 +99,13 @@ export declare class MediaRuntime {
|
|
|
96
99
|
* @returns the models, in catalog order.
|
|
97
100
|
*/
|
|
98
101
|
models(signal?: AbortSignal): Promise<MediaModel[]>;
|
|
102
|
+
/**
|
|
103
|
+
* The catalog as the media tools read it: the media models, and the realtime speech models kept apart from them
|
|
104
|
+
* (only so a request that names one can be told what it is). Cached as {@link models} describes.
|
|
105
|
+
* @param signal - cancels the request.
|
|
106
|
+
* @returns the parsed catalog.
|
|
107
|
+
*/
|
|
108
|
+
private parsedCatalog;
|
|
99
109
|
/** Forget what belonged to the previous account (catalog and uploaded assets), as after a sign-in change. */
|
|
100
110
|
accountChanged(): void;
|
|
101
111
|
/** Forget the cached catalog. */
|
|
@@ -112,11 +122,12 @@ export declare class MediaRuntime {
|
|
|
112
122
|
*/
|
|
113
123
|
pickModel(kind: MediaKind, slot: ModelSlot, requested: string | undefined, accept?: (model: MediaModel) => boolean, signal?: AbortSignal): Promise<MediaModel>;
|
|
114
124
|
/**
|
|
115
|
-
* The model a name refers to, whatever its kind.
|
|
125
|
+
* The media model a name refers to, whatever its kind.
|
|
116
126
|
* @param requested - an id or alias.
|
|
117
127
|
* @param signal - cancels the catalog request.
|
|
118
128
|
* @returns the model.
|
|
119
|
-
* @throws {@link MediaError} when the account has no such model
|
|
129
|
+
* @throws {@link MediaError} `MODEL_NOT_FOUND` when the account has no such media model; for a realtime speech model
|
|
130
|
+
* the message says that is what it is.
|
|
120
131
|
*/
|
|
121
132
|
findModel(requested: string, signal?: AbortSignal): Promise<MediaModel>;
|
|
122
133
|
/**
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the VibeDev speech providers can be used now, from the credential the next gateway request would carry: the
|
|
3
|
+
* app's VibeDev account, the plugin's own sign-in, or a development key. Nothing is sent to the gateway to find out.
|
|
4
|
+
* One source serves as the recognizer's `preparation` and as the synthesizer's `availability`; both registries read
|
|
5
|
+
* the same three states.
|
|
6
|
+
* @module dsh-vibedev/speech/availability
|
|
7
|
+
*/
|
|
8
|
+
import type { CloudReadiness, SpeechPreparation, SynthesisAvailabilitySource } from './host.js';
|
|
9
|
+
/**
|
|
10
|
+
* Published sign-in state. It starts as needing a sign-in; the newest check wins, a check that changes nothing tells
|
|
11
|
+
* nobody, and a stopped source publishes nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CredentialAvailability implements SpeechPreparation, SynthesisAvailabilitySource {
|
|
14
|
+
private readonly signedIn;
|
|
15
|
+
private current;
|
|
16
|
+
private readonly listeners;
|
|
17
|
+
private round;
|
|
18
|
+
private stopped;
|
|
19
|
+
/**
|
|
20
|
+
* @param signedIn - whether a VibeDev credential resolves now; rerun whenever the sign-in may have changed.
|
|
21
|
+
*/
|
|
22
|
+
constructor(signedIn: () => Promise<boolean>);
|
|
23
|
+
/** @returns the latest published state. */
|
|
24
|
+
snapshot(): CloudReadiness;
|
|
25
|
+
/** @param listener - told after the state changed. @returns unsubscribe. */
|
|
26
|
+
subscribe(listener: () => void): () => void;
|
|
27
|
+
/** Check the sign-in again: a cloud provider has nothing to download. */
|
|
28
|
+
prepare(): void;
|
|
29
|
+
/** Nothing runs between checks, so there is nothing to cancel. */
|
|
30
|
+
cancel(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Check the credential and publish the result. A check that fails publishes `failed` with a fixed diagnostic: the
|
|
33
|
+
* error of a credential read may name a stored grant, so its message is not repeated.
|
|
34
|
+
* @returns after this check settles, whether or not a newer one replaced it.
|
|
35
|
+
*/
|
|
36
|
+
refresh(): Promise<void>;
|
|
37
|
+
/** Stop publishing; checks still running settle without telling anyone. */
|
|
38
|
+
stop(): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the speech providers reach the VibeDev gateway: through the plugin's own gateway client, so the credential
|
|
3
|
+
* chain, the refresh after a 401, balance refusals and busy back-off are the ones every other gateway call has. And
|
|
4
|
+
* what a failed call means for the registries.
|
|
5
|
+
* @module dsh-vibedev/speech/gateway
|
|
6
|
+
*/
|
|
7
|
+
import type { GatewayCredential, GatewayHttp, GatewayRequest } from '../gateway/http.js';
|
|
8
|
+
/** What the speech providers need from the plugin. */
|
|
9
|
+
export interface SpeechGateway {
|
|
10
|
+
/** The plugin's gateway client (`GatewayHttp`). */
|
|
11
|
+
readonly http: Pick<GatewayHttp, 'send'>;
|
|
12
|
+
/** The credential the next gateway request carries (the plugin's credential chain); undefined while signed out. */
|
|
13
|
+
readonly resolveCredential: () => Promise<GatewayCredential | undefined>;
|
|
14
|
+
/** Host diagnostics; never given a token, audio or text. */
|
|
15
|
+
readonly log: (message: string) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Busy answers (429, and 503 with `Retry-After`) are tried again once, and only after a wait of at most 2 s: someone
|
|
19
|
+
* is waiting for their words, and the gateway allows each account two requests at a time per channel.
|
|
20
|
+
*/
|
|
21
|
+
export declare const SPEECH_BUSY_RETRIES = 1;
|
|
22
|
+
export declare const SPEECH_MAX_BUSY_WAIT_MS = 2000;
|
|
23
|
+
/** One gateway call, remembering the credential its last attempt carried. */
|
|
24
|
+
export declare class GatewayCall {
|
|
25
|
+
private readonly gateway;
|
|
26
|
+
/** The credential of the last attempt: a rejected development key needs another key, not a sign-in. */
|
|
27
|
+
credential: GatewayCredential | undefined;
|
|
28
|
+
/** @param gateway - the plugin's gateway client and credential chain. */
|
|
29
|
+
constructor(gateway: SpeechGateway);
|
|
30
|
+
/**
|
|
31
|
+
* Send through the plugin's gateway client with the speech busy policy.
|
|
32
|
+
* @param path - the gateway path.
|
|
33
|
+
* @param request - method, body, signal and deadline.
|
|
34
|
+
* @returns the 2xx response, body unread.
|
|
35
|
+
* @throws {@link MediaError} for every refusal, with the gateway's code and status.
|
|
36
|
+
*/
|
|
37
|
+
send(path: string, request: GatewayRequest): Promise<Response>;
|
|
38
|
+
}
|
|
39
|
+
/** What a failed call means, before each registry's own word for input it refuses (`invalid-audio`, `text-rejected`). */
|
|
40
|
+
export type FailureClass = 'sign-in-required' | 'api-key-invalid' | 'rate-limited' | 'quota-exceeded' | 'service-unavailable' | 'rejected-input' | 'timeout' | 'service-error';
|
|
41
|
+
/** A classified failure and its Host diagnostic: status, code and request id only. */
|
|
42
|
+
export interface ClassifiedFailure {
|
|
43
|
+
readonly kind: FailureClass;
|
|
44
|
+
readonly diagnostic: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Classify a failed call.
|
|
48
|
+
* @param error - what the gateway client threw.
|
|
49
|
+
* @param credential - the credential the call carried last.
|
|
50
|
+
* @param inputCodes - the gateway codes that refuse the input itself (`SPEECH_AUDIO_*`, `SPEECH_TEXT_*`).
|
|
51
|
+
* @returns the class and a diagnostic without the gateway's prose, the credential, audio or text.
|
|
52
|
+
*/
|
|
53
|
+
export declare function classifyFailure(error: unknown, credential: GatewayCredential | undefined, inputCodes: RegExp): ClassifiedFailure;
|
|
54
|
+
/**
|
|
55
|
+
* Settle with `work`, or reject with the signal's reason as soon as it aborts. The abort reaches the request through
|
|
56
|
+
* its own signal; this only keeps a body read that undici leaves pending after an abort from holding the caller, and a
|
|
57
|
+
* registry joining the call, past the cancellation.
|
|
58
|
+
* @param signal - cancellation.
|
|
59
|
+
* @param work - the call.
|
|
60
|
+
* @returns the call's own outcome when it settles first.
|
|
61
|
+
*/
|
|
62
|
+
export declare function untilAborted<T>(signal: AbortSignal, work: Promise<T>): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Read a small body completely, or give up past `limit` bytes.
|
|
65
|
+
* @param response - the gateway's answer.
|
|
66
|
+
* @param limit - the most bytes read.
|
|
67
|
+
* @returns the text, or undefined when the body is larger.
|
|
68
|
+
*/
|
|
69
|
+
export declare function boundedText(response: Response, limit: number): Promise<string | undefined>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DSH speech registries the VibeDev providers join, as DSH 0.2.3-alpha.3 defines them: recognition
|
|
3
|
+
* (`ctx.speechToText`, package `@deepseek-ai/dsh-experimental-speech-to-text`) and synthesis (`ctx.textToSpeech`,
|
|
4
|
+
* package `@deepseek-ai/dsh-text-to-speech`).
|
|
5
|
+
*
|
|
6
|
+
* Only the members the providers use are written out, structurally. The plugin builds against older DSH packages:
|
|
7
|
+
* there the synthesis registry does not exist, and the recognition registry has neither the `unavailable` state nor
|
|
8
|
+
* classified failures (`SpeechTranscriptionError`). Each registry sorts a failure by `instanceof` against its own
|
|
9
|
+
* error class, so the class must be the Host's copy: both packages are optional peers the Host alone provides, and
|
|
10
|
+
* they are only ever imported at run time ({@link HOST_SPEECH_MODULES}), never bundled and never imported statically
|
|
11
|
+
* for a value.
|
|
12
|
+
* @module dsh-vibedev/speech/host
|
|
13
|
+
*/
|
|
14
|
+
/** Recognition failure classes (`SpeechFailureCode`) the voice input localizes. */
|
|
15
|
+
export type SpeechFailureCode = 'sign-in-required' | 'api-key-invalid' | 'rate-limited' | 'quota-exceeded' | 'service-unavailable' | 'invalid-audio' | 'timeout' | 'service-error';
|
|
16
|
+
/** Synthesis failure classes (`SynthesisFailureCode`) the read-aloud localizes. */
|
|
17
|
+
export type SynthesisFailureCode = 'sign-in-required' | 'api-key-invalid' | 'rate-limited' | 'quota-exceeded' | 'service-unavailable' | 'text-rejected' | 'timeout' | 'service-error';
|
|
18
|
+
/**
|
|
19
|
+
* Whether a cloud provider takes work now: the states both registries share (`SpeechPreparationState` of recognition,
|
|
20
|
+
* `SynthesisAvailability` of synthesis). `unavailable` until a VibeDev credential exists; `failed` carries a Host
|
|
21
|
+
* diagnostic.
|
|
22
|
+
*/
|
|
23
|
+
export type CloudReadiness = {
|
|
24
|
+
readonly phase: 'ready';
|
|
25
|
+
} | {
|
|
26
|
+
readonly phase: 'unavailable';
|
|
27
|
+
readonly reason: 'sign-in-required';
|
|
28
|
+
} | {
|
|
29
|
+
readonly phase: 'failed';
|
|
30
|
+
readonly message: string;
|
|
31
|
+
};
|
|
32
|
+
/** `SpeechProviderInfo`: public facts of one recognizer. */
|
|
33
|
+
export interface SpeechProviderInfo {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly location: 'host-local' | 'cloud';
|
|
37
|
+
/** Accepted language hints; the registry requires `auto`. */
|
|
38
|
+
readonly languages: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
/** `SpeechPreparation`: a recognizer's readiness, which the registry follows. */
|
|
41
|
+
export interface SpeechPreparation {
|
|
42
|
+
snapshot(): CloudReadiness;
|
|
43
|
+
subscribe(listener: () => void): () => void;
|
|
44
|
+
prepare(): void;
|
|
45
|
+
cancel(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/** `SpeechInput`: one complete recording (16-bit PCM WAV) and its language hint. */
|
|
48
|
+
export interface SpeechInput {
|
|
49
|
+
readonly audio: Uint8Array;
|
|
50
|
+
readonly language: string;
|
|
51
|
+
}
|
|
52
|
+
/** `Transcript`: the final text (empty when nothing was recognized) and the measured durations. */
|
|
53
|
+
export interface Transcript {
|
|
54
|
+
readonly text: string;
|
|
55
|
+
readonly audioSeconds: number;
|
|
56
|
+
readonly inferenceSeconds: number;
|
|
57
|
+
}
|
|
58
|
+
/** `SpeechProvider`: one recognizer. */
|
|
59
|
+
export interface SpeechProvider {
|
|
60
|
+
readonly info: SpeechProviderInfo;
|
|
61
|
+
readonly preparation?: SpeechPreparation;
|
|
62
|
+
transcribe(input: SpeechInput, signal: AbortSignal): Promise<Transcript>;
|
|
63
|
+
}
|
|
64
|
+
/** The member of `ctx.speechToText` the plugin calls. */
|
|
65
|
+
export interface SpeechToTextRegistry {
|
|
66
|
+
/** @returns the disposer that withdraws the provider and joins its work in flight. */
|
|
67
|
+
register(provider: SpeechProvider): () => Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/** `SynthesisAvailabilitySource`: a synthesizer's availability, which the registry follows. */
|
|
70
|
+
export interface SynthesisAvailabilitySource {
|
|
71
|
+
snapshot(): CloudReadiness;
|
|
72
|
+
subscribe(listener: () => void): () => void;
|
|
73
|
+
}
|
|
74
|
+
/** `SynthesisProviderInfo`: public facts of one synthesizer. */
|
|
75
|
+
export interface SynthesisProviderInfo {
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly name: string;
|
|
78
|
+
readonly location: 'host-local' | 'cloud';
|
|
79
|
+
/** Headerless signed 16-bit little-endian mono PCM at this rate. */
|
|
80
|
+
readonly audio: {
|
|
81
|
+
readonly encoding: 'pcm-s16le';
|
|
82
|
+
readonly sampleRate: number;
|
|
83
|
+
};
|
|
84
|
+
/** Longest text, in UTF-16 code units, one synthesis accepts. */
|
|
85
|
+
readonly maxCharacters: number;
|
|
86
|
+
/** Voice ids in menu order; the first is the default. */
|
|
87
|
+
readonly voices: readonly string[];
|
|
88
|
+
}
|
|
89
|
+
/** `SynthesisInput`: the text to speak and one of the provider's voices. */
|
|
90
|
+
export interface SynthesisInput {
|
|
91
|
+
readonly text: string;
|
|
92
|
+
readonly voice: string;
|
|
93
|
+
}
|
|
94
|
+
/** `SynthesisProvider`: one synthesizer. */
|
|
95
|
+
export interface SynthesisProvider {
|
|
96
|
+
readonly info: SynthesisProviderInfo;
|
|
97
|
+
readonly availability?: SynthesisAvailabilitySource;
|
|
98
|
+
synthesize(input: SynthesisInput, signal: AbortSignal): AsyncIterable<Uint8Array>;
|
|
99
|
+
}
|
|
100
|
+
/** The member of `ctx.textToSpeech` the plugin calls. */
|
|
101
|
+
export interface TextToSpeechRegistry {
|
|
102
|
+
/** @returns the disposer that withdraws the provider and joins its calls in flight. */
|
|
103
|
+
register(provider: SynthesisProvider): () => Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A registry's classified failure class: `SpeechTranscriptionError` (recognition) or `SpeechSynthesisError`
|
|
107
|
+
* (synthesis), constructed as `new Class(code, message, { cause })`.
|
|
108
|
+
*/
|
|
109
|
+
export type ClassifiedErrorClass<Code extends string> = new (code: Code, message: string, options?: ErrorOptions) => Error;
|
|
110
|
+
/** Loaders of the Host's speech packages; each rejects where the Host has no such package. */
|
|
111
|
+
export interface HostSpeechModules {
|
|
112
|
+
/** `@deepseek-ai/dsh-experimental-speech-to-text`. */
|
|
113
|
+
readonly speechToText: () => Promise<unknown>;
|
|
114
|
+
/** `@deepseek-ai/dsh-text-to-speech`. */
|
|
115
|
+
readonly textToSpeech: () => Promise<unknown>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The Host's own copies of the speech packages. Each specifier is widened to `string` so TypeScript resolves no
|
|
119
|
+
* package the plugin does not install; the build keeps each one as a literal dynamic import of the package, external
|
|
120
|
+
* like every `@deepseek-ai/*` package, and `scripts/check-package.mjs` finds both among the peers.
|
|
121
|
+
*/
|
|
122
|
+
export declare const HOST_SPEECH_MODULES: HostSpeechModules;
|
|
123
|
+
/**
|
|
124
|
+
* The classified failure class a Host package exports, when it does. DSH 0.2.3-alpha.2 has the recognition package
|
|
125
|
+
* without `SpeechTranscriptionError` and no synthesis package at all; there, and wherever loading fails, the answer is
|
|
126
|
+
* undefined and nothing is registered.
|
|
127
|
+
* @param load - imports the Host package.
|
|
128
|
+
* @param name - the exported class.
|
|
129
|
+
* @returns the class, or undefined.
|
|
130
|
+
*/
|
|
131
|
+
export declare function hostErrorClass<Code extends string>(load: () => Promise<unknown>, name: 'SpeechTranscriptionError' | 'SpeechSynthesisError'): Promise<ClassifiedErrorClass<Code> | undefined>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The VibeDev speech providers in the Host's speech registries: `vibedev-asr` (recognition, `ctx.speechToText`) and
|
|
3
|
+
* `vibedev-tts` (synthesis, `ctx.textToSpeech`), both through the VibeDev gateway and billed to the VibeDev account.
|
|
4
|
+
*
|
|
5
|
+
* Each registers only where the Host's registry classifies failures: the registry service must be present, and its
|
|
6
|
+
* package — imported at run time from the Host, never bundled — must export the error class it sorts failures by
|
|
7
|
+
* (`SpeechTranscriptionError`, `SpeechSynthesisError`; DSH 0.2.3-alpha.3). DSH 0.2.3-alpha.2 has a recognition
|
|
8
|
+
* registry without that class and no synthesis registry: there nothing registers and nothing is reported, and the
|
|
9
|
+
* rest of the plugin runs as usual. Registering sends nothing to the gateway.
|
|
10
|
+
*
|
|
11
|
+
* Both providers say they need a sign-in while no VibeDev credential resolves, and become ready as soon as one does:
|
|
12
|
+
* the plugin's own sign-in, the app's VibeDev account (`deepseekAccount`), or a development key.
|
|
13
|
+
* @module dsh-vibedev/speech
|
|
14
|
+
*/
|
|
15
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
16
|
+
import type { SpeechGateway } from './gateway.js';
|
|
17
|
+
import { type HostSpeechModules } from './host.js';
|
|
18
|
+
export { RECOGNITION_PROVIDER_ID } from './recognition.js';
|
|
19
|
+
export { SYNTHESIS_PROVIDER_ID } from './synthesis.js';
|
|
20
|
+
export { VIBEDEV_SIGN_IN_SERVICE } from './sign-in.js';
|
|
21
|
+
export type { VibeDevSignIn } from './sign-in.js';
|
|
22
|
+
/** What the providers are wired to. */
|
|
23
|
+
export interface SpeechWiring extends SpeechGateway {
|
|
24
|
+
/** Hear about the plugin's own sign-in and sign-out (`PluginLogin.onChange`); returns unsubscribe. */
|
|
25
|
+
readonly onSignInChange: (listener: () => void) => () => void;
|
|
26
|
+
/** The Host's speech packages (test seam). */
|
|
27
|
+
readonly modules?: HostSpeechModules;
|
|
28
|
+
/** Recognition deadline and synthesis idle deadline (test seams). */
|
|
29
|
+
readonly recognitionTimeoutMs?: number;
|
|
30
|
+
readonly synthesisIdleTimeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Register the speech providers wherever the Host's registries can take them, for as long as they are there.
|
|
34
|
+
* @param ctx - the plugin context.
|
|
35
|
+
* @param wiring - the gateway client, the credential chain and the sign-in changes.
|
|
36
|
+
*/
|
|
37
|
+
export declare function installSpeech(ctx: Context, wiring: SpeechWiring): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vibedev-asr`: speech recognition through the VibeDev gateway (`POST /v1/vibedev/speech/asr`), billed to the
|
|
3
|
+
* VibeDev account. One recording goes up as a multipart `file` and the text comes back:
|
|
4
|
+
* `{ text, duration_ms, request_id }`. The gateway takes no language hint, so the provider lists `auto` alone.
|
|
5
|
+
* @module dsh-vibedev/speech/recognition
|
|
6
|
+
*/
|
|
7
|
+
import type { CredentialAvailability } from './availability.js';
|
|
8
|
+
import { type SpeechGateway } from './gateway.js';
|
|
9
|
+
import type { ClassifiedErrorClass, SpeechFailureCode, SpeechProvider } from './host.js';
|
|
10
|
+
/** The provider id the VibeDev desktop's voice input recognizes as VibeDev's. */
|
|
11
|
+
export declare const RECOGNITION_PROVIDER_ID = "vibedev-asr";
|
|
12
|
+
/** The gateway's recognition endpoint. */
|
|
13
|
+
export declare const ASR_PATH = "/v1/vibedev/speech/asr";
|
|
14
|
+
/**
|
|
15
|
+
* Deadline for one recognition, busy retry included: 30 s, as the Host's DeepSeek recognizer allows, and half a second
|
|
16
|
+
* more for each second of audio, since the upload and the recognition grow with it (6.9 s took 2.5 s; 120 s gets 90 s).
|
|
17
|
+
*/
|
|
18
|
+
export declare const RECOGNITION_TIMEOUT_MS = 30000;
|
|
19
|
+
/**
|
|
20
|
+
* The deadline for one recording.
|
|
21
|
+
* @param seconds - its length.
|
|
22
|
+
* @returns milliseconds.
|
|
23
|
+
*/
|
|
24
|
+
export declare function recognitionTimeoutMs(seconds: number): number;
|
|
25
|
+
/** What the recognizer is built from. */
|
|
26
|
+
export interface RecognitionOptions {
|
|
27
|
+
readonly gateway: SpeechGateway;
|
|
28
|
+
/** The Host's `SpeechTranscriptionError`: the registry classifies failures with `instanceof` against it. */
|
|
29
|
+
readonly errorClass: ClassifiedErrorClass<SpeechFailureCode>;
|
|
30
|
+
/** The sign-in state, published as the recognizer's preparation and checked again after a refused sign-in. */
|
|
31
|
+
readonly availability: CredentialAvailability;
|
|
32
|
+
/** Deadline for one recognition, whatever its length (test seam). */
|
|
33
|
+
readonly timeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build the recognizer.
|
|
37
|
+
* @param options - the gateway, the Host's error class and the sign-in state.
|
|
38
|
+
* @returns the provider to register with `ctx.speechToText`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createRecognition(options: RecognitionOptions): SpeechProvider;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client service that opens the VibeDev sign-in for another plugin: `vibedevSignIn`. Pure declarations only, so
|
|
3
|
+
* the browser half bundles this module as it is and the Host half publishes the same contract in its types.
|
|
4
|
+
*
|
|
5
|
+
* Contract (dsh-vibedev 0.12.0). The VibeDev desktop's voice input and read-aloud offer "登录 VibeDev" while their
|
|
6
|
+
* provider is a VibeDev one (`vibedev-asr`, `vibedev-tts`; any `vibedev-*` id) and it reports
|
|
7
|
+
* `{ phase: 'unavailable', reason: 'sign-in-required' }` or fails with `sign-in-required`; that action calls
|
|
8
|
+
* `open()`. The service is provided in a client's root scope while that client can read the VibeDev account (the
|
|
9
|
+
* Host answered its account read, as it does for the owner's desktop window or web page; a peer the plugin's routes
|
|
10
|
+
* refuse never gets it), and is withdrawn when the plugin's client unloads. Consumers follow it with
|
|
11
|
+
* `ctx.inject(['vibedevSignIn'], …)` and offer the action only while it is present; they declare the context member
|
|
12
|
+
* themselves, for example:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { VibeDevSignIn } from '@vibedev-si/dsh-vibedev'
|
|
16
|
+
* declare module '@deepseek-ai/cordis' {
|
|
17
|
+
* interface Context { vibedevSignIn: VibeDevSignIn }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
* @module dsh-vibedev/speech/sign-in
|
|
21
|
+
*/
|
|
22
|
+
/** The service name: `ctx.get('vibedevSignIn')`. Kept as it is: the VibeDev desktop looks it up by this name. */
|
|
23
|
+
export declare const VIBEDEV_SIGN_IN_SERVICE = "vibedevSignIn";
|
|
24
|
+
/** `vibedevSignIn`: open the VibeDev sign-in. */
|
|
25
|
+
export interface VibeDevSignIn {
|
|
26
|
+
/**
|
|
27
|
+
* Start the same sign-in as the 登录 button in Settings → VibeDev 账号: the Host opens the VibeDev sign-in page in
|
|
28
|
+
* the system browser (where it cannot, this page opens the link), and the account section and the sidebar show the
|
|
29
|
+
* sign-in until it completes. Call it synchronously from the user's click, so a page that has to open the link
|
|
30
|
+
* itself may. Returns at once and never throws: a failure shows in the account section, and the providers become
|
|
31
|
+
* ready when the sign-in completes.
|
|
32
|
+
*/
|
|
33
|
+
open(): void;
|
|
34
|
+
}
|