openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
195 lines (194 loc) • 7.37 kB
JavaScript
import { r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs";
import { t as AuthProfileAuthorizationError } from "./authorization-contract-CQ0hvliU.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import { d as isConfiguredKeyAuthSource } from "./provider-model-route-auth-dD2KD9io.mjs";
import { o as resolveProviderModelAuthPolicy } from "./model-runtime-policy-Cfudvy7O.mjs";
import { t as isCliProvider } from "./model-selection-cli-CkH04Wst.mjs";
import { c as resolveCliRuntimeExecutionProvider } from "./model-runtime-aliases-DZy9Ea2c.mjs";
import { i as resolveSessionRuntimeOverrideForProvider } from "./session-runtime-compat-C_CO9LR_.mjs";
import { o as resolveEffectiveAgentRuntime } from "./thinking-runtime-BKWl4CUs.mjs";
import { i as ensureAuthProfileStoreAsync } from "./store-runtime-dW0pXLJI.mjs";
import { r as resolveAgentHarnessSelectionDecision } from "./selection-decision-Bz5cp9Eg.mjs";
import { t as describeCronInferenceBinding } from "./inference-binding-WWjqX5o7.mjs";
import { n as cliBackendAcceptsAuthProfileForwarding, r as resolveCliExecutionAuthProfileId } from "./cli-execution-auth-iYQVEZdU.mjs";
import { n as resolveSessionAuthSelection } from "./session-override-D6B49GCj.mjs";
import { n as workerInferencePlacement } from "./inference-placement-DTrb-mxJ.mjs";
import { r as prepareAgentRuntimeAuth } from "./prepare-auth-Ck7RPVAG.mjs";
import { n as resolveCronModelSelectionOwner, t as resolveCronModelSelection } from "./model-selection-BZhMpZwE.mjs";
import { t as captureAuthProfileAuthorization } from "./authorization-BCfvcvWl.mjs";
import { t as resolveCronCandidateExecution } from "./candidate-execution-DXIQjDnC.mjs";
//#region src/cron/inference-binding.runtime.ts
/** Capture only a selected, current credential owner; never infer a legacy job's history. */
async function captureCronInferenceBinding(e) {
const t = await resolveCronModelSelectionOwner({
cfg: e.cfg,
agentId: e.agentId,
requiredAgentId: e.agentId
});
const { config: n, agentId: r, agentDir: i, workspaceDir: a } = t;
const o = await resolveCronModelSelection({
cfg: n,
owner: t,
agentConfigOverride: resolveAgentConfig(n, r),
agentId: r,
agentDir: i,
workspaceDir: a,
payloadModel: e.model,
sessionEntry: e.executionSessionEntry ?? {},
isGmailHook: e.isGmailHook === true
});
if (!o.ok) throw new Error(o.error);
const s = resolveCliRuntimeExecutionProvider({
cfg: n,
agentId: r,
provider: o.provider,
modelId: o.model,
authProfileId: o.configuredProfileId
});
const c = e.runtimeSessionEntry;
const { runtime: l } = resolveCronCandidateExecution({
cfg: n,
agentId: r,
provider: o.provider,
model: o.model,
sessionRuntimeOverride: resolveSessionRuntimeOverrideForProvider({
provider: o.provider,
entry: c,
cfg: n
}),
sessionEntry: c,
authProfileId: o.configuredProfileId
}, {
isCliProvider,
resolveEffectiveAgentRuntime
});
if (s && !cliBackendAcceptsAuthProfileForwarding({
provider: s,
config: n,
agentId: r
})) return;
const u = e.sessionEntry?.providerOverride ?? e.sessionEntry?.modelProvider;
const d = u && u !== o.provider ? void 0 : e.sessionEntry;
let f;
if (s) {
const e = o.configuredProfileId ?? d?.authProfileOverride;
const t = await resolveCliExecutionAuthProfileId({
cliExecutionProvider: s,
authProfileProvider: o.provider,
config: n,
agentDir: i,
selected: e ? {
authProfileId: e,
authProfileIdSource: o.configuredProfileId || d?.authProfileOverrideSource === "user" || d?.authProfileOverrideSource === "user-link" ? "user" : "auto"
} : void 0
});
if (!t) return;
f = {
profileId: t,
source: o.configuredProfileId ? "user" : "auto",
routeRequirement: void 0
};
} else f = await resolveSessionAuthSelection({
cfg: n,
agentId: r,
agentDir: i,
provider: o.provider,
modelId: o.model,
configuredProfileId: o.configuredProfileId ?? d?.authProfileOverride,
sessionEntry: o.configuredProfileId ? void 0 : d,
isNewSession: false
});
const p = n.cloudWorkers?.requiredProfile;
const m = p ? n.cloudWorkers?.profiles?.[p] : void 0;
if (!f && m && workerInferencePlacement({
providerId: m.provider,
profileSnapshot: m
}) === "worker") return;
const h = await ensureAuthProfileStoreAsync(i, {
profileId: f?.profileId,
allowKeychainPrompt: false,
config: n
});
if (!f) {
const e = resolveAgentHarnessSelectionDecision({
provider: o.provider,
modelId: o.model,
config: n,
agentId: r
});
const [t] = prepareAgentRuntimeAuth({
provider: o.provider,
modelId: o.model,
config: n,
agentId: r,
agentDir: i,
authProfileStore: h,
harnessId: e.selectedHarnessId,
harnessRuntime: e.selectedHarnessId,
harnessAuthBootstrap: e.harness?.authBootstrap
}).attempts;
if (t?.kind !== "profile") {
const e = t?.plan.credentialSource;
if (e?.kind === "direct" && !isConfiguredKeyAuthSource(e)) throw new Error("Automation requires a stored inference account or a key in the environment or provider config. Select an account with model@profile.");
return;
}
f = {
profileId: t.profileId,
source: t.plan.forwardedAuthProfileSource ?? "auto",
routeRequirement: t.plan.modelRoute?.authRequirement
};
}
const g = await e.authorizeProfile?.(f.profileId, !o.configuredProfileId && f.profileId === d?.authProfileOverride);
const _ = h.profiles[f.profileId];
if (!_) throw new Error("Automation requires an available stored inference account.");
const v = f.routeRequirement ?? resolveProviderModelAuthPolicy({
provider: o.provider,
mode: _.type,
authFlow: _.type === "oauth" ? _.authFlow : void 0
}).authRequirement;
if (!v) throw new Error("Automation requires a supported stored inference authentication route.");
const y = await captureAuthProfileAuthorization({
profileId: f.profileId,
agentDir: i,
cfg: n,
assertCurrent: g ?? (() => {})
});
let b = false;
try {
y.assertCurrent();
e.retainAuthorization?.(y);
b = e.retainAuthorization !== void 0;
return {
version: 1,
provider: o.provider,
profileId: f.profileId,
authorizationId: y.authorizationId,
authRequirement: v,
runtime: l,
source: o.configuredProfileId || d?.authProfileOverrideSource === "user" || d?.authProfileOverrideSource === "user-link" || !d?.authProfileOverride && f.source === "user" ? "user" : "auto"
};
} finally {
if (!b) y.dispose();
}
}
/** Reacquire the same owner, including its live revocation and replacement checks. */
async function acquireCronInferenceAuthorization(e) {
let t;
try {
t = await captureAuthProfileAuthorization({
profileId: e.binding.profileId,
agentDir: e.agentDir,
cfg: e.cfg,
assertCurrent() {}
});
if (t.authorizationId !== e.binding.authorizationId) throw new Error(`Automation inference ${describeCronInferenceBinding(e.binding)} was replaced. Explicitly select an authorized account again.`);
t.assertCurrent();
return t;
} catch (n) {
t?.dispose();
if (n instanceof AuthProfileAuthorizationError && n.code === "MCP_AUTHORIZATION_RETIRED") throw new Error(`Automation inference ${describeCronInferenceBinding(e.binding)} was removed or signed out. Explicitly select an authorized account again.`, { cause: n });
throw n;
}
}
//#endregion
export { captureCronInferenceBinding as n, acquireCronInferenceAuthorization as t };