mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:00:43 +00:00
refactor: trim unused extension helpers
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import { formatInboundFromLabel as formatInboundFromLabelShared } from "openclaw/plugin-sdk/channel-inbound";
|
||||
import { createDedupeCache, type OpenClawConfig } from "openclaw/plugin-sdk/core";
|
||||
import { createDedupeCache } from "openclaw/plugin-sdk/core";
|
||||
import { resolveThreadSessionKeys as resolveThreadSessionKeysShared } from "openclaw/plugin-sdk/routing";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalString,
|
||||
} from "openclaw/plugin-sdk/text-runtime";
|
||||
import { rawDataToString } from "openclaw/plugin-sdk/webhook-ingress";
|
||||
|
||||
export { createDedupeCache, rawDataToString };
|
||||
@@ -17,51 +13,8 @@ export type ResponsePrefixContext = {
|
||||
identityName?: string;
|
||||
};
|
||||
|
||||
export function extractShortModelName(fullModel: string): string {
|
||||
const slash = fullModel.lastIndexOf("/");
|
||||
const modelPart = slash >= 0 ? fullModel.slice(slash + 1) : fullModel;
|
||||
return modelPart.replace(/-\d{8}$/, "").replace(/-latest$/, "");
|
||||
}
|
||||
|
||||
export const formatInboundFromLabel = formatInboundFromLabelShared;
|
||||
|
||||
function normalizeAgentId(value: string | undefined | null): string {
|
||||
const trimmed = (value ?? "").trim();
|
||||
if (!trimmed) {
|
||||
return "main";
|
||||
}
|
||||
if (/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(trimmed)) {
|
||||
return trimmed;
|
||||
}
|
||||
return (
|
||||
normalizeLowercaseStringOrEmpty(trimmed)
|
||||
.replace(/[^a-z0-9_-]+/g, "-")
|
||||
.replace(/^-+/, "")
|
||||
.replace(/-+$/, "")
|
||||
.slice(0, 64) || "main"
|
||||
);
|
||||
}
|
||||
|
||||
type AgentEntry = NonNullable<NonNullable<OpenClawConfig["agents"]>["list"]>[number];
|
||||
|
||||
function isAgentEntry(entry: unknown): entry is AgentEntry {
|
||||
return Boolean(entry && typeof entry === "object");
|
||||
}
|
||||
|
||||
function listAgents(cfg: OpenClawConfig): AgentEntry[] {
|
||||
return Array.isArray(cfg.agents?.list) ? cfg.agents.list.filter(isAgentEntry) : [];
|
||||
}
|
||||
|
||||
function resolveAgentEntry(cfg: OpenClawConfig, agentId: string): AgentEntry | undefined {
|
||||
const id = normalizeAgentId(agentId);
|
||||
return listAgents(cfg).find((entry) => normalizeAgentId(entry.id) === id);
|
||||
}
|
||||
|
||||
export function resolveIdentityName(cfg: OpenClawConfig, agentId: string): string | undefined {
|
||||
const entry = resolveAgentEntry(cfg, agentId);
|
||||
return normalizeOptionalString(entry?.identity?.name);
|
||||
}
|
||||
|
||||
export function resolveThreadSessionKeys(params: {
|
||||
baseSessionKey: string;
|
||||
threadId?: string | null;
|
||||
|
||||
@@ -132,17 +132,6 @@ export function parsePostedPayload(
|
||||
return { payload, post };
|
||||
}
|
||||
|
||||
export function parsePostedEvent(
|
||||
data: WebSocket.RawData,
|
||||
): { payload: MattermostEventPayload; post: MattermostPost } | null {
|
||||
const raw = rawDataToString(data);
|
||||
const payload = parseMattermostEventPayload(raw);
|
||||
if (!payload) {
|
||||
return null;
|
||||
}
|
||||
return parsePostedPayload(payload);
|
||||
}
|
||||
|
||||
export function createMattermostConnectOnce(
|
||||
opts: CreateMattermostConnectOnceOpts,
|
||||
): () => Promise<void> {
|
||||
|
||||
@@ -80,10 +80,6 @@ export function setMemoryWorkspaceDir(next: string): void {
|
||||
workspaceDir = next;
|
||||
}
|
||||
|
||||
export function setMemoryStatusCustom(next: Record<string, unknown> | undefined): void {
|
||||
customStatus = next;
|
||||
}
|
||||
|
||||
export function setMemorySearchImpl(next: SearchImpl): void {
|
||||
searchImpl = next;
|
||||
}
|
||||
|
||||
@@ -2,15 +2,6 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { lowercasePreservingWhitespace } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export async function pathExists(filePath: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.access(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function resolveArtifactKey(absolutePath: string): Promise<string> {
|
||||
const canonicalPath = await fs.realpath(absolutePath).catch(() => path.resolve(absolutePath));
|
||||
return process.platform === "win32"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
||||
import type { QaTransportState } from "./qa-transport.js";
|
||||
import type { QaScenarioFlow, QaSeedScenarioWithSource } from "./scenario-catalog.js";
|
||||
|
||||
@@ -292,7 +291,3 @@ export async function runScenarioFlow(params: {
|
||||
}));
|
||||
return await params.api.runScenario(params.scenarioTitle, steps);
|
||||
}
|
||||
|
||||
export function describeScenarioFlowError(error: unknown) {
|
||||
return formatErrorMessage(error);
|
||||
}
|
||||
|
||||
@@ -95,11 +95,6 @@ function readLegacyGrokApiKeyResult(cfg?: OpenClawConfig): ConfiguredRuntimeApiK
|
||||
);
|
||||
}
|
||||
|
||||
export function readLegacyGrokApiKey(cfg?: OpenClawConfig): string | undefined {
|
||||
const resolved = readLegacyGrokApiKeyResult(cfg);
|
||||
return resolved.status === "available" ? resolved.value : undefined;
|
||||
}
|
||||
|
||||
function readPluginXaiWebSearchApiKeyResult(
|
||||
cfg?: OpenClawConfig,
|
||||
): ConfiguredRuntimeApiKeyResolution {
|
||||
@@ -110,11 +105,6 @@ function readPluginXaiWebSearchApiKeyResult(
|
||||
);
|
||||
}
|
||||
|
||||
export function readPluginXaiWebSearchApiKey(cfg?: OpenClawConfig): string | undefined {
|
||||
const resolved = readPluginXaiWebSearchApiKeyResult(cfg);
|
||||
return resolved.status === "available" ? resolved.value : undefined;
|
||||
}
|
||||
|
||||
export function resolveFallbackXaiAuth(cfg?: OpenClawConfig): XaiFallbackAuth | undefined {
|
||||
const pluginApiKey = readConfiguredOrManagedApiKey(
|
||||
resolveProviderWebSearchPluginConfig(cfg as Record<string, unknown> | undefined, "xai")?.apiKey,
|
||||
|
||||
Reference in New Issue
Block a user