dsh-keys-manager 0.0.0 → 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/LICENSE +21 -0
- package/README.md +203 -16
- package/README.zh-CN.md +125 -0
- package/bundle/cordis.patch.yml +5 -0
- package/icon.svg +12 -0
- package/lib/client/format.d.ts +8 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/locales.d.ts +4 -0
- package/lib/client/runtime.d.ts +21 -0
- package/lib/client/store.d.ts +4 -0
- package/lib/client/styles.d.ts +2 -0
- package/lib/client/types.d.ts +130 -0
- package/lib/client/ui.d.ts +18 -0
- package/lib/client.js +2106 -0
- package/lib/core.d.ts +115 -0
- package/lib/core.js +282 -0
- package/lib/core.js.map +1 -0
- package/lib/domain.d.ts +246 -0
- package/lib/domain.js +9 -0
- package/lib/domain.js.map +1 -0
- package/lib/host-types.d.ts +240 -0
- package/lib/host-types.js +2 -0
- package/lib/host-types.js.map +1 -0
- package/lib/index.d.ts +860 -0
- package/lib/index.js +4157 -0
- package/lib/index.js.map +1 -0
- package/lib/providers.d.ts +28 -0
- package/lib/providers.js +1308 -0
- package/lib/providers.js.map +1 -0
- package/lib/store.d.ts +62 -0
- package/lib/store.js +432 -0
- package/lib/store.js.map +1 -0
- package/locale/en.json +25 -0
- package/locale/zh.json +25 -0
- package/package.json +79 -14
- package/scripts/build-client.mjs +53 -0
- package/scripts/prepare-release.mjs +243 -0
- package/scripts/verify-dist.mjs +30 -0
- package/index.js +0 -30
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Host service contracts used by the plugin.
|
|
3
|
+
*
|
|
4
|
+
* These interfaces name only the methods Keys Manager calls. The real
|
|
5
|
+
* implementations are the shipped DSH services; keeping the contract local
|
|
6
|
+
* avoids coupling the plugin to adapter internals while still type-checking
|
|
7
|
+
* every call site.
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
+
import type { KeyRecord, ManagerSettings, ModelRecord } from './domain.js';
|
|
11
|
+
/** One provider route from `llm.listConfigurableProviders()`. */
|
|
12
|
+
export interface DirectoryEntry {
|
|
13
|
+
provider: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
settingsNs: string;
|
|
16
|
+
settingsPath: readonly string[];
|
|
17
|
+
declared?: boolean;
|
|
18
|
+
defaultBaseURL?: string;
|
|
19
|
+
baseURLEnv?: readonly string[];
|
|
20
|
+
nativeAuth?: {
|
|
21
|
+
env: readonly string[];
|
|
22
|
+
oauth: boolean;
|
|
23
|
+
};
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
/** One model an endpoint disclosed during discovery. */
|
|
27
|
+
export interface DiscoveredModel {
|
|
28
|
+
id: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
contextWindow?: number;
|
|
31
|
+
maxTokens?: number;
|
|
32
|
+
inputModalities?: ReadonlyArray<'text' | 'image'>;
|
|
33
|
+
}
|
|
34
|
+
/** Request sent to the adapter's model-discovery operation. */
|
|
35
|
+
export interface DiscoveryRequest {
|
|
36
|
+
provider?: string;
|
|
37
|
+
baseURL?: string;
|
|
38
|
+
api?: string;
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
}
|
|
41
|
+
/** The LLM runtime methods Keys Manager uses. */
|
|
42
|
+
export interface LlmRuntimeLike {
|
|
43
|
+
listConfigurableProviders(): DirectoryEntry[];
|
|
44
|
+
listProviders(): Array<{
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
}>;
|
|
48
|
+
discoverModels(settingsNs: string, request: DiscoveryRequest, signal: AbortSignal): Promise<DiscoveredModel[]>;
|
|
49
|
+
}
|
|
50
|
+
/** Credential value/source facts returned by the credential seam. */
|
|
51
|
+
export interface CredentialHit {
|
|
52
|
+
value: string;
|
|
53
|
+
source: string;
|
|
54
|
+
}
|
|
55
|
+
/** Credential presence facts returned by the credential seam. */
|
|
56
|
+
export interface CredentialDescription {
|
|
57
|
+
configured: boolean;
|
|
58
|
+
source?: string;
|
|
59
|
+
writable: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** One way a flow can obtain its credential, named by the flow that offers it. */
|
|
62
|
+
export interface AuthorizationMethodEntry {
|
|
63
|
+
id: string;
|
|
64
|
+
label: string;
|
|
65
|
+
}
|
|
66
|
+
/** One registered authorization flow (shape of `AuthorizationEntry`). */
|
|
67
|
+
export interface AuthorizationFlowEntry {
|
|
68
|
+
/** The credential record this flow writes, e.g. `llm-pi-ai/anthropic`. */
|
|
69
|
+
key: string;
|
|
70
|
+
label: string;
|
|
71
|
+
methods: readonly AuthorizationMethodEntry[];
|
|
72
|
+
inFlight: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** The interaction surface a begin() caller supplies (shape of `AuthorizationInteraction`). */
|
|
75
|
+
export interface AuthorizationInteractionLike {
|
|
76
|
+
notify(notice: {
|
|
77
|
+
message: string;
|
|
78
|
+
url?: string;
|
|
79
|
+
code?: string;
|
|
80
|
+
}): void;
|
|
81
|
+
prompt(prompt: {
|
|
82
|
+
kind?: 'text' | 'secret' | 'select';
|
|
83
|
+
message: string;
|
|
84
|
+
placeholder?: string;
|
|
85
|
+
options?: ReadonlyArray<{
|
|
86
|
+
id: string;
|
|
87
|
+
label: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
}>;
|
|
90
|
+
signal?: AbortSignal;
|
|
91
|
+
}): Promise<string>;
|
|
92
|
+
}
|
|
93
|
+
/** The outcome of one begin() attempt (shape of `AuthorizationOutcome`). */
|
|
94
|
+
export interface AuthorizationOutcomeLike {
|
|
95
|
+
status: 'authorized' | 'cancelled';
|
|
96
|
+
}
|
|
97
|
+
/** The authorization service methods Keys Manager uses. */
|
|
98
|
+
export interface AuthorizationLike {
|
|
99
|
+
list(): readonly AuthorizationFlowEntry[];
|
|
100
|
+
describe(key: string): AuthorizationFlowEntry | undefined;
|
|
101
|
+
begin(request: {
|
|
102
|
+
key: string;
|
|
103
|
+
method?: string;
|
|
104
|
+
interaction: AuthorizationInteractionLike;
|
|
105
|
+
signal?: AbortSignal;
|
|
106
|
+
}): Promise<AuthorizationOutcomeLike>;
|
|
107
|
+
}
|
|
108
|
+
/** The credential provider methods the broker wraps. */
|
|
109
|
+
export interface CredentialsLike {
|
|
110
|
+
resolve(ref: string): Promise<CredentialHit | undefined>;
|
|
111
|
+
describe(ref: string): Promise<CredentialDescription>;
|
|
112
|
+
set(ref: string, value: string): Promise<void>;
|
|
113
|
+
unset(ref: string): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
/** One stored credential record (shape of `CredentialRecord`). */
|
|
116
|
+
export interface CredentialRecordLike {
|
|
117
|
+
kind: 'api-key' | 'grant';
|
|
118
|
+
key?: string;
|
|
119
|
+
env?: Record<string, string>;
|
|
120
|
+
/** Grant payloads are opaque JSON owned by their writer (pi-ai). */
|
|
121
|
+
payload?: unknown;
|
|
122
|
+
}
|
|
123
|
+
/** The credential record methods Keys Manager uses for OAuth grants. */
|
|
124
|
+
export interface CredentialRecordsLike {
|
|
125
|
+
readRecord(key: string): Promise<CredentialRecordLike | undefined>;
|
|
126
|
+
modifyRecord(key: string, mutate: (current: CredentialRecordLike | undefined) => Promise<CredentialRecordLike | undefined>): Promise<CredentialRecordLike | undefined>;
|
|
127
|
+
deleteRecord(key: string): Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
/** One path-addressed settings edit. */
|
|
130
|
+
export type SettingsPathOp = {
|
|
131
|
+
op: 'set';
|
|
132
|
+
path: readonly string[];
|
|
133
|
+
value: unknown;
|
|
134
|
+
} | {
|
|
135
|
+
op: 'unset';
|
|
136
|
+
path: readonly string[];
|
|
137
|
+
};
|
|
138
|
+
/** One live settings namespace descriptor. */
|
|
139
|
+
export interface SettingsDescriptorLike {
|
|
140
|
+
ns: string;
|
|
141
|
+
value: unknown;
|
|
142
|
+
revision: number;
|
|
143
|
+
}
|
|
144
|
+
/** The settings service methods Keys Manager uses. */
|
|
145
|
+
export interface SettingsLike {
|
|
146
|
+
readonly writable: boolean;
|
|
147
|
+
describe(options?: {
|
|
148
|
+
redactSecrets?: boolean;
|
|
149
|
+
}): SettingsDescriptorLike[];
|
|
150
|
+
mutate(ns: string, ops: readonly SettingsPathOp[], expectedRevision?: number): Promise<void>;
|
|
151
|
+
}
|
|
152
|
+
/** The Typert registry method Keys Manager uses. */
|
|
153
|
+
export interface TypertLike {
|
|
154
|
+
register(contribution: unknown): () => void;
|
|
155
|
+
}
|
|
156
|
+
/** Host context surface this plugin requires. */
|
|
157
|
+
export type HostContext = Context & {
|
|
158
|
+
llm: LlmRuntimeLike;
|
|
159
|
+
credentials: CredentialsLike & Partial<CredentialRecordsLike>;
|
|
160
|
+
settings?: SettingsLike;
|
|
161
|
+
typert: TypertLike;
|
|
162
|
+
authorization?: AuthorizationLike;
|
|
163
|
+
};
|
|
164
|
+
/** Serializable provider failure facts relevant to key health. */
|
|
165
|
+
export interface LlmFailureLike {
|
|
166
|
+
code: string;
|
|
167
|
+
message?: string;
|
|
168
|
+
providerRetryAfterMs?: number;
|
|
169
|
+
}
|
|
170
|
+
/** One stream chunk; only `finish` is inspected by the broker. */
|
|
171
|
+
export interface StreamChunkLike {
|
|
172
|
+
type: string;
|
|
173
|
+
reason?: {
|
|
174
|
+
kind: string;
|
|
175
|
+
failure?: LlmFailureLike;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Minimal `GenerateOptions` surface observed by the stream listener. */
|
|
179
|
+
export interface GenerateOptionsLike {
|
|
180
|
+
provider: string;
|
|
181
|
+
model: string;
|
|
182
|
+
sessionId?: string;
|
|
183
|
+
/** Host-side bypass purposes; any value opts the stream out of retry pins. */
|
|
184
|
+
purpose?: 'compaction' | 'session-title';
|
|
185
|
+
messages: readonly unknown[];
|
|
186
|
+
}
|
|
187
|
+
/** Payload of the `agent/request` waterfall (subset used here). */
|
|
188
|
+
export interface AgentRequestPayload {
|
|
189
|
+
agent?: {
|
|
190
|
+
session?: {
|
|
191
|
+
id?: string;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
turn: number;
|
|
195
|
+
step: number;
|
|
196
|
+
}
|
|
197
|
+
/** Payload of the `agent/request-error` waterfall. */
|
|
198
|
+
export interface RequestErrorPayload {
|
|
199
|
+
agent: {
|
|
200
|
+
session: {
|
|
201
|
+
id: string;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
turn: number;
|
|
205
|
+
step: number;
|
|
206
|
+
provider: string;
|
|
207
|
+
failure: LlmFailureLike;
|
|
208
|
+
retryPolicy?: unknown;
|
|
209
|
+
signal: AbortSignal;
|
|
210
|
+
}
|
|
211
|
+
/** Return value of the request-error waterfall. */
|
|
212
|
+
export type RequestErrorAction = {
|
|
213
|
+
kind: 'retry';
|
|
214
|
+
} | undefined;
|
|
215
|
+
/** Selection result for one request. */
|
|
216
|
+
export interface KeySelection {
|
|
217
|
+
key: KeyRecord | undefined;
|
|
218
|
+
value: string | undefined;
|
|
219
|
+
}
|
|
220
|
+
/** Attempt bookkeeping for retry/failover decisions. */
|
|
221
|
+
export interface AttemptState {
|
|
222
|
+
keyId: string | undefined;
|
|
223
|
+
retries: number;
|
|
224
|
+
failure?: LlmFailureLike;
|
|
225
|
+
at: number;
|
|
226
|
+
turn?: number;
|
|
227
|
+
step?: number;
|
|
228
|
+
/** Whether the request actually resolved a managed key through the broker. */
|
|
229
|
+
usedManagedKey?: boolean;
|
|
230
|
+
/** Monotonic stream-sequence attribution for this step. */
|
|
231
|
+
lastSequence?: number;
|
|
232
|
+
/** Retry budget consumed per selected key. */
|
|
233
|
+
keyRetries?: Record<string, number>;
|
|
234
|
+
}
|
|
235
|
+
/** Provider support verdict used by the UI. */
|
|
236
|
+
export interface ProviderSupport {
|
|
237
|
+
supported: boolean;
|
|
238
|
+
reason?: string;
|
|
239
|
+
}
|
|
240
|
+
export type { ManagerSettings, ModelRecord };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-types.js","sourceRoot":"","sources":["../src/host-types.ts"],"names":[],"mappings":""}
|