mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:40:44 +00:00
refactor: share provider and outbound helpers
This commit is contained in:
@@ -7,9 +7,10 @@ import {
|
||||
resolveStorePath,
|
||||
} from "../../config/sessions/inbound.runtime.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { buildAgentSessionKey, type RoutePeer } from "../../routing/resolve-route.js";
|
||||
import type { RoutePeer } from "../../routing/resolve-route.js";
|
||||
import { resolveAgentIdFromSessionKey } from "../../routing/session-key.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
||||
import { buildOutboundBaseSessionKey } from "./base-session-key.js";
|
||||
import type { ResolvedMessagingTarget } from "./target-resolver.js";
|
||||
|
||||
export type OutboundSessionRoute = {
|
||||
@@ -76,23 +77,6 @@ function inferPeerKind(params: {
|
||||
return "direct";
|
||||
}
|
||||
|
||||
function buildBaseSessionKey(params: {
|
||||
cfg: OpenClawConfig;
|
||||
agentId: string;
|
||||
channel: ChannelId;
|
||||
accountId?: string | null;
|
||||
peer: RoutePeer;
|
||||
}): string {
|
||||
return buildAgentSessionKey({
|
||||
agentId: params.agentId,
|
||||
channel: params.channel,
|
||||
accountId: params.accountId,
|
||||
peer: params.peer,
|
||||
dmScope: params.cfg.session?.dmScope ?? "main",
|
||||
identityLinks: params.cfg.session?.identityLinks,
|
||||
});
|
||||
}
|
||||
|
||||
function resolveFallbackSession(
|
||||
params: ResolveOutboundSessionRouteParams,
|
||||
): OutboundSessionRoute | null {
|
||||
@@ -109,7 +93,7 @@ function resolveFallbackSession(
|
||||
return null;
|
||||
}
|
||||
const peer: RoutePeer = { kind: peerKind, id: peerId };
|
||||
const baseSessionKey = buildBaseSessionKey({
|
||||
const baseSessionKey = buildOutboundBaseSessionKey({
|
||||
cfg: params.cfg,
|
||||
agentId: params.agentId,
|
||||
channel: params.channel,
|
||||
|
||||
@@ -107,21 +107,24 @@ function normalizeExplicitBundledPluginIds(pluginIds: readonly string[]): string
|
||||
return [...new Set(pluginIds)].toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
export function loadBundledWebSearchProviderEntriesFromDir(params: {
|
||||
function loadBundledProviderEntriesFromDir<TProvider extends object>(params: {
|
||||
dirName: string;
|
||||
pluginId: string;
|
||||
}): PluginWebSearchProviderEntry[] | null {
|
||||
artifactCandidates: readonly string[];
|
||||
suffix: string;
|
||||
isProvider: (value: unknown) => value is TProvider;
|
||||
}): Array<TProvider & { pluginId: string }> | null {
|
||||
const mod = tryLoadBundledPublicArtifactModule({
|
||||
dirName: params.dirName,
|
||||
artifactCandidates: WEB_SEARCH_ARTIFACT_CANDIDATES,
|
||||
artifactCandidates: params.artifactCandidates,
|
||||
});
|
||||
if (!mod) {
|
||||
return null;
|
||||
}
|
||||
const providers = collectProviderFactories({
|
||||
mod,
|
||||
suffix: "WebSearchProvider",
|
||||
isProvider: isWebSearchProviderPlugin,
|
||||
suffix: params.suffix,
|
||||
isProvider: params.isProvider,
|
||||
});
|
||||
if (providers.length === 0) {
|
||||
return null;
|
||||
@@ -129,48 +132,43 @@ export function loadBundledWebSearchProviderEntriesFromDir(params: {
|
||||
return providers.map((provider) => Object.assign({}, provider, { pluginId: params.pluginId }));
|
||||
}
|
||||
|
||||
export function loadBundledWebSearchProviderEntriesFromDir(params: {
|
||||
dirName: string;
|
||||
pluginId: string;
|
||||
}): PluginWebSearchProviderEntry[] | null {
|
||||
return loadBundledProviderEntriesFromDir<WebSearchProviderPlugin>({
|
||||
dirName: params.dirName,
|
||||
pluginId: params.pluginId,
|
||||
artifactCandidates: WEB_SEARCH_ARTIFACT_CANDIDATES,
|
||||
suffix: "WebSearchProvider",
|
||||
isProvider: isWebSearchProviderPlugin,
|
||||
});
|
||||
}
|
||||
|
||||
export function loadBundledRuntimeWebSearchProviderEntriesFromDir(params: {
|
||||
dirName: string;
|
||||
pluginId: string;
|
||||
}): PluginWebSearchProviderEntry[] | null {
|
||||
const mod = tryLoadBundledPublicArtifactModule({
|
||||
return loadBundledProviderEntriesFromDir<WebSearchProviderPlugin>({
|
||||
dirName: params.dirName,
|
||||
pluginId: params.pluginId,
|
||||
artifactCandidates: WEB_SEARCH_RUNTIME_ARTIFACT_CANDIDATES,
|
||||
});
|
||||
if (!mod) {
|
||||
return null;
|
||||
}
|
||||
const providers = collectProviderFactories({
|
||||
mod,
|
||||
suffix: "WebSearchProvider",
|
||||
isProvider: isWebSearchProviderPlugin,
|
||||
});
|
||||
if (providers.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return providers.map((provider) => Object.assign({}, provider, { pluginId: params.pluginId }));
|
||||
}
|
||||
|
||||
export function loadBundledWebFetchProviderEntriesFromDir(params: {
|
||||
dirName: string;
|
||||
pluginId: string;
|
||||
}): PluginWebFetchProviderEntry[] | null {
|
||||
const mod = tryLoadBundledPublicArtifactModule({
|
||||
return loadBundledProviderEntriesFromDir<WebFetchProviderPlugin>({
|
||||
dirName: params.dirName,
|
||||
pluginId: params.pluginId,
|
||||
artifactCandidates: WEB_FETCH_ARTIFACT_CANDIDATES,
|
||||
});
|
||||
if (!mod) {
|
||||
return null;
|
||||
}
|
||||
const providers = collectProviderFactories({
|
||||
mod,
|
||||
suffix: "WebFetchProvider",
|
||||
isProvider: isWebFetchProviderPlugin,
|
||||
});
|
||||
if (providers.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return providers.map((provider) => Object.assign({}, provider, { pluginId: params.pluginId }));
|
||||
}
|
||||
|
||||
export function resolveBundledExplicitWebSearchProvidersFromPublicArtifacts(params: {
|
||||
|
||||
Reference in New Issue
Block a user