mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-03 08:34:07 +00:00
* refactor(agents): prepare model runtime catalogs Build lifecycle-owned model and auth snapshots, carry prepared stores into hot agent paths, and serialize config/auth publication. Credits @zeroaltitude's #90741 investigation and benchmark approach. * refactor: finish lifecycle-owned model discovery * fix: align prepared model catalog contracts * test: align lifecycle catalog mocks * test: fix prepared catalog type fixtures * refactor: split prepared model runtime ownership * fix: import prepared runtime replacement gate type * test: split media runtime coverage * test: preserve image auth fixture key types * test: isolate lifecycle gate fixtures * chore: keep release changelog owned * refactor: finish prepared model catalog migration * test: keep catalog review fixtures scanner-safe * refactor: preserve lifecycle model runtime ownership * fix: close prepared runtime lifecycle races * fix: preserve compaction workspace fallback * chore: document btw generation rebinding * fix: preserve prepared generation boundaries * fix: keep model-list discovery flag explicit * fix: serialize standalone model runtime activation * refactor: migrate subagent model catalog lookup * refactor: clarify doctor catalog lookup seam * chore: refresh plugin sdk api baseline * test: migrate swarm catalog dependency * refactor(telegram): rename runtime catalog seam * refactor: extract model-aware tool context * test(models): isolate lifecycle catalog fixtures * refactor(agents): avoid btw parameter rebinding * fix(net-policy): align root ipaddr dependency * fix(build): keep net policy dependency bundled * fix(deadcode): document net policy compile dependency
81 lines
2.8 KiB
TypeScript
81 lines
2.8 KiB
TypeScript
/** Resolves synthetic and external auth provider refs from active runtime state or persisted manifests. */
|
|
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
|
|
import { loadPluginRegistrySnapshotWithMetadata } from "./plugin-registry.js";
|
|
import type { LoadPluginRegistryParams, PluginRegistrySnapshot } from "./plugin-registry.js";
|
|
import { getPluginRegistryState } from "./runtime-state.js";
|
|
|
|
function uniqueProviderRefs(values: readonly string[]): string[] {
|
|
const seen = new Set<string>();
|
|
const next: string[] = [];
|
|
for (const raw of values) {
|
|
const trimmed = raw.trim();
|
|
const normalized = normalizeProviderId(trimmed);
|
|
if (!trimmed || seen.has(normalized)) {
|
|
continue;
|
|
}
|
|
seen.add(normalized);
|
|
next.push(trimmed);
|
|
}
|
|
return next;
|
|
}
|
|
|
|
function resolveManifestSyntheticAuthProviderRefState(
|
|
params: SyntheticAuthProviderRefParams = {},
|
|
): { refs: string[]; complete: boolean } {
|
|
if (params.index && (params.registryDiagnostics?.length ?? 0) > 0) {
|
|
return { refs: [], complete: false };
|
|
}
|
|
const result = loadPluginRegistrySnapshotWithMetadata(params);
|
|
if (result.source !== "persisted" && result.source !== "provided") {
|
|
return { refs: [], complete: false };
|
|
}
|
|
return {
|
|
refs: uniqueProviderRefs(
|
|
result.snapshot.plugins.flatMap((plugin) => plugin.syntheticAuthRefs ?? []),
|
|
),
|
|
complete: true,
|
|
};
|
|
}
|
|
|
|
type SyntheticAuthProviderRefParams = LoadPluginRegistryParams & {
|
|
index?: PluginRegistrySnapshot;
|
|
registryDiagnostics?: readonly unknown[];
|
|
};
|
|
|
|
/** Lists provider refs that can satisfy synthetic auth profile lookups. */
|
|
export function resolveRuntimeSyntheticAuthProviderRefs(
|
|
params: SyntheticAuthProviderRefParams = {},
|
|
): string[] {
|
|
return resolveRuntimeSyntheticAuthProviderRefState(params).refs;
|
|
}
|
|
|
|
/** Returns synthetic-auth refs plus whether the control-plane data source was complete. */
|
|
export function resolveRuntimeSyntheticAuthProviderRefState(
|
|
params: SyntheticAuthProviderRefParams = {},
|
|
): { refs: string[]; complete: boolean } {
|
|
const registry = getPluginRegistryState()?.activeRegistry;
|
|
if (registry) {
|
|
return {
|
|
refs: uniqueProviderRefs([
|
|
...registry.plugins.flatMap((plugin) => plugin.syntheticAuthRefs ?? []),
|
|
...(registry.providers ?? [])
|
|
.filter(
|
|
(entry) =>
|
|
"resolveSyntheticAuth" in entry.provider &&
|
|
typeof entry.provider.resolveSyntheticAuth === "function",
|
|
)
|
|
.map((entry) => entry.provider.id),
|
|
...registry.cliBackends
|
|
.filter(
|
|
(entry) =>
|
|
"resolveSyntheticAuth" in entry.backend &&
|
|
typeof entry.backend.resolveSyntheticAuth === "function",
|
|
)
|
|
.map((entry) => entry.backend.id),
|
|
]),
|
|
complete: true,
|
|
};
|
|
}
|
|
return resolveManifestSyntheticAuthProviderRefState(params);
|
|
}
|