@sagmans/dsh-provider-extra 0.3.0 → 0.4.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 CHANGED
@@ -105,6 +105,20 @@ dsh-provider-extra:
105
105
 
106
106
  Each entry clones wire behavior from its template. Later entries win by ID. A catalog-owned ID is not replaced. An unknown template becomes a model diagnostic without disabling the route.
107
107
 
108
+ ## Codex models
109
+
110
+ The Codex route serves pi-ai's installed `openai-codex` catalog for the signed-in subscription. Extend it the same way when the subscription serves an ID the installed catalog predates:
111
+
112
+ ```yaml
113
+ dsh-provider-extra:
114
+ codexExtraModels:
115
+ - id: gpt-6-luna
116
+ name: GPT-6 Luna
117
+ template: gpt-5.6-luna
118
+ ```
119
+
120
+ Unlike the Go route, these entries must name their `template`: Codex ships no default sibling, so a declaration that names none is reported as a model diagnostic instead of cloned from another vendor's catalog. Later entries win by ID, a catalog-owned ID is not replaced, and an unknown template becomes a diagnostic without disabling the route. Both settings sections are read per request, so a committed change reaches the next turn with no restart.
121
+
108
122
  ## Provider sign-in
109
123
 
110
124
  Sign in from the profile you are already using: the plugin registers a command in the harness command palette, and it reaches every provider the installed pi-ai catalog ships a login for — the two routes here, and core's own.
package/dist/codex.js CHANGED
@@ -14,6 +14,7 @@ import { defaultProviderAuthContext } from '@earendil-works/pi-ai';
14
14
  import { builtinProviders } from '@earendil-works/pi-ai/providers/all';
15
15
  import { credentialKey, credentialKeyId, credentialKeyScope, isCredentialKeySegment, } from '@deepseek-ai/dsh-credentials';
16
16
  import { LlmError, resolveRetryPolicy } from '@deepseek-ai/dsh-llm';
17
+ import { resolveExtraModels } from "./extra-models.js";
17
18
  /** pi-ai catalog id of the ChatGPT-subscription provider this route serves. */
18
19
  export const CODEX_CATALOG_ID = 'openai-codex';
19
20
  /**
@@ -152,8 +153,8 @@ export function catalogCodex() {
152
153
  * catalog provider so its API implementation and OAuth quirks survive, while
153
154
  * identity and models answer to the route configuration.
154
155
  */
