dsh-openrouter-provider-advisor 0.1.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/LICENSE +21 -0
- package/README.md +163 -0
- package/README_EN.md +116 -0
- package/cordis.patch.yml +4 -0
- package/docs/images/provider-panel.png +0 -0
- package/docs/images/settings-weights.png +0 -0
- package/dsh.plugin.json +16 -0
- package/lib/client.js +1369 -0
- package/lib/index.js +954 -0
- package/lib/types/apply-provider.d.ts +52 -0
- package/lib/types/client/i18n.d.ts +24 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/linked-weights.d.ts +3 -0
- package/lib/types/client/provider-panel-store.d.ts +42 -0
- package/lib/types/client/provider-panel.d.ts +47 -0
- package/lib/types/client/settings-card.d.ts +24 -0
- package/lib/types/client/weight-group.d.ts +22 -0
- package/lib/types/config.d.ts +24 -0
- package/lib/types/controller.d.ts +107 -0
- package/lib/types/directory.d.ts +39 -0
- package/lib/types/host-adapter.d.ts +64 -0
- package/lib/types/host-routes.d.ts +21 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/openrouter.d.ts +34 -0
- package/lib/types/resolve-model.d.ts +23 -0
- package/lib/types/score.d.ts +5 -0
- package/lib/types/tools.d.ts +17 -0
- package/lib/types/types.d.ts +53 -0
- package/package.json +77 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { OpenRouterEndpoint } from './types.js';
|
|
2
|
+
export interface DshModelEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
contextWindow?: number;
|
|
6
|
+
compat?: {
|
|
7
|
+
thinkingFormat?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
reasoningEfforts?: Record<string, string | null> | false;
|
|
11
|
+
openrouterModel?: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface ApplyProviderDependencies {
|
|
15
|
+
upsertPreset(modelId: string, tag: string): Promise<{
|
|
16
|
+
slug: string;
|
|
17
|
+
}>;
|
|
18
|
+
readModels(route: string): Promise<DshModelEntry[]>;
|
|
19
|
+
writeModels(route: string, models: DshModelEntry[]): Promise<void>;
|
|
20
|
+
selectModel(selection: {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
provider: string;
|
|
23
|
+
model: string;
|
|
24
|
+
reasoningEffort?: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
saveDefault(selection: {
|
|
27
|
+
provider: string;
|
|
28
|
+
model: string;
|
|
29
|
+
reasoningEffort?: string;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export interface ApplyProviderInput {
|
|
33
|
+
sessionId: string;
|
|
34
|
+
route: string;
|
|
35
|
+
sourceModel: string;
|
|
36
|
+
openrouterModel: string;
|
|
37
|
+
endpoint: OpenRouterEndpoint;
|
|
38
|
+
reasoningEffort?: string;
|
|
39
|
+
}
|
|
40
|
+
export declare class ProviderApplyError extends Error {
|
|
41
|
+
readonly stage: 'preset' | 'settings' | 'select-model' | 'default';
|
|
42
|
+
readonly partial: boolean;
|
|
43
|
+
constructor(message: string, stage: 'preset' | 'settings' | 'select-model' | 'default', partial: boolean, options?: ErrorOptions);
|
|
44
|
+
}
|
|
45
|
+
export declare function applyProvider(deps: ApplyProviderDependencies, input: ApplyProviderInput): Promise<{
|
|
46
|
+
ok: true;
|
|
47
|
+
provider: string;
|
|
48
|
+
model: string;
|
|
49
|
+
tag: string;
|
|
50
|
+
openrouterModel: string;
|
|
51
|
+
}>;
|
|
52
|
+
//# sourceMappingURL=apply-provider.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type SupportedLocale = 'zh-CN' | 'en-US';
|
|
2
|
+
export type TranslationKey = 'panel.title' | 'panel.currentModelLoading' | 'panel.modelSelect' | 'panel.strategyGroup' | 'panel.refresh' | 'panel.close' | 'panel.loading' | 'panel.titleTrigger' | 'panel.unavailable' | 'panel.group.recommended' | 'panel.group.rest' | 'panel.column.provider' | 'panel.column.details' | 'panel.column.score' | 'panel.current' | 'panel.credentialMissing' | 'panel.switchHint' | 'panel.uptime' | 'panel.uptimeDelayHint' | 'panel.strategy.balanced' | 'panel.strategy.price' | 'panel.strategy.speed' | 'panel.strategy.context' | 'settings.title' | 'settings.summary' | 'settings.action.weights' | 'settings.action.priceBlend' | 'settings.action.reset' | 'settings.action.lock' | 'settings.action.unlock' | 'settings.expand' | 'settings.collapse' | 'settings.row.minContextTokens' | 'settings.row.recommendedCount' | 'settings.row.cacheTtlMs' | 'settings.row.weights.quantization' | 'settings.row.weights.speed' | 'settings.row.weights.price' | 'settings.row.weights.context' | 'settings.row.priceBlend.input' | 'settings.row.priceBlend.output' | 'settings.row.priceBlend.cache' | 'settings.row.uptimePenaltyThreshold' | 'settings.row.uptimePenaltyFactor' | 'settings.group.weights.title' | 'settings.group.weights.scope' | 'settings.group.priceBlend.title' | 'settings.group.priceBlend.scope' | 'settings.group.advanced.title' | 'settings.group.strategies.title' | 'settings.group.strategies.scope' | 'settings.dimension.quantization' | 'settings.dimension.speed' | 'settings.dimension.price' | 'settings.dimension.context' | 'settings.dimension.input' | 'settings.dimension.output' | 'settings.dimension.cache' | 'settings.connection.title' | 'settings.connection.loading' | 'settings.connection.configured' | 'settings.connection.missing' | 'settings.connection.error' | 'settings.connection.guide';
|
|
3
|
+
export declare const zh: Record<TranslationKey, string>;
|
|
4
|
+
export declare const en: Record<TranslationKey, string>;
|
|
5
|
+
export declare const LOCALE_NS = "openrouterProviders";
|
|
6
|
+
export interface LocaleServiceLike {
|
|
7
|
+
getSnapshot(): {
|
|
8
|
+
active: string;
|
|
9
|
+
};
|
|
10
|
+
subscribe(listener: () => void): () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function attachLocale(service: LocaleServiceLike | undefined): void;
|
|
13
|
+
export declare function normalizeLocale(input?: string): SupportedLocale;
|
|
14
|
+
export declare function getLocaleSnapshot(): SupportedLocale;
|
|
15
|
+
export declare function createI18n(locale: string): {
|
|
16
|
+
locale: SupportedLocale;
|
|
17
|
+
t(key: TranslationKey, params?: Record<string, string | number>): string;
|
|
18
|
+
};
|
|
19
|
+
export declare function subscribeLocale(listener: () => void): () => void;
|
|
20
|
+
export declare function useUiI18n(): {
|
|
21
|
+
locale: SupportedLocale;
|
|
22
|
+
t(key: TranslationKey, params?: Record<string, string | number>): string;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function rebalanceWeights<V extends Record<string, number>, K extends keyof V & string>(values: V, changedKey: K, requestedValue: number, lockedKeys: ReadonlySet<string>): V;
|
|
2
|
+
export declare function percent(value: number): string;
|
|
3
|
+
//# sourceMappingURL=linked-weights.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RecommendationResponse } from '../directory.js';
|
|
2
|
+
import type { RankingStrategy } from '../config.js';
|
|
3
|
+
export interface ProviderPanelSnapshot {
|
|
4
|
+
open: boolean;
|
|
5
|
+
status: 'idle' | 'loading' | 'ready' | 'applying' | 'error';
|
|
6
|
+
sessionId: string | null;
|
|
7
|
+
data: RecommendationResponse | null;
|
|
8
|
+
models: ConfiguredProviderModel[];
|
|
9
|
+
selected: {
|
|
10
|
+
provider: string;
|
|
11
|
+
model: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
} | null;
|
|
14
|
+
strategy: RankingStrategy;
|
|
15
|
+
error: string | null;
|
|
16
|
+
credential: {
|
|
17
|
+
configured: boolean;
|
|
18
|
+
ref: string;
|
|
19
|
+
source: 'provider' | 'fallback';
|
|
20
|
+
} | null;
|
|
21
|
+
}
|
|
22
|
+
export interface ConfiguredProviderModel {
|
|
23
|
+
provider: string;
|
|
24
|
+
model: string;
|
|
25
|
+
name: string;
|
|
26
|
+
matchName: string;
|
|
27
|
+
current: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface ProviderPanelStore {
|
|
30
|
+
getSnapshot(): ProviderPanelSnapshot;
|
|
31
|
+
subscribe(listener: () => void): () => void;
|
|
32
|
+
toggle(sessionId: string): Promise<void>;
|
|
33
|
+
open(sessionId: string): Promise<void>;
|
|
34
|
+
close(): void;
|
|
35
|
+
refresh(sessionId: string): Promise<void>;
|
|
36
|
+
selectModel(sessionId: string, provider: string, model: string, name: string): Promise<void>;
|
|
37
|
+
setStrategy(sessionId: string, strategy: RankingStrategy): Promise<void>;
|
|
38
|
+
apply(sessionId: string, tag: string): Promise<void>;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
}
|
|
41
|
+
export declare function createProviderPanelStore(fetchImpl?: typeof fetch): ProviderPanelStore;
|
|
42
|
+
//# sourceMappingURL=provider-panel-store.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { RecommendationResponse } from '../directory.js';
|
|
3
|
+
import type { RankingStrategy } from '../config.js';
|
|
4
|
+
import type { ProviderPanelStore } from './provider-panel-store.js';
|
|
5
|
+
interface SessionListLike {
|
|
6
|
+
current?: string | undefined;
|
|
7
|
+
currentAddress?: unknown | undefined;
|
|
8
|
+
}
|
|
9
|
+
interface GlobalSlotProps {
|
|
10
|
+
useSessions<T>(selector: (state: SessionListLike) => T): T;
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderRowView {
|
|
13
|
+
group: string;
|
|
14
|
+
tag: string;
|
|
15
|
+
providerName: string;
|
|
16
|
+
current: boolean;
|
|
17
|
+
detail: string;
|
|
18
|
+
score: number;
|
|
19
|
+
scoreLabel: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const STRATEGY_OPTIONS: ReadonlyArray<{
|
|
22
|
+
id: RankingStrategy;
|
|
23
|
+
labelKey: 'panel.strategy.balanced' | 'panel.strategy.price' | 'panel.strategy.speed' | 'panel.strategy.context';
|
|
24
|
+
}>;
|
|
25
|
+
export declare function providerRows(data: RecommendationResponse, i18n?: {
|
|
26
|
+
locale: import("./i18n.js").SupportedLocale;
|
|
27
|
+
t(key: import("./i18n.js").TranslationKey, params?: Record<string, string | number>): string;
|
|
28
|
+
}): ProviderRowView[];
|
|
29
|
+
export declare function providerTableColumns(i18n?: {
|
|
30
|
+
locale: import("./i18n.js").SupportedLocale;
|
|
31
|
+
t(key: import("./i18n.js").TranslationKey, params?: Record<string, string | number>): string;
|
|
32
|
+
}): [string, string, string];
|
|
33
|
+
export declare function providerTriggerState(state: SessionListLike): {
|
|
34
|
+
sessionId: string | null;
|
|
35
|
+
disabled: boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare function providerTriggerLayout(wide: boolean): CSSProperties;
|
|
38
|
+
export declare function ProviderSidebarTrigger(props: GlobalSlotProps & {
|
|
39
|
+
wide: boolean;
|
|
40
|
+
store: ProviderPanelStore;
|
|
41
|
+
}): ReactNode;
|
|
42
|
+
export declare const providerGridColumns = "minmax(110px,1fr) minmax(0,2fr) minmax(54px,auto)";
|
|
43
|
+
export declare function ProviderOverlay(props: GlobalSlotProps & {
|
|
44
|
+
store: ProviderPanelStore;
|
|
45
|
+
}): ReactNode;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=provider-panel.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type Config } from '../config.js';
|
|
3
|
+
export interface SettingsScopeLike {
|
|
4
|
+
getSnapshot(): {
|
|
5
|
+
status: string;
|
|
6
|
+
value?: Config;
|
|
7
|
+
writable: boolean;
|
|
8
|
+
};
|
|
9
|
+
subscribe(listener: () => void): () => void;
|
|
10
|
+
set(field: string, value: unknown): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
type ConfigField = keyof Config | `weights.${keyof Config['weights']}` | `priceBlend.${keyof Config['priceBlend']}`;
|
|
13
|
+
export declare function setConfigField(scope: Pick<SettingsScopeLike, 'set'>, config: Config, field: ConfigField, value: number): Promise<void>;
|
|
14
|
+
export declare function setConfigGroup(scope: Pick<SettingsScopeLike, 'set'>, group: 'weights' | 'priceBlend', value: Record<string, number>): Promise<void>;
|
|
15
|
+
export declare function settingsDisclosureLabel(open: boolean, locale?: string): string;
|
|
16
|
+
export declare function strategyWeightRows(locale?: string): Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
values: string;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function OpenRouterProvidersSettingsCard({ scope }: {
|
|
21
|
+
scope: SettingsScopeLike;
|
|
22
|
+
}): ReactNode;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=settings-card.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { TranslationKey } from './i18n.js';
|
|
3
|
+
export interface WeightItem<K extends string> {
|
|
4
|
+
key: K;
|
|
5
|
+
label: string;
|
|
6
|
+
color: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WeightGroupProps<K extends string> {
|
|
9
|
+
title: string;
|
|
10
|
+
scope: string;
|
|
11
|
+
values: Record<K, number>;
|
|
12
|
+
defaults: Record<K, number>;
|
|
13
|
+
items: readonly WeightItem<K>[];
|
|
14
|
+
writable: boolean;
|
|
15
|
+
applyLabel: string;
|
|
16
|
+
resetLabel: string;
|
|
17
|
+
t(key: TranslationKey, params?: Record<string, string | number>): string;
|
|
18
|
+
onChange(values: Record<K, number>): void;
|
|
19
|
+
onApply(): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function WeightGroup<K extends string>(props: WeightGroupProps<K>): ReactNode;
|
|
22
|
+
//# sourceMappingURL=weight-group.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
minContextTokens: number;
|
|
3
|
+
cacheTtlMs: number;
|
|
4
|
+
recommendedCount: number;
|
|
5
|
+
weights: {
|
|
6
|
+
quantization: number;
|
|
7
|
+
speed: number;
|
|
8
|
+
price: number;
|
|
9
|
+
context: number;
|
|
10
|
+
};
|
|
11
|
+
priceBlend: {
|
|
12
|
+
input: number;
|
|
13
|
+
output: number;
|
|
14
|
+
cache: number;
|
|
15
|
+
};
|
|
16
|
+
uptimePenaltyThreshold: number;
|
|
17
|
+
uptimePenaltyFactor: number;
|
|
18
|
+
}
|
|
19
|
+
export type RankingStrategy = 'balanced' | 'price' | 'speed' | 'context';
|
|
20
|
+
export declare const STRATEGY_WEIGHTS: Readonly<Record<Exclude<RankingStrategy, 'balanced'>, Config['weights']>>;
|
|
21
|
+
export declare const DEFAULT_CONFIG: Readonly<Config>;
|
|
22
|
+
export declare function validateConfig(config: Config): void;
|
|
23
|
+
export declare function configForStrategy(config: Config, strategy: RankingStrategy): Config;
|
|
24
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type DshModelEntry } from './apply-provider.js';
|
|
2
|
+
import { type Config, type RankingStrategy } from './config.js';
|
|
3
|
+
import { type RecommendationResponse } from './directory.js';
|
|
4
|
+
import type { OpenRouterEndpoint, OpenRouterModel } from './types.js';
|
|
5
|
+
export interface SessionSelection {
|
|
6
|
+
provider: string;
|
|
7
|
+
model: string;
|
|
8
|
+
reasoningEffort?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ProviderProfile {
|
|
11
|
+
baseURL?: string;
|
|
12
|
+
apiKeyEnv?: string;
|
|
13
|
+
models?: DshModelEntry[];
|
|
14
|
+
}
|
|
15
|
+
export interface ProviderCredential {
|
|
16
|
+
configured: boolean;
|
|
17
|
+
ref: string;
|
|
18
|
+
source: 'provider' | 'fallback';
|
|
19
|
+
value?: string;
|
|
20
|
+
}
|
|
21
|
+
export type ResolvedProviderCredential = ProviderCredential & {
|
|
22
|
+
configured: true;
|
|
23
|
+
value: string;
|
|
24
|
+
};
|
|
25
|
+
export interface ControllerDependencies {
|
|
26
|
+
config(): Config;
|
|
27
|
+
credential(provider: string): Promise<ProviderCredential>;
|
|
28
|
+
sessionSelection(sessionId: string): Promise<SessionSelection>;
|
|
29
|
+
sessionDirectory(sessionId: string): Promise<{
|
|
30
|
+
current: SessionSelection;
|
|
31
|
+
groups: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
models: Array<{
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}>;
|
|
38
|
+
}>;
|
|
39
|
+
}>;
|
|
40
|
+
providerProfile(provider: string): ProviderProfile | undefined;
|
|
41
|
+
providerProfiles(): Record<string, ProviderProfile>;
|
|
42
|
+
listModels(credential: ResolvedProviderCredential): Promise<OpenRouterModel[]>;
|
|
43
|
+
getEndpoints(credential: ResolvedProviderCredential, modelId: string, refresh: boolean): Promise<OpenRouterEndpoint[]>;
|
|
44
|
+
upsertPreset(credential: ResolvedProviderCredential, modelId: string, tag: string): Promise<{
|
|
45
|
+
slug: string;
|
|
46
|
+
}>;
|
|
47
|
+
writeModels(route: string, models: DshModelEntry[]): Promise<void>;
|
|
48
|
+
selectModel(selection: {
|
|
49
|
+
sessionId: string;
|
|
50
|
+
provider: string;
|
|
51
|
+
model: string;
|
|
52
|
+
reasoningEffort?: string;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
saveDefault(selection: {
|
|
55
|
+
provider: string;
|
|
56
|
+
model: string;
|
|
57
|
+
reasoningEffort?: string;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
export declare class OpenRouterProviderController {
|
|
61
|
+
private readonly deps;
|
|
62
|
+
private readonly state;
|
|
63
|
+
constructor(deps: ControllerDependencies);
|
|
64
|
+
private key;
|
|
65
|
+
connection(): Promise<{
|
|
66
|
+
ok: true;
|
|
67
|
+
configured: boolean;
|
|
68
|
+
routes: Array<{
|
|
69
|
+
provider: string;
|
|
70
|
+
credentialRef: string;
|
|
71
|
+
configured: boolean;
|
|
72
|
+
source: 'provider' | 'fallback';
|
|
73
|
+
}>;
|
|
74
|
+
}>;
|
|
75
|
+
models(sessionId: string): Promise<{
|
|
76
|
+
ok: true;
|
|
77
|
+
credential: {
|
|
78
|
+
configured: boolean;
|
|
79
|
+
ref: string;
|
|
80
|
+
source: 'provider' | 'fallback';
|
|
81
|
+
};
|
|
82
|
+
current: {
|
|
83
|
+
provider: string;
|
|
84
|
+
model: string;
|
|
85
|
+
};
|
|
86
|
+
models: Array<{
|
|
87
|
+
provider: string;
|
|
88
|
+
model: string;
|
|
89
|
+
name: string;
|
|
90
|
+
matchName: string;
|
|
91
|
+
current: boolean;
|
|
92
|
+
}>;
|
|
93
|
+
}>;
|
|
94
|
+
recommend(sessionId: string, refresh?: boolean, override?: {
|
|
95
|
+
provider?: string;
|
|
96
|
+
model?: string;
|
|
97
|
+
name?: string;
|
|
98
|
+
strategy?: RankingStrategy;
|
|
99
|
+
}): Promise<RecommendationResponse>;
|
|
100
|
+
apply(sessionId: string, tag: string, override?: {
|
|
101
|
+
provider?: string;
|
|
102
|
+
model?: string;
|
|
103
|
+
name?: string;
|
|
104
|
+
strategy?: RankingStrategy;
|
|
105
|
+
}): Promise<unknown>;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Config } from './config.js';
|
|
2
|
+
import { type ResolveInput } from './resolve-model.js';
|
|
3
|
+
import type { OpenRouterEndpoint, OpenRouterModel, RankedProvider } from './types.js';
|
|
4
|
+
export type DirectoryErrorCode = 'NOT_OPENROUTER' | 'MODEL_NOT_FOUND' | 'MODEL_AMBIGUOUS' | 'NO_ELIGIBLE_ENDPOINTS';
|
|
5
|
+
export declare class ProviderDirectoryError extends Error {
|
|
6
|
+
readonly code: DirectoryErrorCode;
|
|
7
|
+
readonly details?: unknown | undefined;
|
|
8
|
+
constructor(message: string, code: DirectoryErrorCode, details?: unknown | undefined);
|
|
9
|
+
}
|
|
10
|
+
export interface DirectoryInput extends ResolveInput {
|
|
11
|
+
currentTag?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface RecommendationResponse {
|
|
14
|
+
ok: true;
|
|
15
|
+
dsh: {
|
|
16
|
+
provider: string;
|
|
17
|
+
model: string;
|
|
18
|
+
};
|
|
19
|
+
openrouterModel: string;
|
|
20
|
+
currentTag?: string;
|
|
21
|
+
recommended: RankedProvider[];
|
|
22
|
+
rest: RankedProvider[];
|
|
23
|
+
}
|
|
24
|
+
export interface DirectoryDependencies {
|
|
25
|
+
config(): Config;
|
|
26
|
+
listModels(): Promise<OpenRouterModel[]>;
|
|
27
|
+
getEndpoints(modelId: string, options?: {
|
|
28
|
+
refresh?: boolean;
|
|
29
|
+
}): Promise<OpenRouterEndpoint[]>;
|
|
30
|
+
}
|
|
31
|
+
export declare class OpenRouterProviderDirectory {
|
|
32
|
+
private readonly deps;
|
|
33
|
+
constructor(deps: DirectoryDependencies);
|
|
34
|
+
recommend(input: DirectoryInput, options?: {
|
|
35
|
+
refresh?: boolean;
|
|
36
|
+
}): Promise<RecommendationResponse>;
|
|
37
|
+
refresh(input: DirectoryInput): Promise<RecommendationResponse>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=directory.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Config } from './config.js';
|
|
2
|
+
import { OpenRouterProviderController, type SessionSelection } from './controller.js';
|
|
3
|
+
interface RpcResult<T> {
|
|
4
|
+
result: {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: T;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
error: {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface HostContextLike {
|
|
16
|
+
credentials: {
|
|
17
|
+
resolve(ref: unknown): Promise<{
|
|
18
|
+
value: string;
|
|
19
|
+
} | undefined>;
|
|
20
|
+
};
|
|
21
|
+
settings: {
|
|
22
|
+
get(ns: unknown): unknown;
|
|
23
|
+
mutate(ns: unknown, ops: Array<{
|
|
24
|
+
op: 'set';
|
|
25
|
+
path: string[];
|
|
26
|
+
value: unknown;
|
|
27
|
+
}>): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
apiProxy: {
|
|
30
|
+
sessions: {
|
|
31
|
+
models(input: {
|
|
32
|
+
payload: {
|
|
33
|
+
sessionId: string;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<RpcResult<{
|
|
36
|
+
current: SessionSelection;
|
|
37
|
+
groups?: Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
models: Array<{
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
}>;
|
|
44
|
+
}>;
|
|
45
|
+
}>>;
|
|
46
|
+
selectModel(input: {
|
|
47
|
+
payload: {
|
|
48
|
+
sessionId: string;
|
|
49
|
+
provider: string;
|
|
50
|
+
model: string;
|
|
51
|
+
reasoningEffort?: string;
|
|
52
|
+
};
|
|
53
|
+
}): Promise<RpcResult<{
|
|
54
|
+
selected: SessionSelection;
|
|
55
|
+
}>>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
agentDefaultModel: {
|
|
59
|
+
saveSelection(selection: Omit<SessionSelection, never>): Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export declare function createHostController(ctx: HostContextLike, config: () => Config, credentialRef: (name: string) => unknown): OpenRouterProviderController;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=host-adapter.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import type { RankingStrategy } from './config.js';
|
|
3
|
+
import type { RecommendationResponse } from './directory.js';
|
|
4
|
+
export interface ProviderHostController {
|
|
5
|
+
connection(): Promise<unknown>;
|
|
6
|
+
models(sessionId: string): Promise<unknown>;
|
|
7
|
+
recommend(sessionId: string, refresh?: boolean, override?: {
|
|
8
|
+
provider?: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
strategy?: RankingStrategy;
|
|
12
|
+
}): Promise<RecommendationResponse>;
|
|
13
|
+
apply(sessionId: string, tag: string, override?: {
|
|
14
|
+
provider?: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
strategy?: RankingStrategy;
|
|
18
|
+
}): Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
export declare function createProviderRoute(controller: ProviderHostController): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
21
|
+
//# sourceMappingURL=host-routes.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import z from '@deepseek-ai/schemastery';
|
|
3
|
+
import { type Config as ProviderConfig } from './config.js';
|
|
4
|
+
export declare const name = "openrouter-providers";
|
|
5
|
+
export declare const inject: string[];
|
|
6
|
+
export declare const NS: import("@deepseek-ai/dsh-settings").SettingsNamespace;
|
|
7
|
+
export declare const Config: z<ProviderConfig>;
|
|
8
|
+
export declare function apply(ctx: Context, initial?: ProviderConfig): void;
|
|
9
|
+
export { OpenRouterProviderDirectory } from './directory.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { OpenRouterEndpoint, OpenRouterModel } from './types.js';
|
|
2
|
+
export declare class OpenRouterError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly body?: unknown | undefined;
|
|
5
|
+
constructor(message: string, status: number, body?: unknown | undefined);
|
|
6
|
+
}
|
|
7
|
+
export interface OpenRouterClientOptions {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
fetch?: typeof globalThis.fetch;
|
|
10
|
+
cacheTtlMs?: number;
|
|
11
|
+
now?: () => number;
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class OpenRouterClient {
|
|
15
|
+
private readonly options;
|
|
16
|
+
private readonly fetchImpl;
|
|
17
|
+
private readonly cache;
|
|
18
|
+
private modelCatalogCache;
|
|
19
|
+
private readonly ttl;
|
|
20
|
+
private readonly now;
|
|
21
|
+
private readonly baseURL;
|
|
22
|
+
constructor(options: OpenRouterClientOptions);
|
|
23
|
+
private request;
|
|
24
|
+
listModels(): Promise<OpenRouterModel[]>;
|
|
25
|
+
getEndpoints(modelId: string, options?: {
|
|
26
|
+
refresh?: boolean;
|
|
27
|
+
}): Promise<OpenRouterEndpoint[]>;
|
|
28
|
+
clearEndpoints(modelId: string): void;
|
|
29
|
+
upsertPreset(modelId: string, tag: string): Promise<{
|
|
30
|
+
slug: string;
|
|
31
|
+
response: unknown;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=openrouter.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { OpenRouterModel } from './types.js';
|
|
2
|
+
export interface ResolveInput {
|
|
3
|
+
provider: string;
|
|
4
|
+
model: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
presetModel?: string;
|
|
8
|
+
}
|
|
9
|
+
export type ResolveResult = {
|
|
10
|
+
kind: 'matched';
|
|
11
|
+
model: OpenRouterModel;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'ambiguous';
|
|
14
|
+
candidates: OpenRouterModel[];
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'not-found';
|
|
17
|
+
normalized: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'not-openrouter';
|
|
20
|
+
};
|
|
21
|
+
export declare function normalizeModelName(value: string): string;
|
|
22
|
+
export declare function resolveOpenRouterModel(input: ResolveInput, catalog: readonly OpenRouterModel[]): ResolveResult;
|
|
23
|
+
//# sourceMappingURL=resolve-model.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Config } from './config.js';
|
|
2
|
+
import type { OpenRouterEndpoint, RankedProviders } from './types.js';
|
|
3
|
+
export declare function uptimeMultiplier(uptime: number | null, config: Config): number;
|
|
4
|
+
export declare function rankEndpoints(endpoints: readonly OpenRouterEndpoint[], config: Config, currentTag?: string): RankedProviders;
|
|
5
|
+
//# sourceMappingURL=score.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProviderHostController } from './host-routes.js';
|
|
2
|
+
type DefineTool = (definition: Record<string, unknown>) => unknown;
|
|
3
|
+
type PreToolDecision = {
|
|
4
|
+
kind: 'allow';
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'deny';
|
|
7
|
+
reason: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'ask';
|
|
10
|
+
reason?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function providerToolApproval(exec: {
|
|
13
|
+
name: string;
|
|
14
|
+
}, next: () => Promise<PreToolDecision>): Promise<PreToolDecision>;
|
|
15
|
+
export declare function createProviderTools(defineTool: DefineTool, controller: Pick<ProviderHostController, 'recommend' | 'apply'>): unknown[];
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface OpenRouterModel {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export interface OpenRouterEndpoint {
|
|
6
|
+
provider_name: string;
|
|
7
|
+
tag: string;
|
|
8
|
+
quantization?: string | null;
|
|
9
|
+
context_length: number;
|
|
10
|
+
status: number;
|
|
11
|
+
throughput_last_30m?: {
|
|
12
|
+
p50?: number | null;
|
|
13
|
+
} | null;
|
|
14
|
+
latency_last_30m?: {
|
|
15
|
+
p50?: number | null;
|
|
16
|
+
} | null;
|
|
17
|
+
pricing: {
|
|
18
|
+
prompt?: string | number | null;
|
|
19
|
+
completion?: string | number | null;
|
|
20
|
+
input_cache_read?: string | number | null;
|
|
21
|
+
};
|
|
22
|
+
uptime_last_30m?: number | null;
|
|
23
|
+
}
|
|
24
|
+
export interface ProviderScore {
|
|
25
|
+
quantization: number;
|
|
26
|
+
speed: number;
|
|
27
|
+
price: number;
|
|
28
|
+
context: number;
|
|
29
|
+
}
|
|
30
|
+
export interface RankedProvider {
|
|
31
|
+
rank: number;
|
|
32
|
+
score: number;
|
|
33
|
+
providerName: string;
|
|
34
|
+
tag: string;
|
|
35
|
+
quantization: string;
|
|
36
|
+
tps: number;
|
|
37
|
+
latency: number | null;
|
|
38
|
+
price: {
|
|
39
|
+
input: number;
|
|
40
|
+
output: number;
|
|
41
|
+
cache: number;
|
|
42
|
+
};
|
|
43
|
+
contextLength: number;
|
|
44
|
+
uptime: number | null;
|
|
45
|
+
current: boolean;
|
|
46
|
+
reasons: string[];
|
|
47
|
+
dimensions: ProviderScore;
|
|
48
|
+
}
|
|
49
|
+
export interface RankedProviders {
|
|
50
|
+
recommended: RankedProvider[];
|
|
51
|
+
rest: RankedProvider[];
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|