@sagmans/dsh-provider-extra 0.8.1 → 0.9.2
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 +272 -91
- package/cordis.patch.yml +3 -0
- package/dist/auth-remote.js +333 -0
- package/dist/catalog-default.js +5 -5
- package/dist/catalog-routes.js +241 -96
- package/dist/catalog-runtime.js +132 -80
- package/dist/catalog.js +50 -26
- package/dist/client.js +887 -90
- package/dist/codex-login.js +21 -12
- package/dist/codex.js +34 -19
- package/dist/extra-models.js +19 -9
- package/dist/headless-startup.js +36 -21
- package/dist/index.js +73 -42
- package/dist/login-attempt.js +25 -19
- package/dist/login-choice.js +24 -14
- package/dist/login-cli.js +7 -5
- package/dist/login-command.js +33 -11
- package/dist/login-host.js +99 -41
- package/dist/login-route.js +9 -3
- package/dist/login-status.js +10 -4
- package/dist/opencode-go.js +37 -18
- package/dist/plugin-error.js +12 -0
- package/dist/service-tiers.js +40 -18
- package/dist/sign-in.js +20 -0
- package/dist/tier-client.js +886 -89
- package/dist/tier-invocation.js +51 -20
- package/dist/tier-remote.js +7 -4
- package/dist/tier-store.js +25 -11
- package/dist/tui-actions.js +29 -12
- package/docs/catalog-v1.example.json +1 -3
- package/docs/catalog.md +1 -2
- package/package.json +42 -32
package/dist/catalog-runtime.js
CHANGED
|
@@ -1,20 +1,96 @@
|
|
|
1
|
+
import { assertUsableApiKey, LlmError, resolveImageAttachmentAccess } from '@deepseek-ai/dsh-llm';
|
|
1
2
|
import { PiAiAdapter } from '@deepseek-ai/dsh-llm-pi-ai';
|
|
2
|
-
import {
|
|
3
|
-
import { codexAuth } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { mountServiceTiers, withServiceTiers } from
|
|
3
|
+
import { catalogDefault } from './catalog-default.js';
|
|
4
|
+
import { codexAuth } from './codex.js';
|
|
5
|
+
import { mountLoginCommand } from './login-host.js';
|
|
6
|
+
import { pluginLlmError } from './plugin-error.js';
|
|
7
|
+
import { mountServiceTiers, withServiceTiers } from './service-tiers.js';
|
|
7
8
|
const PLUGIN_NAME = 'dsh-provider-extra';
|
|
8
9
|
const OWNER_COLLISION = 'CATALOG_OWNER_COLLISION';
|
|
10
|
+
/** Reported when the harness update waterfall arrives without its continuation. */
|
|
11
|
+
const MISSING_UPDATE_CONTINUATION = 'MISSING_UPDATE_CONTINUATION';
|
|
9
12
|
/** Preflight prevents even an unrelated competing row from expanding managed membership. */
|
|
10
13
|
function assertCatalogOwnership(ctx, ownedRoutes = [], defaultOwner) {
|
|
11
14
|
const currentDefault = ctx.get('agentDefaultModel');
|
|
12
|
-
if ((currentDefault !== undefined && currentDefault !== defaultOwner)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw
|
|
15
|
+
if ((currentDefault !== undefined && currentDefault !== defaultOwner) ||
|
|
16
|
+
ctx.llm.listProviders().some((provider) => !ownedRoutes.includes(provider.id)) ||
|
|
17
|
+
ctx.llm.listConfigurableProviders().length > 0) {
|
|
18
|
+
throw pluginLlmError('dsh-provider-extra: ' +
|
|
19
|
+
OWNER_COLLISION +
|
|
20
|
+
': disable competing provider and agent-default-model rows in this opted-in profile before mounting catalog', OWNER_COLLISION);
|
|
16
21
|
}
|
|
17
22
|
}
|
|
23
|
+
/** The stored credential behind a route: an alias shares its source provider's grant. */
|
|
24
|
+
function credentialIdOf(snapshot, route) {
|
|
25
|
+
const configured = snapshot.providers.get(route)?.auth;
|
|
26
|
+
return configured !== undefined && 'credentialProvider' in configured
|
|
27
|
+
? configured.credentialProvider
|
|
28
|
+
: route;
|
|
29
|
+
}
|
|
30
|
+
/** Route aliases must share the source provider's existing OAuth grant. */
|
|
31
|
+
function routeCredentials(snapshot, stored, requireOwnership) {
|
|
32
|
+
const credentialId = (route) => credentialIdOf(snapshot, route);
|
|
33
|
+
return {
|
|
34
|
+
read: async (route) => {
|
|
35
|
+
requireOwnership();
|
|
36
|
+
try {
|
|
37
|
+
return await stored.read(credentialId(route));
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
requireOwnership();
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
modify: async (route, change) => {
|
|
44
|
+
requireOwnership();
|
|
45
|
+
try {
|
|
46
|
+
return await stored.modify(credentialId(route), (current) => {
|
|
47
|
+
// A rotated token must persist; the outer guard still blocks model dispatch.
|
|
48
|
+
requireOwnership();
|
|
49
|
+
return change(current);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
requireOwnership();
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
delete: (route) => {
|
|
57
|
+
requireOwnership();
|
|
58
|
+
return stored.delete(credentialId(route));
|
|
59
|
+
},
|
|
60
|
+
list: async () => {
|
|
61
|
+
// Stored grants are part of the same owned membership: a conflicting
|
|
62
|
+
// composition must not report routes it can no longer dispatch to.
|
|
63
|
+
requireOwnership();
|
|
64
|
+
const records = await stored.list();
|
|
65
|
+
return [...snapshot.providers.values()].flatMap((provider) => {
|
|
66
|
+
if (provider.auth === undefined || !('credentialProvider' in provider.auth))
|
|
67
|
+
return [];
|
|
68
|
+
const record = records.find((item) => item.providerId === credentialId(provider.id));
|
|
69
|
+
return record === undefined ? [] : [{ ...record, providerId: provider.id }];
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** The key a route's Config references, resolved at dispatch so a rotated value applies at once. */
|
|
75
|
+
function catalogApiKey(ctx, snapshot, requireOwnership) {
|
|
76
|
+
return async (route) => {
|
|
77
|
+
// Prepared calls retain their snapshot and bypass profiles(); this gate
|
|
78
|
+
// stops a newly conflicting composition before credential-backed dispatch.
|
|
79
|
+
requireOwnership();
|
|
80
|
+
const configured = snapshot.providers.get(route);
|
|
81
|
+
if (configured === undefined)
|
|
82
|
+
throw pluginLlmError(`dsh-provider-extra: unknown catalog route "${route}"`, 'UNKNOWN_PROVIDER');
|
|
83
|
+
if (configured.auth === undefined || !('apiKeyRef' in configured.auth))
|
|
84
|
+
return undefined;
|
|
85
|
+
const ref = configured.auth.apiKeyRef;
|
|
86
|
+
const credentials = ctx.get('credentials');
|
|
87
|
+
const key = credentials === undefined ? process.env[ref] : (await credentials.resolve(ref))?.value;
|
|
88
|
+
requireOwnership();
|
|
89
|
+
if (key !== undefined && key.length > 0)
|
|
90
|
+
return assertUsableApiKey(key, PLUGIN_NAME, ref);
|
|
91
|
+
throw new LlmError(`dsh-provider-extra: no credential for route "${route}"; its Config references ${ref}`, 'MISSING_CREDENTIAL');
|
|
92
|
+
};
|
|
93
|
+
}
|
|
18
94
|
/** Immutable closures also keep prepared and in-flight calls on their original revision. */
|
|
19
95
|
export function mountCatalog(ctx, snapshot, config) {
|
|
20
96
|
assertCatalogOwnership(ctx);
|
|
@@ -24,79 +100,31 @@ export function mountCatalog(ctx, snapshot, config) {
|
|
|
24
100
|
throw ownershipError;
|
|
25
101
|
};
|
|
26
102
|
const auth = codexAuth(() => ctx.get('credentials'));
|
|
27
|
-
const credentialId = (route) => {
|
|
28
|
-
const configured = snapshot.providers.get(route)?.auth;
|
|
29
|
-
return configured !== undefined && 'credentialProvider' in configured ? configured.credentialProvider : route;
|
|
30
|
-
};
|
|
31
103
|
const sourceFor = (route) => snapshot.providers.get(route)?.source;
|
|
32
|
-
const tiers = mountServiceTiers(ctx, config, () => {
|
|
104
|
+
const tiers = mountServiceTiers(ctx, config, () => {
|
|
105
|
+
requireOwnership();
|
|
106
|
+
return snapshot.profiles;
|
|
107
|
+
}, sourceFor);
|
|
33
108
|
const adapter = new PiAiAdapter({
|
|
34
|
-
profiles: () => {
|
|
109
|
+
profiles: () => {
|
|
110
|
+
requireOwnership();
|
|
111
|
+
return withServiceTiers(snapshot.profiles, tiers.current, sourceFor);
|
|
112
|
+
},
|
|
35
113
|
auth: {
|
|
36
114
|
...auth,
|
|
37
|
-
|
|
38
|
-
credentials: {
|
|
39
|
-
read: async (route) => {
|
|
40
|
-
requireOwnership();
|
|
41
|
-
try {
|
|
42
|
-
return await auth.credentials.read(credentialId(route));
|
|
43
|
-
}
|
|
44
|
-
finally {
|
|
45
|
-
requireOwnership();
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
modify: async (route, change) => {
|
|
49
|
-
requireOwnership();
|
|
50
|
-
try {
|
|
51
|
-
return await auth.credentials.modify(credentialId(route), current => {
|
|
52
|
-
// A rotated token must persist; the outer guard still blocks model dispatch.
|
|
53
|
-
requireOwnership();
|
|
54
|
-
return change(current);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
finally {
|
|
58
|
-
requireOwnership();
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
delete: route => {
|
|
62
|
-
requireOwnership();
|
|
63
|
-
return auth.credentials.delete(credentialId(route));
|
|
64
|
-
},
|
|
65
|
-
list: async () => {
|
|
66
|
-
// Stored grants are part of the same owned membership: a conflicting
|
|
67
|
-
// composition must not report routes it can no longer dispatch to.
|
|
68
|
-
requireOwnership();
|
|
69
|
-
const stored = await auth.credentials.list();
|
|
70
|
-
return [...snapshot.providers.values()].flatMap(provider => {
|
|
71
|
-
if (provider.auth === undefined || !('credentialProvider' in provider.auth))
|
|
72
|
-
return [];
|
|
73
|
-
const record = stored.find(item => item.providerId === credentialId(provider.id));
|
|
74
|
-
return record === undefined ? [] : [{ ...record, providerId: provider.id }];
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
resolveApiKey: async (route) => {
|
|
80
|
-
// Prepared calls retain their snapshot and bypass profiles(); this gate
|
|
81
|
-
// stops a newly conflicting composition before credential-backed dispatch.
|
|
82
|
-
requireOwnership();
|
|
83
|
-
const configured = snapshot.providers.get(route);
|
|
84
|
-
if (configured === undefined)
|
|
85
|
-
throw new LlmError('dsh-provider-extra: unknown catalog route "' + route + '"', 'UNKNOWN_PROVIDER');
|
|
86
|
-
if (configured.auth === undefined || !('apiKeyRef' in configured.auth))
|
|
87
|
-
return undefined;
|
|
88
|
-
const ref = configured.auth.apiKeyRef;
|
|
89
|
-
const credentials = ctx.get('credentials');
|
|
90
|
-
const key = credentials === undefined ? process.env[ref] : (await credentials.resolve(ref))?.value;
|
|
91
|
-
requireOwnership();
|
|
92
|
-
if (key !== undefined && key.length > 0)
|
|
93
|
-
return assertUsableApiKey(key, PLUGIN_NAME, ref);
|
|
94
|
-
throw new LlmError('dsh-provider-extra: no credential for route "' + route + '"; its Config references ' + ref, 'MISSING_CREDENTIAL');
|
|
115
|
+
credentials: routeCredentials(snapshot, auth.credentials, requireOwnership),
|
|
95
116
|
},
|
|
117
|
+
resolveApiKey: catalogApiKey(ctx, snapshot, requireOwnership),
|
|
96
118
|
resolveAttachments: () => ctx.get('attachments'),
|
|
97
|
-
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, hostPath => ctx.get('fs')?.processPathFromHostPath(hostPath), ref),
|
|
119
|
+
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, (hostPath) => ctx.get('fs')?.processPathFromHostPath(hostPath), ref),
|
|
98
120
|
onReplayDegrade: ({ provider, model, reason }) => {
|
|
99
|
-
ctx.logger.warn('dsh-provider-extra: unusable replay state for "' +
|
|
121
|
+
ctx.logger.warn('dsh-provider-extra: unusable replay state for "' +
|
|
122
|
+
provider +
|
|
123
|
+
'/' +
|
|
124
|
+
model +
|
|
125
|
+
'" (' +
|
|
126
|
+
reason +
|
|
127
|
+
')');
|
|
100
128
|
},
|
|
101
129
|
});
|
|
102
130
|
const routes = [...snapshot.profiles.keys()];
|
|
@@ -125,8 +153,18 @@ export function mountCatalog(ctx, snapshot, config) {
|
|
|
125
153
|
// A public update veto runs before disposal, so a competing late-mounted
|
|
126
154
|
// adapter cannot turn a refused reload into loss of the last valid catalog.
|
|
127
155
|
let activeGeneration = true;
|
|
128
|
-
ctx.effect(() => () => {
|
|
129
|
-
|
|
156
|
+
ctx.effect(() => () => {
|
|
157
|
+
activeGeneration = false;
|
|
158
|
+
});
|
|
159
|
+
// cordis 4.1 reads this waterfall as (config, next); 4.0.5 still passes the
|
|
160
|
+
// flag it dropped before the continuation. A host on the supported 0.2.1
|
|
161
|
+
// line must keep reloading, so the continuation is taken from the end
|
|
162
|
+
// instead of a fixed position.
|
|
163
|
+
ctx.on('internal/update', (next, ...args) => {
|
|
164
|
+
const proceed = args.at(-1);
|
|
165
|
+
if (typeof proceed !== 'function') {
|
|
166
|
+
throw pluginLlmError('dsh-provider-extra: internal/update delivered no continuation', MISSING_UPDATE_CONTINUATION);
|
|
167
|
+
}
|
|
130
168
|
// A retired snapshot must not veto replacement of the current catalog owner.
|
|
131
169
|
if (!activeGeneration)
|
|
132
170
|
return proceed();
|
|
@@ -134,10 +172,24 @@ export function mountCatalog(ctx, snapshot, config) {
|
|
|
134
172
|
assertCatalogOwnership(ctx, routes, defaults);
|
|
135
173
|
return proceed();
|
|
136
174
|
});
|
|
137
|
-
mountLoginCommand(ctx, config, {
|
|
175
|
+
mountLoginCommand(ctx, config, {
|
|
176
|
+
catalog: snapshot,
|
|
177
|
+
profiles: () => snapshot.profiles,
|
|
178
|
+
requireOwnership,
|
|
179
|
+
});
|
|
180
|
+
hideAutomaticSettingsPage(ctx);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The catalog is an operator-owned Config edited in the profile, so the settings
|
|
184
|
+
* service must not generate an automatic page that edits it from another place.
|
|
185
|
+
*/
|
|
186
|
+
function hideAutomaticSettingsPage(ctx) {
|
|
138
187
|
ctx.inject(['settings'], (child) => {
|
|
139
188
|
const settings = child.get('settings');
|
|
140
|
-
if (typeof settings.configure === 'function')
|
|
141
|
-
|
|
189
|
+
if (typeof settings.configure === 'function') {
|
|
190
|
+
// The check narrows only this scope; a bound copy carries it into the effect with its receiver.
|
|
191
|
+
const configure = settings.configure.bind(settings);
|
|
192
|
+
child.effect(() => configure({ auto: false }, ctx.fiber));
|
|
193
|
+
}
|
|
142
194
|
});
|
|
143
195
|
}
|
package/dist/catalog.js
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
|
+
/** Managed configuration owns route identity and selection, never provider discovery. */
|
|
1
2
|
import { getSupportedThinkingLevels } from '@earendil-works/pi-ai';
|
|
2
|
-
import { buildCatalogProfile, catalogError, catalogMap, catalogRecord, catalogString, freezeCatalogValue } from
|
|
3
|
+
import { buildCatalogProfile, catalogError, catalogMap, catalogRecord, catalogString, freezeCatalogValue, } from './catalog-routes.js';
|
|
3
4
|
const CONFIG_VERSION = 1;
|
|
4
5
|
const CONFIG_FIELDS = ['version', 'providers', 'default'];
|
|
5
6
|
const SELECTION_FIELDS = ['provider', 'model', 'reasoningEffort'];
|
|
7
|
+
const OUTSIDE_SELECTION = 'provider/model is outside the managed selection';
|
|
8
|
+
/** Every route was just compiled into a profile, so a miss is a broken catalog and must not load. */
|
|
9
|
+
function servedProvider(profiles, id) {
|
|
10
|
+
const provider = profiles.get(id)?.piProvider;
|
|
11
|
+
if (provider === undefined)
|
|
12
|
+
catalogError('providers', `no loaded provider for ${id}`);
|
|
13
|
+
return provider;
|
|
14
|
+
}
|
|
15
|
+
/** The served model a selection names; a name the route does not serve is outside the catalog. */
|
|
16
|
+
function servedModel(profiles, provider, modelId) {
|
|
17
|
+
if (modelId === undefined)
|
|
18
|
+
catalogError('selection', OUTSIDE_SELECTION);
|
|
19
|
+
const model = servedProvider(profiles, provider)
|
|
20
|
+
.getModels()
|
|
21
|
+
.find((candidate) => candidate.id === modelId);
|
|
22
|
+
if (model === undefined)
|
|
23
|
+
catalogError('selection', OUTSIDE_SELECTION);
|
|
24
|
+
return model;
|
|
25
|
+
}
|
|
26
|
+
/** Every name a route answers to, each mapped to the model id it reaches. */
|
|
27
|
+
function routeAliases(profiles, provider) {
|
|
28
|
+
const names = new Map();
|
|
29
|
+
// Served models, not declarations: a filtered route owns ids it never spells out.
|
|
30
|
+
for (const model of servedProvider(profiles, provider.id).getModels())
|
|
31
|
+
names.set(model.id, model.id);
|
|
32
|
+
for (const model of provider.models ?? []) {
|
|
33
|
+
for (const alias of model.aliases ?? [])
|
|
34
|
+
names.set(alias, model.id);
|
|
35
|
+
}
|
|
36
|
+
return names;
|
|
37
|
+
}
|
|
6
38
|
/** Absence keeps legacy ownership separate from a managed empty catalog. */
|
|
7
39
|
export function compileCatalog(config) {
|
|
8
40
|
if (config === undefined)
|
|
@@ -16,40 +48,29 @@ export function compileCatalog(config) {
|
|
|
16
48
|
for (const declaration of raw.providers) {
|
|
17
49
|
const profile = buildCatalogProfile(declaration);
|
|
18
50
|
if (profiles.has(profile.provider))
|
|
19
|
-
catalogError('providers',
|
|
51
|
+
catalogError('providers', `duplicate provider ${profile.provider}`);
|
|
20
52
|
profiles.set(profile.provider, profile);
|
|
21
53
|
}
|
|
22
54
|
const normalized = structuredClone(raw);
|
|
23
|
-
const providers = catalogMap(normalized.providers.map(provider => [provider.id, provider]));
|
|
24
|
-
const aliases = new Map();
|
|
25
|
-
|
|
26
|
-
for (const provider of normalized.providers) {
|
|
27
|
-
const routeAliases = new Map();
|
|
28
|
-
// Served models, not declarations: a filtered route owns ids it never spells out.
|
|
29
|
-
for (const model of profiles.get(provider.id).piProvider.getModels()) {
|
|
30
|
-
routeAliases.set(model.id, model.id);
|
|
31
|
-
count++;
|
|
32
|
-
}
|
|
33
|
-
for (const model of provider.models ?? []) {
|
|
34
|
-
for (const alias of model.aliases ?? [])
|
|
35
|
-
routeAliases.set(alias, model.id);
|
|
36
|
-
}
|
|
37
|
-
aliases.set(provider.id, routeAliases);
|
|
38
|
-
}
|
|
55
|
+
const providers = catalogMap(normalized.providers.map((provider) => [provider.id, provider]));
|
|
56
|
+
const aliases = new Map(normalized.providers.map((provider) => [provider.id, routeAliases(profiles, provider)]));
|
|
57
|
+
const count = normalized.providers.reduce((served, provider) => served + servedProvider(profiles, provider.id).getModels().length, 0);
|
|
39
58
|
const resolveSelection = (input) => {
|
|
40
59
|
const candidate = catalogRecord(input, SELECTION_FIELDS, 'selection');
|
|
41
60
|
catalogString(candidate.provider, 'selection.provider');
|
|
42
61
|
catalogString(candidate.model, 'selection.model');
|
|
43
62
|
const modelId = aliases.get(candidate.provider)?.get(candidate.model);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if ('reasoningEffort' in candidate && !getSupportedThinkingLevels(model).includes(candidate.reasoningEffort)) {
|
|
63
|
+
const model = servedModel(profiles, candidate.provider, modelId);
|
|
64
|
+
if ('reasoningEffort' in candidate &&
|
|
65
|
+
!getSupportedThinkingLevels(model).includes(candidate.reasoningEffort)) {
|
|
48
66
|
catalogError('selection.reasoningEffort', 'effort is not supported by the selected model');
|
|
49
67
|
}
|
|
50
68
|
return freezeCatalogValue({
|
|
51
|
-
provider: candidate.provider,
|
|
52
|
-
|
|
69
|
+
provider: candidate.provider,
|
|
70
|
+
model: model.id,
|
|
71
|
+
...('reasoningEffort' in candidate
|
|
72
|
+
? { reasoningEffort: candidate.reasoningEffort }
|
|
73
|
+
: {}),
|
|
53
74
|
});
|
|
54
75
|
};
|
|
55
76
|
if (count === 0) {
|
|
@@ -59,7 +80,10 @@ export function compileCatalog(config) {
|
|
|
59
80
|
else
|
|
60
81
|
normalized.default = resolveSelection(normalized.default);
|
|
61
82
|
return freezeCatalogValue({
|
|
62
|
-
config: normalized,
|
|
63
|
-
|
|
83
|
+
config: normalized,
|
|
84
|
+
profiles: catalogMap(profiles),
|
|
85
|
+
providers,
|
|
86
|
+
selection: normalized.default,
|
|
87
|
+
resolveSelection,
|
|
64
88
|
});
|
|
65
89
|
}
|