openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
77 lines (76 loc) • 4.7 kB
JavaScript
import { r as getSkillsSnapshotVersion } from "./refresh-state-C65GsLnU.mjs";
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs";
import "./session-key-CqAyZeVk.mjs";
import { i as listAgentIds, m as withAgentRosterFactsBatch } from "./agent-roster-t1ooUdXp.mjs";
import { f as resolveAgentWorkspaceDir } from "./agent-scope-config-DmXgFGKP.mjs";
import { C as resolveRuntimeModelConfigCacheKey } from "./runtime-snapshot-WbwbY5b7.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import { d as getActivePluginRegistryVersion } from "./runtime-ezCEpumg.mjs";
import { C as readAgentDatabaseReadAdmissionRefusal } from "./agent-database-admission-CL6wHJ_N.mjs";
import { l as getRuntimeAuthProfileStoreMetadataRevision, s as getRuntimeAuthProfileStoreCatalogRevision } from "./runtime-snapshots-1lyYKb7Y.mjs";
import { a as getPreparedModelFullCatalogAuth } from "./prepared-model-runtime-auth-DVZroiat.mjs";
import { a as getPreparedRuntimeAuthProfileStoreSnapshot } from "./store-Bh2lUvOT.mjs";
import { t as PreparedModelRuntimeOwnerNotPublishedError } from "./prepared-model-runtime-admission-errors-LxrcCg4d.mjs";
import { E as withPreparedModelRuntimeReadBatch } from "./prepared-model-runtime-Bbo9uBdt.mjs";
import "./prepared-model-runtime.errors-BRsU9-dm.mjs";
import { r as getPublishedPreparedModelCatalogOwnerSnapshot } from "./prepared-model-catalog-DSktrHGK.mjs";
import "./auth-profiles-VRLhewIH.mjs";
//#region src/gateway/server-methods/chat-metadata-facts.ts
var ChatMetadataStartingError = class extends PreparedModelRuntimeOwnerNotPublishedError {};
var ChatMetadataSnapshotUnavailableError = class extends Error {
constructor(e = "prepared chat metadata snapshot is unavailable") {
super(e);
this.name = "ChatMetadataSnapshotUnavailableError";
}
};
function assertPreparedAgentCurrent(e) {
if (!e.owner.isCurrent()) throw new ChatMetadataSnapshotUnavailableError(`prepared chat metadata owner retired for agent "${e.agentId}"`);
}
function authStoresCurrent(e) {
let t;
return e.agents.every(({ owner: e, authStoreRevision: n }) => n === `${getRuntimeAuthProfileStoreMetadataRevision(e.agentDir)}:${e.inheritedAuthDir ? getRuntimeAuthProfileStoreMetadataRevision(e.inheritedAuthDir) : t ??= getRuntimeAuthProfileStoreMetadataRevision()}`);
}
function captureGenerationFacts(e) {
const t = withPreparedModelRuntimeReadBatch(() => withAgentRosterFactsBatch(e, () => listAgentIds(e).filter((e) => !readAgentDatabaseReadAdmissionRefusal(e)).flatMap((t) => {
const n = normalizeAgentId(t);
const r = getPublishedPreparedModelCatalogOwnerSnapshot({
agentId: n,
config: e
});
if (!r) return [];
const i = r.workspaceDir ?? resolveAgentWorkspaceDir(e, n);
const a = r.readFullModelCatalog?.();
const o = a ? getPreparedModelFullCatalogAuth(a) : void 0;
if (a && !o) throw new Error("prepared full model catalog omitted its auth generation");
const s = a ?? r.modelCatalog;
return [{
agentId: n,
owner: r,
authStore: o?.authStore ?? getPreparedRuntimeAuthProfileStoreSnapshot(r.agentDir, r.inheritedAuthDir) ?? {
version: 1,
profiles: {}
},
authModes: o?.authModes ?? r.authModes,
authStoreRevision: `${getRuntimeAuthProfileStoreMetadataRevision(r.agentDir)}:${getRuntimeAuthProfileStoreMetadataRevision(r.inheritedAuthDir)}`,
authCatalogRevision: `${getRuntimeAuthProfileStoreCatalogRevision(r.agentDir)}:${getRuntimeAuthProfileStoreCatalogRevision(r.inheritedAuthDir)}`,
modelCatalog: s,
catalogRefreshFailed: s.refreshFailed === true,
skillsVersion: getSkillsSnapshotVersion(i)
}];
})));
return {
config: e,
configKey: resolveRuntimeModelConfigCacheKey(e),
pluginRegistryVersion: getActivePluginRegistryVersion(),
agents: t
};
}
function generationFactsMatch(e, t, n = "metadata") {
if (e.configKey !== t.configKey || e.pluginRegistryVersion !== t.pluginRegistryVersion || e.agents.length !== t.agents.length) return false;
return e.agents.every((e, r) => {
const i = t.agents[r];
return i?.agentId === e.agentId && (n === "commands" ? i.skillsVersion === e.skillsVersion && i.owner.workspaceDir === e.owner.workspaceDir : i.owner.isCurrent === e.owner.isCurrent && (n === "catalog-notification" ? i.authCatalogRevision === e.authCatalogRevision : i.authStoreRevision === e.authStoreRevision) && i.modelCatalog === e.modelCatalog && (n === "auth" || i.catalogRefreshFailed === e.catalogRefreshFailed) && (n !== "metadata" || i.skillsVersion === e.skillsVersion));
});
}
//#endregion
export { captureGenerationFacts as a, authStoresCurrent as i, ChatMetadataStartingError as n, generationFactsMatch as o, assertPreparedAgentCurrent as r, ChatMetadataSnapshotUnavailableError as t };