omp-multi-auth 1.4.0 → 1.4.1

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
@@ -119,6 +119,20 @@ OpenCode Go reports 5-hour, weekly, and monthly windows. The status line and rea
119
119
  | Global | `~/.omp/agent/multi-auth.json` | Subscriptions and presets |
120
120
  | Project | `.omp/multi-auth.json` | `allowedSubs` allow-list |
121
121
 
122
+ ### Proxy or gateway endpoints
123
+
124
+ An added account takes the `baseUrl` and `headers` that `~/.omp/agent/models.yml` sets for its base provider, so its requests go through the same gateway as the base account. omp-multi-auth reads `models.yaml` instead only when `models.yml` does not exist, as omp does; it never merges the two files, and `models.json` is not read. Each account still signs in with its own credential. Without a `baseUrl`, an account keeps the provider's built-in endpoints, so a provider with several API dialects (OpenCode Go) still uses the right URL for each model. A `baseUrl` replaces the endpoint for every model of that provider, and for GitHub Copilot accounts it replaces the endpoint derived from the sign-in token.
125
+
126
+ ```yaml
127
+ providers:
128
+ anthropic:
129
+ baseUrl: http://127.0.0.1:8080/anthropic
130
+ headers:
131
+ x-proxy-key: example
132
+ ```
133
+
134
+ With this file, `anthropic-2` and `anthropic-3` send their requests to `http://127.0.0.1:8080/anthropic` with `x-proxy-key` too. Codex accounts (`openai-codex-N`) are not covered yet. omp reads the file when it starts, so restart omp after you change it.
135
+
122
136
  ## Credits
123
137
 
