@sagmans/dsh-provider-extra 0.8.0 → 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 +43 -33
package/dist/codex-login.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module dsh-provider-extra/codex-login
|
|
12
12
|
*/
|
|
13
|
-
import { CODEX_CATALOG_ID } from
|
|
13
|
+
import { CODEX_CATALOG_ID } from './codex.js';
|
|
14
14
|
/** pi-ai auth type id for the subscription login. */
|
|
15
15
|
const OAUTH_TYPE = 'oauth';
|
|
16
16
|
/** Render one pi-ai login event as terminal output lines. */
|
|
@@ -18,15 +18,15 @@ export function renderEvent(event) {
|
|
|
18
18
|
switch (event.type) {
|
|
19
19
|
case 'info': {
|
|
20
20
|
const link = event.links?.[0];
|
|
21
|
-
return [event.message + (link === undefined ? '' :
|
|
21
|
+
return [event.message + (link === undefined ? '' : ` ${link.url}`)];
|
|
22
22
|
}
|
|
23
23
|
case 'auth_url':
|
|
24
|
-
return [
|
|
24
|
+
return [event.instructions ?? 'Open this page to continue signing in:', event.url];
|
|
25
25
|
case 'device_code':
|
|
26
26
|
return [
|
|
27
27
|
'Enter this code on the verification page to finish signing in:',
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
` URL: ${event.verificationUri}`,
|
|
29
|
+
` Code: ${event.userCode}`,
|
|
30
30
|
];
|
|
31
31
|
case 'progress':
|
|
32
32
|
return [event.message];
|
|
@@ -36,14 +36,19 @@ export function renderEvent(event) {
|
|
|
36
36
|
export function renderPrompt(prompt) {
|
|
37
37
|
switch (prompt.type) {
|
|
38
38
|
case 'select': {
|
|
39
|
-
const choices = prompt.options
|
|
40
|
-
|
|
39
|
+
const choices = prompt.options
|
|
40
|
+
.map((option, index) => `${index + 1}) ${option.label}`)
|
|
41
|
+
.join(' | ');
|
|
42
|
+
return {
|
|
43
|
+
question: `${prompt.message} ${choices} — answer 1-${prompt.options.length} or id: `,
|
|
44
|
+
options: prompt.options,
|
|
45
|
+
};
|
|
41
46
|
}
|
|
42
47
|
case 'secret':
|
|
43
48
|
case 'text':
|
|
44
49
|
case 'manual_code': {
|
|
45
|
-
const hint = prompt.placeholder === undefined ? '' :
|
|
46
|
-
return { question: prompt.message + hint
|
|
50
|
+
const hint = prompt.placeholder === undefined ? '' : ` (${prompt.placeholder})`;
|
|
51
|
+
return { question: `${prompt.message + hint} ` };
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
}
|
|
@@ -63,10 +68,12 @@ export async function answerPrompt(terminal, prompt) {
|
|
|
63
68
|
if (option !== undefined)
|
|
64
69
|
return option.id;
|
|
65
70
|
}
|
|
66
|
-
const byId = options.find(option => option.id === raw.trim());
|
|
71
|
+
const byId = options.find((option) => option.id === raw.trim());
|
|
67
72
|
if (byId !== undefined)
|
|
68
73
|
return byId.id;
|
|
69
|
-
throw new Error('dsh-provider-extra: answer the prompt with a number 1-' +
|
|
74
|
+
throw new Error('dsh-provider-extra: answer the prompt with a number 1-' +
|
|
75
|
+
String(options.length) +
|
|
76
|
+
' or an option id');
|
|
70
77
|
}
|
|
71
78
|
return terminal.question(rendered.question);
|
|
72
79
|
}
|
|
@@ -120,7 +127,9 @@ export async function runCodexLogin(models, provider, terminal) {
|
|
|
120
127
|
export function readlineTerminal(rl, signal) {
|
|
121
128
|
return {
|
|
122
129
|
question: (prompt) => rl.question(prompt),
|
|
123
|
-
print: (line) => {
|
|
130
|
+
print: (line) => {
|
|
131
|
+
console.log(line);
|
|
132
|
+
},
|
|
124
133
|
signal,
|
|
125
134
|
};
|
|
126
135
|
}
|
package/dist/codex.js
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module dsh-provider-extra/codex
|
|
12
12
|
*/
|
|
13
|
-
import { defaultProviderAuthContext } from '@earendil-works/pi-ai';
|
|
14
|
-
import { builtinProviders } from '@earendil-works/pi-ai/providers/all';
|
|
15
13
|
import { credentialKey, credentialKeyId, credentialKeyScope, isCredentialKeySegment, } from '@deepseek-ai/dsh-credentials';
|
|
16
14
|
import { LlmError, resolveRetryPolicy } from '@deepseek-ai/dsh-llm';
|
|
17
|
-
import {
|
|
15
|
+
import { defaultProviderAuthContext } from '@earendil-works/pi-ai';
|
|
16
|
+
import { builtinProviders } from '@earendil-works/pi-ai/providers/all';
|
|
17
|
+
import { resolveExtraModels, selectWhitelistedModels } from './extra-models.js';
|
|
18
18
|
/** pi-ai catalog id of the ChatGPT-subscription provider this route serves. */
|
|
19
19
|
export const CODEX_CATALOG_ID = 'openai-codex';
|
|
20
20
|
/**
|
|
@@ -52,8 +52,10 @@ export function recordKeyFor(providerId) {
|
|
|
52
52
|
*/
|
|
53
53
|
function jsonImage(value) {
|
|
54
54
|
if (Array.isArray(value))
|
|
55
|
-
return value.map(entry => entry === undefined ? null : jsonImage(entry));
|
|
56
|
-
if (typeof value === 'object' &&
|
|
55
|
+
return value.map((entry) => (entry === undefined ? null : jsonImage(entry)));
|
|
56
|
+
if (typeof value === 'object' &&
|
|
57
|
+
value !== null &&
|
|
58
|
+
Object.getPrototypeOf(value) === Object.prototype) {
|
|
57
59
|
const image = {};
|
|
58
60
|
for (const [key, member] of Object.entries(value)) {
|
|
59
61
|
if (member !== undefined)
|
|
@@ -70,8 +72,8 @@ function toPiCredential(record) {
|
|
|
70
72
|
if (record.kind === 'api-key') {
|
|
71
73
|
return {
|
|
72
74
|
type: 'api_key',
|
|
73
|
-
...record.key === undefined ? {} : { key: record.key },
|
|
74
|
-
...record.env === undefined ? {} : { env: { ...record.env } },
|
|
75
|
+
...(record.key === undefined ? {} : { key: record.key }),
|
|
76
|
+
...(record.env === undefined ? {} : { env: { ...record.env } }),
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
return record.payload;
|
|
@@ -81,8 +83,8 @@ function toRecord(credential) {
|
|
|
81
83
|
if (credential.type === 'api_key') {
|
|
82
84
|
return {
|
|
83
85
|
kind: 'api-key',
|
|
84
|
-
...credential.key === undefined ? {} : { key: credential.key },
|
|
85
|
-
...credential.env === undefined ? {} : { env: { ...credential.env } },
|
|
86
|
+
...(credential.key === undefined ? {} : { key: credential.key }),
|
|
87
|
+
...(credential.env === undefined ? {} : { env: { ...credential.env } }),
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
90
|
return { kind: 'grant', payload: jsonImage(credential) };
|
|
@@ -105,7 +107,7 @@ export class HarnessCredentialStore {
|
|
|
105
107
|
return toPiCredential(await credentials.readRecord(recordKeyFor(providerId)));
|
|
106
108
|
}
|
|
107
109
|
async list() {
|
|
108
|
-
const stored = await this.credentials()?.listRecords() ?? [];
|
|
110
|
+
const stored = (await this.credentials()?.listRecords()) ?? [];
|
|
109
111
|
const mine = [];
|
|
110
112
|
for (const entry of stored) {
|
|
111
113
|
// Records another plugin owns are not this collection's to report:
|
|
@@ -121,13 +123,15 @@ export class HarnessCredentialStore {
|
|
|
121
123
|
}
|
|
122
124
|
async modify(providerId, mutate) {
|
|
123
125
|
if (!isCredentialKeySegment(providerId)) {
|
|
124
|
-
throw new LlmError('dsh-provider-extra: provider id "' +
|
|
125
|
-
+
|
|
126
|
+
throw new LlmError('dsh-provider-extra: provider id "' +
|
|
127
|
+
providerId +
|
|
128
|
+
'" cannot address a stored credential record (a record id is a' +
|
|
129
|
+
' lowercase hyphenated identifier)', 'UNSTORABLE_PROVIDER_ID');
|
|
126
130
|
}
|
|
127
131
|
const credentials = this.credentials();
|
|
128
132
|
if (credentials === undefined) {
|
|
129
|
-
throw new LlmError('dsh-provider-extra: this composition mounts no credentials service, so there is nowhere to store the'
|
|
130
|
-
|
|
133
|
+
throw new LlmError('dsh-provider-extra: this composition mounts no credentials service, so there is nowhere to store the' +
|
|
134
|
+
' credential a sign-in produces; mount one (dsh-credentials-local) to sign in', 'NO_CREDENTIAL_STORE');
|
|
131
135
|
}
|
|
132
136
|
const stored = await credentials.modifyRecord(recordKeyFor(providerId), async (current) => {
|
|
133
137
|
const next = await mutate(toPiCredential(current));
|
|
@@ -163,10 +167,12 @@ export function withTransport(options, config) {
|
|
|
163
167
|
* @throws Error when the installed pi-ai catalog no longer ships Codex.
|
|
164
168
|
*/
|
|
165
169
|
export function catalogCodex() {
|
|
166
|
-
const found = builtinProviders().find(provider => provider.id === CODEX_CATALOG_ID);
|
|
170
|
+
const found = builtinProviders().find((provider) => provider.id === CODEX_CATALOG_ID);
|
|
167
171
|
if (found === undefined) {
|
|
168
|
-
throw new Error('dsh-provider-extra: the installed pi-ai catalog has no provider "' +
|
|
169
|
-
+
|
|
172
|
+
throw new Error('dsh-provider-extra: the installed pi-ai catalog has no provider "' +
|
|
173
|
+
CODEX_CATALOG_ID +
|
|
174
|
+
'";' +
|
|
175
|
+
' pin @earendil-works/pi-ai to a catalog that ships it');
|
|
170
176
|
}
|
|
171
177
|
return found;
|
|
172
178
|
}
|
|
@@ -176,7 +182,7 @@ export function catalogCodex() {
|
|
|
176
182
|
* identity and models answer to the route configuration.
|
|
177
183
|
*/
|
|
178
184
|
function routeProvider(config, catalog, models) {
|
|
179
|
-
const routed = models.map(model => ({
|
|
185
|
+
const routed = models.map((model) => ({
|
|
180
186
|
...model,
|
|
181
187
|
provider: config.provider,
|
|
182
188
|
}));
|
|
@@ -203,6 +209,10 @@ const MAX_REQUEST_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
|
203
209
|
const REQUEST_IMAGE_PIXEL_BUDGET = 2048 * 2048;
|
|
204
210
|
/** Default raw encoded-byte target before inline base64 expansion. */
|
|
205
211
|
const REQUEST_IMAGE_MAX_BYTES = 1024 * 1024;
|
|
212
|
+
/** Default request-level bound on retained image occurrences. */
|
|
213
|
+
const MAX_REQUEST_IMAGES = 50;
|
|
214
|
+
/** Default oldest-image offload step when the occurrence bound overflows. */
|
|
215
|
+
const IMAGE_OFFLOAD_COUNT_QUANTUM = 10;
|
|
206
216
|
/**
|
|
207
217
|
* The resolved profile for the route. It names no credential reference: the
|
|
208
218
|
* subscription authenticates from the stored OAuth grant, never from an
|
|
@@ -224,6 +234,8 @@ export function buildCodexProfile(config) {
|
|
|
224
234
|
displayName: config.displayName,
|
|
225
235
|
streamIdleTimeoutMs: STREAM_IDLE_TIMEOUT_MS,
|
|
226
236
|
maxRequestImageBytes: MAX_REQUEST_IMAGE_BYTES,
|
|
237
|
+
maxRequestImages: MAX_REQUEST_IMAGES,
|
|
238
|
+
imageOffloadCountQuantum: IMAGE_OFFLOAD_COUNT_QUANTUM,
|
|
227
239
|
requestImagePixelBudget: REQUEST_IMAGE_PIXEL_BUDGET,
|
|
228
240
|
requestImageMaxBytes: REQUEST_IMAGE_MAX_BYTES,
|
|
229
241
|
retryPolicy: resolveRetryPolicy(undefined, 'dsh-provider-extra: openai-codex'),
|
|
@@ -253,5 +265,8 @@ export function codexApiKey() {
|
|
|
253
265
|
* store read, so a store holding only the Codex grant changes nothing for it.
|
|
254
266
|
*/
|
|
255
267
|
export function codexAuth(credentials) {
|
|
256
|
-
return {
|
|
268
|
+
return {
|
|
269
|
+
credentials: new HarnessCredentialStore(credentials),
|
|
270
|
+
authContext: defaultProviderAuthContext(),
|
|
271
|
+
};
|
|
257
272
|
}
|
package/dist/extra-models.js
CHANGED
|
@@ -27,7 +27,7 @@ import { LlmError } from '@deepseek-ai/dsh-llm';
|
|
|
27
27
|
export function resolveExtraModels(catalog, specs, fallbackTemplate) {
|
|
28
28
|
const models = [];
|
|
29
29
|
const modelErrors = new Map();
|
|
30
|
-
const shipped = new Set(catalog.map(model => model.id));
|
|
30
|
+
const shipped = new Set(catalog.map((model) => model.id));
|
|
31
31
|
const byId = new Map();
|
|
32
32
|
for (const spec of specs)
|
|
33
33
|
byId.set(spec.id, spec);
|
|
@@ -40,14 +40,20 @@ export function resolveExtraModels(catalog, specs, fallbackTemplate) {
|
|
|
40
40
|
continue;
|
|
41
41
|
const templateId = spec.template ?? fallbackTemplate;
|
|
42
42
|
if (templateId === undefined) {
|
|
43
|
-
modelErrors.set(spec.id, 'dsh-provider-extra: extra model "' +
|
|
44
|
-
+
|
|
43
|
+
modelErrors.set(spec.id, 'dsh-provider-extra: extra model "' +
|
|
44
|
+
spec.id +
|
|
45
|
+
'" names no template' +
|
|
46
|
+
' and this route ships no default sibling to clone');
|
|
45
47
|
continue;
|
|
46
48
|
}
|
|
47
|
-
const template = catalog.find(model => model.id === templateId);
|
|
49
|
+
const template = catalog.find((model) => model.id === templateId);
|
|
48
50
|
if (template === undefined) {
|
|
49
|
-
modelErrors.set(spec.id, 'dsh-provider-extra: extra model "' +
|
|
50
|
-
+
|
|
51
|
+
modelErrors.set(spec.id, 'dsh-provider-extra: extra model "' +
|
|
52
|
+
spec.id +
|
|
53
|
+
'" names template "' +
|
|
54
|
+
templateId +
|
|
55
|
+
'",' +
|
|
56
|
+
' which the installed catalog does not describe');
|
|
51
57
|
continue;
|
|
52
58
|
}
|
|
53
59
|
models.push({ ...template, id: spec.id, name: spec.name ?? template.name });
|
|
@@ -73,7 +79,7 @@ export function resolveExtraModels(catalog, specs, fallbackTemplate) {
|
|
|
73
79
|
export function selectWhitelistedModels(route, models, whitelist) {
|
|
74
80
|
if (whitelist === undefined)
|
|
75
81
|
return [...models];
|
|
76
|
-
const byId = new Map(models.map(model => [model.id, model]));
|
|
82
|
+
const byId = new Map(models.map((model) => [model.id, model]));
|
|
77
83
|
const selected = [];
|
|
78
84
|
const seen = new Set();
|
|
79
85
|
for (const id of whitelist) {
|
|
@@ -84,8 +90,12 @@ export function selectWhitelistedModels(route, models, whitelist) {
|
|
|
84
90
|
seen.add(id);
|
|
85
91
|
const model = byId.get(id);
|
|
86
92
|
if (model === undefined) {
|
|
87
|
-
throw new LlmError('dsh-provider-extra: route "' +
|
|
88
|
-
+
|
|
93
|
+
throw new LlmError('dsh-provider-extra: route "' +
|
|
94
|
+
route +
|
|
95
|
+
'" declares model "' +
|
|
96
|
+
id +
|
|
97
|
+
'" in its model selection,' +
|
|
98
|
+
' but neither the installed pi-ai catalog nor an extra model declaration provides it', 'UNKNOWN_MODEL');
|
|
89
99
|
}
|
|
90
100
|
selected.push(model);
|
|
91
101
|
}
|
package/dist/headless-startup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Headless-only argument ownership leaves the stock runner and its durable session protocol unchanged. */
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
|
-
import { isServiceTierOverride } from
|
|
3
|
+
import { isServiceTierOverride } from './service-tiers.js';
|
|
4
4
|
export const name = 'provider-extra-headless-startup';
|
|
5
5
|
export const inject = ['cmdlineArgs', 'appExit', 'agents', 'providerTierInvocation'];
|
|
6
6
|
const STARTUP_SERVICE = 'headlessStartup';
|
|
@@ -11,7 +11,7 @@ const STDIN_TASK = '-';
|
|
|
11
11
|
const JSON_FLAG = '--json';
|
|
12
12
|
const VALUE_FLAGS = new Set(['--session-id', '--service-tier']);
|
|
13
13
|
const TASK_REQUIRED = 'a task is required, for example: dsh --profile headless "run the tests"';
|
|
14
|
-
const HELP =
|
|
14
|
+
const HELP = 'Usage: dsh --profile headless [options] [task...]\n\nAnswer one task and exit; the answer goes to stdout and diagnostics to stderr.\n\nOptions:\n --json write newline-delimited run events to stdout instead of the final message\n --session-id <id> adopt the persisted Session with this id; an unknown id is an error\n --service-tier <tier> invocation only: auto, default, priority, fast, standard, provider-default\n -h, --help show this help\n\nThe task text joins multiple words with spaces; - reads stdin.\n\nExamples:\n dsh --profile headless "run the tests"\n echo "run the tests" | dsh --profile headless\n dsh --profile headless --json "run the tests"\n dsh --profile headless --session-id session-… "continue"\n';
|
|
15
15
|
/** Only a real flag before the separator can opt parse failures into machine-readable output. */
|
|
16
16
|
function jsonRequested(args) {
|
|
17
17
|
for (let index = 0; index < args.length; index += 1) {
|
|
@@ -34,10 +34,23 @@ function nativeArgs(args) {
|
|
|
34
34
|
break;
|
|
35
35
|
}
|
|
36
36
|
normalized.push(VALUE_FLAGS.has(argument) && index + 1 < args.length
|
|
37
|
-
? argument
|
|
37
|
+
? `${argument}=${args[++index]}`
|
|
38
|
+
: argument);
|
|
38
39
|
}
|
|
39
40
|
return normalized;
|
|
40
41
|
}
|
|
42
|
+
/** The first usage error in a parsed command line, in the order the reader would fix them. */
|
|
43
|
+
function usageProblem(positionals, task, sessionId, override) {
|
|
44
|
+
if (positionals.length > 1 && positionals.includes(STDIN_TASK))
|
|
45
|
+
return '`-` must be the only task argument';
|
|
46
|
+
if ((task !== undefined && task.trim() === '') || (task === undefined && process.stdin.isTTY))
|
|
47
|
+
return TASK_REQUIRED;
|
|
48
|
+
if (sessionId !== undefined && sessionId.trim() === '')
|
|
49
|
+
return '--session-id requires a non-empty session id';
|
|
50
|
+
if (override !== undefined && !isServiceTierOverride(override))
|
|
51
|
+
return `unsupported --service-tier: ${override}`;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
41
54
|
/** Publishing this public service starts the stock runner, so all syntax validation precedes publication. */
|
|
42
55
|
export function apply(ctx) {
|
|
43
56
|
const cmdline = ctx.get('cmdlineArgs');
|
|
@@ -45,14 +58,27 @@ export function apply(ctx) {
|
|
|
45
58
|
if (!cmdline || !exit)
|
|
46
59
|
throw new Error('dsh --profile headless: the launcher must provide ctx.cmdlineArgs and ctx.appExit before the tree mounts');
|
|
47
60
|
const args = cmdline.get();
|
|
61
|
+
/** Usage failures remain launcher-owned exits instead of failing plugin mounts or starting requests. */
|
|
62
|
+
const reject = (message) => {
|
|
63
|
+
if (jsonRequested(args))
|
|
64
|
+
process.stdout.write(`${JSON.stringify({ type: 'error', message })}\n`);
|
|
65
|
+
else
|
|
66
|
+
process.stderr.write(`error: ${message}\n`);
|
|
67
|
+
exit(USAGE_ERROR);
|
|
68
|
+
};
|
|
48
69
|
let parsed;
|
|
49
70
|
try {
|
|
50
|
-
parsed = parseArgs({
|
|
71
|
+
parsed = parseArgs({
|
|
72
|
+
args: nativeArgs(args),
|
|
73
|
+
allowPositionals: true,
|
|
74
|
+
strict: true,
|
|
75
|
+
options: {
|
|
51
76
|
json: { type: 'boolean' },
|
|
52
77
|
'session-id': { type: 'string' },
|
|
53
78
|
'service-tier': { type: 'string' },
|
|
54
79
|
help: { type: 'boolean', short: 'h' },
|
|
55
|
-
}
|
|
80
|
+
},
|
|
81
|
+
});
|
|
56
82
|
}
|
|
57
83
|
catch (error) {
|
|
58
84
|
reject(error instanceof Error ? error.message : String(error));
|
|
@@ -67,26 +93,15 @@ export function apply(ctx) {
|
|
|
67
93
|
const task = positionals.length === 0 ? undefined : positionals.join(' ');
|
|
68
94
|
const sessionId = values['session-id'];
|
|
69
95
|
const override = values['service-tier'];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
return reject('--session-id requires a non-empty session id');
|
|
76
|
-
if (override !== undefined && !isServiceTierOverride(override))
|
|
77
|
-
return reject('unsupported --service-tier: ' + override);
|
|
96
|
+
const problem = usageProblem(positionals, task, sessionId, override);
|
|
97
|
+
if (problem !== undefined) {
|
|
98
|
+
reject(problem);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
78
101
|
const agents = ctx.get('agents');
|
|
79
102
|
const controller = ctx.get('providerTierInvocation');
|
|
80
103
|
if (!agents || !controller)
|
|
81
104
|
throw new Error('headless service tiers require agents and providerTierInvocation');
|
|
82
105
|
ctx.effect(() => controller.activate(override, sessionId, agents));
|
|
83
106
|
ctx.provide(STARTUP_SERVICE, { task, sessionId, json: values.json === true });
|
|
84
|
-
/** Usage failures remain launcher-owned exits instead of failing plugin mounts or starting requests. */
|
|
85
|
-
function reject(message) {
|
|
86
|
-
if (jsonRequested(args))
|
|
87
|
-
process.stdout.write(JSON.stringify({ type: 'error', message }) + '\n');
|
|
88
|
-
else
|
|
89
|
-
process.stderr.write('error: ' + message + '\n');
|
|
90
|
-
exit(USAGE_ERROR);
|
|
91
|
-
}
|
|
92
107
|
}
|
package/dist/index.js
CHANGED
|
@@ -28,19 +28,18 @@
|
|
|
28
28
|
*
|
|
29
29
|
* @module dsh-provider-extra
|
|
30
30
|
*/
|
|
31
|
-
import
|
|
31
|
+
import { assertUsableApiKey, LlmError, resolveImageAttachmentAccess } from '@deepseek-ai/dsh-llm';
|
|
32
32
|
import { PiAiAdapter } from '@deepseek-ai/dsh-llm-pi-ai';
|
|
33
|
-
import
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import { CODEX_TRANSPORTS } from
|
|
37
|
-
import { DEFAULT_LOGIN_COMMAND_NAME } from
|
|
38
|
-
import { mountLoginCommand } from
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
export { buildCatalogProfile } from "./catalog-routes.js";
|
|
33
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
34
|
+
import { compileCatalog } from './catalog.js';
|
|
35
|
+
import { mountCatalog } from './catalog-runtime.js';
|
|
36
|
+
import { buildCodexProfile, CODEX_TRANSPORTS, codexApiKey, codexAuth, DEFAULT_CODEX_DISPLAY_NAME, DEFAULT_CODEX_ROUTE_ID, } from './codex.js';
|
|
37
|
+
import { DEFAULT_LOGIN_COMMAND_NAME } from './login-command.js';
|
|
38
|
+
import { mountLoginCommand } from './login-host.js';
|
|
39
|
+
import { buildOpenCodeGoProfile, DEFAULT_EXTRA_MODEL_TEMPLATE, DEFAULT_OPENCODE_API_KEY_ENV, OPENCODE_GO_PROVIDER_ID, } from './opencode-go.js';
|
|
40
|
+
import { mountServiceTiers, SERVICE_TIER_CHOICES, withServiceTiers } from './service-tiers.js';
|
|
41
|
+
export { compileCatalog } from './catalog.js';
|
|
42
|
+
export { buildCatalogProfile } from './catalog-routes.js';
|
|
44
43
|
/** Settings namespace configuration surfaces address this plugin's section by. */
|
|
45
44
|
const SETTINGS_NS = 'dsh-provider-extra';
|
|
46
45
|
// Declared extra models: the composition entry and the settings section share
|
|
@@ -72,7 +71,7 @@ export const Config = Schema.transform(Schema.object({
|
|
|
72
71
|
serviceTierSelections: Schema.array(Schema.object({
|
|
73
72
|
provider: Schema.string().required(),
|
|
74
73
|
model: Schema.string().required(),
|
|
75
|
-
tier: Schema.union(SERVICE_TIER_CHOICES.map(choice => choice.id)).required(),
|
|
74
|
+
tier: Schema.union(SERVICE_TIER_CHOICES.map((choice) => choice.id)).required(),
|
|
76
75
|
})).default([]),
|
|
77
76
|
apiKeyEnv: Schema.string().role('credential-ref').default(DEFAULT_OPENCODE_API_KEY_ENV),
|
|
78
77
|
routeId: Schema.string().default(OPENCODE_GO_PROVIDER_ID),
|
|
@@ -126,23 +125,25 @@ export function apply(ctx, config) {
|
|
|
126
125
|
provider: config.routeId,
|
|
127
126
|
displayName: config.displayName,
|
|
128
127
|
apiKeyEnv: config.apiKeyEnv,
|
|
129
|
-
...config.baseURL === undefined ? {} : { baseURL: config.baseURL },
|
|
130
|
-
...config.fallbackSessionId === undefined
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
...(config.baseURL === undefined ? {} : { baseURL: config.baseURL }),
|
|
129
|
+
...(config.fallbackSessionId === undefined
|
|
130
|
+
? {}
|
|
131
|
+
: { fallbackSessionId: config.fallbackSessionId }),
|
|
132
|
+
...(config.headers === undefined ? {} : { headers: { ...config.headers } }),
|
|
133
|
+
...(models === undefined ? {} : { models }),
|
|
133
134
|
};
|
|
134
135
|
const codex = {
|
|
135
136
|
provider: config.codexRouteId,
|
|
136
137
|
displayName: config.codexDisplayName,
|
|
137
|
-
...codexModels === undefined ? {} : { models: codexModels },
|
|
138
|
-
...config.codexTransport === undefined ? {} : { transport: config.codexTransport },
|
|
138
|
+
...(codexModels === undefined ? {} : { models: codexModels }),
|
|
139
|
+
...(config.codexTransport === undefined ? {} : { transport: config.codexTransport }),
|
|
139
140
|
};
|
|
140
141
|
// The entry's own declarations are the base layer the settings section sits
|
|
141
142
|
// over, and the value the routes serve on a harness with no settings document
|
|
142
143
|
// at all — which is why they seed the thunk below instead of only the base.
|
|
143
144
|
const entry = {
|
|
144
|
-
extraModels: [...config.extraModels ?? []],
|
|
145
|
-
codexExtraModels: [...config.codexExtraModels ?? []],
|
|
145
|
+
extraModels: [...(config.extraModels ?? [])],
|
|
146
|
+
codexExtraModels: [...(config.codexExtraModels ?? [])],
|
|
146
147
|
};
|
|
147
148
|
// A declared selection is configuration, not a request fact, so it is proven
|
|
148
149
|
// once here. Registration resolves a profile for its route metadata and
|
|
@@ -167,7 +168,9 @@ export function apply(ctx, config) {
|
|
|
167
168
|
codexServable = true;
|
|
168
169
|
}
|
|
169
170
|
catch (error) {
|
|
170
|
-
ctx.logger.error('dsh-provider-extra: codex route "' +
|
|
171
|
+
ctx.logger.error('dsh-provider-extra: codex route "' +
|
|
172
|
+
codex.provider +
|
|
173
|
+
'" disabled; the installed pi-ai catalog cannot serve it');
|
|
171
174
|
ctx.logger.error(error);
|
|
172
175
|
}
|
|
173
176
|
}
|
|
@@ -179,14 +182,22 @@ export function apply(ctx, config) {
|
|
|
179
182
|
const section = currentSection();
|
|
180
183
|
// Selections stay bound to the entry extras that passed mount-time validation.
|
|
181
184
|
const entries = [
|
|
182
|
-
[
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
[
|
|
186
|
+
route.provider,
|
|
187
|
+
buildOpenCodeGoProfile({
|
|
188
|
+
...route,
|
|
189
|
+
extraModels: models !== undefined ? entry.extraModels : section.extraModels,
|
|
190
|
+
}),
|
|
191
|
+
],
|
|
185
192
|
];
|
|
186
193
|
if (codexServable) {
|
|
187
|
-
entries.push([
|
|
188
|
-
|
|
189
|
-
|
|
194
|
+
entries.push([
|
|
195
|
+
codex.provider,
|
|
196
|
+
buildCodexProfile({
|
|
197
|
+
...codex,
|
|
198
|
+
extraModels: codexModels !== undefined ? entry.codexExtraModels : section.codexExtraModels,
|
|
199
|
+
}),
|
|
200
|
+
]);
|
|
190
201
|
}
|
|
191
202
|
return new Map(entries);
|
|
192
203
|
};
|
|
@@ -207,8 +218,11 @@ export function apply(ctx, config) {
|
|
|
207
218
|
if (hit !== undefined && hit.length > 0) {
|
|
208
219
|
return assertUsableApiKey(hit, name, route.apiKeyEnv);
|
|
209
220
|
}
|
|
210
|
-
throw new LlmError('dsh-provider-extra: no credential for route "' +
|
|
211
|
-
+
|
|
221
|
+
throw new LlmError('dsh-provider-extra: no credential for route "' +
|
|
222
|
+
route.provider +
|
|
223
|
+
'"; its profile resolves ' +
|
|
224
|
+
route.apiKeyEnv +
|
|
225
|
+
', which is not set — store it through the credentials service or export it', 'MISSING_CREDENTIAL');
|
|
212
226
|
},
|
|
213
227
|
// One shared injection for both routes: the OpenCode Go key arrives as
|
|
214
228
|
// the request-level override (preferred over every store read), so the
|
|
@@ -221,13 +235,18 @@ export function apply(ctx, config) {
|
|
|
221
235
|
// the filesystem service still sends the image, only without the
|
|
222
236
|
// model-facing normalized-copy path.
|
|
223
237
|
resolveAttachments: () => ctx.get('attachments'),
|
|
224
|
-
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, hostPath => ctx.get('fs')?.processPathFromHostPath(hostPath), ref),
|
|
238
|
+
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, (hostPath) => ctx.get('fs')?.processPathFromHostPath(hostPath), ref),
|
|
225
239
|
// A stored replay state the installed pi-ai cannot reconstruct already
|
|
226
240
|
// degrades to provider-neutral content; naming it keeps that downgrade
|
|
227
241
|
// diagnosable instead of silent.
|
|
228
242
|
onReplayDegrade: ({ provider, model, reason }) => {
|
|
229
|
-
ctx.logger.warn('dsh-provider-extra: unusable replay state on assistant history for route "'
|
|
230
|
-
|
|
243
|
+
ctx.logger.warn('dsh-provider-extra: unusable replay state on assistant history for route "' +
|
|
244
|
+
provider +
|
|
245
|
+
'/' +
|
|
246
|
+
model +
|
|
247
|
+
'"; sending that message as provider-neutral content (' +
|
|
248
|
+
reason +
|
|
249
|
+
')');
|
|
231
250
|
},
|
|
232
251
|
});
|
|
233
252
|
// A route another adapter already owns (opencode-go configured under
|
|
@@ -238,8 +257,10 @@ export function apply(ctx, config) {
|
|
|
238
257
|
servedProviders.add(route.provider);
|
|
239
258
|
}
|
|
240
259
|
catch (error) {
|
|
241
|
-
ctx.logger.error('dsh-provider-extra: route "' +
|
|
242
|
-
+
|
|
260
|
+
ctx.logger.error('dsh-provider-extra: route "' +
|
|
261
|
+
route.provider +
|
|
262
|
+
'" was refused;' +
|
|
263
|
+
" remove it from llm-pi-ai's providers section to serve it here");
|
|
243
264
|
ctx.logger.error(error);
|
|
244
265
|
return;
|
|
245
266
|
}
|
|
@@ -253,23 +274,29 @@ export function apply(ctx, config) {
|
|
|
253
274
|
servedProviders.add(codex.provider);
|
|
254
275
|
}
|
|
255
276
|
catch (error) {
|
|
256
|
-
ctx.logger.warn('dsh-provider-extra: codex route "' +
|
|
257
|
-
+
|
|
277
|
+
ctx.logger.warn('dsh-provider-extra: codex route "' +
|
|
278
|
+
codex.provider +
|
|
279
|
+
'" stays with its existing owner;' +
|
|
280
|
+
" remove it from llm-pi-ai's providers section to serve it here");
|
|
258
281
|
ctx.logger.warn(error);
|
|
259
282
|
}
|
|
260
283
|
}
|
|
261
284
|
try {
|
|
262
|
-
ctx.llm.registerConfigurableProviders([
|
|
285
|
+
ctx.llm.registerConfigurableProviders([
|
|
286
|
+
{
|
|
263
287
|
provider: route.provider,
|
|
264
288
|
displayName: route.displayName,
|
|
265
289
|
settingsNs: SETTINGS_NS,
|
|
266
290
|
settingsPath: [route.provider],
|
|
267
|
-
}
|
|
291
|
+
},
|
|
292
|
+
]);
|
|
268
293
|
}
|
|
269
294
|
catch (error) {
|
|
270
295
|
// llm-pi-ai already lists every catalog id in the directory, including
|
|
271
296
|
// opencode-go; its entry keeps serving the Models page here.
|
|
272
|
-
ctx.logger.warn('dsh-provider-extra: directory entry for "' +
|
|
297
|
+
ctx.logger.warn('dsh-provider-extra: directory entry for "' +
|
|
298
|
+
route.provider +
|
|
299
|
+
'" stays with its existing owner');
|
|
273
300
|
ctx.logger.warn(error);
|
|
274
301
|
}
|
|
275
302
|
ctx.inject(['settings'], (settingsCtx) => {
|
|
@@ -285,11 +312,15 @@ export function apply(ctx, config) {
|
|
|
285
312
|
// stands in for it where none does; the settings service falls back to this
|
|
286
313
|
// same value when it detaches.
|
|
287
314
|
settings.installSection(ctx, SETTINGS_NS, SectionSchema, entry, {
|
|
288
|
-
setSource: (source) => {
|
|
315
|
+
setSource: (source) => {
|
|
316
|
+
currentSection = source;
|
|
317
|
+
},
|
|
289
318
|
// No registration facts derive from the section: the route set is fixed
|
|
290
319
|
// at composition and the adapter rebuilds its snapshot on every
|
|
291
320
|
// operation, so a committed extras change applies alone.
|
|
292
|
-
onChange: () => {
|
|
321
|
+
onChange: () => {
|
|
322
|
+
/* per-operation snapshot; no swap needed */
|
|
323
|
+
},
|
|
293
324
|
});
|
|
294
325
|
});
|
|
295
326
|
mountLoginCommand(ctx, config, { profiles });
|