File size: 1,940 Bytes
4c76b0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Inject store operations to avoid importing loader-backed auth facades during registration.
import { resolveAuthProfileOrder } from "../../agents/auth-profiles/order.js";
import { listProfilesForProvider } from "../../agents/auth-profiles/profile-list.js";
import { resolveProviderIdForAuth } from "../../agents/provider-auth-aliases.js";
import { createLazyRuntimeMethod, createLazyRuntimeModule } from "../../shared/lazy-runtime.js";
import type { PluginRuntime } from "./types.js";

const loadModelAuthRuntime = createLazyRuntimeModule(
  () => import("./runtime-model-auth.runtime.js"),
);

export function createRuntimeModelAuth({
  ensureAuthProfileStore,
  isProviderApiKeyConfigured,
}: Pick<
  PluginRuntime["modelAuth"],
  "ensureAuthProfileStore" | "isProviderApiKeyConfigured"
>): PluginRuntime["modelAuth"] {
  const getApiKeyForModel = createLazyRuntimeMethod(
    loadModelAuthRuntime,
    (runtime) => runtime.getApiKeyForModel,
  );
  const getRuntimeAuthForModel = createLazyRuntimeMethod(
    loadModelAuthRuntime,
    (runtime) => runtime.getRuntimeAuthForModelCore,
  );
  const resolveApiKeyForProvider = createLazyRuntimeMethod(
    loadModelAuthRuntime,
    (runtime) => runtime.resolveProviderRuntimeApiKey,
  );
  return {
    resolveProviderIdForAuth,
    ensureAuthProfileStore,
    resolveAuthProfileOrder,
    listProfilesForProvider,
    isProviderApiKeyConfigured,
    getApiKeyForModel: (params) =>
      getApiKeyForModel({
        model: params.model,
        cfg: params.cfg,
        workspaceDir: params.workspaceDir,
      }),
    getRuntimeAuthForModel: (params) =>
      getRuntimeAuthForModel({
        model: params.model,
        cfg: params.cfg,
        workspaceDir: params.workspaceDir,
      }),
    resolveApiKeyForProvider: (params) =>
      resolveApiKeyForProvider({
        provider: params.provider,
        cfg: params.cfg,
        workspaceDir: params.workspaceDir,
      }),
  };
}