refactor: dedupe acp text normalization helper

This commit is contained in:
Peter Steinberger
2026-04-06 22:19:23 +01:00
parent 961f527842
commit c390e7c6ce
5 changed files with 15 additions and 32 deletions

View File

@@ -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 {

View 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;
}

View File

@@ -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";

View File

@@ -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) {

View File

@@ -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;