mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe acp lowercase helpers
This commit is contained in:
@@ -4,6 +4,7 @@ import { logVerbose } from "../../globals.js";
|
||||
import { formatErrorMessage } from "../../infra/errors.js";
|
||||
import { normalizeAgentId } from "../../routing/session-key.js";
|
||||
import { isAcpSessionKey } from "../../sessions/session-key-utils.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
||||
import {
|
||||
createRunningTaskRun,
|
||||
completeTaskRunByRunId,
|
||||
@@ -1581,12 +1582,12 @@ export class AcpSessionManager {
|
||||
if (!status) {
|
||||
return false;
|
||||
}
|
||||
const detailsStatus = normalizeText(status.details?.status)?.toLowerCase() ?? "";
|
||||
const detailsStatus = normalizeLowercaseStringOrEmpty(status.details?.status);
|
||||
if (detailsStatus === "dead" || detailsStatus === "no-session") {
|
||||
return true;
|
||||
}
|
||||
const summaryMatch = status.summary?.match(/\bstatus=([^\s]+)/i);
|
||||
const summaryStatus = normalizeText(summaryMatch?.[1])?.toLowerCase() ?? "";
|
||||
const summaryStatus = normalizeLowercaseStringOrEmpty(summaryMatch?.[1]);
|
||||
return summaryStatus === "dead" || summaryStatus === "no-session";
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ export function canonicalizeAcpSessionKey(params: {
|
||||
if (!normalized) {
|
||||
return "";
|
||||
}
|
||||
const lowered = normalized.toLowerCase();
|
||||
const lowered = normalizeLowercaseStringOrEmpty(normalized);
|
||||
if (lowered === "global" || lowered === "unknown") {
|
||||
return lowered;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { isAbsolute } from "node:path";
|
||||
import type { AcpSessionRuntimeOptions, SessionAcpMeta } from "../../config/sessions/types.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
||||
import { normalizeText } from "../normalize-text.js";
|
||||
import { AcpRuntimeError } from "../runtime/errors.js";
|
||||
|
||||
@@ -319,7 +320,7 @@ export function inferRuntimeOptionPatchFromConfigOption(
|
||||
value: string,
|
||||
): Partial<AcpSessionRuntimeOptions> {
|
||||
const validated = validateRuntimeConfigOptionInput(key, value);
|
||||
const normalizedKey = validated.key.toLowerCase();
|
||||
const normalizedKey = normalizeLowercaseStringOrEmpty(validated.key);
|
||||
if (normalizedKey === "model") {
|
||||
return { model: validateRuntimeModelInput(validated.value) };
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
} from "@agentclientprotocol/sdk";
|
||||
import {
|
||||
hasNonEmptyString,
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalString,
|
||||
readStringValue,
|
||||
} from "../shared/string-coerce.js";
|
||||
@@ -315,7 +316,7 @@ export function inferToolKind(name?: string): ToolKind {
|
||||
if (!name) {
|
||||
return "other";
|
||||
}
|
||||
const normalized = name.toLowerCase();
|
||||
const normalized = normalizeLowercaseStringOrEmpty(name);
|
||||
if (normalized.includes("read")) {
|
||||
return "read";
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import type { SessionBindingRecord } from "../infra/outbound/session-binding-service.js";
|
||||
import { normalizeAccountId, resolveAgentIdFromSessionKey } from "../routing/session-key.js";
|
||||
import { sanitizeAgentId } from "../routing/session-key.js";
|
||||
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
|
||||
import { normalizeText } from "./normalize-text.js";
|
||||
import type { AcpRuntimeSessionMode } from "./runtime/types.js";
|
||||
|
||||
@@ -38,7 +39,7 @@ export type AcpBindingConfigShape = {
|
||||
};
|
||||
|
||||
export function normalizeMode(value: unknown): AcpRuntimeSessionMode {
|
||||
const raw = normalizeText(value)?.toLowerCase();
|
||||
const raw = normalizeOptionalLowercaseString(value);
|
||||
return raw === "oneshot" ? "oneshot" : "persistent";
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ export function parseConfiguredAcpSessionKey(
|
||||
if (tokens.length !== 5 || tokens[0] !== "acp" || tokens[1] !== "binding") {
|
||||
return null;
|
||||
}
|
||||
const channel = normalizeText(tokens[2])?.toLowerCase();
|
||||
const channel = normalizeOptionalLowercaseString(tokens[2]);
|
||||
if (!channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { SessionAcpIdentity, SessionAcpMeta } from "../../config/sessions/types.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
||||
import { normalizeText } from "../normalize-text.js";
|
||||
import { isSessionIdentityPending, resolveSessionIdentityFromMeta } from "./session-identity.js";
|
||||
|
||||
@@ -40,7 +41,7 @@ function normalizeAgentHintKey(value: unknown): string | undefined {
|
||||
if (!normalized) {
|
||||
return undefined;
|
||||
}
|
||||
return normalized.toLowerCase().replace(/[\s_]+/g, "-");
|
||||
return normalizeLowercaseStringOrEmpty(normalized).replace(/[\s_]+/g, "-");
|
||||
}
|
||||
|
||||
function resolveAcpAgentResumeHintLine(params: {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type SessionEntry,
|
||||
} from "../../config/sessions/types.js";
|
||||
import { parseAgentSessionKey } from "../../routing/session-key.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
||||
|
||||
let sessionStoreRuntimePromise:
|
||||
| Promise<typeof import("../../config/sessions/store.runtime.js")>
|
||||
@@ -37,12 +38,12 @@ function resolveStoreSessionKey(store: Record<string, SessionEntry>, sessionKey:
|
||||
if (store[normalized]) {
|
||||
return normalized;
|
||||
}
|
||||
const lower = normalized.toLowerCase();
|
||||
const lower = normalizeLowercaseStringOrEmpty(normalized);
|
||||
if (store[lower]) {
|
||||
return lower;
|
||||
}
|
||||
for (const key of Object.keys(store)) {
|
||||
if (key.toLowerCase() === lower) {
|
||||
if (normalizeLowercaseStringOrEmpty(key) === lower) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -171,7 +172,7 @@ export async function upsertAcpSessionMeta(params: {
|
||||
return nextEntry;
|
||||
},
|
||||
{
|
||||
activeSessionKey: sessionKey.toLowerCase(),
|
||||
activeSessionKey: normalizeLowercaseStringOrEmpty(sessionKey),
|
||||
allowDropAcpMetaSessionKeys: [sessionKey],
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user