openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
52 lines (51 loc) • 2.48 kB
JavaScript
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs";
import { t as resolveRuntimeCliBackends } from "./cli-backends.runtime.js";
import { a as resolveAuthProfileOrder } from "./order-jOvee2J6.mjs";
import { c as resolveCliRuntimeExecutionProvider } from "./model-runtime-aliases-DZy9Ea2c.mjs";
import { i as ensureAuthProfileStoreAsync, r as ensureAuthProfileStore } from "./store-runtime-dW0pXLJI.mjs";
import { a as resolveModelAuthMode } from "./model-auth-CEsyk_Yg.mjs";
//#region src/agents/embedded-agent-runner/cli-backend-dispatch-eligibility.ts
function resolveDispatchProvider(e) {
const t = new Map(resolveRuntimeCliBackends("metadata").map((e) => [normalizeProviderId(e.id), e]));
const n = normalizeProviderId(e.provider ?? "");
const r = t.has(n) ? n : normalizeProviderId(resolveCliRuntimeExecutionProvider({
provider: e.provider ?? "",
cfg: e.config,
agentId: e.agentId,
modelId: e.model,
authProfileId: e.authProfileId,
preparedAuthStore: e.preparedAuthStore
}) ?? "");
return t.get(r)?.subscriptionAuthDispatch ? r : void 0;
}
function canDispatchWithAuthStore(e, t, n) {
const r = e.authProfileId ? n.profiles[e.authProfileId.trim()]?.type : void 0;
const [i] = resolveAuthProfileOrder({
cfg: e.config,
store: n,
provider: t
});
const a = r ?? (i ? n.profiles[i]?.type : void 0);
const o = a === "api_key" ? "api-key" : a === "oauth" || a === "token" ? a : resolveModelAuthMode(t, e.config, n, { workspaceDir: e.workspaceDir });
return o !== "api-key" && o !== "mixed" && o !== "aws-sdk";
}
/** @deprecated Use resolveEmbeddedCliBackendDispatchEligibilityAsync for worker-owned reads. */
function resolveEmbeddedCliBackendDispatchEligibility(e) {
const t = resolveDispatchProvider(e);
if (!t) return;
try {
if (!canDispatchWithAuthStore(e, t, e.preparedAuthStore ?? ensureAuthProfileStore(e.agentDir, { config: e.config }))) return;
} catch {}
return { provider: t };
}
/** Reads credential metadata through its worker without materializing or refreshing secrets. */
async function resolveEmbeddedCliBackendDispatchEligibilityAsync(e) {
const t = resolveDispatchProvider(e);
if (!t) return;
try {
if (!canDispatchWithAuthStore(e, t, e.preparedAuthStore ?? await ensureAuthProfileStoreAsync(e.agentDir, { config: e.config }))) return;
} catch {}
return { provider: t };
}
//#endregion
export { resolveEmbeddedCliBackendDispatchEligibilityAsync as n, resolveEmbeddedCliBackendDispatchEligibility as t };