124
138
  Originally based on [`pi-multi-pass`](https://github.com/hjanuschka/pi-multi-pass).
@@ -1,7 +1,10 @@
1
1
  // ========================================================================
2
2
  // Provider templates
3
3
  // ========================================================================
4
- import type { ExtensionAPI, ProviderConfig, ProviderModelConfig } from "@oh-my-pi/pi-coding-agent";
4
+ import { YAML } from "bun";
5
+ import { existsSync, readFileSync } from "fs";
6
+ import { join } from "path";
7
+ import { getAgentDir, type ExtensionAPI, type ProviderConfig, type ProviderModelConfig } from "@oh-my-pi/pi-coding-agent";
5
8
  import { getProviderDefinition } from "@oh-my-pi/pi-ai/registry";
6
9
  import type { OAuthCredentials, OAuthLoginCallbacks } from "@oh-my-pi/pi-ai/oauth";
7
10
  import { AssistantMessageEventStream, streamSimple, type Api, type AssistantMessageEvent, type Context, type Model, type SimpleStreamOptions } from "@oh-my-pi/pi-ai";
@@ -249,12 +252,25 @@ export function restoreSubscriptionProvider(event: AssistantMessageEvent, provid
249
252
  return { ...event, partial: { ...event.partial, provider } };
250
253
  }
251
254
 
252
- export function createSubscriptionStream(canonicalProvider: string, builtinApi: Api | ((modelId: string) => Api)): SubscriptionStream {
255
+ export function createSubscriptionStream(
256
+ canonicalProvider: string,
257
+ builtinApi: Api | ((modelId: string) => Api),
258
+ baseUrl?: string,
259
+ ): SubscriptionStream {
253
260
  return (model, context, options) => {
254
261
  const internalApi = typeof builtinApi === "function" ? builtinApi(model.id) : builtinApi;
255
262
  const baseModel = getModels(canonicalProvider).find(candidate => candidate.id === model.id);
256
263
  if (!baseModel) throw new Error(`Missing bundled model ${canonicalProvider}/${model.id}`);
257
- const internalModel = { ...baseModel, api: internalApi, provider: canonicalProvider } as Model<Api>;
264
+ // The host resolves model.resolveHeaders into model.headers before dispatching here, so the clone's
265
+ // headers must ride along. Without an explicit baseUrl keep the catalog's per-model URL (mixed dialects).
266
+ const internalModel = {
267
+ ...baseModel,
268
+ api: internalApi,
269
+ provider: canonicalProvider,
270
+ baseUrl: baseUrl ?? baseModel.baseUrl,
271
+ headers: model.headers ?? baseModel.headers,
272
+ resolveHeaders: model.resolveHeaders,
273
+ } as Model<Api>;
258
274
  const internalOptions: SimpleStreamOptions = {
259
275
  ...(options ?? {}),
260
276
  headers: options?.headers,
@@ -286,9 +302,10 @@ export function createSubscriptionStream(canonicalProvider: string, builtinApi:
286
302
  };
287
303
  }
288
304
  export const SUBSCRIPTION_STREAMS: Record<string, SubscriptionStream> = {};
289
- export function getSubscriptionStream(baseProvider: string): SubscriptionStream | undefined {
305
+ export function getSubscriptionStream(baseProvider: string, baseUrl?: string): SubscriptionStream | undefined {
290
306
  const config = SUB_TRANSPORT_CONFIG[baseProvider];
291
307
  if (!config) return undefined;
308
+ if (baseUrl) return createSubscriptionStream(baseProvider, config.builtinApi, baseUrl);
292
309
  let stream = SUBSCRIPTION_STREAMS[baseProvider];
293
310
  if (!stream) {
294
311
  stream = createSubscriptionStream(baseProvider, config.builtinApi);
@@ -487,6 +504,27 @@ function registerCodexSub(pi: ExtensionAPI, name: string, index: number, oauth:
487
504
  });
488
505
  }
489
506
 
507
+ // An account takes the endpoint its base provider is configured with in
508
+ // models.yml (a gateway or proxy baseUrl and its headers), because
509
+ // models.yml overrides are keyed by provider id and never reach the
510
+ // `<provider>-N` ids registered here. Credentials stay the account's own.
511
+ function baseProviderTransport(provider: string): { baseUrl?: string; headers?: Record<string, string> } {
512
+ let parsed: { providers?: Record<string, { baseUrl?: unknown; headers?: unknown }> } | null;
513
+ // Same lookup as the host: models.yaml is read only when models.yml is absent.
514
+ const yml = join(getAgentDir(), "models.yml");
515
+ try {
516
+ parsed = YAML.parse(readFileSync(existsSync(yml) ? yml : join(getAgentDir(), "models.yaml"), "utf8")) as typeof parsed;
517
+ } catch {
518
+ return {};
519
+ }
520
+ const override = parsed?.providers?.[provider];
521
+ const headers = override?.headers;
522
+ return {
523
+ baseUrl: typeof override?.baseUrl === "string" ? override.baseUrl : undefined,
524
+ headers: headers && typeof headers === "object" ? { ...(headers as Record<string, string>) } : undefined,
525
+ };
526
+ }
527
+
490
528
  export function registerSub(pi: ExtensionAPI, entry: SubEntry): void {
491
529
  const template = PROVIDER_TEMPLATES[entry.provider];
492
530
  if (!template) return;
@@ -496,17 +534,20 @@ export function registerSub(pi: ExtensionAPI, entry: SubEntry): void {
496
534
  registerCodexSub(pi, name, entry.index, oauth);
497
535
  return;
498
536
  }
499
- const modifyModels = template.buildModifyModels?.(name);
537
+ const transport = baseProviderTransport(entry.provider);
538
+ // An explicit baseUrl wins over the token-derived Copilot endpoint.
539
+ const modifyModels = transport.baseUrl ? undefined : template.buildModifyModels?.(name);
500
540
 
501
541
  const builtinModels = getModels(entry.provider);
502
542
  const transportApi = SUB_TRANSPORT_CONFIG[entry.provider]?.customApiId;
503
- const streamSimple = getSubscriptionStream(entry.provider);
504
- const baseUrl = builtinModels[0]?.baseUrl || "";
543
+ const streamSimple = getSubscriptionStream(entry.provider, transport.baseUrl);
544
+ const baseUrl = transport.baseUrl ?? (builtinModels[0]?.baseUrl || "");
505
545
  const models = cloneModels(entry.provider, entry.index);
506
546
 
507
547
  // Static `models` provide startup catalog for this subscription.
508
548
  pi.registerProvider(name, {
509
549
  baseUrl,
550
+ headers: transport.headers,
510
551
  api: transportApi ?? builtinModels[0]?.api,
511
552
  streamSimple,
512
553
  oauth: oauth && modifyModels ? { ...oauth, modifyModels } : oauth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-multi-auth",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "description": "Multi-account OAuth login for omp (Oh My Pi) -- add and manage multiple accounts per provider from one place.",
6
6
  "keywords": [