openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 2.3 kB
JavaScript
import { o as listAgentIds } from "../agent-scope-config-DcbEhP0R.js";
import { b as replaceRuntimeAuthProfileStoreSnapshots } from "../runtime-snapshots-CHAErv1O.js";
import { V as restorePreparedSyntheticAuthFacts } from "../provider-runtime-BRJDPNgk.js";
import { r as serveWorkerTasks } from "../worker-task-pool-BNbf5LmH.js";
import "../auth-profiles-BdUEhE7u.js";
import { t as buildCurrentProviderAuthStateSnapshot } from "../model-provider-auth-jVhbzrw7.js";
//#region src/agents/model-provider-auth.worker.ts
/**
* Worker entrypoint for warming provider auth state off the main thread.
*/
function isWorkerInput(value) {
if (!value || typeof value !== "object") return false;
const record = value;
return "cfg" in record && Array.isArray(record.syntheticAuth) && (!("runtimeAuthStores" in record) || Array.isArray(record.runtimeAuthStores)) && (!("runtimeAuthLookups" in record) || Array.isArray(record.runtimeAuthLookups)) && (!("omitFalseProviderAuth" in record) || typeof record.omitFalseProviderAuth === "boolean");
}
/** Validates worker input and returns a provider auth snapshot or a serializable failure. */
async function runProviderAuthWarmWorkerInput(input) {
if (!isWorkerInput(input)) return {
status: "failed",
error: "invalid provider auth warm worker input"
};
try {
const syntheticAuth = new Map(input.syntheticAuth.map((scope) => [scope.agentId, scope]));
for (const agentId of listAgentIds(input.cfg)) {
const scope = syntheticAuth.get(agentId);
if (!scope) throw new Error(`Prepared synthetic auth scope is missing for ${agentId}`);
restorePreparedSyntheticAuthFacts(input.cfg, scope.facts, { workspaceDir: scope.workspaceDir });
}
if (input.runtimeAuthStores?.length) replaceRuntimeAuthProfileStoreSnapshots(input.runtimeAuthStores);
return {
status: "ok",
snapshot: await buildCurrentProviderAuthStateSnapshot(input.cfg, {
readOnlyAuthStore: true,
runtimeAuthLookups: new Map(input.runtimeAuthLookups?.map(({ agentId, lookup }) => [agentId, lookup])),
syntheticAuth,
omitFalseProviderAuth: input.omitFalseProviderAuth
})
};
} catch (error) {
return {
status: "failed",
error: String(error)
};
}
}
serveWorkerTasks(runProviderAuthWarmWorkerInput);
//#endregion
export { runProviderAuthWarmWorkerInput };