Fix repo Face identity description bounds

This commit is contained in:
Meta Vens 2026-05-18 17:04:36 +01:00
commit aff9ddd04d
3 changed files with 34 additions and 4 deletions

View file

@ -49,14 +49,30 @@ export interface VoidSelfStateIdentityDefaults {
publicDescription?: string;
}
const MAX_PUBLIC_DESCRIPTION_LENGTH = 1000;
export function normalizeVoidSelfStateIdentityDefaults(
identity: VoidSelfStateIdentityDefaults,
): VoidSelfStateIdentityDefaults {
return {
...identity,
publicDescription: truncateOptionalText(
identity.publicDescription,
MAX_PUBLIC_DESCRIPTION_LENGTH,
),
};
}
export function createEmptyVoidSelfState(
options: { createdAt?: string; identity?: VoidSelfStateIdentityDefaults } = {},
): VoidSelfStateTypedProjection {
const createdAt = options.createdAt ?? new Date().toISOString();
const identity = options.identity ?? {
agentId: "void-moderator",
publicName: "Void",
};
const identity = normalizeVoidSelfStateIdentityDefaults(
options.identity ?? {
agentId: "void-moderator",
publicName: "Void",
},
);
return {
selfProfile: voidSelfProfileSchema.parse({
@ -119,6 +135,17 @@ export function createEmptyVoidSelfState(
};
}
function truncateOptionalText(value: string | undefined, maxLength: number): string | undefined {
const trimmed = value?.trim();
if (!trimmed) {
return undefined;
}
if (trimmed.length <= maxLength) {
return trimmed;
}
return trimmed.slice(0, maxLength - 1).trimEnd();
}
export function buildVoidSelfStateContext(
typedState: VoidSelfStateTypedProjection,
options: VoidSelfStateProjectionOptions,

View file

@ -22,6 +22,7 @@ import {
} from "./void-self-state-domain";
import {
createEmptyVoidSelfState,
normalizeVoidSelfStateIdentityDefaults,
type VoidSelfStateIdentityDefaults,
type VoidSelfStateTypedProjection,
} from "./void-self-state-projection";
@ -131,6 +132,7 @@ function repairSelfProfileIdentity(
state: VoidSelfStateTypedProjection,
identity: VoidSelfStateIdentityDefaults,
): void {
identity = normalizeVoidSelfStateIdentityDefaults(identity);
let changed = false;
if (state.selfProfile.agentId !== identity.agentId) {