mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 02:20:30 +00:00
refactor: dedupe acp text normalization helper
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { isAbsolute } from "node:path";
|
||||
import type { AcpSessionRuntimeOptions, SessionAcpMeta } from "../../config/sessions/types.js";
|
||||
import { normalizeText } from "../normalize-text.js";
|
||||
import { AcpRuntimeError } from "../runtime/errors.js";
|
||||
|
||||
export { normalizeText } from "../normalize-text.js";
|
||||
|
||||
const MAX_RUNTIME_MODE_LENGTH = 64;
|
||||
const MAX_MODEL_LENGTH = 200;
|
||||
const MAX_PERMISSION_PROFILE_LENGTH = 80;
|
||||
@@ -211,14 +214,6 @@ export function validateRuntimeOptionPatch(
|
||||
return next;
|
||||
}
|
||||
|
||||
export function normalizeText(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
export function normalizeRuntimeOptions(
|
||||
options: AcpSessionRuntimeOptions | undefined,
|
||||
): AcpSessionRuntimeOptions {
|
||||
|
||||
7
src/acp/normalize-text.ts
Normal file
7
src/acp/normalize-text.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function normalizeText(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
@@ -3,8 +3,11 @@ 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 { normalizeText } from "./normalize-text.js";
|
||||
import type { AcpRuntimeSessionMode } from "./runtime/types.js";
|
||||
|
||||
export { normalizeText } from "./normalize-text.js";
|
||||
|
||||
export type ConfiguredAcpBindingChannel = ChannelId;
|
||||
|
||||
export type ConfiguredAcpBindingSpec = {
|
||||
@@ -34,14 +37,6 @@ export type AcpBindingConfigShape = {
|
||||
label?: string;
|
||||
};
|
||||
|
||||
export function normalizeText(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
export function normalizeMode(value: unknown): AcpRuntimeSessionMode {
|
||||
const raw = normalizeText(value)?.toLowerCase();
|
||||
return raw === "oneshot" ? "oneshot" : "persistent";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { SessionAcpIdentity, SessionAcpMeta } from "../../config/sessions/types.js";
|
||||
import { normalizeText } from "../normalize-text.js";
|
||||
import { isSessionIdentityPending, resolveSessionIdentityFromMeta } from "./session-identity.js";
|
||||
|
||||
export const ACP_SESSION_IDENTITY_RENDERER_VERSION = "v1";
|
||||
@@ -34,14 +35,6 @@ const ACP_AGENT_RESUME_HINT_BY_KEY = new Map<string, SessionResumeHintResolver>(
|
||||
],
|
||||
]);
|
||||
|
||||
function normalizeText(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
function normalizeAgentHintKey(value: unknown): string | undefined {
|
||||
const normalized = normalizeText(value);
|
||||
if (!normalized) {
|
||||
|
||||
@@ -3,16 +3,9 @@ import type {
|
||||
SessionAcpIdentitySource,
|
||||
SessionAcpMeta,
|
||||
} from "../../config/sessions/types.js";
|
||||
import { normalizeText } from "../normalize-text.js";
|
||||
import type { AcpRuntimeHandle, AcpRuntimeStatus } from "./types.js";
|
||||
|
||||
function normalizeText(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
function normalizeIdentityState(value: unknown): SessionAcpIdentity["state"] | undefined {
|
||||
if (value !== "pending" && value !== "resolved") {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user