dsh-opendesign-corouter 0.1.19 → 0.2.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 +6 -6
- package/lib/adapter.d.ts +5 -0
- package/lib/auth.d.ts +2 -0
- package/lib/catalog.d.ts +8 -16
- package/lib/client.d.ts +4 -4
- package/lib/client.js +60 -13
- package/lib/config.d.ts +4 -4
- package/lib/device-auth.d.ts +1 -1
- package/lib/generated/typert.host.js +23 -5
- package/lib/generated/typert.remote-client.js +23 -5
- package/lib/index.d.ts +13 -13
- package/lib/index.js +1164 -686
- package/lib/index.js.map +4 -4
- package/lib/model-catalog-snapshot.d.ts +2 -0
- package/lib/model-directory.d.ts +59 -0
- package/lib/model-discovery.d.ts +1 -1
- package/lib/model-entitlements.d.ts +44 -0
- package/lib/model-settings.d.ts +3 -0
- package/lib/protocol-options.d.ts +7 -1
- package/lib/protocols/messages.d.ts +1 -1
- package/lib/protocols/responses-replay.d.ts +6 -0
- package/lib/protocols/responses.d.ts +5 -5
- package/lib/protocols/types.d.ts +4 -0
- package/lib/remote.d.ts +8 -3
- package/package.json +1 -1
|
@@ -12,6 +12,8 @@ export interface ModelCatalogSnapshot {
|
|
|
12
12
|
/** 成功读取时间的 ISO-8601 字符串。 */
|
|
13
13
|
updatedAt: string;
|
|
14
14
|
models: readonly CatalogModel[];
|
|
15
|
+
/** HMAC binding to the effective runtime key, gateway, workspace and member. */
|
|
16
|
+
binding?: string;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Validate a persisted snapshot into a fresh, allowlisted value.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type CatalogModel } from './catalog.js';
|
|
2
|
+
import { fetchModelCatalog } from './model-discovery.js';
|
|
3
|
+
import { readModelScope, readModelEntitlements, type ModelAccount, type ModelEntitlements } from './model-entitlements.js';
|
|
4
|
+
import type { RuntimeConfig } from './config.js';
|
|
5
|
+
import type { ModelCatalogSnapshot } from './model-catalog-snapshot.js';
|
|
6
|
+
export declare const MODEL_DIRECTORY_REFRESH_MS: number;
|
|
7
|
+
interface DirectoryState {
|
|
8
|
+
key?: string;
|
|
9
|
+
account?: ModelAccount;
|
|
10
|
+
}
|
|
11
|
+
export interface DirectoryCallIdentity {
|
|
12
|
+
key: string;
|
|
13
|
+
workspace?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ModelDirectoryOptions {
|
|
16
|
+
config(): RuntimeConfig;
|
|
17
|
+
state(): Promise<DirectoryState>;
|
|
18
|
+
changed(): void;
|
|
19
|
+
persist(snapshot: ModelCatalogSnapshot): Promise<'saved' | 'unsupported' | 'unavailable' | 'failed'>;
|
|
20
|
+
bindingSecret(signal: AbortSignal): Promise<Uint8Array>;
|
|
21
|
+
fetchModels?: typeof fetchModelCatalog;
|
|
22
|
+
readEntitlements?: typeof readModelEntitlements;
|
|
23
|
+
readScope?: typeof readModelScope;
|
|
24
|
+
}
|
|
25
|
+
export declare class ModelDirectory {
|
|
26
|
+
readonly options: ModelDirectoryOptions;
|
|
27
|
+
private readonly lifetime;
|
|
28
|
+
private controller;
|
|
29
|
+
private pending;
|
|
30
|
+
private epoch;
|
|
31
|
+
private lastAttempt;
|
|
32
|
+
private write;
|
|
33
|
+
private writeSerial;
|
|
34
|
+
private _models;
|
|
35
|
+
private _updatedAt;
|
|
36
|
+
private _error;
|
|
37
|
+
private _entitlements;
|
|
38
|
+
private _scope;
|
|
39
|
+
private _runtimeKey;
|
|
40
|
+
private _callBlocked;
|
|
41
|
+
constructor(options: ModelDirectoryOptions);
|
|
42
|
+
private seed;
|
|
43
|
+
models(): readonly CatalogModel[];
|
|
44
|
+
updatedAt(): string | undefined;
|
|
45
|
+
error(): string | undefined;
|
|
46
|
+
entitlements(): ModelEntitlements;
|
|
47
|
+
workspace(): string | undefined;
|
|
48
|
+
callIdentity(): DirectoryCallIdentity | undefined;
|
|
49
|
+
dispose(): void;
|
|
50
|
+
invalidate(): void;
|
|
51
|
+
/** Status/list reads start at most one background refresh per ten minutes. */
|
|
52
|
+
warm(): void;
|
|
53
|
+
refresh(): Promise<void>;
|
|
54
|
+
private binding;
|
|
55
|
+
private read;
|
|
56
|
+
private dropCoverage;
|
|
57
|
+
private queueWrite;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
package/lib/model-discovery.d.ts
CHANGED
|
@@ -36,4 +36,4 @@ export declare class ModelDiscoveryError extends Error {
|
|
|
36
36
|
* @param fetcher Optional `fetch` replacement (tests, hosts with a custom transport).
|
|
37
37
|
* @throws {ModelDiscoveryError} Fixed classification and fixed message for every failure.
|
|
38
38
|
*/
|
|
39
|
-
export declare function fetchModelCatalog(openAiBaseURL: string, key: string, signal?: AbortSignal, fetcher?: typeof fetch): Promise<readonly CatalogModel[]>;
|
|
39
|
+
export declare function fetchModelCatalog(openAiBaseURL: string, key: string, signal?: AbortSignal, fetcher?: typeof fetch, workspaceId?: string): Promise<readonly CatalogModel[]>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Account-bound, advisory Coding Plan coverage. Never borrows a different runtime identity. */
|
|
2
|
+
import type { CatalogModel } from './catalog.js';
|
|
3
|
+
import { type AuthSession, type LoginGrant } from './auth.js';
|
|
4
|
+
export type ModelCoverage = 'included' | 'not-included' | 'unknown';
|
|
5
|
+
export interface ModelAccount {
|
|
6
|
+
session: AuthSession;
|
|
7
|
+
source: 'device' | 'desktop';
|
|
8
|
+
}
|
|
9
|
+
export interface ModelScope {
|
|
10
|
+
workspaceId: string;
|
|
11
|
+
memberId: string;
|
|
12
|
+
/** Non-secret identity scope. Only its keyed binding may be persisted. */
|
|
13
|
+
source: ModelAccount['source'];
|
|
14
|
+
}
|
|
15
|
+
export interface ModelEntitlements {
|
|
16
|
+
state: 'verified' | 'partial' | 'unavailable';
|
|
17
|
+
source?: ModelAccount['source'];
|
|
18
|
+
tier?: string;
|
|
19
|
+
updatedAt?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface EntitlementResult {
|
|
22
|
+
models: readonly CatalogModel[];
|
|
23
|
+
summary: ModelEntitlements;
|
|
24
|
+
scope?: ModelScope;
|
|
25
|
+
}
|
|
26
|
+
export interface EntitlementOptions {
|
|
27
|
+
account?: ModelAccount;
|
|
28
|
+
scope?: ModelScope;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
fetcher?: typeof fetch;
|
|
31
|
+
}
|
|
32
|
+
export declare const ENTITLEMENT_TIMEOUT_MS = 60000;
|
|
33
|
+
/** Exact equality with an issued pair is required, not a matching tier/name/email. */
|
|
34
|
+
export declare function resolveModelAccount(key: string, baseURL: string, grant: LoginGrant | undefined, useDesktop: boolean): Promise<ModelAccount | undefined>;
|
|
35
|
+
/** Current workspace and member are resolved together from the paired control credential. */
|
|
36
|
+
export declare function readModelScope(account: ModelAccount, signal?: AbortSignal, fetcher?: typeof fetch): Promise<ModelScope>;
|
|
37
|
+
/** A missing preflight is unknown; exhausted quota does not change coverage. */
|
|
38
|
+
export declare function parseModelCoverage(value: unknown, scope: ModelScope, modelId: string): {
|
|
39
|
+
coverage: ModelCoverage;
|
|
40
|
+
tier?: string;
|
|
41
|
+
} | undefined;
|
|
42
|
+
export declare function unverifiedModels(models: readonly CatalogModel[]): readonly CatalogModel[];
|
|
43
|
+
/** At most three bounded control-plane reads are active; no inference or quota reservation. */
|
|
44
|
+
export declare function readModelEntitlements(models: readonly CatalogModel[], options?: EntitlementOptions): Promise<EntitlementResult>;
|
package/lib/model-settings.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { CatalogModel } from './catalog.js';
|
|
15
15
|
import { type ContextWindowPresetId } from './context-budget.js';
|
|
16
|
+
import type { ProtocolSelection } from './protocol-options.js';
|
|
16
17
|
/** One model's overrides; absent context uses the default working-window preset. */
|
|
17
18
|
export interface ModelSettings {
|
|
18
19
|
/** 是否出现在模型选择器;缺省视为启用。 */
|
|
@@ -31,6 +32,8 @@ export interface ModelSettings {
|
|
|
31
32
|
contextTier?: ContextWindowPresetId;
|
|
32
33
|
/** 思考深度;只允许目录同一套档位。 */
|
|
33
34
|
reasoningEffort?: string;
|
|
35
|
+
/** Absent/auto follows the global selection and exact model's preferred native format. */
|
|
36
|
+
apiProtocol?: ProtocolSelection;
|
|
34
37
|
}
|
|
35
38
|
/** Model id → settings. Keys are model ids, never provider-scoped. */
|
|
36
39
|
export type ModelSettingsMap = Record<string, ModelSettings>;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export declare const API_PROTOCOL_IDS: readonly ["chat-completions", "responses", "messages"];
|
|
2
2
|
export type ApiProtocol = typeof API_PROTOCOL_IDS[number];
|
|
3
|
+
export declare const API_PROTOCOL_SELECTION_IDS: readonly ["auto", "chat-completions", "responses", "messages"];
|
|
4
|
+
export type ProtocolSelection = typeof API_PROTOCOL_SELECTION_IDS[number];
|
|
5
|
+
/** Resolve a preference; unconfirmed routes use Responses by explicit product policy. */
|
|
6
|
+
export declare function effectiveProtocol(model: {
|
|
7
|
+
nativeProtocol?: ApiProtocol;
|
|
8
|
+
}, selection?: ProtocolSelection, override?: ProtocolSelection): ApiProtocol;
|
|
3
9
|
/** The public gateway origin and an explicit versioned API base are both accepted. */
|
|
4
10
|
export declare function openAiBaseURL(baseURL: string): string;
|
|
5
11
|
/** Shared by request builders and the settings preview so their paths cannot diverge. */
|
|
6
12
|
export declare function inferenceEndpoint(baseURL: string, protocol: ApiProtocol): string;
|
|
7
13
|
export declare const API_PROTOCOL_OPTIONS: readonly {
|
|
8
|
-
id:
|
|
14
|
+
id: ProtocolSelection;
|
|
9
15
|
name: string;
|
|
10
16
|
description: string;
|
|
11
17
|
}[];
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - `reasoningEffort` 按现代 Messages 标准投影为 `thinking: {type:'adaptive'}` +
|
|
11
11
|
* `output_config.effort`;`none` 投影为 `thinking: {type:'disabled'}`;`minimal`/`ultra`
|
|
12
12
|
* 等没有对应 effort 的档位抛 UNSUPPORTED_OPTION;
|
|
13
|
-
* -
|
|
13
|
+
* - 已确认的九个 Claude 模型先校验 Messages 采样默认值与 128000 输出上限;
|
|
14
14
|
* 其余模型的采样限制及 legacy thinking 兼容性由上游按实际模型判定;
|
|
15
15
|
* - 签名与密态仅保存在 adapter-private replay metadata;历史无签名 reasoning 不回放。
|
|
16
16
|
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RequestMessage, StreamChunk, ReplayEnvelope } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import type { ProtocolContext, ProtocolStreamContext } from './types.js';
|
|
3
|
+
/** Only an unmodified assistant message from the same exact route and credential can replay. */
|
|
4
|
+
export declare function responseReplay(message: RequestMessage, ctx: ProtocolContext): readonly Record<string, unknown>[] | undefined;
|
|
5
|
+
/** Opaque encrypted items stay in replayState, never in visible reasoning text. */
|
|
6
|
+
export declare function responseReplayEnvelope(output: unknown, closed: readonly StreamChunk[], context?: ProtocolStreamContext): ReplayEnvelope | undefined;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* OpenAI Responses 协议(无状态:`store: false` + 每次发送完整 `input`)。
|
|
3
3
|
*
|
|
4
4
|
* 为什么坚持无状态:DSH 的请求是会话日志的纯函数,适配器不持久化 `previous_response_id`,
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* 因此重放、重试与并行分支都不依赖服务端会话。带 encrypted_content 的 reasoning 与
|
|
6
|
+
* assistant phase 保存在有界、同凭据/作用域绑定的私有回放元数据;未取得密态的摘要
|
|
7
|
+
* 不伪装成可继续的私有推理,普通可见消息与函数工具仍完整投影。
|
|
8
8
|
*
|
|
9
9
|
* 终止语义(官方 `response.completed` / `response.incomplete` / `response.failed`):
|
|
10
10
|
* - `completed`:有 `function_call` 项 → tool-calls,否则 stop;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - `failed` 或流内 `error` 事件 → 按固定分类抛错,不回显上游正文。
|
|
14
14
|
*/
|
|
15
15
|
import { type StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
16
|
-
import type { Protocol, ProtocolContext, WireRequest } from './types.js';
|
|
16
|
+
import type { Protocol, ProtocolContext, ProtocolStreamContext, WireRequest } from './types.js';
|
|
17
17
|
/**
|
|
18
18
|
* 构造 Responses 请求。
|
|
19
19
|
*
|
|
@@ -28,5 +28,5 @@ export declare function buildResponsesRequest(ctx: ProtocolContext): WireRequest
|
|
|
28
28
|
* 支持交错输出项(文本 / 工具调用 / 推理),按首次出现顺序分配块索引;
|
|
29
29
|
* 只出现在终态 `output` 里的项也会补成块,避免“终态才给内容”的网关被误判为空响应。
|
|
30
30
|
*/
|
|
31
|
-
export declare function streamResponses(body: ReadableStream<Uint8Array>, signal: AbortSignal, idleMs: number): AsyncGenerator<StreamChunk>;
|
|
31
|
+
export declare function streamResponses(body: ReadableStream<Uint8Array>, signal: AbortSignal, idleMs: number, context?: ProtocolStreamContext): AsyncGenerator<StreamChunk>;
|
|
32
32
|
export declare const responses: Protocol;
|
package/lib/protocols/types.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export interface WireRequest {
|
|
|
30
30
|
url: string;
|
|
31
31
|
headers: Record<string, string>;
|
|
32
32
|
body: unknown;
|
|
33
|
+
/** Local-only bounded request-prefix digest, forwarded to stream context, never upstream. */
|
|
34
|
+
replayPrefix?: string;
|
|
33
35
|
}
|
|
34
36
|
/** Prepared request identity; contains no transport credentials. */
|
|
35
37
|
export interface ProtocolStreamContext {
|
|
@@ -37,6 +39,8 @@ export interface ProtocolStreamContext {
|
|
|
37
39
|
model: string;
|
|
38
40
|
baseURL: string;
|
|
39
41
|
credentialIdentity?: string;
|
|
42
|
+
/** Digest from the exact WireRequest that produced this stream. */
|
|
43
|
+
replayPrefix?: string;
|
|
40
44
|
}
|
|
41
45
|
/** 一种线协议的实现。 */
|
|
42
46
|
export interface Protocol {
|
package/lib/remote.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Shared JSON value types and allowlist parsers; no credential or opaque Host state is returned. */
|
|
2
2
|
import type { QuotaSnapshot, SessionSource } from './quota.js';
|
|
3
|
-
import { type ApiProtocol } from './protocol-options.js';
|
|
3
|
+
import { type ApiProtocol, type ProtocolSelection } from './protocol-options.js';
|
|
4
|
+
import type { ModelEntitlements } from './model-entitlements.js';
|
|
4
5
|
import { type ModelSettingsMap } from './model-settings.js';
|
|
5
6
|
import { type TurnMonitorStatus } from './turn-monitor-status.js';
|
|
6
7
|
export type { QuotaSnapshot, QuotaWindow, SessionSource } from './quota.js';
|
|
@@ -17,7 +18,7 @@ export interface StatusConfig {
|
|
|
17
18
|
baseURL: string;
|
|
18
19
|
/** Credential reference name (an env var or a DSH credential ref), never the value; empty when the profile names none. */
|
|
19
20
|
apiKeyEnv: string;
|
|
20
|
-
apiProtocol?:
|
|
21
|
+
apiProtocol?: ProtocolSelection;
|
|
21
22
|
modelSettings?: ModelSettingsMap;
|
|
22
23
|
requestTimeoutMs?: number;
|
|
23
24
|
streamIdleTimeoutMs?: number;
|
|
@@ -39,6 +40,9 @@ export interface StatusModel {
|
|
|
39
40
|
reasoningEfforts?: readonly string[];
|
|
40
41
|
/** Vendor-declared default effort of the catalog entry, always one of `reasoningEfforts`; omission means the vendor declares none. */
|
|
41
42
|
defaultEffort?: string;
|
|
43
|
+
nativeProtocol?: ApiProtocol;
|
|
44
|
+
effectiveProtocol?: ApiProtocol;
|
|
45
|
+
coverage?: 'included' | 'not-included' | 'unknown';
|
|
42
46
|
}
|
|
43
47
|
/** Public website quotes, independent of account entitlements and gateway discovery. */
|
|
44
48
|
export interface PriceTier {
|
|
@@ -78,7 +82,7 @@ export interface Status {
|
|
|
78
82
|
/** Opaque Host revision of the credential record; passed back on every write. */
|
|
79
83
|
revision: string;
|
|
80
84
|
apiKeyConfigured: boolean;
|
|
81
|
-
apiKeySource?: 'reference' | 'stored' | 'device';
|
|
85
|
+
apiKeySource?: 'reference' | 'stored' | 'device' | 'desktop';
|
|
82
86
|
sessionSource?: SessionSource;
|
|
83
87
|
quota: QuotaSnapshot;
|
|
84
88
|
login: LoginState;
|
|
@@ -90,6 +94,7 @@ export interface Status {
|
|
|
90
94
|
modelsSource?: 'builtin' | 'openai';
|
|
91
95
|
modelsUpdatedAt?: string;
|
|
92
96
|
modelsError?: string;
|
|
97
|
+
modelEntitlements?: ModelEntitlements;
|
|
93
98
|
}
|
|
94
99
|
export interface StartLoginRequest {
|
|
95
100
|
expectedRevision: string;
|