@sagmans/dsh-provider-extra 0.6.0 → 0.7.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
@@ -162,6 +162,45 @@ Routes without models or codexModels continue to read extraModels or codexExtraM
162
162
 
163
163
  `codexTransport` pins the transport pi-ai uses for this route: `sse`, `websocket`, `websocket-cached`, or `auto`. Leave it out and pi-ai chooses, which on a network that never lets the subscription's websocket continue past the first answer leaves the reply printed and the process waiting; pin `sse` there.
164
164
 
165
+ ## Service tiers
166
+
167
+ Codex routes expose service tier selection through the `providerServiceTiers` service.
168
+ Choices are `auto`, `default`, and `priority` (Fast).
169
+ Priority processing can increase usage cost and requires account access.
170
+ The plugin does not offer `ultrafast` or `flex` for Codex.
171
+
172
+ Selections apply to one provider and model pair.
173
+ The owning profile Config stores them in `serviceTierSelections`:
174
+
175
+ ```yaml
176
+ - id: dsh-provider-extra
177
+ config:
178
+ serviceTierSelections:
179
+ - provider: openai-codex
180
+ model: gpt-5.6-luna
181
+ tier: priority
182
+ ```
183
+
184
+ The selection reaches both stream entry points without changing OAuth or transport.
185
+ Managed catalog aliases with the Codex protocol also support selection.
186
+ Other providers and routes owned by another adapter do not advertise tiers.
187
+
188
+ In dsh-tui, confirm an effort to open the tier picker.
189
+ The plugin registers `prefix+t` through the optional `tuiKeymaps` registry.
190
+ The TUI owns generic key dispatch, not this binding or its behavior.
191
+ Use `prefix+t` to open the tier picker independently.
192
+ Rebind `keys.plugin.provider-extra.serviceTier` on the owning TUI row.
193
+ On Config-backed profiles, put `keys` directly under that row's `config`, not under `settings`.
194
+ Keep `sessionId` and the other launch fields when editing the row.
195
+ Removing this provider plugin removes its shortcut and effort follow-up.
196
+ Choose **provider default** to remove the explicit tier.
197
+ Cancelling the tier picker does not change the confirmed effort.
198
+ A failed profile write leaves the previous tier unchanged.
199
+ With footer-hint support, explicit Auto and Fast appear beside effort, for example `(high · Fast)`.
200
+ Standard and provider-default selections stay hidden.
201
+ Provider default clears this plugin's override; it does not add `service_tier` to normal requests.
202
+ Existing caller options and payload hooks remain unchanged.
203
+
165
204
  ## Provider sign-in
166
205
 
167
206
  Sign in from the profile you are already using. The plugin registers a command in the harness command palette.
@@ -3,6 +3,7 @@ import { LlmError, assertUsableApiKey, resolveImageAttachmentAccess } from '@dee
3
3
  import { codexAuth } from "./codex.js";
4
4
  import { catalogDefault } from "./catalog-default.js";
5
5
  import { mountLoginCommand } from "./login-host.js";
6
+ import { mountServiceTiers, withServiceTiers } from "./service-tiers.js";
6
7
  const PLUGIN_NAME = 'dsh-provider-extra';
7
8
  const OWNER_COLLISION = 'CATALOG_OWNER_COLLISION';
8
9
  /** Preflight prevents even an unrelated competing row from expanding managed membership. */
@@ -27,8 +28,9 @@ export function mountCatalog(ctx, snapshot, config) {
27
28
  const configured = snapshot.providers.get(route)?.auth;
28
29
  return configured !== undefined && 'credentialProvider' in configured ? configured.credentialProvider : route;
29
30
  };