155
- function routeProvider(config, catalog) {
156
- const models = catalog.getModels().map(model => ({
156
+ function routeProvider(config, catalog, models) {
157
+ const routed = models.map(model => ({
157
158
  ...model,
158
159
  provider: config.provider,
159
160
  }));
@@ -164,7 +165,7 @@ function routeProvider(config, catalog) {
164
165
  id: config.provider,
165
166
  name: config.displayName,
166
167
  auth: catalog.auth,
167
- getModels: () => models,
168
+ getModels: () => routed,
168
169
  stream: (model, context, options) => catalog.stream(model, context, options),
169
170
  streamSimple: (model, context, options) => catalog.streamSimple(model, context, options),
170
171
  };
@@ -188,6 +189,10 @@ const REQUEST_IMAGE_MAX_BYTES = 1024 * 1024;
188
189
  */
189
190
  export function buildCodexProfile(config) {
190
191
  const catalog = catalogCodex();
192
+ // Codex ships no fallback template: a sibling from another vendor's gateway
193
+ // would be dispatched as if the subscription served it, so a declaration
194
+ // that names none is reported instead of cloned.
195
+ const extras = resolveExtraModels(catalog.getModels(), config.extraModels ?? []);
191
196
  return {
192
197
  provider: config.provider,
193
198
  displayName: config.displayName,
@@ -196,9 +201,9 @@ export function buildCodexProfile(config) {
196
201
  requestImagePixelBudget: REQUEST_IMAGE_PIXEL_BUDGET,
197
202
  requestImageMaxBytes: REQUEST_IMAGE_MAX_BYTES,
198
203
  retryPolicy: resolveRetryPolicy(undefined, 'dsh-provider-extra: openai-codex'),
199
- modelErrors: new Map(),
204
+ modelErrors: extras.modelErrors,
200
205
  configuredMaxTokens: new Map(),
201
- piProvider: routeProvider(config, catalog),
206
+ piProvider: routeProvider(config, catalog, [...catalog.getModels(), ...extras.models]),
202
207
  };
203
208
  }
204
209
  /**
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Settings-declared model additions, shared by every route this plugin owns.
3
+ *
4
+ * The installed catalog stays the authority on wire behavior: an extra only
5
+ * names an id the catalog predates, and clones a template sibling's API quirks,
6
+ * costs, and limits instead of restating them. A declaration that cannot
7
+ * resolve lands in the route's model diagnostics beside its serviceable
8
+ * models, because one mistyped template must not silence a whole route.
9
+ *
10
+ * @module dsh-provider-extra/extra-models
11
+ */
12
+ /**
13
+ * Resolve declared extras against the installed catalog. Later specs win over
14
+ * earlier ones by id, so a settings entry reshapes a shipped default under the
15
+ * same id; an id the catalog itself ships stays with the catalog.
16
+ * @param catalog - installed catalog models to clone wire behavior from.
17
+ * @param specs - declared extras, shipped defaults first.
18
+ * @param fallbackTemplate - catalog id used when a spec names no template; a
19
+ * route whose gateway serves no representative sibling omits it, so the
20
+ * omission is reported instead of cloned from an unrelated provider.
21
+ * @returns the resolved extras and per-model failure diagnostics.
22
+ */
23
+ export function resolveExtraModels(catalog, specs, fallbackTemplate) {
24
+ const models = [];
25
+ const modelErrors = new Map();
26
+ const shipped = new Set(catalog.map(model => model.id));
27
+ const byId = new Map();
28
+ for (const spec of specs)
29
+ byId.set(spec.id, spec);
30
+ for (const spec of byId.values()) {
31
+ if (spec.id.length === 0) {
32
+ modelErrors.set(spec.id, 'dsh-provider-extra: an extra model has an empty id');
33
+ continue;
34
+ }
35
+ if (shipped.has(spec.id))
36
+ continue;
37
+ const templateId = spec.template ?? fallbackTemplate;
38
+ if (templateId === undefined) {
39
+ modelErrors.set(spec.id, 'dsh-provider-extra: extra model "' + spec.id + '" names no template'
40
+ + ' and this route ships no default sibling to clone');
41
+ continue;
42
+ }
43
+ const template = catalog.find(model => model.id === templateId);
44
+ if (template === undefined) {
45
+ modelErrors.set(spec.id, 'dsh-provider-extra: extra model "' + spec.id + '" names template "' + templateId + '",'
46
+ + ' which the installed catalog does not describe');
47
+ continue;
48
+ }
49
+ models.push({ ...template, id: spec.id, name: spec.name ?? template.name });
50
+ }
51
+ return { models, modelErrors };
52
+ }
package/dist/index.js CHANGED
@@ -53,13 +53,22 @@ export const Config = Schema.object({
53
53
  });
54
54
  export const name = 'dsh-provider-extra';
55
55
  export const inject = ['llm'];
56
- const extraModelSchema = Schema.object({
56
+ const goExtraModelSchema = Schema.object({
57
57
  id: Schema.string().required(),
58
58
  name: Schema.string(),
59
59
  template: Schema.string().default(DEFAULT_EXTRA_MODEL_TEMPLATE),
60
60
  });
61
+ // The Codex route ships no default template: a declaration must name the
62
+ // sibling it clones, because a clone from another vendor's catalog would be
63
+ // dispatched as if the subscription served it.
64
+ const codexExtraModelSchema = Schema.object({
65
+ id: Schema.string().required(),
66
+ name: Schema.string(),
67
+ template: Schema.string(),
68
+ });
61
69
  const SectionSchema = Schema.object({
62
- extraModels: Schema.array(extraModelSchema).default([]),
70
+ extraModels: Schema.array(goExtraModelSchema).default([]),
71
+ codexExtraModels: Schema.array(codexExtraModelSchema).default([]),
63
72
  });
64
73
  /**
65
74
  * Every catalog provider that ships an interactive login, in catalog order.
@@ -111,14 +120,15 @@ export function apply(ctx, config) {
111
120
  provider: config.codexRouteId,
112
121
  displayName: config.codexDisplayName,
113
122
  };
114
- // The Codex profile is boot-time, not per-request: it takes no settings
115
- // inputs, and building it per operation would let a catalog drift (pi-ai no
116
- // longer shipping Codex) fail every request on both routes instead of just
117
- // standing this route down once, loudly, here.
118
- let codexProfile;
123
+ // The catalog check stays boot-time even though settings can now extend the
124
+ // profile per request: a catalog drift (pi-ai no longer shipping Codex) must
125
+ // stand this route down once, loudly, here, instead of failing every request
126
+ // on both routes.
127
+ let codexServable = false;
119
128
  if (config.codexEnabled) {
120
129
  try {
121
- codexProfile = buildCodexProfile(codex);
130
+ buildCodexProfile(codex);
131
+ codexServable = true;
122
132
  }
123
133
  catch (error) {
124
134
  ctx.logger.error('dsh-provider-extra: codex route "' + codex.provider + '" disabled; the installed pi-ai catalog cannot serve it');
@@ -128,13 +138,15 @@ export function apply(ctx, config) {
128
138
  // Route wiring is boot-time, but the model list is per-request: the section
129
139
  // thunk below tracks the settings overlay, so a committed extras change
130
140
  // reaches the next operation with no rebuild and no restart.
131
- let currentSection = () => ({ extraModels: [] });
141
+ let currentSection = () => ({ extraModels: [], codexExtraModels: [] });
132
142
  const profiles = () => {
143
+ const section = currentSection();
133
144
  const entries = [
134
- [route.provider, buildOpenCodeGoProfile({ ...route, extraModels: currentSection().extraModels })],
145
+ [route.provider, buildOpenCodeGoProfile({ ...route, extraModels: section.extraModels })],
135
146
  ];
136
- if (codexProfile !== undefined)
137
- entries.push([codex.provider, codexProfile]);
147
+ if (codexServable) {
148
+ entries.push([codex.provider, buildCodexProfile({ ...codex, extraModels: section.codexExtraModels })]);
149
+ }
138
150
  return new Map(entries);
139
151
  };
140
152
  const adapter = new PiAiAdapter({
@@ -190,7 +202,7 @@ export function apply(ctx, config) {
190
202
  // all-or-nothing: one call for both would drop a working route when the
191
203
  // other collides. llm-pi-ai's directory already lists the catalog id, so
192
204
  // no directory entry is registered here — core's serves the Models page.
193
- if (codexProfile !== undefined) {
205
+ if (codexServable) {
194
206
  try {
195
207
  ctx.llm.registerAdapter([codex.provider], adapter);
196
208
  }
@@ -215,7 +227,7 @@ export function apply(ctx, config) {
215
227
  ctx.logger.warn(error);
216
228
  }
217
229
  ctx.inject(['settings'], (settingsCtx) => {
218
- settingsCtx.settings.installSection(ctx, SETTINGS_NS, SectionSchema, { extraModels: [] }, {
230
+ settingsCtx.settings.installSection(ctx, SETTINGS_NS, SectionSchema, { extraModels: [], codexExtraModels: [] }, {
219
231
  setSource: (source) => { currentSection = source; },
220
232
  // No registration facts derive from the section: the route set is fixed
221
233
  // at composition and the adapter rebuilds its snapshot on every
@@ -15,6 +15,7 @@
15
15
  import { defaultProviderAuthContext } from '@earendil-works/pi-ai';
16
16
  import { builtinProviders } from '@earendil-works/pi-ai/providers/all';
17
17
  import { resolveRetryPolicy } from '@deepseek-ai/dsh-llm';
18
+ import { resolveExtraModels } from "./extra-models.js";
18
19
  /** pi-ai catalog id of the OpenCode Go provider this route mirrors. */
19
20
  export const OPENCODE_GO_PROVIDER_ID = 'opencode-go';
20
21
  /** Routing header the OpenCode Go gateway requires on every model request. */
@@ -31,42 +32,6 @@ export const DEFAULT_EXTRA_MODEL_TEMPLATE = 'deepseek-v4-flash';
31
32
  const DEFAULT_EXTRA_MODELS = [
32
33
  { id: DEEPSEEK_V41_FLASH_ID, name: DEEPSEEK_V41_FLASH_NAME, template: DEFAULT_EXTRA_MODEL_TEMPLATE },
33
34
  ];
34
- /**
35
- * Resolve declared extras against the installed catalog. Later specs win over
36
- * earlier ones by id, so a settings entry reshapes the shipped default under
37
- * the same id; an id the catalog itself ships stays with the catalog.
38
- * Failures land in `modelErrors` beside serviceable models instead of
39
- * refusing the route, because one mistyped template must not silence the
40
- * other twenty-seven.
41
- * @param catalog - installed catalog models to clone wire behavior from.
42
- * @param specs - declared extras, shipped defaults first.
43
- * @returns the resolved extras and per-model failure diagnostics.
44
- */
45
- export function resolveExtraModels(catalog, specs) {
46
- const models = [];
47
- const modelErrors = new Map();
48
- const shipped = new Set(catalog.map(model => model.id));
49
- const byId = new Map();
50
- for (const spec of specs)
51
- byId.set(spec.id, spec);
52
- for (const spec of byId.values()) {
53
- if (spec.id.length === 0) {
54
- modelErrors.set(spec.id, 'dsh-provider-extra: an extra model has an empty id');
55
- continue;
56
- }
57
- if (shipped.has(spec.id))
58
- continue;
59
- const templateId = spec.template ?? DEFAULT_EXTRA_MODEL_TEMPLATE;
60
- const template = catalog.find(model => model.id === templateId);
61
- if (template === undefined) {
62
- modelErrors.set(spec.id, `dsh-provider-extra: extra model "${spec.id}" names template "${templateId}",`
63
- + ' which the installed catalog does not describe');
64
- continue;
65
- }
66
- models.push({ ...template, id: spec.id, name: spec.name ?? template.name });
67
- }
68
- return { models, modelErrors };
69
- }
70
35
  // The resolved profile defaults below mirror dsh-llm-pi-ai's config resolution,
71
36
  // which does not export them; drift is caught by that package's own tests.
72
37
  /** Default maximum idle interval while an adapter stream read is outstanding. */
@@ -146,7 +111,7 @@ function routeProvider(config, catalog, extras) {
146
111
  */
147
112
  export function buildOpenCodeGoProfile(config) {
148
113
  const catalog = catalogOpenCodeGo();
149
- const extras = resolveExtraModels(catalog.getModels(), [...DEFAULT_EXTRA_MODELS, ...(config.extraModels ?? [])]);
114
+ const extras = resolveExtraModels(catalog.getModels(), [...DEFAULT_EXTRA_MODELS, ...(config.extraModels ?? [])], DEFAULT_EXTRA_MODEL_TEMPLATE);
150
115
  return {
151
116
  provider: config.provider,
152
117
  displayName: config.displayName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagmans/dsh-provider-extra",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Extra LLM provider routes for DeepSeek Harness: OpenCode Go with per-session x-opencode-session routing, and OpenAI Codex over ChatGPT-subscription OAuth.",
5
5
  "keywords": [
6
6
  "deepseek-harness",