mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: simplify provider channel conversions
This commit is contained in:
@@ -4,9 +4,7 @@ import { buildArceeModelDefinition, ARCEE_BASE_URL, ARCEE_MODEL_CATALOG } from "
|
||||
export const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
||||
|
||||
function normalizeBaseUrl(baseUrl: string | undefined): string {
|
||||
return String(baseUrl ?? "")
|
||||
.trim()
|
||||
.replace(/\/+$/, "");
|
||||
return (baseUrl ?? "").trim().replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
export function isArceeOpenRouterBaseUrl(baseUrl: string | undefined): boolean {
|
||||
|
||||
@@ -668,7 +668,7 @@ export async function typeViaPlaywright(opts: {
|
||||
ssrfPolicy?: SsrFPolicy;
|
||||
}): Promise<void> {
|
||||
const resolved = requireRefOrSelector(opts.ref, opts.selector);
|
||||
const text = String(opts.text ?? "");
|
||||
const text = opts.text ?? "";
|
||||
const page = await getRestoredPageForTarget(opts);
|
||||
const label = resolved.ref ?? resolved.selector!;
|
||||
const locator = resolved.ref
|
||||
|
||||
@@ -115,7 +115,7 @@ export function registerBrowserStateCommands(
|
||||
if (!headersJsonValue) {
|
||||
throw new Error("Missing headers JSON (pass --headers-json or positional JSON argument)");
|
||||
}
|
||||
const parsed = JSON.parse(String(headersJsonValue)) as unknown;
|
||||
const parsed = JSON.parse(headersJsonValue) as unknown;
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
throw new Error("Headers JSON must be a JSON object");
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ async function runChutesOAuth(ctx: ProviderAuthContext): Promise<ProviderAuthRes
|
||||
const scopes = process.env.CHUTES_OAUTH_SCOPES?.trim() || "openid profile chutes:invoke";
|
||||
const clientId =
|
||||
process.env.CHUTES_CLIENT_ID?.trim() ||
|
||||
String(
|
||||
(
|
||||
await ctx.prompter.text({
|
||||
message: "Enter Chutes OAuth client id",
|
||||
placeholder: "cid_xxx",
|
||||
validate: (value: string) => (value?.trim() ? undefined : "Required"),
|
||||
}),
|
||||
})
|
||||
).trim();
|
||||
const clientSecret = normalizeOptionalString(process.env.CHUTES_CLIENT_SECRET);
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ export const HUGGINGFACE_MODEL_CATALOG: ModelDefinitionConfig[] = [
|
||||
];
|
||||
|
||||
export function isHuggingfacePolicyLocked(modelRef: string): boolean {
|
||||
const ref = String(modelRef).trim();
|
||||
const ref = modelRef.trim();
|
||||
return HUGGINGFACE_POLICY_SUFFIXES.some((suffix) => ref.endsWith(`:${suffix}`) || ref === suffix);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ export function createLlmTaskTool(api: OpenClawPluginApi) {
|
||||
const modelKey = toModelKey(provider, model);
|
||||
if (!provider || !model || !modelKey) {
|
||||
throw new Error(
|
||||
`provider/model could not be resolved (provider=${String(provider ?? "")}, model=${String(model ?? "")})`,
|
||||
`provider/model could not be resolved (provider=${provider ?? ""}, model=${model ?? ""})`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ export function resolveMatrixAccount(params: {
|
||||
userId: authView.userId || "",
|
||||
})
|
||||
: false;
|
||||
const configured = hasHomeserver && (hasAccessToken || hasPasswordAuth || Boolean(hasStored));
|
||||
const configured = hasHomeserver && (hasAccessToken || hasPasswordAuth || hasStored);
|
||||
return {
|
||||
accountId,
|
||||
enabled,
|
||||
|
||||
@@ -1245,7 +1245,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
||||
isDirect: isDirectMessage,
|
||||
isGroup: isRoom,
|
||||
isMentionableGroup: isRoom,
|
||||
requireMention: Boolean(shouldRequireMention),
|
||||
requireMention: shouldRequireMention,
|
||||
canDetectMention,
|
||||
effectiveWasMentioned: wasMentioned || shouldBypassMention,
|
||||
shouldBypassMention,
|
||||
|
||||
@@ -62,8 +62,7 @@ export const matrixOutbound: ChannelOutboundAdapter = {
|
||||
};
|
||||
},
|
||||
sendPoll: async ({ cfg, to, poll, threadId, accountId }) => {
|
||||
const resolvedThreadId =
|
||||
threadId !== undefined && threadId !== null ? String(threadId) : undefined;
|
||||
const resolvedThreadId = threadId !== undefined && threadId !== null ? threadId : undefined;
|
||||
const result = await sendPollMatrix(to, poll, {
|
||||
cfg,
|
||||
threadId: resolvedThreadId,
|
||||
|
||||
@@ -319,10 +319,10 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
|
||||
const graph = teamsProbe?.graph;
|
||||
if (graph) {
|
||||
const roles = Array.isArray(graph.roles)
|
||||
? graph.roles.map((role) => String(role).trim()).filter(Boolean)
|
||||
? graph.roles.map((role) => role.trim()).filter(Boolean)
|
||||
: [];
|
||||
const scopes = Array.isArray(graph.scopes)
|
||||
? graph.scopes.map((scope) => String(scope).trim()).filter(Boolean)
|
||||
? graph.scopes.map((scope) => scope.trim()).filter(Boolean)
|
||||
: [];
|
||||
const formatPermission = (permission: string) => {
|
||||
const hint = TEAMS_GRAPH_PERMISSION_HINTS[permission];
|
||||
|
||||
@@ -513,7 +513,7 @@ export function createMSTeamsMessageHandler(deps: MSTeamsMessageHandlerDeps) {
|
||||
},
|
||||
policy: {
|
||||
isGroup: !isDirectMessage,
|
||||
requireMention: Boolean(requireMention),
|
||||
requireMention,
|
||||
allowTextCommands: false,
|
||||
hasControlCommand: false,
|
||||
commandAuthorized: false,
|
||||
|
||||
@@ -16,7 +16,7 @@ function injectOpenRouterRouting(
|
||||
baseStreamFn ??
|
||||
((nextModel) => {
|
||||
throw new Error(
|
||||
`OpenRouter routing wrapper requires an underlying streamFn for ${String(nextModel.id)}.`,
|
||||
`OpenRouter routing wrapper requires an underlying streamFn for ${nextModel.id}.`,
|
||||
);
|
||||
})
|
||||
)(
|
||||
|
||||
@@ -44,7 +44,7 @@ export function createQaRunnerRuntime(): PluginRuntime {
|
||||
}) {
|
||||
sessions.set(sessionKey, {
|
||||
sessionKey,
|
||||
body: String(ctx.BodyForAgent ?? ctx.Body ?? ""),
|
||||
body: ctx.BodyForAgent ?? ctx.Body ?? "",
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -66,7 +66,7 @@ export function createQaRunnerRuntime(): PluginRuntime {
|
||||
dispatcherOptions: { deliver: (payload: { text: string }) => Promise<void> };
|
||||
}) {
|
||||
await dispatcherOptions.deliver({
|
||||
text: `qa-echo: ${String(ctx.BodyForAgent ?? ctx.Body ?? "")}`,
|
||||
text: `qa-echo: ${ctx.BodyForAgent ?? ctx.Body ?? ""}`,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -205,11 +205,11 @@ function isMatrixAccountReady(entry?: {
|
||||
restartPending?: boolean;
|
||||
running?: boolean;
|
||||
}): boolean {
|
||||
return Boolean(
|
||||
return (
|
||||
entry?.running === true &&
|
||||
entry.connected === true &&
|
||||
entry.restartPending !== true &&
|
||||
(entry.healthState === undefined || entry.healthState === "healthy"),
|
||||
(entry.healthState === undefined || entry.healthState === "healthy")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -827,7 +827,7 @@ async function resolveGeneratedImagePath(params: {
|
||||
);
|
||||
for (let index = requests.length - 1; index >= 0; index -= 1) {
|
||||
const request = requests[index];
|
||||
if (!String(request.allInputText ?? "").includes(params.promptSnippet)) {
|
||||
if (!(request.allInputText ?? "").includes(params.promptSnippet)) {
|
||||
continue;
|
||||
}
|
||||
const mediaPath = extractMediaPathFromText(request.toolOutput);
|
||||
@@ -1055,7 +1055,7 @@ async function runAgentPrompt(
|
||||
const waited = await waitForAgentRun(env, started.runId!, params.timeoutMs ?? 30_000);
|
||||
if (waited.status !== "ok") {
|
||||
throw new Error(
|
||||
`agent.wait returned ${String(waited.status ?? "unknown")}: ${waited.error ?? "no error"}`,
|
||||
`agent.wait returned ${waited.status ?? "unknown"}: ${waited.error ?? "no error"}`,
|
||||
);
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -508,7 +508,7 @@ export async function prepareSlackMessage(params: {
|
||||
},
|
||||
policy: {
|
||||
isGroup: isRoom,
|
||||
requireMention: Boolean(shouldRequireMention),
|
||||
requireMention: shouldRequireMention,
|
||||
allowedImplicitMentionKinds: ctx.threadRequireExplicitMention ? [] : undefined,
|
||||
allowTextCommands,
|
||||
hasControlCommand: hasControlCommandInMessage,
|
||||
@@ -576,7 +576,7 @@ export async function prepareSlackMessage(params: {
|
||||
isDirect: isDirectMessage,
|
||||
isGroup: isRoomish,
|
||||
isMentionableGroup: isRoom,
|
||||
requireMention: Boolean(shouldRequireMention),
|
||||
requireMention: shouldRequireMention,
|
||||
canDetectMention,
|
||||
effectiveWasMentioned,
|
||||
shouldBypassMention: mentionDecision.shouldBypassMention,
|
||||
|
||||
@@ -42,7 +42,7 @@ function hasSlackInteractiveRepliesConfig(cfg: OpenClawConfig, accountId: string
|
||||
const capabilities = resolveSlackAccount({ cfg, accountId }).config.capabilities;
|
||||
if (Array.isArray(capabilities)) {
|
||||
return capabilities.some(
|
||||
(entry) => normalizeLowercaseStringOrEmpty(String(entry)) === "interactivereplies",
|
||||
(entry) => normalizeLowercaseStringOrEmpty(entry) === "interactivereplies",
|
||||
);
|
||||
}
|
||||
if (!capabilities || typeof capabilities !== "object") {
|
||||
@@ -61,7 +61,7 @@ function setSlackInteractiveReplies(
|
||||
? interactiveReplies
|
||||
? [...new Set([...capabilities, "interactiveReplies"])]
|
||||
: capabilities.filter(
|
||||
(entry) => normalizeLowercaseStringOrEmpty(String(entry)) !== "interactivereplies",
|
||||
(entry) => normalizeLowercaseStringOrEmpty(entry) !== "interactivereplies",
|
||||
)
|
||||
: {
|
||||
...((capabilities && typeof capabilities === "object" ? capabilities : {}) as Record<
|
||||
|
||||
@@ -239,7 +239,7 @@ export async function runTavilyExtract(
|
||||
...(Array.isArray(r.images)
|
||||
? {
|
||||
images: (r.images as string[]).map((img) =>
|
||||
wrapExternalContent(String(img), { source: "web_fetch", includeWarning: false }),
|
||||
wrapExternalContent(img, { source: "web_fetch", includeWarning: false }),
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function promptZaloAllowFrom(params: {
|
||||
placeholder: "123456789",
|
||||
initialValue: existingAllowFrom[0] ? String(existingAllowFrom[0]) : undefined,
|
||||
validate: (value) => {
|
||||
const raw = String(value ?? "").trim();
|
||||
const raw = (value ?? "").trim();
|
||||
if (!raw) {
|
||||
return "Required";
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export async function promptZaloAllowFrom(params: {
|
||||
return undefined;
|
||||
},
|
||||
});
|
||||
const normalized = String(entry).trim();
|
||||
const normalized = entry.trim();
|
||||
const unique = mergeAllowFromEntries(existingAllowFrom, [normalized]);
|
||||
|
||||
if (accountId === DEFAULT_ACCOUNT_ID) {
|
||||
|
||||
@@ -200,13 +200,13 @@ export const zaloSetupWizard: ChannelSetupWizard = {
|
||||
initialValue: Boolean(resolvedAccount.config.webhookUrl),
|
||||
});
|
||||
if (wantsWebhook) {
|
||||
const webhookUrl = String(
|
||||
const webhookUrl = (
|
||||
await prompter.text({
|
||||
message: "Webhook URL (https://...) ",
|
||||
initialValue: resolvedAccount.config.webhookUrl,
|
||||
validate: (value) =>
|
||||
value?.trim()?.startsWith("https://") ? undefined : "HTTPS URL required",
|
||||
}),
|
||||
})
|
||||
).trim();
|
||||
const defaultPath = (() => {
|
||||
try {
|
||||
@@ -259,11 +259,11 @@ export const zaloSetupWizard: ChannelSetupWizard = {
|
||||
webhookSecretResult.action === "set"
|
||||
? webhookSecretResult.value
|
||||
: resolvedAccount.config.webhookSecret;
|
||||
const webhookPath = String(
|
||||
const webhookPath = (
|
||||
await prompter.text({
|
||||
message: "Webhook path (optional)",
|
||||
initialValue: resolvedAccount.config.webhookPath ?? defaultPath,
|
||||
}),
|
||||
})
|
||||
).trim();
|
||||
next = setZaloUpdateMode(
|
||||
next,
|
||||
|
||||
Reference in New Issue
Block a user