31
+ const tiers = mountServiceTiers(ctx, config, () => { requireOwnership(); return snapshot.profiles; });
30
32
  const adapter = new PiAiAdapter({
31
- profiles: () => { requireOwnership(); return snapshot.profiles; },
33
+ profiles: () => { requireOwnership(); return withServiceTiers(snapshot.profiles, tiers.current); },
32
34
  auth: {
33
35
  ...auth,
34
36
  // Route aliases must share the source provider's existing OAuth grant.
@@ -121,7 +123,12 @@ export function mountCatalog(ctx, snapshot, config) {
121
123
  refreshOwnership();
122
124
  // A public update veto runs before disposal, so a competing late-mounted
123
125
  // adapter cannot turn a refused reload into loss of the last valid catalog.
126
+ let activeGeneration = true;
127
+ ctx.effect(() => () => { activeGeneration = false; });
124
128
  ctx.on('internal/update', (next, _noSave, proceed) => {
129
+ // A retired snapshot must not veto replacement of the current catalog owner.
130
+ if (!activeGeneration)
131
+ return proceed();
125
132
  if (next.catalog !== undefined)
126
133
  assertCatalogOwnership(ctx, routes, defaults);
127
134
  return proceed();
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ import { DEFAULT_LOGIN_COMMAND_NAME } from "./login-command.js";
38
38
  import { mountLoginCommand } from "./login-host.js";
39
39
  import { compileCatalog } from "./catalog.js";
40
40
  import { mountCatalog } from "./catalog-runtime.js";
41
+ import { mountServiceTiers, withServiceTiers, SERVICE_TIER_CHOICES } from "./service-tiers.js";
41
42
  export { compileCatalog } from "./catalog.js";
42
43
  export { buildCatalogProfile } from "./catalog-routes.js";
43
44
  /** Settings namespace configuration surfaces address this plugin's section by. */
@@ -67,6 +68,12 @@ const codexExtraModelSchema = Schema.object({
67
68
  export const Config = Schema.transform(Schema.object({
68
69
  // Keep raw catalog presence: schemastery otherwise materializes absent arrays.
69
70
  catalog: Schema.any(),
71
+ // The validated Config transform owns this array; profile edits reconcile it atomically.
72
+ serviceTierSelections: Schema.array(Schema.object({
73
+ provider: Schema.string().required(),
74
+ model: Schema.string().required(),
75
+ tier: Schema.union(SERVICE_TIER_CHOICES.map(choice => choice.id)).required(),
76
+ })).default([]),
70
77
  apiKeyEnv: Schema.string().role('credential-ref').default(DEFAULT_OPENCODE_API_KEY_ENV),
71
78
  routeId: Schema.string().default(OPENCODE_GO_PROVIDER_ID),
72
79
  displayName: Schema.string().default('OpenCode Go'),
@@ -183,8 +190,10 @@ export function apply(ctx, config) {
183
190
  }
184
191
  return new Map(entries);
185
192
  };
193
+ const servedProviders = new Set();
194
+ const tiers = mountServiceTiers(ctx, config, () => new Map([...profiles()].filter(([provider]) => servedProviders.has(provider))));
186
195
  const adapter = new PiAiAdapter({
187
- profiles,
196
+ profiles: () => withServiceTiers(profiles(), tiers.current),
188
197
  resolveApiKey: async (provider) => {
189
198
  // The Codex route authenticates from the stored OAuth grant, never
190
199
  // from a key: absent here is what lets the collection store serve it.
@@ -225,6 +234,7 @@ export function apply(ctx, config) {
225
234
  // remediation and every other plugin keeps working.
226
235
  try {
227
236
  ctx.llm.registerAdapter([route.provider], adapter);
237
+ servedProviders.add(route.provider);
228
238
  }
229
239
  catch (error) {
230
240
  ctx.logger.error('dsh-provider-extra: route "' + route.provider + '" was refused;'
@@ -239,6 +249,7 @@ export function apply(ctx, config) {
239
249
  if (codexServable) {
240
250
  try {
241
251
  ctx.llm.registerAdapter([codex.provider], adapter);
252
+ servedProviders.add(codex.provider);
242
253
  }
243
254
  catch (error) {
244
255
  ctx.logger.warn('dsh-provider-extra: codex route "' + codex.provider + '" stays with its existing owner;'
@@ -0,0 +1,88 @@
1
+ import { mountTierActions } from "./tui-actions.js";
2
+ /** Protocol identity protects ordinary OpenAI API routes from subscription-only policy. */
3
+ export const CODEX_TIER_API = 'openai-codex-responses';
4
+ /** Limit paid policies to choices the Codex request transport recognizes. */
5
+ export const SERVICE_TIER_CHOICES = [
6
+ { id: 'auto', name: 'Auto', description: 'Use the account service tier' },
7
+ { id: 'default', name: 'Standard', description: 'Standard processing' },
8
+ { id: 'priority', name: 'Fast', description: 'Priority processing; higher usage cost, subject to account access' },
9
+ ];
10
+ const SERVICE_TIER_FIELD = 'serviceTierSelections';
11
+ const SERVICE_NAME = 'providerServiceTiers';
12
+ const EDITOR_SERVICE = 'configEditor';
13
+ const WRITE_UNSUPPORTED = 'service tier could not be saved; writable provider settings are required';
14
+ const INVALID_TIER = 'unsupported service tier for this model route';
15
+ const INVALID_PAYLOAD = 'Codex service tier requires an object request payload';
16
+ /** Reject stale or hand-edited values before they become request parameters. */
17
+ function validTier(tier) {
18
+ return SERVICE_TIER_CHOICES.some(choice => choice.id === tier);
19
+ }
20
+ /** Durable writes complete before the selected row can truthfully report success. */
21
+ export function createTierSelection(read, write, profiles) {
22
+ const choices = (provider, model) => profiles().get(provider)?.piProvider?.getModels().some(entry => entry.id === model && entry.api === CODEX_TIER_API)
23
+ ? SERVICE_TIER_CHOICES : [];
24
+ return {
25
+ choices,
26
+ current: (provider, model) => {
27
+ const tier = read().find(entry => entry.provider === provider && entry.model === model)?.tier;
28
+ return tier !== undefined && validTier(tier) ? tier : undefined;
29
+ },
30
+ select: async (provider, model, tier) => {
31
+ if (choices(provider, model).length === 0 || (tier !== undefined && !validTier(tier)))
32
+ throw new Error(INVALID_TIER);
33
+ await write(entries => {
34
+ const next = entries.filter(entry => entry.provider !== provider || entry.model !== model);
35
+ if (tier !== undefined)
36
+ next.push({ provider, model, tier });
37
+ return next;
38
+ });
39
+ },
40
+ };
41
+ }
42
+ /** Decorate only Codex streams so existing auth, routing, transport, and replay survive. */
43
+ export function withServiceTiers(profiles, current) {
44
+ return new Map([...profiles].map(([id, profile]) => {
45
+ const source = profile.piProvider;
46
+ if (source === undefined || !source.getModels().some(model => model.api === CODEX_TIER_API))
47
+ return [id, profile];
48
+ const optionsFor = (model, options) => {
49
+ const tier = current(id, model.id);
50
+ if (model.api !== CODEX_TIER_API || tier === undefined || options === undefined)
51
+ return options;
52
+ return { ...options, serviceTier: tier, onPayload: async (payload, wireModel) => {
53
+ // pi-ai's simple stream drops serviceTier, but retains this final serialization hook.
54
+ const replacement = await options?.onPayload?.(payload, wireModel);
55
+ const body = replacement === undefined ? payload : replacement;
56
+ if (typeof body !== 'object' || body === null || Array.isArray(body))
57
+ throw new Error(INVALID_PAYLOAD);
58
+ return { ...body, service_tier: tier };
59
+ } };
60
+ };
61
+ return [id, { ...profile, piProvider: {
62
+ ...source,
63
+ stream: (model, context, options) => source.stream(model, context, optionsFor(model, options)),
64
+ streamSimple: (model, context, options) => source.streamSimple(model, context, optionsFor(model, options)),
65
+ } }];
66
+ }));
67
+ }
68
+ /** The profile editor supplies locking, rollback, and canonical plugin reconciliation. */
69
+ export function mountServiceTiers(ctx, config, profiles) {
70
+ const entry = ctx.fiber.entry;
71
+ const service = createTierSelection(
72
+ // Retained calls keep their mounted policy until the editor reconciles a new owner.
73
+ () => config.serviceTierSelections ?? [], async (change) => {
74
+ const editor = ctx.get(EDITOR_SERVICE);
75
+ if (entry === undefined || typeof editor?.edit !== 'function')
76
+ throw new Error(WRITE_UNSUPPORTED);
77
+ await editor.edit(entry, (raw, inherited) => {
78
+ // Merge under the profile lock so another model's simultaneous choice survives.
79
+ const previous = (raw[SERVICE_TIER_FIELD] ?? inherited[SERVICE_TIER_FIELD] ?? []);
80
+ if (!Array.isArray(previous))
81
+ throw new Error(WRITE_UNSUPPORTED);
82
+ return { ...raw, [SERVICE_TIER_FIELD]: change(previous) };
83
+ });
84
+ }, profiles);
85
+ ctx.provide(SERVICE_NAME, service);
86
+ mountTierActions(ctx, service);
87
+ return service;
88
+ }
@@ -0,0 +1,69 @@
1
+ const REGISTRY = 'tuiKeymaps';
2
+ export const TIER_ACTION_ID = 'plugin.provider-extra.serviceTier';
3
+ const TIER_KEY = 't';
4
+ const TIER_LABEL = 'service tier';
5
+ const PROVIDER_DEFAULT = '';
6
+ /** Ordinary processing stays quiet; only account-auto and expedited choices qualify the route. */
7
+ const FOOTER_TIERS = new Set(['auto', 'priority']);
8
+ const SAVE_FAILURE = 'could not save service tier; check writable provider settings and retry';
9
+ const DISCOVERY_FAILURE = 'could not read service tiers; check provider configuration and retry';
10
+ const NO_ROUTE = 'no model route is in use; choose a model first';
11
+ const UNSUPPORTED = 'this model route advertises no service tiers';
12
+ /** The captured owner lasts exactly as long as its scoped registration, including Config reconciliation. */
13
+ export function createTierPicker(tiers) {
14
+ let opening = false;
15
+ return async (ports, quiet = false) => {
16
+ if (opening)
17
+ return;
18
+ opening = true;
19
+ let saving = false;
20
+ try {
21
+ const route = ports.route;
22
+ if (route === undefined) {
23
+ if (!quiet)
24
+ ports.notice(NO_ROUTE);
25
+ return;
26
+ }
27
+ const choices = tiers.choices(route.provider, route.model);
28
+ if (choices.length === 0) {
29
+ if (!quiet)
30
+ ports.notice(UNSUPPORTED);
31
+ return;
32
+ }
33
+ const current = tiers.current(route.provider, route.model);
34
+ const rows = [
35
+ { id: PROVIDER_DEFAULT, name: 'provider default', description: 'clear the explicit service tier', current: current === undefined },
36
+ ...choices.map(choice => ({ ...choice, current: choice.id === current })),
37
+ ];
38
+ const picked = await ports.pick({ title: TIER_LABEL + ' · ' + route.provider + '/' + route.model, rows });
39
+ if (picked === undefined)
40
+ return;
41
+ if (!rows.some(row => row.id === picked))
42
+ throw new Error(DISCOVERY_FAILURE);
43
+ saving = true;
44
+ await tiers.select(route.provider, route.model, picked === PROVIDER_DEFAULT ? undefined : picked);
45
+ ports.notice(TIER_LABEL + ' set to ' + (picked === PROVIDER_DEFAULT ? 'provider default' : picked) + ' for the next request');
46
+ }
47
+ catch {
48
+ ports.notice(saving ? SAVE_FAILURE : DISCOVERY_FAILURE);
49
+ }
50
+ finally {
51
+ opening = false;
52
+ }
53
+ };
54
+ }
55
+ /** Optional injection leaves console and web profiles independent of the terminal bundle. */
56
+ export function mountTierActions(ctx, tiers) {
57
+ ctx.inject([REGISTRY], owner => {
58
+ const registry = owner.get(REGISTRY);
59
+ const choose = createTierPicker(tiers);
60
+ registry.register(owner, { id: TIER_ACTION_ID, layer: 'chord', defaultKeys: [TIER_KEY], label: TIER_LABEL,
61
+ handler: ports => choose(ports),
62
+ routeHint: route => {
63
+ const tier = tiers.current(route.provider, route.model);
64
+ return FOOTER_TIERS.has(tier ?? PROVIDER_DEFAULT)
65
+ ? tiers.choices(route.provider, route.model).find(choice => choice.id === tier)?.name : undefined;
66
+ } });
67
+ registry.afterEffort(owner, ports => choose(ports, true));
68
+ });
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagmans/dsh-provider-extra",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",